<?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.metadata.montdata.mapper.BasedataMontTaskStaDataMapper">

    <resultMap type="com.inspect.metadata.montdata.domain.BasedataMontTaskStaData" id="BasedataMontTaskStaDataResult">
        <result property="dataId" column="data_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="taskStateName" column="task_state_name"/>
        <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="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteFlag" column="delete_flag"/>
    </resultMap>

    <sql id="selectBasedataMontTaskStaDataVo">
        select data_id,
               task_patrolled_id,
               task_name,
               task_code,
               task_state,
               task_state_name,
               plan_start_time,
               start_time,
               task_progress,
               task_estimated_time,
               description,
               create_by,
               create_time,
               update_by,
               update_time,
               delete_flag
        from basedata_mont_taskstadata
    </sql>

    <select id="selectBasedataMontTaskStaDataList" parameterType="com.inspect.metadata.montdata.domain.BasedataMontTaskStaData"
            resultMap="BasedataMontTaskStaDataResult">
        <include refid="selectBasedataMontTaskStaDataVo"/>
        <where>
            <if test="taskPatrolledId != null  and taskPatrolledId != ''">and task_patrolled_id =
                #{taskPatrolledId}
            </if>
            <if test="taskName != null  and taskName != ''">and task_name like concat('%', #{taskName}, '%')</if>
            <if test="taskCode != null  and taskCode != ''">and task_code = #{taskCode}</if>
            <if test="taskState != null  and taskState != ''">and task_state = #{taskState}</if>
            <if test="taskStateName != null  and taskStateName != ''">and task_state_name like concat('%',
                #{taskStateName}, '%')
            </if>
            <if test="planStartTime != null  and planStartTime != ''">and plan_start_time = #{planStartTime}</if>
            <if test="startTime != null  and startTime != ''">and start_time = #{startTime}</if>
            <if test="taskProgress != null  and taskProgress != ''">and task_progress = #{taskProgress}</if>
            <if test="taskEstimatedTime != null  and taskEstimatedTime != ''">and task_estimated_time =
                #{taskEstimatedTime}
            </if>
            <if test="description != null  and description != ''">and description = #{description}</if>
            <if test="deleteFlag != null  and deleteFlag != ''">and delete_flag = #{deleteFlag}</if>
        </where>
    </select>

    <select id="selectBasedataMontTaskStaDataByTaskStaDataId" parameterType="Long"
            resultMap="BasedataMontTaskStaDataResult">
        <include refid="selectBasedataMontTaskStaDataVo"/>
        where data_id = #{dataId}
    </select>

    <insert id="insertBasedataMontTaskStaData" parameterType="com.inspect.metadata.montdata.domain.BasedataMontTaskStaData" useGeneratedKeys="true"
            keyProperty="dataId">
        insert into basedata_mont_taskstadata
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskPatrolledId != null and taskPatrolledId != ''">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="taskStateName != null">task_state_name,</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="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleteFlag != null">delete_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskPatrolledId != null and taskPatrolledId != ''">#{taskPatrolledId},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="taskState != null">#{taskState},</if>
            <if test="taskStateName != null">#{taskStateName},</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="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleteFlag != null">#{deleteFlag},</if>
        </trim>
    </insert>

    <update id="updateBasedataMontTaskStaData" parameterType="com.inspect.metadata.montdata.domain.BasedataMontTaskStaData">
        update basedata_mont_taskstadata
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskPatrolledId != null and taskPatrolledId != ''">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="taskStateName != null">task_state_name = #{taskStateName},</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">description = #{description},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
        </trim>
        where data_id = #{dataId}
    </update>

    <delete id="deleteBasedataMontTaskStaDataByTaskStaDataId" parameterType="Long">
        delete
        from basedata_mont_taskstadata
        where data_id = #{dataId}
    </delete>

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