<?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.testor.module.safeCheck.dao.TSafeHazardCheckDelayDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.safeCheck.model.domain.TSafeHazardCheckDelay">
        <id column="id" property="id"/>
        <id column="task_id" property="taskId"/>
        <id column="approval_user_id" property="approvalUserId"/>
        <id column="initial_check_date" property="initialCheckDate"/>
        <id column="reason" property="reason"/>
        <id column="approval_opinion" property="approvalOpinion"/>
        <id column="delay_check_date" property="delayCheckDate"/>
        <id column="apply_date" property="applyDate"/>
        <id column="approval_date" property="approvalDate"/>
        <id column="approval_status" property="approvalStatus"/>
        <id column="process_id" property="processId"/>
        <id column="receiver_type" property="receiverType"/>
        <id column="receiver_obj" property="receiverObj"/>
    </resultMap>

    <sql id="select_base_column">
        rs.id, rs.task_id taskId, rs.approval_user_id approvalUserId, rs.initial_check_date initialCheckDate,
        rs.reason, rs.approval_opinion approvalOpinion,rs.delay_check_date delayCheckDate,
        rs.apply_date applyDate, rs.approval_date approvalDate,rs.approval_status approvalStatus,
        rs.process_id processId, rs.receiver_type receiverType,rs.receiver_obj receiverObj,
        rs.status, rs.remarks, rs.create_by createBy, rs.create_date createDate,
        rs.update_by as updateBy, rs.update_date updateDate
    </sql>

    <sql id="common_where_if">
        <if test="query.id!=null and query.id!=''">
            and rs.id=#{query.id}
        </if>
        <if test="query.taskId!=null and query.taskId!=''">
            and rs.task_id=#{query.taskId}
        </if>
        <if test="query.approvalUserId!='' and query.approvalUserId!=null">
            and rs.approval_user_id=#{query.approvalUserId}
        </if>
        <if test="query.approvalStatus!='' and query.approvalStatus!=null">
            and rs.approval_status=#{query.approvalStatus}
        </if>
    </sql>

    <select id="listVOByParam" resultType="com.testor.module.safeCheck.model.vo.SafeHazardCheckDelayVO"
            parameterType="com.testor.module.safeCheck.model.dto.TSafeHazardCheckDelayParam">
        select su.user_name as approvalUserName,
        <include refid="select_base_column" />
        from t_safe_hazard_check_delay rs
        left join t_sys_user su on su.user_id = rs.approval_user_id
        <where>
            rs.status = '0'
            <include refid="common_where_if"></include>
        </where>
    </select>
</mapper>