From 8bc3e8c8a8801363fd282cb68527bb2befc494a2 Mon Sep 17 00:00:00 2001 From: yangkunan Date: Tue, 24 Sep 2024 12:38:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=98=8E=E7=BB=86=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/sqldialects.xml | 3 + .../dws_operation_subcompany_plan_level_d.sql | 7 +- .../xiazuan/2_operation/未完成计划明细.sql | 105 ++++++++++++++++++ .../xiazuan/2_operation/计划到期明细.sql | 61 +++++++--- finereport/xiazuan/权责亏损项目明细.sql | 32 ++++++ .../问题修复/计划到期明细组织架构为空.sql | 90 +++++++++++++++ 6 files changed, 278 insertions(+), 20 deletions(-) create mode 100644 finereport/xiazuan/2_operation/未完成计划明细.sql create mode 100644 finereport/xiazuan/权责亏损项目明细.sql create mode 100644 finereport/问题修复/计划到期明细组织架构为空.sql diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 53d4b7b..de6baaf 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -26,6 +26,7 @@ + @@ -38,6 +39,7 @@ + @@ -48,6 +50,7 @@ + diff --git a/dw/dws/dws_operation_subcompany_plan_level_d.sql b/dw/dws/dws_operation_subcompany_plan_level_d.sql index 5c9c04b..708aaaa 100644 --- a/dw/dws/dws_operation_subcompany_plan_level_d.sql +++ b/dw/dws/dws_operation_subcompany_plan_level_d.sql @@ -1,5 +1,5 @@ select - left(a.start_date,7) ym + left(a.end_date,7) ym , b.subcompanyid1 subcompanyid , c.subcompanyname , c.supsubcomid @@ -7,7 +7,7 @@ select , count(*) plan_num , count(plan_name) plan_adjust_num , sum(case when plan_status = 2 then 1 else 0 end) plan_cancel_num - , sum(case when plan_status = 6 then 1 else 0 end) plan_exempt_assess_num + , sum(case when plan_status = 7 then 1 else 0 end) plan_exempt_assess_num , sum(case when plan_status = 4 then 1 else 0 end) plan_incomplete_num , sum(case when left(start_date,7) = left(input_date,7) then 1 else 0 end) plan_thism_num , sum(case when plan_status = 0 then 1 else 0 end) plan_in_progress_num @@ -33,8 +33,9 @@ from ( on b.subcompanyid1 = c.id left join (select distinct plan_name from dwd_operations_plan_adjust_info_d) d on a.id = d.plan_name +WHERE left(a.end_date,7) = '2024-09' group by - left(a.start_date,7) + left(a.end_date,7) , b.subcompanyid1 , c.subcompanyname , c.supsubcomid diff --git a/finereport/xiazuan/2_operation/未完成计划明细.sql b/finereport/xiazuan/2_operation/未完成计划明细.sql new file mode 100644 index 0000000..4de0e7a --- /dev/null +++ b/finereport/xiazuan/2_operation/未完成计划明细.sql @@ -0,0 +1,105 @@ +-- ***************************** +-- 创建人员: 杨坤安 +-- 创建时间: +-- 功能描述: 未完成计划明细 +-- ***************************** + +with one_to_many AS( + SELECT + a.username AS username -- 用户名 + ,SUBSTRING_INDEX(SUBSTRING_INDEX(a.mang_project, ',',b.help_topic_id + 1),',',-1) AS mang_project -- 管理项目名 + FROM ods_one_to_many_perm a + JOIN mysql.help_topic b + on b.help_topic_id < (LENGTH(a.mang_project) - length(replace(a.mang_project,',','')) + 1) + WHERE a.username = '${fine_username}' +) +select + ${if(len(p_area) == 0,"c.organ_name","c.comm_name")} as p_area + ,c.oa_comm_id as oa_comm_id -- oa项目id + ,c.oa_comm_name as oa_comm_name -- oa项目名称 + ,c.oa_organ_code as oa_organ_code -- oa片区id + ,c.oa_organ_name as oa_organ_name -- oa片区名称 + ,c.organ_code as organ_code -- erp片区编码 + ,c.organ_name as organ_name -- erp片区名称 + ,c.comm_id as comm_id -- erp项目id + ,c.comm_name as comm_name -- erp项目名称 + ,b.subcompanyid1 as subcompanyid1 -- 公司id + ,a.plan_name as plan_name -- 计划名称 + ,a.eval_criteria as plan_desc -- 计划内容 + ,a.plan_level as plan_level -- 计划等级 + ,left(a.start_date,7) as ym -- 计划开始年月 + ,a.start_dt as start_dt -- 计划开始时 + ,a.end_date as end_date -- 计划结束时间 + ,a.finish_date as finish_date -- 计划完成时间 + ,a.input_date as input_date -- 计划录入时间 + ,a.day_diff as day_diff -- 距离计划结束天数 + ,a.responsible_person1 as responsible_person1 -- 责任人编码 + ,b.lastname as executor_name -- 责任人名称 + ,d.lastname AS lastname -- 执行人 + ,left(a.end_ym,7) as end_ym -- 计划结束年月 +from + ( + SELECT + concat(left(trim(start_date),5),lpad(substring_index(substring_index(trim(start_date),'-',2),'-',-1),2,0),right(trim(start_date),3)) as start_date + ,a.start_date as start_dt -- 计划开始时间 + ,a.plan_level -- 计划等级 + ,jt.responsible_person1 -- 责任人 + ,a.plan_status -- 计划状态 + ,a.input_date -- 录入时间 + ,a.end_date -- 计划结束时间 + ,a.plan_name -- 计划名称 + ,concat(left(trim(end_date),5),lpad(substring_index(substring_index(trim(end_date),'-',2),'-',-1),2,0),right(trim(end_date),3)) as end_ym + ,a.finish_date -- 完成时间 + ,TO_DAYS(a.end_date) - TO_DAYS(curdate()) AS day_diff + ,a.eval_criteria -- 评价标准 + ,a.executor -- 执行人 + FROM dw.dwd_operations_plan_info_d a, + JSON_TABLE ( + cast( CONCAT( '["', REPLACE ( responsible_person1, ',', '","' ), '"]' ) AS json ), + "$[*]" COLUMNS ( responsible_person1 INT PATH "$" ) + ) AS jt + WHERE a.plan_status = '4' + )a + left join + ( + select + id + ,subcompanyid1 -- 公司id + ,lastname -- 执行人 + from dw.ods_oa_hrmresource_d + + )b + on a.responsible_person1 = b.id + left join + ( + select + distinct + organ_code -- erp片区id + ,organ_name -- erp片区名称 + ,comm_id -- erp项目id + ,comm_name -- erp项目名称 + ,oa_organ_code -- oa片区id + ,oa_organ_name -- oa片区名称 + ,oa_comm_id -- oa项目id + ,oa_comm_name -- oa项目名称 + from dim_organ_mapping -- 组织结构映射维度表 + -- where comm_id is not null + )c + on b.subcompanyid1 = c.oa_comm_id + left join + ( + select + id + ,subcompanyid1 -- 公司id + ,lastname -- 执行人 + from dw.ods_oa_hrmresource_d + + )d + on a.executor = d.id +where 1 = 1 + ${if(len(p_startdate) == 0,"","and left(a.end_ym,7) = '" + p_startdate + "'")} + ${IF(LEN(p_area)!=0," and organ_code IN ('"+p_area+"')","")} +-- ${if(left(fine_role,2)=="项目","and comm_name = '"+GETUSERDEPARTMENTS(3)+"'","")} + AND CASE WHEN (SELECT mang_project FROM ods_one_to_many_perm WHERE username = '${fine_username}' AND mang_organ IS NULL) IS NOT NULL + THEN comm_name IN (SELECT mang_project FROM one_to_many WHERE username = '${fine_username}') + ELSE ${if(left(fine_role,2)=="项目","comm_name = '"+GETUSERDEPARTMENTS(3)+"'","1=1")} END diff --git a/finereport/xiazuan/2_operation/计划到期明细.sql b/finereport/xiazuan/2_operation/计划到期明细.sql index 1ed0e56..1e9c3fa 100644 --- a/finereport/xiazuan/2_operation/计划到期明细.sql +++ b/finereport/xiazuan/2_operation/计划到期明细.sql @@ -5,7 +5,18 @@ -- 目 录: xianzuan>2_运营>计划到期明细.fvs -- **************************************** + + -- 【数据集: report_计划到期】 +with one_to_many AS( + SELECT + a.username AS username -- 用户名 + ,SUBSTRING_INDEX(SUBSTRING_INDEX(a.mang_project, ',',b.help_topic_id + 1),',',-1) AS mang_project -- 管理项目名 + FROM ods_one_to_many_perm a + JOIN mysql.help_topic b + on b.help_topic_id < (LENGTH(a.mang_project) - length(replace(a.mang_project,',','')) + 1) + WHERE a.username = '${fine_username}' +) select ${if(len(p_area) == 0,"c.organ_name","c.comm_name")} as p_area ,c.oa_comm_id as oa_comm_id -- oa项目id @@ -28,6 +39,7 @@ select ,a.day_diff as day_diff -- 距离计划结束天数 ,a.responsible_person1 as responsible_person1 -- 责任人编码 ,b.lastname as executor_name -- 责任人名称 + ,d.lastname AS lastname -- 执行人 ,left(a.end_ym,7) as end_ym -- 计划结束年月 from ( @@ -44,15 +56,16 @@ from ,a.finish_date -- 完成时间 ,TO_DAYS(a.end_date) - TO_DAYS(curdate()) AS day_diff ,a.eval_criteria -- 评价标准 + ,a.executor -- 执行人 FROM dw.dwd_operations_plan_info_d a, JSON_TABLE ( cast( CONCAT( '["', REPLACE ( responsible_person1, ',', '","' ), '"]' ) AS json ), "$[*]" COLUMNS ( responsible_person1 INT PATH "$" ) ) AS jt - -- WHERE TO_DAYS(a.end_date) - TO_DAYS(curdate()) <= 3 + -- WHERE TO_DAYS(a.end_date) - TO_DAYS(curdate()) <= 3 -- AND TO_DAYS(a.end_date) - TO_DAYS(curdate()) >= 1 where a.end_date > date_format(CURDATE() - INTERVAL 3 day,'%Y-%m-%d') - and a.end_date <= date_format(CURDATE(),'%Y-%m-%d') + and a.end_date <= date_format(CURDATE(),'%Y-%m-%d') )a left join ( @@ -64,25 +77,39 @@ from )b on a.responsible_person1 = b.id + left join + ( + select + distinct + organ_code -- erp片区id + ,organ_name -- erp片区名称 + ,comm_id -- erp项目id + ,comm_name -- erp项目名称 + ,oa_organ_code -- oa片区id + ,oa_organ_name -- oa片区名称 + ,oa_comm_id -- oa项目id + ,oa_comm_name -- oa项目名称 + from dim_organ_mapping -- 组织结构映射维度表 + -- where comm_id is not null + )c + on b.subcompanyid1 = c.oa_comm_id left join ( select - distinct - organ_code -- erp片区id - ,organ_name -- erp片区名称 - ,comm_id -- erp项目id - ,comm_name -- erp项目名称 - ,oa_organ_code -- oa片区id - ,oa_organ_name -- oa片区名称 - ,oa_comm_id -- oa项目id - ,oa_comm_name -- oa项目名称 - from dim_organ_mapping -- 组织结构映射维度表 - where comm_id is not null - )c - on b.subcompanyid1 = c.oa_comm_id - where 1 = 1 + id + ,subcompanyid1 -- 公司id + ,lastname -- 执行人 + from dw.ods_oa_hrmresource_d + + )d + on a.executor = d.id +where 1 = 1 ${if(len(p_startdate) == 0,"","and left(a.end_ym,7) = '" + p_startdate + "'")} - ${IF(LEN(p_area)!=0," and organ_code IN ('"+p_area+"')","")} + ${IF(LEN(p_area)!=0," and organ_code IN ('"+p_area+"')","")} +-- ${if(left(fine_role,2)=="项目","and comm_name = '"+GETUSERDEPARTMENTS(3)+"'","")} + AND CASE WHEN (SELECT mang_project FROM ods_one_to_many_perm WHERE username = '${fine_username}' AND mang_organ IS NULL) IS NOT NULL + THEN comm_name IN (SELECT mang_project FROM one_to_many WHERE username = '${fine_username}') + ELSE ${if(left(fine_role,2)=="项目","comm_name = '"+GETUSERDEPARTMENTS(3)+"'","1=1")} END diff --git a/finereport/xiazuan/权责亏损项目明细.sql b/finereport/xiazuan/权责亏损项目明细.sql new file mode 100644 index 0000000..51b5063 --- /dev/null +++ b/finereport/xiazuan/权责亏损项目明细.sql @@ -0,0 +1,32 @@ +with one_to_many AS( + SELECT + a.username AS username -- 用户名 + ,SUBSTRING_INDEX(SUBSTRING_INDEX(a.mang_project, ',',b.help_topic_id + 1),',',-1) AS mang_project -- 管理项目名 + FROM ods_one_to_many_perm a + JOIN mysql.help_topic b + on b.help_topic_id < (LENGTH(a.mang_project) - length(replace(a.mang_project,',','')) + 1) + WHERE a.username = '${fine_username}' +) +SELECT + organ_code -- erp片区code + ,organ_name -- erp片区名称 + ,comm_id -- 项目id + ,comm_name -- 项目名称 + ,index_income_target -- 收入目标 + ,index_income_fact -- 收入完成 + ,income_completion_rate -- 完成率 + ,index_cost_target -- 成本目标 + ,index_cost_fact -- 成本完成 + ,cost_completion_rate -- 完成率 + ,index_profit_target -- 利润目标 + ,index_profit_fact -- 利润完成 + ,profit_completion_rate -- 完成率 + ,index_market_target -- 市扩目标 + ,index_market_fact -- 市扩完成 + ,market_completion_rate -- 完成率 +from ods_caiwu_feecollection +where category = '物业' +and index_profit_fact < 0 +${IF(LEN(p_startdate)>0," AND yr_month ='" + p_startdate + "'","and yr_month = '2024-06' ")} +${if(len(p_area) == 0,"","and organ_code in ('" + p_area + "')")} +${IF(LEN(p_shop)!=0," and comm_name IN ('"+JOINARRAY(p_shop,"','")+"')","")} \ No newline at end of file diff --git a/finereport/问题修复/计划到期明细组织架构为空.sql b/finereport/问题修复/计划到期明细组织架构为空.sql new file mode 100644 index 0000000..c066bda --- /dev/null +++ b/finereport/问题修复/计划到期明细组织架构为空.sql @@ -0,0 +1,90 @@ + + + +SELECT + c.organ_name + ,c.comm_name + ,c.oa_comm_id as oa_comm_id -- oa项目id + ,c.oa_comm_name as oa_comm_name -- oa项目名称 + ,c.oa_organ_code as oa_organ_code -- oa片区id + ,c.oa_organ_name as oa_organ_name -- oa片区名称 + ,c.organ_code as organ_code -- erp片区编码 + ,c.organ_name as organ_name -- erp片区名称 + ,c.comm_id as comm_id -- erp项目id + ,c.comm_name as comm_name -- erp项目名称 + ,b.subcompanyid1 as subcompanyid1 -- 公司id + ,a.plan_name as plan_name -- 计划名称 + ,a.eval_criteria as plan_desc -- 计划内容 + ,a.plan_level as plan_level -- 计划等级 + ,left(a.start_date,7) as ym -- 计划开始年月 + ,a.start_dt as start_dt -- 计划开始时 + ,a.end_date as end_date -- 计划结束时间 + ,a.finish_date as finish_date -- 计划完成时间 + ,a.input_date as input_date -- 计划录入时间 + ,a.day_diff as day_diff -- 距离计划结束天数 + ,a.responsible_person1 as responsible_person1 -- 责任人编码 + ,b.lastname as executor_name -- 责任人名称 + ,left(a.end_ym,7) as end_ym -- 计划结束年月 +from + ( + SELECT + concat(left(trim(start_date),5),lpad(substring_index(substring_index(trim(start_date),'-',2),'-',-1),2,0),right(trim(start_date),3)) as start_date + ,a.start_date as start_dt -- 计划开始时间 + ,a.plan_level -- 计划等级 + ,jt.responsible_person1 -- 责任人 + ,a.plan_status -- 计划状态 + ,a.input_date -- 录入时间 + ,a.end_date -- 计划结束时间 + ,a.plan_name -- 计划名称 + ,concat(left(trim(end_date),5),lpad(substring_index(substring_index(trim(end_date),'-',2),'-',-1),2,0),right(trim(end_date),3)) as end_ym + ,a.finish_date -- 完成时间 + ,TO_DAYS(a.end_date) - TO_DAYS(curdate()) AS day_diff + ,a.eval_criteria -- 评价标准 + FROM dw.dwd_operations_plan_info_d a, + JSON_TABLE ( + cast( CONCAT( '["', REPLACE ( responsible_person1, ',', '","' ), '"]' ) AS json ), + "$[*]" COLUMNS ( responsible_person1 INT PATH "$" ) + ) AS jt + -- WHERE TO_DAYS(a.end_date) - TO_DAYS(curdate()) <= 3 + -- AND TO_DAYS(a.end_date) - TO_DAYS(curdate()) >= 1 + where a.end_date > date_format(CURDATE() - INTERVAL 3 day,'%Y-%m-%d') + and a.end_date <= date_format(CURDATE(),'%Y-%m-%d') + )a + left join + ( + select + id + ,subcompanyid1 -- 公司id + ,lastname -- 执行人 + from dw.ods_oa_hrmresource_d + + )b + on a.responsible_person1 = b.id + left join + ( + select + distinct + organ_code -- erp片区id + ,organ_name -- erp片区名称 + ,comm_id -- erp项目id + ,comm_name -- erp项目名称 + ,oa_organ_code -- oa片区id + ,oa_organ_name -- oa片区名称 + ,oa_comm_id -- oa项目id + ,oa_comm_name -- oa项目名称 + from dim_organ_mapping -- 组织结构映射维度表 + -- WHERE oa_comm_id = '610' + WHERE oa_organ_code = '610' + -- where comm_id is not null + )c + on b.subcompanyid1 = c.oa_comm_id +; + + + +select + id + ,subcompanyid1 -- 公司id + ,lastname -- 执行人 +from dw.ods_oa_hrmresource_d +WHERE ods_oa_hrmresource_d.subcompanyid1 = '610'; \ No newline at end of file