<?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.usky.fire.mapper.PatrolInspectionPlanMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.PatrolInspectionPlan">
        <id column="id" property="id"/>
        <result column="plan_name" property="planName"/>
        <result column="start_date" property="startDate"/>
        <result column="end_date" property="endDate"/>
        <result column="area_id" property="areaId"/>
        <result column="plan_type" property="planType"/>
        <result column="plan_cycle" property="planCycle"/>
        <result column="plan_frequency" property="planFrequency"/>
        <result column="lap_time" property="lapTime"/>
        <result column="interval_time" property="intervalTime"/>
        <result column="plan_describe" property="planDescribe"/>
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="enable" property="enable"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="company_id" property="companyId"/>
        <result column="rest_day" property="restDay"/>
        <result column="week_count" property="weekCount"/>
        <result column="route_id" property="routeId" />
    </resultMap>
    <select id="planSiteCount" resultType="int">
        SELECT
        count(1)
        FROM
        patrol_inspection_plan_son AS p
        JOIN patrol_inspection_plan_site_son AS ps ON p.id = ps.plan_id
        <where>
            ps.site_id =#{siteId}
            AND p.inspection_date = #{inspectionDate}
            AND p.personnel_id in
            <foreach item="item" collection="personnelIdList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </where>
    </select>
    <select id="selectNoPlanList" resultType="com.usky.fire.domain.PatrolInspectionPlan">
        select
        *
        from patrol_inspection_plan
        <where>
            enable = 1
            and id in
            <foreach item="item" collection="planIdList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </where>
    </select>
</mapper>
