已修改5个文件
307 ■■■■ 文件已修改
smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java 182 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java
@@ -93,6 +93,23 @@
    private String scriptids;
    /**
     * 分组类型 drCode, deptCode, leaveHospitalDistrictCode
     */
    @ApiModelProperty(value = "分组类型")
    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
@@ -738,6 +738,17 @@
    @ApiModelProperty(value = "随访部门编码集合")
    private List<String> visitDeptCodes;
    /**
     * 分组key
     */
    @ApiModelProperty(value = "分组key")
    private String groupKey;
    /**
     * 分组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);
    /**
     * 随访及时率详情
     *
@@ -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
@@ -2229,55 +2229,59 @@
    @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<>();
        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
        String groupKey = "drcode";
        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")));
                groupKey = "drcode";
            } else {
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
                groupKey = "leavehospitaldistrictcode";
            }
        } 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")));
                groupKey = "drcode";
            } else {
                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
                groupKey = "deptcode";
            }
        }
        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
        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()) {
            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());
            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);
@@ -2286,6 +2290,40 @@
        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 groupKey = serviceSubtaskCountReq.getGroupKey();
        if(StringUtils.isEmpty(groupKey)){
            return null;
        }
        List<String> groupKeyList = new ArrayList<>(collect.keySet());
        if(ObjectUtils.isEmpty(groupKeyList)){
            return null;
        }
        //及时率统计
        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());
        }
        ssRate.setGroupKey(groupKey);
        ssRate.setGroupKeyList(groupKeyList);
        Map<String, Map<String, Object>> jsRates = new HashMap<>();
        if(!collect.isEmpty()){
            jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
        }
        return jsRates;
    }
    @Override
    public List<ServiceSubtaskStatistic> getSfStatisticsExport(ServiceSubtaskCountReq serviceSubtaskCountReq) {
        List<ServiceSubtaskStatistic> sfStatistics = getSfStatistics(serviceSubtaskCountReq);
@@ -3084,59 +3122,67 @@
    @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<>();
        // 根据条件进行分组
        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
        String orgid = null;
        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
        String groupKey = "drcode";
        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")));
                groupKey = "drcode";
            } else {
                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
                groupKey = "leavehospitaldistrictcode";
            }
        } 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")));
                groupKey = "drcode";
            } else {
                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
                groupKey = "deptcode";
            }
        }
        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
        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()) {
            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) {
                //获取满意度题目总量
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>
@@ -1231,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}