<?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.chinaweal.aiccs.aiccs.fraudreg.mapper.TBizFraudMapper">

    <select id="statistics" resultType="java.util.Map">
        select
            o.orgUnitName as "单位名称",
            count(case when bf.complaintReason = '冒用他人身份信息登记' then 1 else null end) as "冒用他人身份信息登记-业务办理总数",
            count(case when bf.complaintReason = '冒用他人身份信息登记' and bf.status in ('1', '2')then 1 else null end) as "冒用他人身份信息登记-办理中业务数",
            count(case when bf.complaintReason = '冒用他人身份信息登记' and bf.status = '3' then 1 else null end) as "冒用他人身份信息登记-办结业务数",
            count(case when bf.complaintReason = '冒用他人身份信息登记' and bf.bizHandleResult in ('撤销设立', '撤销变更', '撤销注销') then 1 else null end) as "冒用他人身份信息登记-其中撤销决定业务数",
            count(case when bf.complaintReason = '冒用他人身份信息登记' and bf.bizHandleResult = '终止撤销' then 1 else null end) as "冒用他人身份信息登记-终止撤销",
            count(case when bf.complaintReason = '冒用他人身份信息登记' and bf.bizHandleResult = '不予撤销' then 1 else null end) as "冒用他人身份信息登记-不予受理",
            count(case when bf.complaintReason = '冒用地址信息登记' then 1 else null end) as "冒用地址信息登记-业务办理总数",
            count(case when bf.complaintReason = '冒用地址信息登记' and bf.status in ('1', '2')then 1 else null end) as "冒用地址信息登记-办理中业务数",
            count(case when bf.complaintReason = '冒用地址信息登记' and bf.status = '3' then 1 else null end) as "冒用地址信息登记-办结业务数",
            count(case when bf.complaintReason = '冒用地址信息登记' and bf.bizHandleResult in ('撤销设立', '撤销变更', '撤销注销') then 1 else null end) as "冒用地址信息登记-其中撤销决定业务数",
            count(case when bf.complaintReason = '冒用地址信息登记' and bf.bizHandleResult = '终止撤销' then 1 else null end) as "冒用地址信息登记-终止撤销",
            count(case when bf.complaintReason = '冒用地址信息登记' and bf.bizHandleResult = '不予撤销' then 1 else null end) as "冒用地址信息登记-不予受理",
            count(case when bf.complaintReason = '冒用其他信息登记' then 1 else null end) as "冒用其他信息登记-业务办理总数",
            count(case when bf.complaintReason = '冒用其他信息登记' and bf.status in ('1', '2')then 1 else null end) as "冒用其他信息登记-办理中业务数",
            count(case when bf.complaintReason = '冒用其他信息登记' and bf.status = '3' then 1 else null end) as "冒用其他信息登记-办结业务数",
            count(case when bf.complaintReason = '冒用其他信息登记' and bf.bizHandleResult in ('撤销设立', '撤销变更', '撤销注销') then 1 else null end) as "冒用其他信息登记-其中撤销决定业务数",
            count(case when bf.complaintReason = '冒用其他信息登记' and bf.bizHandleResult = '终止撤销' then 1 else null end) as "冒用其他信息登记-终止撤销",
            count(case when bf.complaintReason = '冒用其他信息登记' and bf.bizHandleResult = '不予撤销' then 1 else null end) as "冒用其他信息登记-不予受理"
        from cxaicorg.t_orgunits o left join t_biz_fraud bf on o.orgNumber = bf.orgUnitID  and bf.linkType = '4'
        where length(o.orgNumber) = 6 and o.deleted  = '0'
        <if test="aicCode != null and aicCode != ''">
            and o.orgNumber = #{aicCode}
        </if>
        group by o.orgNumber
    </select>

</mapper>
