<?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.bonus.material.purchase.mapper.PurchaseCheckFileMapper">
    <resultMap type="com.bonus.material.purchase.domain.dto.PurchaseCheckFileDto" id="PurchaseCheckFileResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="url"    column="url"    />
        <result property="taskId"    column="task_id"    />
        <result property="dictCode"    column="dict_code"    />
        <result property="dictLabel"    column="dict_label"    />
    </resultMap>

    <sql id="selectPurchaseCheckFileJoinVo">
        SELECT
            sdd.dict_code,sdd.dict_label,
            bfi.id,bfi.name,bfi.url
        FROM
            sys_dict_data sdd
        LEFT JOIN
            bm_file_info bfi ON bfi.dic_id = sdd.dict_code and bfi.task_type = #{taskType} and bfi.model_id = #{typeId}
        WHERE
            sdd.dict_type = 'purchase_check_report_type'
    </sql>


    <select id="selectPurchaseCheckFileListByTaskType" parameterType="Long" resultMap="PurchaseCheckFileResult">
        <include refid="selectPurchaseCheckFileJoinVo"/>
    </select>
        
    <insert id="insertPurchaseCheckFiles" parameterType="com.bonus.material.purchase.domain.dto.PurchaseCheckFileDto" useGeneratedKeys="true" keyProperty="id">
        insert into bm_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelId != null">model_id,</if>
            <if test="name != null">name,</if>
            <if test="url != null">url,</if>
            <if test="dictCode != null">dic_id,</if>
            <if test="createBy != null">create_by,</if>
            create_time,
            <if test="taskId != null">task_id</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelId != null">#{modelId,jdbcType=INTEGER},</if>
            <if test="name != null">#{name,jdbcType=VARCHAR},</if>
            <if test="url != null">#{url,jdbcType=VARCHAR},</if>
            <if test="dictCode != null">#{dictCode},</if>
            <if test="createBy != null">#{createBy,jdbcType=VARCHAR},</if>
            now(),
            <if test="taskId != null">#{taskId}</if>
         </trim>
    </insert>

</mapper>