<?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.salaryitem.SysSalaryItemMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="code" property="code"/>
        <result column="system_type" property="systemType"/>
        <result column="use_default" property="useDefault"/>
        <result column="use_in_employee_salary" property="useInEmployeeSalary"/>
        <result column="rounding_mode" property="roundingMode"/>
        <result column="pattern" property="pattern"/>
        <result column="value_type" property="valueType"/>
        <result column="formula_id" property="formulaId"/>
        <result column="description" property="description"/>
        <result column="can_edit" property="canEdit"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="data_type" property="dataType"/>
        <result column="shared_type" property="sharedType"/>
        <result column="tax_agent_ids" property="taxAgentIds"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.name
        , t.code
        , t.system_type
        , t.item_type
        , t.use_default
        , t.use_in_employee_salary
        , t.rounding_mode
        , t.pattern
        , t.value_type
        , t.formula_id
        , t.description
        , t.can_edit
        , t.creator
        , t.delete_type
        , t.tenant_key
        , t.create_time
        , t.update_time
        , t.data_type
    </sql>

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

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

    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" databaseId="sqlserver">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_sys_salary_item t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND name = #{name}
        </if>
        <if test="code != null and code != ''">
            AND code = #{code}
        </if>
        <if test="systemType != null and systemType != ''">
            AND system_type = #{systemType}
        </if>
        <if test="useDefault != null and useDefault != ''">
            AND use_default = #{useDefault}
        </if>
        <if test="useInEmployeeSalary != null and useInEmployeeSalary != ''">
            AND use_in_employee_salary = #{useInEmployeeSalary}
        </if>
        <if test="roundingMode != null and roundingMode != ''">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null and pattern != ''">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null and valueType != ''">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null and formulaId != ''">
            AND formula_id = #{formulaId}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="canEdit != null and canEdit != ''">
            AND can_edit = #{canEdit}
        </if>
        <if test="dataType != null and dataType != ''">
            AND data_type = #{dataType}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null and deleteType != ''">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>

    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" >
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_sys_salary_item t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND name = #{name}
        </if>
        <if test="code != null and code != ''">
            AND code = #{code}
        </if>
        <if test="systemType != null and systemType != ''">
            AND system_type = #{systemType}
        </if>
        <if test="useDefault != null and useDefault != ''">
            AND use_default = #{useDefault}
        </if>
        <if test="useInEmployeeSalary != null and useInEmployeeSalary != ''">
            AND use_in_employee_salary = #{useInEmployeeSalary}
        </if>
        <if test="roundingMode != null and roundingMode != ''">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null and pattern != ''">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null and valueType != ''">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null and formulaId != ''">
            AND formula_id = #{formulaId}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="canEdit != null and canEdit != ''">
            AND can_edit = #{canEdit}
        </if>
        <if test="dataType != null and dataType != ''">
            AND data_type = #{dataType}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null and deleteType != ''">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>


    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" databaseId="oracle">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_sys_salary_item t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND name = #{name}
        </if>
        <if test="code != null and code != ''">
            AND code = #{code}
        </if>
        <if test="systemType != null and systemType != ''">
            AND system_type = #{systemType}
        </if>
        <if test="useDefault != null and useDefault != ''">
            AND use_default = #{useDefault}
        </if>
        <if test="useInEmployeeSalary != null and useInEmployeeSalary != ''">
            AND use_in_employee_salary = #{useInEmployeeSalary}
        </if>
        <if test="roundingMode != null and roundingMode != ''">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null and pattern != ''">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null and valueType != ''">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null and formulaId != ''">
            AND formula_id = #{formulaId}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="canEdit != null and canEdit != ''">
            AND can_edit = #{canEdit}
        </if>
        <if test="dataType != null and dataType != ''">
            AND data_type = #{dataType}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null and deleteType != ''">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>

    <select id="listLikeName" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" databaseId="sqlserver">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_sys_salary_item t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND name like '%'+#{name}+'%'
        </if>
        <if test="code != null and code != ''">
            AND code = #{code}
        </if>
        <if test="systemType != null and systemType != ''">
            AND system_type = #{systemType}
        </if>
        <if test="useDefault != null and useDefault != ''">
            AND use_default = #{useDefault}
        </if>
        <if test="useInEmployeeSalary != null and useInEmployeeSalary != ''">
            AND use_in_employee_salary = #{useInEmployeeSalary}
        </if>
        <if test="roundingMode != null and roundingMode != ''">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null and pattern != ''">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null and valueType != ''">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null and formulaId != ''">
            AND formula_id = #{formulaId}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="canEdit != null and canEdit != ''">
            AND can_edit = #{canEdit}
        </if>
        <if test="dataType != null and dataType != ''">
            AND data_type = #{dataType}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null and deleteType != ''">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>

    <select id="listLikeName" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" >
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_sys_salary_item t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND name like CONCAT('%',#{name},'%')
        </if>
        <if test="code != null and code != ''">
            AND code = #{code}
        </if>
        <if test="systemType != null and systemType != ''">
            AND system_type = #{systemType}
        </if>
        <if test="useDefault != null and useDefault != ''">
            AND use_default = #{useDefault}
        </if>
        <if test="useInEmployeeSalary != null and useInEmployeeSalary != ''">
            AND use_in_employee_salary = #{useInEmployeeSalary}
        </if>
        <if test="roundingMode != null and roundingMode != ''">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null and pattern != ''">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null and valueType != ''">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null and formulaId != ''">
            AND formula_id = #{formulaId}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="canEdit != null and canEdit != ''">
            AND can_edit = #{canEdit}
        </if>
        <if test="dataType != null and dataType != ''">
            AND data_type = #{dataType}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null and deleteType != ''">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>


    <select id="listLikeName" resultMap="BaseResultMap"
            parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" databaseId="oracle">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_sys_salary_item t
        WHERE delete_type = 0
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="name != null and name != ''">
            AND name like '%'||#{name}||'%'
        </if>
        <if test="code != null and code != ''">
            AND code = #{code}
        </if>
        <if test="systemType != null and systemType != ''">
            AND system_type = #{systemType}
        </if>
        <if test="useDefault != null and useDefault != ''">
            AND use_default = #{useDefault}
        </if>
        <if test="useInEmployeeSalary != null and useInEmployeeSalary != ''">
            AND use_in_employee_salary = #{useInEmployeeSalary}
        </if>
        <if test="roundingMode != null and roundingMode != ''">
            AND rounding_mode = #{roundingMode}
        </if>
        <if test="pattern != null and pattern != ''">
            AND pattern = #{pattern}
        </if>
        <if test="valueType != null and valueType != ''">
            AND value_type = #{valueType}
        </if>
        <if test="formulaId != null and formulaId != ''">
            AND formula_id = #{formulaId}
        </if>
        <if test="description != null and description != ''">
            AND description = #{description}
        </if>
        <if test="canEdit != null and canEdit != ''">
            AND can_edit = #{canEdit}
        </if>
        <if test="dataType != null and dataType != ''">
            AND data_type = #{dataType}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="deleteType != null and deleteType != ''">
            AND delete_type = #{deleteType}
        </if>
        <if test="tenantKey != null and tenantKey != ''">
            AND tenant_key = #{tenantKey}
        </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="ids != null and ids.size()>0">
            AND id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        ORDER BY id DESC
    </select>


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

            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="code != null">
                code,
            </if>
            <if test="systemType != null">
                system_type,
            </if>
            <if test="useDefault != null">
                use_default,
            </if>
            <if test="useInEmployeeSalary != null">
                use_in_employee_salary,
            </if>
            <if test="roundingMode != null">
                rounding_mode,
            </if>
            <if test="pattern != null">
                pattern,
            </if>
            <if test="valueType != null">
                value_type,
            </if>
            <if test="formulaId != null">
                formula_id,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="canEdit != null">
                can_edit,
            </if>
            <if test="dataType != null">
                data_type,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="code != null">
                #{code},
            </if>
            <if test="systemType != null">
                #{systemType},
            </if>
            <if test="useDefault != null">
                #{useDefault},
            </if>
            <if test="useInEmployeeSalary != null">
                #{useInEmployeeSalary},
            </if>
            <if test="roundingMode != null">
                #{roundingMode},
            </if>
            <if test="pattern != null">
                #{pattern},
            </if>
            <if test="valueType != null">
                #{valueType},
            </if>
            <if test="formulaId != null">
                #{formulaId},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="canEdit != null">
                #{canEdit},
            </if>
            <if test="dataType != null">
                #{dataType},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO" databaseId="oracle"
    >
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select hrsa_sys_salary_item_id.currval from dual
        </selectKey>
        INSERT INTO hrsa_sys_salary_item
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="code != null">
                code,
            </if>
            <if test="systemType != null">
                system_type,
            </if>
            <if test="useDefault != null">
                use_default,
            </if>
            <if test="useInEmployeeSalary != null">
                use_in_employee_salary,
            </if>
            <if test="roundingMode != null">
                rounding_mode,
            </if>
            <if test="pattern != null">
                pattern,
            </if>
            <if test="valueType != null">
                value_type,
            </if>
            <if test="formulaId != null">
                formula_id,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="canEdit != null">
                can_edit,
            </if>
            <if test="dataType != null">
                data_type,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="code != null">
                #{code},
            </if>
            <if test="systemType != null">
                #{systemType},
            </if>
            <if test="useDefault != null">
                #{useDefault},
            </if>
            <if test="useInEmployeeSalary != null">
                #{useInEmployeeSalary},
            </if>
            <if test="roundingMode != null">
                #{roundingMode},
            </if>
            <if test="pattern != null">
                #{pattern},
            </if>
            <if test="valueType != null">
                #{valueType},
            </if>
            <if test="formulaId != null">
                #{formulaId},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="canEdit != null">
                #{canEdit},
            </if>
            <if test="dataType != null">
                #{dataType},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO">
        UPDATE hrsa_sys_salary_item
        <set>
            name=#{name},
            code=#{code},
            system_type=#{systemType},
            use_default=#{useDefault},
            use_in_employee_salary=#{useInEmployeeSalary},
            rounding_mode=#{roundingMode},
            pattern=#{pattern},
            value_type=#{valueType},
            formula_id=#{formulaId},
            description=#{description},
            can_edit=#{canEdit},
            data_type=#{dataType},
            creator=#{creator},
            delete_type=#{deleteType},
            tenant_key=#{tenantKey},
            create_time=#{createTime},
            update_time=#{updateTime},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO">
        UPDATE hrsa_sys_salary_item
        <set>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="code != null">
                code=#{code},
            </if>
            <if test="systemType != null">
                system_type=#{systemType},
            </if>
            <if test="useDefault != null">
                use_default=#{useDefault},
            </if>
            <if test="useInEmployeeSalary != null">
                use_in_employee_salary=#{useInEmployeeSalary},
            </if>
            <if test="roundingMode != null">
                rounding_mode=#{roundingMode},
            </if>
            <if test="pattern != null">
                pattern=#{pattern},
            </if>
            <if test="valueType != null">
                value_type=#{valueType},
            </if>
            <if test="formulaId != null">
                formula_id=#{formulaId},
            </if>
            <if test="description != null">
                description=#{description},
            </if>
            <if test="canEdit != null">
                can_edit=#{canEdit},
            </if>
            <if test="dataType != null">
                data_type=#{dataType},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete" parameterType="com.engine.salary.entity.salaryitem.po.SysSalaryItemPO">
        UPDATE hrsa_sys_salary_item
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

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

</mapper>