<?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.ruoyi.project.patrol.patrol.mapper.TPatrolPlanMapper">

    <resultMap type="TPatrolPlan" id="TPatrolPlanResult">
        <result property="id"    column="id"    />
        <result property="planName"    column="plan_name"    />
        <result property="planYear"    column="plan_year"    />
        <result property="planQuarter"    column="plan_quarter"    />
        <result property="confirmed"    column="confirmed"    />
        <result property="devNum"    column="dev_num"    />
        <result property="detectionFrequency"    column="detection_frequency"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="confirmDate"    column="confirm_date"    />
        <result property="patrolType"    column="patrol_type"    />
        <result property="deadline"    column="deadline"    />
        <result property="checkedNum"    column="checked_num"    />
        <result property="uncheckedNum"    column="unchecked_num"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectTPatrolPlanVo">
        select id,deadline,checked_num,unchecked_num, plan_name,confirm_date,patrol_type, plan_year, plan_quarter, confirmed, dev_num, detection_frequency, del_flag, creater_code, createdate, updater_code, updatedate, remarks, dept_id,status from t_patrol_plan
    </sql>

    <select id="selectTPatrolPlanList" parameterType="TPatrolPlan" resultMap="TPatrolPlanResult">
        <include refid="selectTPatrolPlanVo"/>
        <where>
            <if test="planName != null  and planName != ''"> and plan_name like concat(concat('%', #{planName}), '%')</if>
            <if test="planYear != null  and planYear != ''"> and plan_year = #{planYear}</if>
            <if test="planQuarter != null  and planQuarter != ''"> and plan_quarter = #{planQuarter}</if>
            <if test="confirmed != null  and confirmed != ''"> and confirmed = #{confirmed}</if>
            <if test="devNum != null "> and dev_num = #{devNum}</if>
            <if test="detectionFrequency != null  and detectionFrequency != ''"> and detection_frequency = #{detectionFrequency}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="patrolType != null "> and patrol_type = #{patrolType}</if>
            <if test="uncheckedNum != null "> and unchecked_num = #{uncheckedNum}</if>
            <if test="checkedNum != null "> and checked_num = #{checkedNum}</if>
            <if test="deadline != null "> and deadline = #{deadline}</if>
            <if test="status != null "> and status = #{status}</if>
            and del_flag=0
        </where>
        order by status asc,createdate desc
    </select>

    <select id="selectTPatrolPlanById" parameterType="Long" resultMap="TPatrolPlanResult">
        <include refid="selectTPatrolPlanVo"/>
        where id = #{id}
    </select>

    <insert id="insertTPatrolPlan" parameterType="TPatrolPlan">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_patrol_plan.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_patrol_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="planName != null">plan_name,</if>
            <if test="planYear != null">plan_year,</if>
            <if test="planQuarter != null">plan_quarter,</if>
            <if test="confirmed != null">confirmed,</if>
            <if test="devNum != null">dev_num,</if>
            <if test="detectionFrequency != null">detection_frequency,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="patrolType != null">patrol_type,</if>
            <if test="uncheckedNum != null "> unchecked_num,</if>
            <if test="checkedNum != null "> checked_num,</if>
            <if test="deadline != null "> deadline,</if>
            <if test="status != null "> status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="planName != null">#{planName},</if>
            <if test="planYear != null">#{planYear},</if>
            <if test="planQuarter != null">#{planQuarter},</if>
            <if test="confirmed != null">#{confirmed},</if>
            <if test="devNum != null">#{devNum},</if>
            <if test="detectionFrequency != null">#{detectionFrequency},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="patrolType != null">#{patrolType},</if>
            <if test="uncheckedNum != null "> #{uncheckedNum},</if>
            <if test="checkedNum != null "> #{checkedNum},</if>
            <if test="deadline != null "> #{deadline},</if>
            <if test="status != null "> #{status},</if>
         </trim>
    </insert>

    <update id="updateTPatrolPlan" parameterType="TPatrolPlan">
        update t_patrol_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="planName != null">plan_name = #{planName},</if>
            <if test="planYear != null">plan_year = #{planYear},</if>
            <if test="planQuarter != null">plan_quarter = #{planQuarter},</if>
            <if test="confirmed != null">confirmed = #{confirmed},</if>
            <if test="devNum != null">dev_num = #{devNum},</if>
            <if test="detectionFrequency != null">detection_frequency = #{detectionFrequency},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="confirmDate != null">confirm_date = #{confirmDate},</if>
            <if test="patrolType != null">patrol_type = #{patrolType},</if>
            <if test="uncheckedNum != null ">unchecked_num = #{uncheckedNum},</if>
            <if test="checkedNum != null ">checked_num = #{checkedNum},</if>
            <if test="deadline != null ">deadline = #{deadline},</if>
            <if test="status != null ">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTPatrolPlanById" parameterType="Long">
        delete from t_patrol_plan where id = #{id}
    </delete>

    <delete id="deleteTPatrolPlanByIds" parameterType="String">
        delete from t_patrol_plan where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
