| | |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.smartor.common.LSHospTokenUtil; |
| | | import com.smartor.common.MtSubmitSmUtil; |
| | | import com.smartor.common.QwenLLMUtil; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.domain.entity.ServiceSubtaskEntity; |
| | | import com.smartor.mapper.*; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | |
| | | private String active; |
| | | @Autowired |
| | | private SysConfigMapper sysConfigMapper; |
| | | |
| | | @Autowired |
| | | private IServiceTaskScheduleService serviceTaskScheduleService; |
| | | |
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { |
| | | System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 处理患者信息,进入子任务表 |
| | | * 处理患者信息,进入子任务表(任务组) |
| | | */ |
| | | public void dealOutHospInfoByDimension() { |
| | | public void dealOutHospInfoBySchedule() { |
| | | String config = configService.selectConfigByKey("visit.early.day"); |
| | | if (port.equals("8095")) { |
| | | //出院表 |
| | | iPatMedInhospService.dealOutHospInfoByDimension(config); |
| | | iPatMedInhospService.dealOutHospInfoBySchedule(config); |
| | | //门诊表(新华的暂时不做门诊随访) |
| | | if (!active.equals("xh")) { |
| | | //iPatMedOuthospService.dealOutpatientInfo(); |
| | | } |
| | | // if (!active.equals("xh")) { |
| | | // //iPatMedOuthospService.dealOutpatientInfo(); |
| | | // } |
| | | } |
| | | } |
| | | |
| | |
| | | //获取到sendstate=3 并且 visit_time为小于等于今天的subtask |
| | | ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity(); |
| | | serviceSubtaskVO.setSendstate(3L); |
| | | serviceSubtaskVO.setVisitTime(new Date()); |
| | | List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.getCompensateServiceSubtaskList(serviceSubtaskVO); |
| | | for (ServiceSubtask serviceSubtask : serviceSubtaskList) { |
| | | //根据当前的执行方式,获取下一种执行方式 |
| | | ServiceSubtaskPreachform serviceSubtaskPreachform = new ServiceSubtaskPreachform(); |
| | | serviceSubtaskPreachform.setTaskid(serviceSubtask.getTaskid()); |
| | | serviceSubtaskPreachform.setSubid(serviceSubtask.getId()); |
| | | serviceSubtaskPreachform.setOrgid(serviceSubtask.getOrgid()); |
| | | List<ServiceSubtaskPreachform> serviceSubtaskPreachforms = serviceSubtaskPreachformMapper.selectServiceSubtaskPreachformList(serviceSubtaskPreachform); |
| | | //获取当前执行方式的序号 |
| | | Optional<Long> currentSort = serviceSubtaskPreachforms.stream().filter(item -> serviceSubtask.getCurrentPreachform().equals(item.getPreachform())).map(ServiceSubtaskPreachform::getSort).findFirst(); |
| | | Optional<Long> id = serviceSubtaskPreachforms.stream().filter(item -> serviceSubtask.getCurrentPreachform().equals(item.getPreachform())).map(ServiceSubtaskPreachform::getId).findFirst(); |
| | | if (currentSort.isPresent()) { |
| | | //1先检查一下,是不是有执行状态是完成的(怕之前已经有完的了,没有将servuce_subtask的状态改成功,这里再检查一下) |
| | | boolean finishState = serviceSubtaskPreachforms.stream().allMatch(item -> item.getSendstate().equals("9")); |
| | | if (finishState) { |
| | | serviceSubtask.setSendstate(6L); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | continue; |
| | | } |
| | | |
| | | //2判断一下,当前的sort是不是等于需要执行的总个数,如果等于的话,说明是最后一个,直接将servuce_subtask的状态改成5,执行失败就行了 |
| | | Long cs = currentSort.get(); |
| | | if (cs.equals(serviceSubtaskPreachforms.size())) { |
| | | serviceSubtask.setSendstate(7L); |
| | | serviceSubtask.setRemark("处理补偿任务,当前处理最后补偿,全部执行失败(超时)"); |
| | | |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | //修改发送方式的状态为失败 |
| | | serviceSubtaskPreachform.setSendstate("5"); |
| | | serviceSubtaskPreachform.setId(id.get()); |
| | | |
| | | serviceSubtaskPreachformMapper.updateServiceSubtaskPreachform(serviceSubtaskPreachform); |
| | | continue; |
| | | } |
| | | |
| | | //3.不是最后一个,获取到下一个执行方式(因为都是在今天执行,那就直接发出去就完了) |
| | | sfHandlle(serviceSubtask); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 长期任务发送 |
| | | */ |
| | | public void longTaskSendTest(Long subId) { |
| | | //获取任务信息 |
| | | ServiceTask st = new ServiceTask(); |
| | | st.setDelFlag("0"); |
| | | st.setLongTask(1); |
| | | List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st); |
| | | log.info("【longTaskSend】获取到{}个长期任务", serviceTasks.size()); |
| | | for (ServiceTask serviceTask : serviceTasks) { |
| | | CommonTaskcallMQ commonTaskcallMQ = new CommonTaskcallMQ(); |
| | | commonTaskcallMQ.setTaskid(serviceTask.getTaskid()); |
| | | commonTaskcallMQ.setPreachform(serviceTask.getPreachform()); |
| | | commonTaskcallMQ.setSendType("2"); |
| | | |
| | | //通过任务ID拿到患者信息,并且随访时间得是今天之前的 |
| | | ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity(); |
| | | serviceSubtaskVO.setTaskid(commonTaskcallMQ.getTaskid()); |
| | | serviceSubtaskVO.setSendstate(2L); |
| | | serviceSubtaskVO.setIsVisitAgain(1); |
| | | serviceSubtaskVO.setSubId(subId); |
| | | serviceSubtaskVO.setVisitTime(new Date()); |
| | | List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.queryServiceSubtaskList(serviceSubtaskVO); |
| | | for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | | sfHandlle(serviceSubtask); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理补偿任务 |
| | | */ |
| | | public void compensateTaskTest(Long subId) { |
| | | //获取到sendstate=3 并且 visit_time为小于等于今天的subtask |
| | | ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity(); |
| | | serviceSubtaskVO.setSendstate(3L); |
| | | serviceSubtaskVO.setSubId(subId); |
| | | serviceSubtaskVO.setVisitTime(new Date()); |
| | | List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.getCompensateServiceSubtaskList(serviceSubtaskVO); |
| | | for (ServiceSubtask serviceSubtask : serviceSubtaskList) { |
| | |
| | | serviceOutPath.setParam3(ivrTask1.getTaskName()); |
| | | serviceOutPath.setParam6(subId); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | |
| | | if (serviceSubtask.getType().equals("1")) |
| | | sendMagParam.setUrl(StringUtils.isNotEmpty(req_path) ? localIP + ":" + req_path + "/sf?p=" + format : localIP + "/sf?p=" + format); |
| | | |
| | | SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("wj.sms.template"); |
| | | // SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("wj.sms.template"); |
| | | SysConfig sysConfig = new SysConfig(); |
| | | if (StringUtils.isNotEmpty(serviceSubtask.getServiceType()) && serviceSubtask.getServiceType().equals("6")) { |
| | | sysConfig = sysConfigMapper.checkConfigKeyUnique("zymyd.sms.template"); |
| | | }else if (StringUtils.isNotEmpty(serviceSubtask.getServiceType()) && serviceSubtask.getServiceType().equals("14")) { |
| | | sysConfig = sysConfigMapper.checkConfigKeyUnique("mzmyd.sms.template"); |
| | | }else { |
| | | sysConfig = sysConfigMapper.checkConfigKeyUnique("wj.sms.template"); |
| | | } |
| | | if (!Objects.isNull(sysConfig)) { |
| | | String smsContemt = sysConfig.getConfigValue(); |
| | | // sendMagParam.setContent("您好,邀请您填写出院调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); |
| | |
| | | //任务发送记录 |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | |
| | | if (active.equals("hzszlyy")) { |
| | | //处理中文乱码问题 |
| | | wxCode = smsUtils.sendChat(url, patArchive.getTelcode(), serviceSubtask.getSfzh()); |
| | | log.info(wxCode); |
| | | |
| | | } else { |
| | | wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), patArchive.getTelcode(), serviceSubtask.getSendname(), patArchive.getPatidHis(), wxqqxx); |
| | | } |
| | |
| | | Map<String, String> headerMap = new HashMap<>(); |
| | | headerMap.put("sign", encode); |
| | | String result = HttpUtils.sendPostByHeader(wxqqxx.get(3), body, headerMap); |
| | | |
| | | log.info("【getWXCode】微信公众号返回参数:{}", result); |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | String code = (String) jsonObject.toString(); |
| | | return code; |
| | |
| | | //serviceSubtask.setRemark("setSuccessPreachForm方法,当前的preachform已经是最后一个了,全部执行失败"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | return true; |
| | | |
| | | } |
| | | |
| | | } |
| | | } else { |
| | | log.error("【定时任务中该患者没有查询到属于他的发送方式,subid:{},prechform:{},orgid:{}】", serviceSubtask.getId(), preachform, serviceSubtask.getOrgid()); |
| | |
| | | return serviceTaskMap; |
| | | } |
| | | |
| | | public int qwenLLMTest(String questionText, String voiceText,String value,String regexText) { |
| | | int result = QwenLLMUtil.matchRegex(questionText, voiceText, value, regexText); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 任务组(appltype=5)首轮纳入:扫描新出院患者,按 schedule 绑定的维度匹配任务组, |
| | | * 为命中的患者按计划明细一次性生成第 0 轮 N 条 subtask,并置 schedulecheck_flag=1。 |
| | | * 后续轮次由 {@link #rollTaskGroupCycle()} 负责。 |
| | | * <p> |
| | | * 与主扫描 dealOutHospInfo 分离,互不干扰。建议每 30 分钟执行一次。 |
| | | */ |
| | | public void dealTaskGroupOutHosp() { |
| | | log.info("【dealTaskGroupOutHosp】开始扫描任务组新出院患者"); |
| | | if (!port.equals("8095")) { |
| | | return; |
| | | } |
| | | try { |
| | | String config = configService.selectConfigByKey("visit.early.day"); |
| | | iPatMedInhospService.dealOutHospInfoBySchedule(config); |
| | | log.info("【dealTaskGroupOutHosp】任务组首轮纳入扫描完成"); |
| | | } catch (Exception e) { |
| | | log.error("【dealTaskGroupOutHosp】任务组扫描异常", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 任务组(appltype=5)循环任务滚动调度。 |
| | | * <p> |
| | | * 扫描所有 schedule_style=1 的计划,若本轮 subtask 全部 finalize(sendstate ∉ 1/2/3), |
| | | * 则克隆本轮患者到下一轮,推进 current_loop_count 与 visit_time。 |
| | | * <p> |
| | | * 建议每小时或每半小时执行一次,避免轮次积压。 |
| | | */ |
| | | public void rollTaskGroupCycle() { |
| | | log.info("【rollTaskGroupCycle】开始扫描循环任务组"); |
| | | try { |
| | | int rolled = serviceTaskScheduleService.rollCycleTasks(); |
| | | log.info("【rollTaskGroupCycle】本次推进 {} 个计划", rolled); |
| | | } catch (Exception e) { |
| | | log.error("【rollTaskGroupCycle】滚动调度异常", e); |
| | | } |
| | | } |
| | | } |