<?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.canteen.core.supply.purchase.mapper.DrpPurchaseSupplierMapper">
    <!-- 分页获取供应商信息 -->
<!--    <select id="selectAllList" resultType="net.xnzn.core.drp.vo.DrpSupplierPageVO">-->
<!--        SELECT DISTINCT-->
<!--        a.supplier_id,-->
<!--        a.supplier_num,-->
<!--        a.supplier_name,-->
<!--        a.area_id,-->
<!--        aa.area_name,-->
<!--        a.address,-->
<!--        a.linkman,-->
<!--        a.linkman_number,-->
<!--        a.email,-->
<!--        a.wechat,-->
<!--        a.opening_bank,-->
<!--        a.bank_account,-->
<!--        a.supplier_simple_name,-->
<!--        a.telephone,-->
<!--        a.company_web,-->
<!--        a.region_province,-->
<!--        a.region_city,-->
<!--        a.region_district,-->
<!--        a.tax_rate,-->
<!--        a.payment_days,-->
<!--        a.standby_linkman,-->
<!--        a.standby_phone,-->
<!--        a.standby_email,-->
<!--        a.standby_wechat,-->
<!--        a.regist_fund,-->
<!--        a.establish_date,-->
<!--        a.workers_num,-->
<!--        a.client_num,-->
<!--        a.last_year_operating_income,-->
<!--        a.before_year_operating_income,-->
<!--        a.business_scope,-->
<!--        a.top_five_client,-->
<!--        a.top_five_supplier,-->
<!--        a.company_introduction,-->
<!--        a.main_advantage,-->
<!--        a.if_receive_notice,-->
<!--        a.notice_style,-->
<!--        a.supplier_user_id,-->
<!--        a.`status`,-->
<!--        a.supplier_score,-->
<!--        a.crtime,-->
<!--        a.crby,-->
<!--        a.uptime,-->
<!--        a.upby,-->
<!--        a.id_card_img_z,-->
<!--        a.id_card_img_f,-->
<!--        a.attachment-->
<!--        FROM-->
<!--        drp_supplier a-->
<!--        LEFT JOIN drp_supplier_category b on a.supplier_id = b.supplier_id-->
<!--        LEFT JOIN alloc_area aa on a.area_id = aa.area_id-->
<!--        where-->
<!--        a.del_flag = #{delFlag}-->
<!--        <if test="content.supplierId != null">-->
<!--            and a.supplier_id = #{content.supplierId}-->
<!--        </if>-->
<!--        <if test="content.supplierNum != null and content.supplierNum != ''">-->
<!--            and a.supplier_num = #{content.supplierNum}-->
<!--        </if>-->
<!--        <if test="content.supplierName != null and content.supplierName != ''">-->
<!--            and a.supplier_name like #{content.supplierName}-->
<!--        </if>-->
<!--        <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--            AND a.area_id in-->
<!--            <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="content.linkman != null and content.linkman != ''">-->
<!--            and a.linkman like #{content.linkman}-->
<!--        </if>-->
<!--        <if test="content.status != null">-->
<!--            and a.status = #{content.status}-->
<!--        </if>-->
<!--        <if test="content.ifBindSupplierUser != null and content.ifBindSupplierUser == 1">-->
<!--            and a.supplier_user_id is not null-->
<!--        </if>-->
<!--        <if test="content.ifBindSupplierUser != null and content.ifBindSupplierUser == 2">-->
<!--            and a.supplier_user_id is null-->
<!--        </if>-->
<!--        <if test="content.supplierScore != null">-->
<!--            and a.supplier_score <![CDATA[ >= ]]> #{content.supplierScore}-->
<!--        </if>-->
<!--        <if test="content.categoryIdList != null and content.categoryIdList.size() > 0">-->
<!--            and b.category_id in-->
<!--            <foreach collection="content.categoryIdList" item="categoryId" separator="," open="(" close=")">-->
<!--                #{categoryId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        order by a.crtime desc-->
<!--    </select>-->


