smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.dx.MessageSend;
@@ -15,6 +16,7 @@
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.smartor.common.DeepSeekApi;
import com.smartor.common.FtpService;
import com.smartor.common.MtSubmitSmUtil;
import com.smartor.config.PhoneUtils;
@@ -43,11 +45,9 @@
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
@@ -131,6 +131,9 @@
    @Autowired
    private SvyLibScriptCategoryMapper svyLibScriptCategoryMapper;
    @Autowired
    private IPatMedInhospService patMedInhospService;
    @Value("${pri_key}")
    private String pri_key;
@@ -413,9 +416,74 @@
                    serviceSubtaskRes.setCurrentPreachform(serviceSubtask.getPreachform().split(",")[0]);
                }
            }
            PatMedInhosp inhosp = patMedInhospMapper.selectPatMedInhospByInhospid(serviceSubtask.getInhospid());
            if (ObjectUtils.isNotEmpty(inhosp)) {
                PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(inhosp.getPatid());
                if (ObjectUtils.isNotEmpty(patArchive)) {
                    Map<String, String> stringStringMap = calculateAge(patArchive.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());
                    serviceSubtaskRes.setAge(StringUtils.isNotEmpty(stringStringMap.get("age")) ? Long.valueOf(stringStringMap.get("age")) : null);
                    serviceSubtaskRes.setSex(patArchive.getSex());
                    serviceSubtaskRes.setSexName(patArchive.getSex() != null ? (patArchive.getSex() == 1 ? "男" : "女") : null);
                }
                serviceSubtaskRes.setHospno(inhosp.getInhospno());
                serviceSubtaskRes.setPatno(inhosp.getPatno());
            }
            serviceSubtaskResList.add(serviceSubtaskRes);
        }
        return serviceSubtaskResList;
    }
    public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) {
        if (birthdate == null || today.isBefore(birthdate)) {
            return null;
        }
        Map<String, String> ageMap = new HashMap<>();
        Period period = Period.between(birthdate, today);
        long totalDays = ChronoUnit.DAYS.between(birthdate, today);
        long totalMonths = ChronoUnit.MONTHS.between(birthdate, today);
        int years = period.getYears();
        int months = period.getMonths();
        int days = period.getDays();
        String ageUnit;
        Integer age;
        String ageUnit2 = null;
        Integer age2 = null;
        if (totalDays < 90) {
            // 小于 1 个月,按天计算
            ageUnit = "天";
            age = (int) totalDays;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", null);
            ageMap.put("ageUnit2", null);
        } else if (totalMonths < 36) {
            // 小于 1 年,按月 + 天计算
            ageUnit = "月";
            age = (int) totalMonths;
            ageUnit2 = "天";
            age2 = days;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", age2 != null ? age2.toString() : null);
            ageMap.put("ageUnit2", ageUnit2);
        } else {
            // 大于 1 年,按年 + 月计算
            ageUnit = "岁";
            age = years;
            ageUnit2 = "月";
            age2 = months;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", age2 != null ? age2.toString() : null);
            ageMap.put("ageUnit2", ageUnit2);
        }
        return ageMap;
    }
    @Override
