陈昶聿
17 小时以前 05abe218f8efb25a88dc474ec447d9cc41ee23a9
ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java
@@ -13,10 +13,7 @@
import com.ruoyi.common.enums.ServiceFromEnum;
import com.ruoyi.common.enums.WxGZHEnum;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.HttpUtil;
import com.ruoyi.common.utils.OkHttpExample;
import com.ruoyi.common.utils.RSAPublicKeyExample;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.sign.Md5Utils;
import com.ruoyi.common.utils.sms.smsUtils;
@@ -393,15 +390,14 @@
                        serviceOutPath.setDeptName(serviceSubtask.getDeptname());
                        serviceOutPath.setWardName(serviceSubtask.getLeavehospitaldistrictname());
                        iServiceOutPathService.insertServiceOutPath(serviceOutPath);
                        String url = "";
                        String format = String.format("%03X", serviceOutPath.getId());
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                        //需要通过模板ID去判断要发的内容是宣教还是通知
                        HeLibrary heLibrary = heLibraryMapper.selectHeLibraryById(serviceSubtask.getLibtemplateid());
                        if (heLibrary.getHetype().equals("1")) {
                            sendMagParam.setPhone(serviceSubtask.getPhone());
                            sendMagParam.setUrl(StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/xj?p=" + format : ip + "/xj?p=" + format);
                            url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/xj?p=" + format : ip + "/xj?p=" + format;
                            sendMagParam.setUrl(url);
                            SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("xj.sms.template");
@@ -424,6 +420,10 @@
                            sendMagParam.setPhone(serviceSubtask.getPhone());
                            sendMagParam.setContent(sc);
                        }
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        serviceOutPath.setUrl(url);
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                    }
                    //短信还需要模板
@@ -601,8 +601,9 @@
                        String format = String.format("%03X", serviceOutPath.getId());
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                        url = ip + ":" + req_path + "/sf?p=" + format;
                        serviceOutPath.setUrl(url);
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                    } else if (type == 2) {
                        //问券
                        ServiceOutPath serviceOutPath = new ServiceOutPath();
@@ -618,13 +619,16 @@
                        serviceOutPath.setWardName(serviceSubtask.getLeavehospitaldistrictname());
                        iServiceOutPathService.insertServiceOutPath(serviceOutPath);
                        String format = String.format("%03X", serviceOutPath.getId());
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                        url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
                        //如果type是语音随访的话(说明补偿发送方式中有电话随访的方式,这里的外链就地址只能用/sf)
                        if (serviceSubtask.getType().equals("1"))
                            sendMagParam.setUrl(ip + ":" + req_path + "/sf?p=" + format);
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUrl(url);
                        serviceOutPath.setUpdateTime(new Date());
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                    } else if (type == 3) {
                        //宣教
                        ServiceOutPath serviceOutPath = new ServiceOutPath();
@@ -640,9 +644,6 @@
                        serviceOutPath.setOrgid(serviceSubtask.getOrgid());
                        iServiceOutPathService.insertServiceOutPath(serviceOutPath);
                        String format = String.format("%03X", serviceOutPath.getId());
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                        //需要通过模板ID去判断要发的内容是宣教还是通知
//                        HeLibrary heLibrary = heLibraryMapper.selectHeLibraryById(serviceSubtask.getLibtemplateid());
@@ -662,6 +663,10 @@
//                        }
                        url = ip + ":" + req_path + "/xj?p=" + format;
                        serviceOutPath.setRadix(format);
                        serviceOutPath.setUpdateTime(new Date());
                        serviceOutPath.setUrl(url);
                        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                    }
                    if (StringUtils.isEmpty(patArchive.getPatidHis())) {
                        serviceSubtask.setCurrentPreachform(sendPreachform);
@@ -937,7 +942,8 @@
            serviceSubtaskPreachform1.setRemark(remark);
            serviceSubtaskPreachformMapper.updateServiceSubtaskPreachform(serviceSubtaskPreachform1);
            //如果当前的preachform已经是最后一个了,并且本次还是发送失败,那直接将serviceSubtask的sendstate状态改成5就行了(全失败了)
            if (CollectionUtils.isNotEmpty(spSize) && serviceSubtaskPreachform1.getSort() == spSize.size()) {
            if (CollectionUtils.isNotEmpty(spSize) && serviceSubtaskPreachform1.getSort() == spSize.size()
                    && isSubtaskDeadline(serviceSubtask, serviceSubtaskPreachforms)) {
                if (serviceSubtaskPreachform1.getSort() == spSize.size()) {
                    if (failSendstate.equals("4") || failSendstate.equals("5")) {
                        serviceSubtask.setCurrentPreachform(preachform);
@@ -1089,4 +1095,35 @@
        }
        return toHex(md5.digest());
    }
    /**
     * 随访任务是否超时
     * @param serviceSubtask
     * @param serviceSubtaskPreachforms
     * @return
     */
    public boolean isSubtaskDeadline(ServiceSubtask serviceSubtask, List<ServiceSubtaskPreachform> serviceSubtaskPreachforms){
        if (ObjectUtils.isNotEmpty(serviceSubtask)) {
            //只有出院随访和专病随访有超时
            if(StringUtils.isNotEmpty(serviceSubtask.getServiceType()) &&
                    !serviceSubtask.getServiceType().equals("2") && !serviceSubtask.getServiceType().equals("13")){
                return true;
            }
        }
        if (Objects.isNull(serviceSubtask) || CollectionUtils.isEmpty(serviceSubtaskPreachforms)) {
            return false;
        }
        // 基准时刻:出院时间 + 发送日(sendDay 缺省按 1),并兜底避免 NPE/脏数据
        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()
                .mapToInt(x -> x.getCompensateTime() == null ? 0 : Integer.parseInt(x.getCompensateTime()))
                .sum();
        sumCompensateTime = sumCompensateTime + 1;
        // 只补偿最后一步自身的补偿时间(天),脏值一律按 0 兜底
        deadline = DateUtils.addDays(deadline, sumCompensateTime);
        // 出院(发送)时间 + 本步补偿时间 小于当前时间 -> 超时
        return deadline.getTime() < new Date().getTime();
    }
}