<?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.unis.circulateMonitor.modular.easeEnterprise.mapper.EaseEnterpriseMapper">
    <select id="pageList" parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper" resultType="com.unis.circulateMonitor.modular.easeEnterprise.entity.EaseEnterprise">
        SELECT
            gee.*, CASE gee.is_distribution_center
        WHEN 0 THEN
            '否'
        WHEN 1 THEN
            '是'
        ELSE
            ''
        END isDistributionCenterName,
         CASE gee.is_operative_store
        WHEN 0 THEN
            '否'
        WHEN 1 THEN
            '是'
        ELSE
            ''
        END isOperativeStoreName,
         bar.audit_user_id auditUserId,
         su.`NAME` auditUserName,
         bar.audit_time auditTime
        FROM
            biz_cm_go_ease_enterprise gee
        LEFT JOIN dev_dict dd ON gee.enterprise_province = dd.ID
        LEFT JOIN dev_dict dd1 ON gee.enterprise_city = dd1.ID
        LEFT JOIN dev_dict dd2 ON gee.enterprise_area = dd2.ID
        LEFT JOIN biz_audit_request bar ON gee.id = bar.request_id
        LEFT JOIN sys_user su ON su.ID = bar.audit_user_id
        ${ew.customSqlSegment}
    </select>
    <select id="getEnterpriseList" resultType="map">
        SELECT
            id,
            enterprise_name enterpriseName
        FROM
            biz_cm_go_ease_enterprise
    </select>
    <!-- totalCount:基础信息数量,requestCount:放心粮油申请数量,auditCount:放心粮油已审批数量 -->
    <select id="getCountNumber" resultType="map">
        SELECT
            COUNT(1) totalCount,
            SUM(CASE WHEN `status`=1 THEN 1 ELSE 0 END) requestCount,
          SUM(CASE WHEN `status`=3 OR `status`=2 THEN 1 ELSE 0 END) auditCount
        FROM
            biz_cm_go_ease_enterprise
    </select>
</mapper>