陈昶聿
6 天以前 9f9e9be084ea03f7b7eb301f2f6e201c6c2589d7
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -6,7 +6,6 @@
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;
@@ -18,7 +17,6 @@
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysConfigService;
import com.smartor.common.DeepSeekApi;
import com.smartor.common.FtpService;
import com.smartor.common.MtSubmitSmUtil;
import com.smartor.common.ScheduleSubtaskBuilder;
@@ -34,7 +32,6 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.annotations.Param;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -89,6 +86,8 @@
    @Autowired
    private IServiceTaskdeptService serviceTaskdeptService;
    @Autowired
    private IServiceTaskmedicalService serviceTaskmedicalService;
    @Autowired
    private IServiceTaskdiagService serviceTaskdiagService;
@@ -125,6 +124,9 @@
    @Autowired
    private IServiceTaskScheduleService serviceTaskScheduleService;
    @Autowired
    private IPatArchiveService patArchiveService;
    @Autowired
    private ScheduleSubtaskBuilder scheduleSubtaskBuilder;
@@ -410,7 +412,16 @@
            if (serviceSubtaskEntity.getSendstateView() == 3)
                serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(4L)));
        }
        //患者获取随访任务-需要查询同个患者(身份证)所有的任务 景宁
        if (StringUtils.isNotEmpty(serviceSubtaskEntity.getOrgid()) && serviceSubtaskEntity.getOrgid().equals("47255004333112711A1001")) {
            if(ObjectUtils.isNotEmpty(serviceSubtaskEntity.getPatid())){
                PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtaskEntity.getPatid());
                if(ObjectUtils.isNotEmpty(patArchive) && StringUtils.isNotEmpty(patArchive.getIdcardno())){
                    serviceSubtaskEntity.setPatid(null);
                    serviceSubtaskEntity.setSfzh(patArchive.getIdcardno());
                }
            }
        }
        List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskEntity);
        List<ServiceSubtaskRes> serviceSubtaskResList = new ArrayList<>();
