From 39e98f4e69753c7de9fadf1de406bae37b9c1a99 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 1 Aug 2023 11:23:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20group=5Fby=5Fdept=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/apps/supervision/views2.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/apps/supervision/views2.py b/server/apps/supervision/views2.py index 5d7fd34..15a2294 100644 --- a/server/apps/supervision/views2.py +++ b/server/apps/supervision/views2.py @@ -6,6 +6,8 @@ from utils.sql import query_all_dict class YearSerializer(serializers.Serializer): year = serializers.IntegerField(label='年份') + dept_name = serializers.CharField(label='单位名称', default='') + dept_type_name = serializers.CharField(label='单位类型', default='2级公司') class AnalyseViewSet(GenericViewSet): perms_map = {'post': '*'} @@ -28,6 +30,7 @@ class AnalyseViewSet(GenericViewSet): vdata = self.is_valid(request) sql_str = f"""select task2.year as 年份, dept.name as 单位, +dict.name as 单位类型, pgoal.pgoal_1 as 重大事故数基础值, pdept1.goal_value_b as 重大事故数设定值, SUM(task2do.num_acc) as 重大事故数, @@ -61,9 +64,12 @@ left join supervision_pgoaldept pdept2 on pdept2.goal_key = 'pgoal_2' and pdept2 left join supervision_pgoaldept pdept3 on pdept3.goal_key = 'pgoal_3' and pdept3.year = {vdata['year']} and pdept3.belong_dept_id = task2do.belong_dept_id left join supervision_pgoaldept pdept4 on pdept4.goal_key = 'pgoal_4' and pdept4.year = {vdata['year']} and pdept4.belong_dept_id = task2do.belong_dept_id left join supervision_pgoaldept pdept5 on pdept5.goal_key = 'pgoal_5' and pdept5.year = {vdata['year']} and pdept5.belong_dept_id = task2do.belong_dept_id -left join supervision_pgoal pgoal on pgoal.year = {vdata['year']} +left join supervision_pgoal pgoal on pgoal.year = 2023 +left join system_dict dict on dict.id = dept.type_id where task2.year = {vdata['year']} -GROUP BY task2.year, dept.id, +and (dept.name = '{vdata['dept_name']}' or '{vdata['dept_name']}'='') +and (dic.name = '{vdata['dept_type_name']}' or '{vdata['dept_type_name']}'='') +GROUP BY task2.year, dept.id, dict.name, pgoal.pgoal_1, pgoal.pgoal_2, pgoal.pgoal_3,