<?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="org.linlinjava.jz.db.dao.HmEmployTaskMapper">
    <resultMap id="BaseResultMap" type="org.linlinjava.jz.db.domain.HmEmployTask">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="employ_clock_id" jdbcType="BIGINT" property="employClockId"/>
        <result column="employ_relation_id" jdbcType="BIGINT" property="employRelationId"/>
        <result column="category_id" jdbcType="BIGINT" property="categoryId"/>
        <result column="item_id" jdbcType="BIGINT" property="itemId"/>
        <result column="task_start_time" jdbcType="TIMESTAMP" property="taskStartTime"/>
        <result column="task_complete_time" jdbcType="TIMESTAMP" property="taskCompleteTime"/>
        <result column="task_type" jdbcType="DECIMAL" property="taskType"/>
        <result column="delay" jdbcType="BIT" property="delay"/>
        <result column="state" jdbcType="INTEGER" property="state"/>
        <result column="incomplete_reason" jdbcType="VARCHAR" property="incompleteReason"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        id, order_no, employ_clock_id, employ_relation_id, category_id, item_id, task_start_time,
        task_complete_time, task_type, delay, `state`, incomplete_reason, create_time, update_time,
        remark
    </sql>
    <select id="selectByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from hm_employ_task
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="example != null and example.distinct">
            distinct
        </if>
        <choose>
            <when test="selective != null and selective.length &gt; 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_task
        <if test="example != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
        <if test="example != null and example.orderByClause != null">
            order by ${example.orderByClause}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List"/>
        from hm_employ_task
        where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByPrimaryKeySelective" parameterType="map" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <choose>
            <when test="selective != null and selective.length &gt; 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_task
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from hm_employ_task
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <delete id="deleteByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskExample">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from hm_employ_task
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="org.linlinjava.jz.db.domain.HmEmployTask">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into hm_employ_task (order_no, employ_clock_id, employ_relation_id,
        category_id, item_id, task_start_time,
        task_complete_time, task_type, delay,
        `state`, incomplete_reason, create_time,
        update_time, remark)
        values (#{orderNo,jdbcType=VARCHAR}, #{employClockId,jdbcType=BIGINT}, #{employRelationId,jdbcType=BIGINT},
        #{categoryId,jdbcType=BIGINT}, #{itemId,jdbcType=BIGINT}, #{taskStartTime,jdbcType=TIMESTAMP},
        #{taskCompleteTime,jdbcType=TIMESTAMP}, #{taskType,jdbcType=INTEGER}, #{delay,jdbcType=BIT},
        #{state,jdbcType=INTEGER}, #{incompleteReason,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
        #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="org.linlinjava.jz.db.domain.HmEmployTask">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into hm_employ_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">
                order_no,
            </if>
            <if test="employClockId != null">
                employ_clock_id,
            </if>
            <if test="employRelationId != null">
                employ_relation_id,
            </if>
            <if test="categoryId != null">
                category_id,
            </if>
            <if test="itemId != null">
                item_id,
            </if>
            <if test="taskStartTime != null">
                task_start_time,
            </if>
            <if test="taskCompleteTime != null">
                task_complete_time,
            </if>
            <if test="taskType != null">
                task_type,
            </if>
            <if test="delay != null">
                delay,
            </if>
            <if test="state != null">
                `state`,
            </if>
            <if test="incompleteReason != null">
                incomplete_reason,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="remark != null">
                remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">
                #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="employClockId != null">
                #{employClockId,jdbcType=BIGINT},
            </if>
            <if test="employRelationId != null">
                #{employRelationId,jdbcType=BIGINT},
            </if>
            <if test="categoryId != null">
                #{categoryId,jdbcType=BIGINT},
            </if>
            <if test="itemId != null">
                #{itemId,jdbcType=BIGINT},
            </if>
            <if test="taskStartTime != null">
                #{taskStartTime,jdbcType=TIMESTAMP},
            </if>
            <if test="taskCompleteTime != null">
                #{taskCompleteTime,jdbcType=TIMESTAMP},
            </if>
            <if test="taskType != null">
                #{taskType,jdbcType=INTEGER},
            </if>
            <if test="delay != null">
                #{delay,jdbcType=BIT},
            </if>
            <if test="state != null">
                #{state,jdbcType=INTEGER},
            </if>
            <if test="incompleteReason != null">
                #{incompleteReason,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <insert id="batchInsert">
        insert into hm_employ_task
        (order_no, employ_clock_id, employ_relation_id,
        category_id, item_id, task_start_time,
        task_type,`state`) values
        <foreach collection="itemIds" item="item" index="index" close=";" separator=",">
            (#{hmEmployTask.orderNo},
            #{hmEmployTask.employClockId},
            #{hmEmployTask.employRelationId},
            #{hmEmployTask.categoryId},
            #{item},
            #{hmEmployTask.taskStartTime},
            #{hmEmployTask.taskType},
            #{hmEmployTask.state})
        </foreach>
    </insert>
    <insert id="batchInsertWeekTask">
        insert into hm_employ_task
        (order_no, employ_clock_id, employ_relation_id,
        category_id, item_id, task_start_time,
        task_type,`state`) values
        <foreach collection="mapList" item="map" index="index" close=";" separator=",">
            (#{orderNo},
            #{employClockId},
            #{employRelationId},
            #{map.category_id},
            #{map.item_id},
            now(),
            #{map.task_type},
            #{map.state})
        </foreach>
    </insert>
    <select id="countByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskExample"
            resultType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from hm_employ_task
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_task
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=BIGINT},
            </if>
            <if test="record.orderNo != null">
                order_no = #{record.orderNo,jdbcType=VARCHAR},
            </if>
            <if test="record.employClockId != null">
                employ_clock_id = #{record.employClockId,jdbcType=BIGINT},
            </if>
            <if test="record.employRelationId != null">
                employ_relation_id = #{record.employRelationId,jdbcType=BIGINT},
            </if>
            <if test="record.categoryId != null">
                category_id = #{record.categoryId,jdbcType=BIGINT},
            </if>
            <if test="record.itemId != null">
                item_id = #{record.itemId,jdbcType=BIGINT},
            </if>
            <if test="record.taskStartTime != null">
                task_start_time = #{record.taskStartTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.taskCompleteTime != null">
                task_complete_time = #{record.taskCompleteTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.taskType != null">
                task_type = #{record.taskType,jdbcType=INTEGER},
            </if>
            <if test="record.delay != null">
                delay = #{record.delay,jdbcType=BIT},
            </if>
            <if test="record.state != null">
                `state` = #{record.state,jdbcType=INTEGER},
            </if>
            <if test="record.incompleteReason != null">
                incomplete_reason = #{record.incompleteReason,jdbcType=VARCHAR},
            </if>
            <if test="record.createTime != null">
                create_time = #{record.createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.updateTime != null">
                update_time = #{record.updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.remark != null">
                remark = #{record.remark,jdbcType=VARCHAR},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_task
        set id = #{record.id,jdbcType=BIGINT},
        order_no = #{record.orderNo,jdbcType=VARCHAR},
        employ_clock_id = #{record.employClockId,jdbcType=BIGINT},
        employ_relation_id = #{record.employRelationId,jdbcType=BIGINT},
        category_id = #{record.categoryId,jdbcType=BIGINT},
        item_id = #{record.itemId,jdbcType=BIGINT},
        task_start_time = #{record.taskStartTime,jdbcType=TIMESTAMP},
        task_complete_time = #{record.taskCompleteTime,jdbcType=TIMESTAMP},
        task_type = #{record.taskType,jdbcType=INTEGER},
        delay = #{record.delay,jdbcType=BIT},
        `state` = #{record.state,jdbcType=INTEGER},
        incomplete_reason = #{record.incompleteReason,jdbcType=VARCHAR},
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
        remark = #{record.remark,jdbcType=VARCHAR}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.linlinjava.jz.db.domain.HmEmployTask">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_task
        <set>
            <if test="orderNo != null">
                order_no = #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="employClockId != null">
                employ_clock_id = #{employClockId,jdbcType=BIGINT},
            </if>
            <if test="employRelationId != null">
                employ_relation_id = #{employRelationId,jdbcType=BIGINT},
            </if>
            <if test="categoryId != null">
                category_id = #{categoryId,jdbcType=BIGINT},
            </if>
            <if test="itemId != null">
                item_id = #{itemId,jdbcType=BIGINT},
            </if>
            <if test="taskStartTime != null">
                task_start_time = #{taskStartTime,jdbcType=TIMESTAMP},
            </if>
            <if test="taskCompleteTime != null">
                task_complete_time = #{taskCompleteTime,jdbcType=TIMESTAMP},
            </if>
            <if test="taskType != null">
                task_type = #{taskType,jdbcType=DECIMAL},
            </if>
            <if test="delay != null">
                delay = #{delay,jdbcType=BIT},
            </if>
            <if test="state != null">
                `state` = #{state,jdbcType=INTEGER},
            </if>
            <if test="incompleteReason != null">
                incomplete_reason = #{incompleteReason,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="remark != null">
                remark = #{remark,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="org.linlinjava.jz.db.domain.HmEmployTask">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_task
        set order_no = #{orderNo,jdbcType=VARCHAR},
        employ_clock_id = #{employClockId,jdbcType=BIGINT},
        employ_relation_id = #{employRelationId,jdbcType=BIGINT},
        category_id = #{categoryId,jdbcType=BIGINT},
        item_id = #{itemId,jdbcType=BIGINT},
        task_start_time = #{taskStartTime,jdbcType=TIMESTAMP},
        task_complete_time = #{taskCompleteTime,jdbcType=TIMESTAMP},
        task_type = #{taskType,jdbcType=INTEGER},
        delay = #{delay,jdbcType=BIT},
        `state` = #{state,jdbcType=INTEGER},
        incomplete_reason = #{incompleteReason,jdbcType=VARCHAR},
        create_time = #{createTime,jdbcType=TIMESTAMP},
        update_time = #{updateTime,jdbcType=TIMESTAMP},
        remark = #{remark,jdbcType=VARCHAR}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <select id="selectOneByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List"/>
        from hm_employ_task
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        limit 1
    </select>
    <select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <choose>
            <when test="selective != null and selective.length &gt; 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_task
        <if test="example != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
        <if test="example != null and example.orderByClause != null">
            order by ${example.orderByClause}
        </if>
        limit 1
    </select>
    <select id="queryByClockId" resultType="java.util.Map">
        SELECT
        t.id,
        t.`state`,
        t.`incomplete_reason`,
        (SELECT `item_name` FROM `hm_task_item` WHERE id = t.`item_id`) AS item_name
        FROM `hm_employ_task` t
        WHERE t.`employ_clock_id` = #{clockId}
        <if test="taskType != null">
            AND t.`task_type` = #{taskType}
        </if>
        <if test="stateList != null">
            and t.state IN
            <foreach collection="stateList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>
    <select id="selectTaskList" resultType="java.util.Map">
        SELECT t.id,
               t.`state`,
               t.`incomplete_reason`,
               t.employ_clock_id,
               t.task_type,
               t.category_id,
               t.item_id,
               (SELECT `item_name`
                FROM `hm_task_item`
                WHERE id = t.`item_id`) AS item_name
        FROM `hm_employ_task` t
        WHERE t.employ_relation_id = #{employRelationId}
          AND t.`task_type` = #{taskType}
          AND DATE_FORMAT(t.`task_start_time`, '%Y-%m-%d') = #{date}
    </select>
    <select id="getCompleteEmployTaskList" resultType="java.util.Map">
        SELECT DISTINCT t.id,
                        t.`state`,
                        t.`incomplete_reason`,
                        t.employ_clock_id,
                        t.task_type,
                        t.category_id,
                        t.item_id,
                        (SELECT `item_name`
                         FROM `hm_task_item`
                         WHERE id = t.`item_id`) AS item_name
        FROM `hm_employ_task` t
        WHERE t.employ_relation_id = #{employRelationId}
          and t.`task_type` = #{taskType}
          and t.state in (1, 2)
          AND WEEK(t.`task_start_time`) = WEEK(#{date})
    </select>
    <select id="getMonthCompleteEmployTaskList" resultType="java.util.Map">
        SELECT DISTINCT t.id,
                        t.`state`,
                        t.`incomplete_reason`,
                        t.employ_clock_id,
                        t.task_type,
                        t.category_id,
                        t.item_id,
                        (SELECT `item_name`
                         FROM `hm_task_item`
                         WHERE id = t.`item_id`) AS item_name
        FROM `hm_employ_task` t
        WHERE t.employ_relation_id = #{employRelationId}
                  and t.`task_type` = #{taskType}
                  and t.state in (1, 2)
                  AND MONTH (t.`task_start_time`) = MONTH (#{date})
    </select>
    <select id="queryWeekCount" resultType="java.lang.Long">
        SELECT count(*)
        FROM `hm_employ_task` t
        WHERE t.employ_relation_id = #{employRelationId}
        and t.`task_type` = #{taskType}
        AND WEEK(t.`task_start_time`) = WEEK(now())
        <if test="stateList != null">
            and t.state IN
            <foreach collection="stateList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>
    <select id="queryMonthCount" resultType="java.lang.Long">
        SELECT count(*)
        FROM `hm_employ_task` t
        WHERE t.employ_relation_id = #{employRelationId}
        and t.`task_type` = #{taskType}
        AND MONTH(t.`task_start_time`) = MONTH(now())
        <if test="stateList != null">
            and t.state IN
            <foreach collection="stateList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>