@@ -591,9 +602,30 @@
     * @return 结果
     */
    @Override
    public int insertServiceSubtask(ServiceSubtask serviceSubtask) {
    public Map<String, Object> insertServiceSubtask(ServiceSubtask serviceSubtask) {
        serviceSubtask.setCreateTime(DateUtils.getNowDate());
        return serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
        serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
        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.setCreateTime(new Date());
        serviceOutPath.setParam6(subId);
        serviceOutPath.setOrgid(serviceSubtask.getOrgid());
        iServiceOutPathService.insertServiceOutPath(serviceOutPath);
        //转成16进制
        String format = String.format("%03X", serviceOutPath.getId());
        serviceOutPath.setRadix(format);
        serviceOutPath.setUpdateTime(new Date());
        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
        Map<String, Object> result = new HashMap<>();
        result.put("url", localIP + ":" + req_path + "/wt?p=" + format);
        result.put("subId",serviceSubtask.getId());
        return result;
    }
    /**
@@ -864,6 +896,36 @@
                    log.info("----serviceTaskSchedule的值为:{}", scheduleVO);
                    serviceTaskScheduleService.saveScheduleWithDetail(scheduleVO);
                } else if (serviceTaskVO.getAppltype().equals("6")) {
                    ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical();
                    serviceTaskmedical.setTaskId(serviceTask.getTaskid());
                    serviceTaskmedical.setTaskName(serviceTask.getTaskName());
                    serviceTaskmedical.setServiceType(serviceTaskVO.getServiceType());
                    serviceTaskmedical.setLongtask(Long.valueOf(serviceTask.getLongTask()));
                    if (serviceTaskVO.getLongTask() == 1) serviceTaskmedical.setLongtask(1L);
                    serviceTaskmedical.setMedicalCode(serviceTaskVO.getIcd10code());
                    serviceTaskmedical.setMedicalName(serviceTaskVO.getIcd10name());
                    serviceTaskmedical.setGuid(serviceTask.getGuid());
                    serviceTaskmedical.setOrgid(serviceTask.getOrgid());
                    serviceTaskmedical.setCreateTime(new Date());
                    serviceTaskmedical.setDeptCode(serviceTaskVO.getDeptcode());
                    serviceTaskmedical.setDeptName(serviceTaskVO.getDeptname());
                    serviceTaskmedical.setWardCode(serviceTaskVO.getLeavehospitaldistrictcode());
                    serviceTaskmedical.setWardName(serviceTaskVO.getLeavehospitaldistrictname());
                    //南华附一的icd10code是有重复的,所以不能用南华附一的icd10code去查询
                    log.info("----serviceTaskmedical的值为:{}", serviceTaskmedical);
                    if (!StringUtils.isEmpty(serviceTaskVO.getMedicalName())) {
                        String[] medicalNames = serviceTaskVO.getMedicalName().split(",");
                        String[] medicalcodes = serviceTaskVO.getMedicalCode().split(",");
                        String[] medicalCompanys = serviceTaskVO.getMedicalCompany().split(",");
                        for (int i = 0; i < medicalNames.length; i++) {
                            serviceTaskmedical.setMedicalCode(medicalNames[i]);
                            serviceTaskmedical.setMedicalName(medicalcodes[i]);
                            if (ObjectUtils.isNotEmpty(medicalCompanys))
                                serviceTaskmedical.setMedicalCompany(medicalcodes[i]);
                            serviceTaskmedicalService.insertServiceTaskmedical(serviceTaskmedical);
                        }
                    }
                } else {
                    ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
                    serviceTaskdept.setTaskId(serviceTask.getTaskid());
@@ -1133,6 +1195,51 @@
                                serviceTaskdiagService.updateServiceTaskdiag(serviceTaskdiag);
                            } else {
                                serviceTaskdiagService.insertServiceTaskdiag(serviceTaskdiag);
                            }
                        }
                    }
                } else if (serviceTaskVO.getAppltype().equals("6")) {
                    ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical();
                    serviceTaskmedical.setTaskId(serviceTask.getTaskid());
                    serviceTaskmedical.setTaskName(serviceTask.getTaskName());
                    if (StringUtils.isEmpty(serviceTaskVO.getIcd10code())) {
                        throw new BaseException("药品编码为空");
                    }
                    serviceTaskmedical.setLongtask(Long.valueOf(serviceTask.getLongTask()));
                    serviceTaskmedical.setMedicalName(serviceTaskVO.getMedicalName());
                    serviceTaskmedical.setGuid(serviceTask1.getGuid());
                    serviceTaskmedical.setServiceType(serviceTask1.getServiceType());
                    serviceTaskmedical.setOrgid(serviceTask1.getOrgid());
                    serviceTaskmedical.setDeptCode(serviceTask1.getDeptcode());
                    serviceTaskmedical.setDeptName(serviceTask1.getDeptname());
                    serviceTaskmedical.setWardCode(serviceTask1.getLeavehospitaldistrictcode());
                    serviceTaskmedical.setWardName(serviceTask1.getLeavehospitaldistrictname());
                    serviceTaskmedical.setUpdateTime(new Date());
                    if (StringUtils.isNotEmpty(serviceTaskVO.getMedicalCode())) {
                        String[] medicalCodes = serviceTaskVO.getMedicalCode().split(",");
                        String[] medicalNames = serviceTaskVO.getMedicalName().split(",");
                        String[] medicalCompany = serviceTaskVO.getMedicalCompany().split(",");
                        if (!active.equals("nhfy") && !active.equals("druid")) {
                            if (medicalCodes.length != medicalNames.length) {
                                throw new BaseException("药品编码和药品名称数量不一致");
                            }
                        }
                        for (int i = 0; i < medicalCodes.length; i++) {
                            //先查询一下是否存在
                            ServiceTaskmedical serviceTaskmedical1 = new ServiceTaskmedical();
                            serviceTaskmedical1.setTaskId(serviceTaskVO.getTaskid());
                            serviceTaskmedical1.setMedicalCode(medicalCodes[i]);
                            serviceTaskmedical1.setMedicalName(medicalNames[i]);
                            List<ServiceTaskmedical> serviceTaskmedicals = serviceTaskmedicalService.selectServiceTaskmedicalList(serviceTaskmedical1);
                            serviceTaskmedical.setMedicalCode(medicalCodes[i]);
                            serviceTaskmedical.setMedicalName(medicalNames[i]);
                            log.info("----serviceTaskmedical更新的值为:{}", serviceTaskmedical);
                            if (CollectionUtils.isNotEmpty(serviceTaskmedicals)) {
                                serviceTaskmedical.setId(serviceTaskmedicals.get(0).getId());
                                serviceTaskmedicalService.updateServiceTaskmedical(serviceTaskmedical);
                            } else {
                                serviceTaskmedicalService.insertServiceTaskmedical(serviceTaskmedical);
                            }
                        }
                    }
@@ -1815,20 +1922,16 @@
                //用来标记,是否有匹配上的
                Integer flag = 0;
                //1-AI识别
                SysConfig configVoiceMatchAi = new SysConfig();
                configVoiceMatchAi.setOrgid(phoneCallReqYQVO.getOrgid());
                configVoiceMatchAi.setConfigKey("sys.voice.match.ai");
                SysConfig matchAi = sysConfigMapper.selectConfig(configVoiceMatchAi);
                String url = configService.selectConfigByKey("sys.voice.match.ai.url",phoneCallReqYQVO.getOrgid());
//            if (ObjectUtils.isNotEmpty(matchAi) && StringUtils.isNotEmpty(matchAi.getConfigValue())
//                    && matchAi.getConfigValue().equals("1")) {
//                PhoneCallBackYQVO aiMatchResult = AiMatch(phoneCallReqYQVO, phoneCallBackYQVO,
//                        ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
//                        ivrTaskTemplateScripts, scriptId, flag);
//                if(aiMatchResult != null){
//                    return aiMatchResult;
//                }
//            } else {
            if (ObjectUtils.isNotEmpty(url)) {
                PhoneCallBackYQVO aiMatchResult = AiMatch(url, phoneCallReqYQVO, phoneCallBackYQVO,
                        ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
                        ivrTaskTemplateScripts, scriptId, flag, phoneCallReqYQVO.getUuid());
                if(aiMatchResult != null){
                    return aiMatchResult;
                }
            } else {
                //是选择题
                for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) {
                    log.error("phoneCallReqYQVO.getAsrtext()的值为:{}", phoneCallReqYQVO.getAsrtext());
@@ -2070,7 +2173,7 @@
                        continue;
                    }
                }
//            }
            }
                //都没有匹配到
                if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) {
                    log.info("都没有匹配到-------------------------");
@@ -2692,16 +2795,21 @@
    @Cacheable(value = "sfStatistics", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
    public List<ServiceSubtaskStatistic> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq) {
        log.info("getSfStatistics的入参为:{}", serviceSubtaskCountReq);
        String groupKey = "drcode";
        String drcode = "drcode";
        //缙云人民 根据经管医生分组
        if(serviceSubtaskCountReq.getOrgid().equals("47246116333112211A1001")){
            drcode = "management_doctor_code";
        }
        String groupKey = drcode;
        if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 1) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKey = "drcode";
                groupKey = drcode;
            } else {
                groupKey = "leavehospitaldistrictcode";
            }
        } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 2) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKey = "drcode";
                groupKey = drcode;
            } else {
                groupKey = "deptcode";
            }
@@ -2714,11 +2822,14 @@
        serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        switch (groupKey) {
            case "deptcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                break;
            case "drcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                break;
            case "management_doctor_code":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getManagementDoctorCode()).orElse("Unknown")));
                break;
            case "deptcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                break;
            case "leavehospitaldistrictcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
@@ -5056,16 +5167,16 @@
     * @param options
     * @return
     */
    public Integer matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options){
    public Integer matchOptionIndex(String url, String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options, String uuid){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userQuestion",questionText);
        jsonObject.put("userAnswer",voiceText);
        jsonObject.put("options", options);
        jsonObject.put("uuid", uuid);
        String jsonString = jsonObject.toJSONString();
        String result = null;
        String url = "http://localhost:8099/matchOptionIndex";
//        String url = configService.selectConfigByKey("sys.voice.match.ai.url");
//        String url = "http://localhost:8099/matchOptionIndex";
        if(StringUtils.isNotEmpty(url)){
            try {
                Map<String, String> headers = new HashMap<>();
@@ -5083,15 +5194,15 @@
        }
    }
    public PhoneCallBackYQVO AiMatch(PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
    public PhoneCallBackYQVO AiMatch(String url, PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
                        IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate,
                        List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag){
                        List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag, String uuid){
        PhoneCallBackYQVO back = null;
        List<IvrTaskTemplateTargetoption> options = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList();
        String voiceText = phoneCallReqYQVO.getAsrtext();
        String questionText = StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent();
        Integer matched = -1;
        matched = matchOptionIndex(questionText, voiceText, options);
        matched = matchOptionIndex(url, questionText, voiceText, options, uuid);
        //说明匹配正确了
        if(matched != null && matched >= 0){
            IvrTaskTemplateTargetoption chosenOption = options.get(matched);
@@ -5327,8 +5438,9 @@
        IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption3 = new IvrTaskTemplateTargetoption();
        ivrTaskTemplateTargetoption3.setTargetvalue("其他");
        options.add(ivrTaskTemplateTargetoption3);
        Integer matched = matchOptionIndex(questionText,voiceText,options);
        //1-AI识别
        String url = configService.selectConfigByKey("sys.voice.match.ai.url");
        Integer matched = matchOptionIndex(url, questionText,voiceText,options,"1");
        if(ObjectUtils.isNotEmpty(matched)){
            if(matched >= 0){
                matchedText = options.get(matched).getTargetvalue();