<?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.engine.salary.mapper.salaryacct.SalaryAcctResultTemplateMapper">
  <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryacct.po.SalaryAcctResultTemplatePO">
    <result column="create_time" property="createTime" />
    <result column="creator" property="creator" />
    <result column="delete_type" property="deleteType" />
    <result column="id" property="id" />
    <result column="salary_item_ids" property="salaryItemIds" />
    <result column="salary_sob_id" property="salarySobId" />
    <result column="template_name" property="templateName" />
    <result column="tenant_key" property="tenantKey" />
    <result column="update_time" property="updateTime" />
    <result column="type" property="type" />
  </resultMap>

  <!-- 表字段 -->
  <sql id="baseColumns">
    t.create_time
    , t.creator
        , t.delete_type
        , t.id
        , t.salary_item_ids
        , t.salary_sob_id
        , t.template_name
        , t.tenant_key
        , t.update_time
        , t.type
  </sql>

  <!-- 查询全部 -->
  <select id="listAll" resultMap="BaseResultMap">
    SELECT
    <include refid="baseColumns" />
    FROM hrsa_acct_result_template t
    WHERE delete_type = 0
  </select>

  <!-- 根据主键获取单条记录 -->
  <select id="getById" resultMap="BaseResultMap" parameterType="Long">
    SELECT
    <include refid="baseColumns" />
    FROM hrsa_acct_result_template t
    WHERE id = #{id} AND delete_type = 0
  </select>

  <!-- 条件查询 -->
  <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultTemplatePO">
    SELECT
    <include refid="baseColumns" />
    FROM hrsa_acct_result_template t
    WHERE delete_type = 0
    <if test="createTime != null">
      AND create_time = #{createTime}
    </if>
    <if test="creator != null">
      AND creator = #{creator}
    </if>
    <if test="deleteType != null">
      AND delete_type = #{deleteType}
    </if>
    <if test="id != null">
      AND id = #{id}
    </if>
    <if test="salaryItemIds != null">
      AND salary_item_ids = #{salaryItemIds}
    </if>
    <if test="salarySobId != null">
      AND salary_sob_id = #{salarySobId}
    </if>
    <if test="templateName != null">
      AND template_name = #{templateName}
    </if>
    <if test="tenantKey != null">
      AND tenant_key = #{tenantKey}
    </if>
    <if test="updateTime != null">
      AND update_time = #{updateTime}
    </if>
    <if test="type != null">
      AND type = #{type}
    </if>
    <if test="ids != null and ids.size()>0">
      AND id IN
      <foreach collection="ids" open="(" item="id" separator="," close=")">
        #{id}
      </foreach>
    </if>
    <if test="types != null and types.size()>0">
      AND type IN
      <foreach collection="types" open="(" item="type" separator="," close=")">
        #{type}
      </foreach>
    </if>
    ORDER BY id DESC
  </select>


  <!-- 插入不为NULL的字段 -->
  <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultTemplatePO">
    INSERT INTO hrsa_acct_result_template
    <trim prefix="(" suffix=")" suffixOverrides=",">

      <if test="createTime != null">
        create_time,
      </if>
      <if test="creator != null">
        creator,
      </if>
      <if test="deleteType != null">
        delete_type,
      </if>
      <if test="id != null">
        id,
      </if>
      <if test="salaryItemIds != null">
        salary_item_ids,
      </if>
      <if test="salarySobId != null">
        salary_sob_id,
      </if>
      <if test="templateName != null">
        template_name,
      </if>
      <if test="tenantKey != null">
        tenant_key,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
        <if test="type != null">
            type,
        </if>
    </trim>
    <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
      <if test="createTime != null" >
        #{createTime},
      </if>
      <if test="creator != null" >
        #{creator},
      </if>
      <if test="deleteType != null" >
        #{deleteType},
      </if>
      <if test="id != null" >
        #{id},
      </if>
      <if test="salaryItemIds != null" >
        #{salaryItemIds},
      </if>
      <if test="salarySobId != null" >
        #{salarySobId},
      </if>
      <if test="templateName != null" >
        #{templateName},
      </if>
      <if test="tenantKey != null" >
        #{tenantKey},
      </if>
      <if test="updateTime != null" >
        #{updateTime},
      </if>
        <if test="type != null" >
            #{type},
        </if>
    </trim>
  </insert>

  <!-- 更新,更新全部字段 -->
  <update id="update" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultTemplatePO">
    UPDATE hrsa_acct_result_template
    <set>
      create_time=#{createTime},
      creator=#{creator},
      delete_type=#{deleteType},
      salary_item_ids=#{salaryItemIds},
      salary_sob_id=#{salarySobId},
      template_name=#{templateName},
      tenant_key=#{tenantKey},
      update_time=#{updateTime},
        type=#{type},
    </set>
    WHERE id = #{id} AND delete_type = 0
  </update>


  <!-- 更新不为NULL的字段 -->
  <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultTemplatePO">
    UPDATE hrsa_acct_result_template
    <set>
      <if test="createTime != null" >
        create_time=#{createTime},
      </if>
      <if test="creator != null" >
        creator=#{creator},
      </if>
      <if test="deleteType != null" >
        delete_type=#{deleteType},
      </if>
      <if test="salaryItemIds != null" >
        salary_item_ids=#{salaryItemIds},
      </if>
      <if test="salarySobId != null" >
        salary_sob_id=#{salarySobId},
      </if>
      <if test="templateName != null" >
        template_name=#{templateName},
      </if>
      <if test="tenantKey != null" >
        tenant_key=#{tenantKey},
      </if>
      <if test="updateTime != null" >
        update_time=#{updateTime},
      </if>
      <if test="type != null" >
          type=#{type},
      </if>
    </set>
    WHERE id = #{id} AND delete_type = 0
  </update>


  <!-- 根据主键删除记录 -->
  <delete id="deleteById" parameterType="com.engine.salary.entity.salaryacct.po.SalaryAcctResultTemplatePO">
    UPDATE hrsa_acct_result_template
    SET delete_type=1
    WHERE id = #{id} AND delete_type = 0
  </delete>
    <delete id="deleteByIds">
      UPDATE hrsa_acct_result_template
      SET delete_type=1
      WHERE delete_type = 0
      <if test="ids != null and ids.size()>0">
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
          #{id}
        </foreach>
      </if>
    </delete>


</mapper>