浏览代码

条目缺陷占比优化 sql拆分

chengyao 4 年之前
父节点
当前提交
0d2c462492

+ 18 - 1
src/main/java/com/diagbot/mapper/QcresultInfoMapper.java

@@ -16,7 +16,10 @@ import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcresultFilterVO;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * <p>
@@ -156,6 +159,20 @@ public interface QcresultInfoMapper extends BaseMapper<QcresultInfo> {
      */
     public IPage<EntryNumDTO> entryGroupByEntryInnerPage(@Param("filterPageVO") FilterPageVO filterPageVO);
 
+    /**
+     * 条目缺陷总数(内页)
+     *
+     * @return
+     */
+    public Integer entryGroupByEntrySum(@Param("hospitalId") String hospitalId,@Param("isPlacefile") String isPlacefile,@Param("startDate") String startDate,@Param("endDate") String endDate);
+
+    /**
+     * 条目缺陷分值统计(内页)
+     *
+     * @return
+     */
+    public List<EntryNumDTO> entryGroupByEntryScore(@Param("hospitalId") String hospitalId,@Param("isPlacefile") String isPlacefile, @Param("ids")Set<Long> ids);
+
     /**
      * 条目缺陷占比-科室(内页)
      *
@@ -187,4 +204,4 @@ public interface QcresultInfoMapper extends BaseMapper<QcresultInfo> {
      * @return
      */
     public List<DeptNumDTO> qcResultLevelPercent(FilterVO filterVO);
-}
+}

+ 38 - 3
src/main/java/com/diagbot/service/impl/QcresultInfoServiceImpl.java

