<?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.fs.audit.mapper.AuditTempMapper">
    <resultMap type="AuditTemp" id="AuditTempResult">
        <result property="id"    column="id"    />
        <result property="tempName"    column="temp_name"    />
        <result property="tempCode"    column="temp_code"    />
        <result property="tempJson"    column="temp_json"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectAuditTempVo">
        select id, temp_name, temp_code, temp_json, status, create_time, update_time, is_del, company_id from audit_temp
    </sql>

    <select id="selectAuditTempList" parameterType="AuditTemp" resultMap="AuditTempResult">
        <include refid="selectAuditTempVo"/>
        <where>
            <if test="tempName != null  and tempName != ''"> and temp_name like concat('%', #{tempName}, '%')</if>
            <if test="tempCode != null  and tempCode != ''"> and temp_code = #{tempCode}</if>
            <if test="tempJson != null  and tempJson != ''"> and temp_json = #{tempJson}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>

    <select id="selectAuditTempById" parameterType="Long" resultMap="AuditTempResult">
        <include refid="selectAuditTempVo"/>
        where id = #{id}
    </select>

    <insert id="insertAuditTemp" parameterType="AuditTemp" useGeneratedKeys="true" keyProperty="id">
        insert into audit_temp
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tempName != null">temp_name,</if>
            <if test="tempCode != null">temp_code,</if>
            <if test="tempJson != null">temp_json,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="companyId != null">company_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tempName != null">#{tempName},</if>
            <if test="tempCode != null">#{tempCode},</if>
            <if test="tempJson != null">#{tempJson},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="companyId != null">#{companyId},</if>
        </trim>
    </insert>

    <update id="updateAuditTemp" parameterType="AuditTemp">
        update audit_temp
        <trim prefix="SET" suffixOverrides=",">
            <if test="tempName != null">temp_name = #{tempName},</if>
            <if test="tempCode != null">temp_code = #{tempCode},</if>
            <if test="tempJson != null">temp_json = #{tempJson},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAuditTempById" parameterType="Long">
        delete from audit_temp where id = #{id}
    </delete>

    <delete id="deleteAuditTempByIds" parameterType="String">
        delete from audit_temp where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="selectById" parameterType="Long" resultMap="AuditTempResult">
        <include refid="selectAuditTempVo"/>
        where id = #{id}
    </select>

</mapper>
