| | |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.message.sms.provider.sltd.ws.MessageSend; |
| | | import com.smartor.common.QwenLLMUtil; |
| | | import com.smartor.common.SpecificArchiveConstants; |
| | | import com.smartor.domain.*; |
| | | import com.ruoyi.task.domain.VO.ServiceSubtaskDetailTraceVO; |
| | | import com.smartor.mapper.*; |
| | |
| | | import com.ruoyi.task.domain.ServiceSubtask; |
| | | import com.ruoyi.task.domain.ServiceSubtaskRecord; |
| | | import com.ruoyi.task.domain.ServiceTask; |
| | | import com.ruoyi.task.domain.ServiceTaskSchedule; |
| | | import com.ruoyi.task.domain.ServiceTaskScheduleDetail; |
| | | import com.ruoyi.task.mapper.ServiceSubtaskMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskScheduleMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskScheduleDetailMapper; |
| | | import com.ruoyi.task.domain.ServiceSubtaskDetailTrace; |
| | | import com.ruoyi.task.domain.VO.ServiceSubtaskDetailTraceVO; |
| | | import com.ruoyi.task.service.IServiceSubtaskDetailTraceService; |
| | |
| | | |
| | | @Autowired |
| | | private ServiceSubtaskMapper serviceSubtaskMapper; |
| | | |
| | | @Autowired |
| | | private ServiceTaskScheduleMapper serviceTaskScheduleMapper; |
| | | |
| | | @Autowired |
| | | private ServiceTaskScheduleDetailMapper serviceTaskScheduleDetailMapper; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | |
| | | 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()) { |
| | | // 方案B:只处理当前子任务——公众号已领取(service_subtask.sendstate=1 + current_preachform=5) |
| | | // 且未填写时,按默认选项完成,避免进入下一种发送方式或最后一步超时。 |
| | | // 先用内存字段快速过滤,其他医院/任务/发送方式不会进入下面的默认完成逻辑。 |
| | | if (IServiceSubtaskService.WECHAT_DEFAULT_COMPLETE_ORGID.equals(serviceSubtask.getOrgid()) |
| | | && "2".equals(serviceSubtask.getType()) |
| | | && "5".equals(serviceSubtask.getCurrentPreachform()) |
| | | && Long.valueOf(1L).equals(serviceSubtask.getSendstate()) |
| | | && !Long.valueOf(1L).equals(serviceSubtask.getSubmit())) { |
| | | try { |
| | | if (iServiceSubtaskService.completeWechatClaimedByDefault(serviceSubtask)) { |
| | | log.info("【compensateTask】subid:{},微信公众号已领取未填写,按默认选项完成", serviceSubtask.getId()); |
| | | continue; |
| | | } |
| | | } catch (Exception e) { |
| | | // 单个子任务失败不影响其他任务,回滚后继续原补偿流程 |
| | | log.error("【compensateTask】微信公众号默认完成失败,subid:{},继续原补偿流程", serviceSubtask.getId(), e); |
| | | } |
| | | } |
| | | |
| | | //1先检查一下,是不是有执行状态是完成的(怕之前已经有完的了,没有将servuce_subtask的状态改成功,这里再检查一下) |
| | | boolean finishState = serviceSubtaskPreachforms.stream().allMatch(item -> item.getSendstate().equals("9")); |
| | | if (finishState) { |
| | |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String url = ""; |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | String format = ShortCode.encode(serviceOutPath.getId()); |
| | | //先判断一下发的是不是宣教 |
| | | log.info("serviceSubtask.getType的值为:{}", serviceSubtask.getType()); |
| | | if (!"3".equals(serviceSubtask.getType())) { |
| | |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | String format = ShortCode.encode(serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | serviceOutPath.setUrl(url); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 采集丽水市妇幼保健院门诊接诊完成记录,并按配置生成妇科/儿科档案。 |
| | | * 定时任务默认采集昨天 00:00:00 ~ 今天 00:00:00。 |
| | | */ |
| | | public void collectMchArchive() { |
| | | try { |
| | | LocalDateTime todayZero = LocalDateTime.now().with(LocalTime.MIN); |
| | | LocalDateTime yesterdayZero = todayZero.minusDays(1); |
| | | Date startTime = Date.from(yesterdayZero.atZone(ZoneId.systemDefault()).toInstant()); |
| | | Date endTime = Date.from(todayZero.atZone(ZoneId.systemDefault()).toInstant()); |
| | | log.info("【collectMchArchive】开始采集丽水妇幼门诊接诊完成记录"); |
| | | ichService.collectMchOuthospAndGenerateArchive( |
| | | SpecificArchiveConstants.LISHUI_MCH_ORG_ID, startTime, endTime); |
| | | log.info("【collectMchArchive】丽水妇幼门诊接诊完成记录采集结束"); |
| | | } catch (Exception e) { |
| | | log.error("【collectMchArchive】丽水妇幼门诊接诊完成记录采集异常", e); |
| | | } |
| | | } |
| | | |
| | | public void collectHISYesterday() { |
| | | try { |
| | | // 获取昨天0点到今天0点的时间范围 |
| | |
| | | if (Objects.isNull(serviceSubtask) || CollectionUtils.isEmpty(serviceSubtaskPreachforms)) { |
| | | return false; |
| | | } |
| | | // 基准时刻:出院时间 + 发送日(sendDay 缺省按 1),并兜底避免 NPE/脏数据 |
| | | if (serviceSubtask.getEndtime() == null) { |
| | | log.warn("【isSubtaskDeadline】subid:{} endtime为空,无法计算超时,按未超时处理", serviceSubtask.getId()); |
| | | return false; |
| | | } |
| | | ServiceTask serviceTask = serviceTaskMapper.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | int sendDay = serviceTask != null && serviceTask.getSendDay() != null ? serviceTask.getSendDay().intValue() : 1; |
| | | Date deadline = DateUtils.addDays(serviceSubtask.getEndtime(), sendDay); |
| | | int sumCompensateTime = CollectionUtils.isEmpty(serviceSubtaskPreachforms) ? 0 : serviceSubtaskPreachforms.stream() |
| | | Date deadline; |
| | | if (serviceTask != null && "5".equals(serviceTask.getAppltype())) { |
| | | // 任务组:基准 = schedule_benchmark 解析出的时间 + day_offset,不叠加 send_day |
| | | deadline = resolveTaskGroupDeadlineBase(serviceSubtask); |
| | | if (deadline == null) { |
| | | log.warn("【isSubtaskDeadline】subid:{} 任务组基准时间为空,无法计算超时,按未超时处理", serviceSubtask.getId()); |
| | | return false; |
| | | } |
| | | } else { |
| | | // 非任务组:基准 = 出院时间 + 发送日(sendDay 缺省按 1) |
| | | if (serviceSubtask.getEndtime() == null) { |
| | | log.warn("【isSubtaskDeadline】subid:{} endtime为空,无法计算超时,按未超时处理", serviceSubtask.getId()); |
| | | return false; |
| | | } |
| | | int sendDay = serviceTask != null && serviceTask.getSendDay() != null ? serviceTask.getSendDay().intValue() : 1; |
| | | deadline = DateUtils.addDays(serviceSubtask.getEndtime(), sendDay); |
| | | } |
| | | int sumCompensateTime = serviceSubtaskPreachforms.stream() |
| | | .mapToInt(x -> NumberUtils.toInt(x.getCompensateTime(), 0)) |
| | | .sum(); |
| | | sumCompensateTime = sumCompensateTime + 1; |
| | | // 只补偿最后一步自身的补偿时间(天),脏值一律按 0 兜底 |
| | | // 补偿时间脏值一律按 0 兜底,最后再加 1 天宽限 |
| | | deadline = DateUtils.addDays(deadline, sumCompensateTime); |
| | | // 出院(发送)时间 + 本步补偿时间 小于当前时间 -> 超时 |
| | | return deadline.getTime() < new Date().getTime(); |
| | | } |
| | | |
| | | /** |
| | | * 任务组基准时间:按 schedule_benchmark 解析后加 day_offset。 |
| | | * 0/其它-自定义时间 1-入院 2-出院 3-就诊 4-入组 |
| | | */ |
| | | private Date resolveTaskGroupDeadlineBase(ServiceSubtask serviceSubtask) { |
| | | if (serviceSubtask.getScheduleId() == null || serviceSubtask.getScheduleDetailId() == null) { |
| | | return null; |
| | | } |
| | | ServiceTaskSchedule schedule = serviceTaskScheduleMapper.selectServiceTaskScheduleById(serviceSubtask.getScheduleId()); |
| | | ServiceTaskScheduleDetail detail = serviceTaskScheduleDetailMapper.selectServiceTaskScheduleDetailById(serviceSubtask.getScheduleDetailId()); |
| | | if (schedule == null || detail == null || detail.getDayOffset() == null) { |
| | | return null; |
| | | } |
| | | Date base; |
| | | Integer benchmark = schedule.getScheduleBenchmark() == null ? 0 : schedule.getScheduleBenchmark(); |
| | | switch (benchmark) { |
| | | case 1: |
| | | base = serviceSubtask.getStarttime(); |
| | | break; |
| | | case 2: |
| | | base = serviceSubtask.getEndtime(); |
| | | break; |
| | | case 3: |
| | | base = serviceSubtask.getAdmindate(); |
| | | break; |
| | | case 4: |
| | | base = serviceSubtask.getCreateTime(); |
| | | break; |
| | | default: |
| | | base = schedule.getScheduleBenchmarkCustomTime(); |
| | | break; |
| | | } |
| | | return base == null ? null : DateUtils.addDays(base, detail.getDayOffset()); |
| | | } |
| | | |
| | | /** |
| | | * 处理超时随访任务(随访超时 → 生成"再次随访") |
| | | * <p> |
| | | * 扫描「出院满 deadlineDay 天仍未完成」的首次随访任务(sendstate=7 + visit_count=1), |