<?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.inspect.taskstatus.mapper.PatrolTaskStatusMapper">

    <resultMap type="PatrolTaskStatus" id="PatrolTaskStatusResult">
        <result property="lineId" column="line_id"/>
        <result property="taskPatrolledId" column="task_patrolled_id"/>
        <result property="taskName" column="task_name"/>
        <result property="taskCode" column="task_code"/>
        <result property="taskState" column="task_state"/>
        <result property="planStartTime" column="plan_start_time"/>
        <result property="startTime" column="start_time"/>
        <result property="taskProgress" column="task_progress"/>
        <result property="taskEstimatedTime" column="task_estimated_time"/>
        <result property="description" column="description"/>
        <result property="posType" column="pos_type"/>
        <result property="code" column="code"/>
        <result property="pos" column="pos"/>
        <result property="patrolType" column="patrol_type"/>
        <result property="endTime" column="end_time"/>
        <result property="execType" column="exec_type"/>
        <result property="beginTime" column="beginTime"/>
        <result property="taskType" column="task_type"/>
        <result property="mainId" column="main_id"/>
        <result property="specifiedAlg" column="specified_alg"/>
        <collection property="children"
                    ofType="PatrolTaskStatus"
                    select="selectPatrolTaskStatusListByMainId"
                    column="task_patrolled_id"
        />
    </resultMap>

    <resultMap type="PatrolTaskStatus" id="PatrolTaskStatusResultV2">
        <result property="lineId" column="line_id"/>
        <result property="taskPatrolledId" column="task_patrolled_id"/>
        <result property="taskName" column="task_name"/>
        <result property="taskCode" column="task_code"/>
        <result property="taskState" column="task_state"/>
        <result property="planStartTime" column="plan_start_time"/>
        <result property="startTime" column="start_time"/>
        <result property="taskProgress" column="task_progress"/>
        <result property="taskEstimatedTime" column="task_estimated_time"/>
        <result property="description" column="description"/>
        <result property="posType" column="pos_type"/>
        <result property="code" column="code"/>
        <result property="pos" column="pos"/>
        <result property="patrolType" column="patrol_type"/>
        <result property="endTime" column="end_time"/>
        <result property="execType" column="exec_type"/>
        <result property="taskType" column="task_type"/>
        <result property="beginTime" column="beginTime"/>
        <result property="mainId" column="main_id"/>
        <result property="specifiedAlg" column="specified_alg"/>
        <collection property="children"
                    ofType="PatrolTaskStatus"
                    select="selectPatrolTaskStatusListByMainId"
                    column="task_patrolled_id"
        />
    </resultMap>

    <sql id="selectPatrolTaskStatusVo">
        select line_id,
               task_patrolled_id,
               end_time,
               patrol_type,
               task_name,
               task_code,
               task_state,
               plan_start_time,
               start_time,
               task_progress,
               task_estimated_time,
               description,
               pos_type,
               code,
               pos,
               exec_type,
               task_type,
               main_id,
               summary
        from patrol_task_status
    </sql>

    <select id="selectPatrolTaskStatusCount" parameterType="PatrolTaskStatus" resultMap="PatrolTaskStatusResult">
        select a.* from patrol_task_status a
        <where>

            <if test="taskCode != null  and taskCode != ''">and a.task_code = #{taskCode}</if>
            <if test="taskState != null  and taskState != ''">and a.task_state = #{taskState}</if>
            <if test="description != null  and description != ''">and a.description != #{description}</if>
            <if test="startTime != null ">
                and date_format(a.start_time,'%y%m') = date_format(#{startTime},'%y%m')
            </if>

            <if test="beginTime != null ">
                and date_format(a.start_time,'%y%m%d') = date_format(#{beginTime},'%y%m%d')
            </if>

        </where>
    </select>

    <select id="selectPatrolTaskStatusList" parameterType="PatrolTaskStatus" resultMap="PatrolTaskStatusResult">
          SELECT
            a.line_id,
            a.task_patrolled_id,
            a.task_name,
            a.task_code,
            a.task_state,
            a.plan_start_time,
            a.start_time,
            a.task_progress,
            a.task_estimated_time,
            a.description,
            a.pos_type,
            a.code,
            a.pos,
            a.end_time,
            b.type as patrol_type,
            a.task_type,
            a.main_id,
            a.summary,
            b.execution_status as exec_type,
            b.specified_alg
            from patrol_task_status a
            LEFT JOIN patrol_task b on a.task_code=b.task_code
        <where>
            <if test="filterTaskType != null  and filterTaskType != ''">and a.task_type != #{filterTaskType}
            </if>
            <if test="taskPatrolledId != null  and taskPatrolledId != ''">and a.task_patrolled_id = #{taskPatrolledId}
            </if>
            <if test="taskName != null and taskName != ''">
                and a.task_name like concat('%', #{taskName}, '%')
            </if>
            <if test="areaTaskName != null and areaTaskName != ''">
                and b.area_name like concat('%', #{areaTaskName}, '%')
            </if>
            <if test="taskCode != null  and taskCode != ''">and a.task_code = #{taskCode}</if>
            <if test="taskState != null  and taskState != ''">and a.task_state = #{taskState}</if>
            <if test="planStartTime != null ">and a.plan_start_time = #{planStartTime}</if>
            <if test="startTime != null ">
                and date_format(a.start_time,'%y%m%d') >= date_format(#{startTime},'%y%m%d')
            </if>
            <if test="createTime != null ">and date_format(a.create_time,'%y%m%d') =
                date_format(#{createTime},'%y%m%d')
            </if>
            <if test="taskProgress != null  and taskProgress != ''">and a.task_progress = #{taskProgress}</if>
            <if test="taskEstimatedTime != null  and taskEstimatedTime != ''">and a.task_estimated_time =
                #{taskEstimatedTime}
            </if>
            <if test="description != null  and description != ''">and a.description = #{description}</if>
            <if test="posType != null  and posType != ''">and a.pos_type = #{posType}</if>
            <if test="code != null  and code != ''">and a.code = #{code}</if>
            <if test="pos != null  and pos != ''">and a.pos = #{pos}</if>
            <if test="patrolType != null  and patrolType != ''">and b.type = #{patrolType}</if>
            <if test="beginTime != null and beginTime != ''">
                and date_format(a.start_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''">
                and date_format(a.start_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        ORDER BY line_id desc
    </select>

    <select id="selectPatrolTaskStatusPage" resultType="com.inspect.taskstatus.domain.PatrolTaskStatus">
        a.line_id,
        a.task_patrolled_id,
        a.task_name,
        a.task_code,
        a.task_state,
        a.plan_start_time,
        a.start_time,
        a.task_progress,
        a.task_estimated_time,
        a.description,
        a.pos_type,
        a.code,
        a.pos,
        a.end_time,
        b.type as patrol_type,
        a.task_type,
        a.main_id,
        b.execution_status as exec_type
        from patrol_task_status a
        LEFT JOIN patrol_task b on a.task_code=b.task_code
        LEFT JOIN
        <where>
            <if test="taskPatrolledId != null  and taskPatrolledId != ''">and a.task_patrolled_id = #{taskPatrolledId}
            </if>
            <if test="taskName != null and taskName != ''">
                and a.task_name like concat('%', #{taskName}, '%')
            </if>
            <if test="areaTaskName != null and areaTaskName != ''">
                and b.area_name like concat('%', #{areaTaskName}, '%')
            </if>
            <if test="taskCode != null  and taskCode != ''">and a.task_code = #{taskCode}</if>
            <if test="taskState != null  and taskState != ''">and a.task_state = #{taskState}</if>
            <if test="planStartTime != null ">and a.plan_start_time = #{planStartTime}</if>
            <if test="startTime != null ">
                and date_format(a.start_time,'%y%m%d') >= date_format(#{startTime},'%y%m%d')
            </if>
            <if test="createTime != null ">and date_format(a.create_time,'%y%m%d') =
                date_format(#{createTime},'%y%m%d')
            </if>
            <if test="taskProgress != null  and taskProgress != ''">and a.task_progress = #{taskProgress}</if>
            <if test="taskEstimatedTime != null  and taskEstimatedTime != ''">and a.task_estimated_time =
                #{taskEstimatedTime}
            </if>
            <if test="description != null  and description != ''">and a.description = #{description}</if>
            <if test="posType != null  and posType != ''">and a.pos_type = #{posType}</if>
            <if test="code != null  and code != ''">and a.code = #{code}</if>
            <if test="pos != null  and pos != ''">and a.pos = #{pos}</if>
            <if test="patrolType != null  and patrolType != ''">and b.type = #{patrolType}</if>
            <if test="beginTime != null and beginTime != ''">
                and date_format(a.start_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''">
                and date_format(a.start_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
            AND task_type != 2
            AND main_id IS NULL
        </where>
        ORDER BY line_id desc

    </select>

    <resultMap type="TaskCount" id="TaskCountResult">
        <result property="callName" column="callName"/>
        <result property="descName" column="descName"/>
        <result property="count" column="count"/>
        <result property="completeName" column="completeName"/>
    </resultMap>

    <select id="selectCountList" parameterType="PatrolTaskStatus" resultMap="TaskCountResult">
        <!-- select count(*) as count ,start_time  as  callName,max(task_name) as descName ,
         sum(case when task_state= 1 then 1 else 0 end)as total ,
         convert(sum(case when task_state= 1 then 1 else 0 end)/count(*) *100 ,decimal(15,2)) as completeName
         from patrol_task_status
         <where>
             <if test="beginTime != null and beginTime != ''">
                 and date_format(start_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
             </if>
             <if test="endTime != null and endTime != ''">
                 and date_format(start_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
             </if>
         </where>
         GROUP BY start_time-->

        SELECT
        count( * ) AS count,
        max( a.task_name ) AS descName,
        sum( CASE WHEN a.task_state = 1 THEN 1 ELSE 0 END ) AS total,
        CONVERT (sum( CASE WHEN a.task_state = 1 THEN 1 ELSE 0 END ) / count( * ) * 100,DECIMAL ( 15, 2 ) ) AS completeName
        ,
        a.asd AS callName
        FROM
        ( SELECT task_name,task_state,start_time, date_format( start_time, '%Y-%m-%d' ) AS asd FROM patrol_task_status )
        a
        <where>
            <if test="beginTime != null and beginTime != ''">
                and date_format(a.start_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''">
                and date_format(a.start_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        GROUP BY
        a.asd

    </select>


    <select id="selectCountListByDate" parameterType="PatrolTaskStatus" resultMap="TaskCountResult">
        SELECT d.callName,d.descName,CONCAT(d.total,' / ',d.count) as count ,d.completeName FROM (SELECT
        count( * ) AS count,
        max( a.task_name ) AS descName,
        sum( CASE WHEN a.task_state = 1 THEN 1 ELSE 0 END ) AS total,
        CONVERT (
        sum( CASE WHEN a.task_state = 1 THEN 1 ELSE 0 END ) / count( * ) * 100,
        DECIMAL ( 15, 2 )
        ) AS completeName,
        a.asd AS callName
        FROM
        ( SELECT task_name, task_state, start_time, date_format( start_time, '%Y-%m-%d' ) AS asd FROM patrol_task_status
        ) a
        <where>
            <if test="beginTime != null and beginTime != ''">
                and date_format(a.start_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''">
                and date_format(a.start_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        GROUP BY
        a.asd,a.task_name) d
    </select>

    <select id="selectPatrolTaskStatusByLineId" parameterType="Long" resultMap="PatrolTaskStatusResult">
        SELECT
        pts.line_id,
        pts.task_patrolled_id,
        pts.end_time,
        pts.patrol_type,
        pts.task_name,
        pts.task_code,
        pts.task_state,
        pts.plan_start_time,
        pts.start_time,
        pts.task_progress,
        pts.task_estimated_time,
        pts.description,
        pts.pos_type,
        pts.code,
        pts.pos,
        pts.exec_type,
        pts.task_type,
        pts.main_id,
        pts.summary,
        t.specified_alg
        FROM patrol_task_status pts
        LEFT JOIN patrol_task t ON pts.task_code = t.task_code
        where pts.line_id = #{lineId}
    </select>

    <select id="selectPatrolTaskStatusByTaskPatrolledId" parameterType="String" resultMap="PatrolTaskStatusResult">
        SELECT
            pts.line_id,
            pts.task_patrolled_id,
            pts.end_time,
            pts.patrol_type,
            pts.task_name,
            pts.task_code,
            pts.task_state,
            pts.plan_start_time,
            pts.start_time,
            pts.task_progress,
            pts.task_estimated_time,
            pts.description,
            pts.pos_type,
            pts.code,
            pts.pos,
            pts.exec_type,
            pts.task_type,
            pts.main_id,
            pts.summary,
            t.specified_alg
        FROM patrol_task_status pts
                 LEFT JOIN patrol_task t ON pts.task_code = t.task_code
        WHERE pts.task_patrolled_id = #{taskPatrolledId}
    </select>

    <select id="selectPatrolTaskStatusListByTaskPatrolledIds"
            resultMap="PatrolTaskStatusResult">
        <include refid="selectPatrolTaskStatusVo"/>
        where task_patrolled_id in
        <foreach collection="taskPatrolledIds" item="taskPatrolledId" open="(" separator="," close=")">
            #{taskPatrolledId}
        </foreach>
    </select>

    <select id="selectDailyStatsByYearAndMonth" resultType="com.inspect.calender.domain.DailyTaskStatsDTO">
        SELECT task_patrolled_id as id, task_name as name, task_state as taskState, start_time as startTime, end_time as endTime
        FROM patrol_task_status
        WHERE YEAR(create_time) = #{year} AND MONTH(create_time) = #{month} AND task_state IN (1,2,5)
        ORDER BY create_time
    </select>

    <select id="selectDailyStatsByYearAndMonthAndDay"
            resultType="com.inspect.calender.domain.DailyTaskStatsDTO">
        SELECT task_patrolled_id as id, task_name as name, task_state as taskState, start_time as startTime, end_time as endTime
        FROM patrol_task_status
        WHERE YEAR(create_time) = #{year} AND MONTH(create_time) = #{month} AND DAY(create_time) = #{day} AND task_state IN (1,2,5)
        ORDER BY create_time
    </select>

    <select id="countMonthlyStatsByYear" resultType="com.inspect.calender.domain.MonthlyTaskStatsDTO" parameterType="Integer">
        SELECT m.month AS month,
               COALESCE(SUM(CASE WHEN t.task_state = 1 THEN 1 ELSE 0 END), 0) AS executed,
               COALESCE(SUM(CASE WHEN t.task_state = 2 THEN 1 ELSE 0 END), 0) AS executing,
               COALESCE(SUM(CASE WHEN t.task_state = 5 THEN 1 ELSE 0 END), 0) AS pending
        FROM (
                 SELECT 1 AS month UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6
                 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12
             ) m
                 LEFT JOIN patrol_task_status t
                           ON m.month = MONTH(t.create_time)
                               AND YEAR(t.create_time) = #{year}
        GROUP BY m.month
        ORDER BY m.month
    </select>
    <select id="selectPatrolTaskStatusListByMainId" resultMap="PatrolTaskStatusResult">
        <include refid="selectPatrolTaskStatusVo"/>
        where main_id = #{taskPatrolledId}
    </select>

    <select id="selectPatrolTaskStatusMain" resultMap="PatrolTaskStatusResult" parameterType="String">
        select a.* from patrol_task_status a
        where a.task_patrolled_id = (
            SELECT
                CASE
                    WHEN b.main_id is null THEN b.task_patrolled_id
                    ELSE b.main_id
                    END
            FROM patrol_task_status b where b.task_patrolled_id = #{taskPatrolledId}
        )
    </select>

    <select id="selectExecutedPointsAndAlgs" resultType="java.util.Map">
        SELECT a.objectId AS patrol_point_id, s.alg_subtype_id
        FROM result_analysis a
                 LEFT JOIN basedata_alg_subtype s ON a.alg_type = s.alg_subtype_code
                 LEFT JOIN patrol_task_status t ON a.task_patrol_id = t.task_patrolled_id
        WHERE a.filter = 1
          AND (t.task_patrolled_id = #{taskPatrolledId} or t.main_id = #{taskPatrolledId})
    </select>

    <select id="selectTotalPointsAndAlgs" resultType="java.util.Map">
        SELECT p.patrol_point_id, p.alg_subtype_ids
        FROM basedata_patrolpoint p
                 LEFT JOIN patrol_task_info i ON p.patrol_point_id = i.device_id
                 LEFT JOIN basedata_eqpbook e ON i.ebook_id = e.eqp_book_id
        where i.task_major_id = #{taskCode}
    </select>

    <insert id="insertPatrolTaskStatus" parameterType="PatrolTaskStatus" useGeneratedKeys="true" keyProperty="lineId">
        insert into patrol_task_status
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskPatrolledId != null">task_patrolled_id,</if>
            <if test="taskName != null">task_name,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="taskState != null">task_state,</if>
            <if test="planStartTime != null">plan_start_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="taskProgress != null">task_progress,</if>
            <if test="taskEstimatedTime != null">task_estimated_time,</if>
            <if test="description != null">description,</if>
            <if test="posType != null">pos_type,</if>
            <if test="code != null">code,</if>
            <if test="pos != null">pos,</if>
            <if test="patrolType != null">patrol_type,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="execType != null">exec_type,</if>
            <if test="taskType != null">task_type,</if>
            <if test="mainId != null">main_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskPatrolledId != null">#{taskPatrolledId},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="taskState != null">#{taskState},</if>
            <if test="planStartTime != null">#{planStartTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="taskProgress != null">#{taskProgress},</if>
            <if test="taskEstimatedTime != null">#{taskEstimatedTime},</if>
            <if test="description != null">#{description},</if>
            <if test="posType != null">#{posType},</if>
            <if test="code != null">#{code},</if>
            <if test="pos != null">#{pos},</if>
            <if test="patrolType != null">#{patrolType},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="execType != null">#{execType},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="mainId != null">#{mainId},</if>
        </trim>
    </insert>
    <insert id="insertIgnorePatrolTaskStatus" useGeneratedKeys="true" keyProperty="lineId">
        insert ignore into patrol_task_status
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskPatrolledId != null">task_patrolled_id,</if>
            <if test="taskName != null">task_name,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="taskState != null">task_state,</if>
            <if test="planStartTime != null">plan_start_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="taskProgress != null">task_progress,</if>
            <if test="taskEstimatedTime != null">task_estimated_time,</if>
            <if test="description != null">description,</if>
            <if test="posType != null">pos_type,</if>
            <if test="code != null">code,</if>
            <if test="pos != null">pos,</if>
            <if test="patrolType != null">patrol_type,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="execType != null">exec_type,</if>
            <if test="taskType != null">task_type,</if>
            <if test="mainId != null">main_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskPatrolledId != null">#{taskPatrolledId},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="taskState != null">#{taskState},</if>
            <if test="planStartTime != null">#{planStartTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="taskProgress != null">#{taskProgress},</if>
            <if test="taskEstimatedTime != null">#{taskEstimatedTime},</if>
            <if test="description != null">#{description},</if>
            <if test="posType != null">#{posType},</if>
            <if test="code != null">#{code},</if>
            <if test="pos != null">#{pos},</if>
            <if test="patrolType != null">#{patrolType},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="execType != null">#{execType},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="mainId != null">#{mainId},</if>
        </trim>
    </insert>

    <update id="updatePatrolTaskStatus" parameterType="PatrolTaskStatus">
        update patrol_task_status
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskPatrolledId != null">task_patrolled_id = #{taskPatrolledId},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="taskCode != null">task_code = #{taskCode},</if>
            <if test="taskState != null">task_state = #{taskState},</if>
            <if test="planStartTime != null">plan_start_time = #{planStartTime},</if>
            <!--<if test="startTime != null">start_time = #{startTime},</if>-->
            <if test="taskProgress != null">task_progress = #{taskProgress},</if>
            <if test="taskEstimatedTime != null">task_estimated_time = #{taskEstimatedTime},</if>
            <if test="description != null and description != ''">description = #{description},</if>
            <if test="posType != null">pos_type = #{posType},</if>
            <if test="code != null">code = #{code},</if>
            <if test="pos != null">pos = #{pos},</if>
            <if test="patrolType != null">patrol_type = #{patrolType},</if>
            <if test="summary != null and summary != ''">summary = #{summary},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <update id="updatePatrolTaskStatusOfTaskProgress" parameterType="PatrolTaskStatus">
        update patrol_task_status
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskProgress != null">task_progress = #{taskProgress},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <update id="updatePatrolTaskStatusRunning" parameterType="PatrolTaskStatus">
        update patrol_task_status
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskProgress != null">task_progress = #{taskProgress},</if>
            <if test="taskState != null">task_state = #{taskState},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <update id="updatePatrolTaskStatusOfTaskState" parameterType="PatrolTaskStatus">
        update patrol_task_status
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskState != null">task_state = #{taskState},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <update id="updatePatrolTaskStatusOfTaskStateAndEndTime" parameterType="PatrolTaskStatus">
        update patrol_task_status
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskState != null">task_state = #{taskState},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <delete id="deletePatrolTaskStatusByLineId" parameterType="Long">
        delete
        from patrol_task_status
        where line_id = #{lineId}
    </delete>

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