<?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.aucma.dms.mapper.BaseAttachInfoMapper">
    <resultMap type="BaseAttachInfo" id="BaseAttachInfoResult">
        <result property="attachId" column="attach_id"/>
        <result property="attachCode" column="attach_code"/>
        <result property="attachName" column="attach_name"/>
        <result property="attachType" column="attach_type"/>
        <result property="attachPath" column="attach_path"/>
        <result property="processId" column="process_id"/>
        <result property="activeFlag" column="active_flag"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <!-- Oracle 11g 批量插入语法：使用 INSERT ALL -->
    <insert id="batchDmsKnowLedgeLubeFile" >
        INSERT ALL
        <foreach item="item" index="index" collection="list">
            INTO dms_base_attach_info(attach_id, attach_type, attach_name, attach_path, process_id, active_flag, create_time)
            VALUES (SEQ_MES_BASE_ATTACH_INFO.NEXTVAL, #{item.attachType}, #{item.attachName}, #{item.attachPath}, #{item.processId}, '1', #{item.createTime})
        </foreach>
        SELECT 1 FROM DUAL
    </insert>

    <!-- 查询有效附件列表 -->
    <select id="selectListBaseAttachInfos" resultType="java.lang.String">
        select attach_path
        from dms_base_attach_info
        where attach_type = #{attachType} 
          and process_id = #{processId}
          and active_flag = '1'
        order by create_time desc
    </select>

    <!-- 软删除：将附件标记为无效 -->
    <delete id="deleteListBaseAttachInfos">
        update dms_base_attach_info
        set active_flag = '0'
        where attach_type = #{attachType} 
          and process_id = #{processId}
    </delete>
</mapper>
