| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780 |
- <?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="cn.com.goldenwater.dcproj.dao.AttProjectInsuranceDao">
- <resultMap type="cn.com.goldenwater.dcproj.model.AttProjectInsurance" id="attProjectInsuranceResultMap">
- <result property="businessType" column="BUSINESS_TYPE"/>
- <result property="adName" column="AD_NAME"/>
- <result property="adCode" column="AD_CODE"/>
- <result property="id" column="ID"/>
- <result property="name" column="NAME"/>
- <result property="type" column="TYPE"/>
- <result property="loc" column="LOC"/>
- <result property="investment" column="INVESTMENT"/>
- <result property="plannedDuration" column="PLANNED_DURATION"/>
- <result property="startDate" column="START_DATE"/>
- <result property="status" column="STATUS"/>
- <result property="managementUnit" column="MANAGEMENT_UNIT"/>
- <result property="constructors" column="CONSTRUCTORS"/>
- <result property="contactPerson" column="CONTACT_PERSON"/>
- <result property="centerX" column="CENTER_X"/>
- <result property="centerY" column="CENTER_Y"/>
- <result property="gdX" column="GD_X"/>
- <result property="gdY" column="GD_Y"/>
- <result property="intm" column="INTM"/>
- <result property="uptm" column="UPTM"/>
- <result property="dataStat" column="DATA_STAT"/>
- </resultMap>
- <sql id="table_columns">
- BUSINESS_TYPE
- ,
- AD_NAME,
- AD_CODE,
- ID,
- NAME,
- TYPE,
- LOC,
- INVESTMENT,
- PLANNED_DURATION,
- START_DATE,
- STATUS,
- MANAGEMENT_UNIT,
- CONSTRUCTORS,
- CONTACT_PERSON,
- CENTER_X,
- CENTER_Y,
- GD_X,
- GD_Y,
- INTM,
- UPTM,
- DATA_STAT
- </sql>
- <sql id="entity_properties">
- #{businessType},
- #{adName},
- #{adCode},
- #{id},
- #{name},
- #{type},
- #{loc},
- #{investment},
- #{plannedDuration},
- #{startDate},
- #{status},
- #{managementUnit},
- #{constructors},
- #{contactPerson},
- #{centerX},
- #{centerY},
- #{gdX},
- #{gdY},
- #{intm},
- #{uptm},
- #{dataStat}
- </sql>
- <sql id="page_where">
- <trim prefix="where" prefixOverrides="and | or ">
- <if test="adName != null and adName != ''">and AD_NAME = #{adName}</if>
- <if test="businessType != null and businessType != ''">and BUSINESS_TYPE = #{businessType}</if>
- <if test="adCode != null and adCode != ''">and AD_CODE = #{adCode}</if>
- <if test="id != null and id != ''">and ID = #{id}</if>
- <if test="name != null and name != ''">and NAME like '%${name}%'</if>
- <if test="type != null and type != ''">and TYPE = #{type}</if>
- <if test="loc != null and loc != ''">and LOC = #{loc}</if>
- <if test="investment != null and investment != ''">and INVESTMENT = #{investment}</if>
- <if test="plannedDuration != null and plannedDuration != ''">and PLANNED_DURATION = #{plannedDuration}</if>
- <if test="startDate != null">and START_DATE = #{startDate}</if>
- <if test="status != null and status != ''">and STATUS = #{status}</if>
- <if test="managementUnit != null and managementUnit != ''">and MANAGEMENT_UNIT = #{managementUnit}</if>
- <if test="constructors != null and constructors != ''">and CONSTRUCTORS = #{constructors}</if>
- <if test="contactPerson != null and contactPerson != ''">and CONTACT_PERSON = #{contactPerson}</if>
- <if test="centerX != null and centerX != ''">and CENTER_X = #{centerX}</if>
- <if test="centerY != null and centerY != ''">and CENTER_Y = #{centerY}</if>
- <if test="gdX != null and gdX != ''">and GD_X = #{gdX}</if>
- <if test="gdY != null and gdY != ''">and GD_Y = #{gdY}</if>
- <if test="intm != null">and INTM = #{intm}</if>
- <if test="uptm != null">and UPTM = #{uptm}</if>
- and DATA_STAT='0'
- </trim>
- </sql>
- <select id="get" resultMap="attProjectInsuranceResultMap" parameterType="String">
- select
- <include refid="table_columns"/>
- from ATT_PROJECT_INSURANCE where ID = #{id}
- </select>
- <select id="getBy" resultMap="attProjectInsuranceResultMap">
- select
- <include refid="table_columns"/>
- from ATT_PROJECT_INSURANCE
- <include refid="page_where"/>
- </select>
- <select id="findAll" resultMap="attProjectInsuranceResultMap">
- select
- <include refid="table_columns"/>
- from ATT_PROJECT_INSURANCE
- </select>
- <select id="findList" resultMap="attProjectInsuranceResultMap">
- select
- <include refid="table_columns"/>
- from ATT_PROJECT_INSURANCE
- <include refid="page_where"/>
- </select>
- <select id="selectCount" resultType="int">
- select count(ID) from ATT_PROJECT_INSURANCE
- <include refid="page_where"/>
- </select>
- <insert id="insert" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
- insert into ATT_PROJECT_INSURANCE(
- <include refid="table_columns"/>
- )
- values (
- <include refid="entity_properties"/>
- )
- </insert>
- <delete id="delete" parameterType="java.lang.String">
- update ATT_PROJECT_INSURANCE
- set DATA_STAT='9'
- where ID = #{id}
- </delete>
- <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
- update ATT_PROJECT_INSURANCE set DATA_STAT='9'
- <include refid="page_where"/>
- </delete>
- <update id="deleteInFlag" parameterType="java.lang.String">
- update ATT_PROJECT_INSURANCE
- set DATA_STAT = '9'
- where ID = #{id}
- </update>
- <update id="update" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
- update ATT_PROJECT_INSURANCE
- <trim prefix="set" suffixOverrides=",">
- <if test="adName != null and adName != ''">AD_NAME = #{adName},</if>
- <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
- <if test="id != null and id != ''">ID = #{id},</if>
- <if test="name != null and name != ''">NAME = #{name},</if>
- <if test="type != null and type != ''">TYPE = #{type},</if>
- <if test="loc != null and loc != ''">LOC = #{loc},</if>
- <if test="investment != null and investment != ''">INVESTMENT = #{investment},</if>
- <if test="plannedDuration != null and plannedDuration != ''">PLANNED_DURATION = #{plannedDuration},</if>
- <if test="startDate != null">START_DATE = #{startDate},</if>
- <if test="status != null and status != ''">STATUS = #{status},</if>
- <if test="managementUnit != null and managementUnit != ''">MANAGEMENT_UNIT = #{managementUnit},</if>
- <if test="constructors != null and constructors != ''">CONSTRUCTORS = #{constructors},</if>
- <if test="contactPerson != null and contactPerson != ''">CONTACT_PERSON = #{contactPerson},</if>
- <if test="centerX != null and centerX != ''">CENTER_X = #{centerX},</if>
- <if test="centerY != null and centerY != ''">CENTER_Y = #{centerY},</if>
- <if test="gdX != null and gdX != ''">GD_X = #{gdX},</if>
- <if test="gdY != null and gdY != ''">GD_Y = #{gdY},</if>
- <if test="intm != null">INTM = #{intm},</if>
- <if test="uptm != null">UPTM = #{uptm},</if>
- <if test="dataStat != null and dataStat != ''">DATA_STAT = #{dataStat},</if>
- </trim>
- <where>ID = #{id}</where>
- </update>
- <update id="updateBy" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
- update ATT_PROJECT_INSURANCE
- <trim prefix="set" suffixOverrides=",">
- <if test="adName != null and adName != ''">AD_NAME = #{adName},</if>
- <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
- <if test="id != null and id != ''">ID = #{id},</if>
- <if test="name != null and name != ''">NAME = #{name},</if>
- <if test="type != null and type != ''">TYPE = #{type},</if>
- <if test="loc != null and loc != ''">LOC = #{loc},</if>
- <if test="investment != null and investment != ''">INVESTMENT = #{investment},</if>
- <if test="plannedDuration != null and plannedDuration != ''">PLANNED_DURATION = #{plannedDuration},</if>
- <if test="startDate != null">START_DATE = #{startDate},</if>
- <if test="status != null and status != ''">STATUS = #{status},</if>
- <if test="managementUnit != null and managementUnit != ''">MANAGEMENT_UNIT = #{managementUnit},</if>
- <if test="constructors != null and constructors != ''">CONSTRUCTORS = #{constructors},</if>
- <if test="contactPerson != null and contactPerson != ''">CONTACT_PERSON = #{contactPerson},</if>
- <if test="centerX != null and centerX != ''">CENTER_X = #{centerX},</if>
- <if test="centerY != null and centerY != ''">CENTER_Y = #{centerY},</if>
- <if test="gdX != null and gdX != ''">GD_X = #{gdX},</if>
- <if test="gdY != null and gdY != ''">GD_Y = #{gdY},</if>
- <if test="intm != null">INTM = #{intm},</if>
- <if test="uptm != null">UPTM = #{uptm},</if>
- <if test="dataStat != null and dataStat != ''">DATA_STAT = #{dataStat},</if>
- </trim>
- <include refid="page_where"/>
- </update>
- <!-- 其他自定义SQL -->
- <select id="getByRgstrId" resultMap="attProjectInsuranceResultMap">
- SELECT A.*
- FROM ATT_PROJECT_INSURANCE A
- JOIN BIS_INSP_ALL_OBJ B ON A.ID = B.CODE
- JOIN BIS_INSP_ANZE_RGSTR ON B.OBJ_ID = C.OBJ_ID
- where C.ID = #{id}
- </select>
- <select id="listOfUnderwriting" resultType="cn.com.goldenwater.dcproj.dto.AttAnzeUnderwritingDto">
- SELECT
- A.ID, A.AD_CODE, A.AD_NAME, A.NAME, A.TYPE, A.LOC, A.INVESTMENT,
- A.PLANNED_DURATION, A.START_DATE, A.STATUS, A.MANAGEMENT_UNIT,
- A.CONTACT_PERSON, A.CENTER_X, A.CENTER_Y, A.GD_X, A.GD_Y,
- B.ID AS recordId, B.POLICYHOLDER, B.POLICYHOLDER_PHONE, B.INSURANCE_COMPANY,
- B.INSURANCE_CONTACT_PERSON, B.INSURANCE_CONTACT_PHONE, B.PREMIUM_AMOUNT, B.PREVENTION_SERVICE_FEE,
- B.INSURANCE_DATE, B.PREVENTION_SERVICE_UNIT, B.SERVICE_UNIT_CONTACT_PERSON,
- B.SERVICE_UNIT_CONTACT_PHONE, B.INTM, B.UPTM, B.YEAR
- FROM ATT_PROJECT_INSURANCE A
- JOIN ATT_PROJECT_INSURANCE_RECORD B ON A.ID = B.PROJECT_ID
- WHERE B.YEAR = #{year}
- AND A.BUSINESS_TYPE = '1'
- <if test="id != null and id != ''">and A.ID = #{id}</if>
- <if test="adCode != null and adCode != ''">and A.AD_CODE like '${adCode}%'</if>
- <if test="adName != null and adName != ''">and A.AD_NAME like '%${adName}%'</if>
- <if test="name != null and name != ''">and A.NAME like '%${name}%'</if>
- <if test="type != null and type != ''">and A.TYPE = #{type}</if>
- <if test="insuranceCompany != null and insuranceCompany != ''">and B.INSURANCE_COMPANY like '%${insuranceCompany}%'</if>
- <if test="preventionServiceUnit != null and preventionServiceUnit != ''">and B.PREVENTION_SERVICE_UNIT like '%${preventionServiceUnit}%'</if>
- <if test="investment != null and investment != ''">and A.INVESTMENT = #{investment}</if>
- <if test="plannedDuration != null and plannedDuration != ''">and A.PLANNED_DURATION = #{plannedDuration}</if>
- <if test="startDate != null">and A.START_DATE = #{startDate}</if>
- <if test="state != null and state != ''">and B.STATE = #{state}</if>
- <if test="managementUnit != null and managementUnit != ''">and A.MANAGEMENT_UNIT = #{managementUnit}</if>
- <if test="contactPerson != null and contactPerson != ''">and A.CONTACT_PERSON = #{contactPerson}</if>
- and A.DATA_STAT='0'
- and B.DATA_STAT='0'
- </select>
- <select id="cityRecordView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH city_total_proj AS (
- -- 各地市总有效工程数量
- SELECT
- CASE SUBSTR(t."AD_CODE",1,4)
- WHEN '3501' THEN '福州市'
- WHEN '3502' THEN '厦门市'
- WHEN '3503' THEN '莆田市'
- WHEN '3504' THEN '三明市'
- WHEN '3505' THEN '泉州市'
- WHEN '3506' THEN '漳州市'
- WHEN '3507' THEN '南平市'
- WHEN '3508' THEN '龙岩市'
- WHEN '3509' THEN '宁德市'
- END AS "CITY_NAME",
- COUNT(DISTINCT t."ID") AS "TOTAL_PROJECT_CNT"
- FROM "ATT_PROJECT_INSURANCE" t
- WHERE t."DATA_STAT" = '0'
- AND SUBSTR(t."AD_CODE",1,4) IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509')
- GROUP BY SUBSTR(t."AD_CODE",1,4)
- ),
- city_insured_proj AS (
- -- 各地市2026年已投保有效工程数量,新增过滤保险机构不为空
- SELECT
- CASE SUBSTR(p."AD_CODE",1,4)
- WHEN '3501' THEN '福州市'
- WHEN '3502' THEN '厦门市'
- WHEN '3503' THEN '莆田市'
- WHEN '3504' THEN '三明市'
- WHEN '3505' THEN '泉州市'
- WHEN '3506' THEN '漳州市'
- WHEN '3507' THEN '南平市'
- WHEN '3508' THEN '龙岩市'
- WHEN '3509' THEN '宁德市'
- END AS "CITY_NAME",
- COUNT(DISTINCT r."PROJECT_ID") AS "INSURED_CNT"
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- INNER JOIN "ATT_PROJECT_INSURANCE" p ON r."PROJECT_ID" = p."ID"
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r."DATA_STAT" = '0'
- AND p."DATA_STAT" = '0'
- AND SUBSTR(p."AD_CODE",1,4) IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509')
- -- 新增条件:仅保险机构不为空的投保记录参与统计
- AND r."INSURANCE_COMPANY" IS NOT NULL
- GROUP BY SUBSTR(p."AD_CODE",1,4)
- )
- SELECT
- t."CITY_NAME" AS city,
- t."TOTAL_PROJECT_CNT" AS projectTotal,
- NVL(i."INSURED_CNT", 0) AS insuredTotal,
- LTRIM(TO_CHAR(ROUND(NVL(i."INSURED_CNT",0) / NULLIF(t."TOTAL_PROJECT_CNT",0) * 100, 1), '999.0')) || '%' AS insuranceRatio
- FROM city_total_proj t
- LEFT JOIN city_insured_proj i ON t."CITY_NAME" = i."CITY_NAME"
- ORDER BY
- CASE t."CITY_NAME"
- WHEN '福州市' THEN 1
- WHEN '厦门市' THEN 2
- WHEN '泉州市' THEN 3
- WHEN '漳州市' THEN 4
- WHEN '南平市' THEN 5
- WHEN '宁德市' THEN 6
- WHEN '龙岩市' THEN 7
- WHEN '三明市' THEN 8
- WHEN '莆田市' THEN 9
- END
- </select>
- <select id="projectView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH all_type_total AS (
- -- 全局分母:所有TYPE不为空的工程总数量
- SELECT COUNT(DISTINCT t."ID") AS global_total
- FROM "ATT_PROJECT_INSURANCE" t
- WHERE t."DATA_STAT" = '0'
- AND t."TYPE" IS NOT NULL
- ),
- type_total AS (
- -- 各类型自身总工程(TYPE非空)
- SELECT
- t."TYPE" AS project_type,
- COUNT(DISTINCT t."ID") AS type_self_total
- FROM "ATT_PROJECT_INSURANCE" t
- WHERE t."DATA_STAT" = '0'
- AND t."TYPE" IS NOT NULL
- GROUP BY t."TYPE"
- ),
- type_insured AS (
- -- 各类型投保数量,仅TYPE非空
- SELECT
- p."TYPE" AS project_type,
- COUNT(DISTINCT r."PROJECT_ID") AS insured_cnt
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- INNER JOIN "ATT_PROJECT_INSURANCE" p
- ON r."PROJECT_ID" = p."ID"
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r."DATA_STAT" = '0'
- AND p."DATA_STAT" = '0'
- AND p."TYPE" IS NOT NULL
- GROUP BY p."TYPE"
- )
- SELECT
- t.project_type AS projectType,
- t.type_self_total AS projectTotal,
- NVL(i.insured_cnt, 0) AS insuredTotal,
- -- 投保率:当前类型投保数 / 全局所有TYPE非空工程总数
- LTRIM(
- TO_CHAR(
- ROUND(NVL(i.insured_cnt,0) / NULLIF(g.global_total, 0) * 100, 1),
- '999.0'
- )
- ) || '%' AS insuranceRatio
- FROM type_total t
- CROSS JOIN all_type_total g
- LEFT JOIN type_insured i
- ON t.project_type = i.project_type
- ORDER BY t.type_self_total DESC
- </select>
- <select id="insuranceCompanyView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH all_insured AS (
- -- 所有2026有效投保工程总数量(分母,仅保险机构不为空)
- SELECT COUNT(DISTINCT r.PROJECT_ID) AS total_all_insured
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- JOIN "ATT_PROJECT_INSURANCE" p ON r.PROJECT_ID = p.ID
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r.DATA_STAT = '0'
- AND p.DATA_STAT = '0'
- -- 过滤保险机构为空的记录
- AND r.INSURANCE_COMPANY IS NOT NULL
- ),
- company_data AS (
- -- 每家保险机构承保的工程数量,直接剔除空机构数据,不再生成“未填写保险机构”分组
- SELECT
- r.INSURANCE_COMPANY AS insurance_company,
- COUNT(DISTINCT r.PROJECT_ID) AS company_insured_cnt
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- JOIN "ATT_PROJECT_INSURANCE" p ON r.PROJECT_ID = p.ID
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r.DATA_STAT = '0'
- AND p.DATA_STAT = '0'
- -- 统一过滤:只保留保险机构不为空的数据
- AND r.INSURANCE_COMPANY IS NOT NULL
- GROUP BY r.INSURANCE_COMPANY
- )
- SELECT
- c.insurance_company AS insuranceCompany,
- c.company_insured_cnt AS insuredTotal,
- a.total_all_insured AS projectTotal,
- -- 计算占比,去除前导空格,除零保护
- LTRIM(TO_CHAR(ROUND(c.company_insured_cnt / NULLIF(a.total_all_insured, 0) * 100, 1), '999.0')) || '%' AS insuranceRatio
- FROM company_data c, all_insured a
- ORDER BY c.company_insured_cnt DESC
- </select>
- <select id="preventionServiceUnitView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH all_insured AS (
- SELECT COUNT(DISTINCT "PROJECT_ID") AS total_all_proj
- FROM "ATT_PROJECT_INSURANCE_RECORD"
- WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND "DATA_STAT" = '0'
- ),
- unit_group AS (
- SELECT
- service_unit,
- COUNT(DISTINCT "PROJECT_ID") AS unit_proj_cnt
- FROM (
- SELECT
- CASE
- WHEN "PREVENTION_SERVICE_UNIT" IS NULL THEN '无预防服务单位'
- ELSE "PREVENTION_SERVICE_UNIT"
- END AS service_unit,
- "PROJECT_ID"
- FROM "ATT_PROJECT_INSURANCE_RECORD"
- WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND "DATA_STAT" = '0'
- ) t
- GROUP BY service_unit
- )
- SELECT
- g.service_unit AS preventionServiceUnit,
- g.unit_proj_cnt AS projectTotal,
- a.total_all_proj AS insuredTotal,
- DECODE(a.total_all_proj,
- 0, '0.0%',
- TRUNC(g.unit_proj_cnt * 1000 / a.total_all_proj) / 10 || '%'
- ) AS insuranceRatio
- FROM unit_group g
- CROSS JOIN all_insured a
- ORDER BY g.unit_proj_cnt DESC
- </select>
- <select id="handView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH raw_data AS (
- SELECT
- r."INSURANCE_COMPANY",
- r."PROJECT_ID",
- r."PREMIUM_AMOUNT",
- SUBSTR(p."AD_CODE",1,4) AS city_code
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- INNER JOIN "ATT_PROJECT_INSURANCE" p ON r."PROJECT_ID" = p."ID"
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r."DATA_STAT" = '0'
- AND p."DATA_STAT" = '0'
- -- 新增:仅保险机构不为空的数据参与统计
- AND r."INSURANCE_COMPANY" IS NOT NULL
- ),
- agg_all AS (
- SELECT
- COUNT(DISTINCT "INSURANCE_COMPANY") AS company_total,
- COUNT(DISTINCT "PROJECT_ID") AS project_total,
- SUM("PREMIUM_AMOUNT") AS total_premium,
- COUNT(DISTINCT CASE WHEN city_code IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509') THEN city_code END) AS covered_city_num
- FROM raw_data
- )
- SELECT
- company_total AS companyCount,
- project_total AS insuredTotal,
- total_premium AS premiumSum,
- covered_city_num || '/9' AS coveredCityNum
- FROM agg_all
- </select>
- <select id="numberRanking" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- r."INSURANCE_COMPANY" AS insuranceCompany,
- COUNT(DISTINCT r."PROJECT_ID") AS insuredTotal
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r."DATA_STAT" = '0'
- -- 新增过滤:只保留保险机构不为空的数据
- AND r."INSURANCE_COMPANY" IS NOT NULL
- GROUP BY r."INSURANCE_COMPANY"
- ORDER BY COUNT(DISTINCT r."PROJECT_ID") DESC
- </select>
- <select id="insuranceCompanyDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH year_total AS (
- -- 当年全省总承保工程(分母,仅保险机构不为空的数据)
- SELECT COUNT(DISTINCT "PROJECT_ID") AS total_proj
- FROM "ATT_PROJECT_INSURANCE_RECORD"
- WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND "DATA_STAT" = '0'
- -- 新增:过滤保险机构为空记录
- AND "INSURANCE_COMPANY" IS NOT NULL
- ),
- company_stat AS (
- SELECT
- "INSURANCE_COMPANY",
- COUNT(DISTINCT "PROJECT_ID") AS company_proj_cnt,
- SUM("PREMIUM_AMOUNT") AS company_premium
- FROM "ATT_PROJECT_INSURANCE_RECORD"
- WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND "DATA_STAT" = '0'
- -- 新增:只统计保险机构有值的记录
- AND "INSURANCE_COMPANY" IS NOT NULL
- GROUP BY "INSURANCE_COMPANY"
- )
- SELECT
- c."INSURANCE_COMPANY" AS insuranceCompany,
- c.company_proj_cnt AS insuredTotal,
- -- 占比 保留1位小数
- LTRIM(TO_CHAR(ROUND(c.company_proj_cnt / NULLIF(t.total_proj,0) * 100,1), '999.0')) || '%' AS insuranceRatio,
- c.company_premium AS premiumSum
- FROM company_stat c, year_total t
- ORDER BY c.company_proj_cnt DESC
- </select>
- <select id="handServiceView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH rec_all AS (
- -- 当年全部投保记录(含有无服务单位)
- SELECT
- r."PROJECT_ID",
- r."PREVENTION_SERVICE_UNIT",
- SUBSTR(p."AD_CODE",1,4) AS city_code
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- LEFT JOIN "ATT_PROJECT_INSURANCE" p
- ON r."PROJECT_ID" = p."ID"
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r."DATA_STAT" = '0'
- AND p."DATA_STAT" = '0'
- ),
- agg_base AS (
- SELECT
- -- 全部当年总工程(分母,空/非空服务单位都算)
- COUNT(DISTINCT "PROJECT_ID") AS total_all_proj,
- -- 有服务单位的工程总数
- COUNT(DISTINCT CASE WHEN "PREVENTION_SERVICE_UNIT" IS NOT NULL THEN "PROJECT_ID" END) AS service_proj_cnt,
- -- 去重有效服务机构数量
- COUNT(DISTINCT CASE WHEN "PREVENTION_SERVICE_UNIT" IS NOT NULL THEN "PREVENTION_SERVICE_UNIT" END) AS service_org_total,
- -- 已覆盖地市编码数量
- COUNT(DISTINCT CASE
- WHEN city_code IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509')
- THEN city_code
- END) AS covered_city
- FROM rec_all
- )
- SELECT
- service_org_total AS serviceCount,
- service_proj_cnt AS insuredTotal,
- -- 服务覆盖率 保留1位小数
- LTRIM(TO_CHAR(ROUND(service_proj_cnt / NULLIF(total_all_proj, 0) * 100, 1), '999.0')) || '%' AS insuranceRatio,
- covered_city || '/9' AS coveredCityNum
- FROM agg_base
- </select>
- <select id="numberServiceRanking" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- r."PREVENTION_SERVICE_UNIT" AS preventionServiceUnit,
- COUNT(DISTINCT r."PROJECT_ID") AS insuredTotal
- FROM "ATT_PROJECT_INSURANCE_RECORD" r
- WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND r."DATA_STAT" = '0'
- AND r."PREVENTION_SERVICE_UNIT" IS NOT NULL
- GROUP BY r."PREVENTION_SERVICE_UNIT"
- ORDER BY COUNT(DISTINCT r."PROJECT_ID") DESC
- </select>
- <select id="serviceUnitDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- WITH year_total AS (
- -- 当年全部工程总数(占比分母,有无服务单位都计入)
- SELECT COUNT(DISTINCT "PROJECT_ID") AS total_proj
- FROM "ATT_PROJECT_INSURANCE_RECORD"
- WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND "DATA_STAT" = '0'
- ),
- org_stat AS (
- SELECT
- "PREVENTION_SERVICE_UNIT" AS service_unit,
- COUNT(DISTINCT "PROJECT_ID") AS unit_proj_cnt
- FROM "ATT_PROJECT_INSURANCE_RECORD"
- WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
- AND "DATA_STAT" = '0'
- AND "PREVENTION_SERVICE_UNIT" IS NOT NULL
- GROUP BY "PREVENTION_SERVICE_UNIT"
- )
- SELECT
- o.service_unit AS preventionServiceUnit,
- o.unit_proj_cnt AS insuredTotal,
- LTRIM(TO_CHAR(ROUND(o.unit_proj_cnt / NULLIF(t.total_proj, 0) * 100, 1), '999.0')) || '%' AS insuranceRatio
- FROM org_stat o, year_total t
- ORDER BY o.unit_proj_cnt DESC
- </select>
- <select id="cityCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- r.INSURANCE_COMPANY AS insuranceCompany,
- COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
- ROUND(SUM(r.PREMIUM_AMOUNT)/1,2) AS premiumSum,
- CONCAT(COUNT(DISTINCT CASE WHEN SUBSTR(p.AD_CODE,1,4) IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509') THEN SUBSTR(p.AD_CODE,1,4) END), '/9') AS coveredCityNum
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
- JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
- WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
- AND r.DATA_STAT='0'
- AND p.DATA_STAT='0'
- <if test="insuranceCompany != null and insuranceCompany != ''">
- and r.INSURANCE_COMPANY = #{insuranceCompany}
- </if>
- GROUP BY r.INSURANCE_COMPANY
- </select>
- <select id="cityCoveredDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- SUBSTR(p.AD_CODE,1,4) AS adCode,
- CASE SUBSTR(p.AD_CODE,1,4)
- WHEN '3501' THEN '福州市'
- WHEN '3502' THEN '厦门市'
- WHEN '3503' THEN '莆田市'
- WHEN '3504' THEN '三明市'
- WHEN '3505' THEN '泉州市'
- WHEN '3506' THEN '漳州市'
- WHEN '3507' THEN '南平市'
- WHEN '3508' THEN '龙岩市'
- WHEN '3509' THEN '宁德市'
- END AS city,
- COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
- -- 占比:当前地市有效工程 / 筛选范围内全部有效工程
- LTRIM(TO_CHAR(
- ROUND(
- COUNT(DISTINCT r.PROJECT_ID)
- / NULLIF(
- (SELECT COUNT(DISTINCT rr.PROJECT_ID)
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD rr
- INNER JOIN GW_HUIYI.ATT_PROJECT_INSURANCE pp ON rr.PROJECT_ID = pp.ID
- WHERE rr.YEAR = TO_CHAR(SYSDATE, 'yyyy')
- AND rr.DATA_STAT = '0'
- AND pp.DATA_STAT = '0'
- -- 新增:保险机构不为空才计入分母总数
- AND rr.INSURANCE_COMPANY IS NOT NULL
- <if test="insuranceCompany != null and insuranceCompany != ''">
- AND rr.INSURANCE_COMPANY = #{insuranceCompany}
- </if>
- ),
- 0) * 100,
- 1), '999.0')) || '%' AS insuranceRatio,
- ROUND(SUM(r.PREMIUM_AMOUNT),1) AS premiumSum
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
- JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
- WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
- AND r.DATA_STAT='0'
- AND p.DATA_STAT='0'
- -- 新增:保险机构为空的整条记录直接过滤,不参与计数、保费求和
- AND r.INSURANCE_COMPANY IS NOT NULL
- <if test="insuranceCompany != null and insuranceCompany != ''">
- AND r.INSURANCE_COMPANY = #{insuranceCompany}
- </if>
- GROUP BY SUBSTR(p.AD_CODE,1,4)
- ORDER BY COUNT(DISTINCT r.PROJECT_ID) DESC
- </select>
- <select id="countyCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- CASE SUBSTR(p.AD_CODE,1,4)
- WHEN '3501' THEN '福州市'
- WHEN '3502' THEN '厦门市'
- WHEN '3503' THEN '莆田市'
- WHEN '3504' THEN '三明市'
- WHEN '3505' THEN '泉州市'
- WHEN '3506' THEN '漳州市'
- WHEN '3507' THEN '南平市'
- WHEN '3508' THEN '龙岩市'
- WHEN '3509' THEN '宁德市'
- END AS city,
- r.INSURANCE_COMPANY AS insuranceCompany,
- COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
- TO_CHAR(ROUND(SUM(r.PREMIUM_AMOUNT),2)) AS premiumSum
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
- JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID = p.ID
- WHERE r.YEAR = TO_CHAR(SYSDATE,'yyyy')
- AND r.DATA_STAT = '0'
- AND p.DATA_STAT = '0'
- -- 新增条件:保险机构不为空才纳入统计
- AND r.INSURANCE_COMPANY IS NOT NULL
- <if test="insuranceCompany != null and insuranceCompany != ''">
- AND r.INSURANCE_COMPANY = #{insuranceCompany}
- </if>
- <if test="adCode != null and adCode != ''">
- AND SUBSTR(p.AD_CODE,1,4) LIKE CONCAT(SUBSTR(#{adCode},1,4),'%')
- </if>
- GROUP BY SUBSTR(p.AD_CODE,1,4), r.INSURANCE_COMPANY
- </select>
- <select id="serviceCityCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- r.PREVENTION_SERVICE_UNIT AS preventionServiceUnit,
- COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
- ROUND(SUM(r.PREVENTION_SERVICE_FEE)/1,2) AS premiumSum,
- CONCAT(COUNT(DISTINCT CASE WHEN SUBSTR(p.AD_CODE,1,4) IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509') THEN SUBSTR(p.AD_CODE,1,4) END), '/9') AS coveredCityNum
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
- JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
- WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
- AND r.DATA_STAT='0'
- AND p.DATA_STAT='0'
- -- 新增:只保留服务单位不为空的数据
- AND r.PREVENTION_SERVICE_UNIT IS NOT NULL
- <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
- and r.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
- </if>
- GROUP BY r.PREVENTION_SERVICE_UNIT
- </select>
- <select id="serviceCityCoveredDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- SUBSTR(p.AD_CODE,1,4) AS adCode,
- CASE SUBSTR(p.AD_CODE,1,4)
- WHEN '3501' THEN '福州市'
- WHEN '3502' THEN '厦门市'
- WHEN '3503' THEN '莆田市'
- WHEN '3504' THEN '三明市'
- WHEN '3505' THEN '泉州市'
- WHEN '3506' THEN '漳州市'
- WHEN '3507' THEN '南平市'
- WHEN '3508' THEN '龙岩市'
- WHEN '3509' THEN '宁德市'
- END AS city,
- COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
- -- 占比:当前地市有效工程 / 该机构当年全部有效工程(PREVENTION_SERVICE_UNIT不为空)
- LTRIM(TO_CHAR(
- ROUND(
- COUNT(DISTINCT r.PROJECT_ID)
- / NULLIF(
- (SELECT COUNT(DISTINCT rr.PROJECT_ID)
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD rr
- INNER JOIN GW_HUIYI.ATT_PROJECT_INSURANCE pp ON rr.PROJECT_ID = pp.ID
- WHERE rr.YEAR = TO_CHAR(SYSDATE, 'yyyy')
- AND rr.DATA_STAT = '0'
- AND pp.DATA_STAT = '0'
- -- 关键:服务单位不为空才计入分母总数
- AND rr.PREVENTION_SERVICE_UNIT IS NOT NULL
- <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
- AND rr.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
- </if>
- ),
- 0) * 100,
- 1), '999.0')) || '%' AS insuranceRatio,
- ROUND(SUM(r.PREVENTION_SERVICE_FEE),1) AS premiumSum
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
- JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
- WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
- AND r.DATA_STAT='0'
- AND p.DATA_STAT='0'
- -- 关键:当前地市只统计服务单位不为空的数据
- AND r.PREVENTION_SERVICE_UNIT IS NOT NULL
- <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
- AND r.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
- </if>
- GROUP BY SUBSTR(p.AD_CODE,1,4)
- ORDER BY COUNT(DISTINCT r.PROJECT_ID) DESC
- </select>
- <select id="serviceCountyCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
- SELECT
- CASE SUBSTR(p.AD_CODE,1,4)
- WHEN '3501' THEN '福州市'
- WHEN '3502' THEN '厦门市'
- WHEN '3503' THEN '莆田市'
- WHEN '3504' THEN '三明市'
- WHEN '3505' THEN '泉州市'
- WHEN '3506' THEN '漳州市'
- WHEN '3507' THEN '南平市'
- WHEN '3508' THEN '龙岩市'
- WHEN '3509' THEN '宁德市'
- END AS city,
- r.PREVENTION_SERVICE_UNIT AS preventionServiceUnit,
- COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
- TO_CHAR(ROUND(SUM(r.PREVENTION_SERVICE_FEE),2)) AS premiumSum
- FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
- JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID = p.ID
- WHERE r.YEAR = TO_CHAR(SYSDATE,'yyyy')
- AND r.DATA_STAT = '0'
- AND p.DATA_STAT = '0'
- -- 新增:仅保留服务单位不为空的数据
- AND r.PREVENTION_SERVICE_UNIT IS NOT NULL
- <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
- AND r.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
- </if>
- <if test="adCode != null and adCode != ''">
- AND SUBSTR(p.AD_CODE,1,4) LIKE CONCAT(SUBSTR(#{adCode},1,4),'%')
- </if>
- GROUP BY SUBSTR(p.AD_CODE,1,4), r.PREVENTION_SERVICE_UNIT
- </select>
- </mapper>
|