<?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.dsk.system.mapper.BusinessBacklogMapper">

    <resultMap type="com.dsk.common.core.domain.entity.BusinessBacklog" id="BusinessBacklogResult">
        <result property="id" column="id"/>
        <result property="businessId" column="business_id"/>
        <result property="target" column="target"/>
        <result property="task" column="task"/>
        <result property="finishTime" column="finish_time"/>
        <result property="state" column="state"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBusinessBacklogVo">
        select id,
               business_id,
               target,
               task,
               finish_time,
               state,
               create_time,
               update_time
        from business_backlog
    </sql>

    <select id="selectBusinessBacklogList" parameterType="com.dsk.common.core.domain.entity.BusinessBacklog"
            resultMap="BusinessBacklogResult">
        <include refid="selectBusinessBacklogVo"/>
        <where>
            <if test="businessId != null ">and business_id = #{businessId}</if>
            <if test="target != null  and target != ''">and target = #{target}</if>
            <if test="task != null  and task != ''">and task = #{task}</if>
            <if test="finishTime != null ">and finish_time = #{finishTime}</if>
            <if test="state != null ">and state = #{state}</if>
        </where>
        ORDER BY create_time DESC
    </select>

    <select id="selectBusinessBacklogById" parameterType="Long" resultMap="BusinessBacklogResult">
        <include refid="selectBusinessBacklogVo"/>
        where id = #{id}
    </select>

    <insert id="insertBusinessBacklog" parameterType="com.dsk.common.core.domain.entity.BusinessBacklog"
            useGeneratedKeys="true" keyProperty="id">
        insert into business_backlog
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="target != null">target,</if>
            <if test="task != null">task,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="state != null">state,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="target != null">#{target},</if>
            <if test="task != null">#{task},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="state != null">#{state},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateBusinessBacklog" parameterType="com.dsk.common.core.domain.entity.BusinessBacklog">
        update business_backlog
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="target != null">target = #{target},</if>
            <if test="task != null">task = #{task},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="state != null">state = #{state},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBacklogByBusinessId" parameterType="Long">
        delete
        from business_backlog
        where business_id = #{businessId}
    </delete>

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