@@ -16,10 +16,13 @@ import com.diagbot.vo.FilterPageByDeptVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcresultFilterVO;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import java.text.DecimalFormat;
+import java.util.*;
 
 /**
  * <p>
@@ -206,7 +209,39 @@ public class QcresultInfoServiceImpl extends ServiceImpl<QcresultInfoMapper, Qcr
      */
     @Override
     public IPage<EntryNumDTO> entryGroupByEntryInnerPage(@Param("filterPageVO") FilterPageVO filterPageVO) {
-        return baseMapper.entryGroupByEntryInnerPage(filterPageVO);
+       //基础数据
+        IPage<EntryNumDTO> entryNumDTOIPage  = baseMapper.entryGroupByEntryInnerPage(filterPageVO);
+        String hospitalId = filterPageVO.getHospitalId();
+        //缺陷总数
+          Integer sumInteget = baseMapper.entryGroupByEntrySum(filterPageVO.getHospitalId(),filterPageVO.getIsPlacefile(),
+                                                                filterPageVO.getStartDate(),filterPageVO.getEndDate());
+        Set<Long> ids = new HashSet<Long>();
+        List<EntryNumDTO> records = entryNumDTOIPage.getRecords();
+        if(CollectionUtils.isEmpty(records)){
+            return null;
+        }
+        for (EntryNumDTO record : records) {
+            ids.add(record.getId());
+            int num = record.getNum().intValue();
+            int sum = sumInteget.intValue();
+            float nsum =(float) num/sum;
+            DecimalFormat df = new DecimalFormat("0.00");
+            String percent = df.format(nsum*100);
+            record.setPercent(Double.valueOf(percent));
+            record.setPercentStr(percent+"%");
+            record.setTotleNum(sumInteget);
+        }
+        //缺陷分值
+        String isPlacefile = filterPageVO.getIsPlacefile();
+        List<EntryNumDTO> entryScore = baseMapper.entryGroupByEntryScore(hospitalId,isPlacefile, ids);
+        for (EntryNumDTO record : records) {
+            for (EntryNumDTO entryNumDTO : entryScore) {
+                if(record.getId().equals(entryNumDTO.getId())){
+                 record.setScore(entryNumDTO.getScore());
+                    }
+                }
+            }
+        return entryNumDTOIPage;
     }
 
     /**
@@ -252,4 +287,4 @@ public class QcresultInfoServiceImpl extends ServiceImpl<QcresultInfoMapper, Qcr
     public List<DeptNumDTO> qcResultLevelPercent(FilterVO filterVO) {
         return baseMapper.qcResultLevelPercent(filterVO);
     }
-}
+}

+ 1 - 3
src/main/resources/mapper/BehospitalInfoMapper.xml

@@ -731,9 +731,7 @@
     <!-- 死亡人数统计-全院-首页 -->
     <select id="deathCount" parameterType="com.diagbot.vo.FilterVO" resultType="int">
         SELECT
-        a.behospital_code,
-        b.mode_id,
-        b.rec_id
+        COUNT(*)
         FROM
         med_behospital_info a,
         med_medical_record b,

+ 87 - 61
src/main/resources/mapper/QcresultInfoMapper.xml

@@ -431,71 +431,76 @@
     <!-- 条目缺陷占比(内页) -->
     <select id="entryGroupByEntryInnerPage" resultType="com.diagbot.dto.EntryNumDTO">
         SELECT
-        t1.id AS id,
-        t1.name AS name,
-        t1.casesId AS casesId,
-        t1.casesName AS casesName,
-        t1.num AS num,
-        t2.mrNum AS totleNum,
-        t1.isReject AS isReject,
-        t1.score AS score,
-        Round( t1.num / t2.mrNum, 4 ) AS percent,
-        CONCAT( Round( t1.num / t2.mrNum * 100, 2 ), '%' ) AS percentStr
-        from(
+        tt2.id as id,
+        tt2.NAME as name,
+        tt2.cases_id AS casesId,
+        tt2.cases_name AS casesName,
+        tt1.num as num,
+        tt1.is_reject AS isReject
+        FROM
+        (
         SELECT
-        id,
-        name,
-        casesId,
-        casesName,
-        isReject,
-        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 0">
-            score_run as score,
-        </if>
-        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 1">
-            score,
-        </if>
-        count(*) num
-        from new_table_name
+        a.hospital_id,
+        d.cases_entry_id,
+        d.cases_id,
+        count(*) AS num,
+        d.is_reject
+        FROM
+        med_behospital_info a,
+        med_qcresult_detail d
         WHERE
-        is_deleted = 'N'
+        a.is_deleted = 'N'
+        AND d.is_deleted = 'N'
+        AND a.hospital_id = d.hospital_id
+        AND a.behospital_code = d.behospital_code
         <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile != ''">
-            and is_placefile = #{filterPageVO.isPlacefile}
-        </if>
-        AND qc_type_id != 0
-        <if test="filterPageVO.hospitalId != null and filterPageVO.hospitalId != ''">
-            AND hospital_id = #{filterPageVO.hospitalId}
+            and a.is_placefile = #{filterPageVO.isPlacefile}
         </if>
+        AND a.qc_type_id != 0
         <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 0">
             <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
-                <![CDATA[ AND behospital_date >= #{filterPageVO.startDate}]]>
+                <![CDATA[ AND a.behospital_date >= #{filterPageVO.startDate}]]>
             </if>
             <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
-                <![CDATA[ AND behospital_date <= #{filterPageVO.endDate}]]>
+                <![CDATA[ AND a.behospital_date <= #{filterPageVO.endDate}]]>
             </if>
         </if>
         <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 1">
             <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
-                <![CDATA[ AND leave_hospital_date >= #{filterPageVO.startDate}]]>
+                <![CDATA[ AND a.leave_hospital_date >= #{filterPageVO.startDate}]]>
             </if>
             <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
-                <![CDATA[ AND leave_hospital_date <= #{filterPageVO.endDate}]]>
+                <![CDATA[ AND a.leave_hospital_date <= #{filterPageVO.endDate}]]>
             </if>
         </if>
         <if test="filterPageVO.isReject != null">
-            AND is_reject = #{filterPageVO.isReject}
+            AND d.is_reject = #{filterPageVO.isReject}
+        </if>
+        GROUP BY
+        d.cases_entry_id,
+        d.is_reject,
+        d.cases_id
+        having
+        1=1
+        <if test="filterPageVO.hospitalId != null and filterPageVO.hospitalId != ''">
+            AND a.hospital_id = #{filterPageVO.hospitalId}
         </if>
+        ) tt1,
+        qc_cases_entry tt2
+        WHERE
+        tt2.is_deleted = 'N'
+        AND tt1.cases_id = tt2.cases_id
+        AND tt1.cases_entry_id = tt2.id
         <if test="filterPageVO.name != null and filterPageVO.name != ''">
-            AND name like CONCAT('%', #{filterPageVO.name},'%')
+            AND tt2.name like CONCAT('%', #{filterPageVO.name},'%')
         </if>
         <if test="filterPageVO.casesName != null and filterPageVO.casesName != ''">
-            AND cases_name = #{filterPageVO.casesName}
+            AND tt2.cases_name = #{filterPageVO.casesName}
         </if>
-        GROUP BY
-        id,
-        isReject,
-        casesId)t1,
-
-        ( SELECT
+    </select>
+    <!-- 条目缺陷占比缺陷总量(内页) -->
+    <select id="entryGroupByEntrySum" resultType="java.lang.Integer">
+        SELECT
         count(*) AS mrNum
         FROM
         med_behospital_info a,
@@ -505,31 +510,54 @@
         AND c.is_deleted = 'N'
         AND a.hospital_id = c.hospital_id
         AND a.behospital_code = c.behospital_code
-        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile != ''">
-            and a.is_placefile = #{filterPageVO.isPlacefile}
+        <if test="isPlacefile != null and isPlacefile != ''">
+            and a.is_placefile = #{isPlacefile}
         </if>
         AND a.qc_type_id != 0
-        <if test="filterPageVO.hospitalId != null and filterPageVO.hospitalId != ''">
-            AND a.hospital_id = #{filterPageVO.hospitalId}
+        <if test="hospitalId != null and hospitalId != ''">
+            AND a.hospital_id = #{hospitalId}
         </if>
-        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 0">
-            <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
-                <![CDATA[ AND a.behospital_date >= #{filterPageVO.startDate}]]>
+        <if test="isPlacefile != null and isPlacefile == 0">
+            <if test="startDate != null and startDate != ''">
+                <![CDATA[ AND a.behospital_date >= #{startDate}]]>
             </if>
-            <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
-                <![CDATA[ AND a.behospital_date <= #{filterPageVO.endDate}]]>
+            <if test="endDate != null and endDate != ''">
+                <![CDATA[ AND a.behospital_date <= #{endDate}]]>
             </if>
         </if>
-        <if test="filterPageVO.isPlacefile != null and filterPageVO.isPlacefile == 1">
-            <if test="filterPageVO.startDate != null and filterPageVO.startDate != ''">
-                <![CDATA[ AND a.leave_hospital_date >= #{filterPageVO.startDate}]]>
+        <if test="isPlacefile != null and isPlacefile == 1">
+            <if test="startDate != null and startDate != ''">
+                <![CDATA[ AND a.leave_hospital_date >= #{startDate}]]>
             </if>
-            <if test="filterPageVO.endDate != null and filterPageVO.endDate != ''">
-                <![CDATA[ AND a.leave_hospital_date <= #{filterPageVO.endDate}]]>
+            <if test="endDate != null and endDate != ''">
+                <![CDATA[ AND a.leave_hospital_date <= #{endDate}]]>
             </if>
         </if>
-        )t2
     </select>
+
+    <!-- 条目缺陷占比分值统计 -->
+    <select id="entryGroupByEntryScore"  resultType="com.diagbot.dto.EntryNumDTO">
+    SELECT
+        a.hospital_id as hospitalId,
+
+        <if test="isPlacefile != null and isPlacefile == 0">
+            a.score_run as score,
+        </if>
+        <if test="isPlacefile != null and isPlacefile == 1">
+            a.score,
+        </if>
+        a.cases_entry_id as id
+    FROM
+        qc_cases_entry_hospital a
+    WHERE
+        a.is_deleted = 'N'
+        AND a.hospital_id = #{hospitalId}
+        AND a.cases_entry_id IN
+        <foreach collection="ids" open="(" separator="," close=")" item="item">
+            ${item}
+        </foreach>
+    </select>
+
    <!-- <select id="entryGroupByEntryInnerPage" resultType="com.diagbot.dto.EntryNumDTO">
         SELECT
         t.*
@@ -664,8 +692,7 @@
         </if>
         ) t2
         ) t
-    </select>
--->
+    </select>-->
     <!-- 单项否决缺陷占比(首页) -->
     <select id="entryRejectPercent" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.EntryNumDTO">
         SELECT
@@ -790,7 +817,6 @@
         ORDER BY
         percent DESC
     </select>
-
     <!-- 各科室质控平均分(首页) -->
     <select id="getAverageScore" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.AverageStatisticsDTO">
         SELECT