<?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.policy.info.modular.auditRequest.mapper.AuditRequestMapper">
    <select id="queryReconds" resultType="java.util.Map">
        SELECT c.name                                    as "auditUserName",
               DATE_FORMAT(a.audit_time, '%Y-%m-%d %T')  as "auditTime",
               DATE_FORMAT(b.launch_time, '%Y-%m-%d %T') as "launchTime",
               a.audit_status                            as "auditStatus",
               a.audit_advice                            as "auditAdvice"
        FROM biz_audit_record a
                 INNER JOIN biz_al_policy_file_report b ON a.request_id = b.id
                 LEFT JOIN sys_user c on a.audit_user_id = c.ID
        where a.request_id = #{reporttId}
        ORDER BY a.create_time
    </select>


    <select id="selectMyPage" resultType="com.unis.policy.info.modular.auditRequest.vo.AuditRequestVO">


        SELECT bgqa.id,
        bui.dwmc,
        bui.dwdm,
        bui.fddbr,
        dd.DICT_LABEL dwlx,
        bgqa.apply_status,
        bgqa.apply_type,
        ifnull( bgq.audit_status,0) auditStatus
        FROM biz_sqr_enterprise_apply bgqa
        LEFT JOIN biz_unit_info bui ON bgqa.unit_info_id = bui.id
        LEFT JOIN biz_audit_request bgq ON bgqa.id = bgq.request_id
        left join dev_dict dd on dd.id=bui.dwlx
        <where>
            bgqa.apply_status='1' and bgqa.apply_type='1' and bui.delete_flag='NOT_DELETE'
            <if test="dwmc !=null and dwmc!=''">
                and bui.dwmc like concat("%",#{dwmc},"%")
            </if>
        </where>

        order by bgqa.create_time desc

    </select>

    <select id="enterprisePage" resultType="com.unis.policy.info.modular.auditRequest.vo.AuditRequestVO">
        SELECT ent.id, uni.dwmc, dd.DICT_LABEL dwlx, uni.dwdm, uni.fddbr
        FROM biz_sqr_enterprise ent
        LEFT JOIN biz_unit_info uni
        ON ent.unit_info_id = uni.id
        left join dev_dict dd on dd.id=uni.dwlx
        where ent.STATUS = 2
        and uni.delete_flag = 'NOT_DELETE'
        <if test="dwmc !=null and dwmc!=''">
            and uni.dwmc like concat("%",#{dwmc},"%")
        </if>
        order by ent.create_time desc
    </select>

    <select id="continuationPage" resultType="com.unis.policy.info.modular.auditRequest.vo.AuditRequestVO">
        SELECT
        bgqa.id,A.id unitInfoId,A.dwmc,A.dwdm,A.fddbr,A.DICT_LABEL dwlx,bgqa.apply_status,bgqa.reissue_time,bgqa.apply_type,bgq.audit_status
        FROM
        biz_sqr_enterprise_apply bgqa
        LEFT JOIN biz_audit_request bgq ON bgqa.id = bgq.request_id
        LEFT JOIN (
        SELECT
        bui.id,
        bui.dwmc,
        bui.dwdm,
        bui.fddbr,
        bui.dwlx,
        bui.zcdz,
        bui.cfs,
        bui.ygs,
        dict.DICT_LABEL
        FROM
        province_all.biz_unit_info bui
        LEFT JOIN province_all.dev_dict dict ON bui.dwlx = dict.id
        WHERE
        bui.delete_flag = 'NOT_DELETE'
        ) A ON A.id = bgqa.unit_info_id
        WHERE
        bgqa.apply_type = '2'
        AND bgqa.apply_status = '1'
        <if test="dwmc !=null and dwmc!=''">
            and A.dwmc like concat("%",#{dwmc},"%")
        </if>
        order by bgqa.create_time desc
    </select>

     <select id="reissuePage" resultType="com.unis.policy.info.modular.auditRequest.vo.AuditRequestVO">
        SELECT a1.id, a3.dwmc, dd.DICT_LABEL dwlx, a3.dwdm, a3.fddbr,ifnull( a4.audit_status,0)
        auditStatus,a1.reissue_time
        FROM biz_sqr_enterprise_apply a1
        LEFT JOIN biz_unit_info a3 ON a1.unit_info_id = a3.id
        left join dev_dict dd on dd.id=a3.dwlx
        left join biz_audit_request a4 on a4.request_id=a1.id
        WHERE
        a1.apply_type = '3'
        and
        a1.apply_status = '1'
        and
        a3.delete_flag = 'NOT_DELETE'
        <if test="dwmc !=null and dwmc!=''">
            and a3.dwmc like concat("%",#{dwmc},"%")
        </if>
        order by a1.create_time desc
    </select>


    <select id="selectReissueInfo" resultType="com.unis.policy.info.modular.auditRequest.vo.UnitInfoVO">
        SELECT t4.dwmc,
               t4.dwdm,
               t4.zcdz,
               t4.fddbr,
               dd.DICT_LABEL dwlx,
               t2.reissue_time,
               t2.attachment,
               t1.audit_advice
        FROM biz_audit_request t1
                 LEFT JOIN biz_sqr_enterprise_apply t2 ON t1.request_id = t2.id
                 LEFT JOIN biz_unit_info t4 on t4.id = t2.unit_info_id
                 left join dev_dict dd on dd.id = t4.dwlx
        where t2.id = #{id}
          and t4.delete_flag = 'NOT_DELETE'
    </select>


    <select id="infoChangesPage" resultType="com.unis.policy.info.modular.auditRequest.vo.AuditRequestVO">
        SELECT a1.id, a3.dwmc, dd.DICT_LABEL dwlx, a3.dwdm, a3.fddbr,ifnull( a4.audit_status,0)
        auditStatus,a1.reissue_time
        FROM biz_sqr_enterprise_apply a1
        LEFT JOIN biz_unit_info a3 ON a1.unit_info_id = a3.id
        left join dev_dict dd on dd.id=a3.dwlx
        left join biz_audit_request a4 on a4.request_id=a1.id
        WHERE
        a1.apply_type = '4'
        and
        a1.apply_status = '1'
        and
        a3.delete_flag = 'NOT_DELETE'
        <if test="dwmc !=null and dwmc!=''">
            and a3.dwmc like concat("%",#{dwmc},"%")
        </if>
        order by a1.create_time desc
    </select>
    <select id="esNetworkEntryPage" resultType="com.unis.emergencySupport.modular.es.entity.EsNetworkEntry">
        select
            ene.id,
            ene.city_state,
            ene.enterprise_name,
            ene.contact_number,
            ene.contact_person,
            ar.audit_status auditStatus,
            su.Name
        from biz_es_network_entry ene
                 left  join biz_audit_request ar on ar.request_id =ene.id
        left join sys_user su on ar.audit_user_id=su.id
        where ar.type =5 and ar.step=1
        <if test="esNetworkEntryPageParam.enterpriseName !=null and esNetworkEntryPageParam.enterpriseName!=''">
            and ene.enterprise_name like concat("%",#{esNetworkEntryPageParam.enterpriseName},"%")
        </if>
    </select>



    <select id="selectApprovalPage"
            resultType="com.unis.policy.info.modular.auditRequest.vo.PmApplicationVO">

        SELECT
        t2.*,
        t1.audit_status
        FROM
        biz_audit_request t1
        LEFT JOIN biz_pm_application t2 ON t1.request_id = t2.id
        <where>
            t1.type = '6'
            AND t1.step = '1'
            <if test="projectName!=null and projectName!=''">
                and t2.project_name like concat("%",#{projectName},"%")
            </if>
            <if test="auditStatus!=null ">
                and t1.audit_status=#{auditStatus}
            </if>
        </where>
        order by t2.create_time desc

    </select>


    <select id="selectPmStorageConstructionPage"
            resultType="com.unis.projectManagement.modular.pmStorageConstruction.entity.PmStorageConstruction">

        SELECT
        t2.*
        FROM
        biz_audit_request t1
        LEFT JOIN biz_pm_storage_construction t2 ON t1.request_id = t2.id
        <where>
            t1.type = '9'
            AND t1.step = '1'
            <if test="projectName!=null and projectName!=''">
                and t2.project_name like concat("%",#{projectName},"%")
            </if>
        </where>
        order by t2.create_time desc

    </select>
</mapper>