<?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 * FROM (
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime,deductTime,1 AS checkType ,'attend' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>

        <if test="checkTimeStart != null and checkTimeStart!=''"> AND errorTime <![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 errorTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime,deductTime,4 AS checkType ,'effect' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND happenTime <![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 happenTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,6 AS checkType ,'complain' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND complainTime <![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 complainTime <![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, subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,3 AS checkType ,'gowork' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND goworkTime <![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 goworkTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,2 AS checkType ,'review' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>

        <if test="checkTimeStart != null and checkTimeStart!=''"> AND reviewTime <![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 reviewTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,5 AS checkType ,'other' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>

        <if test="checkTimeStart != null and checkTimeStart!=''"> AND happenTime <![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 happenTime <![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>
        ) AS a
        where 1=1
        <if test="subMethodList != null">
            and subMethod in
            <foreach collection="subMethodList" open="(" close=")" index="index" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="orderColList != null and !orderColList.isEmpty()">
            order by
            <trim suffixOverrides=","  suffix="">
                <foreach collection="orderColList" open="" close="" index="index" item="item" separator=",">
                    ${item.colName} ${item.sortKind}
                </foreach>
            </trim>
        </if>

    </select>

    <select id="getListCount" parameterType="com.mortals.xhx.module.check.model.CheckAllRecordQuery" resultType="int">
        SELECT count(1) FROM (
        SELECT id,recordId,staffId,staffName,workNum,deptId,deptName,ruleId,ruleName,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime,deductTime,1 AS checkType ,'attend' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>

        <if test="checkTimeStart != null and checkTimeStart!=''"> AND errorTime <![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 errorTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime,deductTime,4 AS checkType ,'effect' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND happenTime <![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 happenTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,6 AS checkType ,'complain' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND complainTime <![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 complainTime <![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, subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,3 AS checkType ,'gowork' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="checkTimeStart != null and checkTimeStart!=''"> AND goworkTime <![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 goworkTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,2 AS checkType ,'review' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>

        <if test="checkTimeStart != null and checkTimeStart!=''"> AND reviewTime <![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 reviewTime <![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,subAddType,checkStatus,checkResult,auditStatus,createTime,score,subMethod,checkTime, deductTime,5 AS checkType ,'other' AS performType,updateTime 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="subAddType != null and subAddType!=''"> AND subAddType = #{subAddType} </if>
        <if test="staffId != null and staffId!=''"> AND staffId = #{staffId} </if>
        <if test="createTimeStart != null and createTimeStart!=''"> AND createTime <![CDATA[ >= ]]> STR_TO_DATE(left(concat(#{createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') </if>
        <if test="createTimeEnd != null and createTimeEnd!=''"> AND createTime <![CDATA[ <= ]]> STR_TO_DATE(left(concat(#{createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') </if>

        <if test="checkTimeStart != null and checkTimeStart!=''"> AND happenTime <![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 happenTime <![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>
        ) AS a
        where 1=1
        <if test="subMethodList != null">
            and subMethod in
            <foreach collection="subMethodList" open="(" close=")" index="index" item="item" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="getScoreSummary" parameterType="com.mortals.xhx.module.check.model.vo.StaffCheckSummaryQuery" resultType="com.mortals.xhx.module.check.model.vo.CheckAllScoreSummaryVo">
        SELECT sum(0-a.initScore) AS initScore,sum(0-a.checkScore) AS checkScore,sum(a.appealScore) AS appealScore,sum(0-a.checkScore-a.appealScore) AS total FROM (
        SELECT sum(CASE subMethod WHEN 4 THEN 0 ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) as initScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN 0  ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) ELSE 0 END) ELSE 0 END) checkScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN (CASE subAddType WHEN 1 THEN score ELSE score*-1 END)  ELSE 0 END) ELSE 0 END) ELSE 0 END) appealScore
        FROM mortals_xhx_check_attend_record WHERE 1=1
        <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>
        UNION

        SELECT sum(CASE subMethod WHEN 4 THEN 0 ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) as initScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN 0  ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) ELSE 0 END) ELSE 0 END) checkScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN (CASE subAddType WHEN 1 THEN score ELSE score*-1 END)  ELSE 0 END) ELSE 0 END) ELSE 0 END) appealScore
        FROM mortals_xhx_check_effect_record WHERE 1=1
        <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>
        UNION

        SELECT sum(CASE subMethod WHEN 4 THEN 0 ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) as initScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN 0  ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) ELSE 0 END) ELSE 0 END) checkScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN (CASE subAddType WHEN 1 THEN score ELSE score*-1 END)  ELSE 0 END) ELSE 0 END) ELSE 0 END) appealScore
        FROM mortals_xhx_check_complain_record WHERE 1=1
        <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>

        UNION
        SELECT sum(CASE subMethod WHEN 4 THEN 0 ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) as initScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN 0  ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) ELSE 0 END) ELSE 0 END) checkScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN (CASE subAddType WHEN 1 THEN score ELSE score*-1 END)  ELSE 0 END) ELSE 0 END) ELSE 0 END) appealScore
        FROM mortals_xhx_check_gowork_record WHERE 1=1
        <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>

        UNION
        SELECT sum(CASE subMethod WHEN 4 THEN 0 ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) as initScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN 0  ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) ELSE 0 END) ELSE 0 END) checkScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN (CASE subAddType WHEN 1 THEN score ELSE score*-1 END)  ELSE 0 END) ELSE 0 END) ELSE 0 END) appealScore
        FROM mortals_xhx_check_review_record WHERE 1=1
        <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>

        UNION
        SELECT sum(CASE subMethod WHEN 4 THEN 0 ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) as initScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN 0  ELSE (CASE subAddType WHEN 1 THEN score ELSE score*-1 END) END) ELSE 0 END) ELSE 0 END) checkScore,
        sum(CASE checkStatus WHEN 2 THEN (CASE auditStatus WHEN 1 THEN (CASE subMethod WHEN 4 THEN (CASE subAddType WHEN 1 THEN score ELSE score*-1 END)  ELSE 0 END) ELSE 0 END) ELSE 0 END) appealScore
        FROM mortals_xhx_check_other_record WHERE 1=1
        <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>
        ) AS a
    </select>
</mapper>