You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
6.5 KiB
158 lines
6.5 KiB
<?xml version="1.0" encoding="UTF-8" ?> |
|
<!DOCTYPE mapper |
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|
<mapper namespace="com.biutag.supervision.mapper.SamplingMapper"> |
|
|
|
<select id="queryPage" resultType="com.biutag.supervision.pojo.entity.Sampling"> |
|
SELECT |
|
* |
|
FROM |
|
sampling a |
|
${ew.getCustomSqlSegment} |
|
</select> |
|
|
|
<select id="selectPoliceData" resultType="com.biutag.supervision.pojo.vo.PoliceVo" parameterType="com.biutag.supervision.pojo.vo.SamplingVo"> |
|
SELECT |
|
sup.name, |
|
sup.id_code as idCode, |
|
sdp.short_name as shortName, |
|
sup.emp_no as empNo, |
|
stp.isdrink, |
|
sup.person_type as personnelType, |
|
sap.time as crtTime, |
|
sup.org_id as deptId, |
|
IFNULL(scp.cjnum,0) as cjnum, |
|
CASE WHEN sup.position IS NOT NULL THEN 1 ELSE 0 END AS isLeader, |
|
DATEDIFF(CURDATE(), sap.time) AS daysDifference, |
|
YEAR(CURDATE()) - YEAR(STR_TO_DATE(SUBSTRING(sup.id_code, 7, 8), '%Y%m%d')) - |
|
CASE |
|
WHEN DATE_FORMAT(CURDATE(), '%m%d') < DATE_FORMAT(STR_TO_DATE(SUBSTRING(id_code, 7, 8), '%Y%m%d'), '%m%d') THEN 1 |
|
ELSE 0 |
|
END AS age, |
|
CASE |
|
WHEN CAST(SUBSTRING(sup.id_code, 17, 1) AS UNSIGNED) % 2 = 0 THEN '2' |
|
ELSE '1' |
|
END AS gender |
|
from sup_police sup |
|
LEFT JOIN |
|
(SELECT emp_no,max(crt_time) as time from sampling_police) sap on sup.emp_no = sap.emp_no |
|
LEFT JOIN |
|
( |
|
SELECT emp_no, COUNT(emp_no) as cjnum FROM sampling_police |
|
<where> |
|
<if test="startTime != null and startTime != '' and endtime != null and endtime != ''"> |
|
and crt_time BETWEEN #{startTime} and #{endTime} |
|
</if> |
|
</where> |
|
GROUP BY emp_no |
|
) scp ON sup.emp_no = scp.emp_no |
|
LEFT JOIN sup_depart sdp on sdp.id = sup.org_id |
|
LEFT JOIN (SELECT emp_no, MAX(case when drink_result = "饮酒" THEN 1 ELSE 0 end) as isdrink from sup_task_testing_alcohol_people GROUP BY emp_no) stp on sup.emp_no = stp.emp_no |
|
<where> |
|
sup.position is null |
|
and sup.del = 0 |
|
<if test="personnelTypeArray != null and personnelTypeArray != '' and personnelTypeArray.size() > 0"> |
|
and sup.person_type in |
|
<foreach collection="personnelTypeArray" item="data" open="(" close=")" separator=","> |
|
#{data} |
|
</foreach> |
|
</if> |
|
<if test="orgIds != null and orgIds !='' and orgIds.size() > 0"> |
|
AND sup.org_id IN |
|
<foreach collection="orgIds" item="item" open="(" close=")" separator=","> |
|
#{item} |
|
</foreach> |
|
</if> |
|
<if test="drinkAlcohol != null and drinkAlcohol != '' "> |
|
and stp.isdrink = #{drinkAlcohol} |
|
</if> |
|
</where> |
|
HAVING (age is not null and age > 0) |
|
<if test="gender != null and gender !='' "> |
|
and gender = #{gender} |
|
</if> |
|
<if test=" ageMax != null and ageMax != 0 "> |
|
and (age < #{ageMax} and age > #{ageMin}) |
|
</if> |
|
<if test="policeCodes != null and policeCodes.length > 0"> |
|
and idCode in |
|
<foreach collection="policeCodes" item="code" open="(" separator="," close=")"> |
|
#{code} |
|
</foreach> |
|
</if> |
|
order by RAND() |
|
</select> |
|
|
|
<select id="selectPoliceDataLead" resultType="com.biutag.supervision.pojo.vo.PoliceVo" parameterType="com.biutag.supervision.pojo.vo.SamplingVo"> |
|
SELECT |
|
sup.`name`, |
|
sup.emp_no as empNo, |
|
sup.id_code as idCode, |
|
sdp.short_name as shortName, |
|
sup.person_type as personnelType, |
|
sap.time as crtTime, |
|
stp.isdrink, |
|
sup.org_id as deptId, |
|
CASE WHEN sup.position IS NOT NULL THEN 1 ELSE 0 END AS isLeader, |
|
IFNULL(scp.cjnum,0) as cjnum, |
|
DATEDIFF(CURDATE(), sap.time) AS daysDifference, |
|
YEAR(CURDATE()) - YEAR(STR_TO_DATE(SUBSTRING(sup.id_code, 7, 8), '%Y%m%d')) - |
|
CASE |
|
WHEN DATE_FORMAT(CURDATE(), '%m%d') < DATE_FORMAT(STR_TO_DATE(SUBSTRING(id_code, 7, 8), '%Y%m%d'), '%m%d') THEN 1 |
|
ELSE 0 |
|
END AS age, |
|
CASE |
|
WHEN CAST(SUBSTRING(sup.id_code, 17, 1) AS UNSIGNED) % 2 = 0 THEN '2' |
|
ELSE '1' |
|
END AS gender |
|
from sup_police sup |
|
LEFT JOIN |
|
(SELECT emp_no,max(crt_time) as time from sampling_police) sap on sup.emp_no = sap.emp_no |
|
LEFT JOIN |
|
( |
|
SELECT emp_no, COUNT(emp_no) as cjnum FROM sampling_police |
|
<where> |
|
<if test="startTime != null and startTime !='' and endtime != null and endTime !=''"> |
|
WHERE crt_time BETWEEN #{startTime} AND #{endTime} |
|
</if> |
|
</where> |
|
GROUP BY emp_no |
|
) scp ON sup.emp_no = scp.emp_no |
|
LEFT JOIN sup_depart sdp on sdp.id = sup.org_id |
|
LEFT JOIN (SELECT emp_no, MAX(case when drink_result = "饮酒" THEN 1 ELSE 0 end) as isdrink from sup_task_testing_alcohol_people GROUP BY emp_no) stp on sup.emp_no = stp.emp_no |
|
<where> |
|
sup.position is not null |
|
and sup.del = 0 |
|
<if test="orgIds != null and orgIds != '' and orgIds.size() > 0"> |
|
AND sup.org_id IN |
|
<foreach collection="orgIds" item="item" open="(" close=")" separator=","> |
|
#{item} |
|
</foreach> |
|
</if> |
|
<if test="personnelTypeArray != null and personnelTypeArray != '' and personnelTypeArray.size() > 0"> |
|
and sup.person_type in |
|
<foreach collection="personnelTypeArray" item="data" open="(" close=")" separator=","> |
|
#{data} |
|
</foreach> |
|
</if> |
|
<if test="drinkAlcohol != null and drinkAlcohol != '' "> |
|
and stp.isdrink = #{drinkAlcohol} |
|
</if> |
|
</where> |
|
having (age is not null and age > 0) |
|
<if test=" gender != null and gender !='' "> |
|
and gender = #{gender} |
|
</if> |
|
<if test=" ageMax != null and ageMax != 0 "> |
|
and (age < #{ageMax} and age > #{ageMin}) |
|
</if> |
|
<if test="policeCodes != null and policeCodes.length > 0"> |
|
and idCode in |
|
<foreach collection="policeCodes" item="code" open="(" separator="," close=")"> |
|
#{code} |
|
</foreach> |
|
</if> |
|
order by RAND() |
|
</select> |
|
</mapper>
|
|
|