陈昶聿
2026-01-22 c3395d01203fd57d191b36f3410f8ae6e6aafd09
【丽水】getSfStatistics、getSfStatisticsScript 优化
已修改5个文件
178 ■■■■ 文件已修改
smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java 104 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java
@@ -99,6 +99,17 @@
    private String groupKeyType;
    /**
     * 分组key
     */
    @ApiModelProperty(value = "分组key")
    private String groupKey;
    /**
     * 分组code集合
     */
    @ApiModelProperty(value = "分组code集合")
    private List<String> groupKeyList;
    /**
     * pageNum
     */
    @ApiModelProperty("pageNum")
smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
@@ -739,15 +739,13 @@
    private List<String> visitDeptCodes;
    /**
     * 医生编码
     * 分组key
     */
    @Excel(name = "分组key")
    @ApiModelProperty(value = "分组key")
    private String groupKey;
    /**
     * 医生编码
     * 分组code集合
     */
    @Excel(name = "分组code集合")
    @ApiModelProperty(value = "分组code集合")
    private List<String> groupKeyList;
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
@@ -117,6 +117,8 @@
    public List<ServiceSubtask> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq);
    public List<String> getSfStatisticsGroupKey(ServiceSubtaskCountReq serviceSubtaskCountReq);
    public List<ServiceSubtaskCount> getSfStatisticsJoy(ServiceSubtaskCountReq serviceSubtaskCountReq);
    public List<ServiceSubtaskCount> getSfStatisticsJoydetails(ServiceSubtaskCountReq serviceSubtaskCountReq);
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2228,33 +2228,43 @@
    @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);
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        String groupKeyType = "";
        String groupKey = "drcode";
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKeyType = "drCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                groupKey = "drcode";
            } else {
                groupKeyType = "leaveHospitalDistrictCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
                groupKey = "leavehospitaldistrictcode";
            }
        } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKeyType = "drCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                groupKey = "drcode";
            } else {
                groupKeyType = "deptCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                groupKey = "deptcode";
            }
        }
        serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        serviceSubtaskCountReq.setGroupKey(groupKey);
        List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq);
        serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        switch (groupKey)
        {
            case "deptcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                break;
            case "drcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                break;
            case "leavehospitaldistrictcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
                break;
            default:
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                break;
        }
        //获取及时率统计合集
        Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
        for (String collectKey : collect.keySet()) {
@@ -2290,8 +2300,8 @@
        if(ObjectUtils.isEmpty(serviceSubtaskCountReq)){
            return null;
        }
        String groupKeyType = serviceSubtaskCountReq.getGroupKeyType();
        if(StringUtils.isEmpty(groupKeyType)){
        String groupKey = serviceSubtaskCountReq.getGroupKey();
        if(StringUtils.isEmpty(groupKey)){
            return null;
        }
        List<String> groupKeyList = new ArrayList<>(collect.keySet());
@@ -2306,25 +2316,8 @@
        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;
        }
        ssRate.setGroupKey(groupKey);
        ssRate.setGroupKeyList(groupKeyList);
        Map<String, Map<String, Object>> jsRates = new HashMap<>();
        if(!collect.isEmpty()){
            jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
@@ -3131,29 +3124,42 @@
    public List<ServiceSubtaskStatistic> getSfStatisticsScript(ServiceSubtaskCountReq serviceSubtaskCountReq) {
        log.info("getSfStatisticsScript的入参为:{}", serviceSubtaskCountReq);
        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        String groupKeyType = "";
        String groupKey = "drcode";
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKeyType = "drCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                groupKey = "drcode";
            } else {
                groupKeyType = "leaveHospitalDistrictCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
                groupKey = "leavehospitaldistrictcode";
            }
        } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) {
            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
                groupKeyType = "drCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                groupKey = "drcode";
            } else {
                groupKeyType = "deptCode";
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                groupKey = "deptcode";
            }
        }
        serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
        serviceSubtaskCountReq.setGroupKey(groupKey);
        List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq);
        serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        switch (groupKey)
        {
            case "deptcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                break;
            case "drcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                break;
            case "leavehospitaldistrictcode":
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
                break;
            default:
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
                break;
        }
        //获取及时率统计合集
        Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
        for (String collectKey : collect.keySet()) {
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -1255,6 +1255,61 @@
            <!-- 目前只统计语音和问卷 -->
            <if test="type != null">
                and type = #{type}
        </if>
        <if test="groupKey != null and groupKey != '' and groupKeyList != null and groupKeyList.size>0">
            AND ${groupKey} IN
            <foreach collection="groupKeyList" item="key" open="(" separator=","
                     close=")">
                #{key}
            </foreach>
        </if>
    </select>
    <select id="getSfStatisticsGroupKey" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultType="String">
            select
            <if test="groupKey != null and groupKey != ''">
                ${groupKey} as groupKey
            </if>
            from service_subtask
            where 1=1
            and del_flag = 0
            <if test="orgid != null and orgid != ''">
            and orgid = #{orgid}
            </if>
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
            AND leavehospitaldistrictcode IN
            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
                     close=")">
                #{leavehospitaldistrictcode}
            </foreach>
            </if>
            <if test="deptcodes != null and deptcodes.size() > 0">
            AND deptcode IN
            <foreach collection="deptcodes" item="deptcode" open="(" separator=","
                     close=")">
                #{deptcode}
            </foreach>
            </if>
            <if test="serviceType != null and serviceType.size() > 0">
            AND service_type IN
            <foreach collection="serviceType" item="serviceType" open="(" separator=","
                     close=")">
                #{serviceType}
            </foreach>
            </if>
            <if test="startTime != null and endTime!=null">
            AND visit_time >= DATE(#{startTime})
            AND visit_time &lt; DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY)
            </if>
            <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
            <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
            <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
            <!-- 目前只统计语音和问卷 -->
            <if test="type != null">
            and type = #{type}
            </if>
            <if test="groupKey != null and groupKey != ''">
                group by ${groupKey}
            </if>
            <if test="pageSize != null  and pageNum != null">
                limit ${pageSize} OFFSET ${pageNum}