<?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.yunfeiyun.agmp.fms.mapper.FmsTaskpatrolMapper">
    
    <resultMap type="FmsTaskpatrol" id="FmsTaskpatrolResult">
        <result property="taskpatrolId"    column="taskpatrolId"    />
        <result property="taskId"    column="taskId"    />
        <result property="taskpatrolWay"    column="taskpatrolWay"    />
        <result property="taskpatrolAddress"    column="taskpatrolAddress"    />
        <result property="taskpatrolHour"    column="taskpatrolHour"    />
    </resultMap>

    <resultMap id="FmsTaskPatrolListResVo" type="FmsTaskPatrolListResVo" >
        <result property="taskId" column="taskId"/>
        <result property="taskNo" column="taskNo"></result>
        <result property="landName" column="landName"></result>
        <result property="taskpatrolAddress" column="taskpatrolAddress"></result>
        <result property="taskpatrolWay" column="taskpatrolWay"></result>
        <result property="taskpatrolHour" column="taskpatrolHour"></result>
        <result property="taskPlanstartdate" column="taskPlanstartdate"></result>
        <result property="taskPlanenddate" column="taskPlanenddate"></result>
        <result property="taskCreateddate" column="taskCreateddate"></result>
        <result property="taskManagername" column="taskManagername"></result>
        <result property="taskAudittype" column="taskAudittype"></result>
        <result property="taskStatus" column="taskStatus"></result>
        <result property="taskContent" column="taskContent"></result>
        <result property="taskAuditor" column="taskAuditor"></result>

    </resultMap>

    <sql id="selectFmsTaskpatrolVo">
        select taskpatrolId, taskId, taskpatrolWay, taskpatrolAddress, taskpatrolHour from FmsTaskpatrol
    </sql>

    <select id="selectFmsTaskpatrolList" parameterType="FmsTaskPatrolListReqVo" resultMap="FmsTaskPatrolListResVo">
        select t.taskNo,t.taskId, t.taskAuditor, l.landName, p.taskpatrolAddress, p.taskpatrolWay, p.taskpatrolHour, t.taskPlanstartdate, t.taskPlanenddate, t.taskCreateddate, t.taskManagername, t.taskAudittype, t.taskStatus, t.taskContent
        FROM FmsTask t
        LEFT JOIN FmsLand l ON t.landId = l.landId
        LEFT JOIN FmsTaskpatrol p ON t.taskId = p.taskId
        <where>
            <if test="landId != null  and landId != ''"> and t.landId = #{landId}</if>
            <if test="taskpatrolWay != null  and taskpatrolWay != ''"> and p.taskpatrolWay = #{taskpatrolWay}</if>
            <if test="taskAudittype != null  and taskAudittype != ''"> and t.taskAudittype = #{taskAudittype}</if>
            <if test="taskStatus != null  and taskStatus != ''"> and t.taskStatus = #{taskStatus}</if>
            <if test="taskNo != null  and taskNo != ''"> and t.taskNo like concat('%', #{taskNo}, '%')</if>
            <if test="taskManagername != null  and taskManagername != ''"> and t.taskManagername like concat('%', #{taskManagername}, '%')</if>
            <if test="taskPlanstartdate != null  and taskPlanstartdate != '' and taskPlanenddate != null and taskPlanenddate != ''">
                and t.taskPlanstartdate between #{taskPlanstartdate} and #{taskPlanenddate}
            </if>
            <if test="dataFilter == true and landIds != null and landIds.size() > 0">
                AND l.landId in
                <foreach collection="landIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            and t.taskType = -2
        </where>
    </select>
    
    <select id="selectFmsTaskpatrolByTaskpatrolId" parameterType="String" resultMap="FmsTaskpatrolResult">
        <include refid="selectFmsTaskpatrolVo"/>
        where taskpatrolId = #{taskpatrolId}
    </select>

    <select id="selectFmsTaskpatrolByTaskId" parameterType="String" resultMap="FmsTaskpatrolResult">
        <include refid="selectFmsTaskpatrolVo"/>
        where taskId = #{taskId}

    </select>
        
    <insert id="insertFmsTaskpatrol" parameterType="FmsTaskpatrol">
        insert into FmsTaskpatrol
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskpatrolId != null">taskpatrolId,</if>
            <if test="taskId != null">taskId,</if>
            <if test="taskpatrolWay != null">taskpatrolWay,</if>
            <if test="taskpatrolAddress != null">taskpatrolAddress,</if>
            <if test="taskpatrolHour != null">taskpatrolHour,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskpatrolId != null">#{taskpatrolId},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="taskpatrolWay != null">#{taskpatrolWay},</if>
            <if test="taskpatrolAddress != null">#{taskpatrolAddress},</if>
            <if test="taskpatrolHour != null">#{taskpatrolHour},</if>
         </trim>
    </insert>

    <update id="updateFmsTaskpatrol" parameterType="FmsTaskpatrol">
        update FmsTaskpatrol
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">taskId = #{taskId},</if>
            <if test="taskpatrolWay != null">taskpatrolWay = #{taskpatrolWay},</if>
            <if test="taskpatrolAddress != null">taskpatrolAddress = #{taskpatrolAddress},</if>
            <if test="taskpatrolHour != null">taskpatrolHour = #{taskpatrolHour},</if>
        </trim>
        where taskpatrolId = #{taskpatrolId}
    </update>

    <delete id="deleteFmsTaskpatrolByTaskpatrolId" parameterType="String">
        delete from FmsTaskpatrol where taskpatrolId = #{taskpatrolId}
    </delete>

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