liujie
2026-04-02 de462cca87a041cc73889be62986db8446a24ef2
修改bug
7个文件已修改
269 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-test.yml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/model/Record.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceUsageServiceImpl.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java 180 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/DeviceUsageMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ProjectController.java
@@ -184,6 +184,23 @@
        return R.ok(hiddenDangerVo);
    }
    @ApiOperation(value = "获取项目所有隐患数量",response = HiddenDangerVo.class)
    @GetMapping("/getProjectHiddenDangerCountAll/{id}")
    public R<HiddenDangerVo> getProjectHiddenDangerCountAll(@PathVariable Integer id) {
        HiddenDangerVo hiddenDangerVo = new HiddenDangerVo();
        List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getProjectId, id));
        if(!list.isEmpty()){
            List<Integer> taskIds = list.stream().map(Task::getId).collect(Collectors.toList());
            // 0是一级隐患
            List<Record> records = recordService.list(new LambdaQueryWrapper<Record>().eq(Record::getDeleted, 0).in(Record::getCheckTaskId, taskIds));
            hiddenDangerVo.setSerious(records.size());
            int rectified = records.stream().filter(Record::getReformed).collect(Collectors.toList()).size();
            hiddenDangerVo.setRectified(rectified);
            hiddenDangerVo.setUnRectified(records.size()-rectified);
        }
        return R.ok(hiddenDangerVo);
    }
    @ApiOperation(value = "获取设备数量",response = DeviceCountVo.class)
    @GetMapping("/getProjectDeviceCount/{id}")
    public R<List<DeviceCountVo>> getProjectDeviceCount(@PathVariable Integer id) {
ruoyi-admin/src/main/resources/application-test.yml
@@ -95,7 +95,7 @@
    druid:
      # 主库数据源
      master:
        url: jdbc:mysql://192.168.110.111:3306/estate_expert?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai
        url: jdbc:mysql://192.168.110.111:3306/estate?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: 123456
      # 从库数据源
ruoyi-system/src/main/java/com/ruoyi/system/model/Record.java
@@ -74,4 +74,11 @@
    private String responsiblePerson;
    /**
     * 用于区分分类  1本轮 2上轮
     */
    @TableField(exist = false)
    private int category;
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceUsageServiceImpl.java
@@ -418,7 +418,7 @@
    @Override
    public List<EntrustDeviceListVo> deviceList(Page<EntrustDeviceListVo> page, EntrustDeviceListQuery query) {
        String startTime = query.getStartTime().replace("年", "-").replace("月", "-").replace("日", "-");
        String startTime = query.getStartTime();
        String endTime = query.getEndTime();
        // 查询在建工程项目(usage_type 表示项目用途类型,假设 0 表示在建工程)
@@ -435,7 +435,7 @@
                                .eq(Project::getStatus, 1)  // 在建项目
                                .or(w -> w
                                        .eq(Project::getStatus, 2)  // 已完成项目
                                        .between(Project::getSuccessTime, startTime, endTime)  // 完成时间 >= 开始日期// 完成时间 <= 结束日期
                                        // 完成时间 >= 开始日期// 完成时间 <= 结束日期
                                )
                        );
                break;
@@ -447,66 +447,33 @@
                                .eq(Project::getStatus, 1)  // 在建项目
                                .or(w -> w
                                        .eq(Project::getStatus, 2)  // 已完成项目
                                        .between(Project::getSuccessTime, startTime, endTime)  // 完成时间 >= 开始日期// 完成时间 <= 结束日期
                                          // 完成时间 >= 开始日期// 完成时间 <= 结束日期
                                )
                        );
                break;
        }
        List<Integer> projectIds = projectMapper.selectList(projectWrapper).stream().map(Project::getId).collect(Collectors.toList());
        if(projectIds.isEmpty()){
            projectIds.add(-1);
        }
        query.setProjectIds(projectIds);
        List<EntrustDeviceListVo> deviceList = this.baseMapper.deviceList(page, query);
        List<Integer> deviceIds = deviceList.stream().map(EntrustDeviceListVo::getId).collect(Collectors.toList());
        if (deviceIds.isEmpty()) {
            deviceIds.add(-1);
        }
        LambdaQueryWrapper<Record> recordWrapper = new LambdaQueryWrapper<>();
        recordWrapper.eq(Record::getRecordType, "error")
                .isNotNull(Record::getDeviceId)
                .in(Record::getDeviceId, deviceIds)
                .eq(Record::getDeleted, false);
        List<Record> records = recordMapper.selectList(recordWrapper);
        List<Integer> deviceIdsRecord = records.stream().map(Record::getDeviceId).distinct().collect(Collectors.toList());
        for (EntrustDeviceListVo deviceListVo : deviceList) {
            if (deviceIdsRecord.contains(deviceListVo.getId())) {
                Record record = records.stream().filter(e -> e.getDeviceId().equals(deviceListVo.getId())).findFirst()
                        .orElse(null);
                if (record != null) {
                    Task task = taskMapper.selectById(record.getCheckTaskId());
                    if (task != null) {
                        deviceListVo.setCheckTime(task.getCreateTime());
                    }
                    deviceListVo.setCheckResult("已检查");
                }
            if (deviceListVo.getCheckTime() != null) {
                deviceListVo.setCheckResult("已检查");
            } else {
                deviceListVo.setCheckResult("未检查");
                deviceListVo.setCheckTime(null);
            }
//
//            LocalDateTime checkTime = deviceListVo.getCheckTime();
//            // 判断checkTime是否是本月的时间
//            if (checkTime != null && YearMonth.from(checkTime).equals(YearMonth.now())) {
//                deviceListVo.setCheckResult("已检查");
//            }else {
//                deviceListVo.setCheckResult("未检查");
//            }
        }
        return deviceList;
    }
    @Override
    public List<ErrorListVo> errorList(Page<ErrorListVo> page, ErrorListQuery query) throws ParseException {
        String startTime;
        String endTime;
        String startTime=query.getStartTime();
        String endTime=query.getEndTime();
        // 查询在建工程项目(usage_type 表示项目用途类型,假设 0 表示在建工程)
        if (StringUtils.hasLength(query.getStartTime())) {
            startTime = query.getStartTime().replace("年", "-").replace("月", "-").replace("日", "-");
            endTime = query.getEndTime();
        } else {
            endTime = "";
            startTime = "";
        }
        LambdaQueryWrapper<Project> projectWrapper = new LambdaQueryWrapper<>();
        if(query.getCategory()!=null) {
            switch (query.getCategory()) {
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java
@@ -1,16 +1,16 @@
package com.ruoyi.system.service.impl;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.mapper.ProjectInfoMapper;
import com.ruoyi.system.model.Project;
import com.ruoyi.system.model.ProjectInfo;
import com.ruoyi.system.model.Record;
import com.ruoyi.system.model.Task;
import com.ruoyi.system.query.ProjectDangerousTrendQuery;
import com.ruoyi.system.query.ProjectHiddenDangerTrendListQuery;
import com.ruoyi.system.service.ProjectCategoryCalculator;
import com.ruoyi.system.service.ProjectInfoService;
import com.ruoyi.system.service.ProjectService;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.ProjectDangerousTrendVo;
import com.ruoyi.system.vo.ProjectHiddenDangerList;
import com.ruoyi.system.vo.ProjectHiddenDangerNextList;
@@ -26,10 +26,7 @@
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import static java.util.stream.Collectors.groupingBy;
@@ -51,56 +48,144 @@
    @Autowired
    private ProjectService projectService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private RecordService recordService;
    @Override
    public List<ProjectHiddenDangerTrendVo> getProjectHiddenDangerTrend(Integer projectId) {
        // 获取上月第一天的时间
        LocalDate lastMonth = LocalDate.now().minusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
        List<Record> list = this.baseMapper.getProjectHiddenDangerTrend(projectId,lastMonth+" 00:00:00",LocalDate.now()+" 23:59:59");
        for (Record record : list) {
            String hierarchyNames = record.getHierarchyNames();
            JSONArray jsonArray = JSONArray.parseArray(hierarchyNames);
            if(record.getDeviceId()!=null){
                // 取出倒数第3个
                String name = jsonArray.getString(jsonArray.size()-3);
                record.setHierarchyName( name);
            }else {
                // 取出倒数第4个
                String name = jsonArray.getString(jsonArray.size()-4);
                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> resultList = new ArrayList<>();
        for (Map.Entry<String, List<Record>> entry : map.entrySet()) {
            ProjectHiddenDangerTrendVo vo = new ProjectHiddenDangerTrendVo();
            vo.setName(entry.getKey());
            List<Record> value = entry.getValue();
            long count = value.stream().filter(record -> record.getCreateTime().isAfter(thisMonth.atStartOfDay())).count();
            // 根据value集合中的createTime 选出本月的数据
            vo.setThisMonth((int) count);
            vo.setLastMonth(value.size()-(int) count);
        // 找出最近的的2个计划任务
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getProjectId, projectId).in(Task::getState, Arrays.asList(3,7)).orderByDesc(Task::getCreateTime).last("limit 2"));
        if(tasks.size()==1){
            Task task = tasks.get(0);
            List<Record> list0 = recordService.list(new LambdaQueryWrapper<Record>().eq(Record::getCheckTaskId, task.getId()));
            for (Record record : list0) {
                String hierarchyNames = record.getHierarchyNames();
                JSONArray jsonArray = JSONArray.parseArray(hierarchyNames);
                if(record.getDeviceId()!=null){
                    // 取出倒数第3个
                    String name = jsonArray.getString(jsonArray.size()-3);
            int num = vo.getThisMonth() - vo.getLastMonth();
            if (num != 0) {
                if(vo.getLastMonth()>0){
                    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);
                    record.setHierarchyName( name);
                }else {
                    vo.setRate(100.00d);
                    // 取出倒数第4个
                    String name = jsonArray.getString(jsonArray.size()-4);
                    record.setHierarchyName( name);
                    record.setCategory(1);
                }
            }else {
                vo.setRate(0.00d);
            }
            resultList.add(vo) ;
            Map<String, List<Record>> map = list0.stream().collect(groupingBy(Record::getHierarchyName));
            for (Map.Entry<String, List<Record>> entry : map.entrySet()) {
                ProjectHiddenDangerTrendVo vo = new ProjectHiddenDangerTrendVo();
                vo.setName(entry.getKey());
                List<Record> value = entry.getValue();
                long count = value.stream().filter(record -> record.getCategory()==1).count();
                // 根据value集合中的createTime 选出本月的数据
                vo.setThisMonth((int) count);
                vo.setLastMonth(0);
                int num = vo.getThisMonth() - vo.getLastMonth();
                if (num != 0) {
                    if(vo.getLastMonth()>0){
                        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.00d);
                    }
                }else {
                    vo.setRate(0.00d);
                }
                resultList.add(vo) ;
            }
        }
        if(tasks.size()==2){
            Task task0 = tasks.get(0);
            List<Record> list0 = recordService.list(new LambdaQueryWrapper<Record>().eq(Record::getCheckTaskId, task0.getId()));
            for (Record record : list0) {
                String hierarchyNames = record.getHierarchyNames();
                JSONArray jsonArray = JSONArray.parseArray(hierarchyNames);
                if(record.getDeviceId()!=null){
                    // 取出倒数第3个
                    String name = jsonArray.getString(jsonArray.size()-3);
                    record.setHierarchyName( name);
                }else {
                    // 取出倒数第4个
                    String name = jsonArray.getString(jsonArray.size()-4);
                    record.setHierarchyName( name);
                    record.setCategory(1);
                }
            }
            Task task1 = tasks.get(1);
            List<Record> list1 = recordService.list(new LambdaQueryWrapper<Record>().eq(Record::getCheckTaskId, task1.getId()));
            for (Record record : list1) {
                String hierarchyNames = record.getHierarchyNames();
                JSONArray jsonArray = JSONArray.parseArray(hierarchyNames);
                if(record.getDeviceId()!=null){
                    // 取出倒数第3个
                    String name = jsonArray.getString(jsonArray.size()-3);
                    record.setHierarchyName( name);
                }else {
                    // 取出倒数第4个
                    String name = jsonArray.getString(jsonArray.size()-4);
                    record.setHierarchyName( name);
                    record.setCategory(2);
                }
            }
            list0.addAll(list1);
            Map<String, List<Record>> map = list0.stream().collect(groupingBy(Record::getHierarchyName));
            for (Map.Entry<String, List<Record>> entry : map.entrySet()) {
                ProjectHiddenDangerTrendVo vo = new ProjectHiddenDangerTrendVo();
                vo.setName(entry.getKey());
                List<Record> value = entry.getValue();
                long count = value.stream().filter(record -> record.getCategory()==1).count();
                // 根据value集合中的createTime 选出本月的数据
                vo.setThisMonth((int) count);
                vo.setLastMonth(value.size()-(int) count);
                int num = vo.getThisMonth() - vo.getLastMonth();
                if (num != 0) {
                    if(vo.getLastMonth()>0){
                        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.00d);
                    }
                }else {
                    vo.setRate(0.00d);
                }
                resultList.add(vo) ;
            }
        }
        return resultList;
    }
    @Override
@@ -186,15 +271,20 @@
                    Map<Integer, String> integerStringMap = projectCategoryCalculator.calculateFixedAssetCategories(projects, Long.valueOf(project.getClientId()), startDate, endDate);
                    String s = integerStringMap.get(query.getProjectId());
                    vo.setLevel(s);
                    if(integerStringMap.isEmpty()){
                        vo.setStatus(2);
                    }
                }else {
                    Map<Integer, String> integerStringMap = projectCategoryCalculator.calculateOngoingProjectCategories(projects, Long.valueOf(project.getClientId()), startDate, endDate);
                    String s = integerStringMap.get(query.getProjectId());
                    vo.setLevel(s);
                    if(integerStringMap.isEmpty()){
                        vo.setStatus(2);
                    }
                }
                // 如果没有则沿用上次的
                if(vo.getLevel()!=null){
                    temp=vo.getLevel();
                    vo.setStatus(2);
                }else {
                    vo.setLevel(temp);
                }
ruoyi-system/src/main/java/com/ruoyi/system/vo/ProjectHiddenDangerTrendVo.java
@@ -11,10 +11,10 @@
    @ApiModelProperty("隐患名称")
    private String name;
    @ApiModelProperty("本月数量")
    @ApiModelProperty("本轮数量")
    private Integer thisMonth;
    @ApiModelProperty("上月数量")
    @ApiModelProperty("上轮数量")
    private Integer lastMonth;
    @ApiModelProperty("环比趋势")
ruoyi-system/src/main/resources/mapper/system/DeviceUsageMapper.xml
@@ -73,6 +73,12 @@
        <if test="query.content!= null and query.content!=''">
            and t2.name like CONCAT('%', #{query.content}, '%')
        </if>
        <if test="query.startTime != null and query.startTime != ''">
            and latest.record_time >= #{query.startTime}
        </if>
        <if test="query.endTime != null and query.endTime != ''">
            and #{query.endTime} >= latest.record_time
        </if>
        order by latest.record_time desc
    </select>