保单信息.sql 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. CREATE OR REPLACE PROCEDURE shanglifeecif.init_insurancearrangement_main() -- 创建主存储过程
  2. IS
  3. BEGIN
  4. DELETE FROM shanglifeecif.insurancearrangement;
  5. --根据policy_information 更新保单表
  6. shanglifeecif.init_insurancearrangement_policy_information();
  7. --其他标的字段 更新
  8. shanglifeecif.update_risk_categories();
  9. END;
  10. /
  11. CREATE OR REPLACE PROCEDURE shanglifeecif.init_insurancearrangement_policy_information() -- 创建主存储过程
  12. IS
  13. BEGIN
  14. INSERT INTO shanglifeecif.insurancearrangement(
  15. iaid ,--'保单ID',
  16. policyno ,-- '保险单号 INSURANCEINFO.CONTNO',
  17. pindate ,-- '起保日期 POLICY_INFORMATION.CVALIDATE',
  18. pmdate ,-- '终保日期 POLICY_INFORMATION.ENDDATE',
  19. norenewal ,-- '续保次数 POLICY_INFORMATION.PAYCOUNT',
  20. payment ,-- '缴费方式 POLICY_INFORMATION.PAYINTV',
  21. applicantscustid ,-- '投保人 上游客户号,再找到individualid',
  22. appname ,-- '投保人名称 POLICY_INFORMATION.NAME',
  23. appcertid ,-- '投保人证件号码 POLICY_INFORMATION.IDNO',
  24. insuredscustid ,-- '主被保险人 游客户号',
  25. insname ,-- '主被保险人名称 POLICY_INFORMATION.INSUREDNAME',
  26. inscertid ,-- '主被保险人证件号码 POLICY_INFORMATION.INSUREDIDNO',
  27. productid ,-- '险种代码 POLICY_INFORMATION.RISKCODE',
  28. productname,--险种名称
  29. policybelong ,-- '业绩归属 POLICY_INFORMATION.SALECOM',
  30. payendyear ,-- '缴费年期 POLICY_INFORMATION.PAYENDYEAR',
  31. policystate,--保单状态
  32. prem,--保费
  33. sumprem, --累计保费,
  34. Risk,--保额
  35. NPDate,--下次缴费日期
  36. PADate,--投保日期
  37. pisdate,--签单日期
  38. AgentOrg,--代理机构
  39. schannel,--销售渠道
  40. schannelname,--销售渠道中文
  41. salecomname,--业绩归属中文
  42. POService,--保全标志
  43. PWComp,--承保分公司
  44. security ,--保险期原始值
  45. agrmntage ,--保险期限
  46. salesperson,--业务员标识代码
  47. SPName,--业务员名称
  48. renewalDate,--续保日期
  49. created_by ,-- '创建人',
  50. created_time -- '创建时间',
  51. )
  52. SELECT
  53. row_number()over(),
  54. trim(CONTNO) as CONTNO,--policyno ,-- '保险单号 INSURANCEINFO.CONTNO',
  55. trim(CVALIDATE) as CVALIDATE,--pindate ,-- '起保日期 POLICY_INFORMATION.CVALIDATE',
  56. trim(ENDDATE) as ENDDATE,--pmdate ,-- '终保日期 POLICY_INFORMATION.ENDDATE',
  57. PAYCOUNT,--norenewal ,-- '续保次数 POLICY_INFORMATION.PAYCOUNT',
  58. trim(PAYINTV) as PAYINTV,--payment ,-- '缴费方式 POLICY_INFORMATION.PAYINTV',
  59. trim(CUSTOMERNO) as CUSTOMERNO,--applicantid ,-- '投保人 根据POLICY_INFORMATION.CUSTOMERNO关联individual上游客户号,再找到individualid',
  60. trim(NAME) as NAME,--appname ,-- '投保人名称 POLICY_INFORMATION.NAME',
  61. trim(IDNO) as IDNO,--appcertid ,-- '投保人证件号码 POLICY_INFORMATION.IDNO',
  62. trim(insuredno) as insuredno,--insuredid ,-- '主被保险人 insuredno',
  63. trim(INSUREDNAME) as INSUREDNAME,--insname ,-- '主被保险人名称 POLICY_INFORMATION.INSUREDNAME',
  64. trim(INSUREDIDNO) as INSUREDIDNO,--inscertid ,-- '主被保险人证件号码 POLICY_INFORMATION.INSUREDIDNO',
  65. trim(RISKCODE) as RISKCODE,--productid ,-- '险种代码 POLICY_INFORMATION.RISKCODE',
  66. trim(RISKNAME) as RISKNAME, --productname 险种名称
  67. trim(SALECOM) as SALECOM,--policybelong ,-- '业绩归属 POLICY_INFORMATION.SALECOM',
  68. PAYENDYEAR,--payendyear ,-- '缴费年期 POLICY_INFORMATION.PAYENDYEAR',
  69. trim(APPFLAG) as APPFLAG, --保单状态
  70. prem,--保费
  71. sumprem,--累计保费
  72. AMNT,--保额
  73. trim(PAYTODATE) as PAYTODATE,--下次缴费日期
  74. trim(polapplydate) as polapplydate,--投保日期
  75. trim(SIGNDATE) as SIGNDATE,--签单日期
  76. trim(AGENTCOM) as AGENTCOM,--代理机构
  77. trim(SALECHNL) as SALECHNL,--销售渠道
  78. trim(SALECHNLNAME) as SALECHNLNAME,--销售渠道中文
  79. trim(salecomname) as salecomname,--业绩归属中文
  80. trim(PRESERVATIONFLAG) as PRESERVATIONFLAG,--保全标志
  81. "上海人寿上海分公司",
  82. trim(security) as security, --保险期原始值
  83. case
  84. when security ='终身' then 42720
  85. when security = '至100周岁' then 36500
  86. when security = '至80周岁' then 29200
  87. when security = '70年' then 25550
  88. when security = '至70周岁' then 25550
  89. when security = '至65周岁' then 23725
  90. when security = '至60周岁' then 21900
  91. when security = '30年' then 10950
  92. when security = '20年' then 7300
  93. when security = '10年' then 3650
  94. when security = '6年' then 2190
  95. when security = '5年' then 1825
  96. when security = '1年' then 365
  97. when security = '180天' then 180
  98. when security = '6月' then 180
  99. when security = '90天' then 90
  100. when security = '3月' then 90
  101. when security = '1月' then 30
  102. when security = '30天' then 30
  103. when security = '15天' then 15
  104. when security = '7天' then 7
  105. end,
  106. trim(AGENTCODE) as AGENTCODE,--代理人代码
  107. trim(AGENTNAME) as AGENTNAME,--代理人名称
  108. trim(paytodate) as paytodate,--续保日期
  109. 'admin',
  110. sysdate()
  111. FROM policy_information;
  112. --更新INSURANCEINFO 表中的信息
  113. UPDATE shanglifeecif.insurancearrangement a SET (
  114. pano ,-- '投保单号 INSURANCEINFO.PRTNO',
  115. --pisdate ,-- '签单日期 INSURANCEINFO.SIGNDATE',
  116. --padate ,-- '投保日期 INSURANCEINFO.POLAPPLYDATE',
  117. --policystate ,--INSURANCEINFO,appflag
  118. --prem ,-- '总保费 INSURANCEINFO.PREM',
  119. --productname ,-- '险种名称 INSURANCEINFO.RISKNAME'
  120. agentchannel -- '代理渠道 INSURANCEINFO.SELLTYPE',
  121. ) = (
  122. select
  123. trim(b.PRTNO) as PRTNO,--pano ,-- '投保单号 INSURANCEINFO.PRTNO',
  124. --SIGNDATE,--pisdate ,-- '签单日期 INSURANCEINFO.SIGNDATE',
  125. --POLAPPLYDATE,--padate ,-- '投保日期 INSURANCEINFO.POLAPPLYDATE',
  126. --appflag,--policystate ,--INSURANCEINFO,appflag
  127. --PREM,--prem ,-- '总保费 INSURANCEINFO.PREM',
  128. --RISKNAME,--productname ,-- '险种名称 INSURANCEINFO.RISKNAME'
  129. trim(b.SELLTYPE) as SELLTYPE--agentchannel ,-- '代理渠道 INSURANCEINFO.SELLTYPE',
  130. from INSURANCEINFO b
  131. where b.contno = a.policyno
  132. ) WHERE 1=1 ;
  133. EXCEPTION
  134. WHEN HIVE_EXCEPTION THEN
  135. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  136. WHEN Others THEN
  137. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  138. END;
  139. /
  140. CREATE OR REPLACE PROCEDURE shanglifeecif.update_risk_categories() -- 创建主存储过程
  141. IS
  142. BEGIN
  143. --更新险种大类
  144. UPDATE shanglifeecif.insurancearrangement a SET (
  145. risk_categories_name
  146. ) = (
  147. select
  148. kindtype
  149. from riskkind b WHERE a.productid = b.riskcode
  150. ) WHERE 1=1;
  151. EXCEPTION
  152. WHEN HIVE_EXCEPTION THEN
  153. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  154. WHEN Others THEN
  155. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  156. END;
  157. /
  158. 万能保险总保额,总客户数,拥有3-5保单数量的客户数
  159. /*
  160. CREATE OR REPLACE PROCEDURE shanglifeecif.update_risk_categories() -- 创建主存储过程
  161. IS
  162. BEGIN
  163. --更新险种大类
  164. UPDATE shanglifeecif.insurancearrangement a SET (
  165. risk_categories,
  166. risk_categories_name
  167. ) = (
  168. select
  169. b.kindcode,
  170. (CASE b.kindcode
  171. WHEN 'A' THEN '意外伤害险'
  172. WHEN 'U' THEN '万能保险'
  173. WHEN 'R' THEN '年金保险'
  174. WHEN 'S' THEN '重疾保险'
  175. WHEN 'L' THEN '人寿保险'
  176. WHEN 'H' THEN '健康险'
  177. END) AS kindname
  178. from lmriskapp b WHERE a.productid = b.riskcode
  179. ) WHERE 1=1;
  180. EXCEPTION
  181. WHEN HIVE_EXCEPTION THEN
  182. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  183. WHEN Others THEN
  184. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  185. END;
  186. DROP TABLE IF EXISTS shanglifeecif.insurancearrangement_health_tmp;
  187. CREATE TABLE shanglifeecif.insurancearrangement_health_tmp(
  188. id string,
  189. orderid string DEFAULT NULL COMMENT '用于分组的排序号',
  190. contno string DEFAULT NULL COMMENT '保单号',
  191. AGENTGROUP string DEFAULT NULL COMMENT '承保分公司',--pwcomp ,-- '承保分公司 HEALTH_INSURANCE_LISTING.AGENTGROUPAREA 营业区HEALTH_INSURANCE_LISTING.AGENTGROUP 营业部',
  192. SALECHANNELS string DEFAULT NULL COMMENT '销售渠道',--schannel ,-- '销售渠道 HEALTH_INSURANCE_LISTING.SALECHANNELS 1 2 3 4 5',
  193. AMNT string DEFAULT NULL COMMENT '总保额',--risk ,-- '总保额 HEALTH_INSURANCE_LISTING.AMNT(测试环境中,此表保单数据量较其他表如:POLICY_INFORMATION,INSURANCEINFO 缺少至少一个数据量级)',
  194. AGENTCODE string DEFAULT NULL COMMENT'业务员名称'--spname ,-- '业务员名称 HEALTH_INSURANCE_LISTING.AGENTCODE',
  195. ) COMMENT '保单处理个险承保清单自助分析 数据临时表 '
  196. STORED AS ES
  197. with shard number 10
  198. replication 1;
  199. CREATE OR REPLACE PROCEDURE shanglifeecif.up_insurancearrangement_health_insurance_listing() -- 创建主存储过程
  200. IS
  201. BEGIN
  202. --清空临时表数据
  203. delete from shanglifeecif.insurancearrangement_health_tmp;
  204. --初始化临时表
  205. insert into shanglifeecif.insurancearrangement_health_tmp (
  206. id,
  207. orderid,
  208. contno,
  209. agentgroup,
  210. SALECHANNELS,
  211. AMNT,
  212. AGENTCODE
  213. ) select
  214. row_number()over(),
  215. row_number()over(PARTITION BY contno),
  216. contno,
  217. agentgroup,
  218. SALECHANNELS,
  219. AMNT,
  220. AGENTCODE
  221. from HEALTH_INSURANCE_LISTING
  222. --根据临时表更新insurancearrangement 表
  223. UPDATE shanglifeecif.insurancearrangement a SET (
  224. pwcomp ,-- '承保分公司 HEALTH_INSURANCE_LISTING.AGENTGROUPAREA 营业区HEALTH_INSURANCE_LISTING.AGENTGROUP 营业部',
  225. schannel ,-- '销售渠道 HEALTH_INSURANCE_LISTING.SALECHANNELS 1 2 3 4 5',
  226. risk ,-- '总保额 HEALTH_INSURANCE_LISTING.AMNT(测试环境中,此表保单数据量较其他表如:POLICY_INFORMATION,INSURANCEINFO 缺少至少一个数据量级)',
  227. spname -- '业务员名称 HEALTH_INSURANCE_LISTING.AGENTCODE',
  228. ) = (
  229. select
  230. b.AGENTGROUP,--pwcomp ,-- '承保分公司 HEALTH_INSURANCE_LISTING.AGENTGROUPAREA 营业区HEALTH_INSURANCE_LISTING.AGENTGROUP 营业部',
  231. b.SALECHANNELS,--schannel ,-- '销售渠道 HEALTH_INSURANCE_LISTING.SALECHANNELS 1 2 3 4 5',
  232. b.AMNT,--risk ,-- '总保额 HEALTH_INSURANCE_LISTING.AMNT(测试环境中,此表保单数据量较其他表如:POLICY_INFORMATION,INSURANCEINFO 缺少至少一个数据量级)',
  233. b.AGENTCODE--spname ,-- '业务员名称 HEALTH_INSURANCE_LISTING.AGENTCODE',
  234. from shanglifeecif.insurancearrangement_health_tmp b
  235. where b.contno = a.policyno
  236. and b.orderid = 1
  237. ) WHERE 1=1 ;
  238. END;
  239. */
  240. /
  241. CREATE OR REPLACE PROCEDURE shanglifeecif.up_insurancearrangement_other() -- 创建主存储过程
  242. IS
  243. BEGIN
  244. UPDATE shanglifeecif.insurancearrangement a SET (
  245. policytype -- '保单类型',
  246. ) = (
  247. select
  248. c.CONTTYPE
  249. from (
  250. select
  251. row_number()over(PARTITION BY b.contno) rn,
  252. b.CONTTYPE,
  253. b.contno
  254. from PERSONAL_INSURANCE b
  255. ) c
  256. WHERE c.contno = a.policyno and c.rn=1
  257. ) WHERE 1=1 ;
  258. UPDATE shanglifeecif.insurancearrangement a SET (
  259. poservice -- '是否保全',
  260. ) = (
  261. SELECT
  262. IF(count(b.CONTNO) >0,1,0)
  263. FROM AUDIT_EDORLIST b
  264. where b.contno = a.policyno
  265. ) WHERE 1=1 ;
  266. UPDATE shanglifeecif.insurancearrangement a SET (
  267. soinsured-- '被保人数',
  268. ) = (
  269. SELECT
  270. PEOPLES3
  271. FROM HEALTH_GROUP_LISTING b
  272. where b.contno = a.policyno
  273. ) WHERE 1=1 ;
  274. END;
  275. /
  276. BEGIN
  277. shanglifeecif.init_insurancearrangement();
  278. end
  279. /*
  280. UPDATE shanglifeecif.insurancearrangement a SET (
  281. pindate ,-- '起保日期 POLICY_INFORMATION.CVALIDATE',
  282. pmdate ,-- '终保日期 POLICY_INFORMATION.ENDDATE',
  283. norenewal ,-- '续保次数 POLICY_INFORMATION.PAYCOUNT',
  284. payment ,-- '缴费方式 POLICY_INFORMATION.PAYINTV',
  285. applicantscustid ,-- '投保人 上游客户号,再找到individualid',
  286. appname ,-- '投保人名称 POLICY_INFORMATION.NAME',
  287. appcertid ,-- '投保人证件号码 POLICY_INFORMATION.IDNO',
  288. insuredscustid ,-- '主被保险人 游客户号',
  289. insname ,-- '主被保险人名称 POLICY_INFORMATION.INSUREDNAME',
  290. inscertid ,-- '主被保险人证件号码 POLICY_INFORMATION.INSUREDIDNO',
  291. productid ,-- '险种代码 POLICY_INFORMATION.RISKCODE',
  292. productname,--险种名称
  293. policybelong ,-- '业绩归属 POLICY_INFORMATION.SALECOM',
  294. payendyear ,-- '缴费年期 POLICY_INFORMATION.PAYENDYEAR',
  295. policystate,--保单状态
  296. prem,--保费
  297. Risk,--保额
  298. NPDate,--下次缴费日期
  299. PADate,--投保日期
  300. AgentOrg,--代理机构
  301. schannel,--销售渠道
  302. PWComp--承保分公司
  303. ) = (
  304. select
  305. CVALIDATE,--pindate ,-- '起保日期 POLICY_INFORMATION.CVALIDATE',
  306. ENDDATE,--pmdate ,-- '终保日期 POLICY_INFORMATION.ENDDATE',
  307. PAYCOUNT,--norenewal ,-- '续保次数 POLICY_INFORMATION.PAYCOUNT',
  308. PAYINTV,--payment ,-- '缴费方式 POLICY_INFORMATION.PAYINTV',
  309. CUSTOMERNO,--applicantid ,-- '投保人 根据POLICY_INFORMATION.CUSTOMERNO关联individual上游客户号,再找到individualid',
  310. NAME,--appname ,-- '投保人名称 POLICY_INFORMATION.NAME',
  311. IDNO,--appcertid ,-- '投保人证件号码 POLICY_INFORMATION.IDNO',
  312. insuredno,--insuredid ,-- '主被保险人 insuredno',
  313. INSUREDNAME,--insname ,-- '主被保险人名称 POLICY_INFORMATION.INSUREDNAME',
  314. INSUREDIDNO,--inscertid ,-- '主被保险人证件号码 POLICY_INFORMATION.INSUREDIDNO',
  315. RISKCODE,--productid ,-- '险种代码 POLICY_INFORMATION.RISKCODE',
  316. RISKNAME, --productname 险种名称
  317. SALECOM,--policybelong ,-- '业绩归属 POLICY_INFORMATION.SALECOM',
  318. PAYENDYEAR,--payendyear ,-- '缴费年期 POLICY_INFORMATION.PAYENDYEAR',
  319. APPFLAG, --保单状态
  320. prem,--保费
  321. AMNT,--保额
  322. PAYTODATE,--下次缴费日期
  323. polapplydate,--投保日期
  324. AGENTCOM,--代理机构
  325. SALECHNL,--销售渠道
  326. "上海人寿上海分公司"
  327. from shanghailifeecif.policy_information b
  328. where b.contno = a.policyno
  329. ) WHERE 1=1 ;
  330. */