From 1c973a8fd4e126c3dbd9b95af68a963363b35a34 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 21 一月 2026 17:20:12 +0800
Subject: [PATCH] 大屏项目接口
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java | 25 ++++++
ruoyi-system/src/main/java/com/ruoyi/system/vo/DeviceDetailCheckListVo.java | 6 +
ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerNextList.java | 16 ++++
ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java | 2
ruoyi-system/src/main/java/com/ruoyi/system/query/ProjectHiddenDangerTrendListQuery.java | 29 +++++++
ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerList.java | 20 +++++
ruoyi-system/src/main/resources/mapper/system/RecordMapper.xml | 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java | 105 ++++++++++++++++++++++++--
ruoyi-system/src/main/java/com/ruoyi/system/service/ProjectInfoService.java | 5 +
ruoyi-system/src/main/resources/mapper/system/ProjectMapper.xml | 5
10 files changed, 202 insertions(+), 13 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java
index e1c896b..34c6365 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java
@@ -22,6 +22,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -280,9 +281,31 @@
@ApiOperation(value = "各分项隐患趋势")
@GetMapping("/getProjectHiddenDangerTrend")
- public R<List<ProjectHiddenDangerTrendVo>> getProjectHiddenDangerTrend(@RequestParam Integer projectId) {
+ public R<List<ProjectHiddenDangerTrendVo>> getProjectHiddenDangerTrend(@RequestParam Integer projectId,@RequestParam(value = "desc", required = true) Boolean desc,@RequestParam(value = "type", required = true)Integer type) {
List<ProjectHiddenDangerTrendVo> list = projectInfoService.getProjectHiddenDangerTrend(projectId);
+ if(type==1){
+ if(desc){
+ list = list.stream().sorted(Comparator.comparingInt(ProjectHiddenDangerTrendVo::getThisMonth).reversed()).toList();
+ }else {
+ list = list.stream().sorted(Comparator.comparingInt(ProjectHiddenDangerTrendVo::getThisMonth)).toList();
+ }
+ }else {
+ if(desc){
+ list = list.stream().sorted(Comparator.comparingDouble(ProjectHiddenDangerTrendVo::getRate).reversed()).toList();
+ }else {
+ list = list.stream().sorted(Comparator.comparingDouble(ProjectHiddenDangerTrendVo::getRate)).toList();
+ }
+ }
+
return R.ok(list);
}
+
+ @ApiOperation(value = "各分项隐患趋势列表")
+ @PostMapping("/getProjectHiddenDangerTrendList")
+ public R<List<ProjectHiddenDangerList>> getProjectHiddenDangerTrendList(@RequestBody @Valid ProjectHiddenDangerTrendListQuery query) {
+ List<ProjectHiddenDangerList> list = projectInfoService.getProjectHiddenDangerTrendList(query);
+ return R.ok(list);
+ }
+
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/query/ProjectHiddenDangerTrendListQuery.java b/ruoyi-system/src/main/java/com/ruoyi/system/query/ProjectHiddenDangerTrendListQuery.java
new file mode 100644
index 0000000..24c0cd7
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/query/ProjectHiddenDangerTrendListQuery.java
@@ -0,0 +1,29 @@
+package com.ruoyi.system.query;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+@Data
+@ApiModel("项目隐患趋势列表查询参数")
+public class ProjectHiddenDangerTrendListQuery {
+
+ @ApiModelProperty("项目id")
+ @NotNull(message = "项目id不能为空")
+ private Integer projectId;
+
+ @ApiModelProperty("开始时间")
+ @NotBlank(message = "开始时间不能为空")
+ private String startTime;
+
+ @ApiModelProperty("结束时间")
+ @NotBlank(message = "结束时间不能为空")
+ private String endTime;
+
+ @ApiModelProperty("内容")
+ private String content;
+}
+
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ProjectInfoService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ProjectInfoService.java
index bc2d67e..91ce556 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ProjectInfoService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ProjectInfoService.java
@@ -2,8 +2,11 @@
import com.ruoyi.system.model.ProjectInfo;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.system.query.ProjectHiddenDangerTrendListQuery;
+import com.ruoyi.system.vo.ProjectHiddenDangerList;
import com.ruoyi.system.vo.ProjectHiddenDangerTrendVo;
+import javax.validation.Valid;
import java.util.List;
/**
@@ -18,4 +21,6 @@
List<ProjectHiddenDangerTrendVo> getProjectHiddenDangerTrend(Integer projectId);
+ List<ProjectHiddenDangerList> getProjectHiddenDangerTrendList(@Valid ProjectHiddenDangerTrendListQuery query);
+
}
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));
+ }
}
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/vo/DeviceDetailCheckListVo.java b/ruoyi-system/src/main/java/com/ruoyi/system/vo/DeviceDetailCheckListVo.java
index 7a7b26e..7ad7afc 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/vo/DeviceDetailCheckListVo.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/vo/DeviceDetailCheckListVo.java
@@ -36,4 +36,10 @@
private Integer commentType=1;
+ @ApiModelProperty("设备报告 1有 0无")
+ private Integer containDeviceRes;
+
+ @ApiModelProperty("安全报告 1有 0无")
+ private Integer containSystemRes;
+
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerList.java b/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerList.java
new file mode 100644
index 0000000..c637d30
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerList.java
@@ -0,0 +1,20 @@
+package com.ruoyi.system.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@ApiModel("项目隐患列表")
+public class ProjectHiddenDangerList {
+
+ @ApiModelProperty("名称")
+ private String name;
+
+
+ @ApiModelProperty("数量集合")
+ private List<ProjectHiddenDangerNextList> list;
+
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerNextList.java b/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerNextList.java
new file mode 100644
index 0000000..91312a0
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerNextList.java
@@ -0,0 +1,16 @@
+package com.ruoyi.system.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel("项目隐患二级列表")
+public class ProjectHiddenDangerNextList {
+ @ApiModelProperty("数量")
+ private Integer num;
+
+
+ @ApiModelProperty("时间")
+ private String time;
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java b/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java
index 4fc96d8..63a04b1 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java
@@ -18,5 +18,5 @@
private Integer lastMonth;
@ApiModelProperty("环比趋势")
- private String rate;
+ private Double rate;
}
diff --git a/ruoyi-system/src/main/resources/mapper/system/ProjectMapper.xml b/ruoyi-system/src/main/resources/mapper/system/ProjectMapper.xml
index 11f3bff..11859e2 100644
--- a/ruoyi-system/src/main/resources/mapper/system/ProjectMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/ProjectMapper.xml
@@ -22,10 +22,11 @@
<result column="usage_type" property="usageType" />
<result column="creator_id" property="creatorId" />
<result column="client_id" property="clientId" />
- <result column="premission" property="premission" />
+ <result column="permission" property="permission" />
</resultMap>
<select id="getDeviceDetailCheckList" resultType="com.ruoyi.system.vo.DeviceDetailCheckListVo">
- select t1.id,t2.name planName,t2.type planType,t1.date checkTime,t2.system_fuzzy fuzzyScore,t2.system_score score,t3.risk_level riskLevel
+ select t1.id,t2.name planName,t2.type planType,t1.date checkTime,t1.system_fuzzy fuzzyScore,t1.system_score score,t3.risk_level riskLevel,
+ t3.contain_device_res ,t3.contain_system_res
from task t1
left join plan t2 on t1.plan_id = t2.id
left join eval_result t3 on t1.id = t3.check_task_id
diff --git a/ruoyi-system/src/main/resources/mapper/system/RecordMapper.xml b/ruoyi-system/src/main/resources/mapper/system/RecordMapper.xml
index bd677ae..b359e23 100644
--- a/ruoyi-system/src/main/resources/mapper/system/RecordMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/RecordMapper.xml
@@ -42,7 +42,7 @@
left join problem t2 on t1.problem_id = t2.id
left join task t3 on t1.check_task_id = t3.id
left join plan t4 on t3.plan_id = t4.id
- where t1.deleted = 0
+ where t1.deleted = 0 and t1.level is not null
and t1.check_task_id in
<foreach item="item" index="index" collection="taskIds" open="(" separator="," close=")">
#{item}
--
Gitblit v1.7.1