222NewProcedure.sql 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. CREATE PROCEDURE shanglifeecif.222NewProcedure( )
  2. IS
  3. DECLARE
  4. s_count int
  5. BEGIN
  6. DELETE FROM shanglifeecif.IndRelationShip;
  7. --从保单信息表(dsj.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. reflect("java.util.UUID", "randomUUID"),
  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 dsj.POLICY_INFORMATION p
  36. WHERE (p.RELATIONTOAPPNT = '父母' OR p.RELATIONTOAPPNT = '子女')
  37. AND p.birthday > p.insuredbirthday
  38. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  39. insert into shanglifeecif.IndRelationShip(
  40. irsid,
  41. RSType,
  42. IndID1,
  43. Name1,
  44. IDCard1,
  45. Role1,
  46. IndID2,
  47. Name2,
  48. IDCard2,
  49. RSSTime,
  50. Role2
  51. )
  52. SELECT
  53. reflect("java.util.UUID", "randomUUID"),
  54. '子女',
  55. p.CUSTOMERNO,
  56. max(p.NAME),
  57. max(p.IDNO),
  58. CASE max(p.sex)
  59. WHEN '0' THEN '父亲' WHEN '1' THEN '母亲' END,
  60. p.INSUREDNO,
  61. max(p.INSUREDNAME),
  62. max(p.INSUREDIDNO),
  63. min(p.polapplydate),
  64. CASE max(p.INSUREDSEX)
  65. WHEN '0' THEN '儿子' WHEN '1' THEN '女儿' END
  66. FROM dsj.POLICY_INFORMATION p
  67. WHERE (p.RELATIONTOAPPNT = '父母' OR p.RELATIONTOAPPNT = '子女')
  68. AND p.birthday < p.insuredbirthday
  69. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  70. --第二步取关系祖父母、外祖父母 祖孙、外祖孙
  71. insert into shanglifeecif.IndRelationShip(
  72. irsid,
  73. RSType,
  74. IndID1,
  75. Name1,
  76. IDCard1,
  77. Role1,
  78. IndID2,
  79. Name2,
  80. IDCard2,
  81. RSSTime,
  82. Role2
  83. )SELECT
  84. reflect("java.util.UUID", "randomUUID"),
  85. '祖父母、外祖父母',
  86. p.CUSTOMERNO,
  87. max(p.NAME),
  88. max(p.IDNO),
  89. CASE max(p.sex)
  90. WHEN '0' THEN '(外)祖孙' WHEN '1' THEN '(外)孙女' END,
  91. p.INSUREDNO,
  92. max(p.INSUREDNAME),
  93. max(p.INSUREDIDNO),
  94. min(p.polapplydate),
  95. CASE max(p.INSUREDSEX)
  96. WHEN '0' THEN '(外)祖父' WHEN '1' THEN '(外)祖母' END
  97. FROM dsj.POLICY_INFORMATION p
  98. WHERE (p.RELATIONTOAPPNT = '祖父母、外祖父母' OR p.RELATIONTOAPPNT = '祖孙、外祖孙')
  99. AND p.birthday > p.insuredbirthday
  100. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  101. insert into shanglifeecif.IndRelationShip(
  102. irsid,
  103. RSType,
  104. IndID1,
  105. Name1,
  106. IDCard1,
  107. Role1,
  108. IndID2,
  109. Name2,
  110. IDCard2,
  111. RSSTime,
  112. Role2
  113. )SELECT
  114. reflect("java.util.UUID", "randomUUID"),
  115. '祖孙、外祖孙',
  116. p.CUSTOMERNO,
  117. max(p.NAME),
  118. max(p.IDNO),
  119. CASE max(p.sex)
  120. WHEN '0' THEN '(外)祖父' WHEN '1' THEN '(外)祖母' END,
  121. p.INSUREDNO,
  122. max(p.INSUREDNAME),
  123. max(p.INSUREDIDNO),
  124. min(p.polapplydate),
  125. CASE max(p.INSUREDSEX)
  126. WHEN '0' THEN '(外)祖孙' WHEN '1' THEN '(外)孙女' END
  127. FROM dsj.POLICY_INFORMATION p
  128. WHERE (p.RELATIONTOAPPNT = '祖父母、外祖父母' OR p.RELATIONTOAPPNT = '祖孙、外祖孙')
  129. AND p.birthday < p.insuredbirthday
  130. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  131. --第三步取配偶和其他
  132. insert into shanglifeecif.IndRelationShip(
  133. irsid,
  134. RSType,
  135. IndID1,
  136. Name1,
  137. IDCard1,
  138. Role1,
  139. IndID2,
  140. Name2,
  141. IDCard2,
  142. RSSTime,
  143. Role2
  144. )SELECT
  145. reflect("java.util.UUID", "randomUUID"),
  146. max(p.RELATIONTOAPPNT),
  147. p.CUSTOMERNO,
  148. max(p.NAME),
  149. max(p.IDNO),
  150. CASE max(p.RELATIONTOAPPNT)
  151. WHEN '配偶'
  152. THEN case max(p.sex) WHEN '0' THEN '丈夫' WHEN '1' THEN '妻子' END
  153. ELSE max(p.RELATIONTOAPPNT)
  154. END,
  155. p.INSUREDNO,
  156. max(p.INSUREDNAME),
  157. max(p.INSUREDIDNO),
  158. min(p.polapplydate),
  159. CASE max(p.RELATIONTOAPPNT)
  160. WHEN '配偶'
  161. THEN case max(p.INSUREDSEX) WHEN '0' THEN '丈夫' WHEN '1' THEN '妻子' END
  162. ELSE max(p.RELATIONTOAPPNT)
  163. END
  164. FROM dsj.POLICY_INFORMATION p
  165. WHERE p.RELATIONTOAPPNT = '配偶'
  166. -- or p.RELATIONTOAPPNT = '其他'
  167. GROUP BY p.CUSTOMERNO,p.INSUREDNO;
  168. -- 完善被保人关系
  169. /** */
  170. insert into shanglifeecif.IndRelationShip(
  171. irsid,
  172. RSType,
  173. IndID1,
  174. Name1,
  175. IDCard1,
  176. Role1,
  177. IndID2,
  178. Name2,
  179. IDCard2,
  180. Role2
  181. )SELECT reflect("java.util.UUID", "randomUUID"),
  182. CASE RSType
  183. WHEN '父母' THEN '子女'
  184. WHEN '子女' THEN '父母'
  185. WHEN '祖孙、外祖孙' THEN '祖父母、外祖父母'
  186. WHEN '祖父母、外祖父母' THEN '祖孙、外祖孙'
  187. WHEN '配偶' THEN '配偶'
  188. ELSE RSType
  189. END,
  190. IndID2,
  191. Name2,
  192. IDCard2,
  193. Role2,
  194. IndID1,
  195. Name1,
  196. IDCard1,
  197. Role1
  198. FROM shanglifeecif.IndRelationShip sis ;
  199. dbms_output.put_line('init_indrelationship_main函数跑批完成!');
  200. EXCEPTION
  201. WHEN HIVE_EXCEPTION THEN
  202. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  203. WHEN Others THEN
  204. INSERT INTO shanglifeecif.exception_log(log_id,log_code,log_msg,log_time) VALUES (to_char(sysdate(),'yyyyMMddHHmmss'),sqlcode(),sqlerrm(),sysdate());
  205. END;