<?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.yc.ship.module.resource.dal.mysql.supplier.ProductSupplierMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="queryPage" resultType="com.yc.ship.module.resource.controller.admin.supplier.vo.SupplierRespVO">
        SELECT
        t.id,t.name,t.short_name,t.type,t.use_status,t.tax_id,t.telephone,t.interbank_number,
        t.cooperate_start_time,t.cooperate_end_time,t.contact_man,t.contact_phone,t.contact_address,t.business_area,
        t.contract,t.is_system_direct,t.direct_param,t.direct_account,t.direct_check_url,t.direct_order_url,
        t.direct_refund_url,t.unit_name,t.unit_address,t.bank_name,t.bank_account,t.direct_server,t.create_time,
        GROUP_CONCAT(cate_name SEPARATOR ',') AS resource_category
        FROM(
            SELECT
                t1.id,t1.name,t1.short_name,t1.type,t1.use_status,t1.direct_server,
                t3.cate_name,t1.cooperate_start_time,t1.cooperate_end_time,t1.contact_man,t1.contact_phone,t1.contact_address,t1.business_area,
                t1.contract,t1.is_system_direct,t1.direct_param,t1.direct_account,t1.direct_check_url,t1.direct_order_url,t1.direct_refund_url,
                t1.unit_name,t1.unit_address,t1.bank_name,t1.bank_account,t1.tax_id,t1.telephone,t1.interbank_number,t1.create_time,t1.update_time
            FROM
            product_supplier t1
            left JOIN product_supplier_category t2 ON t1.id = t2.supplier_id
            left JOIN product_category t3 ON t2.category_id = t3.id
            where 1=1 and t1.deleted =0
            <if test="param.name != null and param.name !=''">
                <bind name="bindName" value="'%'+param.name+'%'"/>
                and t1.name like #{bindName}
            </if>
            <if test="param.type != null ">
                and FIND_IN_SET(t1.type,#{param.type})
            </if>
            <if test="param.useStatus != null and param.useStatus !=''">
                and FIND_IN_SET(t1.use_status,#{param.useStatus})
            </if>
        ) t
        GROUP BY t.id
        order by t.create_time desc , t.update_time desc

    </select>


    <select id="getSimpleListByCategory" resultType="com.yc.ship.module.resource.dal.dataobject.supplier.ProductSupplierDO">
        select ps.name,ps.id,ps.type from product_supplier ps
        INNER JOIN product_supplier_category psc
        on ps.id = psc.supplier_id and psc.category_id = #{param.cateId}
        where ps.deleted = 0 and ps.use_status =#{param.useStatus}
        GROUP BY ps.id
        order by ps.id desc
    </select>


</mapper>