<?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.psimanage.supplier.mapper.PsiMaterialSupplierMapper">

    <resultMap id="BaseResultMap" type="com.jeeplus.psimanage.supplier.service.dto.PsiMaterialSupplierDTO">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="createBy.id" column="create_by_id" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy.id" column="update_by_id" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="isUscCode" column="is_usc_code" jdbcType="VARCHAR"/>
            <result property="uscCode" column="usc_code" jdbcType="VARCHAR"/>
            <result property="reconciliationArea" column="reconciliation_area" jdbcType="VARCHAR"/>
            <result property="characterIs" column="character_is" jdbcType="VARCHAR"/>
            <result property="zipCode" column="zip_code" jdbcType="VARCHAR"/>
            <result property="fax" column="fax" jdbcType="VARCHAR"/>
            <result property="telPhone" column="tel_phone" jdbcType="VARCHAR"/>
            <result property="address" column="address" jdbcType="VARCHAR"/>
            <result property="createName" column="create_name" jdbcType="VARCHAR"/>
<!--            <collection property="materialSupplierLinkDTOList" column="id" select="getLinkList" ofType="com.jeeplus.test.materialManagement.supplier.service.dto.MaterialSupplierLinkDTO"></collection>-->
<!--            <collection property="workAttachmentDtoList" column="id" select="getFileList" ofType="com.jeeplus.p.workContract.service.dto.WorkAttachmentDto"></collection>-->
    </resultMap>

    <resultMap id="AttachmentMap" type="com.jeeplus.psimanage.oss.service.dto.WorkAttachmentDto">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="createBy.id" column="create_by_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy.id" column="update_by_id" jdbcType="VARCHAR"/>
        <result property="createBy.name" column="create_time" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_date" jdbcType="TIMESTAMP"/>
        <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
        <result property="url" column="url" jdbcType="VARCHAR"/>
        <result property="name" column="attachment_name" jdbcType="VARCHAR"/>
        <result property="size" column="file_size" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        ms.id,
        ms.create_by_id,
        ms.create_time,
        ms.update_by_id,
        ms.update_time,
        ms.del_flag,
        ms.remarks,
        ms.name,
        ms.is_usc_code,
        ms.usc_code,
        ms.reconciliation_area,
        ms.character_is,
        ms.zip_code,
        ms.fax,
        ms.tel_phone,
        ms.address
    </sql>

    <sql id="MSL_Column_List">
        msl.id,
        msl.create_by_id,
        msl.create_time,
        msl.update_by_id,
        msl.update_time,
        msl.del_flag,
        msl.remarks,
        msl.name,
        msl.office,
        msl.position,
        msl.sex,
        msl.link_phone,
        msl.link_mobile,
        msl.email,
        msl.supplier_id
    </sql>

    <sql id="File_Column_List">
        wa.id,
        wa.create_by_id,
        wa.create_time,
        wa.update_by_id,
        wa.update_time,
        wa.remarks,
        wa.del_flag,
        wa.url,
        wa.type,
        wa.attachment_id,
        wa.attachment_name,
        wa.attachment_flag,
        wa.module_type,
        wa.attachment_type,
        wa.file_size,
        wa.sort,
        wa.description
    </sql>

    <select id="findList" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"></include>,
            su.name as create_name
        from psi_supplier ms
        left join sys_user su on su.id = ms.create_by_id
        ${ew.customSqlSegment}
        order by ms.create_time desc
    </select>

    <select id="getLinkList" resultType="com.jeeplus.psimanage.supplier.service.dto.PsiMaterialSupplierLinkDTO">
        select
            <include refid="MSL_Column_List"></include>
        from psi_supplier_link msl
        where msl.del_flag = '0' and msl.supplier_id = #{id}
    </select>

    <select id="getFileList" resultMap="AttachmentMap">
        select
            <include refid="File_Column_List"></include>,
            su.name as create_name
        from work_attachment wa
        left join sys_user su on su.id = wa.create_by_id and su.del_flag = '0'
        where wa.del_flag = '0' and wa.attachment_id = #{id}
    </select>

    <select id="queryById" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"></include>
        from psi_supplier ms
        where ms.del_flag = '0' and ms.id = #{id}
    </select>
</mapper>
