<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.check.dao.ibatis.CheckAllRecordDaoImpl">

    <select id="getList" parameterType="com.mortals.xhx.module.check.model.CheckAllRecordQuery" resultType="com.mortals.xhx.module.check.model.vo.CheckAllRecordVo">
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,subAddType,score,subMethod,checkTime,createTime AS deductTime,1 AS checkType FROM mortals_xhx_check_attend_record WHERE 1=1
        <if test="checkStatus != null and checkStatus!=''"> AND checkStatus = #{checkStatus} </if>
        <if test="subMethod != null and subMethod!=''"> AND subMethod = #{subMethod} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND checkTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{checkTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeEnd != null and checkTimeEnd!=''"> AND checkTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{checkTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createUserId != null and createUserId!=''"> AND createUserId = #{createUserId} </if>
        UNION
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,2 AS subAddType,score,subMethod,checkTime,createTime AS deductTime,2 AS checkType FROM mortals_xhx_check_effect_record WHERE 1=1
        <if test="checkStatus != null and checkStatus!=''"> AND checkStatus = #{checkStatus} </if>
        <if test="subMethod != null and subMethod!=''"> AND subMethod = #{subMethod} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND checkTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{checkTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeEnd != null and checkTimeEnd!=''"> AND checkTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{checkTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createUserId != null and createUserId!=''"> AND createUserId = #{createUserId} </if>
        UNION
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,2 AS subAddType,score,subMethod,checkTime,createTime AS deductTime,3 AS checkType FROM mortals_xhx_check_complain_record WHERE 1=1
        <if test="checkStatus != null and checkStatus!=''"> AND checkStatus = #{checkStatus} </if>
        <if test="subMethod != null and subMethod!=''"> AND subMethod = #{subMethod} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND checkTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{checkTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeEnd != null and checkTimeEnd!=''"> AND checkTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{checkTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createUserId != null and createUserId!=''"> AND createUserId = #{createUserId} </if>
        UNION
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,2 AS subAddType,score,subMethod,checkTime,createTime AS deductTime,4 AS checkType FROM mortals_xhx_check_gowork_record WHERE 1=1
        <if test="checkStatus != null and checkStatus!=''"> AND checkStatus = #{checkStatus} </if>
        <if test="subMethod != null and subMethod!=''"> AND subMethod = #{subMethod} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND checkTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{checkTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeEnd != null and checkTimeEnd!=''"> AND checkTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{checkTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createUserId != null and createUserId!=''"> AND createUserId = #{createUserId} </if>
        UNION
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,2 AS subAddType,score,subMethod,checkTime,createTime AS deductTime,5 AS checkType FROM mortals_xhx_check_review_record WHERE 1=1
        <if test="checkStatus != null and checkStatus!=''"> AND checkStatus = #{checkStatus} </if>
        <if test="subMethod != null and subMethod!=''"> AND subMethod = #{subMethod} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND checkTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{checkTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeEnd != null and checkTimeEnd!=''"> AND checkTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{checkTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createUserId != null and createUserId!=''"> AND createUserId = #{createUserId} </if>
        UNION
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,2 AS subAddType,score,subMethod,checkTime,createTime AS deductTime,6 AS checkType FROM mortals_xhx_check_other_record WHERE 1=1
        <if test="checkStatus != null and checkStatus!=''"> AND checkStatus = #{checkStatus} </if>
        <if test="subMethod != null and subMethod!=''"> AND subMethod = #{subMethod} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND checkTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{checkTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeEnd != null and checkTimeEnd!=''"> AND checkTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{checkTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createUserId != null and createUserId!=''"> AND createUserId = #{createUserId} </if>
    </select>
</mapper>