smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -1,6 +1,7 @@
package com.smartor.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -12,6 +13,7 @@
import com.smartor.common.FtpService;
import com.smartor.config.PhoneUtils;
import com.smartor.domain.*;
import com.smartor.domain.VO.ServiceSubtaskCotinueCountVO;
import com.smartor.domain.entity.ServiceSubtaskEntity;
import com.smartor.mapper.*;
import com.smartor.service.*;
@@ -410,18 +412,18 @@
        // 处理空异常
        if (MapUtils.isEmpty(result)) {
            result = new HashMap<>();
            // 确保所有 key 都有值,避免空指针异常
            // MyBatis 的 SUM 在没有匹配行时会返回 null
            result.putIfAbsent("wzx", 0);
            result.putIfAbsent("ysf", 0);
            result.putIfAbsent("yc", 0);
            result.putIfAbsent("jg", 0);
            result.putIfAbsent("fssb", 0);
            result.putIfAbsent("yfs", 0);
            result.putIfAbsent("blq", 0);
            result.putIfAbsent("dsf", 0);
            result.putIfAbsent("total", 0);
        }
        // 确保所有 key 都有值,避免空指针异常
        // MyBatis 的 SUM 在没有匹配行时会返回 null
        result.putIfAbsent("wzx", 0);
        result.putIfAbsent("ysf", 0);
        result.putIfAbsent("yc", 0);
        result.putIfAbsent("jg", 0);
        result.putIfAbsent("fssb", 0);
        result.putIfAbsent("yfs", 0);
        result.putIfAbsent("blq", 0);
        result.putIfAbsent("dsf", 0);
        return result;
    }
@@ -576,14 +578,14 @@
            if (StringUtils.isNotEmpty(serviceTaskVO.getLibtemplateid())) {
                serviceTask.setLibtemplateid(serviceTaskVO.getLibtemplateid());
                serviceTask.setLibtemplatename(serviceTaskVO.getLibtemplatename());
            }else {
            } else {
                if (ObjectUtils.isNotEmpty(serviceTaskVO.getSvyTaskTemplateVO())) {
                    serviceTask.setLibtemplateid(""+serviceTaskVO.getSvyTaskTemplateVO().getTemplateid());
                    serviceTask.setLibtemplatename(""+serviceTaskVO.getLibtemplatename());
                    serviceTask.setLibtemplateid("" + serviceTaskVO.getSvyTaskTemplateVO().getTemplateid());
                    serviceTask.setLibtemplatename("" + serviceTaskVO.getLibtemplatename());
                }
                if (ObjectUtils.isNotEmpty(serviceTaskVO.getIvrTaskTemplateVO())) {
                    serviceTask.setLibtemplateid(""+serviceTaskVO.getIvrTaskTemplateVO().getLibtemplateid());
                    serviceTask.setLibtemplatename(""+serviceTaskVO.getIvrTaskTemplateVO().getLibtemplatename());
                    serviceTask.setLibtemplateid("" + serviceTaskVO.getIvrTaskTemplateVO().getLibtemplateid());
                    serviceTask.setLibtemplatename("" + serviceTaskVO.getIvrTaskTemplateVO().getLibtemplatename());
                }
            }
            if (serviceTaskVO.getTemplateid() != null) {
@@ -1591,7 +1593,12 @@
                            subtaskDetailTrace.setAsrtext(phoneCallReqYQVO.getAsrtext());
                            subtaskDetailTrace.setRecordpath(phoneCallReqYQVO.getRecordpath());
                            subtaskDetailTrace.setPatid(serviceSubtask.getPatid());
                            subtaskDetailTrace.setPatdesc(serviceSubtask.getSendname() + "," + serviceSubtask.getPhone() + "," + serviceSubtask.getDeptname());
                            JSONObject patdescJson = new JSONObject();
                            patdescJson.put("sendname", serviceSubtask.getSendname());
                            patdescJson.put("phone", serviceSubtask.getPhone());
                            patdescJson.put("age", serviceSubtask.getAge());
                            patdescJson.put("sex", serviceSubtask.getSex() != null ? serviceSubtask.getSex() == 1 ? "男" : "女" : null);
                            subtaskDetailTrace.setPatdesc(patdescJson.toJSONString());
                            subtaskDetailTrace.setTodeptcode(ivrTaskTemplateScriptVO.getDutyDeptCode());
                            subtaskDetailTrace.setTodeptname(ivrTaskTemplateScriptVO.getDutyDeptName());
                            subtaskDetailTrace.setOrgid(serviceSubtask.getOrgid());
@@ -1976,7 +1983,7 @@
//        if (existSize > 0) return pullTaskVOList;
        int count = 0;
        long size = listOps.size("cache-0");
        log.error("---------打电话之前缓存中的数据量:{}", size);
        log.info("---------打电话之前缓存中的数据量:{}", size);
        if (size > 0) {
            //phoneCount()  通过给出的每个小时需要打出的电话量,算出到晚上8点一点能打出多少个电话,获取到总量
            //如果需要立即执行的数据量大于一天要执行的上限,则只取上限的数量,其它的则放回redis中
@@ -2025,7 +2032,7 @@
            }
        }
