<?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.salarybill.SalarySendRangeMapper">
  <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryBill.po.SalarySendRangePO">
    <!--@mbg.generated-->
    <!--@Table hrsa_salary_send_range-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="salary_send_id" jdbcType="BIGINT" property="salarySendId" />
    <result column="grant_type" jdbcType="VARCHAR" property="grantType" />
    <result column="creator" jdbcType="BIGINT" property="creator" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="delete_type" jdbcType="INTEGER" property="deleteType" />
    <result column="tenant_key" jdbcType="VARCHAR" property="tenantKey" />
  </resultMap>

  <resultMap id="RangeListMap" type="com.engine.salary.entity.salaryBill.dto.SalarySendRangeListDTO">
    <result column="id" jdbcType="BIGINT" property="id"/>
    <result column="grant_type" jdbcType="VARCHAR" property="grantType"/>
  </resultMap>

  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, salary_send_id, grant_type, creator, create_time, update_time, delete_type, tenant_key
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from hrsa_salary_send_range
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
   update hrsa_salary_send_range
    set delete_type = 1
    where id = #{id,jdbcType=BIGINT} and delete_type = 0
  </delete>


  <insert id="insertSelective" keyColumn="id" keyProperty="id"
          parameterType="com.engine.salary.entity.salaryBill.po.SalarySendRangePO"
          useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into hrsa_salary_send_range
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="salarySendId != null">
        salary_send_id,
      </if>
      <if test="grantType != null">
        grant_type,
      </if>
      <if test="creator != null">
        creator,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="deleteType != null">
        delete_type,
      </if>
      <if test="tenantKey != null">
        tenant_key,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="salarySendId != null">
        #{salarySendId,jdbcType=BIGINT},
      </if>
      <if test="grantType != null">
        #{grantType,jdbcType=VARCHAR},
      </if>
      <if test="creator != null">
        #{creator,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteType != null">
        #{deleteType,jdbcType=INTEGER},
      </if>
      <if test="tenantKey != null">
        #{tenantKey,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <insert id="insertSelective" databaseId="oracle"
          parameterType="com.engine.salary.entity.salaryBill.po.SalarySendRangePO">
    <!--@mbg.generated-->
    <selectKey  keyProperty="id" resultType="long" order="AFTER">
      select HRSA_S_S_R_ID.currval from dual
    </selectKey>
    insert into hrsa_salary_send_range
    <trim prefix="(" suffix=")" suffixOverrides=",">
      id,
      <if test="salarySendId != null">
        salary_send_id,
      </if>
      <if test="grantType != null">
        grant_type,
      </if>
      <if test="creator != null">
        creator,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="deleteType != null">
        delete_type,
      </if>
      <if test="tenantKey != null">
        tenant_key,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      #{id,jdbcType=BIGINT},
      <if test="salarySendId != null">
        #{salarySendId,jdbcType=BIGINT},
      </if>
      <if test="grantType != null">
        #{grantType,jdbcType=VARCHAR},
      </if>
      <if test="creator != null">
        #{creator,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteType != null">
        #{deleteType,jdbcType=INTEGER},
      </if>
      <if test="tenantKey != null">
        #{tenantKey,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>


  <update id="updateByPrimaryKeySelective" parameterType="com.engine.salary.entity.salaryBill.po.SalarySendRangePO">
    <!--@mbg.generated-->
    update hrsa_salary_send_range
    <set>
      <if test="salarySendId != null">
        salary_send_id = #{salarySendId,jdbcType=BIGINT},
      </if>
      <if test="grantType != null">
        grant_type = #{grantType,jdbcType=VARCHAR},
      </if>
      <if test="creator != null">
        creator = #{creator,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleteType != null">
        delete_type = #{deleteType,jdbcType=INTEGER},
      </if>
      <if test="tenantKey != null">
        tenant_key = #{tenantKey,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>


  <select id="selectByAll" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from hrsa_salary_send_range
        <where>
            <if test="id != null">
                and id=#{id,jdbcType=BIGINT}
            </if>
            <if test="salarySendId != null">
                and salary_send_id=#{salarySendId,jdbcType=BIGINT}
            </if>
            <if test="grantType != null">
                and grant_type=#{grantType,jdbcType=VARCHAR}
            </if>
            <if test="creator != null">
                and creator=#{creator,jdbcType=BIGINT}
            </if>
            <if test="createTime != null">
                and create_time=#{createTime,jdbcType=TIMESTAMP}
            </if>
            <if test="updateTime != null">
                and update_time=#{updateTime,jdbcType=TIMESTAMP}
            </if>
            <if test="deleteType != null">
                and delete_type=#{deleteType,jdbcType=INTEGER}
            </if>
            <if test="tenantKey != null">
                and tenant_key=#{tenantKey,jdbcType=VARCHAR}
            </if>
        </where>
    </select>


  <select id="selectBySendIdAndGrantType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hrsa_salary_send_range
        <where>
          delete_type = 0
          and salary_send_id=#{salarySendId,jdbcType=BIGINT}
          <if test="grantType != null and grantType != ''">
            and grant_type=#{grantType,jdbcType=VARCHAR}
          </if>
        </where>
    </select>


  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update hrsa_salary_send_range
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="salary_send_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.salarySendId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.salarySendId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="grant_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.grantType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.grantType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="creator = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.creator != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.creator,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createTime != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateTime != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="delete_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.deleteType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.deleteType,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="tenant_key = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.tenantKey != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.tenantKey,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>


  <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into hrsa_salary_send_range
    (salary_send_id, grant_type, creator, create_time, update_time, delete_type, tenant_key
      )
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.salarySendId,jdbcType=BIGINT}, #{item.grantType,jdbcType=VARCHAR}, #{item.creator,jdbcType=BIGINT}, 
        #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.deleteType,jdbcType=INTEGER}, 
        #{item.tenantKey,jdbcType=VARCHAR})
    </foreach>
  </insert>
  <insert id="batchInsert" databaseId="sqlserver">
    <foreach collection="list" item="item" separator=";">
    insert into hrsa_salary_send_range
    (salary_send_id, grant_type, creator, create_time, update_time, delete_type, tenant_key
      )
    values
      (#{item.salarySendId,jdbcType=BIGINT}, #{item.grantType,jdbcType=VARCHAR}, #{item.creator,jdbcType=BIGINT},
        #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.deleteType,jdbcType=INTEGER},
        #{item.tenantKey,jdbcType=VARCHAR})
    </foreach>
  </insert>
  <insert id="batchInsert" databaseId="oracle">
    <!--@mbg.generated-->
    insert into hrsa_salary_send_range
    (salary_send_id, grant_type, creator, create_time, update_time, delete_type, tenant_key
      )
    select
    <foreach collection="list" item="item" separator=",">
      #{item.salarySendId,jdbcType=BIGINT}, #{item.grantType,jdbcType=VARCHAR}, #{item.creator,jdbcType=BIGINT},
        #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.deleteType,jdbcType=INTEGER},
        #{item.tenantKey,jdbcType=VARCHAR}
    </foreach>
    from dual
  </insert>


  <select id="selectIdsBySendIdAndGrantType" resultType="java.lang.Long">
    select
    id
    from hrsa_salary_send_range
    <where>
      delete_type = 0
      and salary_send_id=#{salarySendId,jdbcType=BIGINT}
      <if test="grantType != null and grantType != ''">
        and grant_type=#{grantType,jdbcType=VARCHAR}
      </if>
    </where>
  </select>


  <select id="selectByParam" resultMap="RangeListMap">
    select r.id,
           r.grant_type
    from hrsa_salary_send_range r
    <where>
      delete_type = 0
      <if test="queryParam.grantType != null">
        and r.grant_type = #{queryParam.grantType}
      </if>
      <if test="queryParam.salarySendId">
        and r.salary_send_id = #{queryParam.salarySendId}
      </if>
    </where>
    <if test="queryParam.orderRule != null">
      order by ${queryParam.orderRule.orderRule} ${queryParam.orderRule.ascOrDesc}
    </if>
  </select>
</mapper>