<?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.salarysob.SalarySobMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.salarysob.po.SalarySobPO">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="income_category" property="incomeCategory"/>
        <result column="salary_cycle_type" property="salaryCycleType"/>
        <result column="salary_cycle_from_day" property="salaryCycleFromDay"/>
        <result column="tax_cycle_type" property="taxCycleType"/>
        <result column="attend_cycle_type" property="attendCycleType"/>
        <result column="attend_cycle_from_day" property="attendCycleFromDay"/>
        <result column="social_security_cycle_type" property="socialSecurityCycleType"/>
        <result column="disable" property="disable"/>
        <result column="description" property="description"/>
        <result column="creator" property="creator"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="delete_type" property="deleteType"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="tax_agent_id" property="taxAgentId"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.name
        , t.income_category
        , t.salary_cycle_type
        , t.salary_cycle_from_day
        , t.tax_cycle_type
        , t.attend_cycle_type
        , t.attend_cycle_from_day
        , t.social_security_cycle_type
        , t.disable
        , t.description
        , t.creator
        , t.create_time
        , t.update_time
        , t.delete_type
        , t.tenant_key
        , t.tax_agent_id
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.salarysob.po.SalarySobPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_sob t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="incomeCategory != null and incomeCategory != ''">
            AND income_category = #{incomeCategory}
        </if>
        <if test="salaryCycleType != null and salaryCycleType != ''">
            AND salary_cycle_type = #{salaryCycleType}
        </if>
        <if test="salaryCycleFromDay != null and salaryCycleFromDay != ''">
            AND salary_cycle_from_day = #{salaryCycleFromDay}
        </if>
        <if test="taxCycleType != null and taxCycleType != ''">
            AND tax_cycle_type = #{taxCycleType}
        </if>
        <if test="attendCycleType != null and attendCycleType != ''">
            AND attend_cycle_type = #{attendCycleType}
        </if>
        <if test="attendCycleFromDay != null and attendCycleFromDay != ''">
            AND attend_cycle_from_day = #{attendCycleFromDay}
        </if>
        <if test="socialSecurityCycleType != null">
            AND social_security_cycle_type = #{socialSecurityCycleType}
        </if>
        <if test="disable != null">
            AND disable = #{disable}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </if>
        <if test="createTime != null and createTime != ''">
            AND create_time = #{createTime}
        </if>
        <if test="updateTime != null and updateTime != ''">
            AND update_time = #{updateTime}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="taxAgentId != null">
            AND tax_agent_id = #{taxAgentId}
        </if>
        <if test="taxAgentIds != null and taxAgentIds.size()>0">
            AND tax_agent_id IN
            <foreach collection="taxAgentIds" open="(" item="taxAgentId" separator="," close=")">
                #{taxAgentId}
            </foreach>
        </if>
        <include refid="listSomeParamSql"/>
        ORDER BY create_time DESC
    </select>


    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SalarySobPO"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO hrsa_salary_sob
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="incomeCategory != null">
                income_category,
            </if>
            <if test="salaryCycleType != null">
                salary_cycle_type,
            </if>
            <if test="salaryCycleFromDay != null">
                salary_cycle_from_day,
            </if>
            <if test="taxCycleType != null">
                tax_cycle_type,
            </if>
            <if test="attendCycleType != null">
                attend_cycle_type,
            </if>
            <if test="attendCycleFromDay != null">
                attend_cycle_from_day,
            </if>
            <if test="socialSecurityCycleType != null">
                social_security_cycle_type,
            </if>
            <if test="disable != null">
                disable,
            </if>
            <if test="description != null">
                description,
            </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>
            <if test="taxAgentId != null">
                tax_agent_id,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="incomeCategory != null">
                #{incomeCategory},
            </if>
            <if test="salaryCycleType != null">
                #{salaryCycleType},
            </if>
            <if test="salaryCycleFromDay != null">
                #{salaryCycleFromDay},
            </if>
            <if test="taxCycleType != null">
                #{taxCycleType},
            </if>
            <if test="attendCycleType != null">
                #{attendCycleType},
            </if>
            <if test="attendCycleFromDay != null">
                #{attendCycleFromDay},
            </if>
            <if test="socialSecurityCycleType != null">
                #{socialSecurityCycleType},
            </if>
            <if test="disable != null">
                #{disable},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="taxAgentId != null">
                #{taxAgentId},
            </if>
        </trim>
    </insert>


    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SalarySobPO" databaseId="oracle">

        <selectKey keyProperty="id" resultType="long" order="AFTER">
            select hrsa_salary_sob_id.currval from dual
        </selectKey>

        INSERT INTO hrsa_salary_sob
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="incomeCategory != null">
                income_category,
            </if>
            <if test="salaryCycleType != null">
                salary_cycle_type,
            </if>
            <if test="salaryCycleFromDay != null">
                salary_cycle_from_day,
            </if>
            <if test="taxCycleType != null">
                tax_cycle_type,
            </if>
            <if test="attendCycleType != null">
                attend_cycle_type,
            </if>
            <if test="attendCycleFromDay != null">
                attend_cycle_from_day,
            </if>
            <if test="socialSecurityCycleType != null">
                social_security_cycle_type,
            </if>
            <if test="disable != null">
                disable,
            </if>
            <if test="description != null">
                description,
            </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>
            <if test="taxAgentId != null">
                tax_agent_id,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="incomeCategory != null">
                #{incomeCategory},
            </if>
            <if test="salaryCycleType != null">
                #{salaryCycleType},
            </if>
            <if test="salaryCycleFromDay != null">
                #{salaryCycleFromDay},
            </if>
            <if test="taxCycleType != null">
                #{taxCycleType},
            </if>
            <if test="attendCycleType != null">
                #{attendCycleType},
            </if>
            <if test="attendCycleFromDay != null">
                #{attendCycleFromDay},
            </if>
            <if test="socialSecurityCycleType != null">
                #{socialSecurityCycleType},
            </if>
            <if test="disable != null">
                #{disable},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="taxAgentId != null">
                #{taxAgentId},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.salarysob.po.SalarySobPO">
        UPDATE hrsa_salary_sob
        <set>
            name=#{name},
            income_category=#{incomeCategory},
            salary_cycle_type=#{salaryCycleType},
            salary_cycle_from_day=#{salaryCycleFromDay},
            tax_cycle_type=#{taxCycleType},
            attend_cycle_type=#{attendCycleType},
            attend_cycle_from_day=#{attendCycleFromDay},
            social_security_cycle_type=#{socialSecurityCycleType},
            disable=#{disable},
            description=#{description},
            creator=#{creator},
            create_time=#{createTime},
            update_time=#{updateTime},
            delete_type=#{deleteType},
            tenant_key=#{tenantKey},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salarysob.po.SalarySobPO">
        UPDATE hrsa_salary_sob
        <set>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="incomeCategory != null">
                income_category=#{incomeCategory},
            </if>
            <if test="salaryCycleType != null">
                salary_cycle_type=#{salaryCycleType},
            </if>
            <if test="salaryCycleFromDay != null">
                salary_cycle_from_day=#{salaryCycleFromDay},
            </if>
            <if test="taxCycleType != null">
                tax_cycle_type=#{taxCycleType},
            </if>
            <if test="attendCycleType != null">
                attend_cycle_type=#{attendCycleType},
            </if>
            <if test="attendCycleFromDay != null">
                attend_cycle_from_day=#{attendCycleFromDay},
            </if>
            <if test="socialSecurityCycleType != null">
                social_security_cycle_type=#{socialSecurityCycleType},
            </if>
            <if test="disable != null">
                disable=#{disable},
            </if>
            <if test="description != null">
                description=#{description},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="taxAgentId != null">
                tax_agent_id=#{taxAgentId},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <update id="deleteByIds">
        UPDATE hrsa_salary_sob
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>


    <select id="listByParam" resultType="com.engine.salary.entity.salarysob.po.SalarySobPO">
        SELECT
        <include refid="baseColumns"/>
        FROM
        hrsa_salary_sob t
        WHERE
        delete_type = 0
        <include refid="paramSql"/>
    </select>

    <sql id="paramSql">
        <if test="param.name != null and param.name != ''">
            AND name like CONCAT('%',#{param.name},'%')
        </if>
    </sql>
    <sql id="paramSql" databaseId="oracle">
        <if test="param.name != null and param.name != ''">
            AND name like '%'||#{param.name}||'%'
        </if>
    </sql>
    <sql id="paramSql" databaseId="sqlserver">
        <if test="param.name != null and param.name != ''">
            AND name like '%'+#{param.name}+'%'
        </if>
    </sql>


    <sql id="listSomeParamSql">
        <if test="name != null and name != ''">
            AND name like CONCAT('%',#{name},'%')
        </if>
    </sql>
    <sql id="listSomeParamSql" databaseId="oracle">
        <if test="name != null and name != ''">
            AND name like '%'||#{name}||'%'
        </if>
    </sql>
    <sql id="listSomeParamSql" databaseId="sqlserver">
        <if test="name != null and name != ''">
            AND name like '%'+#{name}+'%'
        </if>
    </sql>


    <select id="listByName" resultType="com.engine.salary.entity.salarysob.po.SalarySobPO">
        SELECT
        <include refid="baseColumns"/>
        FROM
        hrsa_salary_sob t
        WHERE
        delete_type = 0
        and name = #{name}
    </select>



</mapper>