//        if (existList.size() != 0) redisCache.setCacheListRight("cache-exist", existList);
        log.error("-----------实际拉取的电话数据量:{}", CollectionUtils.isNotEmpty(pullTaskVOList) ? pullTaskVOList.size() : null);
        log.info("-----------实际拉取的电话数据量:{}", CollectionUtils.isNotEmpty(pullTaskVOList) ? pullTaskVOList.size() : null);
        return pullTaskVOList;
    }
@@ -2659,9 +2666,9 @@
        if (visitCount != null && visitCount > 1) {
            serviceSubtaskStatistic = getStatisticAgain(serviceSubtaskList, followUpCountStyle);
        }else if(visitCount != null && visitCount == 1){
        } else if (visitCount != null && visitCount == 1) {
            serviceSubtaskStatistic = getStatisticFirst(serviceSubtaskList, followUpCountStyle);
        }else {
        } else {
            //格式化为两位小数的百分比
            DecimalFormat percentFormat = new DecimalFormat("##.##%");
            serviceSubtaskStatistic.setDeptname(serviceSubtaskList.get(0).getDeptname());
@@ -2921,6 +2928,7 @@
    /**
     * 首次随访统计
     *
     * @param serviceSubtaskList
     * @param followUpCountStyle
     * @return
@@ -3082,6 +3090,7 @@
    /**
     * 再次随访统计
     *
     * @param serviceSubtaskList
     * @param followUpCountStyle
     * @return
@@ -3839,7 +3848,7 @@
            if (serviceSubtaskPreachform1.getSort() == spSize.size() && failSendstate.equals("4")) {
                serviceSubtask.setCurrentPreachform(preachform);
                serviceSubtask.setSendstate(5L);
                serviceSubtask.setRemark("setFailPreachForm方法 当前的preachform已经是最后一个了,全失败了");
                serviceSubtask.setRemark("所有发送方式均未获取结果,任务失败");
                serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                return true;
            }
@@ -4009,4 +4018,65 @@
    public Map<String, Object> getCurrentUserServiceSubtaskCount(ServiceSubtaskEntity entity) {
        return serviceSubtaskMapper.getCurrentUserServiceSubtaskCount(entity);
    }
    @Override
    public Map<String, Object> getContinueNurseCount(ServiceSubtaskCotinueCountVO vo) {
        boolean hasDistrict = !CollectionUtils.isEmpty(vo.getLeavehospitaldistrictcodes());
        boolean hasDept = !CollectionUtils.isEmpty(vo.getDeptcodes());
        List<Map<String, Object>> districtRows;
        List<Map<String, Object>> deptRows;
        if (hasDistrict) {
            // 只传了病区:仅按病区维度统计
            districtRows = serviceSubtaskMapper.getContinueNurseCount(vo);
            deptRows = Collections.emptyList();
        } else if (hasDept) {
            // 只传了科室:仅按科室维度统计
            districtRows = Collections.emptyList();
            deptRows = serviceSubtaskMapper.getContinueNurseCountByDept(vo);
        } else {
            // 都未传:病区和科室各统计一遍
            districtRows = serviceSubtaskMapper.getContinueNurseCount(vo);
            deptRows = serviceSubtaskMapper.getContinueNurseCountByDept(vo);
        }
        long totalNoContinue = 0L;
        long totalContinue = 0L;
        List<Map<String, Object>> detail = new ArrayList<>();
        for (Map<String, Object> row : districtRows) {
            String groupName = row.get("groupName") == null
                    ? (row.get("groupCode") == null ? "" : row.get("groupCode").toString())
                    : row.get("groupName").toString();
            long noCnt = row.get("noContinueCnt") == null ? 0L : Long.parseLong(row.get("noContinueCnt").toString());
            long yesCnt = row.get("continueCnt") == null ? 0L : Long.parseLong(row.get("continueCnt").toString());
            totalNoContinue += noCnt;
            totalContinue += yesCnt;
            Map<String, Object> item = new LinkedHashMap<>();
            item.put("未延续_" + groupName, noCnt);
            item.put("已延续_"+groupName, yesCnt);
            detail.add(item);
        }
        for (Map<String, Object> row : deptRows) {
            String groupName = row.get("groupName") == null
                    ? (row.get("groupCode") == null ? "" : row.get("groupCode").toString())
                    : row.get("groupName").toString();
            long noCnt = row.get("noContinueCnt") == null ? 0L : Long.parseLong(row.get("noContinueCnt").toString());
            long yesCnt = row.get("continueCnt") == null ? 0L : Long.parseLong(row.get("continueCnt").toString());
            totalNoContinue += noCnt;
            totalContinue += yesCnt;
            Map<String, Object> item = new LinkedHashMap<>();
            item.put("未延续_" + groupName, noCnt);
            item.put("已延续_" + groupName, yesCnt);
            detail.add(item);
        }
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("未延续总数量", totalNoContinue);
        result.put("已延续总数量", totalContinue);
        result.put("详情", detail);
        return result;
    }
}