AttProjectInsuranceDao.xml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.com.goldenwater.dcproj.dao.AttProjectInsuranceDao">
  4. <resultMap type="cn.com.goldenwater.dcproj.model.AttProjectInsurance" id="attProjectInsuranceResultMap">
  5. <result property="businessType" column="BUSINESS_TYPE"/>
  6. <result property="adName" column="AD_NAME"/>
  7. <result property="adCode" column="AD_CODE"/>
  8. <result property="id" column="ID"/>
  9. <result property="name" column="NAME"/>
  10. <result property="type" column="TYPE"/>
  11. <result property="loc" column="LOC"/>
  12. <result property="investment" column="INVESTMENT"/>
  13. <result property="plannedDuration" column="PLANNED_DURATION"/>
  14. <result property="startDate" column="START_DATE"/>
  15. <result property="status" column="STATUS"/>
  16. <result property="managementUnit" column="MANAGEMENT_UNIT"/>
  17. <result property="constructors" column="CONSTRUCTORS"/>
  18. <result property="contactPerson" column="CONTACT_PERSON"/>
  19. <result property="centerX" column="CENTER_X"/>
  20. <result property="centerY" column="CENTER_Y"/>
  21. <result property="gdX" column="GD_X"/>
  22. <result property="gdY" column="GD_Y"/>
  23. <result property="intm" column="INTM"/>
  24. <result property="uptm" column="UPTM"/>
  25. <result property="dataStat" column="DATA_STAT"/>
  26. </resultMap>
  27. <sql id="table_columns">
  28. BUSINESS_TYPE
  29. ,
  30. AD_NAME,
  31. AD_CODE,
  32. ID,
  33. NAME,
  34. TYPE,
  35. LOC,
  36. INVESTMENT,
  37. PLANNED_DURATION,
  38. START_DATE,
  39. STATUS,
  40. MANAGEMENT_UNIT,
  41. CONSTRUCTORS,
  42. CONTACT_PERSON,
  43. CENTER_X,
  44. CENTER_Y,
  45. GD_X,
  46. GD_Y,
  47. INTM,
  48. UPTM,
  49. DATA_STAT
  50. </sql>
  51. <sql id="entity_properties">
  52. #{businessType},
  53. #{adName},
  54. #{adCode},
  55. #{id},
  56. #{name},
  57. #{type},
  58. #{loc},
  59. #{investment},
  60. #{plannedDuration},
  61. #{startDate},
  62. #{status},
  63. #{managementUnit},
  64. #{constructors},
  65. #{contactPerson},
  66. #{centerX},
  67. #{centerY},
  68. #{gdX},
  69. #{gdY},
  70. #{intm},
  71. #{uptm},
  72. #{dataStat}
  73. </sql>
  74. <sql id="page_where">
  75. <trim prefix="where" prefixOverrides="and | or ">
  76. <if test="adName != null and adName != ''">and AD_NAME = #{adName}</if>
  77. <if test="businessType != null and businessType != ''">and BUSINESS_TYPE = #{businessType}</if>
  78. <if test="adCode != null and adCode != ''">and AD_CODE = #{adCode}</if>
  79. <if test="id != null and id != ''">and ID = #{id}</if>
  80. <if test="name != null and name != ''">and NAME like '%${name}%'</if>
  81. <if test="type != null and type != ''">and TYPE = #{type}</if>
  82. <if test="loc != null and loc != ''">and LOC = #{loc}</if>
  83. <if test="investment != null and investment != ''">and INVESTMENT = #{investment}</if>
  84. <if test="plannedDuration != null and plannedDuration != ''">and PLANNED_DURATION = #{plannedDuration}</if>
  85. <if test="startDate != null">and START_DATE = #{startDate}</if>
  86. <if test="status != null and status != ''">and STATUS = #{status}</if>
  87. <if test="managementUnit != null and managementUnit != ''">and MANAGEMENT_UNIT = #{managementUnit}</if>
  88. <if test="constructors != null and constructors != ''">and CONSTRUCTORS = #{constructors}</if>
  89. <if test="contactPerson != null and contactPerson != ''">and CONTACT_PERSON = #{contactPerson}</if>
  90. <if test="centerX != null and centerX != ''">and CENTER_X = #{centerX}</if>
  91. <if test="centerY != null and centerY != ''">and CENTER_Y = #{centerY}</if>
  92. <if test="gdX != null and gdX != ''">and GD_X = #{gdX}</if>
  93. <if test="gdY != null and gdY != ''">and GD_Y = #{gdY}</if>
  94. <if test="intm != null">and INTM = #{intm}</if>
  95. <if test="uptm != null">and UPTM = #{uptm}</if>
  96. and DATA_STAT='0'
  97. </trim>
  98. </sql>
  99. <select id="get" resultMap="attProjectInsuranceResultMap" parameterType="String">
  100. select
  101. <include refid="table_columns"/>
  102. from ATT_PROJECT_INSURANCE where ID = #{id}
  103. </select>
  104. <select id="getBy" resultMap="attProjectInsuranceResultMap">
  105. select
  106. <include refid="table_columns"/>
  107. from ATT_PROJECT_INSURANCE
  108. <include refid="page_where"/>
  109. </select>
  110. <select id="findAll" resultMap="attProjectInsuranceResultMap">
  111. select
  112. <include refid="table_columns"/>
  113. from ATT_PROJECT_INSURANCE
  114. </select>
  115. <select id="findList" resultMap="attProjectInsuranceResultMap">
  116. select
  117. <include refid="table_columns"/>
  118. from ATT_PROJECT_INSURANCE
  119. <include refid="page_where"/>
  120. </select>
  121. <select id="selectCount" resultType="int">
  122. select count(ID) from ATT_PROJECT_INSURANCE
  123. <include refid="page_where"/>
  124. </select>
  125. <insert id="insert" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
  126. insert into ATT_PROJECT_INSURANCE(
  127. <include refid="table_columns"/>
  128. )
  129. values (
  130. <include refid="entity_properties"/>
  131. )
  132. </insert>
  133. <delete id="delete" parameterType="java.lang.String">
  134. update ATT_PROJECT_INSURANCE
  135. set DATA_STAT='9'
  136. where ID = #{id}
  137. </delete>
  138. <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
  139. update ATT_PROJECT_INSURANCE set DATA_STAT='9'
  140. <include refid="page_where"/>
  141. </delete>
  142. <update id="deleteInFlag" parameterType="java.lang.String">
  143. update ATT_PROJECT_INSURANCE
  144. set DATA_STAT = '9'
  145. where ID = #{id}
  146. </update>
  147. <update id="update" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
  148. update ATT_PROJECT_INSURANCE
  149. <trim prefix="set" suffixOverrides=",">
  150. <if test="adName != null and adName != ''">AD_NAME = #{adName},</if>
  151. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  152. <if test="id != null and id != ''">ID = #{id},</if>
  153. <if test="name != null and name != ''">NAME = #{name},</if>
  154. <if test="type != null and type != ''">TYPE = #{type},</if>
  155. <if test="loc != null and loc != ''">LOC = #{loc},</if>
  156. <if test="investment != null and investment != ''">INVESTMENT = #{investment},</if>
  157. <if test="plannedDuration != null and plannedDuration != ''">PLANNED_DURATION = #{plannedDuration},</if>
  158. <if test="startDate != null">START_DATE = #{startDate},</if>
  159. <if test="status != null and status != ''">STATUS = #{status},</if>
  160. <if test="managementUnit != null and managementUnit != ''">MANAGEMENT_UNIT = #{managementUnit},</if>
  161. <if test="constructors != null and constructors != ''">CONSTRUCTORS = #{constructors},</if>
  162. <if test="contactPerson != null and contactPerson != ''">CONTACT_PERSON = #{contactPerson},</if>
  163. <if test="centerX != null and centerX != ''">CENTER_X = #{centerX},</if>
  164. <if test="centerY != null and centerY != ''">CENTER_Y = #{centerY},</if>
  165. <if test="gdX != null and gdX != ''">GD_X = #{gdX},</if>
  166. <if test="gdY != null and gdY != ''">GD_Y = #{gdY},</if>
  167. <if test="intm != null">INTM = #{intm},</if>
  168. <if test="uptm != null">UPTM = #{uptm},</if>
  169. <if test="dataStat != null and dataStat != ''">DATA_STAT = #{dataStat},</if>
  170. </trim>
  171. <where>ID = #{id}</where>
  172. </update>
  173. <update id="updateBy" parameterType="cn.com.goldenwater.dcproj.model.AttProjectInsurance">
  174. update ATT_PROJECT_INSURANCE
  175. <trim prefix="set" suffixOverrides=",">
  176. <if test="adName != null and adName != ''">AD_NAME = #{adName},</if>
  177. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  178. <if test="id != null and id != ''">ID = #{id},</if>
  179. <if test="name != null and name != ''">NAME = #{name},</if>
  180. <if test="type != null and type != ''">TYPE = #{type},</if>
  181. <if test="loc != null and loc != ''">LOC = #{loc},</if>
  182. <if test="investment != null and investment != ''">INVESTMENT = #{investment},</if>
  183. <if test="plannedDuration != null and plannedDuration != ''">PLANNED_DURATION = #{plannedDuration},</if>
  184. <if test="startDate != null">START_DATE = #{startDate},</if>
  185. <if test="status != null and status != ''">STATUS = #{status},</if>
  186. <if test="managementUnit != null and managementUnit != ''">MANAGEMENT_UNIT = #{managementUnit},</if>
  187. <if test="constructors != null and constructors != ''">CONSTRUCTORS = #{constructors},</if>
  188. <if test="contactPerson != null and contactPerson != ''">CONTACT_PERSON = #{contactPerson},</if>
  189. <if test="centerX != null and centerX != ''">CENTER_X = #{centerX},</if>
  190. <if test="centerY != null and centerY != ''">CENTER_Y = #{centerY},</if>
  191. <if test="gdX != null and gdX != ''">GD_X = #{gdX},</if>
  192. <if test="gdY != null and gdY != ''">GD_Y = #{gdY},</if>
  193. <if test="intm != null">INTM = #{intm},</if>
  194. <if test="uptm != null">UPTM = #{uptm},</if>
  195. <if test="dataStat != null and dataStat != ''">DATA_STAT = #{dataStat},</if>
  196. </trim>
  197. <include refid="page_where"/>
  198. </update>
  199. <!-- 其他自定义SQL -->
  200. <select id="getByRgstrId" resultMap="attProjectInsuranceResultMap">
  201. SELECT A.*
  202. FROM ATT_PROJECT_INSURANCE A
  203. JOIN BIS_INSP_ALL_OBJ B ON A.ID = B.CODE
  204. JOIN BIS_INSP_ANZE_RGSTR ON B.OBJ_ID = C.OBJ_ID
  205. where C.ID = #{id}
  206. </select>
  207. <select id="listOfUnderwriting" resultType="cn.com.goldenwater.dcproj.dto.AttAnzeUnderwritingDto">
  208. SELECT
  209. A.ID, A.AD_CODE, A.AD_NAME, A.NAME, A.TYPE, A.LOC, A.INVESTMENT,
  210. A.PLANNED_DURATION, A.START_DATE, A.STATUS, A.MANAGEMENT_UNIT,
  211. A.CONTACT_PERSON, A.CENTER_X, A.CENTER_Y, A.GD_X, A.GD_Y,
  212. B.ID AS recordId, B.POLICYHOLDER, B.POLICYHOLDER_PHONE, B.INSURANCE_COMPANY,
  213. B.INSURANCE_CONTACT_PERSON, B.INSURANCE_CONTACT_PHONE, B.PREMIUM_AMOUNT, B.PREVENTION_SERVICE_FEE,
  214. B.INSURANCE_DATE, B.PREVENTION_SERVICE_UNIT, B.SERVICE_UNIT_CONTACT_PERSON,
  215. B.SERVICE_UNIT_CONTACT_PHONE, B.INTM, B.UPTM, B.YEAR
  216. FROM ATT_PROJECT_INSURANCE A
  217. JOIN ATT_PROJECT_INSURANCE_RECORD B ON A.ID = B.PROJECT_ID
  218. WHERE B.YEAR = #{year}
  219. AND A.BUSINESS_TYPE = '1'
  220. <if test="id != null and id != ''">and A.ID = #{id}</if>
  221. <if test="adCode != null and adCode != ''">and A.AD_CODE like '${adCode}%'</if>
  222. <if test="adName != null and adName != ''">and A.AD_NAME like '%${adName}%'</if>
  223. <if test="name != null and name != ''">and A.NAME like '%${name}%'</if>
  224. <if test="type != null and type != ''">and A.TYPE = #{type}</if>
  225. <if test="insuranceCompany != null and insuranceCompany != ''">and B.INSURANCE_COMPANY like '%${insuranceCompany}%'</if>
  226. <if test="preventionServiceUnit != null and preventionServiceUnit != ''">and B.PREVENTION_SERVICE_UNIT like '%${preventionServiceUnit}%'</if>
  227. <if test="investment != null and investment != ''">and A.INVESTMENT = #{investment}</if>
  228. <if test="plannedDuration != null and plannedDuration != ''">and A.PLANNED_DURATION = #{plannedDuration}</if>
  229. <if test="startDate != null">and A.START_DATE = #{startDate}</if>
  230. <if test="state != null and state != ''">and B.STATE = #{state}</if>
  231. <if test="managementUnit != null and managementUnit != ''">and A.MANAGEMENT_UNIT = #{managementUnit}</if>
  232. <if test="contactPerson != null and contactPerson != ''">and A.CONTACT_PERSON = #{contactPerson}</if>
  233. and A.DATA_STAT='0'
  234. and B.DATA_STAT='0'
  235. </select>
  236. <select id="cityRecordView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  237. WITH city_total_proj AS (
  238. -- 各地市总有效工程数量
  239. SELECT
  240. CASE SUBSTR(t."AD_CODE",1,4)
  241. WHEN '3501' THEN '福州市'
  242. WHEN '3502' THEN '厦门市'
  243. WHEN '3503' THEN '莆田市'
  244. WHEN '3504' THEN '三明市'
  245. WHEN '3505' THEN '泉州市'
  246. WHEN '3506' THEN '漳州市'
  247. WHEN '3507' THEN '南平市'
  248. WHEN '3508' THEN '龙岩市'
  249. WHEN '3509' THEN '宁德市'
  250. END AS "CITY_NAME",
  251. COUNT(DISTINCT t."ID") AS "TOTAL_PROJECT_CNT"
  252. FROM "ATT_PROJECT_INSURANCE" t
  253. WHERE t."DATA_STAT" = '0'
  254. AND SUBSTR(t."AD_CODE",1,4) IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509')
  255. GROUP BY SUBSTR(t."AD_CODE",1,4)
  256. ),
  257. city_insured_proj AS (
  258. -- 各地市2026年已投保有效工程数量,新增过滤保险机构不为空
  259. SELECT
  260. CASE SUBSTR(p."AD_CODE",1,4)
  261. WHEN '3501' THEN '福州市'
  262. WHEN '3502' THEN '厦门市'
  263. WHEN '3503' THEN '莆田市'
  264. WHEN '3504' THEN '三明市'
  265. WHEN '3505' THEN '泉州市'
  266. WHEN '3506' THEN '漳州市'
  267. WHEN '3507' THEN '南平市'
  268. WHEN '3508' THEN '龙岩市'
  269. WHEN '3509' THEN '宁德市'
  270. END AS "CITY_NAME",
  271. COUNT(DISTINCT r."PROJECT_ID") AS "INSURED_CNT"
  272. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  273. INNER JOIN "ATT_PROJECT_INSURANCE" p ON r."PROJECT_ID" = p."ID"
  274. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  275. AND r."DATA_STAT" = '0'
  276. AND p."DATA_STAT" = '0'
  277. AND SUBSTR(p."AD_CODE",1,4) IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509')
  278. -- 新增条件:仅保险机构不为空的投保记录参与统计
  279. AND r."INSURANCE_COMPANY" IS NOT NULL
  280. GROUP BY SUBSTR(p."AD_CODE",1,4)
  281. )
  282. SELECT
  283. t."CITY_NAME" AS city,
  284. t."TOTAL_PROJECT_CNT" AS projectTotal,
  285. NVL(i."INSURED_CNT", 0) AS insuredTotal,
  286. LTRIM(TO_CHAR(ROUND(NVL(i."INSURED_CNT",0) / NULLIF(t."TOTAL_PROJECT_CNT",0) * 100, 1), '999.0')) || '%' AS insuranceRatio
  287. FROM city_total_proj t
  288. LEFT JOIN city_insured_proj i ON t."CITY_NAME" = i."CITY_NAME"
  289. ORDER BY
  290. CASE t."CITY_NAME"
  291. WHEN '福州市' THEN 1
  292. WHEN '厦门市' THEN 2
  293. WHEN '泉州市' THEN 3
  294. WHEN '漳州市' THEN 4
  295. WHEN '南平市' THEN 5
  296. WHEN '宁德市' THEN 6
  297. WHEN '龙岩市' THEN 7
  298. WHEN '三明市' THEN 8
  299. WHEN '莆田市' THEN 9
  300. END
  301. </select>
  302. <select id="projectView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  303. WITH all_type_total AS (
  304. -- 全局分母:所有TYPE不为空的工程总数量
  305. SELECT COUNT(DISTINCT t."ID") AS global_total
  306. FROM "ATT_PROJECT_INSURANCE" t
  307. WHERE t."DATA_STAT" = '0'
  308. AND t."TYPE" IS NOT NULL
  309. ),
  310. type_total AS (
  311. -- 各类型自身总工程(TYPE非空)
  312. SELECT
  313. t."TYPE" AS project_type,
  314. COUNT(DISTINCT t."ID") AS type_self_total
  315. FROM "ATT_PROJECT_INSURANCE" t
  316. WHERE t."DATA_STAT" = '0'
  317. AND t."TYPE" IS NOT NULL
  318. GROUP BY t."TYPE"
  319. ),
  320. type_insured AS (
  321. -- 各类型投保数量,仅TYPE非空
  322. SELECT
  323. p."TYPE" AS project_type,
  324. COUNT(DISTINCT r."PROJECT_ID") AS insured_cnt
  325. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  326. INNER JOIN "ATT_PROJECT_INSURANCE" p
  327. ON r."PROJECT_ID" = p."ID"
  328. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  329. AND r."DATA_STAT" = '0'
  330. AND p."DATA_STAT" = '0'
  331. AND p."TYPE" IS NOT NULL
  332. GROUP BY p."TYPE"
  333. )
  334. SELECT
  335. t.project_type AS projectType,
  336. t.type_self_total AS projectTotal,
  337. NVL(i.insured_cnt, 0) AS insuredTotal,
  338. -- 投保率:当前类型投保数 / 全局所有TYPE非空工程总数
  339. LTRIM(
  340. TO_CHAR(
  341. ROUND(NVL(i.insured_cnt,0) / NULLIF(g.global_total, 0) * 100, 1),
  342. '999.0'
  343. )
  344. ) || '%' AS insuranceRatio
  345. FROM type_total t
  346. CROSS JOIN all_type_total g
  347. LEFT JOIN type_insured i
  348. ON t.project_type = i.project_type
  349. ORDER BY t.type_self_total DESC
  350. </select>
  351. <select id="insuranceCompanyView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  352. WITH all_insured AS (
  353. -- 所有2026有效投保工程总数量(分母,仅保险机构不为空)
  354. SELECT COUNT(DISTINCT r.PROJECT_ID) AS total_all_insured
  355. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  356. JOIN "ATT_PROJECT_INSURANCE" p ON r.PROJECT_ID = p.ID
  357. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  358. AND r.DATA_STAT = '0'
  359. AND p.DATA_STAT = '0'
  360. -- 过滤保险机构为空的记录
  361. AND r.INSURANCE_COMPANY IS NOT NULL
  362. ),
  363. company_data AS (
  364. -- 每家保险机构承保的工程数量,直接剔除空机构数据,不再生成“未填写保险机构”分组
  365. SELECT
  366. r.INSURANCE_COMPANY AS insurance_company,
  367. COUNT(DISTINCT r.PROJECT_ID) AS company_insured_cnt
  368. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  369. JOIN "ATT_PROJECT_INSURANCE" p ON r.PROJECT_ID = p.ID
  370. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  371. AND r.DATA_STAT = '0'
  372. AND p.DATA_STAT = '0'
  373. -- 统一过滤:只保留保险机构不为空的数据
  374. AND r.INSURANCE_COMPANY IS NOT NULL
  375. GROUP BY r.INSURANCE_COMPANY
  376. )
  377. SELECT
  378. c.insurance_company AS insuranceCompany,
  379. c.company_insured_cnt AS insuredTotal,
  380. a.total_all_insured AS projectTotal,
  381. -- 计算占比,去除前导空格,除零保护
  382. LTRIM(TO_CHAR(ROUND(c.company_insured_cnt / NULLIF(a.total_all_insured, 0) * 100, 1), '999.0')) || '%' AS insuranceRatio
  383. FROM company_data c, all_insured a
  384. ORDER BY c.company_insured_cnt DESC
  385. </select>
  386. <select id="preventionServiceUnitView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  387. WITH all_insured AS (
  388. SELECT COUNT(DISTINCT "PROJECT_ID") AS total_all_proj
  389. FROM "ATT_PROJECT_INSURANCE_RECORD"
  390. WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  391. AND "DATA_STAT" = '0'
  392. ),
  393. unit_group AS (
  394. SELECT
  395. service_unit,
  396. COUNT(DISTINCT "PROJECT_ID") AS unit_proj_cnt
  397. FROM (
  398. SELECT
  399. CASE
  400. WHEN "PREVENTION_SERVICE_UNIT" IS NULL THEN '无预防服务单位'
  401. ELSE "PREVENTION_SERVICE_UNIT"
  402. END AS service_unit,
  403. "PROJECT_ID"
  404. FROM "ATT_PROJECT_INSURANCE_RECORD"
  405. WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  406. AND "DATA_STAT" = '0'
  407. ) t
  408. GROUP BY service_unit
  409. )
  410. SELECT
  411. g.service_unit AS preventionServiceUnit,
  412. g.unit_proj_cnt AS projectTotal,
  413. a.total_all_proj AS insuredTotal,
  414. DECODE(a.total_all_proj,
  415. 0, '0.0%',
  416. TRUNC(g.unit_proj_cnt * 1000 / a.total_all_proj) / 10 || '%'
  417. ) AS insuranceRatio
  418. FROM unit_group g
  419. CROSS JOIN all_insured a
  420. ORDER BY g.unit_proj_cnt DESC
  421. </select>
  422. <select id="handView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  423. WITH raw_data AS (
  424. SELECT
  425. r."INSURANCE_COMPANY",
  426. r."PROJECT_ID",
  427. r."PREMIUM_AMOUNT",
  428. SUBSTR(p."AD_CODE",1,4) AS city_code
  429. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  430. INNER JOIN "ATT_PROJECT_INSURANCE" p ON r."PROJECT_ID" = p."ID"
  431. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  432. AND r."DATA_STAT" = '0'
  433. AND p."DATA_STAT" = '0'
  434. -- 新增:仅保险机构不为空的数据参与统计
  435. AND r."INSURANCE_COMPANY" IS NOT NULL
  436. ),
  437. agg_all AS (
  438. SELECT
  439. COUNT(DISTINCT "INSURANCE_COMPANY") AS company_total,
  440. COUNT(DISTINCT "PROJECT_ID") AS project_total,
  441. SUM("PREMIUM_AMOUNT") AS total_premium,
  442. COUNT(DISTINCT CASE WHEN city_code IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509') THEN city_code END) AS covered_city_num
  443. FROM raw_data
  444. )
  445. SELECT
  446. company_total AS companyCount,
  447. project_total AS insuredTotal,
  448. total_premium AS premiumSum,
  449. covered_city_num || '/9' AS coveredCityNum
  450. FROM agg_all
  451. </select>
  452. <select id="numberRanking" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  453. SELECT
  454. r."INSURANCE_COMPANY" AS insuranceCompany,
  455. COUNT(DISTINCT r."PROJECT_ID") AS insuredTotal
  456. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  457. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  458. AND r."DATA_STAT" = '0'
  459. -- 新增过滤:只保留保险机构不为空的数据
  460. AND r."INSURANCE_COMPANY" IS NOT NULL
  461. GROUP BY r."INSURANCE_COMPANY"
  462. ORDER BY COUNT(DISTINCT r."PROJECT_ID") DESC
  463. </select>
  464. <select id="insuranceCompanyDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  465. WITH year_total AS (
  466. -- 当年全省总承保工程(分母,仅保险机构不为空的数据)
  467. SELECT COUNT(DISTINCT "PROJECT_ID") AS total_proj
  468. FROM "ATT_PROJECT_INSURANCE_RECORD"
  469. WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  470. AND "DATA_STAT" = '0'
  471. -- 新增:过滤保险机构为空记录
  472. AND "INSURANCE_COMPANY" IS NOT NULL
  473. ),
  474. company_stat AS (
  475. SELECT
  476. "INSURANCE_COMPANY",
  477. COUNT(DISTINCT "PROJECT_ID") AS company_proj_cnt,
  478. SUM("PREMIUM_AMOUNT") AS company_premium
  479. FROM "ATT_PROJECT_INSURANCE_RECORD"
  480. WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  481. AND "DATA_STAT" = '0'
  482. -- 新增:只统计保险机构有值的记录
  483. AND "INSURANCE_COMPANY" IS NOT NULL
  484. GROUP BY "INSURANCE_COMPANY"
  485. )
  486. SELECT
  487. c."INSURANCE_COMPANY" AS insuranceCompany,
  488. c.company_proj_cnt AS insuredTotal,
  489. -- 占比 保留1位小数
  490. LTRIM(TO_CHAR(ROUND(c.company_proj_cnt / NULLIF(t.total_proj,0) * 100,1), '999.0')) || '%' AS insuranceRatio,
  491. c.company_premium AS premiumSum
  492. FROM company_stat c, year_total t
  493. ORDER BY c.company_proj_cnt DESC
  494. </select>
  495. <select id="handServiceView" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  496. WITH rec_all AS (
  497. -- 当年全部投保记录(含有无服务单位)
  498. SELECT
  499. r."PROJECT_ID",
  500. r."PREVENTION_SERVICE_UNIT",
  501. SUBSTR(p."AD_CODE",1,4) AS city_code
  502. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  503. LEFT JOIN "ATT_PROJECT_INSURANCE" p
  504. ON r."PROJECT_ID" = p."ID"
  505. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  506. AND r."DATA_STAT" = '0'
  507. AND p."DATA_STAT" = '0'
  508. ),
  509. agg_base AS (
  510. SELECT
  511. -- 全部当年总工程(分母,空/非空服务单位都算)
  512. COUNT(DISTINCT "PROJECT_ID") AS total_all_proj,
  513. -- 有服务单位的工程总数
  514. COUNT(DISTINCT CASE WHEN "PREVENTION_SERVICE_UNIT" IS NOT NULL THEN "PROJECT_ID" END) AS service_proj_cnt,
  515. -- 去重有效服务机构数量
  516. COUNT(DISTINCT CASE WHEN "PREVENTION_SERVICE_UNIT" IS NOT NULL THEN "PREVENTION_SERVICE_UNIT" END) AS service_org_total,
  517. -- 已覆盖地市编码数量
  518. COUNT(DISTINCT CASE
  519. WHEN city_code IN ('3501','3502','3503','3504','3505','3506','3507','3508','3509')
  520. THEN city_code
  521. END) AS covered_city
  522. FROM rec_all
  523. )
  524. SELECT
  525. service_org_total AS serviceCount,
  526. service_proj_cnt AS insuredTotal,
  527. -- 服务覆盖率 保留1位小数
  528. LTRIM(TO_CHAR(ROUND(service_proj_cnt / NULLIF(total_all_proj, 0) * 100, 1), '999.0')) || '%' AS insuranceRatio,
  529. covered_city || '/9' AS coveredCityNum
  530. FROM agg_base
  531. </select>
  532. <select id="numberServiceRanking" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  533. SELECT
  534. r."PREVENTION_SERVICE_UNIT" AS preventionServiceUnit,
  535. COUNT(DISTINCT r."PROJECT_ID") AS insuredTotal
  536. FROM "ATT_PROJECT_INSURANCE_RECORD" r
  537. WHERE r."YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  538. AND r."DATA_STAT" = '0'
  539. AND r."PREVENTION_SERVICE_UNIT" IS NOT NULL
  540. GROUP BY r."PREVENTION_SERVICE_UNIT"
  541. ORDER BY COUNT(DISTINCT r."PROJECT_ID") DESC
  542. </select>
  543. <select id="serviceUnitDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  544. WITH year_total AS (
  545. -- 当年全部工程总数(占比分母,有无服务单位都计入)
  546. SELECT COUNT(DISTINCT "PROJECT_ID") AS total_proj
  547. FROM "ATT_PROJECT_INSURANCE_RECORD"
  548. WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  549. AND "DATA_STAT" = '0'
  550. ),
  551. org_stat AS (
  552. SELECT
  553. "PREVENTION_SERVICE_UNIT" AS service_unit,
  554. COUNT(DISTINCT "PROJECT_ID") AS unit_proj_cnt
  555. FROM "ATT_PROJECT_INSURANCE_RECORD"
  556. WHERE "YEAR" = TO_CHAR(SYSDATE, 'YYYY')
  557. AND "DATA_STAT" = '0'
  558. AND "PREVENTION_SERVICE_UNIT" IS NOT NULL
  559. GROUP BY "PREVENTION_SERVICE_UNIT"
  560. )
  561. SELECT
  562. o.service_unit AS preventionServiceUnit,
  563. o.unit_proj_cnt AS insuredTotal,
  564. LTRIM(TO_CHAR(ROUND(o.unit_proj_cnt / NULLIF(t.total_proj, 0) * 100, 1), '999.0')) || '%' AS insuranceRatio
  565. FROM org_stat o, year_total t
  566. ORDER BY o.unit_proj_cnt DESC
  567. </select>
  568. <select id="cityCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  569. SELECT
  570. r.INSURANCE_COMPANY AS insuranceCompany,
  571. COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
  572. ROUND(SUM(r.PREMIUM_AMOUNT)/1,2) AS premiumSum,
  573. 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
  574. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
  575. JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
  576. WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
  577. AND r.DATA_STAT='0'
  578. AND p.DATA_STAT='0'
  579. <if test="insuranceCompany != null and insuranceCompany != ''">
  580. and r.INSURANCE_COMPANY = #{insuranceCompany}
  581. </if>
  582. GROUP BY r.INSURANCE_COMPANY
  583. </select>
  584. <select id="cityCoveredDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  585. SELECT
  586. SUBSTR(p.AD_CODE,1,4) AS adCode,
  587. CASE SUBSTR(p.AD_CODE,1,4)
  588. WHEN '3501' THEN '福州市'
  589. WHEN '3502' THEN '厦门市'
  590. WHEN '3503' THEN '莆田市'
  591. WHEN '3504' THEN '三明市'
  592. WHEN '3505' THEN '泉州市'
  593. WHEN '3506' THEN '漳州市'
  594. WHEN '3507' THEN '南平市'
  595. WHEN '3508' THEN '龙岩市'
  596. WHEN '3509' THEN '宁德市'
  597. END AS city,
  598. COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
  599. -- 占比:当前地市有效工程 / 筛选范围内全部有效工程
  600. LTRIM(TO_CHAR(
  601. ROUND(
  602. COUNT(DISTINCT r.PROJECT_ID)
  603. / NULLIF(
  604. (SELECT COUNT(DISTINCT rr.PROJECT_ID)
  605. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD rr
  606. INNER JOIN GW_HUIYI.ATT_PROJECT_INSURANCE pp ON rr.PROJECT_ID = pp.ID
  607. WHERE rr.YEAR = TO_CHAR(SYSDATE, 'yyyy')
  608. AND rr.DATA_STAT = '0'
  609. AND pp.DATA_STAT = '0'
  610. -- 新增:保险机构不为空才计入分母总数
  611. AND rr.INSURANCE_COMPANY IS NOT NULL
  612. <if test="insuranceCompany != null and insuranceCompany != ''">
  613. AND rr.INSURANCE_COMPANY = #{insuranceCompany}
  614. </if>
  615. ),
  616. 0) * 100,
  617. 1), '999.0')) || '%' AS insuranceRatio,
  618. ROUND(SUM(r.PREMIUM_AMOUNT),1) AS premiumSum
  619. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
  620. JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
  621. WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
  622. AND r.DATA_STAT='0'
  623. AND p.DATA_STAT='0'
  624. -- 新增:保险机构为空的整条记录直接过滤,不参与计数、保费求和
  625. AND r.INSURANCE_COMPANY IS NOT NULL
  626. <if test="insuranceCompany != null and insuranceCompany != ''">
  627. AND r.INSURANCE_COMPANY = #{insuranceCompany}
  628. </if>
  629. GROUP BY SUBSTR(p.AD_CODE,1,4)
  630. ORDER BY COUNT(DISTINCT r.PROJECT_ID) DESC
  631. </select>
  632. <select id="countyCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  633. SELECT
  634. CASE SUBSTR(p.AD_CODE,1,4)
  635. WHEN '3501' THEN '福州市'
  636. WHEN '3502' THEN '厦门市'
  637. WHEN '3503' THEN '莆田市'
  638. WHEN '3504' THEN '三明市'
  639. WHEN '3505' THEN '泉州市'
  640. WHEN '3506' THEN '漳州市'
  641. WHEN '3507' THEN '南平市'
  642. WHEN '3508' THEN '龙岩市'
  643. WHEN '3509' THEN '宁德市'
  644. END AS city,
  645. r.INSURANCE_COMPANY AS insuranceCompany,
  646. COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
  647. TO_CHAR(ROUND(SUM(r.PREMIUM_AMOUNT),2)) AS premiumSum
  648. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
  649. JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID = p.ID
  650. WHERE r.YEAR = TO_CHAR(SYSDATE,'yyyy')
  651. AND r.DATA_STAT = '0'
  652. AND p.DATA_STAT = '0'
  653. -- 新增条件:保险机构不为空才纳入统计
  654. AND r.INSURANCE_COMPANY IS NOT NULL
  655. <if test="insuranceCompany != null and insuranceCompany != ''">
  656. AND r.INSURANCE_COMPANY = #{insuranceCompany}
  657. </if>
  658. <if test="adCode != null and adCode != ''">
  659. AND SUBSTR(p.AD_CODE,1,4) LIKE CONCAT(SUBSTR(#{adCode},1,4),'%')
  660. </if>
  661. GROUP BY SUBSTR(p.AD_CODE,1,4), r.INSURANCE_COMPANY
  662. </select>
  663. <select id="serviceCityCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  664. SELECT
  665. r.PREVENTION_SERVICE_UNIT AS preventionServiceUnit,
  666. COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
  667. ROUND(SUM(r.PREVENTION_SERVICE_FEE)/1,2) AS premiumSum,
  668. 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
  669. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
  670. JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
  671. WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
  672. AND r.DATA_STAT='0'
  673. AND p.DATA_STAT='0'
  674. -- 新增:只保留服务单位不为空的数据
  675. AND r.PREVENTION_SERVICE_UNIT IS NOT NULL
  676. <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
  677. and r.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
  678. </if>
  679. GROUP BY r.PREVENTION_SERVICE_UNIT
  680. </select>
  681. <select id="serviceCityCoveredDetail" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  682. SELECT
  683. SUBSTR(p.AD_CODE,1,4) AS adCode,
  684. CASE SUBSTR(p.AD_CODE,1,4)
  685. WHEN '3501' THEN '福州市'
  686. WHEN '3502' THEN '厦门市'
  687. WHEN '3503' THEN '莆田市'
  688. WHEN '3504' THEN '三明市'
  689. WHEN '3505' THEN '泉州市'
  690. WHEN '3506' THEN '漳州市'
  691. WHEN '3507' THEN '南平市'
  692. WHEN '3508' THEN '龙岩市'
  693. WHEN '3509' THEN '宁德市'
  694. END AS city,
  695. COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
  696. -- 占比:当前地市有效工程 / 该机构当年全部有效工程(PREVENTION_SERVICE_UNIT不为空)
  697. LTRIM(TO_CHAR(
  698. ROUND(
  699. COUNT(DISTINCT r.PROJECT_ID)
  700. / NULLIF(
  701. (SELECT COUNT(DISTINCT rr.PROJECT_ID)
  702. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD rr
  703. INNER JOIN GW_HUIYI.ATT_PROJECT_INSURANCE pp ON rr.PROJECT_ID = pp.ID
  704. WHERE rr.YEAR = TO_CHAR(SYSDATE, 'yyyy')
  705. AND rr.DATA_STAT = '0'
  706. AND pp.DATA_STAT = '0'
  707. -- 关键:服务单位不为空才计入分母总数
  708. AND rr.PREVENTION_SERVICE_UNIT IS NOT NULL
  709. <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
  710. AND rr.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
  711. </if>
  712. ),
  713. 0) * 100,
  714. 1), '999.0')) || '%' AS insuranceRatio,
  715. ROUND(SUM(r.PREVENTION_SERVICE_FEE),1) AS premiumSum
  716. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
  717. JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID=p.ID
  718. WHERE r.YEAR=TO_CHAR(SYSDATE,'yyyy')
  719. AND r.DATA_STAT='0'
  720. AND p.DATA_STAT='0'
  721. -- 关键:当前地市只统计服务单位不为空的数据
  722. AND r.PREVENTION_SERVICE_UNIT IS NOT NULL
  723. <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
  724. AND r.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
  725. </if>
  726. GROUP BY SUBSTR(p.AD_CODE,1,4)
  727. ORDER BY COUNT(DISTINCT r.PROJECT_ID) DESC
  728. </select>
  729. <select id="serviceCountyCovered" resultType="cn.com.goldenwater.dcproj.dto.AttProjectInsuranceRecordViewDto">
  730. SELECT
  731. CASE SUBSTR(p.AD_CODE,1,4)
  732. WHEN '3501' THEN '福州市'
  733. WHEN '3502' THEN '厦门市'
  734. WHEN '3503' THEN '莆田市'
  735. WHEN '3504' THEN '三明市'
  736. WHEN '3505' THEN '泉州市'
  737. WHEN '3506' THEN '漳州市'
  738. WHEN '3507' THEN '南平市'
  739. WHEN '3508' THEN '龙岩市'
  740. WHEN '3509' THEN '宁德市'
  741. END AS city,
  742. r.PREVENTION_SERVICE_UNIT AS preventionServiceUnit,
  743. COUNT(DISTINCT r.PROJECT_ID) AS insuredTotal,
  744. TO_CHAR(ROUND(SUM(r.PREVENTION_SERVICE_FEE),2)) AS premiumSum
  745. FROM GW_HUIYI.ATT_PROJECT_INSURANCE_RECORD r
  746. JOIN GW_HUIYI.ATT_PROJECT_INSURANCE p ON r.PROJECT_ID = p.ID
  747. WHERE r.YEAR = TO_CHAR(SYSDATE,'yyyy')
  748. AND r.DATA_STAT = '0'
  749. AND p.DATA_STAT = '0'
  750. -- 新增:仅保留服务单位不为空的数据
  751. AND r.PREVENTION_SERVICE_UNIT IS NOT NULL
  752. <if test="preventionServiceUnit != null and preventionServiceUnit != ''">
  753. AND r.PREVENTION_SERVICE_UNIT = #{preventionServiceUnit}
  754. </if>
  755. <if test="adCode != null and adCode != ''">
  756. AND SUBSTR(p.AD_CODE,1,4) LIKE CONCAT(SUBSTR(#{adCode},1,4),'%')
  757. </if>
  758. GROUP BY SUBSTR(p.AD_CODE,1,4), r.PREVENTION_SERVICE_UNIT
  759. </select>
  760. </mapper>