<?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.TSafeHazardCheckPeopleDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.safeCheck.model.domain.TSafeHazardCheckPeople">
        <id column="id" property="id"/>
        <id column="plan_id" property="planId"/>
        <id column="user_id" property="userId"/>
        <id column="check_type_id" property="checkTypeId"/>
        <id column="frequency_key" property="frequencyKey"/>
        <id column="start_time" property="startTime"/>
        <id column="start_date" property="startDate"/>
        <id column="start_day_num" property="startDayNum"/>
        <id column="start_month_num" property="startMonthNum"/>
        <id column="end_time" property="endTime"/>
        <id column="end_date" property="endDate"/>
        <id column="end_day_num" property="endDayNum"/>
        <id column="end_month_num" property="endMonthNum"/>
        <id column="start_cron_expression" property="startCronExpression"/>
        <id column="end_cron_expression" property="endCronExpression"/>
        <id column="generate_task" property="generateTask"/>
        <id column="user_parent_ids" property="userParentIds"/>
    </resultMap>

    <sql id="select_base_column">
        rs.id, rs.plan_id planId, rs.user_id userId, rs.check_type_id checkTypeId, rs.frequency_key frequencyKey,
        rs.start_time startTime, rs.start_date startDate, rs.start_day_num  startDayNum, rs.start_month_num startMonthNum,
        rs.end_time endTime, rs.end_date endDate, rs.end_day_num endDayNum, rs.end_month_num endMonthNum,rs.generate_task generateTask,
        rs.start_cron_expression startCronExpression, rs.end_cron_expression endCronExpression, rs.user_parent_ids userParentIds,
        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.planId!=null and query.planId!=''">
            and rs.plan_id=#{query.planId}
        </if>
        <if test="query.userId!='' and query.userId!=null">
            and rs.user_id=#{query.userId}
        </if>
        <if test="query.checkTypeId!='' and query.checkTypeId!=null">
            and rs.check_type_id=#{query.checkTypeId}
        </if>
        <if test="query.frequencyKey!='' and query.frequencyKey!=null">
            and rs.frequencyKey=#{query.frequencyKey}
        </if>
    </sql>

    <select id="listVOByPlan" resultType="com.testor.module.safeCheck.model.vo.SafeHazardCheckPeopleVO">
        select su.user_name as userName, dd.dict_value checkTypeName, dd.dict_key checkTypeKey,
        <include refid="select_base_column" />
        from t_safe_hazard_check_people rs
        left join t_sys_user su on rs.user_id = su.user_id
        left join t_sys_dict_data dd on rs.check_type_id = dd.dict_data_id
        <where>
            rs.status = '0'
            and rs.plan_id=#{planId}
        </where>
    </select>

    <select id="listDoingVOByPlanDate" resultType="com.testor.module.safeCheck.model.vo.SafeHazardCheckPeopleVO">
    select
        <include refid="select_base_column" />
        from t_safe_hazard_check_people rs
        inner join t_safe_hazard_check_plan cp on cp.id = rs.plan_id
        <where>
            rs.status = '0'
            <if test="doingDate!=null">
                and #{doingDate} >= cp.start_date
                and cp.end_date >= #{doingDate}
            </if>
        </where>
    </select>
</mapper>