客户标签label41-60.sql 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.updateIndividualLable_41_60() IS
  2. DECLARE
  3. BEGIN
  4. --47 是否仅有1年期短险保单 Label43 仅有1年期短险保单,有1年期短险保单 "policy_information表 SECURITY in('1年','6月','180天') riskperiod=‘短期险’
  5. --riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')" 客户为保单投保人,所有保单的保障期限为一年
  6. UPDATE shanglifeecif.Individual si1 SET si1.Label43 = (
  7. SELECT
  8. CASE
  9. WHEN temp.cnt >0 THEN
  10. '有1年期短险保单'
  11. END
  12. FROM
  13. (
  14. SELECT
  15. count(1) cnt,
  16. policy.customerno
  17. FROM
  18. policy_information policy
  19. where
  20. policy.SECURITY in('1年','6月','180天')
  21. and
  22. policy.riskperiod='短期险'
  23. and
  24. policy.riskcode not in('1066008','1066007','1066006','1066004','1066003','1066002','1066001','1065005','1065003','1065001','1025003')
  25. GROUP BY
  26. policy.customerno
  27. ) temp
  28. WHERE
  29. temp.customerno = si1.scustid
  30. );
  31. --48 是否有失效保单 Label44 有失效保单 NOIVPolicy 客户为保单投保人,持有保单中保单状态为失效 (最新文档逻辑)
  32. UPDATE shanglifeecif.Individual si1 SET si1.label44 = '有失效保单' WHERE si1.scustid IN (
  33. SELECT p.customerno FROM policy_information p WHERE p.contno IN (select contno from lccontstate where statetype = 'Available' and state = '1')
  34. );
  35. --49 是否有缴费期满长险保单 Label45 有缴费期满长险保单 POLICY_INFORMATION:paycount= payendyear AND riskperiod='长期险' 客户持有保险期限为一年以上,剩余保费期数为0
  36. UPDATE shanglifeecif.Individual si1 SET si1.label45 = '有缴费期满长险保单' WHERE si1.scustid IN (
  37. SELECT p.customerno FROM policy_information p WHERE p.contno IN (
  38. select contno from lcpol where payintv > 0 and paytodate = payenddate and months_between(cvalidate, enddate) > 12
  39. )
  40. );
  41. --50 是否有续期缴费的保单 Label46 有续期缴费的保单 客户为投保人,含有待缴费状态的保单
  42. UPDATE shanglifeecif.Individual si1 SET si1.label46 = '有续期缴费保单' WHERE si1.scustid IN (
  43. SELECT p.customerno FROM policy_information p WHERE p.contno IN (
  44. select otherno from ljspay where othernotype = '2'
  45. )
  46. );
  47. --51 有责任期满的保单 Label47 有责任期满的保单 客户持有保单含有保险期限已满的保单
  48. UPDATE shanglifeecif.Individual si1 SET si1.label47 = '有责任期满的保单' WHERE si1.scustid IN (
  49. SELECT p.customerno FROM policy_information p WHERE p.contno IN (
  50. select contno from lcpol where enddate < SYSDATE
  51. )
  52. );
  53. --52 第一张保单投保日期 Label48 首次投保日期XXXX-XX-XX FADate 客户所有保单中投保时间最早的日期
  54. --第一步
  55. UPDATE shanglifeecif.Individual si1 SET si1.FADate = (
  56. SELECT fadate FROM (
  57. SELECT p.customerno,min(p.CUSTOMGETPOLDATE) AS fadate FROM POLICY_INFORMATION p WHERE p.customgetpoldate IS NOT null GROUP BY p.customerno
  58. ) t WHERE t.customerno = si1.scustid
  59. );
  60. UPDATE shanglifeecif.Individual si1 SET si1.label48 = '首次投保日期' || si1.fadate WHERE si1.fadate IS NOT NULL;
  61. --53 最后一次寿险投保距今时长 Label49 最后一次投保距今XXX天 LAPPDate 当前日期减去客户所有保单中最后一次投保的保单的投保时间
  62. UPDATE shanglifeecif.Individual si1 SET si1.LAPPDate = (
  63. SELECT fadate FROM (
  64. SELECT p.customerno,max(p.CUSTOMGETPOLDATE) AS fadate FROM POLICY_INFORMATION p WHERE p.customgetpoldate IS NOT null GROUP BY p.customerno
  65. ) t WHERE t.customerno = si1.scustid
  66. );
  67. UPDATE shanglifeecif.Individual si1 SET si1.label49 = '最后一次投保距今' || DATEDIFF(sysdate(), si1.LAPPDate) || '天' WHERE si1.lappdate IS NOT NULL;
  68. --54 最近一次保单所属渠道 Label50 最近保单团险渠道、最近保单个人营销、最近保单银行代理、最近保单中介渠道、最近保单网销渠道 --LPChannel,InsuranceArrangement.AgentChannel 客户最后一次投保归属渠道
  69. UPDATE shanglifeecif.Individual si1 SET si1.label50 = (SELECT '最近保单' || trim(t.salecomname) FROM (
  70. SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate DESC) rd,p.salecomname FROM POLICY_INFORMATION p
  71. WHERE p.salecomname IS NOT null
  72. ) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  73. --UPDATE shanglifeecif.Individual si1 SET si1.label50 = (SELECT t.SALECHNL FROM (
  74. --SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate DESC) rd,p.SALECHNL FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  75. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  76. --UPDATE shanglifeecif.Individual si1 SET si1.label50 = '最近保单' || si1.label50 WHERE si1.label50 IS NOT NULL;
  77. --55 最近一次保单所属机构 Label51 最近XX机构 LPOrg,InsuranceArrangement.AgentOrg 客户最后一次投保归属机构
  78. --UPDATE shanglifeecif.Individual si1 SET si1.label51 = (SELECT t.AGENTCOM FROM (
  79. -- SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate DESC) rd,p.AGENTCOM FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  80. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  81. --UPDATE shanglifeecif.Individual si1 SET si1.label51 = '最近机构' || si1.label51 WHERE si1.label51 IS NOT NULL;
  82. --56 最早保单所属渠道 Label52 首单团险渠道、首单个人营销、首单银行代理、首单中介渠道、首单网销渠道 FAChannel 客户第一次投保时保单归属渠道
  83. UPDATE shanglifeecif.Individual si1 SET si1.label52 = (SELECT '首单' || trim(t.salecomname) FROM (
  84. SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate asc) rd,p.salecomname FROM POLICY_INFORMATION p WHERE p.salecomname IS NOT null
  85. ) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  86. --UPDATE shanglifeecif.Individual si1 SET si1.label52 = (SELECT t.SALECHNL FROM (
  87. --SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate asc) rd,p.SALECHNL FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  88. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  89. --UPDATE shanglifeecif.Individual si1 SET si1.label52 = '首单' || si1.label52 WHERE si1.label52 IS NOT NULL;
  90. --57 最早保单所属机构 Label53 首单XX机构 FAOrg 客户第一次投保时保单归属机构
  91. --UPDATE shanglifeecif.Individual si1 SET si1.label53 = (SELECT t.AGENTCOM FROM (
  92. -- SELECT p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate ASC) rd,p.AGENTCOM FROM POLICY_INFORMATION p WHERE p.salechnl IS NOT null
  93. --) t WHERE t.rd = 1 AND t.customerno = si1.scustid);
  94. --UPDATE shanglifeecif.Individual si1 SET si1.Label53 = '最近机构' || si1.Label53 WHERE si1.Label53 IS NOT NULL;
  95. --58 最近保单状态 Label54 "未承保承保新增附加险终止续保未对账对账失败" LPState 客户最后一张保单的保单状态
  96. UPDATE shanglifeecif.Individual si1 SET si1.label54 =
  97. (SELECT
  98. (CASE temp.appflag
  99. WHEN '0' THEN '最近保单状态未承保'
  100. WHEN '1' THEN '最近保单状态承保'
  101. WHEN '2' THEN '最近保单状态新增附加险'
  102. WHEN '4' THEN '最近保单状态终止'
  103. WHEN '9' THEN '最近保单状态续保'
  104. WHEN 'B' THEN '最近保单状态未对账'
  105. WHEN 'F' THEN '最近保单状态对账失败'
  106. END) a
  107. FROM (
  108. SELECT t.appflag,p.customerno,row_number()OVER(PARTITION BY p.customerno ORDER BY p.customgetpoldate desc) rd FROM policy_information p,lccont t WHERE p.contno = t.contno
  109. ) temp WHERE temp.rd = 1 AND si1.scustid = temp.customerno);
  110. --60 是否有退保保单 Label56 有退保保单 如何判断? 客户所有的保单中是否存在保单状态为退保的保单
  111. UPDATE shanglifeecif.Individual si1 SET si1.label56 = '有退保保单' WHERE si1.scustid IN (
  112. SELECT p.customerno FROM policy_information p WHERE p.contno IN (
  113. select contno from lpedoritem where edortype in ('CT', 'XT', 'GT') and edorstate = '0'
  114. )
  115. );
  116. --61 最近一次理赔类型 Label57 --意外医疗、意外伤残、意外死亡、意外高残、意外大病、意外特种疾病、意外失业失能、意外生命末期重疾、意外豁免、疾病医疗、疾病伤残、疾病死亡、疾病高残、疾病大病、疾病特种疾病、疾病失---业失能、疾病生命末期重疾、疾病豁免 无 客户最后一次投办理理赔业务的业务类型
  117. UPDATE shanglifeecif.Individual si1 SET si1.Label57 = (
  118. SELECT t.ACCIDENTTYPE FROM (
  119. SELECT row_number()OVER(PARTITION BY c.insuredno ORDER BY c.applydate desc) rd,c.insuredno,c.ACCIDENTTYPE FROM INSURANCE_CLAIM c
  120. ) t WHERE t.rd = 1 AND t.insuredno = si1.scustid
  121. );
  122. --62 最近一次出险类型 Label58 疾病出险、意外出险 无 客户最后一次出险的类型
  123. UPDATE shanglifeecif.Individual si1 SET si1.Label58 = (
  124. SELECT t.RISKTYPE FROM (
  125. SELECT row_number()OVER(PARTITION BY c.insuredno ORDER BY c.applydate desc) rd,c.insuredno,c.RISKTYPE FROM INSURANCE_CLAIM c
  126. ) t WHERE t.rd = 1 AND t.insuredno = si1.scustid
  127. );
  128. --63 最近一次理赔状态 Label59 理赔报案中、理赔已受理、理赔已立案、理赔审核中、理赔预付审批中、理赔结案、理赔完成、理赔关闭 InsuranceClaimThread.ClaimCaseStatus --客户最后一次发生理赔的理赔类型
  129. UPDATE shanglifeecif.Individual si1 SET si1.Label59 = (
  130. SELECT '最近一次理赔状态' || t.LLCLAIMSTATE FROM (
  131. SELECT row_number()OVER(PARTITION BY c.insuredno ORDER BY c.applydate desc) rd,c.insuredno,c.LLCLAIMSTATE FROM INSURANCE_CLAIM c
  132. ) t WHERE t.rd = 1 AND t.insuredno = si1.scustid
  133. );
  134. EXCEPTION
  135. WHEN HIVE_EXCEPTION THEN
  136. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  137. WHEN Others THEN
  138. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  139. END