保单处理增量数据koucx.sql 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --处理增量的保单信息
  2. CREATE OR REPLACE PROCEDURE shanglifeecif.incrementInsuranceArrangement2() IS
  3. DECLARE
  4. sianum INT;
  5. BEGIN
  6. SELECT COUNT(*) INTO sianum FROM shanglifeecif.InsuranceArrangement;
  7. MERGE INTO shanglifeecif.InsuranceArrangement sia using
  8. (SELECT * FROM shanghailifeecif.policy_information) si ON sia.policyno = si.CONTNO AND sia.ProductID = si.RISKCODE
  9. WHEN MATCHED THEN UPDATE SET sia.pindate = si.CVALIDATE, sia.pmdate = si.ENDDATE,sia.norenewal = si.PAYCOUNT,
  10. sia.payment = si.PAYINTV,sia.applicantid = si.individual,
  11. sia.appname = si.NAME,sia.appcertid = si.IDNO,sia.insuredid= si.insuredno,sia.insname = si.INSUREDNAME,sia.inscertid = si.INSUREDIDNO,
  12. sia.productid= si.RISKCODE,sia.policybelong = si.SALECOM,sia.payendyear = si.PAYENDYEAR
  13. WHEN NOT MATCHED THEN
  14. INSERT ( iaid ,--'保单ID',
  15. policyno ,-- '保险单号 INSURANCEINFO.CONTNO',
  16. pindate ,-- '起保日期 POLICY_INFORMATION.CVALIDATE',
  17. pmdate ,-- '终保日期 POLICY_INFORMATION.ENDDATE',
  18. norenewal ,-- '续保次数 POLICY_INFORMATION.PAYCOUNT',
  19. payment ,-- '缴费方式 POLICY_INFORMATION.PAYINTV',
  20. applicantscustid ,-- '投保人 上游客户号,再找到individualid',
  21. appname ,-- '投保人名称 POLICY_INFORMATION.NAME',
  22. appcertid ,-- '投保人证件号码 POLICY_INFORMATION.IDNO',
  23. insuredscustid ,-- '主被保险人 游客户号',
  24. insname ,-- '主被保险人名称 POLICY_INFORMATION.INSUREDNAME',
  25. inscertid ,-- '主被保险人证件号码 POLICY_INFORMATION.INSUREDIDNO',
  26. productid ,-- '险种代码 POLICY_INFORMATION.RISKCODE',
  27. policybelong ,-- '业绩归属 POLICY_INFORMATION.SALECOM',
  28. payendyear ,-- '缴费年期 POLICY_INFORMATION.PAYENDYEAR',
  29. created_by ,-- '创建人',
  30. created_time -- '创建时间',
  31. )
  32. values(row_number()over()+sianum,
  33. CONTNO,--policyno ,-- '保险单号 INSURANCEINFO.CONTNO',
  34. CVALIDATE,--pindate ,-- '起保日期 POLICY_INFORMATION.CVALIDATE',
  35. ENDDATE,--pmdate ,-- '终保日期 POLICY_INFORMATION.ENDDATE',
  36. PAYCOUNT,--norenewal ,-- '续保次数 POLICY_INFORMATION.PAYCOUNT',
  37. PAYINTV,--payment ,-- '缴费方式 POLICY_INFORMATION.PAYINTV',
  38. individual,--applicantid ,-- '投保人 根据POLICY_INFORMATION.CUSTOMERNO关联individual上游客户号,再找到individualid',
  39. NAME,--appname ,-- '投保人名称 POLICY_INFORMATION.NAME',
  40. IDNO,--appcertid ,-- '投保人证件号码 POLICY_INFORMATION.IDNO',
  41. insuredno,--insuredid ,-- '主被保险人 insuredno',
  42. INSUREDNAME,--insname ,-- '主被保险人名称 POLICY_INFORMATION.INSUREDNAME',
  43. INSUREDIDNO,--inscertid ,-- '主被保险人证件号码 POLICY_INFORMATION.INSUREDIDNO',
  44. RISKCODE,--productid ,-- '险种代码 POLICY_INFORMATION.RISKCODE',
  45. SALECOM,--policybelong ,-- '业绩归属 POLICY_INFORMATION.SALECOM',
  46. PAYENDYEAR,--payendyear ,-- '缴费年期 POLICY_INFORMATION.PAYENDYEAR',
  47. 'koucx',
  48. sysdate() );
  49. UPDATE insurancearrangement a SET (
  50. applicantid --'投保人ID',
  51. ) = (
  52. select
  53. indid ,--'投保人ID',
  54. from individual b
  55. where b.scustid = a.applicantscustid
  56. ) WHERE 1=1 ;
  57. UPDATE insurancearrangement a SET (
  58. insuredid --'主保险人ID',
  59. ) = (
  60. select
  61. indid ,--'投保人ID',
  62. from individual b
  63. where b.scustid = a.insuredscustid
  64. ) WHERE 1=1 ;
  65. --更新INSURANCEINFO 表中的信息
  66. UPDATE insurancearrangement a SET (
  67. pano ,-- '投保单号 INSURANCEINFO.PRTNO',
  68. pisdate ,-- '签单日期 INSURANCEINFO.SIGNDATE',
  69. padate ,-- '投保日期 INSURANCEINFO.POLAPPLYDATE',
  70. policystate ,--INSURANCEINFO,appflag
  71. prem ,-- '总保费 INSURANCEINFO.PREM',
  72. productname ,-- '险种名称 INSURANCEINFO.RISKNAME'
  73. agentchannel ,-- '代理渠道 INSURANCEINFO.SELLTYPE',
  74. ) = (
  75. select
  76. PRTNO,--pano ,-- '投保单号 INSURANCEINFO.PRTNO',
  77. SIGNDATE,--pisdate ,-- '签单日期 INSURANCEINFO.SIGNDATE',
  78. POLAPPLYDATE,--padate ,-- '投保日期 INSURANCEINFO.POLAPPLYDATE',
  79. appflag,--policystate ,--INSURANCEINFO,appflag
  80. PREM,--prem ,-- '总保费 INSURANCEINFO.PREM',
  81. RISKNAME,--productname ,-- '险种名称 INSURANCEINFO.RISKNAME'
  82. SELLTYPE--agentchannel ,-- '代理渠道 INSURANCEINFO.SELLTYPE',
  83. from shanghailifeecif.INSURANCEINFO b
  84. where b.contno = a.policyno
  85. ) WHERE 1=1 ;
  86. EXCEPTION
  87. WHEN HIVE_EXCEPTION THEN
  88. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  89. WHEN Others THEN
  90. INSERT INTO shanglifeecif.exception_log(log_code,log_msg,log_time) VALUES (sqlcode(),sqlerrm(),sysdate());
  91. END ;