@@ -1662,20 +1730,39 @@
                    if (StringUtils.isEmpty(phoneCallReqYQVO.getAsrtext())) {
                        continue;
                    }
                    //包含
                    Matcher matcher = null;
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) {
                        Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex());
                        matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
                    //2-AI识别
                    SysConfig configVoiceMatchType = new SysConfig();
                    configVoiceMatchType.setOrgid(phoneCallReqYQVO.getOrgid());
                    configVoiceMatchType.setConfigKey("sys.voice.match.type");
                    SysConfig matchType = sysConfigMapper.selectConfig(configVoiceMatchType);
                    boolean matchedFlag = false;
                    if(ObjectUtils.isNotEmpty(matchType) && StringUtils.isNotEmpty(matchType.getConfigValue()) && matchType.getConfigValue().equals("2")){
                        int checkFlag = DeepSeekApi.matchQuestionAnswer(ivrTaskTemplateScriptVO.getScriptContent(),
                                phoneCallReqYQVO.getAsrtext(),
                                ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetvalue());
                        if(checkFlag == 1){
                            matchedFlag = true;
                        }
                    }else {
                        //包含
                        Matcher matcher = null;
                        if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) {
                            Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex());
                            matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
                        }
                        //不包含
                        Matcher matcher2 = null;
                        if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) {
                            Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
                            matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
                        }
                        if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
                            matchedFlag = true;
                        }
                    }
                    //不包含
                    Matcher matcher2 = null;
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) {
                        Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
                        matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
                    }
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
                        //说明匹配正确了
                    //说明匹配正确了
                    if(matchedFlag){
                        //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法
                        log.info("匹配正确了吗--------------");
                        ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(1);
@@ -4540,9 +4627,9 @@
    }
    @Override
    public List<ServiceSubtask> gethelibraryCountHyperlink(HeLibraryCountVO heLibraryCountVO){
    public List<ServiceSubtask> gethelibraryCountHyperlink(HeLibraryCountVO heLibraryCountVO) {
        String hyperLinkInfoType = heLibraryCountVO.getHyperLinkInfoType();
        if(StringUtils.isNotEmpty(hyperLinkInfoType)){
        if (StringUtils.isNotEmpty(hyperLinkInfoType)) {
            heLibraryCountVO.setSendstate(null);
            heLibraryCountVO.setIsFinished(null);
            switch (hyperLinkInfoType) {
@@ -4765,4 +4852,105 @@
        }
    }
    public String scanGenerateSubtask(ServiceTask serviceTaskVo) {
        String content = "";
        String ip = localIP;
        ServiceTask serviceTask = new ServiceTask();
        serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceTaskVo.getTaskid());
        if (ObjectUtils.isNotEmpty(serviceTask)) {
            try {
                ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
                if (ObjectUtils.isNotEmpty(serviceTaskVo.getDeptcode())) {
                    serviceTaskdept.setDeptType("1");
                    serviceTaskdept.setDeptCode(serviceTask.getDeptcode());
                }
                if (ObjectUtils.isNotEmpty(serviceTaskVo.getLeavehospitaldistrictcode())) {
                    serviceTaskdept.setDeptType("2");
                    serviceTaskdept.setDeptCode(serviceTaskVo.getLeavehospitaldistrictcode());
                }
                serviceTaskdept.setServiceType(serviceTask.getServiceType());
                serviceTaskdept.setOrgid(serviceTask.getOrgid());
                serviceTaskdept.setTaskId(serviceTaskVo.getTaskid());
                List<ServiceTaskdept> serviceTaskdepts = serviceTaskdeptService.selectServiceTaskdeptList(serviceTaskdept);
                if (!CollectionUtils.isEmpty(serviceTaskdepts)) {
                    PatArchive patArchive = new PatArchive();
                    patArchive.setId(-1L);
                    patArchive.setName("虚拟患者");
                    //封装serviceSubtask
                    ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patArchive);
                    int i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                    //根据生成外链
                    if (ObjectUtils.isNotEmpty(serviceSubtask.getTaskid()) && ObjectUtils.isNotEmpty(serviceSubtask.getPatid()) && ObjectUtils.isNotEmpty(serviceSubtask.getId())) {
                        RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
                        String taskId = rsaPublicKeyExample.encryptedData(serviceSubtask.getTaskid().toString(), pub_key);
                        String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key);
                        String subId = rsaPublicKeyExample.encryptedData(serviceSubtask.getId().toString(), pub_key);
                        ServiceOutPath serviceOutPath = new ServiceOutPath();
                        serviceOutPath.setParam1(taskId);
                        serviceOutPath.setParam2(patid);
                        serviceOutPath.setParam3(serviceTask.getTaskName());
                        serviceOutPath.setParam6(subId);
                        serviceOutPath.setCreateTime(new Date());
                        serviceOutPath.setOrgid(serviceTask.getOrgid());
                        iServiceOutPathService.insertServiceOutPath(serviceOutPath);
                        String format = String.format("%03X", serviceOutPath.getId());
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        String url = ip + ":" + req_path + "/wt?p=" + format;
                        content = url;
                        serviceOutPath.setUrl(url);
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("【扫码生成任务】处理异常:{}", e.getMessage());
            }
        }
        return content;
    }
    public ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, PatArchive patArchive) {
        ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class);
        serviceSubtask.setTaskid(serviceTask.getTaskid());
        if (StringUtils.isNotEmpty(serviceTask.getLibtemplateid()))
            serviceSubtask.setLibtemplateid(Long.valueOf(serviceTask.getLibtemplateid()));
//        serviceSubtask.setNurseId(patMedInhosp1.getNurseId());
//        serviceSubtask.setNurseName(patMedInhosp1.getNurseName());
//        serviceSubtask.setDrcode(patMedInhosp1.getDrcode());
//        serviceSubtask.setDrname(patMedInhosp1.getDrname());
        serviceSubtask.setDeptcode(serviceTask.getDeptcode());
        serviceSubtask.setDeptname(serviceTask.getDeptname());
        serviceSubtask.setLeavehospitaldistrictcode(serviceTask.getLeavehospitaldistrictcode());
        serviceSubtask.setLeavehospitaldistrictname(serviceTask.getLeavehospitaldistrictname());
        serviceSubtask.setTemplateid(serviceTask.getTemplateid());
        serviceSubtask.setTemplatename(serviceTask.getTemplatename());
        serviceSubtask.setPatid(patArchive.getId());
        serviceSubtask.setSendname(patArchive.getName());
        serviceSubtask.setSfzh(patArchive.getIdcardno());
        serviceSubtask.setPhone(patArchive.getTelcode());
        if (StringUtils.isBlank(patArchive.getTelcode())) serviceSubtask.setPhone(patArchive.getRelativetelcode());
        serviceSubtask.setSex(patArchive.getSex());
        serviceSubtask.setAge(patArchive.getAge());
        serviceSubtask.setSendstate(3L);
//        serviceSubtask.setManagementDoctor(patMedInhosp1.getManagementDoctor());
//        serviceSubtask.setManagementDoctorCode(patMedInhosp1.getManagementDoctorCode());
        serviceSubtask.setServiceType(serviceTask.getServiceType());
        serviceSubtask.setPreachform(serviceTask.getPreachform());
        serviceSubtask.setHospType("8");
        serviceSubtask.setCreateTime(new Date());
        serviceSubtask.setUpdateTime(new Date());
//        serviceSubtask.setCreateBy(patMedInhosp1.getNurseName());
//        serviceSubtask.setLeavehospitaldistrictcode(patMedInhosp1.getLeavehospitaldistrictcode());
//        serviceSubtask.setLeavehospitaldistrictname(patMedInhosp1.getLeavehospitaldistrictname());
        serviceSubtask.setUpdateBy(serviceTask.getUpdateBy());
        serviceSubtask.setUpdateTime(new Date());
        serviceTask.setSendDay(1L);
        Date newDate = new Date();
        serviceSubtask.setLongSendTime(newDate);
        serviceSubtask.setVisitTime(newDate);
        return serviceSubtask;
    }
}