个体关系信息.sql 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.init_indrelationship_main( )
  2. IS
  3. DECLARE
  4. s_count int
  5. BEGIN
  6. DELETE FROM shanglifeecif.IndRelationShip;
  7. --从保单信息表(POLICY_INFORMATION)获取投保人和被保人的关系并
  8. --第一步取关系父母,子女
  9. insert into shanglifeecif.IndRelationShip(
  10. irsid,
  11. RSType,
  12. IndID1,
  13. Name1,
  14. IDCard1,
  15. Role1,
  16. IndID2,
  17. Name2,
  18. IDCard2,
  19. RSSTime,
  20. Role2
  21. )SELECT
  22. row_number()over(),
  23. '父母',
  24. p.CUSTOMERNO,
  25. max(p.NAME),
  26. max(p.IDNO),
  27. CASE max(p.sex)
  28. WHEN '0' THEN '儿子' WHEN '1' THEN '女儿' END,
  29. p.INSUREDNO,
  30. max(p.INSUREDNAME),
  31. max(p.INSUREDIDNO),
  32. min(p.polapplydate),
  33. CASE max(p.INSUREDSEX)
  34. WHEN '0' THEN '父亲' WHEN '1' THEN '母亲' END
  35. FROM POLICY_INFORMATION p
  36. WHERE (p.RELATIONTOAPPNT = '父母' OR p.RELATIONTOAPPNT = '子女')
  37. AND p.birthday > p.insuredbirthday
  38. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  39. select count(*) into s_count from shanglifeecif.IndRelationShip;
  40. insert into shanglifeecif.IndRelationShip(
  41. irsid,
  42. RSType,
  43. IndID1,
  44. Name1,
  45. IDCard1,
  46. Role1,
  47. IndID2,
  48. Name2,
  49. IDCard2,
  50. RSSTime,
  51. Role2
  52. )
  53. SELECT
  54. row_number()over()+s_count,
  55. '子女',
  56. p.CUSTOMERNO,
  57. max(p.NAME),
  58. max(p.IDNO),
  59. CASE max(p.sex)
  60. WHEN '0' THEN '父亲' WHEN '1' THEN '母亲' END,
  61. p.INSUREDNO,
  62. max(p.INSUREDNAME),
  63. max(p.INSUREDIDNO),
  64. min(p.polapplydate),
  65. CASE max(p.INSUREDSEX)
  66. WHEN '0' THEN '儿子' WHEN '1' THEN '女儿' END
  67. FROM POLICY_INFORMATION p
  68. WHERE (p.RELATIONTOAPPNT = '父母' OR p.RELATIONTOAPPNT = '子女')
  69. AND p.birthday < p.insuredbirthday
  70. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  71. select count(*) into s_count from shanglifeecif.IndRelationShip;
  72. --第二步取关系祖父母、外祖父母 祖孙、外祖孙
  73. insert into shanglifeecif.IndRelationShip(
  74. irsid,
  75. RSType,
  76. IndID1,
  77. Name1,
  78. IDCard1,
  79. Role1,
  80. IndID2,
  81. Name2,
  82. IDCard2,
  83. RSSTime,
  84. Role2
  85. )SELECT
  86. row_number()over()+s_count,
  87. '祖父母、外祖父母',
  88. p.CUSTOMERNO,
  89. max(p.NAME),
  90. max(p.IDNO),
  91. CASE max(p.sex)
  92. WHEN '0' THEN '(外)祖孙' WHEN '1' THEN '(外)孙女' END,
  93. p.INSUREDNO,
  94. max(p.INSUREDNAME),
  95. max(p.INSUREDIDNO),
  96. min(p.polapplydate),
  97. CASE max(p.INSUREDSEX)
  98. WHEN '0' THEN '(外)祖父' WHEN '1' THEN '(外)祖母' END
  99. FROM POLICY_INFORMATION p
  100. WHERE (p.RELATIONTOAPPNT = '祖父母、外祖父母' OR p.RELATIONTOAPPNT = '祖孙、外祖孙')
  101. AND p.birthday > p.insuredbirthday
  102. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  103. select count(*) into s_count from shanglifeecif.IndRelationShip;
  104. insert into shanglifeecif.IndRelationShip(
  105. irsid,
  106. RSType,
  107. IndID1,
  108. Name1,
  109. IDCard1,
  110. Role1,
  111. IndID2,
  112. Name2,
  113. IDCard2,
  114. RSSTime,
  115. Role2
  116. )SELECT
  117. row_number()over()+s_count,
  118. '祖孙、外祖孙',
  119. p.CUSTOMERNO,
  120. max(p.NAME),
  121. max(p.IDNO),
  122. CASE max(p.sex)
  123. WHEN '0' THEN '(外)祖父' WHEN '1' THEN '(外)祖母' END,
  124. p.INSUREDNO,
  125. max(p.INSUREDNAME),
  126. max(p.INSUREDIDNO),
  127. min(p.polapplydate),
  128. CASE max(p.INSUREDSEX)
  129. WHEN '0' THEN '(外)祖孙' WHEN '1' THEN '(外)孙女' END
  130. FROM POLICY_INFORMATION p
  131. WHERE (p.RELATIONTOAPPNT = '祖父母、外祖父母' OR p.RELATIONTOAPPNT = '祖孙、外祖孙')
  132. AND p.birthday < p.insuredbirthday
  133. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  134. select count(*) into s_count from shanglifeecif.IndRelationShip;
  135. --第三步取配偶和其他
  136. insert into shanglifeecif.IndRelationShip(
  137. irsid,
  138. RSType,
  139. IndID1,
  140. Name1,
  141. IDCard1,
  142. Role1,
  143. IndID2,
  144. Name2,
  145. IDCard2,
  146. RSSTime,
  147. Role2
  148. )SELECT
  149. row_number()over()+s_count,
  150. max(p.RELATIONTOAPPNT),
  151. p.CUSTOMERNO,
  152. max(p.NAME),
  153. max(p.IDNO),
  154. CASE max(p.RELATIONTOAPPNT)
  155. WHEN '配偶'
  156. THEN case max(p.sex) WHEN '0' THEN '丈夫' WHEN '1' THEN '妻子' END
  157. ELSE max(p.RELATIONTOAPPNT)
  158. END,
  159. p.INSUREDNO,
  160. max(p.INSUREDNAME),
  161. max(p.INSUREDIDNO),
  162. min(p.polapplydate),
  163. CASE max(p.RELATIONTOAPPNT)
  164. WHEN '配偶'
  165. THEN case max(p.INSUREDSEX) WHEN '0' THEN '丈夫' WHEN '1' THEN '妻子' END
  166. ELSE max(p.RELATIONTOAPPNT)
  167. END
  168. FROM POLICY_INFORMATION p
  169. WHERE p.RELATIONTOAPPNT = '配偶' or p.RELATIONTOAPPNT = '其他'
  170. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  171. /*insert into shanglifeecif.IndRelationShip(
  172. irsid,
  173. RSType,
  174. IndID1,
  175. Name1,
  176. IDCard1,
  177. Role1,
  178. IndID2,
  179. Name2,
  180. IDCard2,
  181. RSSTime,
  182. Role2
  183. )
  184. SELECT
  185. row_number()over(),
  186. max(p.RELATIONTOAPPNT),
  187. p.CUSTOMERNO,
  188. max(p.NAME),
  189. max(p.IDNO),
  190. CASE max(p.RELATIONTOAPPNT)
  191. WHEN '子女'
  192. THEN CASE max(p.sex)
  193. WHEN 1 THEN '母亲'
  194. WHEN 0 THEN '父亲'
  195. END
  196. WHEN '父母'
  197. THEN CASE max(p.sex)
  198. WHEN 1 THEN '女儿'
  199. WHEN 0 THEN '儿子'
  200. END
  201. WHEN '配偶'
  202. THEN CASE max(p.sex)
  203. WHEN 1 THEN '妻子'
  204. WHEN 0 THEN '丈夫'
  205. END
  206. WHEN '祖父母、外祖父母'
  207. THEN CASE max(p.sex)
  208. WHEN 1 THEN '(外)孙女'
  209. WHEN 0 THEN '(外)祖孙'
  210. END
  211. WHEN '祖孙、外祖孙'
  212. THEN CASE max(p.sex)
  213. WHEN 1 THEN '(外)祖母'
  214. WHEN 0 THEN '(外)祖父'
  215. END
  216. ELSE max(p.RELATIONTOAPPNT)
  217. END AS Role1,
  218. p.INSUREDNO,
  219. max(p.INSUREDNAME),
  220. max(p.INSUREDIDNO),
  221. min(p.polapplydate),
  222. CASE max(p.RELATIONTOAPPNT)
  223. WHEN '子女'
  224. THEN CASE max(p.INSUREDSEX)
  225. WHEN 1 THEN '女儿'
  226. WHEN 0 THEN '儿子'
  227. END
  228. WHEN '父母'
  229. THEN CASE max(p.INSUREDSEX)
  230. WHEN 1 THEN '母亲'
  231. WHEN 0 THEN '父亲'
  232. END
  233. WHEN '配偶'
  234. THEN CASE max(p.INSUREDSEX)
  235. WHEN 1 THEN '妻子'
  236. WHEN 0 THEN '丈夫'
  237. END
  238. WHEN '祖父母、外祖父母'
  239. THEN CASE max(p.INSUREDSEX)
  240. WHEN 1 THEN '(外)祖母'
  241. WHEN 0 THEN '(外)祖父'
  242. END
  243. WHEN '祖孙、外祖孙'
  244. THEN CASE max(p.INSUREDSEX)
  245. WHEN 1 THEN '(外)孙女'
  246. WHEN 0 THEN '(外)祖孙'
  247. END
  248. ELSE max(p.RELATIONTOAPPNT)
  249. END AS Role2
  250. FROM POLICY_INFORMATION p
  251. WHERE p.RELATIONTOAPPNT<>'本人'
  252. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  253. --此时插入IndRelationShip的IndID1,IndID2为上游系统客户号,根据Individual.SCustID更新为Individual.IndID
  254. UPDATE shanglifeecif.IndRelationShip sirs SET sirs.indid1 =
  255. (SELECT si.indid FROM shanglifeecif.individual si WHERE si.scustid = sirs.indid1);
  256. UPDATE shanglifeecif.IndRelationShip sirs SET sirs.indid2 =
  257. (SELECT si.indid FROM shanglifeecif.individual si WHERE si.scustid = sirs.indid2);
  258. */
  259. EXCEPTION
  260. WHEN HIVE_EXCEPTION THEN
  261. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  262. WHEN Others THEN
  263. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  264. END;