| | |
| | | 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') >= |
| | | date_format(#{startOutHospTime},'%y%m%d') |
| | | </if> |
| | | <if test="endOutHospTime != null ">and date_format(b.endtime,'%y%m%d') <= |
| | | date_format(#{endOutHospTime},'%y%m%d') |
| | | </if> |
| | | <if test="startInHospTime != null ">and date_format(b.starttime,'%y%m%d') >= |
| | | date_format(#{startInHospTime},'%y%m%d') |
| | | </if> |
| | | <if test="endInHospTime != null ">and date_format(b.starttime,'%y%m%d') <= |
| | | date_format(#{endInHospTime},'%y%m%d') |
| | | </if> |
| | | <!-- 时间范围保持“按日期、结束日含当天”的语义;列保持裸列,避免 date_format 导致索引失效 --> |
| | | <if test="startOutHospTime != null ">and b.endtime >= DATE(#{startOutHospTime})</if> |
| | | <if test="endOutHospTime != null ">and b.endtime < DATE_ADD(DATE(#{endOutHospTime}), INTERVAL 1 DAY)</if> |
| | | <if test="startInHospTime != null ">and b.starttime >= DATE(#{startInHospTime})</if> |
| | | <if test="endInHospTime != null ">and b.starttime < DATE_ADD(DATE(#{endInHospTime}), INTERVAL 1 DAY)</if> |
| | | <if test="hospitalname != null and hospitalname != ''">and hospitalname like concat('%', #{hospitalname}, |
| | | '%') |
| | | </if> |
| | |
| | | <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> |
| | |
| | | a.idcardno |
| | | FROM |
| | | <include refid="selectPatMedInhospListFromWhere"/> |
| | | GROUP BY |
| | | b.inhospid, |
| | | a.age, |
| | | a.age_unit, |
| | | a.telcode, |
| | | a.id, |
| | | a.sex |
| | | <!-- |
| | | 性能说明:pat_med_inhosp.inhospid 唯一,pat_archive.id 是主键,a.id = b.patid 一对一, |
| | | 原 GROUP BY 是多余的,且会让 MySQL 先物化 60 列临时表再排序,LIMIT 无法提前结束。 |
| | | 上线前请确认以下两条均无重复: |
| | | SELECT inhospid, COUNT(*) c FROM pat_med_inhosp GROUP BY inhospid HAVING c > 1 LIMIT 10; |
| | | SELECT id, COUNT(*) c FROM pat_archive GROUP BY id HAVING c > 1 LIMIT 10; |
| | | --> |
| | | <if test="cry != null and cry==1"> |
| | | order by b.endtime desc |
| | | </if> |
| | |
| | | <!-- |
| | | 分页总数(PageHelper 手写 count,id = 主查询 id + _COUNT 会被自动采用)。 |
| | | |
| | | 原状态:主查询带 GROUP BY,pagehelper 的 CountSqlParser#isSimpleCount 判定为 |
| | | "不能简化",于是总数变成 SELECT count(0) FROM ( 上面那条 60 列查询 ) tmp_count — |
| | | 等于每次翻页把整条查询再跑一遍。 |
| | | |
| | | 这里保持【完全相同的 FROM/WHERE/GROUP BY】(共用 selectPatMedInhospListFromWhere 片段, |
| | | 条件不会漂),但子查询只 select 1,不物化 60 列,也不带 order by。 |
| | | 因为分组键包含 a.id 而这个 join 是一对一,分组数 == join 结果行数,总数与原来一致。 |
| | | 主查询已去掉 GROUP BY:pat_med_inhosp.inhospid 唯一、pat_archive.id 是主键, |
| | | a.id = b.patid 一对一,因此 join 结果行数就是业务记录数。 |
| | | 这里直接对相同的 FROM/WHERE 做 COUNT,不再包一层分组子查询。 |
| | | --> |
| | | <select id="selectPatMedInhospList_COUNT" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp" |
| | | resultType="java.lang.Long"> |
| | | select count(1) |
| | | from ( |
| | | select 1 |
| | | FROM |
| | | <include refid="selectPatMedInhospListFromWhere"/> |
| | | group by b.inhospid, a.age, a.age_unit, a.telcode, a.id, a.sex |
| | | ) t |
| | | </select> |
| | | |
| | | <select id="selectPatMedInhospListBySerialnum" parameterType="com.ruoyi.inhospvisit.domain.PatMedInhosp" |