个人信息开发qxp.sql 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. -----------------------------------------------------------------------
  2. --创建数据源
  3. CREATE TABLE policy_information(
  4. contno varchar2(200) DEFAULT NULL COMMENT '保单号', -- dialect: ORACLE
  5. riskcode varchar2(200) DEFAULT NULL COMMENT '险种代码', -- dialect: ORACLE
  6. riskname varchar2(200) DEFAULT NULL COMMENT '险种名称', -- dialect: ORACLE
  7. riskperiod varchar2(200) DEFAULT NULL COMMENT '险种分类', -- dialect: ORACLE
  8. risktype varchar2(200) DEFAULT NULL COMMENT '险种设计类型',
  9. payintv varchar2(200) DEFAULT NULL COMMENT '缴费方式',
  10. security varchar2(200) not NULL COMMENT '保障年期',
  11. payendyear number not NULL COMMENT '缴费期间',
  12. payendyearflag varchar2(200) not NULL COMMENT '缴费年期单位',
  13. insuyer number not NULL COMMENT '保险年期',
  14. insuyerflag varchar2(200) not NULL COMMENT '保险年期单位',
  15. paycount number not NULL COMMENT '续保次数',
  16. signdate timestamp not NULL COMMENT '承保日期',
  17. cvalidate timestamp not NULL COMMENT '生效日期',
  18. enddate timestamp not NULL COMMENT '保单终止日期',
  19. modifydate timestamp not null comment '更新时间',
  20. prem number not null COMMENT '保费',
  21. appflag varchar2(200) not NULL COMMENT '保单状态',
  22. customerno varchar2(200) not null comment '客户号',
  23. name varchar2(200) not null comment '客户姓名',
  24. sex varchar2(200) not null comment '客户性别',
  25. birthday timestamp not null comment '客户出生日期',
  26. idtype varchar2(200) not null comment '客户证件类型',
  27. idno varchar2(200) not null comment '客户证件号',
  28. insuredno varchar2(200) not null comment '被保人号',
  29. insuredname varchar2(200) not null comment '被保人姓名',
  30. insuredsex varchar2(200) not null comment '被保人性别',
  31. insuredbirthday timestamp not null comment '被保人出生日期',
  32. insuredidtype varchar2(200) not null comment '被保人证件类型',
  33. insuredidno varchar2(200) not null comment '被保人证件号码',
  34. relationtoappnt varchar2(200) not null comment '与投保人关系',
  35. salechnl varchar2(200) not null comment '销售渠道',
  36. salecom varchar2(200) not null comment '业绩归属',
  37. salechannels varchar2(200) not NULL COMMENT '二级业绩归属',
  38. customgetpoldate timestamp not null comment '客户投保日期',
  39. prem_js number not null comment 'prem_js'
  40. )
  41. COMMENT '投保清单'
  42. STORED AS CSVFILE ;
  43. --推送数据命令
  44. --hdfs dfs -put /home/frontData/ /tmp/myData/
  45. LOAD DATA INPATH '/tmp/myData/policy_information.txt' OVERWRITE INTO TABLE qxp.policy_information;
  46. --------------------------------------------------------------------------------------------------------------------
  47. TRUNCATE TABLE individual;
  48. --创建search目的表
  49. DROP TABLE IF EXISTS individual;
  50. CREATE TABLE qxp.individual_search(
  51. indid string DEFAULT NULL COMMENT '个体ID',
  52. custid string DEFAULT NULL COMMENT '全局客户号',
  53. SCustID string DEFAULT NULL COMMENT '客户号',
  54. created_by string DEFAULT NULL COMMENT '创建人',
  55. created_time timestamp DEFAULT NULL COMMENT '创建时间',
  56. updated_by string DEFAULT NULL COMMENT '更新人',
  57. updated_time timestamp DEFAULT NULL COMMENT '更新时间',
  58. name string DEFAULT NULL COMMENT '名称',
  59. birthday date DEFAULT NULL COMMENT '出生日期',
  60. nobirth string DEFAULT NULL COMMENT '出生国家', -- dialect: ORACLE
  61. sobirth string DEFAULT NULL COMMENT '出生省份', -- dialect: ORACLE
  62. cobirth string DEFAULT NULL COMMENT '出生城市', -- dialect: ORACLE
  63. homeadress string DEFAULT NULL COMMENT '籍贯',
  64. dday date DEFAULT NULL COMMENT '死亡日期',
  65. gender string DEFAULT NULL COMMENT '性别', -- dialect: ORACLE
  66. ethnic string DEFAULT NULL COMMENT '民族', -- dialect: ORACLE
  67. nation string DEFAULT NULL COMMENT '国籍', -- dialect: ORACLE
  68. regresidence string DEFAULT NULL COMMENT '户口所在地',
  69. maritalstat string DEFAULT NULL COMMENT '婚姻状况', -- dialect: ORACLE
  70. maritalstatdate date DEFAULT NULL COMMENT '婚姻状况日期',
  71. offspring string DEFAULT NULL COMMENT '生育状况', -- dialect: ORACLE
  72. support string DEFAULT NULL COMMENT '赡养状况', -- dialect: ORACLE
  73. empstat string DEFAULT NULL COMMENT '就业状况', -- dialect: ORACLE
  74. empstatdate string DEFAULT NULL COMMENT '就业状况日期', -- dialect: ORACLE
  75. raid string DEFAULT NULL COMMENT '居住地址',
  76. ral string DEFAULT NULL COMMENT '居住地址不分段',
  77. al string DEFAULT NULL COMMENT '曾用地址不分段',
  78. coadress int DEFAULT NULL COMMENT '地址登录数量',
  79. pmphone string DEFAULT NULL COMMENT '常用手机',
  80. mhone string DEFAULT NULL COMMENT '曾用手机',
  81. sophone int DEFAULT NULL COMMENT '手机登录数量',
  82. height decimal(8,2) DEFAULT NULL COMMENT '身高',
  83. weight decimal(8,2) DEFAULT NULL COMMENT '体重',
  84. cillness string DEFAULT NULL COMMENT '当前疾病', -- dialect: ORACLE
  85. pillness string DEFAULT NULL COMMENT '曾患疾病', -- dialect: ORACLE
  86. bmi decimal(8,2) DEFAULT NULL COMMENT 'BMI体制指数',
  87. evadate date DEFAULT NULL COMMENT '健康评估日期',
  88. cohevaluation int DEFAULT NULL COMMENT '健康评估登录数量',
  89. hphone string DEFAULT NULL COMMENT '家庭电话',
  90. occupation string DEFAULT NULL COMMENT '职业', -- dialect: ORACLE
  91. odate date DEFAULT NULL COMMENT '职业时间',
  92. employer string DEFAULT NULL COMMENT '工作单位',
  93. wphone string DEFAULT NULL COMMENT '工作电话',
  94. empdate date DEFAULT NULL COMMENT '工作单位时间',
  95. idcard string DEFAULT NULL COMMENT '身份证',
  96. passport string DEFAULT NULL COMMENT '护照',
  97. dlicense string DEFAULT NULL COMMENT '驾驶证',
  98. education string DEFAULT NULL COMMENT '最高学历', -- dialect: ORACLE
  99. university string DEFAULT NULL COMMENT '毕业学校',
  100. edate date DEFAULT NULL COMMENT '学历时间',
  101. wechat string DEFAULT NULL COMMENT '微信',
  102. weibo string DEFAULT NULL COMMENT '微博',
  103. email string DEFAULT NULL COMMENT '邮箱',
  104. qq string DEFAULT NULL COMMENT 'QQ',
  105. tiktok string DEFAULT NULL COMMENT '抖音',
  106. saccount1 string DEFAULT NULL COMMENT '社交账号1',
  107. sa1cat string DEFAULT NULL COMMENT '社交账号1类别', -- dialect: ORACLE
  108. saccount2 string DEFAULT NULL COMMENT '社交账号2',
  109. sa2cat string DEFAULT NULL COMMENT '社交账号2类别', -- dialect: ORACLE
  110. ctype string DEFAULT NULL COMMENT '首选联系方式', -- dialect: ORACLE
  111. father string DEFAULT NULL COMMENT '父亲',
  112. mother string DEFAULT NULL COMMENT '母亲',
  113. mate string DEFAULT NULL COMMENT '配偶',
  114. child1 string DEFAULT NULL COMMENT '子女1',
  115. child2 string DEFAULT NULL COMMENT '子女2',
  116. cochild int DEFAULT NULL COMMENT '子女登录数量',
  117. fmhistory string DEFAULT NULL COMMENT '家族病史', -- dialect: ORACLE
  118. rpid string DEFAULT NULL COMMENT '房产',
  119. rpdescribe string DEFAULT NULL COMMENT '房产描述',
  120. corp int DEFAULT NULL COMMENT '房产登录数量',
  121. vid string DEFAULT NULL COMMENT '车辆',
  122. vdescribe string DEFAULT NULL COMMENT '车辆描述',
  123. covehicle int DEFAULT NULL COMMENT '车辆登录数量',
  124. anniversary1 date DEFAULT NULL COMMENT '纪念日1',
  125. a1describe string DEFAULT NULL COMMENT '纪念日1类型', -- dialect: ORACLE
  126. anniversary2 date DEFAULT NULL COMMENT '纪念日2',
  127. a2describe string DEFAULT NULL COMMENT '纪念日2类型', -- dialect: ORACLE
  128. soanniversary int DEFAULT NULL COMMENT '纪念日登录数量',
  129. custtype string DEFAULT NULL COMMENT '客户类型', -- dialect: ORACLE
  130. bankname string DEFAULT NULL COMMENT '开户银行', -- dialect: ORACLE
  131. tobankcard string DEFAULT NULL COMMENT '银行卡类型', -- dialect: ORACLE
  132. accname string DEFAULT NULL COMMENT '账户名',
  133. bankaccno string DEFAULT NULL COMMENT '银行帐号',
  134. cobaccount int DEFAULT NULL COMMENT '账户登录数量',
  135. sotlirisk decimal(32,8) DEFAULT NULL COMMENT '传统寿险种保额合计',
  136. soairisk decimal(32,8) DEFAULT NULL COMMENT '意外类险种保额合计',
  137. sosiirisk decimal(32,8) DEFAULT NULL COMMENT '重疾类险种保额合计',
  138. somcirisk decimal(32,8) DEFAULT NULL COMMENT '医疗费用类险种保额合计',
  139. someirisk decimal(32,8) DEFAULT NULL COMMENT '医疗补贴类险种保额合计',
  140. soefirisk decimal(32,8) DEFAULT NULL COMMENT '教育金类险种保额合计',
  141. sopirisk decimal(32,8) DEFAULT NULL COMMENT '养老金类险种保额合计',
  142. sowmirisk decimal(32,8) DEFAULT NULL COMMENT '财富管理险种保额合计',
  143. custclass int DEFAULT NULL COMMENT '客户等级',
  144. convalue int DEFAULT NULL COMMENT '贡献度分',
  145. awarded3 int DEFAULT NULL COMMENT '家庭加分',
  146. awarded2 int DEFAULT NULL COMMENT '续期加分',
  147. awarded1 int DEFAULT NULL COMMENT '保单加分',
  148. sovalue int DEFAULT NULL COMMENT '总分值',
  149. enddate date DEFAULT NULL COMMENT '客户等级失效日期',
  150. systemtag1 string DEFAULT NULL COMMENT '系统标签域1',
  151. systemtag2 string DEFAULT NULL COMMENT '系统标签域2',
  152. systemtag3 string DEFAULT NULL COMMENT '系统标签域3',
  153. cocommunication int DEFAULT NULL COMMENT '接触次数',
  154. lcdate date DEFAULT NULL COMMENT '最近接触时间',
  155. lctype string DEFAULT NULL COMMENT '最近接触类型', -- dialect: ORACLE
  156. cocomplaint int DEFAULT NULL COMMENT '投诉次数',
  157. lcptdate date DEFAULT NULL COMMENT '最近投诉时间',
  158. lcptreason string DEFAULT NULL COMMENT '最近投诉原因', -- dialect: ORACLE
  159. lcptlink string DEFAULT NULL COMMENT '最近投诉环节', -- dialect: ORACLE
  160. lcptresult string DEFAULT NULL COMMENT '最近投诉处理结果', -- dialect: ORACLE
  161. lcptduration decimal(8,2) DEFAULT NULL COMMENT '最近投诉处理时长',
  162. lcptperson string DEFAULT NULL COMMENT '最近投诉人', -- dialect: ORACLE
  163. soppremium decimal(32,8) DEFAULT NULL COMMENT '累计已缴保费',
  164. lappdate date DEFAULT NULL COMMENT '最近投保日期',
  165. cndate date DEFAULT NULL COMMENT '最近报案日期',
  166. cnstatus string DEFAULT NULL COMMENT '最近报案状态', -- dialect: ORACLE
  167. cocnotification int DEFAULT NULL COMMENT '报案登录数量',
  168. fadate date DEFAULT NULL COMMENT '首次投保日期',
  169. ladate date DEFAULT NULL COMMENT '最近投保日期',
  170. lpno string DEFAULT NULL COMMENT '最近保险单号',
  171. lpstate string DEFAULT NULL COMMENT '最近保单状态', -- dialect: ORACLE
  172. lpname string DEFAULT NULL COMMENT '最近投保险种名称',
  173. copolicy int DEFAULT NULL COMMENT '保单登录数量',
  174. iaccno1 string DEFAULT NULL COMMENT '保险账户1',
  175. iaccno2 string DEFAULT NULL COMMENT '保险账户2',
  176. iaccno3 string DEFAULT NULL COMMENT '保险账户3',
  177. soiaccount1 decimal(32,8) DEFAULT NULL COMMENT '保险账户1余额',
  178. soiaccount2 decimal(32,8) DEFAULT NULL COMMENT '保险账户2余额',
  179. soiaccount3 decimal(32,8) DEFAULT NULL COMMENT '保险账户3余额',
  180. coiaccount int DEFAULT NULL COMMENT '保险账户登录数量',
  181. Label1 string COMMENT 'Label1' ,
  182. Label2 string COMMENT 'Label2' ,
  183. Label3 string COMMENT 'Label3' ,
  184. Label4 string COMMENT 'Label4' ,
  185. Label5 string COMMENT 'Label5' ,
  186. Label6 string COMMENT 'Label6' ,
  187. Label7 string COMMENT 'Label7' ,
  188. Label8 string COMMENT 'Label8' ,
  189. Label9 string COMMENT 'Label9' ,
  190. Label10 string COMMENT 'Label10' ,
  191. Label11 string COMMENT 'Label11' ,
  192. Label12 string COMMENT 'Label12' ,
  193. Label13 string COMMENT 'Label13' ,
  194. Label14 string COMMENT 'Label14' ,
  195. Label15 string COMMENT 'Label15' ,
  196. Label16 string COMMENT 'Label16' ,
  197. Label17 string COMMENT 'Label17' ,
  198. Label18 string COMMENT 'Label18' ,
  199. Label19 string COMMENT 'Label19' ,
  200. Label20 string COMMENT 'Label20' ,
  201. Label21 string COMMENT 'Label21' ,
  202. Label22 string COMMENT 'Label22' ,
  203. Label23 string COMMENT 'Label23' ,
  204. Label24 string COMMENT 'Label24' ,
  205. Label25 string COMMENT 'Label25' ,
  206. Label26 string COMMENT 'Label26' ,
  207. Label27 string COMMENT 'Label27' ,
  208. Label28 string COMMENT 'Label28' ,
  209. Label29 string COMMENT 'Label29' ,
  210. Label30 string COMMENT 'Label30' ,
  211. Label31 string COMMENT 'Label31' ,
  212. Label32 string COMMENT 'Label32' ,
  213. Label33 string COMMENT 'Label33' ,
  214. Label34 string COMMENT 'Label34' ,
  215. Label35 string COMMENT 'Label35' ,
  216. Label36 string COMMENT 'Label36' ,
  217. Label37 string COMMENT 'Label37' ,
  218. Label38 string COMMENT 'Label38' ,
  219. Label39 string COMMENT 'Label39' ,
  220. Label40 string COMMENT 'Label40' ,
  221. Label41 string COMMENT 'Label41' ,
  222. Label42 string COMMENT 'Label42' ,
  223. Label43 string COMMENT 'Label43' ,
  224. Label44 string COMMENT 'Label44' ,
  225. Label45 string COMMENT 'Label45' ,
  226. Label46 string COMMENT 'Label46' ,
  227. Label47 string COMMENT 'Label47' ,
  228. Label48 string COMMENT 'Label48' ,
  229. Label49 string COMMENT 'Label49' ,
  230. Label50 string COMMENT 'Label50' ,
  231. Label51 string COMMENT 'Label51' ,
  232. Label52 string COMMENT 'Label52' ,
  233. Label53 string COMMENT 'Label53' ,
  234. Label54 string COMMENT 'Label54' ,
  235. Label55 string COMMENT 'Label55' ,
  236. Label56 string COMMENT 'Label56' ,
  237. Label57 string COMMENT 'Label57' ,
  238. Label58 string COMMENT 'Label58' ,
  239. Label59 string COMMENT 'Label59' ,
  240. Label60 string COMMENT 'Label60' ,
  241. Label61 string COMMENT 'Label61' ,
  242. Label62 string COMMENT 'Label62' ,
  243. Label63 string COMMENT 'Label63' ,
  244. Label64 string COMMENT 'Label64' ,
  245. Label65 string COMMENT 'Label65' ,
  246. Label66 string COMMENT 'Label66' ,
  247. Label67 string COMMENT 'Label67' ,
  248. Label68 string COMMENT 'Label68' ,
  249. Label69 string COMMENT 'Label69' ,
  250. Label70 string COMMENT 'Label70' ,
  251. Label71 string COMMENT 'Label71' ,
  252. Label72 string COMMENT 'Label72' ,
  253. Label73 string COMMENT 'Label73' ,
  254. Label74 string COMMENT 'Label74' ,
  255. Label75 string COMMENT 'Label75' ,
  256. Label76 string COMMENT 'Label76' ,
  257. Label77 string COMMENT 'Label77' ,
  258. Label78 string COMMENT 'Label78' ,
  259. Label79 string COMMENT 'Label79' ,
  260. Label80 string COMMENT 'Label80' ,
  261. Label81 string COMMENT 'Label81' ,
  262. Label82 string COMMENT 'Label82' ,
  263. Label83 string COMMENT 'Label83' ,
  264. Label84 string COMMENT 'Label84' ,
  265. Label85 string COMMENT 'Label85' ,
  266. Label86 string COMMENT 'Label86' ,
  267. Label87 string COMMENT 'Label87' ,
  268. Label88 string COMMENT 'Label88' ,
  269. Label89 string COMMENT 'Label89' ,
  270. Label90 string COMMENT 'Label90' ,
  271. Label91 string COMMENT 'Label91' ,
  272. Label92 string COMMENT 'Label92' ,
  273. Label93 string COMMENT 'Label93' ,
  274. Label94 string COMMENT 'Label94' ,
  275. Label95 string COMMENT 'Label95' ,
  276. Label96 string COMMENT 'Label96' ,
  277. Label97 string COMMENT 'Label97' ,
  278. Label98 string COMMENT 'Label98' ,
  279. Label99 string COMMENT 'Label99' ,
  280. Label100 string COMMENT 'Label100' ,
  281. Label101 string COMMENT 'Label101' ,
  282. Label102 string COMMENT 'Label102' ,
  283. Label103 string COMMENT 'Label103' ,
  284. Label104 string COMMENT 'Label104' ,
  285. Label105 string COMMENT 'Label105' ,
  286. Label106 string COMMENT 'Label106' ,
  287. Label107 string COMMENT 'Label107' ,
  288. Label108 string COMMENT 'Label108' ,
  289. Label109 string COMMENT 'Label109' ,
  290. Label110 string COMMENT 'Label110' ,
  291. Label111 string COMMENT 'Label111' ,
  292. Label112 string COMMENT 'Label112' ,
  293. Label113 string COMMENT 'Label113' ,
  294. Label114 string COMMENT 'Label114' ,
  295. Label115 string COMMENT 'Label115' ,
  296. Label116 string COMMENT 'Label116' ,
  297. Label117 string COMMENT 'Label117' ,
  298. Label118 string COMMENT 'Label118' ,
  299. Label119 string COMMENT 'Label119' ,
  300. Label120 string COMMENT 'Label120'
  301. )
  302. COMMENT '个人信息'
  303. STORED AS ES
  304. with shard number 10
  305. replication 1;
  306. ---------------------------------------------------------------------------------------、
  307. --创建 自增id
  308. --创建序列
  309. CREATE SEQUENCE globaleCusId_sequence
  310. INCREMENT BY 1
  311. START WITH 1
  312. NOMAXVALUE
  313. NOMINVALUE
  314. NOCYCLE
  315. CACHE 1;
  316. -----------------------------------------------------------------------------------
  317. -- 增量数据
  318. --------------------------------------------------------------------------------------------
  319. --创建存储过程 插入individual_search
  320. !set plsqlUseSlash true
  321. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  322. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  323. CREATE OR REPLACE PROCEDURE insertOrUpdate_individual() -- 创建存储过程
  324. IS
  325. DECLARE
  326. BEGIN
  327. MERGE INTO individual is1 using
  328. (
  329. SELECT scustid ,name,gender ,birthday, idcard
  330. FROM (
  331. SELECT
  332. customerno AS scustid,--投保人
  333. name AS name,
  334. sex AS gender,
  335. birthday AS birthday,
  336. idtype AS idtype ,
  337. idno AS idcard
  338. FROM
  339. policy_information
  340. WHERE customerno IS NOT NULL AND idtype=0
  341. UNION
  342. SELECT
  343. insuredno AS scustid,--被保人
  344. insuredname AS name,
  345. insuredsex AS gender,
  346. insuredbirthday AS birthday,
  347. insuredidtype AS idtype ,
  348. insuredidno AS idcard
  349. FROM
  350. policy_information
  351. WHERE insuredno IS NOT NULL AND insuredidtype=0
  352. ) tmpTable
  353. LIMIT IN 0,100000
  354. ) is2 on (is2.scustid = is1.scustid and is2.name = is1.name
  355. and is2.gender = is1.gender and is2.birthday = is1.birthday and is2.idcard = is1.idcard)
  356. WHEN NOT MATCHED THEN INSERT (
  357. scustid,
  358. name,
  359. gender,
  360. birthday,
  361. idcard,
  362. custid,
  363. indid,
  364. created_time,
  365. created_by
  366. ) VALUES (
  367. is2.scustid,
  368. is2.name,
  369. is2.gender,
  370. is2.birthday,
  371. is2.idcard,
  372. 'CP'||lpad(globaleCusId_sequence.nextval,10,'0'),
  373. globaleCusId_sequence.CURRVAL,
  374. sysdate,
  375. 'qxp'
  376. )
  377. EXCEPTION
  378. WHEN HIVE_EXCEPTION THEN
  379. log_exception('insertOrUpdate_individual',sqlerrm(),sqlcode())
  380. WHEN Others THEN
  381. log_exception('insertOrUpdate_individual',sqlerrm(),sqlcode())
  382. END;
  383. --------------------------------------------------------------------------------------------
  384. --------------------------------------------------------------------------------------------
  385. -------------------------------------------------------------------------------------------
  386. -------------------------------------------------------------------------------------------
  387. =============================================================================================================================================================
  388. ==============================================================利用行号全部插入用户数据==========================================================================
  389. =============================================================================================================================================================
  390. --初始化存储过程
  391. -- 身份证 0
  392. -- 护照 1
  393. -- 军人证(军官证) 2
  394. -- 驾照 3
  395. -- 户口本 4
  396. -- 学生证 5
  397. -- 工作证 6
  398. -- 出生证 7
  399. -- 其它 8
  400. -- 无证件 9
  401. -- 士兵证 A
  402. -- 回乡证 B
  403. -- 临时身份证 C
  404. -- 警官证 D
  405. -- 台胞证 E
  406. -- 港、澳通行证 F
  407. -- 外国人永久居留身份证 I
  408. -- 港澳台居民居住证 J
  409. -- 港澳居民居住证 K
  410. -- 台湾居民居住证 M
  411. DROP SEQUENCE IF EXISTS globaleCusId_sequence;
  412. !set plsqlUseSlash true
  413. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  414. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  415. CREATE OR REPLACE PROCEDURE init_individual_main() -- 初始化 数据全部插入
  416. IS
  417. DECLARE
  418. individual_count int
  419. strsql string
  420. BEGIN
  421. --先验是否一个客户id有多条记录对应不通的证件类别
  422. --初始化 身份证 用户
  423. init_individual_0(individual_count);
  424. --初始化 护照用户
  425. individual_count:=individual_count+1;
  426. init_individual_1(individual_count);
  427. --初始化 驾照用户
  428. individual_count:=individual_count+1;
  429. init_individual_3(individual_count);
  430. --其他 证件类型用户
  431. individual_count:=individual_count+1;
  432. init_individual_other(individual_count);
  433. --初始化 全局序列
  434. individual_count:=individual_count+1;
  435. strsql:='
  436. DROP SEQUENCE IF EXISTS globaleCusId_sequence;
  437. CREATE SEQUENCE globaleCusId_sequence
  438. INCREMENT BY 1
  439. START WITH '|| individual_count||'
  440. NOMAXVALUE
  441. NOMINVALUE
  442. NOCYCLE
  443. CACHE 1;
  444. ';
  445. EXECUTE IMMEDIATE strsql
  446. --更新用户等级信息
  447. up_t_customers_class_1();
  448. --更新职业信息
  449. up_health_insurance_listing_1();
  450. EXCEPTION
  451. WHEN HIVE_EXCEPTION THEN
  452. log_exception('init_individual_main',sqlerrm(),sqlcode())
  453. WHEN Others THEN
  454. log_exception('init_individual_main',sqlerrm(),sqlcode())
  455. END;
  456. !set plsqlUseSlash true
  457. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  458. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  459. CREATE OR REPLACE PROCEDURE init_individual_0( individual_count OUT int) -- 初始化 省份证
  460. IS
  461. BEGIN
  462. --查询出此次处理的数据并出表中
  463. insert into individual (
  464. indid,
  465. custid,
  466. scustid,
  467. name,
  468. gender,
  469. birthday,
  470. idcard,
  471. created_time,
  472. created_by
  473. )
  474. SELECT
  475. row_number()over(),
  476. 'CP'||lpad(row_number()over(),10,'0'),
  477. scustid ,
  478. name,
  479. gender ,
  480. birthday,
  481. idcard ,
  482. sysdate,
  483. 'qxp'
  484. FROM (
  485. SELECT
  486. customerno AS scustid,--投保人
  487. name AS name,
  488. sex AS gender,
  489. birthday AS birthday,
  490. idtype AS idtype ,
  491. idno AS idcard
  492. FROM
  493. policy_information
  494. WHERE customerno IS NOT NULL AND idtype=0
  495. UNION
  496. SELECT
  497. insuredno AS scustid,--被保人
  498. insuredname AS name,
  499. insuredsex AS gender,
  500. insuredbirthday AS birthday,
  501. insuredidtype AS idtype ,
  502. insuredidno AS idcard
  503. FROM
  504. policy_information
  505. WHERE insuredno IS NOT NULL AND insuredidtype=0
  506. ) tmpTable
  507. --已经存在的数据行数
  508. select count(0) into individual_count from individual
  509. EXCEPTION
  510. WHEN HIVE_EXCEPTION THEN
  511. log_exception('init_individual_0',sqlerrm(),sqlcode())
  512. WHEN Others THEN
  513. log_exception('init_individual_0',sqlerrm(),sqlcode())
  514. END;
  515. !set plsqlUseSlash true
  516. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  517. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  518. CREATE OR REPLACE PROCEDURE init_individual_1(individual_count INOUT int) -- 初始化 护照
  519. IS
  520. BEGIN
  521. --查询出此次处理的数据并出表中
  522. insert into individual (
  523. indid,
  524. custid,
  525. scustid,
  526. name,
  527. gender,
  528. birthday,
  529. passport,
  530. created_time,
  531. created_by
  532. )
  533. SELECT
  534. row_number()over()+individual_count,
  535. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  536. scustid ,
  537. name,
  538. gender ,
  539. birthday,
  540. idcard ,
  541. sysdate,
  542. 'qxp'
  543. FROM (
  544. SELECT
  545. customerno AS scustid,--投保人
  546. name AS name,
  547. sex AS gender,
  548. birthday AS birthday,
  549. idtype AS idtype ,
  550. idno AS idcard
  551. FROM
  552. policy_information
  553. WHERE customerno IS NOT NULL AND idtype=1
  554. UNION
  555. SELECT
  556. insuredno AS scustid,--被保人
  557. insuredname AS name,
  558. insuredsex AS gender,
  559. insuredbirthday AS birthday,
  560. insuredidtype AS idtype ,
  561. insuredidno AS idcard
  562. FROM
  563. policy_information
  564. WHERE insuredno IS NOT NULL AND insuredidtype=1
  565. ) tmpTable
  566. --已经存在的数据行数
  567. select count(0) into individual_count from individual
  568. EXCEPTION
  569. WHEN HIVE_EXCEPTION THEN
  570. log_exception('init_individual_1',sqlerrm(),sqlcode())
  571. WHEN Others THEN
  572. log_exception('init_individual_1',sqlerrm(),sqlcode())
  573. END;
  574. !set plsqlUseSlash true
  575. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  576. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  577. CREATE OR REPLACE PROCEDURE init_individual_3(individual_count INOUT int) -- 初始化 护照
  578. IS
  579. BEGIN
  580. --查询出此次处理的数据并出表中
  581. insert into individual(
  582. indid,
  583. custid,
  584. scustid,
  585. name,
  586. gender,
  587. birthday,
  588. dlicense,
  589. created_time,
  590. created_by
  591. )
  592. SELECT
  593. row_number()over()+individual_count,
  594. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  595. scustid ,
  596. name,
  597. gender ,
  598. birthday,
  599. idcard ,
  600. sysdate,
  601. 'qxp'
  602. FROM (
  603. SELECT
  604. customerno AS scustid,--投保人
  605. name AS name,
  606. sex AS gender,
  607. birthday AS birthday,
  608. idtype AS idtype ,
  609. idno AS idcard
  610. FROM
  611. policy_information
  612. WHERE customerno IS NOT NULL AND idtype=3
  613. UNION
  614. SELECT
  615. insuredno AS scustid,--被保人
  616. insuredname AS name,
  617. insuredsex AS gender,
  618. insuredbirthday AS birthday,
  619. insuredidtype AS idtype ,
  620. insuredidno AS idcard
  621. FROM
  622. policy_information
  623. WHERE insuredno IS NOT NULL AND insuredidtype=3
  624. ) tmpTable
  625. --已经存在的数据行数
  626. select count(0) into individual_count from individual
  627. EXCEPTION
  628. WHEN HIVE_EXCEPTION THEN
  629. log_exception('init_individual_3',sqlerrm(),sqlcode())
  630. WHEN Others THEN
  631. log_exception('init_individual_3',sqlerrm(),sqlcode())
  632. END;
  633. !set plsqlUseSlash true
  634. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  635. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  636. CREATE OR REPLACE PROCEDURE init_individual_other(individual_count INOUT int) -- 初始化 护照
  637. IS
  638. BEGIN
  639. --查询出此次处理的数据并出表中
  640. insert into individual(
  641. indid,
  642. custid,
  643. scustid,
  644. name,
  645. gender,
  646. birthday,
  647. created_time,
  648. created_by
  649. )
  650. SELECT
  651. row_number()over()+individual_count,
  652. 'CP'||lpad(row_number()over()+individual_count,10,'0'),
  653. scustid ,
  654. name,
  655. gender ,
  656. birthday,
  657. sysdate,
  658. 'qxp'
  659. FROM (
  660. SELECT
  661. customerno AS scustid,--投保人
  662. name AS name,
  663. sex AS gender,
  664. birthday AS birthday,
  665. idtype AS idtype ,
  666. idno AS idcard
  667. FROM
  668. policy_information
  669. WHERE customerno IS NOT NULL AND idtype not in (0,1,3)
  670. UNION
  671. SELECT
  672. insuredno AS scustid,--被保人
  673. insuredname AS name,
  674. insuredsex AS gender,
  675. insuredbirthday AS birthday,
  676. insuredidtype AS idtype ,
  677. insuredidno AS idcard
  678. FROM
  679. policy_information
  680. WHERE insuredno IS NOT NULL AND insuredidtype in (0,1,3)
  681. ) tmpTable
  682. --已经存在的数据行数
  683. select count(0) into individual_count from individual
  684. EXCEPTION
  685. WHEN HIVE_EXCEPTION THEN
  686. log_exception('init_individual_other',sqlerrm(),sqlcode())
  687. WHEN Others THEN
  688. log_exception('init_individual_other',sqlerrm(),sqlcode())
  689. END;
  690. --创建存储过程 插入individual_search
  691. !set plsqlUseSlash true
  692. SET plsql.catch.hive.exception=true; --使用HIVE_EXCEPTION捕获Hive异常
  693. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  694. CREATE OR REPLACE PROCEDURE up_t_customers_class_1() -- 创建存储过程
  695. IS
  696. BEGIN
  697. UPDATE individual a SET (
  698. CustClass ,-- 客户等级
  699. ConValue ,-- 贡献度分
  700. Awarded3 ,-- 家庭加分2
  701. Awarded2 ,-- 续期加分
  702. Awarded1 ,-- 保单加分
  703. SOValue ,-- 总分值
  704. EndDate -- 客户等级失效日期
  705. ) = (
  706. select
  707. CLASS_VALUE ,--客户等级
  708. CONTRIBUTION_VALUE ,--贡献度分
  709. AWARDED3, --家庭加分
  710. AWARDED2, --续期加分
  711. AWARDED1, --保单加分
  712. TOTAL_VALUE, --总分值
  713. END_DATE --失效日期
  714. from t_customer_class b
  715. where b.CUSTOMER_ID = a.scustid;
  716. ) WHERE 1=1 ;
  717. EXCEPTION
  718. WHEN HIVE_EXCEPTION THEN
  719. log_exception('up_t_customers_class_1',sqlerrm(),sqlcode())
  720. WHEN Others THEN
  721. log_exception('up_t_customers_class_1',sqlerrm(),sqlcode())
  722. END;
  723. /
  724. DROP TABLE IF EXISTS occupation_tmp;
  725. CREATE TABLE occupation_tmp(
  726. scustid string not NULL COMMENT '客户号',
  727. OccupationId string DEFAULT NULL COMMENT '名称',
  728. Occupation string DEFAULT NULL COMMENT '出生日期' ,
  729. HomeAdress string DEFAULT NULL COMMENT '籍贯'
  730. )
  731. COMMENT 'occupation_tmp 客户职业临时表' STORED AS ES
  732. with shard number 10
  733. replication 1;
  734. --根据HEALTH_INSURANCE_LISTING表更新
  735. CREATE OR REPLACE PROCEDURE up_health_insurance_listing_1() -- 创建存储过程
  736. IS
  737. BEGIN
  738. --清楚临时表数据
  739. delete occupation_tmp;
  740. --插入去重数据到临时表
  741. insert into occupation_tmp(
  742. scustid,
  743. OccupationId,
  744. Occupation,
  745. HomeAdress
  746. )
  747. select
  748. appntno,
  749. appntoccupationcode ,--职业代码
  750. appntoccupationname ,
  751. APPNTHOMEADDRESS--职业名称
  752. from HEALTH_INSURANCE_LISTING
  753. WHERE appntoccupationcode is not null
  754. and appntoccupationname is not null
  755. group by appntno,appntoccupationcode,appntoccupationname,APPNTHOMEADDRESS
  756. --更新个人信息表
  757. UPDATE individual a SET (
  758. OccupationId ,-- 职业代码
  759. Occupation, -- 职业名称
  760. HomeAdress
  761. ) = (
  762. select
  763. OccupationId ,--职业代码
  764. Occupation,--职业名称
  765. APPNTHOMEADDRESS
  766. from occupation_tmp b
  767. where b.scustid = a.scustid
  768. ) WHERE 1=1 ;
  769. EXCEPTION
  770. WHEN HIVE_EXCEPTION THEN
  771. log_exception('up_health_insurance_listing_1',sqlerrm(),sqlcode())
  772. WHEN Others THEN
  773. log_exception('up_health_insurance_listing_1',sqlerrm(),sqlcode())
  774. END;
  775. =======================================================================================================================================
  776. ===================================================用户关系信息解析插入====================================================================
  777. =======================================================================================================================================
  778. --更新individual 的用户关系
  779. CREATE OR REPLACE PROCEDURE up_individual_relationship() -- 创建存储过程
  780. IS
  781. BEGIN
  782. --清楚临时表数据
  783. EXCEPTION
  784. WHEN HIVE_EXCEPTION THEN
  785. log_exception('up_individual_relationship',sqlerrm(),sqlcode())
  786. WHEN Others THEN
  787. log_exception('up_individual_relationship',sqlerrm(),sqlcode())
  788. END;
  789. =======================================================================================================================================
  790. ===================================================用户上游客户ID去重临时表====================================================================
  791. =======================================================================================================================================
  792. DROP TABLE IF EXISTS scustid_unique_tmp;
  793. CREATE TABLE scustid_unique_tmp(
  794. scustid string COMMENT '上游客户号' ,
  795. indid string COMMENT '客户号'
  796. )
  797. COMMENT '用户上游客户ID去重临时表'
  798. STORED AS ES
  799. with shard number 10
  800. replication 1;
  801. --更新individual 的用户关系
  802. CREATE OR REPLACE PROCEDURE up_scustid_unique_tmp() -- 创建存储过程
  803. IS
  804. BEGIN
  805. --清楚临时表数据
  806. delete from scustid_unique_tmp;
  807. --插入临时表数据
  808. insert into scustid_unique_tmp(scustid,indid)
  809. select scustid,min(indid) from individual_search1 group by scustid;
  810. EXCEPTION
  811. WHEN HIVE_EXCEPTION THEN
  812. log_exception('up_scustid_unique_tmp',sqlerrm(),sqlcode())
  813. WHEN Others THEN
  814. log_exception('up_scustid_unique_tmp',sqlerrm(),sqlcode())
  815. END;
  816. =====================================================================================================================
  817. 1,105,462 ---581292 插入投保
  818. 1,105,500 ---578591 插入被保人
  819. 1,119,154 ---156901 插入UNION
  820. 1,119,154 ---row_number()over(), 使用row_number()over() 329312
  821. row_number()over() 行号