<!--    <select id="pageCompariseSupplierQualification"-->
<!--            resultType="net.xnzn.core.drp.vo.DrpCompariseSupplierQualificationPageVO">-->
<!--        SELECT-->
<!--        a.supplier_num,-->
<!--        a.supplier_id,-->
<!--        a.supplier_name,-->
<!--        a.last_year_operating_income,-->
<!--        a.before_year_operating_income,-->
<!--        a.regist_fund,-->
<!--        a.workers_num,-->
<!--        a.establish_date,-->
<!--        a.client_num,-->
<!--        a.area_id,-->
<!--        aa.area_name-->
<!--        FROM-->
<!--        drp_supplier a-->
<!--        LEFT JOIN alloc_area aa on a.area_id = aa.area_id-->
<!--        <where>-->
<!--            a.del_flag = #{delFlag}-->
<!--            <if test="content.supplierId != null">-->
<!--                and a.supplier_id = #{content.supplierId}-->
<!--            </if>-->
<!--            <if test="content.clientNum != null">-->
<!--                and a.client_num <![CDATA[ >= ]]> #{content.clientNum}-->
<!--            </if>-->
<!--            <if test="content.lastYearOperatingIncome != null">-->
<!--                and a.last_year_operating_income <![CDATA[ >= ]]> #{content.lastYearOperatingIncome}-->
<!--            </if>-->
<!--            <if test="content.registFund != null">-->
<!--                and a.regist_fund <![CDATA[ >= ]]> #{content.registFund}-->
<!--            </if>-->
<!--            <if test="content.workersNum != null">-->
<!--                and a.workers_num <![CDATA[ >= ]]> #{content.workersNum}-->
<!--            </if>-->
<!--            <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--                and a.area_id in-->
<!--                <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--        </where>-->
<!--    </select>-->
<!--    <select id="supplyStatistics" resultType="net.xnzn.core.drp.vo.DrpSupplyStatisticsPageVO">-->
<!--        SELECT-->
<!--        a.supplier_num,-->
<!--        a.supplier_id,-->
<!--        a.supplier_name,-->
<!--        a.area_id,-->
<!--        aa.area_name-->
<!--        FROM-->
<!--        drp_supplier a-->
<!--        LEFT JOIN alloc_area aa on a.area_id = aa.area_id-->
<!--        WHERE-->
<!--        a.del_flag = #{delFlag}-->
<!--        <if test="content.supplierId != null">-->
<!--            AND a.supplier_id = #{content.supplierId}-->
<!--        </if>-->
<!--        <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--            and a.area_id in-->
<!--            <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--    </select>-->
<!--    <select id="listSupplierScoreSupplier" resultType="net.xnzn.core.drp.po.SupplierScoreSupplierModel">-->
<!--        SELECT-->
<!--        a.supplier_id,-->
<!--        a.supplier_name,-->
<!--        a.area_id,-->
<!--        a.last_year_operating_income,-->
<!--        a.workers_num,-->
<!--        a.regist_fund,-->
<!--        count(b.supplier_id) mainQualificationNum-->
<!--        FROM-->
<!--        drp_supplier a-->
<!--        LEFT JOIN ( SELECT supplier_id FROM drp_supplier_qualification WHERE validity >= NOW() AND main_flag =-->
<!--        #{mainFlag} ) b ON a.supplier_id = b.supplier_id-->
<!--        WHERE-->
<!--        a.del_flag = #{delFlag}-->
<!--        <if test="content.supplierId != null">-->
<!--            and a.supplier_id = #{content.supplierId}-->
<!--        </if>-->
<!--        <if test="content.areaId != null">-->
<!--            and a.area_id = #{content.areaId}-->
<!--        </if>-->
<!--        GROUP BY-->
<!--        a.supplier_id,-->
<!--        a.supplier_name,-->
<!--        a.area_id,-->
<!--        a.last_year_operating_income,-->
<!--        a.workers_num,-->
<!--        a.regist_fund-->
<!--    </select>-->
<!--    <select id="pageSupplier" resultType="net.xnzn.core.drp.vo.DrpSupplierScorePageVO">-->
<!--        SELECT-->
<!--        a.supplier_id,-->
<!--        a.supplier_name,-->
<!--        a.area_id,-->
<!--        aa.area_name-->
<!--        FROM-->
<!--        drp_supplier a-->
<!--        LEFT JOIN alloc_area aa on a.area_id = aa.area_id-->
<!--        where-->
<!--        a.del_flag = #{delFlag}-->
<!--        <if test="content.supplierId != null">-->
<!--            and a.supplier_id = #{content.supplierId}-->
<!--        </if>-->
<!--        <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--            and a.area_id in-->
<!--            <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--    </select>-->
    <select id="getSupplierMainInfoById" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierMainInfoVO">
        SELECT
            ds.supplier_id,
            ds.supplier_num,
            ds.supplier_name,
            ds.address,
            ds.linkman,
            ds.linkman_number,
            ds.email,
            ds.wechat,
            ds.opening_bank,
            ds. bank_account,
            ds. supplier_simple_name,
            ds.telephone,
            ds.company_web,
            ds.region_province,
            ds.region_city,
            ds.region_district,
            ds.tax_rate,
            ds.payment_days,
            ds.standby_linkman,
            ds.standby_phone,
            ds.standby_email,
            ds.standby_wechat,
            ds.regist_fund,
            ds.establish_date,
            ds.workers_num,
            ds.client_num,
            ds.last_year_operating_income,
            ds.before_year_operating_income,
            ds.business_scope,
            ds.top_five_client,
            ds.top_five_supplier,
            ds.company_introduction,
            ds.main_advantage,
            ds. if_receive_notice,
            ds.notice_style,
            ds.supplier_user_id,
            ds.`status`,
            ds.supplier_score,
            ds.area_id,
            aa.area_name
        FROM
        drp_supplier ds
        LEFT JOIN alloc_area aa on ds.area_id = aa.area_id
        where
            ds.supplier_id = #{supplierId}
    </select>
<!--  <select id="queryTotal" resultType="net.xnzn.core.drp.vo.DrpSupplierTotalVO">-->
<!--      SELECT-->
<!--            (SELECT COUNT(*) FROM drp_supplier WHERE status = 2) AS 'total',-->
<!--            (SELECT COUNT(*) FROM drp_supplier WHERE month(crtime) = month(CURDATE()) AND status = 2) AS 'monthly_increase';-->
<!--  </select>-->
<!--    <select id="queryTotal" resultType="net.xnzn.core.drp.vo.DrpSupplierTotalVO" databaseId="kb">-->
<!--        SELECT-->
<!--                (SELECT COUNT(*) FROM drp_supplier WHERE status = 2) AS "total",-->
<!--                (SELECT COUNT(*) FROM drp_supplier WHERE EXTRACT(YEAR FROM crtime) = EXTRACT(YEAR FROM CURRENT_DATE) AND EXTRACT(MONTH FROM crtime) = EXTRACT(MONTH FROM CURRENT_DATE) AND status = 2) AS "monthly_increase";-->

<!--    </select>-->

<!--    <select id="listSupplierNew" resultType="net.xnzn.core.drp.vo.DrpSupplierVO">-->
<!--        select supplier_id,supplier_name,supplier_score from drp_supplier where status = #{status} and del_flag = #{delFlag}-->
<!--        <if test="content.supplierName != null and content.supplierName != ''">-->
<!--            and supplier_name like concat('%',#{content.supplierName},'%')-->
<!--        </if>-->
<!--        <if test="content.supplierIdList != null and content.supplierIdList.size()>0">-->
<!--            AND supplier_id IN-->
<!--            <foreach collection="content.supplierIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="content.areaIdList != null and content.areaIdList.size() > 0">-->
<!--            and area_id in-->
<!--            <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--    </select>-->
    <select id="listSupplier" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierVO">
        SELECT
        ds.supplier_id,
        ds.supplier_name,
        ds.supplier_score,
        ds.area_id,
        aa.area_name
        FROM
        drp_supplier ds
        LEFT JOIN alloc_area aa ON aa.area_id = ds.area_id
        where ds.status = #{status}
        and ds.del_flag = #{delFlag}
        <if test="content.areaIdList != null and content.areaIdList.size() > 0">
            and ds.area_id in
            <foreach collection="content.areaIdList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="content.supplierName != null and content.supplierName != ''">
            and ds.supplier_name like concat('%',#{content.supplierName},'%')
        </if>
    </select>

<!--    <select id="getCategorySupplier" resultType="net.xnzn.core.drp.vo.DrpMaterialSupplierVO"-->
<!--            parameterType="net.xnzn.core.drp.dto.DrpMaterialInfoDTO">-->
<!--        select-->
<!--        mmc.category_id,-->
<!--        mmc.category_name,-->
<!--        dms.supplier_id,-->
<!--        ds.supplier_name,-->
<!--        dms.alternative_supplier,-->
<!--        dms.canteen_id-->
<!--        from menu_material_category mmc-->
<!--        left join drp_menu_material_supplier dms on mmc.category_id  = dms.category_id and dms.material_id is null-->
<!--        <if test="content.canteenId != null">-->
<!--            and dms.canteen_id = #{content.canteenId}-->
<!--        </if>-->
<!--        left join drp_supplier ds on dms.supplier_id = ds.supplier_id-->
<!--        <where>-->
<!--            and mmc.del_flag = 2-->
<!--            and (-->
<!--            mmc.area_id in (select area_id from alloc_canteen where canteen_id = #{content.canteenId})-->
<!--            or mmc.area_id is null-->
<!--            )-->
<!--            <if test="content.categoryIdList != null and content.categoryIdList.size() > 0">-->
<!--                and mmc.category_id in-->
<!--                <foreach collection="content.categoryIdList" item="categoryId" separator="," open="(" close=")">-->
<!--                    #{categoryId}-->
<!--                </foreach>-->
<!--            </if>-->
<!--        </where>-->
<!--    </select>-->


</mapper>







