关键费用指标历史数据保存及指标预警推送
This commit is contained in:
parent
3a65a27a77
commit
6f1b07e6e0
@ -1,5 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
@ -67,9 +67,15 @@
|
||||
<file url="file://$PROJECT_DIR$/finereport/xiazuan/6_innovation/9_多径回款情况.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/xiazuan/6_innovation/新零售订单明细.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/xiazuan/权责亏损项目明细.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/历史数据/今日收费历史数据保留.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/历史数据/关键指标历史数据保留.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/问题修复/计划到期明细组织架构为空.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/预警/片区预警数据.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/预警/项目预警数据.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/预警/预警-片区.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/预警/预警-项目级-客满完成率.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/预警/预警-项目级-收缴完成率.sql" dialect="MySQL" />
|
||||
<file url="file://$PROJECT_DIR$/finereport/预警/预警-项目级-水电、综合、巡查.sql" dialect="MySQL" />
|
||||
<file url="PROJECT" dialect="MySQL" />
|
||||
</component>
|
||||
</project>
|
75
finereport/历史数据/今日收费历史数据保留.sql
Normal file
75
finereport/历史数据/今日收费历史数据保留.sql
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
DROP TABLE ods_history_today_fee_save;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE ods_history_today_fee_save(
|
||||
dt VARCHAR(50) COMMENT '时间'
|
||||
,extract_date VARCHAR(50) COMMENT '抽数日期'
|
||||
,extract_time VARCHAR(50) COMMENT '抽数时间'
|
||||
,metric_value VARCHAR(50) COMMENT '指标值'
|
||||
)COMMENT = '今日收费历史数据保留';
|
||||
|
||||
SELECT * FROM ods_history_today_fee_save;
|
||||
/*
|
||||
总裁驾驶舱、财务看板PC端和移动端:
|
||||
1、今日收费:最新拉取数据=上次拉取数据时、08:00之前数据大于50w时;推送角色
|
||||
2、今日收费:最新拉取数据为空;
|
||||
*/
|
||||
|
||||
INSERT INTO ods_history_today_fee_save
|
||||
SELECT
|
||||
CURRENT_DATE AS dt -- 当天
|
||||
,CURRENT_TIMESTAMP AS extract_date -- 抽数日期
|
||||
,CURRENT_TIME AS extract_time -- 抽数时间
|
||||
,sum(ifnull(pr_paid_amt,0) + ifnull(cu_paid_amt,0) + ifnull(fu_paid_amt,0))/10000 paid_amt
|
||||
from dws_finance_today_fees_d
|
||||
WHERE ParentCostCode not in ('0006','0009','0010','0011')
|
||||
and MiddleCostCode not in ('00080013','00080014','00080015','00080016','00080025','00080029','00080033','00080036','00080037')
|
||||
and commid not in(select comm_id from ods_remove_comm)
|
||||
;
|
||||
|
||||
-- 时间 上次拉取数据、当前拉取数据、8点前拉取数据
|
||||
|
||||
with base AS(
|
||||
SELECT
|
||||
t.dt AS dt
|
||||
,t.extract_date AS extract_date
|
||||
,t.extract_time AS extract_time
|
||||
,t.metric_value AS metric_value
|
||||
,row_number() OVER (PARTITION BY dt ORDER BY extract_date desc) as rk -- 根据抽数时间排序
|
||||
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
dt
|
||||
,extract_date
|
||||
,extract_time
|
||||
,metric_value
|
||||
-- 如果一个小时内多次抽数的情况,取最新的
|
||||
,row_number() OVER (PARTITION BY dt,hour(extract_date) ORDER BY extract_date desc) as rk
|
||||
FROM ods_history_today_fee_save
|
||||
WHERE dt = '${s_ym}'
|
||||
)t
|
||||
WHERE t.rk = 1
|
||||
)
|
||||
SELECT
|
||||
a.dt AS dt
|
||||
,a.extract_date AS extract_date
|
||||
,a.extract_time AS extract_time
|
||||
,hour(a.extract_date) AS extract_hour
|
||||
,a.metric_value AS current_value
|
||||
,coalesce(b.metric_value,0) AS last_metric_value
|
||||
,CASE WHEN hour(a.extract_date) < 8 THEN a.metric_value ELSE 0 END AS before_eight
|
||||
,CASE WHEN hour(a.extract_date) < 8 AND a.metric_value > 50 THEN '1'
|
||||
WHEN a.metric_value = b.metric_value THEN '1'
|
||||
WHEN hour(a.extract_date) > 8 AND coalesce(a.metric_value,0) = 0 THEN '1'
|
||||
ELSE '0' END AS is_exception -- 是否异常 1:是 0:否
|
||||
,CASE WHEN hour(a.extract_date) < 8 AND a.metric_value > 50 THEN '08:00之前数据大于50w'
|
||||
WHEN a.metric_value = b.metric_value THEN '最新数据等于上次拉取数据'
|
||||
WHEN hour(a.extract_date) > 8 AND coalesce(a.metric_value,0) = 0 THEN '最新拉取数据为空'
|
||||
ELSE '最新数据等于上次拉取数据' END AS exception_rule
|
||||
FROM base a
|
||||
LEFT JOIN base b
|
||||
on a.rk = b.rk - 1
|
||||
ORDER BY a.extract_date
|
211
finereport/历史数据/关键指标历史数据保留.sql
Normal file
211
finereport/历史数据/关键指标历史数据保留.sql
Normal file
@ -0,0 +1,211 @@
|
||||
|
||||
DROP TABLE ods_history_metric_save;
|
||||
|
||||
CREATE TABLE ods_history_metric_save(
|
||||
dt VARCHAR(50) COMMENT '时间'
|
||||
,extract_time VARCHAR(50) COMMENT '抽数时间'
|
||||
,metric_name VARCHAR(50) COMMENT '指标名称'
|
||||
,metric_value VARCHAR(50) COMMENT '指标值'
|
||||
)COMMENT = '关键指标历史数据保留';
|
||||
|
||||
SELECT * FROM ods_history_metric_save;
|
||||
/*
|
||||
总裁驾驶舱、财务看板PC端和移动端:
|
||||
1、今日收费:最新拉取数据=上次拉取数据时、08:00之前数据大于50w时;推送角色
|
||||
2、今日收费:最新拉取数据为空;
|
||||
|
||||
3、当期欠费金额:当日数据>昨日数据时;
|
||||
4、往期欠费金额:当日数据>昨日数据时;
|
||||
5、当期收缴率:当日数据<昨日数据时;
|
||||
6、往期收缴率:当日数据<昨日数据时;
|
||||
7、月度累计收费:当日数据<昨日数据时;
|
||||
8、年度累计收费:当日数据<昨日数据时;
|
||||
*/
|
||||
|
||||
|
||||
-- 当期欠费金额
|
||||
-- 往期欠费金额
|
||||
-- 当期收缴率
|
||||
-- 往期收缴率
|
||||
|
||||
WITH base_metric AS(
|
||||
select
|
||||
sum((ifnull(pr_paid_cu_amt,0) + ifnull(cu_paid_cu_amt,0) - ifnull(pr_offset_cu_amt,0) - ifnull(cu_offset_cu_amt,0))) / sum((ifnull(cu_receivable_amt,0) + ifnull(pr_exempt_cu_amt,0) + ifnull(cu_exempt_cu_amt,0))) cu_collection_rate -- 当期收缴率
|
||||
,sum((- ifnull(cu_paid_pr_amt,0) - ifnull(cu_offset_pr_amt,0))) / sum((ifnull(pr_total_receivable_amt,0) + ifnull(pr_total_received_amt,0) + ifnull(cu_early_exempt_pr_amt,0) + ifnull(cu_exempt_pr_amt,0))) pr_collection_rate -- 往期收缴率
|
||||
,sum((ifnull(pr_total_receivable_amt,0) + ifnull(pr_total_received_amt,0) + ifnull(cu_early_exempt_pr_amt,0) + ifnull(cu_exempt_pr_amt,0))-(- ifnull(cu_paid_pr_amt,0) - ifnull(cu_offset_pr_amt,0)))/10000 pr_owed_amt -- 往期欠费金额
|
||||
,sum((ifnull(cu_receivable_amt,0) + ifnull(pr_exempt_cu_amt,0) + ifnull(cu_exempt_cu_amt,0))-(ifnull(pr_paid_cu_amt,0) + ifnull(cu_paid_cu_amt,0) - ifnull(pr_offset_cu_amt,0) - ifnull(cu_offset_cu_amt,0)))/10000 cu_owed_amt -- 当期欠费金额
|
||||
|
||||
,0 AS thisy_paid_amt -- 年度累计收费
|
||||
,0 AS thism_paid_amt -- 月度累计收费
|
||||
from dwd_finance_fees_serial_d
|
||||
where ParentCostCode = '0001'
|
||||
and organ_name not in ('东湖商管','领悦总部','演示机构')
|
||||
and commid not in(select comm_id from ods_remove_comm)
|
||||
and ym = DATE_FORMAT(NOW(),'%Y-%m')
|
||||
UNION ALL
|
||||
select
|
||||
0 AS cu_collection_rate -- 当期收缴率
|
||||
,0 AS pr_collection_rate -- 往期收缴率
|
||||
,0 AS pr_owed_amt -- 往期欠费金额
|
||||
,0 AS cu_owed_amt -- 当期欠费金额
|
||||
,a.thisy_paid_amt AS thisy_paid_amt -- 年度累计收费
|
||||
,b.thism_paid_amt AS thism_paid_amt -- 月度累计收费
|
||||
from
|
||||
(
|
||||
select
|
||||
'集团' tmp
|
||||
, sum(ifnull(pr_paid_cu_amt,0) + ifnull(cu_paid_cu_amt,0) - ifnull(cu_paid_pr_amt,0)) /10000 thisy_paid_amt
|
||||
, sum(case when ParentCostCode = '0008' and MiddleCostCode in ('00080001','00080002','00080003','00080004','00080005','00080006','00080007','00080008','00080009','00080010','00080011','00080012','00080017','00080018','00080019','00080020','00080021','00080022','00080023','00080024','00080027','00080028','00080032','00080034','00080035') then (ifnull(pr_paid_cu_amt,0) + ifnull(cu_paid_cu_amt,0) - ifnull(cu_paid_pr_amt,0) - ifnull(cu_paid_fu_amt,0)) else 0 end) /10000 thism_shuidian_paid_amt
|
||||
from dwd_finance_fees_serial_d a
|
||||
where ym = date_format(current_date(),'%Y-%m')
|
||||
and organ_name not in ('东湖商管','领悦总部','演示机构')
|
||||
and ParentCostCode not in ('0006','0009','0010','0011')
|
||||
and MiddleCostCode not in ('00080013','00080014','00080015','00080016','00080025','00080026','00080029','00080030','00080031','00080033','00080036','00080037')
|
||||
and commid not in(select comm_id from ods_remove_comm)
|
||||
|
||||
)a
|
||||
left join
|
||||
(
|
||||
select
|
||||
'集团' tmp
|
||||
, sum(ifnull(cu_paid_cu_amt,0) - ifnull(cu_paid_pr_amt,0)) /10000 thism_paid_amt
|
||||
from dwd_finance_total_paid_fees_m a
|
||||
where ym = date_format(current_date(),'%Y-%m')
|
||||
and organ_name not in ('东湖商管','领悦总部','演示机构')
|
||||
and ParentCostCode not in ('0006','0009','0010','0011')
|
||||
and MiddleCostCode not in ('00080013','00080014','00080015','00080016','00080025','00080029','00080033','00080036','00080037')
|
||||
and commid not in(select comm_id from ods_remove_comm)
|
||||
)b
|
||||
on a.tmp = b.tmp
|
||||
)
|
||||
SELECT
|
||||
T.dt AS dt-- 前一天
|
||||
,T.extract_time AS extract_time-- 抽数时间
|
||||
,T.metric_name AS metric_name-- 指标名称
|
||||
,SUM(T.metric_value) AS metric_value -- 指标值
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY) AS dt -- 前一天
|
||||
,CURRENT_TIMESTAMP AS extract_time -- 抽数时间
|
||||
,'当期收缴率' AS metric_name -- 指标名称
|
||||
,cu_collection_rate AS metric_value -- 指标值
|
||||
FROM base_metric
|
||||
UNION ALL
|
||||
SELECT
|
||||
DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY) AS dt -- 前一天
|
||||
,CURRENT_TIMESTAMP AS extract_time -- 抽数时间
|
||||
,'往期收缴率' AS metric_name -- 指标名称
|
||||
,pr_collection_rate AS metric_value -- 指标值
|
||||
FROM base_metric
|
||||
UNION ALL
|
||||
SELECT
|
||||
DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY) AS dt -- 前一天
|
||||
,CURRENT_TIMESTAMP AS extract_time -- 抽数时间
|
||||
,'往期欠费金额' AS metric_name -- 指标名称
|
||||
,pr_owed_amt AS metric_value -- 指标值
|
||||
FROM base_metric
|
||||
UNION ALL
|
||||
SELECT
|
||||
DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY) AS dt -- 前一天
|
||||
,CURRENT_TIMESTAMP AS extract_time -- 抽数时间
|
||||
,'当期欠费金额' AS metric_name -- 指标名称
|
||||
,cu_owed_amt AS metric_value -- 指标值
|
||||
FROM base_metric
|
||||
UNION ALL
|
||||
SELECT
|
||||
DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY) AS dt -- 前一天
|
||||
,CURRENT_TIMESTAMP AS extract_time -- 抽数时间
|
||||
,'年度累计收费' AS metric_name -- 指标名称
|
||||
,thisy_paid_amt AS metric_value -- 指标值
|
||||
FROM base_metric
|
||||
UNION ALL
|
||||
SELECT
|
||||
DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY) AS dt -- 前一天
|
||||
,CURRENT_TIMESTAMP AS extract_time -- 抽数时间
|
||||
,'月度累计收费' AS metric_name -- 指标名称
|
||||
,thism_paid_amt AS metric_value -- 指标值
|
||||
FROM base_metric
|
||||
)T
|
||||
GROUP BY T.dt,T.extract_time,T.metric_name
|
||||
;
|
||||
|
||||
|
||||
with base_date AS
|
||||
(
|
||||
SELECT
|
||||
T.metric_name AS metric_name
|
||||
,sum(T.yesterday_value) AS yesterday_value
|
||||
,SUM(T.today_value) AS today_value
|
||||
FROM
|
||||
(
|
||||
SELECT A.metric_name AS metric_name -- 指标名称
|
||||
, 0 AS yesterday_value -- 昨日指标值
|
||||
, A.metric_value AS today_value -- 今日指标值
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
metric_name
|
||||
, metric_value
|
||||
, ROW_NUMBER() OVER (PARTITION BY metric_name,dt ORDER BY extract_time DESC) AS rk
|
||||
FROM ods_history_metric_save
|
||||
WHERE LEFT(dt, 10) = DATE_SUB('${s_ym}', INTERVAL 1 DAY)) A
|
||||
WHERE rk = 1
|
||||
UNION ALL
|
||||
SELECT
|
||||
A.metric_name AS metric_name -- 指标名称
|
||||
, A.metric_value AS yesterday_value -- 昨日指标值
|
||||
, 0 AS today_value -- 今日指标值
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
metric_name
|
||||
, metric_value
|
||||
, ROW_NUMBER() OVER (PARTITION BY metric_name,dt ORDER BY extract_time DESC) AS rk
|
||||
FROM ods_history_metric_save
|
||||
WHERE LEFT(dt, 10) = DATE_SUB('${s_ym}', INTERVAL 2 DAY)
|
||||
) A
|
||||
WHERE rk = 1
|
||||
)T
|
||||
GROUP BY T.metric_name
|
||||
)
|
||||
SELECT
|
||||
metric_name
|
||||
,yesterday_value AS yesterday_value
|
||||
,today_value AS today_value
|
||||
,CASE WHEN metric_name = '当期欠费金额' THEN (CASE WHEN today_value > yesterday_value THEN '1' ELSE '0' END)
|
||||
WHEN metric_name = '往期欠费金额' THEN (CASE WHEN today_value > yesterday_value THEN '1' ELSE '0' END)
|
||||
WHEN metric_name = '当期收缴率' THEN (CASE WHEN today_value < yesterday_value THEN '1' ELSE '0' END)
|
||||
WHEN metric_name = '往期收缴率' THEN (CASE WHEN today_value < yesterday_value THEN '1' ELSE '0' END)
|
||||
WHEN metric_name = '月度累计收费' THEN (CASE WHEN today_value < yesterday_value THEN '1' ELSE '0' END)
|
||||
WHEN metric_name = '年度累计收费' THEN (CASE WHEN today_value < yesterday_value THEN '1' ELSE '0' END)
|
||||
END AS is_exception -- 是否异常 1:是 0:否
|
||||
,CASE WHEN metric_name = '当期欠费金额' THEN '当日数据>昨日数据'
|
||||
WHEN metric_name = '往期欠费金额' THEN '当日数据>昨日数据'
|
||||
WHEN metric_name = '当期收缴率' THEN '当日数据<昨日数据'
|
||||
WHEN metric_name = '往期收缴率' THEN '当日数据<昨日数据'
|
||||
WHEN metric_name = '月度累计收费' THEN '当日数据<昨日数据'
|
||||
WHEN metric_name = '年度累计收费' THEN '当日数据<昨日数据'
|
||||
END AS exception_rule -- 异常条件
|
||||
|
||||
/*
|
||||
-- 异常指标规则:
|
||||
3、当期欠费金额:当日数据>昨日数据时;
|
||||
4、往期欠费金额:当日数据>昨日数据时;
|
||||
5、当期收缴率:当日数据<昨日数据时;
|
||||
6、往期收缴率:当日数据<昨日数据时;
|
||||
7、月度累计收费:当日数据<昨日数据时;
|
||||
8、年度累计收费:当日数据<昨日数据时;
|
||||
*/
|
||||
FROM base_date
|
||||
ORDER BY
|
||||
CASE WHEN metric_name = '当期欠费金额' THEN 1
|
||||
WHEN metric_name = '往期欠费金额' THEN 2
|
||||
WHEN metric_name = '当期收缴率' THEN 3
|
||||
WHEN metric_name = '往期收缴率' THEN 4
|
||||
WHEN metric_name = '月度累计收费' THEN 5
|
||||
WHEN metric_name = '年度累计收费' THEN 6
|
||||
END
|
||||
|
||||
|
||||
-- 测试数据
|
961
finereport/预警/预警-片区.sql
Normal file
961
finereport/预警/预警-片区.sql
Normal file
@ -0,0 +1,961 @@
|
||||
-- ======================================
|
||||
-- 预警-片区-回款率-30%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '回款率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.3'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.payment_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.payment_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-客满完成率-90%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '客满完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.9'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.km_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.km_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-客满完成率-95%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '客满完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.95'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.km_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.km_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-当期收缴完成率-80%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '当期收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.cu_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.cu_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-当期收缴完成率-75%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '当期收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.75'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.cu_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.cu_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-当期收缴完成率-70%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '当期收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.cu_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.cu_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-往期收缴完成率-75%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '往期收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.75'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.pr_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.pr_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-往期收缴完成率-70%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '往期收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.pr_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.pr_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-往期收缴完成率-80%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '往期收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.pr_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.pr_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-投诉关闭率-95%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '投诉关闭率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.95'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.ts_close_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.ts_close_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-投诉关闭率-90%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '投诉关闭率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.9'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.ts_close_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.ts_close_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-报事关闭率-80%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '报事关闭率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.report_close_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.report_close_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-报事关闭率-90%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '报事关闭率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.9'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.report_close_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.report_close_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-新零售收入完成率-70%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '新零售收入完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.xing_revenue_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.xing_revenue_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-水电费收缴率-98%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '水电费收缴率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.98'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.water_electric_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.water_electric_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-空间运营收入完成率-100%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '空间运营收入完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '1'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.space_operate_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.space_operate_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-综合收缴完成率-75%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '综合收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.75'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.total_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.total_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-综合收缴完成率-80%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '综合收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.total_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.total_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-综合收缴完成率-70%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '综合收缴完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.total_coll_comple_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.total_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-美居收入完成率-50%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '美居收入完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.5'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.meiju_revenue_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.meiju_revenue_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-设备空间巡查完成率-98%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '设备空间巡查完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.98'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.device_space_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.device_space_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-资产租售收入完成率-50%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '资产租售收入完成率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.5'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.rent_revenue_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.rent_revenue_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-片区-销户率-30%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '销户率'
|
||||
and comm_organ = '片区'
|
||||
and index_value = '0.3'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.account_rate from dim_early_warning_organ_d t1
|
||||
inner join b t2 on t1.account_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
;
|
190
finereport/预警/预警-项目级-客满完成率.sql
Normal file
190
finereport/预警/预警-项目级-客满完成率.sql
Normal file
@ -0,0 +1,190 @@
|
||||
-- ======================================
|
||||
-- 预警-项目级-客满完成率-95%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '客满完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.95'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
|
||||
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.km_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.km_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-客满完成率-90%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '客满完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.9'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
|
||||
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.km_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.km_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-客满完成率-85%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '客满完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.85'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
|
||||
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.km_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.km_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-客满完成率-75%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '客满完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.75'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
|
||||
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.km_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.km_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
280
finereport/预警/预警-项目级-收缴完成率.sql
Normal file
280
finereport/预警/预警-项目级-收缴完成率.sql
Normal file
@ -0,0 +1,280 @@
|
||||
-- ======================================
|
||||
-- 预警-项目级-当期收缴完成率-60%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '当期收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.6'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.cu_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.cu_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-当期收缴完成率-70%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '当期收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.cu_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.cu_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-当期收缴完成率-80%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '当期收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.cu_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.cu_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-往期收缴完成率-60%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '往期收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.6'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.pr_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.pr_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-往期收缴完成率-70%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '往期收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.pr_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.pr_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-往期收缴完成率-80%
|
||||
-- ======================================
|
||||
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '往期收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.pr_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.pr_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
231
finereport/预警/预警-项目级-水电、综合、巡查.sql
Normal file
231
finereport/预警/预警-项目级-水电、综合、巡查.sql
Normal file
@ -0,0 +1,231 @@
|
||||
-- ======================================
|
||||
-- 预警-项目级-水电费收缴率-98%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '水电费收缴率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.98'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
|
||||
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.water_electric_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.water_electric_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-综合收缴完成率-80%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '综合收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.8'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.total_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.total_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-综合收缴完成率-70%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '综合收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.7'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.total_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.total_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-综合收缴完成率-60%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '综合收缴完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.6'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.total_coll_comple_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.total_coll_comple_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
||||
|
||||
|
||||
|
||||
-- ======================================
|
||||
-- 预警-项目级-设备空间巡查完成率-98%
|
||||
-- ======================================
|
||||
with a as( -- 所有有角色的人员
|
||||
select t1.username,t3.name as role_name from finedb.fine_user t1
|
||||
inner join finedb.fine_user_role_middle t2 on t1.id = t2.userId
|
||||
inner join finedb.fine_custom_role t3 on t2.roleId = t3.id
|
||||
),
|
||||
b as( -- 找到单条预警规则**
|
||||
select index_name,comm_organ,index_value,mang_organ from ods_index_early_warning
|
||||
where index_name = '设备空间巡查完成率'
|
||||
and comm_organ = '项目'
|
||||
and index_value = '0.98'
|
||||
limit 1
|
||||
),
|
||||
c as( -- 找到关联的用户
|
||||
select distinct username from b
|
||||
join a on FIND_IN_SET(a.role_name,b.mang_organ)
|
||||
),
|
||||
d as( -- 找到规则下受影响的项目**
|
||||
select t1.organ_name,t1.comm_name,t1.device_space_rate from dim_early_warning_comm_d t1
|
||||
inner join b t2 on t1.device_space_rate < t2.index_value
|
||||
),
|
||||
e as( -- 要推送的总部人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '总部人员'
|
||||
),
|
||||
f as( -- 要推送的片区人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '片区人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.organ_name,t2.ProjectAuth)
|
||||
),
|
||||
g as( -- 要推送的项目人员
|
||||
select distinct t2.username,t2.LoginCode,t2.user_type,t2.ProjectAuth from c t1
|
||||
inner join v_erp_user_auth t2 on t1.username = t2.LoginCode and t2.user_type = '项目人员'
|
||||
inner join d t3 on FIND_IN_SET(t3.comm_name,t2.ProjectAuth)
|
||||
)
|
||||
-- 要推送的人员合集
|
||||
select username,LoginCode,user_type,ProjectAuth from e
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from f
|
||||
union all
|
||||
select username,LoginCode,user_type,ProjectAuth from g
|
||||
;
|
Loading…
Reference in New Issue
Block a user