Bläddra i källkod

分页查询优化

wangfeng 4 år sedan
förälder
incheckning
59a6f545be

+ 5 - 0
src/main/java/com/diagbot/dto/PlanInfoPageDTO.java

@@ -3,6 +3,7 @@ package com.diagbot.dto;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -27,6 +28,10 @@ public class PlanInfoPageDTO {
     private String planCode;
 
     private Integer planStatus;
+
+    private Date gmtCreate;
+
+    private String planDetail;
     /**
      * 备注
      */

+ 33 - 23
src/main/resources/mapper/PlanMapper.xml

@@ -4,40 +4,50 @@
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.diagbot.entity.Plan">
-        <id column="id" property="id" />
-        <result column="is_deleted" property="isDeleted" />
-        <result column="gmt_create" property="gmtCreate" />
-        <result column="gmt_modified" property="gmtModified" />
-        <result column="creator" property="creator" />
-        <result column="modifier" property="modifier" />
-        <result column="hospital_id" property="hospitalId" />
-        <result column="plan_name" property="planName" />
-        <result column="plan_code" property="planCode" />
-        <result column="plan_status" property="planStatus" />
-        <result column="remark" property="remark" />
+        <id column="id" property="id"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="gmt_create" property="gmtCreate"/>
+        <result column="gmt_modified" property="gmtModified"/>
+        <result column="creator" property="creator"/>
+        <result column="modifier" property="modifier"/>
+        <result column="hospital_id" property="hospitalId"/>
+        <result column="plan_name" property="planName"/>
+        <result column="plan_code" property="planCode"/>
+        <result column="plan_status" property="planStatus"/>
+        <result column="remark" property="remark"/>
     </resultMap>
 
     <select id="getPlanInfoPageAll" resultType="com.diagbot.dto.PlanInfoPageDTO">
         SELECT
-        id as id,
-        hospital_id as hospitalId,
-        plan_name as planName,
-        plan_code as planCode,
-        plan_status as planStatus
-        FROM tran_plan u
-        WHERE u.is_deleted = 'N'
+        u.id AS id,
+        u.hospital_id AS hospitalId,
+        u.plan_name AS planName,
+        u.plan_code AS planCode,
+        u.plan_status AS planStatus,
+        u.gmt_create AS gmtCreate,
+        GROUP_CONCAT(
+        pd.NAME
+        ORDER BY
+        pd.order_no ASC
+        ) AS planDetail
+        FROM
+        tran_plan u,
+        tran_plan_detail pd
+        WHERE
+        u.is_deleted = 'N'
+        AND pd.is_deleted = 'N'
         <if test="hospitalId !=null">
-            and hospital_id =#{hospitalId}
+            and u.hospital_id =#{hospitalId}
         </if>
+        AND pd.plan_id = u.id
+        AND pd.parent_id = -1
         <if test="planName != null and planName =''">
             AND UPPER(u.plan_name) LIKE CONCAT('%', UPPER(trim(#{planName})), '%')
         </if>
         <if test="planCode != null and planCode != ''">
             AND u.plan_code = #{planCode}
         </if>
-        <if test="planStatus != null">
-            AND u.plan_status = #{planStatus}
-        </if>
-        ORDER BY gmt_create DESC
+        GROUP BY u.id
+        ORDER BY gmtCreate DESC
     </select>
 </mapper>