<?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.staffing.custom.mapper.StTaskMapper">

    <resultMap type="StTask" id="StTaskResult">
        <result property="id"    column="id"    />
        <result property="taskName"    column="task_name"    />
        <result property="taskDate"    column="task_date"    />
        <result property="dayPrice"    column="day_price"    />
        <result property="useNum"    column="use_num"    />
        <result property="codePic"    column="code_pic"    />
        <result property="status"    column="status"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectStTaskVo">
        select id, task_name, task_date, day_price, use_num, code_pic, status, update_time, create_time from st_task
    </sql>

    <select id="selectStTaskList" parameterType="StTask" resultMap="StTaskResult">
        select id, task_name, task_date, day_price, use_num, code_pic, status, update_time, create_time
        <if test="params.order != null">
            , (task_date >= #{params.order,jdbcType=DATE}) as progress_status
        </if>
        from st_task

        <where>
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="taskDate != null"> and task_date = #{taskDate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="dateStatus != null ">
                <if test="dateStatus == 1 ">
                    <![CDATA[ and task_date >= #{taskDateCompare,jdbcType=DATE}]]>
                </if>
                <if test="dateStatus == 2 ">
                    <![CDATA[ and task_date < #{taskDateCompare,jdbcType=DATE}]]>
                </if>
            </if>
            <if test="taskIds != null ">
                and id in
                <foreach collection="taskIds" index="index" item="item" open="(" separator="," close=")">
                    (#{item})
                </foreach>
            </if>
        </where>
        <if test="params.order != null">
            order by progress_status desc, create_time desc
        </if>
        <if test="params.order == null">
            order by create_time desc
        </if>
    </select>


    <select id="selectStTaskById" parameterType="Long" resultMap="StTaskResult">
        <include refid="selectStTaskVo"/>
        where id = #{id}
    </select>

    <insert id="insertStTask" parameterType="StTask" useGeneratedKeys="true" keyProperty="id">
        insert into st_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">task_name,</if>
            <if test="taskDate != null">task_date,</if>
            <if test="dayPrice != null and dayPrice != ''">day_price,</if>
            <if test="useNum != null">use_num,</if>
            <if test="codePic != null">code_pic,</if>
            <if test="status != null">status,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">#{taskName},</if>
            <if test="taskDate != null">#{taskDate},</if>
            <if test="dayPrice != null and dayPrice != ''">#{dayPrice},</if>
            <if test="useNum != null">#{useNum},</if>
            <if test="codePic != null">#{codePic},</if>
            <if test="status != null">#{status},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateStTask" parameterType="StTask">
        update st_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">task_name = #{taskName},</if>
            <if test="taskDate != null">task_date = #{taskDate},</if>
            <if test="dayPrice != null and dayPrice != ''">day_price = #{dayPrice},</if>
            <if test="useNum != null">use_num = #{useNum},</if>
            <if test="codePic != null">code_pic = #{codePic},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStTaskById" parameterType="Long">
        delete from st_task where id = #{id}
    </delete>

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