<?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.report.SalaryStatisticsDimensionMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO">
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="dim_code" property="dimCode"/>
        <result column="dim_name" property="dimName"/>
        <result column="dim_type" property="dimType"/>
        <result column="id" property="id"/>
        <result column="is_default" property="isDefault"/>
        <result column="label_id" property="labelId"/>
        <result column="remark" property="remark"/>
        <result column="setting" property="setting"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        create_time
        , t.creator
        , t.delete_type
        , t.dim_code
        , t.dim_name
        , t.dim_type
        , t.id
        , t.is_default
        , t.label_id
        , t.remark
        , t.setting
        , t.tenant_key
        , t.update_time
    </sql>

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

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

    <sql id="paramSql">
        <!-- 关键字（姓名、工号 -->
        <if test="dimNameLike != null and dimNameLike != ''">
            AND dim_name like CONCAT('%',#{dimNameLike},'%')
        </if>
    </sql>
    <sql id="paramSql" databaseId="oracle">
        <if test="dimNameLike != null and dimNameLike != ''">
            AND dim_name like '%'||#{dimName}||'%'
        </if>
    </sql>
    <sql id="paramSql" databaseId="sqlserver">
        <if test="dimNameLike != null and dimNameLike != ''">
            AND dim_name like '%'+#{dimNameLike}+'%'
        </if>
    </sql>

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_stats_dim 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="dimCode != null">
            AND dim_code = #{dimCode}
        </if>
        <if test="dimName != null and dimName != ''">
            AND dim_name = #{dimName}
        </if>
        <if test="dimType != null">
            AND dim_type = #{dimType}
        </if>
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="isDefault != null">
            AND is_default = #{isDefault}
        </if>
        <if test="labelId != null">
            AND label_id = #{labelId}
        </if>
        <if test="remark != null">
            AND remark = #{remark}
        </if>
        <if test="setting != null">
            AND setting = #{setting}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="updateTime != null">
            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>
        <include refid="paramSql"/>
        ORDER BY id DESC
    </select>


    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO">
        INSERT INTO hrsa_salary_stats_dim
        <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="dimCode != null">
                dim_code,
            </if>
            <if test="dimName != null">
                dim_name,
            </if>
            <if test="dimType != null">
                dim_type,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="isDefault != null">
                is_default,
            </if>
            <if test="labelId != null">
                label_id,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="setting != null">
                setting,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="updateTime != null">
                update_time,
            </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="dimCode != null">
                #{dimCode},
            </if>
            <if test="dimName != null">
                #{dimName},
            </if>
            <if test="dimType != null">
                #{dimType},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="isDefault != null">
                #{isDefault},
            </if>
            <if test="labelId != null">
                #{labelId},
            </if>
            <if test="remark != null">
                #{remark},
            </if>
            <if test="setting != null">
                #{setting},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO">
        UPDATE hrsa_salary_stats_dim
        <set>
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            dim_code=#{dimCode},
            dim_name=#{dimName},
            dim_type=#{dimType},
            is_default=#{isDefault},
            label_id=#{labelId},
            remark=#{remark},
            setting=#{setting},
            tenant_key=#{tenantKey},
            update_time=#{updateTime},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO">
        UPDATE hrsa_salary_stats_dim
        <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="dimCode != null">
                dim_code=#{dimCode},
            </if>
            <if test="dimName != null">
                dim_name=#{dimName},
            </if>
            <if test="dimType != null">
                dim_type=#{dimType},
            </if>
            <if test="isDefault != null">
                is_default=#{isDefault},
            </if>
            <if test="labelId != null">
                label_id=#{labelId},
            </if>
            <if test="remark != null">
                remark=#{remark},
            </if>
            <if test="setting != null">
                setting=#{setting},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </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.report.entity.po.SalaryStatisticsDimensionPO">
        UPDATE hrsa_salary_stats_dim
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

    <delete id="batDelete" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsDimensionPO">
        UPDATE hrsa_salary_stats_dim
        SET delete_type=1
        WHERE
        id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
        AND delete_type = 0
    </delete>


</mapper>