参与方事件.sql 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. CREATE TABLE shanghailifeecif.edorinfo(
  2. contno string DEFAULT NULL COMMENT '保单号',
  3. edortype string DEFAULT NULL COMMENT '管理机构',
  4. lppostaladdress string DEFAULT NULL COMMENT '原客户地址',
  5. lcpostaladdress string DEFAULT NULL COMMENT '现客户地址',
  6. lpmobile string DEFAULT NULL COMMENT '原手机号',
  7. lcmobile string DEFAULT NULL COMMENT '现手机号 ',
  8. lpidtype string DEFAULT NULL COMMENT '原证件类型',
  9. lcidtype string DEFAULT NULL COMMENT '现证件类型 ',
  10. lpidno string DEFAULT NULL COMMENT '原证件号码',
  11. lcidno string DEFAULT NULL COMMENT '现证件号码 ',
  12. EDORAPPDATE string DEFAULT NULL COMMENT '保全申请日期',
  13. EDORCVALIDATE string DEFAULT NULL COMMENT '保全生效日期 '
  14. )
  15. COMMENT '保全'
  16. STORED AS csvfile;
  17. CREATE TABLE shanghailifeecif.audit_edorlist(
  18. managecom varchar2(200) DEFAULT NULL COMMENT '管理机构', -- dialect: ORACLE
  19. managename varchar2(200) DEFAULT NULL COMMENT '管理机构名称', -- dialect: ORACLE
  20. salechnl varchar2(200) DEFAULT NULL COMMENT '销售渠道', -- dialect: ORACLE
  21. salechnlname varchar2(64) DEFAULT NULL COMMENT '销售渠道名称', -- dialect: ORACLE
  22. selltype varchar2(64) DEFAULT NULL COMMENT '合作渠道代码', -- dialect: ORACLE
  23. selltypename varchar2(64) DEFAULT NULL COMMENT '合作渠道名称', -- dialect: ORACLE
  24. contno varchar2(200) DEFAULT NULL COMMENT '保单号', -- dialect: ORACLE
  25. riskcodes varchar2(200) DEFAULT NULL COMMENT '险种代码', -- dialect: ORACLE
  26. risknames varchar2(200) DEFAULT NULL COMMENT '险种名称', -- dialect: ORACLE
  27. risktypes varchar2(64) DEFAULT NULL COMMENT '险种类型', -- dialect: ORACLE
  28. signdate timestamp DEFAULT NULL COMMENT '承保日期',
  29. appntname varchar2(200) DEFAULT NULL COMMENT '投保人', -- dialect: ORACLE
  30. prem decimal(10,2) DEFAULT NULL COMMENT '保费',
  31. edorname varchar2(256) DEFAULT NULL COMMENT '保全类型', -- dialect: ORACLE
  32. edoracceptno varchar2(256) DEFAULT NULL COMMENT '保全受理号', -- dialect: ORACLE
  33. edorno varchar2(256) DEFAULT NULL COMMENT '批单号', -- dialect: ORACLE
  34. edorvalidate timestamp DEFAULT NULL COMMENT '保全生效日期',
  35. customerhandleflag varchar2(64) DEFAULT NULL COMMENT '是否亲办', -- dialect: ORACLE
  36. operator varchar2(256) DEFAULT NULL COMMENT '操作人', -- dialect: ORACLE
  37. approveoperator varchar2(256) DEFAULT NULL COMMENT '审批人', -- dialect: ORACLE
  38. getmoney decimal(10,2) DEFAULT NULL COMMENT '保全退补费金额',
  39. cusappdate timestamp DEFAULT NULL COMMENT '客户申请日期',
  40. payyears varchar2(64) DEFAULT NULL COMMENT '缴费年期', -- dialect: ORACLE
  41. agentname varchar2(256) DEFAULT NULL COMMENT '代理人姓名', -- dialect: ORACLE
  42. edorstate varchar2(64) DEFAULT NULL COMMENT '保全状态', -- dialect: ORACLE
  43. ins_time timestamp DEFAULT NULL
  44. )
  45. COMMENT '保全清单';
  46. ======================================================================
  47. =================================目的表结构=================================
  48. ======================================================================
  49. CREATE TABLE PartyTimeLine(
  50. TripID string NOT NULL COMMENT '旅程ID' ,
  51. PartyID string NOT NULL COMMENT '参与方ID' ,
  52. Name string COMMENT '参与方名称' ,
  53. PCertID string COMMENT '参与方证件号码' ,
  54. PPhone string COMMENT '参与方手机' ,
  55. PRole string COMMENT '参与方角色 投保人、被保人、受益人' ,
  56. Scenario string COMMENT '场景 投保 保全 报案 咨询 投诉 其他' ,
  57. SDate DATE COMMENT '发生日期' ,
  58. ThreadID string COMMENT '关联ID 可关联至更详细信息,如保单ID、报案ID等' ,
  59. ParentID string COMMENT '父ID 如报案对应的保单ID' ,
  60. Describe string COMMENT '描述' ,
  61. Channel string COMMENT '来源' ,
  62. EndDate DATE COMMENT '完成日期' ,
  63. CREATED_BY string COMMENT '创建人' ,
  64. CREATED_TIME DATE COMMENT '创建时间' ,
  65. UPDATED_BY string COMMENT '更新人' ,
  66. UPDATED_TIME DATE COMMENT '更新时间'
  67. ) COMMENT '参与方事件 '
  68. STORED AS ES
  69. with shard number 10
  70. replication 1;
  71. ==================================================初始化数据====================================================================
  72. DROP SEQUENCE IF EXISTS globaleTripID_sequence;
  73. CREATE OR REPLACE PROCEDURE init_partytimeline_main() -- 创建主存储过程
  74. IS
  75. DECLARE
  76. partytimeline_count int
  77. strsql string
  78. BEGIN
  79. --1.从保全清单表中初始化 参与事件
  80. select count(0) into partytimeline_count from PartyTimeLine;
  81. partytimeline_count:=partytimeline_count+1;
  82. DBMS_OUTPUT.PUT_LINE(partytimeline_count);
  83. init_insuranceclaimthread_edorlist(partytimeline_count)
  84. --2.从保全表中初始化 参与事件
  85. select count(0) into partytimeline_count from PartyTimeLine;
  86. partytimeline_count:=partytimeline_count+1;
  87. DBMS_OUTPUT.PUT_LINE(partytimeline_count);
  88. init_insuranceclaimthread_edorinfo(partytimeline_count)
  89. -- 3.初始化理赔相关信息
  90. select count(0) into partytimeline_count from PartyTimeLine;
  91. partytimeline_count:=partytimeline_count+1;
  92. DBMS_OUTPUT.PUT_LINE(partytimeline_count);
  93. init_insuranceclaimthread_insuranceclaimthread(partytimeline_count)
  94. -- 4.初始化投保赔相关信息
  95. select count(0) into partytimeline_count from PartyTimeLine;
  96. partytimeline_count:=partytimeline_count+1;
  97. DBMS_OUTPUT.PUT_LINE(partytimeline_count);
  98. init_insuranceclaimthread_InsuranceArrangement(partytimeline_count)
  99. partytimeline_count:=partytimeline_count+1;
  100. DBMS_OUTPUT.PUT_LINE(partytimeline_count);
  101. -- 用于以后更新时是用的序列
  102. strsql:='
  103. CREATE SEQUENCE globaleTripID_sequence
  104. INCREMENT BY 1
  105. START WITH '|| partytimeline_count||'
  106. NOMAXVALUE
  107. NOMINVALUE
  108. NOCYCLE
  109. CACHE 1;
  110. '
  111. EXECUTE IMMEDIATE strsql
  112. EXCEPTION
  113. WHEN HIVE_EXCEPTION THEN
  114. log_exception('init_partytimeline_main',sqlerrm(),sqlcode())
  115. WHEN Others THEN
  116. log_exception('init_partytimeline_main',sqlerrm(),sqlcode())
  117. END;
  118. /*audit_edorlist 表
  119. managecom varchar2(200) DEFAULT NULL COMMENT '管理机构', -- dialect: ORACLE
  120. managename varchar2(200) DEFAULT NULL COMMENT '管理机构名称', -- dialect: ORACLE
  121. salechnl varchar2(200) DEFAULT NULL COMMENT '销售渠道', -- dialect: ORACLE
  122. salechnlname varchar2(64) DEFAULT NULL COMMENT '销售渠道名称', -- dialect: ORACLE
  123. selltype varchar2(64) DEFAULT NULL COMMENT '合作渠道代码', -- dialect: ORACLE
  124. selltypename varchar2(64) DEFAULT NULL COMMENT '合作渠道名称', -- dialect: ORACLE
  125. contno varchar2(200) DEFAULT NULL COMMENT '保单号', -- dialect: ORACLE
  126. riskcodes varchar2(200) DEFAULT NULL COMMENT '险种代码', -- dialect: ORACLE
  127. risknames varchar2(200) DEFAULT NULL COMMENT '险种名称', -- dialect: ORACLE
  128. risktypes varchar2(64) DEFAULT NULL COMMENT '险种类型', -- dialect: ORACLE
  129. signdate timestamp DEFAULT NULL COMMENT '承保日期',
  130. appntname varchar2(200) DEFAULT NULL COMMENT '投保人', -- dialect: ORACLE
  131. prem decimal(10,2) DEFAULT NULL COMMENT '保费',
  132. edorname varchar2(256) DEFAULT NULL COMMENT '保全类型', -- dialect: ORACLE
  133. edoracceptno varchar2(256) DEFAULT NULL COMMENT '保全受理号', -- dialect: ORACLE
  134. edorno varchar2(256) DEFAULT NULL COMMENT '批单号', -- dialect: ORACLE
  135. edorvalidate timestamp DEFAULT NULL COMMENT '保全生效日期',
  136. customerhandleflag varchar2(64) DEFAULT NULL COMMENT '是否亲办', -- dialect: ORACLE
  137. operator varchar2(256) DEFAULT NULL COMMENT '操作人', -- dialect: ORACLE
  138. approveoperator varchar2(256) DEFAULT NULL COMMENT '审批人', -- dialect: ORACLE
  139. getmoney decimal(10,2) DEFAULT NULL COMMENT '保全退补费金额',
  140. cusappdate timestamp DEFAULT NULL COMMENT '客户申请日期',
  141. payyears varchar2(64) DEFAULT NULL COMMENT '缴费年期', -- dialect: ORACLE
  142. agentname varchar2(256) DEFAULT NULL COMMENT '代理人姓名', -- dialect: ORACLE
  143. edorstate varchar2(64) DEFAULT NULL COMMENT '保全状态', -- dialect: ORACLE
  144. ins_time timestamp DEFAULT NULL
  145. */
  146. CREATE TABLE PartyTimeLine_edor_tmp(
  147. id string,
  148. contno string comment '保单号',
  149. PartyID string COMMENT '参与方ID' ,
  150. appntname string COMMENT '参与方名称' ,
  151. PCertID string COMMENT '参与方证件号码' ,
  152. PPhone string COMMENT '参与方手机' ,
  153. cusappdate DATE COMMENT '客户申请日期' ,
  154. edoracceptno string COMMENT '保全受理号' ,
  155. edorvalidate DATE COMMENT '保全生效日期'
  156. ) COMMENT '参与方保全事件临时表 '
  157. STORED AS ES
  158. with shard number 10
  159. replication 1;
  160. !set plsqlUseSlash true
  161. SET plsql.catch.hive.exception=true;
  162. --set plsql.compile.dml.check.semantic=false; --禁止编译过程对PL/SQL内部语法进行检查。
  163. CREATE OR REPLACE PROCEDURE init_insuranceclaimthread_edorlist(partytimeline_count OUT int)
  164. IS
  165. BEGIN
  166. --初始化临时表
  167. delete from PartyTimeLine_edor_tmp;
  168. insert into PartyTimeLine_edor_tmp(
  169. id,
  170. contno,
  171. appntname,
  172. cusappdate,
  173. edoracceptno,
  174. edorvalidate
  175. )
  176. SELECT
  177. row_number()over(),
  178. contno,
  179. appntname,
  180. cusappdate,
  181. edoracceptno,
  182. edorvalidate
  183. from shanghailifeecif.audit_edorlist;
  184. --更新临时表信息
  185. UPDATE PartyTimeLine_edor_tmp a SET (
  186. PartyID ,-- 参与方ID
  187. PCertID ,-- 参与方证件号码
  188. PPhone
  189. ) = (
  190. select
  191. ApplicantID ,
  192. AppCertID ,
  193. AppPhone
  194. from shanglifeecif.InsuranceArrangement b
  195. where b.PolicyNo = a.contno
  196. ) WHERE 1=1 ;
  197. --更新参与方事件表
  198. insert into PartyTimeLine(
  199. TripID,
  200. PartyID, --参与方id
  201. Name,
  202. PCertID,
  203. PPhone,
  204. PRole,
  205. Scenario,
  206. SDate,
  207. ThreadID,
  208. ParentID,
  209. EndDate,
  210. CREATED_BY,
  211. CREATED_TIME
  212. )
  213. SELECT
  214. row_number()over(),
  215. PartyID,
  216. appntname,
  217. PCertID,
  218. PPhone,
  219. '投保人',
  220. '保全',
  221. cusappdate,
  222. edoracceptno,
  223. contno,
  224. edorvalidate,
  225. 'admin',
  226. sysdate
  227. from PartyTimeLine_edor_tmp where PartyID is not null;
  228. --已经存在的数据行数
  229. select count(0) into partytimeline_count from PartyTimeLine
  230. EXCEPTION
  231. WHEN HIVE_EXCEPTION THEN
  232. log_exception('init_insuranceclaimthread_edorlist',sqlerrm(),sqlcode())
  233. WHEN Others THEN
  234. log_exception('init_insuranceclaimthread_edorlist',sqlerrm(),sqlcode())
  235. END;
  236. =============================================================================================================================================================
  237. ============================================================根据edorinfo更新========================================================================================
  238. ==========================================================================================================================================================
  239. --------------------------------根据edorinfo更新 保全----------------------------------------
  240. /*
  241. contno string DEFAULT NULL COMMENT '保单号',
  242. edortype string DEFAULT NULL COMMENT '管理机构',
  243. lppostaladdress string DEFAULT NULL COMMENT '原客户地址',
  244. lcpostaladdress string DEFAULT NULL COMMENT '现客户地址',
  245. lpmobile string DEFAULT NULL COMMENT '原手机号',
  246. lcmobile string DEFAULT NULL COMMENT '现手机号 ',
  247. lpidtype string DEFAULT NULL COMMENT '原证件类型',
  248. lcidtype string DEFAULT NULL COMMENT '现证件类型 ',
  249. lpidno string DEFAULT NULL COMMENT '原证件号码',
  250. lcidno string DEFAULT NULL COMMENT '现证件号码 ',
  251. EDORAPPDATE string DEFAULT NULL COMMENT '保全申请日期',
  252. EDORCVALIDATE string DEFAULT NULL COMMENT '保全生效日期 '
  253. */
  254. CREATE OR REPLACE PROCEDURE init_insuranceclaimthread_edorinfo(partytimeline_count OUT int)
  255. IS
  256. BEGIN
  257. --初始化临时表
  258. delete from PartyTimeLine_edor_tmp;
  259. insert into PartyTimeLine_edor_tmp(
  260. id,
  261. contno,
  262. PPhone,
  263. PCertID,
  264. edoracceptno ,
  265. edorvalidate
  266. )
  267. SELECT
  268. row_number()over(),
  269. contno,
  270. lcmobile,
  271. lcidno,
  272. EDORAPPDATE,
  273. EDORCVALIDATE
  274. from shanghailifeecif.edorinfo;
  275. --更新临时表信息
  276. UPDATE PartyTimeLine_edor_tmp a SET (
  277. PartyID ,-- 参与方ID
  278. appntname
  279. ) = (
  280. select
  281. ApplicantID ,
  282. appname--投保人名称
  283. from shanglifeecif.InsuranceArrangement b
  284. where b.PolicyNo = a.contno
  285. ) WHERE 1=1 ;
  286. --更新参与方事件表
  287. insert into PartyTimeLine(
  288. TripID,
  289. PartyID, --参与方id
  290. Name,
  291. PCertID,
  292. PPhone,
  293. PRole,
  294. Scenario,
  295. SDate,
  296. ThreadID,
  297. ParentID,
  298. EndDate,
  299. CREATED_BY,
  300. CREATED_TIME
  301. )
  302. SELECT
  303. row_number()over() +partytimeline_count,
  304. PartyID,
  305. appntname,
  306. PCertID,
  307. PPhone,
  308. '投保人',
  309. '保全',
  310. cusappdate,
  311. edoracceptno,
  312. contno,
  313. edorvalidate,
  314. 'admin',
  315. sysdate
  316. from PartyTimeLine_edor_tmp where PartyID is not null;
  317. --已经存在的数据行数
  318. select count(0) into partytimeline_count from PartyTimeLine
  319. EXCEPTION
  320. WHEN HIVE_EXCEPTION THEN
  321. log_exception('init_insuranceclaimthread_edorinfo',sqlerrm(),sqlcode())
  322. WHEN Others THEN
  323. log_exception('init_insuranceclaimthread_edorinfo',sqlerrm(),sqlcode())
  324. END;
  325. =============================================================================================================================================================
  326. ============================================================根据insuranceclaimthread更新理赔========================================================================================
  327. ==========================================================================================================================================================
  328. CREATE OR REPLACE PROCEDURE init_insuranceclaimthread_insuranceclaimthread(partytimeline_count OUT int)
  329. IS
  330. BEGIN
  331. --初始化临时表、
  332. insert into PartyTimeLine(
  333. TripID,
  334. PartyID, --参与方id
  335. Name,
  336. PCertID,
  337. PPhone,
  338. PRole,
  339. Scenario,
  340. SDate,
  341. ThreadID,
  342. ParentID,
  343. EndDate,
  344. CREATED_BY,
  345. CREATED_TIME
  346. )
  347. SELECT
  348. row_number()over() +partytimeline_count,
  349. applicantid,
  350. appname,
  351. appcertid,
  352. appphone,
  353. '投保人',
  354. '报案',
  355. crdate,
  356. icthreadid,
  357. policyno,
  358. csdate,
  359. 'admin',
  360. sysdate
  361. from qxp.insuranceclaimthread where applicantid is not null;
  362. --已经存在的数据行数
  363. select count(0) into partytimeline_count from PartyTimeLine;
  364. EXCEPTION
  365. WHEN HIVE_EXCEPTION THEN
  366. log_exception('init_insuranceclaimthread_insuranceclaimthread',sqlerrm(),sqlcode())
  367. WHEN Others THEN
  368. log_exception('init_insuranceclaimthread_insuranceclaimthread',sqlerrm(),sqlcode())
  369. END;
  370. =============================================================================================================================================================
  371. ============================================================根据InsuranceArrangement更新投保========================================================================================
  372. ==========================================================================================================================================================
  373. CREATE OR REPLACE PROCEDURE init_insuranceclaimthread_InsuranceArrangement(partytimeline_count OUT int)
  374. IS
  375. BEGIN
  376. --初始化临时表、
  377. insert into PartyTimeLine(
  378. TripID,
  379. PartyID, --参与方id
  380. Name,
  381. PCertID,
  382. PPhone,
  383. PRole,
  384. Scenario,
  385. SDate,
  386. ThreadID,
  387. ParentID,
  388. EndDate,
  389. CREATED_BY,
  390. CREATED_TIME
  391. )
  392. SELECT
  393. row_number()over() +partytimeline_count,
  394. applicantid,
  395. appname,
  396. appcertid,
  397. appphone,
  398. '投保人',
  399. '投保',
  400. PADate,
  401. PANo,
  402. PolicyNo,
  403. PMDate ,
  404. 'admin',
  405. sysdate
  406. from shanglifeecif.InsuranceArrangement where applicantid is not null;
  407. --已经存在的数据行数
  408. select count(0) into partytimeline_count from PartyTimeLine
  409. EXCEPTION
  410. WHEN HIVE_EXCEPTION THEN
  411. log_exception('init_insuranceclaimthread_InsuranceArrangement',sqlerrm(),sqlcode())
  412. WHEN Others THEN
  413. log_exception('init_insuranceclaimthread_InsuranceArrangement',sqlerrm(),sqlcode())
  414. END;
  415. ================================================数据解析============================================================================================
  416. --保全号是唯一的 是不重复的
  417. --从 audit_edorlist 的表中插入的数据为 619006
  418. --有1060个数据 因为查不到保单无法进入数据库
  419. --带edorinfo 一共插入 619685
  420. --带理赔和保单一共插入 2086136 保单总数 1520720
  421. SELECT count(1) FROM audit_edorlist ; --620066
  422. SELECT count(1) FROM (
  423. SELECT contno FROM audit_edorlist GROUP BY contno
  424. ); --根据保单 去重550805
  425. SELECT count(1) FROM (
  426. SELECT contno,cusappdate FROM audit_edorlist GROUP BY contno,cusappdate
  427. );--根据保单和申请时间 去重 591350
  428. SELECT count(1) a,contno FROM audit_edorlist GROUP BY contno,cusappdate ORDER BY a DESC;
  429. --查询重复最多的数据
  430. SELECT * FROM audit_edorlist WHERE contno = '2018020800060078';
  431. SELECT count(1) FROM PartyTimeLine WHERE scenario = "保全" ; --619713
  432. SELECT count(1) FROM PartyTimeLine WHERE Scenario ='投保' ; --1466423
  433. SELECT count(1) FROM PartyTimeLine WHERE Scenario ='报案' ; --11490
  434. SELECT count(1) FROM PartyTimeLine; --2097626
  435. SELECT count(1) FROM shanglifeecif.InsuranceArrangement; --1520720
  436. SELECT count(1) FROM shanglifeecif.insuranceclaimthread; --13957
  437. --