From dd57251f66ecb6b7f7535a2f42afd3b73c054f50 Mon Sep 17 00:00:00 2001 From: yangkunan Date: Mon, 29 Jul 2024 17:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E7=9C=8B=E6=9D=BF=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E6=8C=87=E6=A0=87=E6=A0=B8=E5=AF=B9=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?+=E6=80=BB=E8=A3=81=E7=9C=8B=E6=9D=BF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/sqldialects.xml | 3 + finereport/kanban/pc/商业.sql | 24 +++-- finereport/kanban/pc/工程.sql | 153 +++++++++++++++++++++++++- finereport/kanban/pc/总裁.sql | 197 +++++++++++++++++++++++++++++++++- 4 files changed, 360 insertions(+), 17 deletions(-) diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 42cee4a..24dba3b 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -2,13 +2,16 @@ + + + diff --git a/finereport/kanban/pc/商业.sql b/finereport/kanban/pc/商业.sql index 7107868..702eaaf 100644 --- a/finereport/kanban/pc/商业.sql +++ b/finereport/kanban/pc/商业.sql @@ -1,5 +1,6 @@ +-- --------------------- -- 【出租率】 - +-- --------------------- SELECT `type` @@ -7,19 +8,19 @@ SELECT FROM dws_business_rent_rate_d ${if(len(project) == 0,"","where project_id in (" + project + ")")} group by `type` - +; -- 【出租面积】 -SELECT +/*SELECT project_id , project_name , `type` , construction_area/10000 construction_area -- 建筑面积 , lease_area/10000 lease_area , lease_area/construction_area rent_rate - +*/ SELECT sum(lease_area ) as lease_area -- 出租面积 ,sum(construction_area) as construction_area -- 建筑面积 @@ -31,25 +32,26 @@ where lease_end_date >= '2024-07-25' -- 合同结束时间 ; - - -${if(len(project) == 0,"","where project_id in (" + project + ")")} +-- ${if(len(project) == 0,"","where project_id in (" + project + ")")} ; -- 出租率计算: sum(出租面积.select(lease_area))/sum(出租面积.select(construction_area)) -- 正确值: 33.45% +-- 业务反馈 建筑面积 :335335.36 +-- 租赁面积: 298452.2 +-- 出租率: 0.890011122000376 +-- ============================================================================================================ + +-- ------------------------------ -- 【收款金额】 +-- ------------------------------- SELECT sum(received_money) 实收金额 ,sum(current_sure_money) 收款金额 ,sum(received_money) / sum(current_sure_money) rate -,sum(areare_money) as areare_money -,sum(current_sure_money) as current_sure_money - -,sum(areare_money) / sum(current_sure_money) as rate1 FROM ( SELECT diff --git a/finereport/kanban/pc/工程.sql b/finereport/kanban/pc/工程.sql index a53c238..a062b25 100644 --- a/finereport/kanban/pc/工程.sql +++ b/finereport/kanban/pc/工程.sql @@ -5,7 +5,7 @@ SELECT DISTINCT organ_code AS 片区id, organ_name AS 片区名称 FROM dim_organ_mapping - +; -- report_车场启费 @@ -27,6 +27,23 @@ from ( where 1=1 ${IF(LEN(p_area)>0," AND a.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} +-- report_单位面积能耗(水) + +select + organ_code + , organ_name + , comm_id + , comm_name + , MeterType + , list_ym + ,coalesce(Dosage/ContractArea,0) dosage_per_square_meter +from dws_engine_meter_dosage_m a + left join (select * from dim_project_base_info_d) b on a.comm_id = b.CommId +where 1=1 + and MeterType = '水表' + ${IF(LEN(p_area)>0," AND organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} + ${IF(LEN(p_ym)>0," AND list_ym ='" + p_ym+ "'","")} + -- report_设备完好率 @@ -45,7 +62,7 @@ union all select '巡查点位数', count(*) from dim_engine_point_d union all select '设施设备总数', count(*) from dim_engine_equipment_d - +; -- 能耗环比 select * @@ -54,7 +71,7 @@ where left(list_ym,4) = ${left(p_ym,4)} AND list_ym <> DATE_FORMAT(CURDATE(), '%Y%m') and MeterType in ('水表','电表') ${IF(LEN(p_area)>0," AND organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} - +; -- 能耗排名 select ${IF(LEN(p_area)>0,"comm_id code, comm_name name,","organ_code code, organ_name name,")} dosage @@ -64,7 +81,7 @@ where MeterType = '电表' ${IF(LEN(p_ym)>0," AND list_ym ='" + left(p_ym,4) + right(p_ym,2) + "'","")} order by Dosage desc limit 5 - +; -- 能耗同比 SELECT @@ -176,4 +193,130 @@ select , sum(manualOutNum) / sum(carflow) exceptionRate from dws_engine_stat_exception_rate_w where yw = (select distinct yw from dws_engine_stat_exception_rate_w order by yw desc limit 1) -group by organ_code , organ_name \ No newline at end of file +group by organ_code , organ_name; + + +-- ============================================================================================================ +-- 单位面积能耗 水 + +select + organ_code + , organ_name + , comm_id + , comm_name + , MeterType + , list_ym + ,coalesce(Dosage/ContractArea,0) dosage_per_square_meter -- 单位面积能耗 水 +from dws_engine_meter_dosage_m a + left join (select * from dim_project_base_info_d) b on a.comm_id = b.CommId +where 1=1 + and MeterType = '水表' + ${IF(LEN(p_area)>0," AND organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} + ${IF(LEN(p_ym)>0," AND list_ym ='" + left(p_ym,4) + right(p_ym,2) + "'","")} +; +-- =================================== +-- 基础指标 +-- =================================== +SELECT + SUM(CASE WHEN TypeName = 'SpaceNum' THEN CNT ELSE 0 END) AS SpaceNum -- 设备空间数 + ,SUM(CASE WHEN TypeName = 'ParkingSpaceNUM' THEN CNT ELSE 0 END) AS ParkingSpaceNUM -- 车位数量 + ,SUM(CASE WHEN TypeName = 'ParkingNum' THEN CNT ELSE 0 END) AS ParkingNum -- 停车场数量 + ,SUM(CASE WHEN TypeName = 'SpaceTaskNum' THEN CNT ELSE 0 END) AS SpaceTaskNum -- 设备空间任务数 + ,SUM(CASE WHEN TypeName = 'DeviceNum' THEN CNT ELSE 0 END) AS DeviceNum -- 设备档案数 +FROM + ( + SELECT + CommID -- 项目ID + ,'SpaceNum' AS TypeName + ,COUNT(1) AS CNT -- 设备空间数 + FROM dw.dim_engine_space_info_d -- 工程设备空间 + GROUP BY + CommID + UNION ALL + select + CommID + ,'ParkingSpaceNUM' AS TypeName + ,COUNT(1) AS CNT -- 车位数量 + from dw.dim_parking_info_d a + where exists(select 1 from dw.dim_organ_mapping b where a.CommID = b.comm_id) + GROUP BY + CommID + UNION ALL + SELECT + CommID + ,'ParkingNum' AS TypeName + ,count(1) AS CNT -- 停车场数量 + from dw.dim_carpark_info_d a + -- where exists(select 1 from dw.dim_organ_mapping b where a.CommID = b.comm_id) + GROUP BY + CommID + UNION ALL + SELECT + CommID + ,'SpaceTaskNum' AS TypeName + ,count(1) AS CNT -- 设备空间任务数 + from dw.ods_erp_tb_eq_plan_inspection_d a + where a.IsEnable=1 and a.IsAuditing=1 + -- where exists(select 1 from dw.dim_organ_mapping b where a.CommID = b.comm_id) + GROUP BY + CommID + UNION ALL + SELECT + CommID + ,'DeviceNum' AS TypeName + ,COUNT(1) AS CNT + from dw.dim_engine_equipment_d -- 设备档案数 + GROUP BY + CommID + )A + LEFT JOIN + ( + SELECT + organ_code -- 片区code + ,organ_name -- 片区名称 + ,comm_id -- 项目id + ,comm_name -- 项目名称 + FROM dw.dim_organ_mapping -- 组织架构映射表 + GROUP BY + organ_code -- 片区code + ,organ_name -- 片区名称 + ,comm_id -- 项目id + ,comm_name -- 项目名称 + )B + ON A.CommID = B.comm_id + ${IF(LEN(p_area)>0," AND B.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} +; + + +-- =========================================== +-- 车位数量明细查询 +-- =========================================== +SELECT + B.organ_name AS organ_name + ,B.comm_name AS comm_name + ,COUNT(1) AS CNT +FROM + ( + SELECT + CommID + FROM dw.dim_parking_info_d + -- WHERE UseState = '使用' + -- and PropertyUses not in('闲置','未售出','未售') + )A + LEFT JOIN + ( + SELECT + distinct + organ_code + ,organ_name + ,comm_id + ,comm_name + from dim_organ_mapping + where comm_id is not null + )B + ON A.CommID = B.comm_id + WHERE B.comm_name IS NOT NULL +GROUP BY + B.organ_name + ,B.comm_name +; \ No newline at end of file diff --git a/finereport/kanban/pc/总裁.sql b/finereport/kanban/pc/总裁.sql index 6283126..70c79d5 100644 --- a/finereport/kanban/pc/总裁.sql +++ b/finereport/kanban/pc/总裁.sql @@ -50,4 +50,199 @@ group by - 设备巡查.select(task_finish_num) / 设备巡查.select(task_num) \ No newline at end of file + 设备巡查.select(task_finish_num) / 设备巡查.select(task_num) + + +-- ---------------------------------- +-- report_商业出租率 +-- --------------------------------- +select sum(lease_area)/sum(construction_area) rent_rate +FROM dws_business_rent_rate_d a + left join (select distinct id, erp_id from ods_bs_project_d) b + on a.project_id = b.id + left join (select distinct organ_code, organ_name, comm_id, comm_name from dim_organ_mapping where comm_id is not null) c + on b.erp_id = c.comm_id +where 1=1 + ${if(len(organ)=0,"","and c.organ_code = '"+organ+"'")} + + +-- ---------------------------------- +-- report_商业出租率_new +-- --------------------------------- + +SELECT + T.`type` + ,SUM(T.rentRoomAreaSum) / (SUM(T.rentRoomAreaSum) + SUM(T.notRentRoomAreaSum)) as rent_rate -- 出租率 +FROM + ( + SELECT + B.`type` + ,SUM(CASE WHEN A.business_status = 1 THEN A.construction_area ELSE 0 END ) AS rentRoomAreaSum -- 出租面积 + ,SUM(CASE WHEN A.business_status != 4 AND A.business_status != 1 THEN A.construction_area ELSE 0 END ) AS notRentRoomAreaSum -- 未出租面积 + FROM + ( + SELECT + id + ,erp_id + ,building_id + ,business_status + ,construction_area -- 建筑面积 + FROM dw.ods_bs_room_d -- 商管房间表 + WHERE del_flag = 0 + AND enable_flag = 0 + AND review_status = 2 + )A + LEFT JOIN + ( + select + id + ,project_id + ,project_name + ,`type` -- 业态 商业街,集中商业,写字楼,底商 + from dim_business_building_d + )B + on A.building_id = B.id + LEFT JOIN + ( + select + distinct + organ_code + ,organ_name + ,comm_id + ,comm_name + from dim_organ_mapping + where comm_id is not null + )C + on A.erp_id = C.comm_id + where 1=1 + ${if(len(organ)=0,"","and b.organ_code = '"+ organ+"'")} + GROUP BY + B.`type` + )T +GROUP BY + T.`type` +; + + + + +-- ---------------------------------- +-- report_商业收缴率 +-- --------------------------------- + +select sum(received_money) / sum(current_sure_money) collection_rate +FROM dws_business_bill_m a + left join (select distinct id, erp_id from ods_bs_project_d) b + on a.project_id = b.id + left join (select distinct organ_code, organ_name, comm_id, comm_name from dim_organ_mapping where comm_id is not null) c + on b.erp_id = c.comm_id +where left(accrual_month,7) = '2024-06' + ${if(len(organ)=0,"","and c.organ_code = '"+organ+"'")} + +; + + +-- ---------------------------------- +-- report_商业收缴率_new +-- --------------------------------- + +SELECT + SUM(T.received_money) / SUM(T.current_sure_money) AS collection_rate -- 收缴率 +FROM + ( + SELECT + T1.received_money AS received_money + ,T1.current_sure_money AS current_sure_money + + FROM + ( + SELECT + a.project_id -- 项目id 关联bs_project表 + ,SUM(a.received_money) AS received_money -- 实收金额 + ,SUM(a.current_sure_money) AS current_sure_money -- 实际应收金额=应收金额-合同减免金额 + -- ,SUM(a.under_money) AS under_money -- 欠收金额 + FROM + ( + SELECT + contract_id + ,accrual_month + ,start_period + ,bill_type + ,received_money -- 实收金额 + ,current_sure_money -- 实际应收金额=应收金额-合同减免金额 + ,current_sure_money - received_money as under_money -- 欠收金额 + ,project_id + FROM dw.ods_bs_fi_bills_d + WHERE save_status = 1 -- 账单状态 0是保存 1是审核过的 + -- ${if(len(project) == 0,"","AND project_id in (" + project + ")")} + )a + left join + ( + SELECT + status + ,stop_date + ,id + FROM dw.ods_bs_contract_d + WHERE del_flag = 0 + )bc + on bc.id = a.contract_id + WHERE ((bc.status != 2 and bc.stop_date is null) OR + (bc.stop_date is not null + and ((a.accrual_month <= DATE_FORMAT(bc.stop_date, '%Y-%m') + and a.start_period <= bc.stop_date) + + or a.bill_type = 15) + )) + group by + a.project_id + UNION ALL + SELECT + a.project_id + ,SUM(b.received_amount) AS received_money + ,SUM(b.received_money) AS current_sure_money + -- ,SUM(b.under_money) AS under_money + FROM + ( + SELECT + receive_no -- 催缴单号 + ,project_id + FROM dw.ods_bs_fi_receive_other_d + where recheck_status = 2 + )a + LEFT JOIN + ( + SELECT + receive_no + ,received_amount + ,received_money + ,received_money - received_amount AS under_money + FROM dw.ods_bs_fi_receive_other_item_d + )b + ON a.receive_no = b.receive_no + group by + project_id + )T1 + left join + ( + select + distinct id + ,erp_id + from dw.ods_bs_project_d + ) b + on T1.project_id = b.id + left join + ( + select + distinct + organ_code + ,organ_name + ,comm_id + ,comm_name + from dim_organ_mapping + where comm_id is not null + ) c + on b.erp_id = c.comm_id + ${if(len(organ)=0,"","and c.organ_code = '"+organ+"'")} + )T + +; \ No newline at end of file