| | |
| | | <!-- 优化的统计查询:直接在数据库层完成聚合计算 --> |
| | | <select id="countByCondition" parameterType="com.smartor.domain.ServiceSubtaskVO" resultType="map"> |
| | | SELECT |
| | | -- 未执行数量 (sendstate = 4) |
| | | SUM(CASE WHEN sendstate = 4 THEN 1 ELSE 0 END) AS wzx, |
| | | |
| | | -- 已随访数量 (sendstate != 4 AND sendstate != 2) |
| | | SUM(CASE WHEN sendstate != 4 AND sendstate != 2 THEN 1 ELSE 0 END) AS ysf, |
| | | |
| | | -- 发送失败数量 (sendstate = 5) |
| | | SUM(CASE WHEN sendstate = 5 THEN 1 ELSE 0 END) AS fssb, |
| | | |
| | | -- 已发送数量 (sendstate >= 3 OR sendstate = 1) |
| | | SUM(CASE WHEN sendstate >= 3 OR sendstate = 1 THEN 1 ELSE 0 END) AS yfs, |
| | | |
| | | -- 待随访数量 (sendstate = 2) |
| | | SUM(CASE WHEN sendstate = 2 THEN 1 ELSE 0 END) AS dsf, |
| | | |
| | | -- 不理睬数量 (sendstate = 1) |
| | | SUM(CASE WHEN sendstate = 1 THEN 1 ELSE 0 END) AS blq, |
| | | |
| | | -- 异常数量 (excep IS NOT NULL AND excep != '0') |
| | | SUM(CASE WHEN excep IS NOT NULL AND excep != '0' THEN 1 ELSE 0 END) AS yc |
| | | FROM service_subtask |
| | | <where> |
| | |
| | | <if test="phone != null and phone != ''"> |
| | | AND phone = #{phone} |
| | | </if> |
| | | <if test="leavehospitaldistrictcode != null and leavehospitaldistrictcode != ''"> |
| | | AND leavehospitaldistrictcode = #{leavehospitaldistrictcode} |
| | | <if test="deptOrDistrict==1"> |
| | | <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0"> |
| | | AND leavehospitaldistrictcode IN |
| | | <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" |
| | | separator="," |
| | | close=")"> |
| | | #{leavehospitaldistrictcode} |
| | | </foreach> |
| | | </if> |
| | | <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0"> |
| | | AND deptcode IN |
| | | <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," |
| | | close=")"> |
| | | #{leaveldeptcode} |
| | | </foreach> |
| | | </if> |
| | | </if> |
| | | <if test="deptOrDistrict==2"> |
| | | <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0"> |
| | | AND (leavehospitaldistrictcode IN |
| | | <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" |
| | | separator="," |
| | | close=")"> |
| | | #{leavehospitaldistrictcode} |
| | | </foreach> |
| | | </if> |
| | | <if test=" leaveldeptcodes != null and leaveldeptcodes.size()>0"> |
| | | OR deptcode IN |
| | | <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator="," |
| | | close="))"> |
| | | #{leaveldeptcode} |
| | | </foreach> |
| | | </if> |
| | | </if> |
| | | <if test="leavehospitaldistrictname != null and leavehospitaldistrictname != ''"> |
| | | AND leavehospitaldistrictname = #{leavehospitaldistrictname} |
| | |
| | | <if test="guid != null and guid != ''"> |
| | | AND guid = #{guid} |
| | | </if> |
| | | <if test="visitCount != null and visitCount == 1"> |
| | | AND visit_count = 1 |
| | | </if> |
| | | <if test="visitCount != null and visitCount > 1"> |
| | | AND visit_count > 1 |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |