<?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.StTaskSignMapper">
    
    <resultMap type="StTaskSign" id="StTaskSignResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="taskName"    column="task_name"    />
        <result property="dayPrice"    column="day_price"    />
        <result property="signTime"    column="sign_time"    />
        <result property="employeeId"    column="employee_id"    />
        <result property="employeeName"    column="employee_name"    />
        <result property="phone"    column="phone"    />
        <result property="idCard"    column="id_card"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectStTaskSignVo">
        select id, task_id, task_name, day_price, sign_time, employee_id, employee_name, phone, id_card, status, remark from st_task_sign
    </sql>

    <select id="selectStTaskSignList" parameterType="StTaskSign" resultMap="StTaskSignResult">
        <include refid="selectStTaskSignVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="employeeId != null "> and employee_id = #{employeeId}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        <if test="orderType == 1">
            order by create_time
        </if>
        <if test="orderType == null">
            order by create_time desc
        </if>

    </select>
    
    <select id="selectStTaskSignById" parameterType="Long" resultMap="StTaskSignResult">
        <include refid="selectStTaskSignVo"/>
        where id = #{id}
    </select>

    <select id="selectStTaskSignByTaskIds"  resultMap="StTaskSignResult">
        <include refid="selectStTaskSignVo"/>
        <where>
            <if test="taskIds != null ">
                and task_id in
                <foreach collection="taskIds" index="index" item="item" open="(" separator="," close=")">
                    (#{item})
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectStTaskSignByTaskIdAndUserId" parameterType="Long" resultMap="StTaskSignResult">
        <include refid="selectStTaskSignVo"/>
        where task_id = #{taskId}
        and employee_id = #{uid}
    </select>


    <insert id="insertStTaskSign" parameterType="StTaskSign" useGeneratedKeys="true" keyProperty="id">
        insert into st_task_sign
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="taskName != null">task_name,</if>
            <if test="dayPrice != null">day_price,</if>
            <if test="signTime != null">sign_time,</if>
            <if test="employeeId != null">employee_id,</if>
            <if test="employeeName != null">employee_name,</if>
            <if test="phone != null">phone,</if>
            <if test="idCard != null">id_card,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="dayPrice != null">#{dayPrice},</if>
            <if test="signTime != null">#{signTime},</if>
            <if test="employeeId != null">#{employeeId},</if>
            <if test="employeeName != null">#{employeeName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateStTaskSign" parameterType="StTaskSign">
        update st_task_sign
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="dayPrice != null">day_price = #{dayPrice},</if>
            <if test="signTime != null">sign_time = #{signTime},</if>
            <if test="employeeId != null">employee_id = #{employeeId},</if>
            <if test="employeeName != null">employee_name = #{employeeName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateStTaskSignByEmId" parameterType="StTaskSign">
        update st_task_sign
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="dayPrice != null">day_price = #{dayPrice},</if>
            <if test="signTime != null">sign_time = #{signTime},</if>
            <if test="employeeId != null">employee_id = #{employeeId},</if>
            <if test="employeeName != null">employee_name = #{employeeName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where employee_id = #{employeeId}
    </update>


    <update id="updateStTaskSignByTaskIdAndEmId" parameterType="StTaskSign">
        update st_task_sign
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="dayPrice != null">day_price = #{dayPrice},</if>
            sign_time = #{signTime},
            <if test="employeeName != null">employee_name = #{employeeName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where task_id = #{taskId} and employee_id = #{employeeId}
    </update>

    <update id="updateStTaskSignByTaskId" parameterType="StTaskSign">
        update st_task_sign
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="dayPrice != null">day_price = #{dayPrice},</if>
            <if test="signTime != null">sign_time = #{signTime},</if>
            <if test="employeeName != null">employee_name = #{employeeName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where task_id = #{taskId}
    </update>
    <delete id="deleteStTaskSignById" parameterType="Long">
        delete from st_task_sign where id = #{id}
    </delete>

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