<?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.ruoyi.system.mapper.ActSuppliesHistorydataMapper">
    
    <resultMap type="ActSuppliesHistorydata" id="ActSuppliesHistorydataResult">
        <result property="id"    column="id"    />
        <result property="importUuid"    column="import_uuid"    />
        <result property="templateId"    column="template_id"    />
        <result property="exportUuid"    column="export_uuid"    />
        <result property="roleId"    column="role_id"    />
        <result property="historyName"    column="history_name"    />
        <result property="historyContent"    column="history_content"    />
        <result property="identifyingCode"    column="identifying_code"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectActSuppliesHistorydataVo">
        select id, import_uuid, template_id, export_uuid, role_id, history_name, history_content, identifying_code, status, create_by, create_time from act_supplies_historydata
    </sql>

    <select id="selectActSuppliesHistorydataList" parameterType="ActSuppliesHistorydata" resultMap="ActSuppliesHistorydataResult">
        <include refid="selectActSuppliesHistorydataVo"/>
        <where>  
            <if test="importUuid != null  and importUuid != ''"> and import_uuid = #{importUuid}</if>
            <if test="templateId != null "> and template_id = #{templateId}</if>
            <if test="exportUuid != null  and exportUuid != ''"> and export_uuid = #{exportUuid}</if>
            <if test="roleId != null "> and role_id = #{roleId}</if>
            <if test="historyName != null  and historyName != ''"> and history_name like concat('%', #{historyName}, '%')</if>
            <if test="historyContent != null  and historyContent != ''"> and history_content = #{historyContent}</if>
            <if test="identifyingCode != null "> and identifying_code = #{identifyingCode}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectActSuppliesHistorydataById" parameterType="Long" resultMap="ActSuppliesHistorydataResult">
        <include refid="selectActSuppliesHistorydataVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertActSuppliesHistorydata" parameterType="ActSuppliesHistorydata" useGeneratedKeys="true" keyProperty="id">
        insert into act_supplies_historydata
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="importUuid != null">import_uuid,</if>
            <if test="templateId != null">template_id,</if>
            <if test="exportUuid != null">export_uuid,</if>
            <if test="roleId != null">role_id,</if>
            <if test="historyName != null">history_name,</if>
            <if test="historyContent != null">history_content,</if>
            <if test="identifyingCode != null">identifying_code,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="importUuid != null">#{importUuid},</if>
            <if test="templateId != null">#{templateId},</if>
            <if test="exportUuid != null">#{exportUuid},</if>
            <if test="roleId != null">#{roleId},</if>
            <if test="historyName != null">#{historyName},</if>
            <if test="historyContent != null">#{historyContent},</if>
            <if test="identifyingCode != null">#{identifyingCode},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateActSuppliesHistorydata" parameterType="ActSuppliesHistorydata">
        update act_supplies_historydata
        <trim prefix="SET" suffixOverrides=",">
            <if test="importUuid != null">import_uuid = #{importUuid},</if>
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="exportUuid != null">export_uuid = #{exportUuid},</if>
            <if test="roleId != null">role_id = #{roleId},</if>
            <if test="historyName != null">history_name = #{historyName},</if>
            <if test="historyContent != null">history_content = #{historyContent},</if>
            <if test="identifyingCode != null">identifying_code = #{identifyingCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteActSuppliesHistorydataById" parameterType="Long">
        delete from act_supplies_historydata where id = #{id}
    </delete>

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



    <select id="selectActSuppliesHistorydatauuid" parameterType="String" resultType="Long">
        select count(*) from act_supplies_historydata where import_uuid = #{importUuid}
    </select>

    <select id="selectActSuppliesRole" parameterType="Long" resultType="Long">
        select temp_id from act_supplies_role where temp_id = #{templateId}
    </select>

    <update id="updateActSuppliesHistorydatas" parameterType="ActSuppliesHistorydata">
        update act_supplies_historydata
        <trim prefix="SET" suffixOverrides=",">
            <if test="historyName != null">history_name = #{historyName},</if>
            <if test="historyContent != null">history_content = #{historyContent},</if>
            <if test="identifyingCode != null">identifying_code = #{identifyingCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where import_uuid = #{importUuid}
    </update>

</mapper>