<?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.formula.FormulaMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.salaryformula.po.FormulaPO">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="description" property="description"/>
        <result column="module" property="module"/>
        <result column="use_for" property="useFor"/>
        <result column="reference_type" property="referenceType"/>
        <result column="return_type" property="returnType"/>
        <result column="validate_type" property="validateType"/>
        <result column="extend_param" property="extendParam"/>
        <result column="formula" property="formula"/>
        <result column="formulaRunScript" property="formulaRunScript"/>
        <result column="creator" property="creator"/>
        <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.name
        , t.description
        , t.module
        , t.use_for
        , t.reference_type
        , t.return_type
        , t.validate_type
        , t.extend_param
        , t.formula
        , t.formulaRunScript
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>

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

    <select id="list2All" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_formula t
    </select>

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

    <!-- 条件查询 -->
    <select id="listSome" resultMap="BaseResultMap" parameterType="com.engine.salary.entity.salaryformula.po.FormulaPO">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_formula t
        WHERE delete_type = 0
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="name != null">
            AND name = #{name}
        </if>
        <if test="description != null">
            AND description = #{description}
        </if>
        <if test="module != null">
            AND module = #{module}
        </if>
        <if test="useFor != null">
            AND use_for = #{useFor}
        </if>
        <if test="referenceType != null">
            AND reference_type = #{referenceType}
        </if>
        <if test="returnType != null">
            AND return_type = #{returnType}
        </if>
        <if test="validateType != null">
            AND validate_type = #{validateType}
        </if>
        <if test="extendParam != null">
            AND extend_param = #{extendParam}
        </if>
        <if test="formula != null">
            AND formula = #{formula}
        </if>
        <if test="creator != null">
            AND creator = #{creator}
        </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>
        <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.salaryformula.po.FormulaPO">
        INSERT INTO hrsa_formula
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="module != null">
                module,
            </if>
            <if test="useFor != null">
                use_for,
            </if>
            <if test="referenceType != null">
                reference_type,
            </if>
            <if test="returnType != null">
                return_type,
            </if>
            <if test="validateType != null">
                validate_type,
            </if>
            <if test="extendParam != null">
                extend_param,
            </if>
            <if test="formula != null">
                formula,
            </if>
            <if test="formulaRunScript != null">
                formulaRunScript,
            </if>
            <if test="creator != null">
                creator,
            </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="name != null">
                #{name},
            </if>
            <if test="description != null">
                #{description},
            </if>
            <if test="module != null">
                #{module},
            </if>
            <if test="useFor != null">
                #{useFor},
            </if>
            <if test="referenceType != null">
                #{referenceType},
            </if>
            <if test="returnType != null">
                #{returnType},
            </if>
            <if test="validateType != null">
                #{validateType},
            </if>
            <if test="extendParam != null">
                #{extendParam},
            </if>
            <if test="formula != null">
                #{formula},
            </if>
            <if test="formulaRunScript != null">
                #{formulaRunScript},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salaryformula.po.FormulaPO">
        UPDATE hrsa_formula
        <set>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="description != null">
                description=#{description},
            </if>
            <if test="module != null">
                module=#{module},
            </if>
            <if test="useFor != null">
                use_for=#{useFor},
            </if>
            <if test="referenceType != null">
                reference_type=#{referenceType},
            </if>
            <if test="returnType != null">
                return_type=#{returnType},
            </if>
            <if test="validateType != null">
                validate_type=#{validateType},
            </if>
            <if test="extendParam != null">
                extend_param=#{extendParam},
            </if>
            <if test="formula != null">
                formula=#{formula},
            </if>
            <if test="formulaRunScript != null">
                formulaRunScript=#{formulaRunScript},
            </if>
            <if test="creator != null">
                creator=#{creator},
            </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.entity.salaryformula.po.FormulaPO">
        UPDATE hrsa_formula
        SET delete_type=1
        WHERE id = #{id}
          AND delete_type = 0
    </delete>

    <!-- 查询全部 -->
    <select id="listByIds" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM hrsa_formula t
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <!-- 根据主键删除记录 -->
    <delete id="deleteIn">
        UPDATE hrsa_formula
        SET delete_type=1
        WHERE
        delete_type = 0
        AND id  IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
        and create_time <![CDATA[ < ]]>  #{yesterday}
    </delete>


</mapper>