<?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.SalaryStatisticsItemMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.report.entity.po.SalaryStatisticsItemPO">
        <result column="avg_rule" property="avgRule"/>
        <result column="count_rule" property="countRule"/>
        <result column="create_time" property="createTime"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="id" property="id"/>
        <result column="index_value" property="indexValue"/>
        <result column="item_name" property="itemName"/>
        <result column="item_value" property="itemValue"/>
        <result column="max_rule" property="maxRule"/>
        <result column="median_rule" property="medianRule"/>
        <result column="min_rule" property="minRule"/>
        <result column="stat_report_id" property="statReportId"/>
        <result column="sum_rule" property="sumRule"/>
        <result column="tenant_key" property="tenantKey"/>
        <result column="unit_type" property="unitType"/>
        <result column="update_time" property="updateTime"/>
        <result column="last_rule" property="lastRule"/>
        <result column="old_rule" property="oldRule"/>
        <result column="frequent_rule" property="frequentRule"/>
        <result column="tile_rule" property="tileRule"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        avg_rule
        , t.count_rule
        , t.create_time
        , t.creator
        , t.delete_type
        , t.id
        , t.index_value
        , t.item_name
        , t.item_value
        , t.max_rule
        , t.median_rule
        , t.min_rule
        , t.stat_report_id
        , t.sum_rule
        , t.tenant_key
        , t.unit_type
        , t.update_time
        , t.last_rule
        , t.old_rule
        , t.frequent_rule
        , t.tile_rule
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap"
            parameterType="com.engine.salary.report.entity.po.SalaryStatisticsItemPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_statistics_item t
        WHERE delete_type = 0
        <if test="avgRule != null">
            AND avg_rule = #{avgRule}
        </if>
        <if test="countRule != null">
            AND count_rule = #{countRule}
        </if>
        <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="id != null">
            AND id = #{id}
        </if>
        <if test="indexValue != null">
            AND index_value = #{indexValue}
        </if>
        <if test="itemName != null">
            AND item_name = #{itemName}
        </if>
        <if test="itemValue != null">
            AND item_value = #{itemValue}
        </if>
        <if test="maxRule != null">
            AND max_rule = #{maxRule}
        </if>
        <if test="medianRule != null">
            AND median_rule = #{medianRule}
        </if>
        <if test="minRule != null">
            AND min_rule = #{minRule}
        </if>
        <if test="statReportId != null">
            AND stat_report_id = #{statReportId}
        </if>
        <if test="sumRule != null">
            AND sum_rule = #{sumRule}
        </if>
        <if test="tenantKey != null">
            AND tenant_key = #{tenantKey}
        </if>
        <if test="unitType != null">
            AND unit_type = #{unitType}
        </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>
        ORDER BY index_value
    </select>


    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsItemPO">
        INSERT INTO hrsa_salary_statistics_item
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="avgRule != null">
                avg_rule,
            </if>
            <if test="countRule != null">
                count_rule,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="indexValue != null">
                index_value,
            </if>
            <if test="itemName != null">
                item_name,
            </if>
            <if test="itemValue != null">
                item_value,
            </if>
            <if test="maxRule != null">
                max_rule,
            </if>
            <if test="medianRule != null">
                median_rule,
            </if>
            <if test="minRule != null">
                min_rule,
            </if>
            <if test="statReportId != null">
                stat_report_id,
            </if>
            <if test="sumRule != null">
                sum_rule,
            </if>
            <if test="tenantKey != null">
                tenant_key,
            </if>
            <if test="unitType != null">
                unit_type,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="lastRule != null">
                last_rule,
            </if>
            <if test="oldRule != null">
                old_rule,
            </if>
            <if test="frequentRule != null">
                frequent_rule,
            </if>
            <if test="tileRule != null">
                tile_rule,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="avgRule != null">
                #{avgRule},
            </if>
            <if test="countRule != null">
                #{countRule},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="indexValue != null">
                #{indexValue},
            </if>
            <if test="itemName != null">
                #{itemName},
            </if>
            <if test="itemValue != null">
                #{itemValue},
            </if>
            <if test="maxRule != null">
                #{maxRule},
            </if>
            <if test="medianRule != null">
                #{medianRule},
            </if>
            <if test="minRule != null">
                #{minRule},
            </if>
            <if test="statReportId != null">
                #{statReportId},
            </if>
            <if test="sumRule != null">
                #{sumRule},
            </if>
            <if test="tenantKey != null">
                #{tenantKey},
            </if>
            <if test="unitType != null">
                #{unitType},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="lastRule != null">
                #{lastRule},
            </if>
            <if test="oldRule != null">
                #{oldRule},
            </if>
            <if test="frequentRule != null">
                #{frequentRule},
            </if>
            <if test="tileRule != null">
                #{tileRule},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsItemPO">
        UPDATE hrsa_salary_statistics_item
        <set>
            avg_rule=#{avgRule},
            count_rule=#{countRule},
            create_time=#{createTime},
            creator=#{creator},
            delete_type=#{deleteType},
            index_value=#{indexValue},
            item_name=#{itemName},
            item_value=#{itemValue},
            max_rule=#{maxRule},
            median_rule=#{medianRule},
            min_rule=#{minRule},
            stat_report_id=#{statReportId},
            sum_rule=#{sumRule},
            tenant_key=#{tenantKey},
            unit_type=#{unitType},
            update_time=#{updateTime},
            last_rule=#{lastRule},
            old_rule=#{oldRule},
            frequent_rule=#{frequentRule},
            tile_rule=#{tileRule},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.report.entity.po.SalaryStatisticsItemPO">
        UPDATE hrsa_salary_statistics_item
        <set>
            <if test="avgRule != null">
                avg_rule=#{avgRule},
            </if>
            <if test="countRule != null">
                count_rule=#{countRule},
            </if>
            <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="indexValue != null">
                index_value=#{indexValue},
            </if>
            <if test="itemName != null">
                item_name=#{itemName},
            </if>
            <if test="itemValue != null">
                item_value=#{itemValue},
            </if>
            <if test="maxRule != null">
                max_rule=#{maxRule},
            </if>
            <if test="medianRule != null">
                median_rule=#{medianRule},
            </if>
            <if test="minRule != null">
                min_rule=#{minRule},
            </if>
            <if test="statReportId != null">
                stat_report_id=#{statReportId},
            </if>
            <if test="sumRule != null">
                sum_rule=#{sumRule},
            </if>
            <if test="tenantKey != null">
                tenant_key=#{tenantKey},
            </if>
            <if test="unitType != null">
                unit_type=#{unitType},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="lastRule != null">
                last_rule=#{lastRule},
            </if>
            <if test="oldRule != null">
                old_rule=#{oldRule},
            </if>
            <if test="frequentRule != null">
                frequent_rule=#{frequentRule},
            </if>
            <if test="tileRule != null">
                tile_rule=#{tileRule},
            </if>
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete">
        UPDATE hrsa_salary_statistics_item
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

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

    <delete id="deleteByReportIds">
        UPDATE hrsa_salary_statistics_item
        SET delete_type = 1
        WHERE delete_type = 0
        AND stat_report_id IN
        <foreach collection="reportIds" open="(" item="reportIds" separator="," close=")">
            #{reportIds}
        </foreach>
    </delete>

</mapper>