参与方事件.sql 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_tb() -- 创建主存储过程
  2. IS
  3. BEGIN
  4. insert into shanglifeecif.partytimeline (
  5. TripID,
  6. PolicyNo,
  7. PartyID,
  8. name,
  9. PCertID,
  10. PRole,
  11. Scenario,
  12. SDate,
  13. enddate,
  14. created_by ,
  15. created_time
  16. ) select
  17. reflect("java.util.UUID", "randomUUID"),
  18. trim(contno) as contno,
  19. trim(max(customerno)) as customerno,
  20. trim(max(name)) as name,
  21. trim(max(idno)) as idno,
  22. '投保人',
  23. '投保',
  24. trim(max(polapplydate)) as polapplydate,
  25. trim(max(enddate)) as enddate,
  26. 'admin',
  27. sysdate()
  28. from dsj.policy_information WHERE contno IS NOT NULL GROUP BY contno;
  29. EXCEPTION
  30. WHEN HIVE_EXCEPTION THEN
  31. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  32. WHEN Others THEN
  33. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  34. END;
  35. /
  36. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_lp()
  37. IS
  38. DECLARE
  39. p_count int
  40. BEGIN
  41. insert into shanglifeecif.partytimeline (
  42. TripID,
  43. PolicyNo,
  44. PartyID,
  45. name,
  46. PCertID,
  47. PRole,
  48. Scenario,
  49. SDate,
  50. describe,
  51. created_by ,
  52. created_time
  53. ) select
  54. reflect("java.util.UUID", "randomUUID"),
  55. trim(contno) as contno,
  56. trim(INSUREDNO) as INSUREDNO,
  57. trim(INSUREDNAME) as INSUREDNAME,
  58. trim(idno) as idno,
  59. '投保人',
  60. '理赔',
  61. CASE
  62. WHEN APPLYDATE IS NOT NULL THEN APPLYDATE
  63. WHEN APPLYDATE IS NULL THEN RPTDATE
  64. END AS SDate,
  65. trim(ACCIDENTTYPE) as ACCIDENTTYPE,
  66. 'admin',
  67. sysdate()
  68. from dsj.insurance_claim WHERE contno IS NOT NULL;
  69. EXCEPTION
  70. WHEN HIVE_EXCEPTION THEN
  71. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  72. WHEN Others THEN
  73. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  74. END;
  75. /
  76. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_zx()
  77. IS
  78. DECLARE
  79. p_count int
  80. BEGIN
  81. insert into shanglifeecif.partytimeline (
  82. TripID,
  83. PolicyNo,
  84. PartyID,
  85. name,
  86. PRole,
  87. Scenario,
  88. SDate,
  89. DESCRIBE,
  90. created_by ,
  91. created_time
  92. ) SELECT
  93. reflect("java.util.UUID", "randomUUID"),
  94. m.contnos,
  95. max(i.customerno) customerno,
  96. max(m.econtactsName) econtactsName,
  97. '投保人' AS tbr,
  98. '咨询' AS zx,
  99. m.starttime,
  100. max(m.reasonsecondname) reasonsecondname,
  101. 'admin',
  102. sysdate()
  103. from dsj.cc_record_main m
  104. LEFT JOIN dsj.policy_information i ON m.contnos = i.contno
  105. WHERE m.contnos IS NOT NULL GROUP BY m.contnos,m.starttime;
  106. EXCEPTION
  107. WHEN HIVE_EXCEPTION THEN
  108. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  109. WHEN Others THEN
  110. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  111. END;
  112. /
  113. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_bq()
  114. IS
  115. DECLARE
  116. p_count int
  117. BEGIN
  118. insert into shanglifeecif.partytimeline (
  119. TripID,
  120. PolicyNo,
  121. PartyID,
  122. name,
  123. PRole,
  124. Scenario,
  125. SDate,
  126. DESCRIBE,
  127. created_by ,
  128. created_time
  129. )select
  130. reflect("java.util.UUID", "randomUUID"),
  131. i.contno,
  132. i.customerno,
  133. i.name,
  134. '投保人' AS tbr,
  135. '保全' AS bq,
  136. l.edorappdate,
  137. lm.edorname,
  138. 'admin',
  139. sysdate()
  140. FROM dsj.lpedoritem l,dsj.lmedoritem lm,dsj.policy_information i
  141. WHERE l.edortype = lm.edorcode AND lm.appobj <> 'G' AND l.edorstate = '0' AND i.contno = l.contno
  142. EXCEPTION
  143. WHEN HIVE_EXCEPTION THEN
  144. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  145. WHEN Others THEN
  146. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  147. END
  148. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_hf()
  149. IS
  150. DECLARE
  151. p_count int
  152. BEGIN
  153. insert into shanglifeecif.partytimeline (
  154. TripID,
  155. PolicyNo,
  156. PartyID,
  157. name,
  158. PRole,
  159. Scenario,
  160. SDate,
  161. DESCRIBE,
  162. created_by ,
  163. created_time
  164. ) SELECT
  165. reflect("java.util.UUID", "randomUUID"),
  166. cad.productno,
  167. cac.customerno,
  168. max(cac.customername),
  169. '投保人',
  170. '回访',
  171. cad.inserttime,
  172. CASE max(cad.actiondefguid)
  173. when '402837815c1a4fc6015c1a735351122d' then '特殊回访'
  174. when '402837815c1a4fc6015c1a735350012a' then '其他回访'
  175. when '402837815c2ff6b5015c3005e7fb0004' then '失效回访'
  176. when '402837815c2ff6b5015c3005e7fb2222' then '回执超期回访'
  177. when '402837815c2ff6b5015c3005e7fb0003' then '宽限期50天'
  178. when '402837815c2ff6b5015c3005e7fb0002' then '宽限期30天'
  179. when '402837815c1a4fc6015c1a735350012f' then '新契约回访'
  180. when '402837815c2ff6b5015c3005e7fb0001' then '续期回访'
  181. end ,
  182. 'admin',
  183. sysdate()
  184. FROM dsj.CC_ACTION_DATA cad,dsj.cc_action_customerinfo cac
  185. WHERE cac.unioncustomerid = cad.unioncustomerid AND cad.inserttime IS NOT null GROUP BY cad.productno,cac.customerno,cad.inserttime;
  186. EXCEPTION
  187. WHEN HIVE_EXCEPTION THEN
  188. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  189. WHEN Others THEN
  190. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  191. END;
  192. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_ts()
  193. IS
  194. DECLARE
  195. p_count int
  196. BEGIN
  197. insert into shanglifeecif.partytimeline (
  198. TripID,
  199. PolicyNo,
  200. PartyID,
  201. name,
  202. PRole,
  203. Scenario,
  204. SDate,
  205. DESCRIBE,
  206. created_by ,
  207. created_time
  208. ) SELECT
  209. reflect("java.util.UUID", "randomUUID"),
  210. max(ac.productnos),
  211. max(i.customerno),
  212. max(ac.complaintsname),
  213. '投保人'||CASE max(ac.complaintsrelation)
  214. WHEN '201' THEN ''
  215. WHEN '202' THEN '子女'
  216. WHEN '203' THEN '配偶'
  217. WHEN '204' THEN '父母'
  218. WHEN '205' THEN '其他关系'
  219. END AS complaintsrelation,
  220. '投诉',
  221. ac.inserttime ,
  222. CASE max(ac.resultclassification)
  223. WHEN '101' THEN '销售纠纷'
  224. WHEN '102' THEN '理赔纠纷'
  225. WHEN '103' THEN '退保纠纷'
  226. WHEN '104' THEN '承保纠纷'
  227. WHEN '105' THEN '续收续保纠纷'
  228. WHEN '106' THEN '保全纠纷'
  229. WHEN '107' THEN '其他'
  230. END as resultclassification,
  231. 'admin',
  232. sysdate
  233. FROM dsj.cc_action_complaints ac
  234. LEFT JOIN dsj.policy_information i ON ac.productnos = i.contno
  235. WHERE ac.productnos IS NOT NULL AND i.customerno IS NOT NULL
  236. GROUP BY ac.inserttime ;
  237. EXCEPTION
  238. WHEN HIVE_EXCEPTION THEN
  239. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  240. WHEN Others THEN
  241. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  242. END;
  243. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_tuibao()
  244. IS
  245. DECLARE
  246. p_count int
  247. BEGIN
  248. insert into shanglifeecif.partytimeline (
  249. TripID,
  250. PolicyNo,
  251. PartyID,
  252. name,
  253. PRole,
  254. Scenario,
  255. SDate,
  256. DESCRIBE,
  257. created_by ,
  258. created_time
  259. ) SELECT
  260. reflect("java.util.UUID", "randomUUID"),
  261. trim(t.contno) as contno,
  262. trim(t.customerno) as customerno,
  263. trim(t.name) as name,
  264. trim(t.tbr) as tbr,
  265. trim(t.tb) as tb,
  266. trim(t.edorappdate) as edorappdate,
  267. t.edorreason,
  268. 'admin',
  269. sysdate()
  270. FROM (
  271. SELECT
  272. row_number() over(partition by i.contno) rn,
  273. lm.contno,
  274. i.customerno,
  275. i.name,
  276. '投保人' AS tbr,
  277. '退保' AS tb,
  278. to_char(lm.edorappdate,"yyyy-MM-dd") edorappdate,
  279. CASE lm.edorreasoncode
  280. WHEN '01' THEN '死亡'
  281. WHEN '02' THEN '失踪'
  282. WHEN '03' THEN '离异'
  283. WHEN '04' THEN '债权转移'
  284. WHEN '05' THEN '被保险人成年'
  285. WHEN '06' THEN '其它'
  286. ELSE '其它'
  287. END AS edorreason
  288. FROM dsj.lpedoritem lm,dsj.policy_information i
  289. where lm.contno = i.contno AND lm.edortype='CT' AND lm.edorstate = 0
  290. ) t WHERE t.rn = 1;
  291. EXCEPTION
  292. WHEN HIVE_EXCEPTION THEN
  293. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  294. WHEN Others THEN
  295. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  296. END;
  297. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_xq() -- 创建主存储过程
  298. IS
  299. BEGIN
  300. insert into shanglifeecif.partytimeline (
  301. TripID,
  302. PolicyNo,
  303. PartyID,
  304. name,
  305. PRole,
  306. Scenario,
  307. SDate,
  308. created_by ,
  309. created_time
  310. ) select
  311. reflect("java.util.UUID", "randomUUID"),
  312. lp.contno,
  313. lp.appntno,
  314. '',
  315. '投保人',
  316. '续期',
  317. to_char(lp.confdate,'yyyy-MM-dd'),
  318. 'admin',
  319. sysdate
  320. FROM dsj.ljapayperson lp WHERE lp.paycount > 1;
  321. EXCEPTION
  322. WHEN HIVE_EXCEPTION THEN
  323. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  324. WHEN Others THEN
  325. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  326. END;
  327. CREATE OR REPLACE PROCEDURE shanglifeecif.partytimeline_main()
  328. IS
  329. BEGIN
  330. DELETE FROM shanglifeecif.partytimeline;
  331. shanglifeecif.partytimeline_tb();
  332. shanglifeecif.partytimeline_lp();
  333. shanglifeecif.partytimeline_zx();
  334. shanglifeecif.partytimeline_bq();
  335. shanglifeecif.partytimeline_tuibao();
  336. shanglifeecif.partytimeline_ts();
  337. shanglifeecif.partytimeline_hf();
  338. shanglifeecif.partytimeline_xq();
  339. END;