Commit 1f72aecc authored by 胡涛's avatar 胡涛

指标统计sql脚本

parent 3df96b96
......@@ -12,6 +12,7 @@ POLICY_PLCSOLUTION_PLCCOMMISSIONDETAIL
来源:
{
"sigAndStaExchangeRate": 1,
"policyCreatDate": 1642142368422,
"endorseNo": null , -- 1 批单号
"policyNo": "6605212022411424000406", -- 2 保单号
......
......@@ -8,43 +8,18 @@
-- 2、汇率换算 = 承保保费 * sigAndStaExchangeRate (汇率)
-- 备注:批单不用计算,sta开头得字段是被转过汇率得
-- 条件: 车险 或 (非车险 并且 plcSolution.plcCoins.plcCoinsBasicInformation.coinsIdentity(共保我方) =1)
insert into ZB_ODS.ZB_ODS_KAFKA.CBDATA
select
s1.uwConclueDate as `uwConclueDate` -- 核保通过时间
,s1.startTime as `startTime` -- 起保时间
,s1.businessOffice as `COMCODE` --
,t1.COMNAME as `COMNAME` --
,t1.LEVEL1COMCODE as `LEVEL1COMCODE` --
,t1.LEVEL2COMCODE as `LEVEL2COMCODE` --
,t1.LEVEL3COMCODE as `LEVEL3COMCODE` --
,t1.LEVEL4COMCODE as `LEVEL4COMCODE` --
,t1.LEVEL5COMCODE as `LEVEL5COMCODE` --
,t1.LEVEL1COMDESC as `LEVEL1COMDESC` --
,t1.LEVEL2COMDESC as `LEVEL2COMDESC` --
,t1.LEVEL3COMDESC as `LEVEL3COMDESC` --
,t1.LEVEL4COMDESC as `LEVEL4COMDESC` --
,t1.LEVEL5COMDESC as `LEVEL5COMDESC` --
,s1.productCode as `risk` -- 险种代码
,t3.RISKNAME as `riskname` --
,s1.businessChannelCode as `chnl` -- 业务渠道
,t2.NEWCHNLTYPEDESC as `chnlname` --
,s1.businessNatureCode as `businessNatureCode` -- 业务来源
,t4.CODEDESC as `businessNatureName` --
,s1.netPremium as `cost` -- 不含税保费
,s1.policyNo as `no` -- 保单号
,s1.xxzflag as xxzflag -- 新续转标记 1是0否
,s1.recordClerkCode as `id` -- 14 归属业务员ID
,s1.recordClerkName as `name` -- 15 归属业务员名称
from (
CREATE TEMPORARY VIEW VIEW_HIS_CBDATA AS
select
LongTimeToStringUDF(policyCreatDate,'yyyyMMdd') as uwConclueDate -- 核保通过时间
LongTimeToStringUDF(uwConclueDate,'yyyyMMdd') as uwConclueDate -- 核保通过时间
,LongTimeToStringUDF(startTime,'yyyyMMdd') as startTime -- 起保时间
,businessOffice as businessOffice -- 保单归属机构代码
,productCode as productCode -- 险种代码
,businessChannelCode as businessChannelCode -- 业务渠道
,businessNatureCode as businessNatureCode -- 业务来源
,netPremium as netPremium -- 不含税保费
,cast(netPremium as decimal(18,2)) * cast(sigAndStaExchangeRate as decimal(18,2))*(case when JsonValueUDF(plcSolution[1].plcCoins,'plcCoinsBasicInformation.coinsRate') is null then 1
else cast(JsonValueUDF(plcSolution[1].plcCoins,'plcCoinsBasicInformation.coinsRate') AS decimal(18,2) )
end )
as netPremium -- 不含税保费
,policyNo as policyNo -- 保单号
,case
when LEFT(productCode,2) = '05' and (newPolicyFlag = '1' or autoTransrenewFlag = '1' or autoTransrenewFlag = '4' or transferPolicyFlag = '1' or transrenewFlag = '1' or transrenewFlag ='4') then '1'
......@@ -53,20 +28,23 @@ from (
,recordClerkCode as recordClerkCode -- 14 归属业务员ID
,recordClerkName as recordClerkName -- 15 归属业务员名称
,'bd' as flag -- 保单或批单标记
,proctime as proctime
-- ,ROW_NUMBER() OVER(PARTITION BY policyNo,businessOffice,netPremium ORDER BY uwConclueDate DESC) as rownum
from ZB_ODS.ZB_SOURCE_RMQ_POLICY_UAT.POLICY -- 保单业务数据
,proctime as proctime-- ,ROW_NUMBER() OVER(PARTITION BY policyNo,businessOffice,netPremium ORDER BY uwConclueDate DESC) as rownum
from ZB_ODS.ZB_SOURCE_RMQ_POLICY_SIT.POLICY -- 保单业务数据
where `uwConclueDate` = DATE_FORMAT(LOCALTIMESTAMP,'yyyyMMdd')
and (LEFT(productCode,2) = '05' or (LEFT(productCode,2) <> '05' and JsonValueUDF(plcSolution[1].plcCoins,'plcCoinsBasicInformation.coinsIdentity') = '1'))
union all
select
LongTimeToStringUDF(policyCreatDate,'yyyyMMdd') as uwConclueDate -- 核保通过时间 ??
LongTimeToStringUDF(uwConclueDate,'yyyyMMdd') as uwConclueDate -- 核保通过时间 ??
,LongTimeToStringUDF(endorseEffectiveTime,'yyyyMMdd') as startTime -- 起保时间
,businessOffice as businessOffice -- 保单归属机构代码
,productCode as productCode -- 险种代码
,businessChannelCode as businessChannelCode -- 业务渠道
,businessNatureCode as businessNatureCode -- 业务来源
,plpEndorse.staCurPremiumVariation as netPremium -- 不含税保费 ??
,cast(plpEndorse.staCurPremiumVariation as decimal(18,2)) *(case when JsonValueUDF(plcSolution[1].plcCoins,'plcCoinsBasicInformation.coinsRate') is null then 1
else cast(JsonValueUDF(plcSolution[1].plcCoins,'plcCoinsBasicInformation.coinsRate') AS decimal(18,2) )
end )
as netPremium -- 不含税保费 ??
,endorseNo as policyNo -- 批单号
,case
when LEFT(productCode,2) = '05' and (newPolicyFlag = '1' or autoTransrenewFlag = '1' or autoTransrenewFlag = '4' or transferPolicyFlag = '1' or transrenewFlag = '1' or transrenewFlag ='4') then '1'
......@@ -76,10 +54,42 @@ from (
,recordClerkName as recordClerkName -- 15 归属业务员名称
,'pd' as flag -- 保单或批单标记
,proctime as proctime
-- ,ROW_NUMBER() OVER(PARTITION BY endorseNo,businessOffice,plpEndorse.staCurPremiumVariation ORDER BY uwConclueDate DESC) as rownum
from ZB_ODS.ZB_SOURCE_RMQ_ENDOR_UAT.ENDOR -- 批单业务数据
-- ,ROW_NUMBER() OVER(PARTITION BY endorseNo,businessOffice,plpEndorse.staCurPremiumVariation ORDER BY uwConclueDate DESC) as rownum
from ZB_ODS.ZB_SOURCE_RMQ_ENDOR_SIT.ENDOR -- 批单业务数据
where `uwConclueDate` = DATE_FORMAT(LOCALTIMESTAMP,'yyyyMMdd')
and (LEFT(productCode,2) = '05' or (LEFT(productCode,2) <> '05' and JsonValueUDF(plcSolution[1].plcCoins,'plcCoinsBasicInformation.coinsIdentity') = '1'))
;
insert into ZB_ODS.ZB_ODS_KAFKA.CBDATA
select
s1.uwConclueDate as `uwConclueDate` -- 核保通过时间
,s1.startTime as `startTime` -- 起保时间
,s1.businessOffice as `COMCODE` --
,t1.COMNAME as `COMNAME` --
,t1.LEVEL1COMCODE as `LEVEL1COMCODE` --
,t1.LEVEL2COMCODE as `LEVEL2COMCODE` --
,t1.LEVEL3COMCODE as `LEVEL3COMCODE` --
,t1.LEVEL4COMCODE as `LEVEL4COMCODE` --
,t1.LEVEL5COMCODE as `LEVEL5COMCODE` --
,t1.LEVEL1COMDESC as `LEVEL1COMDESC` --
,t1.LEVEL2COMDESC as `LEVEL2COMDESC` --
,t1.LEVEL3COMDESC as `LEVEL3COMDESC` --
,t1.LEVEL4COMDESC as `LEVEL4COMDESC` --
,t1.LEVEL5COMDESC as `LEVEL5COMDESC` --
,s1.productCode as `risk` -- 险种代码
,t3.RISKNAME as `riskname` --
,s1.businessChannelCode as `chnl` -- 业务渠道
,t2.NEWCHNLTYPEDESC as `chnlname` --
,s1.businessNatureCode as `businessNatureCode` -- 业务来源
,t4.CODEDESC as `businessNatureName` --
,cast(s1.netPremium as varchar) as `cost` -- 不含税保费
,s1.policyNo as `no` -- 保单号
,s1.xxzflag as xxzflag -- 新续转标记 1是0否
,s1.recordClerkCode as `id` -- 14 归属业务员ID
,s1.recordClerkName as `name` -- 15 归属业务员名称
,cast(s1.fcxgbwfbfxs as varchar) as fcxgbwfbfxs -- 非车险共保我方保费系数
from (
select * from VIEW_HIS_CBDATA
) s1
left join ZB_ODS.ZB_ODS_MYSQL.CD_COM_ALL for system_time as of s1.proctime as t1 on s1.businessOffice = t1.COMCODE
left join ZB_ODS.ZB_ODS_MYSQL.CD_NEWCHNLTYPE for system_time as of s1.proctime as t2 on s1.businessChannelCode = t2.NEWCHNLTYPE
......@@ -90,3 +100,18 @@ left join ZB_ODS.ZB_ODS_MYSQL.CD_BUSINESSNATURE for system_time as of s1.proctim
uwConclueDate
startTime
businessOffice
productCode
businessChannelCode
businessNatureCode
netPremium
policyNo
xxzflag
recordClerkCode
recordClerkName
flag
proctime
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment