<?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.pubmodules.workCollectAccessory.mapper.WorkCollectAccessoryMapper">



    <select id="findPageList" resultType="com.jeeplus.pubmodules.workCollectAccessory.domain.WorkCollectAccessory">
            select
                a.id,
                a.url,
                a.file_name,
                a.type,
                a.office_id,
                a.company_id,
                a.collect_type,
                a.collect_user_id,
                a.file_size,
                a.classification,
                a.file_description,
                a.office_share,
                a.company_share,
                a.create_by_id,
                a.create_time,
                a.update_by_id,
                a.update_time,
                b.name as userName,
                c.name as collectUserName
            from work_collect_accessory a
            left join sys_user b on a.create_by_id = b.id
            left join sys_user c on a.collect_user_id = c.id
                ${ew.customSqlSegment}
            ORDER BY a.create_time DESC
    </select>


    <select id="getDictByName" resultType="com.jeeplus.pubmodules.workCollectAccessory.service.dto.DictType">
        select
            a.id,
            a.type
        from
            sys_dict_type a
        where
            type = #{dictName}
        and del_flag = 0
    </select>


    <select id="listWorkAttachment" resultType="com.jeeplus.pubmodules.workCollectAccessory.service.dto.WorkAttachmentInfo">
        SELECT
            id,
            url,
            attachment_name AS `name`,
            create_by_id AS `by`,
            attachment_flag AS `attachmentFlag`,
            create_time
        FROM
            work_attachment
        WHERE
            del_flag = 0
          AND attachment_id = #{id}
    </select>



    <insert id="insertDictValue" parameterType="com.jeeplus.pubmodules.workCollectAccessory.service.dto.DictValueDTO">
        INSERT INTO sys_dict_value (id,dict_type_id,label,value,sort,create_by_id,create_time,update_by_id,update_time,del_flag,tenant_id)
        VALUES (#{id},
                #{dictTypeId},
                #{label},
                #{value},
                #{sort},
                #{createById},
                #{createTime},
                #{updateById},
                #{updateTime},
                #{delFlag},
                #{tenantId})
    </insert>

    <delete id="deleteAttachment">
        delete from work_attachment
        <where>
            attachment_id = #{id}
        </where>
    </delete>

    <select id="getDictValueByName" resultType="com.jeeplus.pubmodules.workCollectAccessory.service.dto.DictValue">
        SELECT v.label,
               v.value,
               v.sort,
               v.create_by_id
        FROM `sys_dict_value` v
        LEFT JOIN `sys_dict_type` t ON v.dict_type_id = t.id
        WHERE t.type = #{dictName} and v.create_by_id = #{userId}
        AND t.del_flag = 0
        AND v.del_flag = 0
    </select>

    <select id="getClassificationList" resultType="com.jeeplus.pubmodules.workCollectAccessory.domain.WorkCollectAccessory">
        SELECT DISTINCT a.classification
        FROM work_collect_accessory a
            ${ew.customSqlSegment}
    </select>

</mapper>