<?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.SalarySendRangeObjMapper">
  <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryBill.po.SalarySendRangeObj">
    <!--@mbg.generated-->
    <!--@Table hrsa_salary_send_range_obj-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="salary_send_id" jdbcType="BIGINT" property="salarySendId" />
    <result column="salary_send_range_id" jdbcType="BIGINT" property="salarySendRangeId" />
    <result column="range_type" jdbcType="INTEGER" property="rangeType" />
    <result column="target_type" jdbcType="INTEGER" property="targetType" />
    <result column="target_id" jdbcType="BIGINT" property="targetId" />
    <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>

  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, salary_send_id, salary_send_range_id, range_type, target_type, target_id, 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_obj
    where id = #{id,jdbcType=BIGINT}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from hrsa_salary_send_range_obj
    where id = #{id,jdbcType=BIGINT}
  </delete>

  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.engine.salary.entity.salaryBill.po.SalarySendRangeObj" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into hrsa_salary_send_range_obj
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="salarySendId != null">
        salary_send_id,
      </if>
      <if test="salarySendRangeId != null">
        salary_send_range_id,
      </if>
      <if test="rangeType != null">
        range_type,
      </if>
      <if test="targetType != null">
        target_type,
      </if>
      <if test="targetId != null">
        target_id,
      </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="salarySendRangeId != null">
        #{salarySendRangeId,jdbcType=BIGINT},
      </if>
      <if test="rangeType != null">
        #{rangeType,jdbcType=INTEGER},
      </if>
      <if test="targetType != null">
        #{targetType,jdbcType=INTEGER},
      </if>
      <if test="targetId != null">
        #{targetId,jdbcType=BIGINT},
      </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.SalarySendRangeObj">
    <!--@mbg.generated-->
    update hrsa_salary_send_range_obj
    <set>
      <if test="salarySendId != null">
        salary_send_id = #{salarySendId,jdbcType=BIGINT},
      </if>
      <if test="salarySendRangeId != null">
        salary_send_range_id = #{salarySendRangeId,jdbcType=BIGINT},
      </if>
      <if test="rangeType != null">
        range_type = #{rangeType,jdbcType=INTEGER},
      </if>
      <if test="targetType != null">
        target_type = #{targetType,jdbcType=INTEGER},
      </if>
      <if test="targetId != null">
        target_id = #{targetId,jdbcType=BIGINT},
      </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_obj
        <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="salarySendRangeId != null">
                and salary_send_range_id=#{salarySendRangeId,jdbcType=BIGINT}
            </if>
            <if test="rangeType != null">
                and range_type=#{rangeType,jdbcType=INTEGER}
            </if>
            <if test="targetType != null">
                and target_type=#{targetType,jdbcType=INTEGER}
            </if>
            <if test="targetId != null">
                and target_id=#{targetId,jdbcType=BIGINT}
            </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="listBySalarySendIdAndRangeIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from hrsa_salary_send_range_obj
        where salary_send_id=#{salarySendId,jdbcType=BIGINT}
        and delete_type = 0 and tenant_key = #{tenantKey}
        <if test="salarySendRangeIds != null and salarySendRangeIds.size() != 0">
          and salary_send_range_id
          <foreach collection="salarySendRangeIds" separator="," open=" in (" close=" )" item="salarySendRangeId">
            #{salarySendRangeId,jdbcType=BIGINT}
          </foreach>
        </if>
    </select>

  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update hrsa_salary_send_range_obj
    <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="salary_send_range_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.salarySendRangeId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.salarySendRangeId,jdbcType=BIGINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="range_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.rangeType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.rangeType,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="target_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.targetType != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.targetType,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="target_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.targetId != null">
            when id = #{item.id,jdbcType=BIGINT} then #{item.targetId,jdbcType=BIGINT}
          </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">
    insert into hrsa_salary_send_range_obj
    (salary_send_id, salary_send_range_id, range_type, target_type, target_id, creator, 
      create_time, update_time, delete_type, tenant_key)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.salarySendId,jdbcType=BIGINT}, #{item.salarySendRangeId,jdbcType=BIGINT}, 
        #{item.rangeType,jdbcType=INTEGER}, #{item.targetType,jdbcType=INTEGER}, #{item.targetId,jdbcType=BIGINT}, 
        #{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_obj
        (salary_send_id, salary_send_range_id, range_type, target_type, target_id, creator,
         create_time, update_time, delete_type, tenant_key)
        values (#{item.salarySendId,jdbcType=BIGINT}, #{item.salarySendRangeId,jdbcType=BIGINT},
                #{item.rangeType,jdbcType=INTEGER}, #{item.targetType,jdbcType=INTEGER},
                #{item.targetId,jdbcType=BIGINT},
                #{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">
    insert into hrsa_salary_send_range_obj
    (salary_send_id, salary_send_range_id, range_type, target_type, target_id, creator,
      create_time, update_time, delete_type, tenant_key)
    <foreach collection="list" item="item" separator="union all">
      select
      #{item.salarySendId,jdbcType=BIGINT}, #{item.salarySendRangeId,jdbcType=BIGINT},
        #{item.rangeType,jdbcType=INTEGER}, #{item.targetType,jdbcType=INTEGER}, #{item.targetId,jdbcType=BIGINT},
        #{item.creator,jdbcType=BIGINT}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP},
        #{item.deleteType,jdbcType=INTEGER}, #{item.tenantKey,jdbcType=VARCHAR}
      from dual
    </foreach>
  </insert>

  <update id="deleteBySalarySendIds">
    update hrsa_salary_send_range_obj
    set delete_type = 1
    where salary_send_id in (
    <foreach collection="salarySendIds" item="salarySendId" separator=",">
      #{salarySendId}
    </foreach>
    )
    and delete_type = 0
  </update>

  <update id="deleteByRangeIds">
    update hrsa_salary_send_range_obj
    set delete_type = 1
    where delete_type = 0
    and salary_send_range_id in (
      <foreach collection="salarySendRangeIds" item="salarySendId" separator=",">
        #{salarySendId}
      </foreach>
      )
  </update>

  <resultMap id="userInfoMap" type="com.engine.salary.entity.salaryBill.dto.SalarySendUserInfoDTO">
    <result column="id" property="resourceId" jdbcType="BIGINT"/>
    <result column="departmentid" property="departmentId" jdbcType="BIGINT"/>
    <result column="subcompanyid1" property="subCompanyId" jdbcType="BIGINT"/>
    <result column="jobtitle" property="jobTitle" jdbcType="BIGINT"/>
  </resultMap>
  <select id="getUserInfoByEmployeeIds" resultMap="userInfoMap">
    select id,
    departmentid,
    subcompanyid1,
    jobtitle
    from hrmresource
    where id in (
      <foreach collection="employeeIds" item="item" separator=",">
        #{item}
      </foreach>
      )
  </select>
</mapper>