<?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.gree.mall.manager.commonmapper.workorder.IncreMapper">


    <select id="list" resultType="com.gree.mall.manager.bean.workorder.IncreVO">
        SELECT
        ${ex.selected}
        FROM pg_incre a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listDispatch" resultType="com.gree.mall.manager.bean.workorder.DispatchVO">
        SELECT
        a.province_name,
        a.province_code,
        a.city_name,
        a.city_code,
        a.area_name,
        a.area_code,
        a.name as streetName,
        a.id as streetCode,
        b.dict_value,
        b.dict_code,
        c.order_small_type_text,
        c.id as orderSmallId,
        d.name as categoryName,
        d.category_id,
        e.dict_value as order_source,
        e.dict_code as order_source_id
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ${ex.query}
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null


    </select>
    <select id="listDispatchWebsit" resultType="com.gree.mall.manager.bean.workorder.WebsitDispatchVO">
        SELECT
        ${ex.selected}
        FROM websit_dispatch a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="pList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        a.province_name as valueName,
        a.province_code as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
      where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

     group by a.province_code
    </select>
    <select id="cList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        a.city_name as valueName,
        a.city_code as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by a.city_code
    </select>
    <select id="aList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        a.area_name as valueName,
        a.area_code as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by a.area_code
    </select>
    <select id="sList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        a.name as valueName,
        a.id as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by a.id
    </select>
    <select id="channel" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        b.dict_value as valueName,
        b.dict_code as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by b.dict_code
    </select>
    <select id="smallList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        c.order_small_type_text as valueName,
        c.id as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by c.id
    </select>
    <select id="categoryList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        d.name as valueName,
        d.category_id as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by d.category_id
    </select>
    <select id="sourceList" resultType="com.gree.mall.manager.bean.workorder.DispatchCherVO">
        SELECT
        e.dict_value as valueName,
        e.dict_code as keyId
        FROM
        region a
        join sys_dict_company b on b.dict_type = 'ORDER_CHANNEL' and b.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND b.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join order_small_type c
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            on c.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join goods_category d on d.type = 2 and d.del =0 and d.`level` = 1
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND d.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        join sys_dict_company e on e.dict_type = 'WORKER_ORDER_SOURCE' and e.del = 0
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND e.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        LEFT JOIN websit_dispatch f on a.id = f.street_code and b.dict_code = f.dict_code and c.id = f.order_small_id and d.category_id = f.category_id and e.dict_code = f.order_source_id
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND f.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        where 1=1
        and
        a.city_name IN ( '广州市', '清远市', '韶关市', '佛山市', '肇庆市', '云浮市' )
        AND a.`level` = 4
        and f.id is null

        <if test="pId != null and pId !=''">
            AND a.province_code = #{pId}
        </if>
        <if test="cityCode != null and cityCode !=''">
            AND a.city_code = #{cityCode}
        </if>
        <if test="areaCode != null and areaCode !=''">
            AND a.area_code = #{areaCode}
        </if>
        <if test="streetCode != null and streetCode !=''">
            AND a.id =  #{streetCode}
        </if>
        <if test="dictCode != null and dictCode.size > 0">
            AND b.dict_code IN
            <foreach item="item" index="index" collection="dictCode" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSmallId != null and orderSmallId.size > 0">
            AND c.id in
            <foreach item="item" index="index" collection="orderSmallId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="categoryId != null and categoryId.size > 0">
            AND d.category_id in
            <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="orderSourceId != null and orderSourceId.size > 0">
            AND e.dict_code in
            <foreach item="item" index="index" collection="orderSourceId" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        group by  e.dict_code
    </select>
    <select id="listAbnormal" resultType="com.gree.mall.manager.bean.workorder.AbnormalVO">
        SELECT
        ${ex.selected}
        FROM abnormal a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
</mapper>