陈昶聿
4 天以前 d7e3192804fca756d881af360ffd5eea157ef9ad
smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
@@ -247,18 +247,15 @@
        AND b.del_flag = 0
        AND a.idcardno IS NOT NULL
        <if test="inhospid != null">and b.inhospid = #{inhospid}</if>
        <if test="startOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &gt;=
            date_format(#{startOutHospTime},'%y%m%d')
        </if>
        <if test="endOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &lt;=
            date_format(#{endOutHospTime},'%y%m%d')
        </if>
        <if test="startInHospTime != null ">and date_format(b.starttime,'%y%m%d') &gt;=
            date_format(#{startInHospTime},'%y%m%d')
        </if>
        <if test="endInHospTime != null ">and date_format(b.starttime,'%y%m%d') &lt;=
            date_format(#{endInHospTime},'%y%m%d')
        </if>
        <!--
          时间范围不要写成 date_format(b.endtime,'%y%m%d') >= date_format(#{...},'%y%m%d'):
          列上套函数会让 endtime / starttime 上的索引彻底失效(而且 %y 是两位年份)。
          这里把函数挪到参数侧,语义等价:>= 当天 0 点,< 次日 0 点。
        -->
        <if test="startOutHospTime != null ">and b.endtime &gt;= date(#{startOutHospTime})</if>
        <if test="endOutHospTime != null ">and b.endtime &lt; date(#{endOutHospTime}) + interval 1 day</if>
        <if test="startInHospTime != null ">and b.starttime &gt;= date(#{startInHospTime})</if>
        <if test="endInHospTime != null ">and b.starttime &lt; date(#{endInHospTime}) + interval 1 day</if>
        <if test="hospitalname != null  and hospitalname != ''">and hospitalname like concat('%', #{hospitalname},
            '%')
        </if>
@@ -276,7 +273,6 @@
        <if test="orgid != null ">and b.orgid = #{orgid}</if>
        <if test="campusid != null ">and b.campusid = #{campusid}</if>
        <if test="serialnum != null ">and b.serialnum = #{serialnum}</if>
        <if test="endtime != null ">and b.endtime = #{endtime}</if>
        <if test="patno != null ">and b.patno = #{patno}</if>
        <if test="nurseId != null ">and b.nurse_id = #{nurseId}</if>
        <if test="nurseName != null and nurseName != ''">and b.nurse_name = #{nurseName}</if>
@@ -353,20 +349,12 @@
        <if test="medicalCode != null and medicalCode != ''">and b.medical_code = #{medicalCode}</if>
        <if test="medicalName != null and medicalName != ''">and b.medical_name = #{medicalName}</if>
        <if test="medicalCompany != null and medicalCompany != ''">and b.medical_company = #{medicalCompany}</if>
        GROUP BY
        b.inhospid,
        a.age,
        a.age_unit,
        a.telcode,
        a.id,
        a.sex
        <if test="cry != null and cry==1">
            order by b.endtime desc
        </if>
        <if test="cry != null and cry==2">
            order by b.endtime desc
        </if>
        <if test="cry != null and cry==3">
        <!--
          原来这里有一段 GROUP BY b.inhospid, a.age, a.age_unit, a.telcode, a.id, a.sex。
          b.inhospid 是主键、a.id = b.patid 是一对一关联,分组不会合并任何行,只会让 MySQL
          多建一张临时表、并让分页的 count 变成派生表。这里直接去掉。
        -->
        <if test="cry != null and (cry == 1 or cry == 2 or cry == 3)">
            order by b.endtime desc
        </if>
        <if test="cry != null and cry==0">
@@ -661,6 +649,19 @@
          AND d.del_flag = 0
    </select>
    <!-- 批量查标签,替代列表逐行调用 getTagnameBypatid 的 N+1 查询 -->
    <select id="selectTagnameByPatids" resultType="com.smartor.domain.PatArchivetag">
        SELECT d.patid      AS patid,
               GROUP_CONCAT(d.tagname, ', ') AS tagname
        FROM pat_archivetag d
        WHERE d.del_flag = 0
          AND d.patid IN
        <foreach collection="patids" item="patid" open="(" separator="," close=")">
            #{patid}
        </foreach>
        GROUP BY d.patid
    </select>
    <select id="selectPatMedInhospByInhospid" parameterType="Long" resultMap="PatMedInhospResult">
        <include refid="selectPatMedInhospVo"/>