客户信息存储过程.sql 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_main() -- 初始化 数据全部插入
  2. IS
  3. DECLARE
  4. individual_count int
  5. strsql string
  6. BEGIN
  7. --先验是否一个客户id有多条记录对应不通的证件类别
  8. --初始化 身份证 用户
  9. shanglifeecif.init_individual_0(individual_count);
  10. --初始化 护照用户
  11. individual_count:=individual_count+1;
  12. shanglifeecif.init_individual_1(individual_count);
  13. --初始化 驾照用户
  14. individual_count:=individual_count+1;
  15. shanglifeecif.init_individual_3(individual_count);
  16. --其他 证件类型用户
  17. individual_count:=individual_count+1;
  18. shanglifeecif.init_individual_other(individual_count);
  19. --更新用户等级信息
  20. shanglifeecif.up_t_customers_class_1();
  21. --更新职业信息
  22. shanglifeecif.up_health_insurance_listing_1();
  23. END;
  24. /
  25. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_0( individual_count OUT int) -- 初始化 身份证
  26. IS
  27. BEGIN
  28. --查询出此次处理的数据并出表中
  29. insert into shanglifeecif.individual (
  30. indid,
  31. custid,
  32. scustid,
  33. name,
  34. gender,
  35. birthday,
  36. idcard,
  37. custtype,
  38. created_time,
  39. created_by
  40. )
  41. SELECT
  42. row_number()over(),
  43. 'CP'||lpad(row_number()over(),10,'0'),
  44. scustid ,
  45. name,
  46. gender ,
  47. birthday,
  48. idcard ,
  49. max(custtype) AS custtype,
  50. sysdate,
  51. 'admin'
  52. FROM (
  53. SELECT
  54. customerno AS scustid,--投保人
  55. name AS name,
  56. sex AS gender,
  57. birthday AS birthday,
  58. idtype AS idtype ,
  59. idno AS idcard,
  60. "投保人" AS custtype
  61. FROM
  62. shanghailifeecif.policy_information
  63. WHERE customerno IS NOT NULL AND idtype=0
  64. UNION
  65. SELECT
  66. insuredno AS scustid,--被保人
  67. insuredname AS name,
  68. insuredsex AS gender,
  69. insuredbirthday AS birthday,
  70. insuredidtype AS idtype ,
  71. insuredidno AS idcard,
  72. "被保人" AS custtype
  73. FROM
  74. shanghailifeecif.policy_information
  75. WHERE insuredno IS NOT NULL AND insuredidtype=0
  76. ) tmpTable GROUP BY scustid ,name,gender,birthday,idcard
  77. --已经存在的数据行数
  78. select count(0) into individual_count from shanglifeecif.individual
  79. END;
  80. /
  81. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_1(individual_count INOUT int) -- 初始化 护照
  82. IS
  83. BEGIN
  84. --查询出此次处理的数据并出表中
  85. insert into shanglifeecif.individual (
  86. indid,
  87. custid,
  88. scustid,
  89. name,
  90. gender,
  91. birthday,
  92. passport,
  93. custtype,
  94. created_time,
  95. created_by
  96. )
  97. SELECT
  98. row_number()over()+individual_count,
  99. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  100. scustid ,
  101. name,
  102. gender ,
  103. birthday,
  104. idcard ,
  105. max(custtype) as custtype,
  106. sysdate,
  107. 'admin'
  108. FROM (
  109. SELECT
  110. customerno AS scustid,--投保人
  111. name AS name,
  112. sex AS gender,
  113. birthday AS birthday,
  114. idtype AS idtype ,
  115. idno AS idcard,
  116. "投保人" as custtype
  117. FROM
  118. shanghailifeecif.policy_information
  119. WHERE customerno IS NOT NULL AND idtype=1
  120. UNION
  121. SELECT
  122. insuredno AS scustid,--被保人
  123. insuredname AS name,
  124. insuredsex AS gender,
  125. insuredbirthday AS birthday,
  126. insuredidtype AS idtype ,
  127. insuredidno AS idcard,
  128. "被保人" as custtype
  129. FROM
  130. shanghailifeecif.policy_information
  131. WHERE insuredno IS NOT NULL AND insuredidtype=1
  132. ) tmpTable GROUP BY scustid ,name,gender ,birthday,idcard
  133. --已经存在的数据行数
  134. select count(0) into individual_count from shanglifeecif.individual
  135. END;
  136. /
  137. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_3(individual_count INOUT int) -- 初始化 护照
  138. IS
  139. BEGIN
  140. --查询出此次处理的数据并出表中
  141. insert into shanglifeecif.individual(
  142. indid,
  143. custid,
  144. scustid,
  145. name,
  146. gender,
  147. birthday,
  148. dlicense,
  149. custtype,
  150. created_time,
  151. created_by
  152. )
  153. SELECT
  154. row_number()over()+individual_count,
  155. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  156. scustid ,
  157. name,
  158. gender ,
  159. birthday,
  160. idcard ,
  161. max(custtype) as custtype,
  162. sysdate,
  163. 'admin'
  164. FROM (
  165. SELECT
  166. customerno AS scustid,--投保人
  167. name AS name,
  168. sex AS gender,
  169. birthday AS birthday,
  170. idtype AS idtype ,
  171. idno AS idcard,
  172. "投保人" as custtype
  173. FROM
  174. shanghailifeecif.policy_information
  175. WHERE customerno IS NOT NULL AND idtype=3
  176. UNION
  177. SELECT
  178. insuredno AS scustid,--被保人
  179. insuredname AS name,
  180. insuredsex AS gender,
  181. insuredbirthday AS birthday,
  182. insuredidtype AS idtype ,
  183. insuredidno AS idcard,
  184. "被保人" as custtype
  185. FROM
  186. shanghailifeecif.policy_information
  187. WHERE insuredno IS NOT NULL AND insuredidtype=3
  188. ) tmpTable GROUP BY scustid ,name,gender ,birthday,idcard
  189. --已经存在的数据行数
  190. select count(0) into individual_count from shanglifeecif.individual
  191. END;
  192. /
  193. CREATE OR REPLACE PROCEDURE shanglifeecif.init_individual_other(individual_count INOUT int) -- 初始化出了以上三种证件信息
  194. IS
  195. BEGIN
  196. --查询出此次处理的数据并出表中
  197. insert into shanglifeecif.individual(
  198. indid,
  199. custid,
  200. scustid,
  201. name,
  202. gender,
  203. birthday,
  204. created_time,
  205. created_by
  206. )
  207. SELECT
  208. row_number()over()+individual_count,
  209. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  210. scustid ,
  211. name,
  212. gender ,
  213. birthday,
  214. sysdate,
  215. 'admin'
  216. FROM (
  217. SELECT
  218. customerno AS scustid,--投保人
  219. name AS name,
  220. sex AS gender,
  221. birthday AS birthday,
  222. idtype AS idtype ,
  223. idno AS idcard,
  224. "投保人" as custtype
  225. FROM
  226. shanghailifeecif.policy_information
  227. WHERE customerno IS NOT NULL AND idtype not in (0,1,3)
  228. UNION
  229. SELECT
  230. insuredno AS scustid,--被保人
  231. insuredname AS name,
  232. insuredsex AS gender,
  233. insuredbirthday AS birthday,
  234. insuredidtype AS idtype ,
  235. insuredidno AS idcard,
  236. "被保人" as custtype
  237. FROM
  238. shanghailifeecif.policy_information
  239. WHERE insuredno IS NOT NULL AND insuredidtype in (0,1,3)
  240. ) tmpTable GROUP BY scustid ,name,gender ,birthday,idcard
  241. --已经存在的数据行数
  242. select count(0) into individual_count from shanglifeecif.individual
  243. END;
  244. /
  245. CREATE OR REPLACE PROCEDURE shanglifeecif.up_t_customers_class_1() -- 创建存储过程
  246. IS
  247. BEGIN
  248. UPDATE shanglifeecif.individual a SET (
  249. CustClass ,-- 客户等级
  250. ConValue ,-- 贡献度分
  251. Awarded3 ,-- 家庭加分2
  252. Awarded2 ,-- 续期加分
  253. Awarded1 ,-- 保单加分
  254. SOValue ,-- 总分值
  255. EndDate, -- 客户等级失效日期
  256. Height, --身高
  257. Weight, --体重
  258. BMI,
  259. PIncome, --个人年收入
  260. FIncome, --家庭年收入
  261. IncomeSource, --收入来源
  262. SIStatus, --社保情况
  263. Ethnic, --民族情况
  264. Nation, --国籍
  265. MaritalStat, --婚姻
  266. Employer,--工作单位
  267. Education,--学历
  268. Dday, --死亡日期
  269. regtype, --户籍类型
  270. ZIPCODE,--邮编
  271. HPhone,--电话
  272. PMPhone,--手机
  273. email, -- 邮箱
  274. RAL --联系地址
  275. ) = (
  276. select
  277. CLASS_VALUE ,--客户等级
  278. CONTRIBUTION_VALUE ,--贡献度分
  279. AWARDED3, --家庭加分
  280. AWARDED2, --续期加分
  281. AWARDED1, --保单加分
  282. TOTAL_VALUE, --总分值
  283. END_DATE, --失效日期
  284. STATURE, --身高
  285. AVOIRDUPOIS,--体重
  286. BMI, --根据身高体重计算
  287. YEARINCOME, --个人年收入
  288. FAMILYYEARSALARY, --家庭年收入
  289. INCOMESOURCE, --收入来源
  290. SOCIALINSUFLAG, --社保情况
  291. NATIONALITY, --民族情况
  292. NATIVEPLACE, --国籍
  293. MARRIAGE,--婚姻
  294. GRPNAME,--工作单位名称
  295. DEGREE,--学历
  296. DEATHDATE,--死亡日期
  297. DENTYPE,--户籍类型
  298. ZIPCODE,--邮编
  299. PHONE,--电话
  300. MOBILE,--手机
  301. EMAIL,--邮箱
  302. POSTALADDRESS --联系地址
  303. from shanghailifeecif.t_customer_class b
  304. where b.CUSTOMER_ID = a.scustid
  305. ) WHERE 1=1 ;
  306. END;
  307. /
  308. DROP TABLE IF EXISTS shanglifeecif.occupation_tmp;
  309. CREATE TABLE shanglifeecif.occupation_tmp(
  310. scustid string not NULL COMMENT '客户号',
  311. OccupationId string DEFAULT NULL COMMENT '名称',
  312. Occupation string DEFAULT NULL COMMENT '出生日期' ,
  313. HomeAdress string DEFAULT NULL COMMENT '籍贯'
  314. )
  315. COMMENT 'occupation_tmp 客户职业临时表' STORED AS ES
  316. with shard number 10
  317. replication 1;
  318. CREATE OR REPLACE PROCEDURE shanglifeecif.up_health_insurance_listing_1() -- 创建存储过程
  319. IS
  320. BEGIN
  321. --清楚临时表数据
  322. delete shanglifeecif.occupation_tmp;
  323. --插入去重数据到临时表
  324. insert into shanglifeecif.occupation_tmp(
  325. scustid,
  326. OccupationId,
  327. Occupation,
  328. HomeAdress
  329. )
  330. select
  331. appntno,
  332. appntoccupationcode ,--职业代码
  333. appntoccupationname ,
  334. APPNTHOMEADDRESS--职业名称
  335. from shanghailifeecif.HEALTH_INSURANCE_LISTING
  336. WHERE appntoccupationcode is not null
  337. and appntoccupationname is not null
  338. group by appntno,appntoccupationcode,appntoccupationname,APPNTHOMEADDRESS
  339. --更新个人信息表
  340. UPDATE shanglifeecif.individual a SET (
  341. OccupationId ,-- 职业代码
  342. Occupation, -- 职业名称
  343. HomeAdress
  344. ) = (
  345. select
  346. OccupationId ,--职业代码
  347. Occupation,--职业名称
  348. HomeAdress
  349. from shanglifeecif.occupation_tmp b
  350. where b.scustid = a.scustid
  351. ) WHERE 1=1 ;
  352. /*--更新被保人手机号
  353. UPDATE shanglifeecif.individual a SET (
  354. PMPhone
  355. ) = (
  356. select
  357. INSUREDMOBILE
  358. from shanghailifeecif.policy_information b
  359. where b.INSUREDNO = a.scustid
  360. ) WHERE 1=1 ;*/
  361. END;
  362. /
  363. BEGIN
  364. shanglifeecif.init_individual_main();
  365. end ;