陈昶聿
2026-01-22 9b96619ab91dce35b606faa3f4e0468ec702fd69
【丽水】getSfStatisticsScript 优化
已修改2个文件
131 ■■■■■ 文件已修改
smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java
@@ -93,6 +93,12 @@
    private String scriptids;
    /**
     * 分组类型 drCode, deptCode, leaveHospitalDistrictCode
     */
    @ApiModelProperty(value = "分组类型")
    private String groupKeyType;
    /**
     * pageNum
     */
    @ApiModelProperty("pageNum")
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2228,6 +2228,7 @@
    @Override
    @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) {
        //todo
        log.info("getSfStatistics的入参为:{}", serviceSubtaskCountReq);
        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
@@ -2236,7 +2237,6 @@
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        String groupKeyType = "";
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKeyType = "drCode";
@@ -2254,7 +2254,50 @@
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
            }
        }
        serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
        //获取及时率统计合集
        Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
        for (String collectKey : collect.keySet()) {
            List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
            if (CollectionUtils.isEmpty(serviceSubtaskList)) {
                continue;
            }
            ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList);
            if(ObjectUtils.isNotEmpty(jsRates)){
                Map<String, Object> jsRateMap = jsRates.get(collectKey);
                BigDecimal jsRate = new BigDecimal("0");
                if(ObjectUtils.isNotEmpty(jsRateMap) && ObjectUtils.isNotEmpty(jsRateMap.get("rate"))){
                    jsRate = new BigDecimal(jsRateMap.get("rate").toString());
                }
                Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
                statistic.setRate(jsRateDouble);
            }
            if (ObjectUtils.isNotEmpty(statistic)) {
                serviceSubtaskStatistics.add(statistic);
            }
        }
        return serviceSubtaskStatistics;
    }
    /**
     * 随访统计-及时率统计
     * @param serviceSubtaskCountReq
     * @param collect
     * @return
     */
    public  Map<String, Map<String, Object>> getSsRateForSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq, Map<String, List<ServiceSubtask>> collect){
        if(ObjectUtils.isEmpty(serviceSubtaskCountReq)){
            return null;
        }
        String groupKeyType = serviceSubtaskCountReq.getGroupKeyType();
        if(StringUtils.isEmpty(groupKeyType)){
            return null;
        }
        List<String> groupKeyList = new ArrayList<>(collect.keySet());
        if(ObjectUtils.isEmpty(groupKeyList)){
            return null;
        }
        //及时率统计
        ServiceSubtaskVO ssRate = new ServiceSubtaskVO();
        ssRate.setOrgid(serviceSubtaskCountReq.getOrgid());
@@ -2286,27 +2329,8 @@
        if(!collect.isEmpty()){
            jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
        }
        for (String collectKey : collect.keySet()) {
            List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
            if (CollectionUtils.isEmpty(serviceSubtaskList)) {
                continue;
            }
            ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList);
            Map<String, Object> jsRateMap = jsRates.get(collectKey);
            BigDecimal jsRate = new BigDecimal("0");
            if(ObjectUtils.isNotEmpty(jsRateMap) && ObjectUtils.isNotEmpty(jsRateMap.get("rate"))){
                jsRate = new BigDecimal(jsRateMap.get("rate").toString());
            }
            Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
            statistic.setRate(jsRateDouble);
            if (ObjectUtils.isNotEmpty(statistic)) {
                serviceSubtaskStatistics.add(statistic);
            }
        }
        return serviceSubtaskStatistics;
        return jsRates;
    }
    @Override
    public List<ServiceSubtaskStatistic> getSfStatisticsExport(ServiceSubtaskCountReq serviceSubtaskCountReq) {
        List<ServiceSubtaskStatistic> sfStatistics = getSfStatistics(serviceSubtaskCountReq);
@@ -3105,59 +3129,54 @@
    @Override
    @Cacheable(value = "getSfStatisticsScript", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
    public List<ServiceSubtaskStatistic> getSfStatisticsScript(ServiceSubtaskCountReq serviceSubtaskCountReq) {
        log.error("getSfStatisticsScript的入参为:{}", serviceSubtaskCountReq);
        log.info("getSfStatisticsScript的入参为:{}", serviceSubtaskCountReq);
        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        String orgid = null;
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
        String groupKeyType = "";
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
                groupKeyType = "drCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
            } else {
                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
                groupKeyType = "leaveHospitalDistrictCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
            }
        } else if (serviceSubtaskCountReq.getDeptcodes() != null && serviceSubtaskCountReq.getDeptcodes().size() > 0) {
        } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
                groupKeyType = "drCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
            } else {
                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
                groupKeyType = "deptCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
            }
        }
        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
        serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
        //获取及时率统计合集
        Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
        for (String collectKey : collect.keySet()) {
            List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
            if (CollectionUtils.isEmpty(serviceSubtaskList)) {
                continue;
            }
            ServiceSubtaskStatistic statistic = getStatisticCategory(serviceSubtaskList, serviceSubtaskCountReq);
            //及时率
            ServiceSubtask ss = new ServiceSubtask();
            orgid = serviceSubtaskList.get(0).getOrgid();
            ss.setOrgid(orgid);
            // 如果有医生编码,设置医生编码用于及时率查询
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                ss.setDrcode(serviceSubtaskList.get(0).getDrcode());
            } else {
                if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getLeavehospitaldistrictcodes())) {
                    ss.setLeavehospitaldistrictcode(serviceSubtaskList.get(0).getLeavehospitaldistrictcode());
                } else if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getDeptcodes())) {
                    ss.setDeptcode(serviceSubtaskList.get(0).getDeptcode());
            if(ObjectUtils.isNotEmpty(jsRates)){
                Map<String, Object> jsRateMap = jsRates.get(collectKey);
                BigDecimal jsRate = new BigDecimal("0");
                if(ObjectUtils.isNotEmpty(jsRateMap) && ObjectUtils.isNotEmpty(jsRateMap.get("rate"))){
                    jsRate = new BigDecimal(jsRateMap.get("rate").toString());
                }
                Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
                statistic.setRate(jsRateDouble);
            }
            ss.setStarttime(serviceSubtaskCountReq.getStartTime());
            ss.setEndtime(serviceSubtaskCountReq.getEndTime());
            if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) {
                ss.setEndtime(new Date());
            }
            Double jsRate = serviceSubtaskMapper.selectTimelyRate(ss);
            statistic.setRate(jsRate);
            if (ObjectUtils.isNotEmpty(statistic)) {
                serviceSubtaskStatistics.add(statistic);
            }
        }
        //统计随访题目分类
        if (CollectionUtils.isNotEmpty(serviceSubtaskStatistics)) {
            for (ServiceSubtaskStatistic serviceSubtaskStatistic : serviceSubtaskStatistics) {
                //获取满意度题目总量