<?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.sys.SalarySysConfMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.sys.entity.po.SalarySysConfPO">
        <result column="id" property="id"/>
        <result column="conf_key" property="confKey"/>
        <result column="conf_value" property="confValue"/>
        <result column="title" property="title"/>
        <result column="module" property="module"/>
        <result column="order_weight" property="orderWeight"/>
        <result column="description" property="description"/>
        <result column="delete_type" property="deleteType"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.conf_key
        , t.conf_value
        , t.title
        , t.module
        , t.order_weight
        , t.description
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>

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

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.sys.entity.po.SalarySysConfPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_sys_conf t
        WHERE delete_type = 0
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="confKey != null">
            AND conf_key = #{confKey}
        </if>
        <if test="confValue != null">
            AND conf_value = #{confValue}
        </if>
        <if test="title != null">
            AND title = #{title}
        </if>
        <if test="module != null">
            AND module = #{module}
        </if>
        <if test="orderWeight != null">
            AND order_weight = #{orderWeight}
        </if>
        <if test="description != null">
            AND description = #{description}
        </if>
        <if test="deleteType != null">
            AND delete_type = #{deleteType}
        </if>
        <if test="createTime != null">
            AND create_time = #{createTime}
        </if>
        <if test="updateTime != null">
            AND update_time = #{updateTime}
        </if>
        ORDER BY create_time,order_weight DESC
    </select>


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

            <if test="id != null">
                id,
            </if>
            <if test="confKey != null">
                conf_key,
            </if>
            <if test="confValue != null">
                conf_value,
            </if>
            <if test="title != null">
                title,
            </if>
            <if test="module != null">
                module,
            </if>
            <if test="orderWeight != null">
                order_weight,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="deleteType != null">
                delete_type,
            </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="confKey != null">
                #{confKey},
            </if>
            <if test="confValue != null">
                #{confValue},
            </if>
            <if test="title != null">
                #{title},
            </if>
            <if test="module != null">
                #{module},
            </if>
            <if test="orderWeight != null">
                #{orderWeight},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.engine.salary.sys.entity.po.SalarySysConfPO">
        UPDATE hrsa_salary_sys_conf
        <set>
            conf_key=#{confKey},
            conf_value=#{confValue},
            title=#{title},
            module=#{module},
            order_weight=#{orderWeight},
            description=#{description},
            delete_type=#{deleteType},
            create_time=#{createTime},
            update_time=#{updateTime},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.sys.entity.po.SalarySysConfPO">
        UPDATE hrsa_salary_sys_conf
        <set>
            <if test="confKey != null">
                conf_key=#{confKey},
            </if>
            <if test="confValue != null">
                conf_value=#{confValue},
            </if>
            <if test="title != null">
                title=#{title},
            </if>
            <if test="module != null">
                module=#{module},
            </if>
            <if test="orderWeight != null">
                order_weight=#{orderWeight},
            </if>
            <if test="description != null">
                description=#{description},
            </if>
            <if test="deleteType != null">
                delete_type=#{deleteType},
            </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.sys.entity.po.SalarySysConfPO">
        UPDATE hrsa_salary_sys_conf
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>


    <select id="getOneByCode" resultMap="BaseResultMap" parameterType="com.engine.salary.sys.entity.po.SalarySysConfPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_sys_conf t
        WHERE delete_type = 0
        AND conf_key = #{confKey}
    </select>

    <select id="countByCode" resultType="java.lang.Integer">
        SELECT count(0)
        FROM hrsa_salary_sys_conf t
        WHERE delete_type = 0
          AND conf_key = #{confKey}
    </select>
    <select id="getTaxDeclarationRebootDate" resultType="java.util.Date">
        select update_time from HRSA_SALARY_SYS_CONF WHERE conf_key = 'taxDeclarationFunction'
    </select>

    <select id="getListByCodes" resultType="com.engine.salary.sys.entity.po.SalarySysConfPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_salary_sys_conf t
        WHERE delete_type = 0
        <if test="codes != null and codes.size()>0">
            and conf_key IN
            <foreach collection="codes" open="(" close=")" item="code" separator=",">
                #{code}
            </foreach>
        </if>
    </select>

</mapper>