<?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.mapper.DrpSupplierQualificationMapper">

    <select id="expire" resultType="com.bonus.canteen.core.supply.dto.DrpSupplierQualificationExpireVO">
        SELECT
        ds.supplier_id,
        ds.supplier_num,
        ds.supplier_name,
        ds.area_id,
        aa.area_name,
        ds.linkman,
        ds.linkman_number,
        dsq.qualification_num,
        dsq.qualification_name,
        dsq.main_flag,
        dsq.validity,
        dsq.img_url
        FROM
        drp_supplier_qualification dsq
        LEFT JOIN drp_supplier ds ON ds.supplier_id = dsq.supplier_id
        LEFT JOIN alloc_area aa on ds.area_id = aa.area_id
        <where>
            <if test="content.qualificationNum != null and content.qualificationNum != '' ">
                and dsq.qualification_num like concat('%', #{content.qualificationNum}, '%')
            </if>
            <if test="content.qualificationName != null and content.qualificationName != '' ">
                and dsq.qualification_name like concat('%', #{content.qualificationName}, '%')
            </if>
            <if test="content.supplierId != null and content.supplierId != '' ">
                and ds.supplier_id = #{content.supplierId}
            </if>
            <if test="content.isLessThanMonth != null and content.isLessThanMonth != '' ">
                <if test="content.isLessThanMonth == 1 ">
                    and (DATEDIFF(dsq.validity, now())) <![CDATA[<]]> 30
                </if>
                <if test="content.isLessThanMonth == 2 ">
                    and (DATEDIFF(dsq.validity, now())) <![CDATA[>=]]> 30
                </if>
            </if>
            <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>
        </where>
    </select>
</mapper>
