<?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.jeeplus.assess.program.configuration.projectDict.mapper.ProjectDictMapper">

    <select id="parentList" resultType="com.jeeplus.assess.program.configuration.projectDict.domain.vo.FileDictVo">
        SELECT
            id AS file_id,
            create_by_id,
            create_time,
            update_by_id,
            update_time,
            del_flag,
            remarks,
            parent_id,
            `name`,
            type,
            sort,
            size
        FROM
            program_file_dict
        WHERE
            del_flag = 0
            AND parent_id = 0
            ORDER BY sort
    </select>

    <select id="list" resultType="com.jeeplus.assess.program.configuration.projectDict.domain.vo.FileDictVo">
        SELECT
            a.id,
            a.required_stage,
            b.id AS file_id,
            b.create_by_id,
            b.create_time,
            b.update_by_id,
            b.update_time,
            b.del_flag,
            b.remarks,
            b.parent_id,
            b.`name`,
            b.type,
            b.sort,
            b.size
        FROM
            program_project_dict a
            LEFT JOIN program_file_dict b ON a.file_id = b.id
        WHERE
            a.del_flag = 0
            AND a.attachment_project_type = #{type}
            ORDER BY b.sort
    </select>

    <select id="getFileParentList" resultType="com.jeeplus.assess.program.configuration.fileDict.domain.ProgramFileDict">
        SELECT
        *
        FROM
        program_file_dict
        WHERE
        del_flag = 0
        AND parent_id = #{id}
        <if test="fileIds != null">
            AND id NOT IN
            <foreach collection="fileIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        ORDER BY sort
    </select>

    <select id="getFileList" resultType="com.jeeplus.assess.program.configuration.fileDict.domain.ProgramFileDict">
        SELECT
            *
        FROM
            program_file_dict
        WHERE
            del_flag = 0
            AND parent_id = (SELECT parent_id FROM program_file_dict WHERE del_flag = 0 AND id = #{id})
            <if test="fileIds != null">
                AND id NOT IN
                <foreach collection="fileIds" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            ORDER BY sort
    </select>

    <select id="findById" resultType="com.jeeplus.assess.program.configuration.projectDict.domain.vo.FileDictVo">
        SELECT
            a.id,
            a.required_stage,
            b.id AS file_id,
            b.create_by_id,
            b.create_time,
            b.update_by_id,
            b.update_time,
            b.del_flag,
            b.remarks,
            b.parent_id,
            b.`name`,
            b.type,
            b.sort,
            b.size
        FROM
            program_project_dict a
            LEFT JOIN program_file_dict b ON a.file_id = b.id
        WHERE
            a.del_flag = 0
            AND a.id = #{id}
    </select>

</mapper>
