coalesce(sum(case when jkpvr.do_status = '0' and jkpvr.is_overdue = '0' then 1 else 0 end), 0) as total_pending,
coalesce(sum(case when jkpvr.do_status = '1' then 1 else 0 end), 0) as total_done,
SELECT
coalesce(sum(case when jkpvr.do_status = '2' then 1 else 0 end), 0) as total_overdue,
(
coalesce(sum(case when jkpvr.do_status = '0' and jkpvr.is_overdue = '1' then 1 else 0 end), 0) as total_overdue_pending
SELECT COUNT(*)
from jl_key_person_visit_record jkpvr
FROM jl_key_person_visit_record
left join jl_key_person jkp on jkp.sys_type = '3' and jkp.id = jkpvr.key_person_id
WHERE FIND_IN_SET(key_person_id, GROUP_CONCAT(DISTINCT t1.person_id))
<where>
) AS total_done,
and jkp.id is not null
SUM(if(
r.id is NULL
or
(
v.id is NOT NULL
AND r.id is not NULL
AND DATE_FORMAT(NOW(),'%Y-%m-%d') >= DATE_FORMAT(DATE_ADD(r.visit_time, INTERVAL v.visit_start_day DAY), '%Y-%m-%d')
AND DATE_FORMAT(NOW(),'%Y-%m-%d') < DATE_FORMAT(DATE_ADD(r.visit_time, INTERVAL v.visit_end_day - v.overdue_warning_day DAY), '%Y-%m-%d')
)
, 1, 0)) AS total_pending,
SUM(if(
v.id is NOT NULL
AND r.id is not NULL
AND DATE_FORMAT(NOW(),'%Y-%m-%d') >= DATE_FORMAT(DATE_ADD(r.visit_time, INTERVAL v.visit_end_day - v.overdue_warning_day DAY), '%Y-%m-%d')
AND DATE_FORMAT(NOW(),'%Y-%m-%d') <= DATE_FORMAT(DATE_ADD(r.visit_time, INTERVAL v.visit_end_day DAY), '%Y-%m-%d')
, 1, 0)) AS total_overdue_pending,
SUM(if(
v.id is NOT NULL
AND r.id is not NULL
AND DATE_FORMAT(NOW(),'%Y-%m-%d') > DATE_FORMAT(DATE_ADD(r.visit_time, INTERVAL v.visit_end_day DAY), '%Y-%m-%d')
, 1, 0)) AS total_overdue
FROM
(
SELECT
kp.id AS person_id,
kp.sys_type,
s.id AS rating_id,
s.rating_type
FROM
(<includerefid="getPsersonList"></include>) kp,
jl_key_person_rating_summary s
WHERE
s.key_person_id = kp.id
AND s.is_history = '1'
) t1
LEFT JOIN jl_key_person_visit v ON v.rating_type = t1.rating_type AND v.status = '1' AND v.sys_type_office_label = #{office_label} AND v.rating_dict_type = t1.sys_type
LEFT JOIN jl_key_person_visit_record r ON t1.person_id = r.key_person_id AND r.is_new = '1' AND r.sys_type_office_label = #{office_label}
</select>
<sqlid="getPsersonList">
SELECT t1.* FROM
<choose>
<choose>
<whentest="scope_grade == '3'">
<whentest="sys_type != null and (sys_type == '2'.toString() or sys_type == '3'.toString())">
AND jkp.city_id = #{scope_area_id}
jl_key_person t1
</when>
<whentest="scope_grade == '4'">
AND jkp.area_id = #{scope_area_id}
</when>
</when>
<whentest="scope_grade == '5'">
<whentest="sys_type != null and sys_type == '6'.toString()">
LEFT JOIN jl_key_person_visit v ON v.rating_type = t1.rating_type AND v.status = '1' AND v.sys_type_office_label = #{params.office_label} AND v.rating_dict_type = t1.sys_type
LEFT JOIN jl_key_person_visit v ON v.rating_type = t1.rating_type AND v.status = '1' AND v.sys_type_office_label = #{params.office_label} AND v.rating_dict_type = t1.sys_type
LEFT JOIN jl_key_person_visit_record r ON t1.person_id = r.key_person_id AND r.is_new = '1' AND r.sys_type_office_label = #{params.office_label}
LEFT JOIN jl_key_person_visit_record r ON t1.person_id = r.key_person_id AND r.is_new = '1' AND r.sys_type_office_label = #{params.office_label}
...
@@ -117,6 +118,9 @@
...
@@ -117,6 +118,9 @@
<whentest="params.sys_type != null and params.sys_type == '6'.toString()">
<whentest="params.sys_type != null and params.sys_type == '6'.toString()">
jl_key_person_minor t1
jl_key_person_minor t1
</when>
</when>
<otherwise>
jl_key_person t1
</otherwise>
</choose>
</choose>
<where>
<where>
<includerefid="getPersonWhere"></include>
<includerefid="getPersonWhere"></include>
...
@@ -132,6 +136,9 @@
...
@@ -132,6 +136,9 @@
<whentest="params.sys_type != null and params.sys_type == '6'.toString()">
<whentest="params.sys_type != null and params.sys_type == '6'.toString()">