<?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.bonus.sgzb.app.mapper.TmTaskMapper">

  <resultMap id="BaseResultMap" type="com.bonus.sgzb.base.api.domain.TmTask">
    <!--@Table tm_task-->
    <id column="task_id" jdbcType="BIGINT" property="taskId" />
    <result column="task_type" jdbcType="INTEGER" property="taskType" />
    <result column="task_status" jdbcType="INTEGER" property="taskStatus" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="company_id" jdbcType="INTEGER" property="companyId" />
  </resultMap>

  <sql id="Base_Column_List">
    task_id, task_type, task_status, code, create_by, create_time, update_by, update_time,
    remark, company_id
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tm_task
    where task_id = #{taskId,jdbcType=BIGINT}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from tm_task
    where task_id = #{taskId,jdbcType=BIGINT}
  </delete>

  <insert id="insert" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.base.api.domain.TmTask" useGeneratedKeys="true">
    insert into tm_task (task_type, task_status, code, create_by, create_time, update_by, update_time, remark, company_id)
    values (#{taskType,jdbcType=INTEGER}, #{taskStatus,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR},
    #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER})
  </insert>

  <insert id="insertSelective" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.base.api.domain.TmTask" useGeneratedKeys="true">
    insert into tm_task
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="taskType != null">
        task_type,
      </if>
      <if test="taskStatus != null">
        task_status,
      </if>
      <if test="code != null and code != ''">
        code,
      </if>
      <if test="createBy != null and createBy != ''">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null and updateBy != ''">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="remark != null and remark != ''">
        remark,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="taskType != null">
        #{taskType,jdbcType=INTEGER},
      </if>
      <if test="taskStatus != null">
        #{taskStatus,jdbcType=INTEGER},
      </if>
      <if test="code != null and code != ''">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="createBy != null and createBy != ''">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null and updateBy != ''">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="companyId != null">
        #{companyId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.bonus.sgzb.base.api.domain.TmTask">
    <!--@mbg.generated-->
    update tm_task
    <set>
      <if test="taskType != null">
        task_type = #{taskType,jdbcType=INTEGER},
      </if>
      <if test="taskStatus != null">
        task_status = #{taskStatus,jdbcType=INTEGER},
      </if>
      <if test="code != null and code != ''">
        code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="createBy != null and createBy != ''">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null and updateBy != ''">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="companyId != null">
        company_id = #{companyId,jdbcType=INTEGER},
      </if>
    </set>
    where task_id = #{taskId,jdbcType=BIGINT}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.bonus.sgzb.base.api.domain.TmTask">
    <!--@mbg.generated-->
    update tm_task
    set task_type = #{taskType,jdbcType=INTEGER},
      task_status = #{taskStatus,jdbcType=INTEGER},
      code = #{code,jdbcType=VARCHAR},
      create_by = #{createBy,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      remark = #{remark,jdbcType=VARCHAR},
      company_id = #{companyId,jdbcType=INTEGER}
    where task_id = #{taskId,jdbcType=BIGINT}
  </update>

  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update tm_task
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="task_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.taskType,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="task_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.taskStatus,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.code,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.createBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="update_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.updateBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="remark = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.remark,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="company_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.companyId,jdbcType=INTEGER}
        </foreach>
      </trim>
    </trim>
    where task_id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.taskId,jdbcType=BIGINT}
    </foreach>
  </update>

  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update tm_task
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="task_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.taskType != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.taskType,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="task_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.taskStatus != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.taskStatus,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.code != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.code,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="create_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createBy != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.createBy,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createTime != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="update_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateBy != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.updateBy,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateTime != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="remark = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.remark != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.remark,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="company_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.companyId != null">
            when task_id = #{item.taskId,jdbcType=BIGINT} then #{item.companyId,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
    </trim>
    where task_id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.taskId,jdbcType=BIGINT}
    </foreach>
  </update>

  <insert id="batchInsert" keyColumn="task_id" keyProperty="taskId" parameterType="map" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into tm_task
    (task_type, task_status, code, create_by, create_time, update_by, update_time, remark, 
      company_id)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.taskType,jdbcType=INTEGER}, #{item.taskStatus,jdbcType=INTEGER}, #{item.code,jdbcType=VARCHAR}, 
        #{item.createBy,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=VARCHAR}, 
        #{item.updateTime,jdbcType=TIMESTAMP}, #{item.remark,jdbcType=VARCHAR}, #{item.companyId,jdbcType=INTEGER}
        )
    </foreach>
  </insert>

  <insert id="insertOrUpdate" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.base.api.domain.TmTask" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into tm_task
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="taskId != null">
        task_id,
      </if>
      task_type,
      task_status,
      code,
      create_by,
      create_time,
      update_by,
      update_time,
      remark,
      company_id,
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="taskId != null">
        #{taskId,jdbcType=BIGINT},
      </if>
      #{taskType,jdbcType=INTEGER},
      #{taskStatus,jdbcType=INTEGER},
      #{code,jdbcType=VARCHAR},
      #{createBy,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP},
      #{updateBy,jdbcType=VARCHAR},
      #{updateTime,jdbcType=TIMESTAMP},
      #{remark,jdbcType=VARCHAR},
      #{companyId,jdbcType=INTEGER},
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="taskId != null">
        task_id = #{taskId,jdbcType=BIGINT},
      </if>
      task_type = #{taskType,jdbcType=INTEGER},
      task_status = #{taskStatus,jdbcType=INTEGER},
      code = #{code,jdbcType=VARCHAR},
      create_by = #{createBy,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      remark = #{remark,jdbcType=VARCHAR},
      company_id = #{companyId,jdbcType=INTEGER},
    </trim>
  </insert>

  <insert id="insertOrUpdateSelective" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.base.api.domain.TmTask" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into tm_task
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="taskId != null">
        task_id,
      </if>
      <if test="taskType != null">
        task_type,
      </if>
      <if test="taskStatus != null">
        task_status,
      </if>
      <if test="code != null and code != ''">
        code,
      </if>
      <if test="createBy != null and createBy != ''">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null and updateBy != ''">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="remark != null and remark != ''">
        remark,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="taskId != null">
        #{taskId,jdbcType=BIGINT},
      </if>
      <if test="taskType != null">
        #{taskType,jdbcType=INTEGER},
      </if>
      <if test="taskStatus != null">
        #{taskStatus,jdbcType=INTEGER},
      </if>
      <if test="code != null and code != ''">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="createBy != null and createBy != ''">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null and updateBy != ''">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="companyId != null">
        #{companyId,jdbcType=INTEGER},
      </if>
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="taskId != null">
        task_id = #{taskId,jdbcType=BIGINT},
      </if>
      <if test="taskType != null">
        task_type = #{taskType,jdbcType=INTEGER},
      </if>
      <if test="taskStatus != null">
        task_status = #{taskStatus,jdbcType=INTEGER},
      </if>
      <if test="code != null and code != ''">
        code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="createBy != null and createBy != ''">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null and updateBy != ''">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="companyId != null">
        company_id = #{companyId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>

</mapper>