From 9e55658adfc7496184ddba15f0f1f6c8970ffecf Mon Sep 17 00:00:00 2001 From: 13233904609 <13233904609@163.cm> Date: Thu, 13 Jun 2024 13:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8A=A5=E9=94=99SQL?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=BD=93=E5=B9=B412=E4=B8=AA=E6=9C=88?= =?UTF-8?q?=E4=BB=BD=E4=B8=80=E8=88=AC=E9=9A=90=E6=82=A3=E5=92=8C=E9=87=8D?= =?UTF-8?q?=E5=A4=A7=E9=9A=90=E6=82=A3=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ehs/EhsIndexStatisticsController.java | 8 +++ .../mapper/ehs/EhsIndexStatisticsMapper.xml | 61 +++---------------- 2 files changed, 18 insertions(+), 51 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsIndexStatisticsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsIndexStatisticsController.java index 0f787e7..73a5094 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsIndexStatisticsController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsIndexStatisticsController.java @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -157,6 +158,10 @@ public class EhsIndexStatisticsController extends BaseController { List> list = ehsIndexStatisticsService.getHiddenDangerTypeMapList(); return AjaxResult.success(list); } + + public static void main(String[] args) { + System.out.println(DateUtil.year(new Date())); + } /** * 隐患数据统计分析 */ @@ -165,6 +170,9 @@ public class EhsIndexStatisticsController extends BaseController { public AjaxResult getHiddenDangerDataMapList(String year) { JSONArray row = new JSONArray(); + if(StringUtils.isEmpty(year)){ + year = DateUtil.year(new Date())+""; + } List> list = ehsIndexStatisticsService.getHiddenDangerDataMapList(year); if(StringUtils.isNotEmpty(list)){ LinkedHashMap>> nameList = list.stream().collect(Collectors.groupingBy(e -> e.get("name"), LinkedHashMap::new, Collectors.toList())); diff --git a/ruoyi-system/src/main/resources/mapper/ehs/EhsIndexStatisticsMapper.xml b/ruoyi-system/src/main/resources/mapper/ehs/EhsIndexStatisticsMapper.xml index 9ac10e3..3d0ed35 100644 --- a/ruoyi-system/src/main/resources/mapper/ehs/EhsIndexStatisticsMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/ehs/EhsIndexStatisticsMapper.xml @@ -266,61 +266,20 @@ SELECT d.dict_value FROM ( + WITH RECURSIVE months AS ( SELECT - DATE_FORMAT( date_add( CONCAT( #{yearStr}, '-01-01' ), INTERVAL ROW MONTH ), '%Y-%m' ) date_time - FROM - ( + CONCAT( #{yearStr}, '-01-01' ) AS month_date UNION ALL SELECT - @ROW := @ROW + 1 AS ROW + DATE_ADD( month_date, INTERVAL 1 MONTH ) AS month_date FROM - ( - SELECT - 0 UNION ALL - SELECT - 1 UNION ALL - SELECT - 2 UNION ALL - SELECT - 3 UNION ALL - SELECT - 4 UNION ALL - SELECT - 5 UNION ALL - SELECT - 6 UNION ALL - SELECT - 7 UNION ALL - SELECT - 8 UNION ALL - SELECT - 9 - ) t, - ( - SELECT - 0 UNION ALL - SELECT - 1 UNION ALL - SELECT - 2 UNION ALL - SELECT - 3 UNION ALL - SELECT - 4 UNION ALL - SELECT - 5 UNION ALL - SELECT - 6 UNION ALL - SELECT - 7 UNION ALL - SELECT - 8 UNION ALL - SELECT - 9 - ) t2, - ( SELECT @ROW :=- 1 ) r - ) se + months WHERE - DATE_FORMAT( date_add( CONCAT( #{yearStr}, '-01-01' ), INTERVAL ROW MONTH ), '%Y-%m' ) <= DATE_FORMAT( CONCAT( #{yearStr}, '-12-01' ), '%Y-%m' )) s, + month_date < CONCAT( #{yearStr}, '-12-01' ) + ) SELECT + DATE_FORMAT( month_date, '%Y-%m' ) AS date_time + FROM + months + ) s, sys_dict_data d WHERE d.dict_type = 'hidden_danger_grade'