<?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.HmEmployTaskSetMapper">
    <resultMap id="BaseResultMap" type="org.linlinjava.jz.db.domain.HmEmployTaskSet">
        <!--
          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="task_no" jdbcType="VARCHAR" property="taskNo"/>
        <result column="task_type" jdbcType="INTEGER" property="taskType"/>
        <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="state" jdbcType="INTEGER" property="state"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </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, task_no, task_type, employ_relation_id, category_id, item_id, `state`,
        create_time, update_time
    </sql>
    <select id="selectByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSetExample"
            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_set
        <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 > 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_task_set
        <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_set
        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 > 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_task_set
        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_set
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <delete id="deleteByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSetExample">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from hm_employ_task_set
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSet">
        <!--
          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_set (order_no, task_no, task_type,
        employ_relation_id, category_id, item_id,
        `state`, create_time, update_time
        )
        values (#{orderNo,jdbcType=VARCHAR}, #{taskNo,jdbcType=VARCHAR}, #{taskType,jdbcType=INTEGER},
        #{employRelationId,jdbcType=BIGINT}, #{categoryId,jdbcType=BIGINT}, #{itemId,jdbcType=BIGINT},
        #{state,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
        )
    </insert>
    <insert id="insertSelective" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSet">
        <!--
          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_set
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null">
                order_no,
            </if>
            <if test="taskNo != null">
                task_no,
            </if>
            <if test="taskType != null">
                task_type,
            </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="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="orderNo != null">
                #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="taskNo != null">
                #{taskNo,jdbcType=VARCHAR},
            </if>
            <if test="taskType != null">
                #{taskType,jdbcType=INTEGER},
            </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="state != null">
                #{state,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSetExample"
            resultType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from hm_employ_task_set
        <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
        <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.taskNo != null">
                task_no = #{record.taskNo,jdbcType=VARCHAR},
            </if>
            <if test="record.taskType != null">
                task_type = #{record.taskType,jdbcType=INTEGER},
            </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.state != null">
                `state` = #{record.state,jdbcType=INTEGER},
            </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>
        </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
        set id = #{record.id,jdbcType=BIGINT},
        order_no = #{record.orderNo,jdbcType=VARCHAR},
        task_no = #{record.taskNo,jdbcType=VARCHAR},
        task_type = #{record.taskType,jdbcType=INTEGER},
        employ_relation_id = #{record.employRelationId,jdbcType=BIGINT},
        category_id = #{record.categoryId,jdbcType=BIGINT},
        item_id = #{record.itemId,jdbcType=BIGINT},
        `state` = #{record.state,jdbcType=INTEGER},
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
        update_time = #{record.updateTime,jdbcType=TIMESTAMP}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSet">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_task_set
        <set>
            <if test="orderNo != null">
                order_no = #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="taskNo != null">
                task_no = #{taskNo,jdbcType=VARCHAR},
            </if>
            <if test="taskType != null">
                task_type = #{taskType,jdbcType=INTEGER},
            </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="state != null">
                `state` = #{state,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSet">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_task_set
        set order_no = #{orderNo,jdbcType=VARCHAR},
        task_no = #{taskNo,jdbcType=VARCHAR},
        task_type = #{taskType,jdbcType=INTEGER},
        employ_relation_id = #{employRelationId,jdbcType=BIGINT},
        category_id = #{categoryId,jdbcType=BIGINT},
        item_id = #{itemId,jdbcType=BIGINT},
        `state` = #{state,jdbcType=INTEGER},
        create_time = #{createTime,jdbcType=TIMESTAMP},
        update_time = #{updateTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <select id="selectOneByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployTaskSetExample"
            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_set
        <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 > 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_task_set
        <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="queryGroupByTaskType" resultType="java.util.Map">
        SELECT task_type,
               category_id,
               GROUP_CONCAT(DISTINCT item_id) AS item_id
        FROM `hm_employ_task_set`
        WHERE state = 0
          AND task_type = #{taskType}
          and order_no = #{orderNo}
        GROUP BY category_id
    </select>
    <select id="selectByOrderNoAndCategory" resultType="java.util.Map">
        SELECT t.`id`                               AS itemId,
               t.`item_name`                        as itemName,
               t.`category_id`                      as categoryId,
               IF(s.`item_id` IS NULL, FALSE, TRUE) AS choose
        FROM `hm_task_item` t
                 LEFT JOIN `hm_employ_task_set` s
                           ON s.item_id = t.`id`
                               AND s.`order_no` = #{orderNo}
                               AND s.`task_type` = #{taskType}
                               AND s.`state` = 0
        WHERE t.`disabled` = 0
          AND t.`category_id` = #{categoryId}
    </select>
    <select id="getTaskByTaskType" resultType="java.util.Map">
        SELECT DISTINCT 0                      AS id,
                        0                      AS state,
                        ''                     AS `incomplete_reason`,
                        task_type,
                        `category_id`,
                        item_id,
                        (SELECT `item_name`
                         FROM `hm_task_item`
                         WHERE id = `item_id`) AS item_name
        FROM `hm_employ_task_set`
        WHERE state = 0
          AND `employ_relation_id` = #{employRelationId}
          AND task_type = #{taskType}
    </select>
</mapper>