From 1c973a8fd4e126c3dbd9b95af68a963363b35a34 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 21 一月 2026 17:20:12 +0800
Subject: [PATCH] 大屏项目接口
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 97 insertions(+), 8 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java
index e007aba..ae0efc4 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java
@@ -1,13 +1,18 @@
package com.ruoyi.system.service.impl;
+import cn.hutool.core.date.DateUnit;
+import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.system.model.ProjectInfo;
import com.ruoyi.system.mapper.ProjectInfoMapper;
import com.ruoyi.system.model.Record;
+import com.ruoyi.system.query.ProjectHiddenDangerTrendListQuery;
import com.ruoyi.system.service.ProjectInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.service.RecordService;
+import com.ruoyi.system.vo.ProjectHiddenDangerList;
+import com.ruoyi.system.vo.ProjectHiddenDangerNextList;
import com.ruoyi.system.vo.ProjectHiddenDangerTrendVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -15,7 +20,10 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -46,10 +54,9 @@
record.setHierarchyName( name);
}
-
LocalDate thisMonth = LocalDate.now().minusMonths(0).with(TemporalAdjusters.firstDayOfMonth());
Map<String, List<Record>> map = list.stream().collect(groupingBy(Record::getHierarchyName));
- List<ProjectHiddenDangerTrendVo> collect = map.entrySet().stream().map(entry -> {
+ List<ProjectHiddenDangerTrendVo> resultList = map.entrySet().stream().map(entry -> {
ProjectHiddenDangerTrendVo vo = new ProjectHiddenDangerTrendVo();
vo.setName(entry.getKey());
List<Record> value = entry.getValue();
@@ -61,23 +68,105 @@
int num = vo.getThisMonth() - vo.getLastMonth();
if (num != 0) {
if(vo.getLastMonth()>0){
- String rate = BigDecimal.valueOf(num).divide(BigDecimal.valueOf(vo.getLastMonth()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString();
+ Double rate = BigDecimal.valueOf(num).divide(BigDecimal.valueOf(vo.getLastMonth()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).doubleValue();
vo.setRate(rate);
}else {
- vo.setRate("100.00");
+ vo.setRate(100.00d);
}
}else {
- vo.setRate("0.00");
+ vo.setRate(0.00d);
}
return vo;
}).toList();
- return collect;
+ return resultList;
}
+ @Override
+ public List<ProjectHiddenDangerList> getProjectHiddenDangerTrendList(ProjectHiddenDangerTrendListQuery query) {
+ List<Record> list = this.baseMapper.getProjectHiddenDangerTrend(query.getProjectId(),getMonthBoundaries(query.getStartTime(),true)+" 00:00:00",getMonthBoundaries(query.getEndTime(),false)+" 23:59:59");
+ for (Record record : list) {
+ String hierarchyNames = record.getHierarchyNames();
+ JSONArray jsonArray = JSONArray.parseArray(hierarchyNames);
+ // 取出倒数第4个
+ String name = jsonArray.getString(jsonArray.size()-4);
+ record.setHierarchyName( name);
+ }
+
+ // 算出跨度几个月
+ int months = calculateMonthsBetween(query.getStartTime(),query.getEndTime());
+
+
+ ArrayList<ProjectHiddenDangerList> projectHiddenDangerLists = new ArrayList<>();
+
+ Map<String, List<Record>> map = list.stream().collect(groupingBy(Record::getHierarchyName));
+ for (Map.Entry<String, List<Record>> stringListEntry : map.entrySet()) {
+ String key = stringListEntry.getKey();
+ if(query.getContent()!=null && !query.getContent().isEmpty()){
+ if(!key.contains( query.getContent())){
+ continue;
+ }
+ }
+
+ List<Record> value = stringListEntry.getValue();
+ ProjectHiddenDangerList projectHiddenDangerList1 = new ProjectHiddenDangerList();
+ projectHiddenDangerList1.setName(key);
+ ArrayList<ProjectHiddenDangerNextList> projectHiddenDangerNextLists = new ArrayList<>();
+ for (int i = 0; i < months; i++) {
+ ProjectHiddenDangerNextList projectHiddenDangerNextList = new ProjectHiddenDangerNextList();
+ LocalDate localDate = getMonthBoundaries(query.getStartTime(), true).plusMonths(i);
+ String dateStr = localDate.toString().substring(0, 7);
+ long count = value.stream().filter(record -> record.getCreateTime().toString().contains(dateStr)).count();
+ ProjectHiddenDangerList projectHiddenDangerList = new ProjectHiddenDangerList();
+ projectHiddenDangerList.setName(key);
+ projectHiddenDangerNextList.setTime(dateStr);
+ projectHiddenDangerNextList.setNum((int) count);
+ projectHiddenDangerNextLists.add(projectHiddenDangerNextList);
+ }
+ projectHiddenDangerList1.setList(projectHiddenDangerNextLists);
+ projectHiddenDangerLists.add(projectHiddenDangerList1);
+ }
+
+ return projectHiddenDangerLists;
+
+ }
+
+
+ public static LocalDate getMonthBoundaries(String yearMonthStr,boolean isInclusive) {
+ // 解析字符串为YearMonth
+ YearMonth yearMonth = YearMonth.parse(yearMonthStr);
+ if(isInclusive){
+ // 获取第一天
+ LocalDate firstDay = yearMonth.atDay(1);
+ return firstDay;
+ }else {
+ // 获取最后一天
+ LocalDate lastDay = yearMonth.atEndOfMonth();
+ return lastDay;
+ }
+ }
+
+
+
+ public static int calculateMonthsBetween(String startYearMonth, String endYearMonth) {
+ YearMonth start = YearMonth.parse(startYearMonth);
+ YearMonth end = YearMonth.parse(endYearMonth);
+
+ // 计算月份差 + 1(包含结束月份)
+ return (int) ChronoUnit.MONTHS.between(start, end) + 1;
+ }
public static void main(String[] args) {
- LocalDate lastMonth = LocalDate.now().minusMonths(0).with(TemporalAdjusters.firstDayOfMonth());
- System.out.println(lastMonth+" 23:59:59");
+ LocalDate monthBoundaries = getMonthBoundaries("2025-03", true);
+ System.out.println(monthBoundaries);
+ System.out.println(getMonthBoundaries("2025-02",false));
+
+ System.out.println(calculateMonthsBetween("2025-03", "2026-01"));
+
+ for (int count = 0; count < 11; count++) {
+ // 根据2025-03 根据循环获取下一个月的时间
+ LocalDate monthBoundaries1 = getMonthBoundaries("2025-03", true).plusMonths(count);
+ System.out.println(monthBoundaries1.toString().substring(0,7));
+ }
}
}
--
Gitblit v1.7.1