陈昶聿
2026-01-22 9198cc1d419a239096d8d083b8cec5be72def7c2
【丽水】getSfStatistics 优化
已修改4个文件
138 ■■■■ 文件已修改
smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
@@ -738,6 +738,19 @@
    @ApiModelProperty(value = "随访部门编码集合")
    private List<String> visitDeptCodes;
    /**
     * 医生编码
     */
    @Excel(name = "分组key")
    @ApiModelProperty(value = "分组key")
    private String groupKey;
    /**
     * 医生编码
     */
    @Excel(name = "分组code集合")
    @ApiModelProperty(value = "分组code集合")
    private List<String> groupKeyList;
//    /**
//     * 日期限制 目前由前端控制
//     */
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
@@ -70,11 +70,11 @@
    /**
     * 随访及时率:应随访时间<实际随访时间
     *
     * @param ServiceSubtask
     * @param ServiceSubtaskvo
     * @return
     */
    @MapKey("groupKey")
    public Map<String, Double> selectTimelyRateBatch(ServiceSubtask ServiceSubtask);
    public Map<String, Map<String,Object>> selectTimelyRateBatch(ServiceSubtaskVO ServiceSubtaskvo);
    /**
     * 随访及时率详情
     *
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2226,7 +2226,7 @@
     * @return
     */
    @Override
    @Cacheable(value = "sfStatistics", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
//    @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) {
        log.info("getSfStatistics的入参为:{}", serviceSubtaskCountReq);
        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
@@ -2235,50 +2235,71 @@
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        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 = rawData.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 = rawData.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 = rawData.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 = rawData.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")));
            }
        }
        List<String> groupKeyList = new ArrayList<>(collect.keySet());
        //及时率
        ServiceSubtaskVO ssRate = new ServiceSubtaskVO();
        ssRate.setOrgid(serviceSubtaskCountReq.getOrgid());
        ssRate.setStarttime(serviceSubtaskCountReq.getStartTime());
        ssRate.setEndtime(serviceSubtaskCountReq.getEndTime());
        if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) {
            ssRate.setEndtime(new Date());
        }
        switch (groupKeyType)
        {
            case "deptCode":
                ssRate.setGroupKey("deptcode");
                ssRate.setGroupKeyList(groupKeyList);
                break;
            case "drCode":
                ssRate.setGroupKey("drcode");
                ssRate.setGroupKeyList(groupKeyList);
                break;
            case "leaveHospitalDistrictCode":
                ssRate.setGroupKey("leavehospitaldistrictcode");
                ssRate.setGroupKeyList(groupKeyList);
                break;
            default:
                ssRate.setGroupKey("drcode");
                ssRate.setGroupKeyList(groupKeyList);
                break;
        }
        Map<String, Map<String, Object>> jsRates = new HashMap<>();
        if(!collect.isEmpty()){
            jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
        }
        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
        for (String collectKey : collect.keySet()) {
            List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
            if (CollectionUtils.isEmpty(serviceSubtaskList)) {
                continue;
            }
            ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList);
            //及时率
            ServiceSubtask ss = new ServiceSubtask();
            ss.setOrgid(serviceSubtaskList.get(0).getOrgid());
            // 如果有医生编码,设置医生编码用于及时率查询
            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());
                }
            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());
            }
            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);
            Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
            statistic.setRate(jsRateDouble);
            if (ObjectUtils.isNotEmpty(statistic)) {
                serviceSubtaskStatistics.add(statistic);
            }
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -563,16 +563,40 @@
    <select id="selectTimelyRateBatch" parameterType="com.smartor.domain.ServiceSubtask" resultType="map">
        SELECT
        <if test="deptcode != null">deptcode as groupKey,</if>
        <if test="leavehospitaldistrictcode != null">leavehospitaldistrictcode as groupKey,</if>
        <if test="drcode != null">drcode as groupKey,</if>
        <if test="groupKey != null and groupKey != ''">
            ${groupKey} as groupKey,
        </if>
        SUM(CASE WHEN DATE(visit_time) &lt; DATE(IFNULL(finishtime, NOW())) THEN 1 ELSE 0 END) / COUNT(*) as rate
        FROM service_subtask
        WHERE del_flag = 0
        AND visit_time >= #{starttime}
        AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
        <if test="orgid != null">AND orgid = #{orgid}</if>
        GROUP BY groupKey
        <if test="starttime == null and endtime==null">
            AND visit_time &lt; NOW()
        </if>
        <if test="starttime != null and endtime!=null">
            AND visit_time >= #{starttime}
            AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
        </if>
        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
        <if test="deptcode != null  and deptcode != ''">and deptcode = #{deptcode}</if>
        <if test="deptname != null  and deptname != ''">and deptname = #{deptname}</if>
        <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
        <if test="leavehospitaldistrictcode != null  and leavehospitaldistrictcode != ''">and
            leavehospitaldistrictcode = #{leavehospitaldistrictcode}
        </if>
        <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
            leavehospitaldistrictname = #{leavehospitaldistrictname}
        </if>
        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
        <if test="groupKey != null and groupKey != ''">
            AND ${groupKey} IN
            <foreach collection="groupKeyList" item="key" open="(" separator=","
                     close=")">
                #{key}
            </foreach>
            GROUP BY ${groupKey}
        </if>
    </select>