zxl
2025-04-10 1f11310ba04770a4efe4657d39872590575828f1
设备未知状态,新增,导出页新增统计一个月的离线数,与在线率
4个文件已修改
2个文件已添加
644 ■■■■■ 已修改文件
ycl-pojo/src/main/java/com/ycl/platform/domain/excel/VideoDailyExp.java 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/excel/VideoOnlineRateExp.java 141 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/excel/VideoTypeOffOnlineExp.java 153 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java 276 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/task/UYTask.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/excel/VideoDailyExp.java
@@ -1,7 +1,12 @@
package com.ycl.platform.domain.excel;
import annotation.Excel;
import com.ycl.platform.domain.result.SYS.TMonitorResult;
import lombok.Data;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.util.List;
@Data
public class VideoDailyExp {
@@ -12,6 +17,14 @@
    /** 设备名称 */
    @Excel(name = "设备名称",width = 20)
    private String deviceName;
    /** 设备类型 **/
    private String type;
    /** 改设备当月在线情况 **/
    private List<TMonitorResult> onlineStateList;
    /** 内部处理用 */
    private LocalDate mongoCreateTime;
    /** 标签 */
    @Excel(name = "标签")
@@ -145,5 +158,56 @@
    @Excel(name = "31",width = 10)
    private String day31;
    public boolean isAllOfflineByMonth() {
        boolean allOffline = true;
        try {
            // 遍历 day1 到 day31
            for (int i = 1; i <= 31; i++) {
                // 构造字段名
                String fieldName = "day" + i;
                // 获取字段
                Field field = this.getClass().getDeclaredField(fieldName);
                // 确保字段是私有的可以访问
                field.setAccessible(true);
                // 获取字段值
                String value = (String) field.get(this);
                // 检查值是否为 "离线"
                if (!"离线".equals(value)) {
                    allOffline = false;
                    break;
                }
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return allOffline;
    }
    public long getAllOnlineDayCountByMonth() {
        long count = 0;
        try {
            // 遍历 day1 到 day31
            for (int i = 1; i <= 31; i++) {
                // 构造字段名
                String fieldName = "day" + i;
                // 获取字段
                Field field = this.getClass().getDeclaredField(fieldName);
                // 确保字段是私有的可以访问
                field.setAccessible(true);
                // 获取字段值
                String value = (String) field.get(this);
                // 检查值是否为 "在线"
                if ("在线".equals(value)) {
                    count++;
                }
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return count;
    }
}
ycl-pojo/src/main/java/com/ycl/platform/domain/excel/VideoOnlineRateExp.java
New file
@@ -0,0 +1,141 @@
package com.ycl.platform.domain.excel;
import annotation.Excel;
import lombok.Data;
//在线率统计
@Data
public class VideoOnlineRateExp {
    //区域
    @Excel(name="区域",width = 20)
    private String area;
    //1人脸 2车辆 3视频
    //设备类型
    @Excel(name="设备类型",width = 20)
    private String type;
    /** 日期 */
    @Excel(name = "1",width = 10)
    private String day1;
    /** 日期 */
    @Excel(name = "2",width = 10)
    private String day2;
    /** 日期 */
    @Excel(name = "3",width = 10)
    private String day3;
    /** 日期 */
    @Excel(name = "4",width = 10)
    private String day4;
    /** 日期 */
    @Excel(name = "5",width = 10)
    private String day5;
    /** 日期 */
    @Excel(name = "6",width = 10)
    private String day6;
    /** 日期 */
    @Excel(name = "7",width = 10)
    private String day7;
    /** 日期 */
    @Excel(name = "8",width = 10)
    private String day8;
    /** 日期 */
    @Excel(name = "9",width = 10)
    private String day9;
    /** 日期 */
    @Excel(name = "10",width = 10)
    private String day10;
    /** 日期 */
    @Excel(name = "11",width = 10)
    private String day11;
    /** 日期 */
    @Excel(name = "12",width = 10)
    private String day12;
    /** 日期 */
    @Excel(name = "13",width = 10)
    private String day13;
    /** 日期 */
    @Excel(name = "14",width = 10)
    private String day14;
    /** 日期 */
    @Excel(name = "15",width = 10)
    private String day15;
    /** 日期 */
    @Excel(name = "16",width = 10)
    private String day16;
    /** 日期 */
    @Excel(name = "17",width = 10)
    private String day17;
    /** 日期 */
    @Excel(name = "18",width = 10)
    private String day18;
    /** 日期 */
    @Excel(name = "19",width = 10)
    private String day19;
    /** 日期 */
    @Excel(name = "20",width = 10)
    private String day20;
    /** 日期 */
    @Excel(name = "21",width = 10)
    private String day21;
    /** 日期 */
    @Excel(name = "22",width = 10)
    private String day22;
    /** 日期 */
    @Excel(name = "23",width = 10)
    private String day23;
    /** 日期 */
    @Excel(name = "24",width = 10)
    private String day24;
    /** 日期 */
    @Excel(name = "25",width = 10)
    private String day25;
    /** 日期 */
    @Excel(name = "26",width = 10)
    private String day26;
    /** 日期 */
    @Excel(name = "27",width = 10)
    private String day27;
    /** 日期 */
    @Excel(name = "28",width = 10)
    private String day28;
    /** 日期 */
    @Excel(name = "29",width = 10)
    private String day29;
    /** 日期 */
    @Excel(name = "30",width = 10)
    private String day30;
    /** 日期 */
    @Excel(name = "31",width = 10)
    private String day31;
}
ycl-pojo/src/main/java/com/ycl/platform/domain/excel/VideoTypeOffOnlineExp.java
New file
@@ -0,0 +1,153 @@
package com.ycl.platform.domain.excel;
import annotation.Excel;
import lombok.Data;
//离线数统计
@Data
public class VideoTypeOffOnlineExp {
    //区域
    @Excel(name="区域",width = 20)
    private String area;
    //1人脸 2车辆 3视频
    //设备类型
    @Excel(name="设备类型",width = 20)
    private String type;
    //离线数量
    @Excel(name="离线数量",width = 20)
    private String offlineCount;
    /** 日期 */
    @Excel(name = "1",width = 10)
    private String day1;
    /** 日期 */
    @Excel(name = "2",width = 10)
    private String day2;
    /** 日期 */
    @Excel(name = "3",width = 10)
    private String day3;
    /** 日期 */
    @Excel(name = "4",width = 10)
    private String day4;
    /** 日期 */
    @Excel(name = "5",width = 10)
    private String day5;
    /** 日期 */
    @Excel(name = "6",width = 10)
    private String day6;
    /** 日期 */
    @Excel(name = "7",width = 10)
    private String day7;
    /** 日期 */
    @Excel(name = "8",width = 10)
    private String day8;
    /** 日期 */
    @Excel(name = "9",width = 10)
    private String day9;
    /** 日期 */
    @Excel(name = "10",width = 10)
    private String day10;
    /** 日期 */
    @Excel(name = "11",width = 10)
    private String day11;
    /** 日期 */
    @Excel(name = "12",width = 10)
    private String day12;
    /** 日期 */
    @Excel(name = "13",width = 10)
    private String day13;
    /** 日期 */
    @Excel(name = "14",width = 10)
    private String day14;
    /** 日期 */
    @Excel(name = "15",width = 10)
    private String day15;
    /** 日期 */
    @Excel(name = "16",width = 10)
    private String day16;
    /** 日期 */
    @Excel(name = "17",width = 10)
    private String day17;
    /** 日期 */
    @Excel(name = "18",width = 10)
    private String day18;
    /** 日期 */
    @Excel(name = "19",width = 10)
    private String day19;
    /** 日期 */
    @Excel(name = "20",width = 10)
    private String day20;
    /** 日期 */
    @Excel(name = "21",width = 10)
    private String day21;
    /** 日期 */
    @Excel(name = "22",width = 10)
    private String day22;
    /** 日期 */
    @Excel(name = "23",width = 10)
    private String day23;
    /** 日期 */
    @Excel(name = "24",width = 10)
    private String day24;
    /** 日期 */
    @Excel(name = "25",width = 10)
    private String day25;
    /** 日期 */
    @Excel(name = "26",width = 10)
    private String day26;
    /** 日期 */
    @Excel(name = "27",width = 10)
    private String day27;
    /** 日期 */
    @Excel(name = "28",width = 10)
    private String day28;
    /** 日期 */
    @Excel(name = "29",width = 10)
    private String day29;
    /** 日期 */
    @Excel(name = "30",width = 10)
    private String day30;
    /** 日期 */
    @Excel(name = "31",width = 10)
    private String day31;
}
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
@@ -3,14 +3,11 @@
import annotation.DataScope;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mongodb.ExplainVerbosity;
import com.mongodb.client.AggregateIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.ycl.platform.domain.entity.TMonitor;
import com.ycl.platform.domain.excel.TMonitorExp;
import com.ycl.platform.domain.excel.VideoDailyExp;
import com.ycl.platform.domain.excel.VideoTotalExp;
import com.ycl.platform.domain.excel.*;
import com.ycl.platform.domain.form.VideoExportForm;
import com.ycl.platform.domain.query.DashboardQuery;
import com.ycl.platform.domain.query.DataCenterQuery;
@@ -37,7 +34,6 @@
import com.ycl.platform.service.ITMonitorService;
import com.ycl.system.Result;
import com.ycl.system.entity.SysDictData;
import com.ycl.system.mapper.SysConfigMapper;
import com.ycl.system.mapper.SysDictDataMapper;
import com.ycl.system.page.PageUtil;
import com.ycl.system.service.ISysConfigService;
@@ -45,13 +41,12 @@
import com.ycl.utils.StringUtils;
import com.ycl.utils.poi.ExcelUtil;
import constant.ApiConstants;
import constant.CheckConstants;
import enumeration.general.AreaDeptEnum;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Validate;
import org.bson.Document;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
@@ -68,17 +63,13 @@
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -89,6 +80,7 @@
 * @date 2024-03-04
 */
@Service
@Slf4j
public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService {
    @Autowired
    private TMonitorMapper tMonitorMapper;
@@ -570,6 +562,8 @@
     */
    @Override
    public void exportVideoOnline(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
        log.error("开始导出数据");
        log.error("传入的月份:{}",exportForm.getMonth());
        //默认查所有部门
        if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
            List<Integer> deptIds = new ArrayList<>();
@@ -585,6 +579,7 @@
        Query query = getQuery(exportForm);
        //月份每日在线数据
        List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
        log.error("月份在线数据:{}条数",onlineResult.size());
        // 使用 Collectors.toMap 去重,保留每个 No 的第一个遇到的元素
        Map<String, TMonitorResult> uniqueResultsMap = onlineResult.stream()
                .collect(Collectors.toMap(
@@ -594,6 +589,7 @@
                ));
        // 将 Map 转换为 List
        List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
        log.error("去重后大小:{}",tMonitorResults.size());
        //获取动态列数据
        List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
        List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
@@ -605,6 +601,8 @@
                tMonitorResult.setDynamicColumnList(map.get(pointId));
            }
        }
        //存放区域 与 设备列表 map key为 区域
        Map<Integer, List<VideoDailyExp>> map = new HashMap<>();
        List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
        for (Integer deptId : exportForm.getDeptIds()) {
            CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
@@ -628,6 +626,8 @@
                    VideoDailyExp videoDailyExp = new VideoDailyExp();
                    videoDailyExp.setSerialNumber(result.getNo());
                    videoDailyExp.setDeviceName(result.getName());
                    videoDailyExp.setType(result.getMonitorType());
                    videoDailyExp.setArea(areaDeptEnum == null ? "未知" : areaDeptEnum.getName());
                    StringBuilder tag = new StringBuilder("" +
@@ -663,19 +663,267 @@
                );
                mysheet.add(excelExp);
                return videoDailyExps;
            }, threadPoolTaskExecutor);
            futures.add(future);
            map.put(deptId,future.join());
        }
        // 获取全量数据
        List<VideoDailyExp> totalExps = futures.stream()
                .map(CompletableFuture::join)
                .flatMap(List::stream)
                .collect(Collectors.toList());
        log.error("打印全量数据:{}",totalExps);
        ExcelExp excelExp = new ExcelExp("全量", totalExps, VideoDailyExp.class);
        mysheet.add(excelExp);
        //添加新的sheet 离线数统计表
        List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps = new ArrayList<>();
        //插入excel时确保数据出现在最后
        List<VideoTypeOffOnlineExp> allVideoTypeOffOnlineExps = new ArrayList<>();
        //在线率统计表
        List<VideoOnlineRateExp> videoOnlineRateExps = new ArrayList<>();
        //插入excel时确保数据出现在最后
        List<VideoOnlineRateExp> allVideoOnlineRateExps = new ArrayList<>();
        for (Integer deptId : map.keySet()){
            List<VideoDailyExp>  list = map.get(deptId);
            AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
            // 添加离线表记录
            //设备类型 1人脸 2车辆 3视频
            //人脸
            log.error("传入部门集合大小:{} + 部门id:{}" ,list.size(),deptId);
            VideoTypeOffOnlineExp faceVideoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"1",areaDeptEnum,false);
            //卡口
            VideoTypeOffOnlineExp carVideoTypeOffOnlineExp =this.getListOfflineCountInfo(list,"2",areaDeptEnum,false);
            //视频
            VideoTypeOffOnlineExp videoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"3",areaDeptEnum,false);
            VideoOnlineRateExp faceVideoOnlineRateExp = this.getListOnLineCountInfo(list,"1",areaDeptEnum,false);
            //卡口
            VideoOnlineRateExp carVideoOnlineRateExp =this.getListOnLineCountInfo(list,"2",areaDeptEnum,false);
            //视频
            VideoOnlineRateExp VideoOnlineRateExp = this.getListOnLineCountInfo(list,"3",areaDeptEnum,false);
            //将该区域类三种设备类型的 信息 放入 excel对象内
            //放入当前区域的人脸设备相关详细
            videoTypeOffOnlineExps.add(faceVideoTypeOffOnlineExp);
            //放入当前区域的车辆设备相关详细
            videoTypeOffOnlineExps.add(carVideoTypeOffOnlineExp);
            //放入当前区域的视频设备相关详细
            videoTypeOffOnlineExps.add(videoTypeOffOnlineExp);
            videoOnlineRateExps.add(faceVideoOnlineRateExp);
            videoOnlineRateExps.add(carVideoOnlineRateExp);
            videoOnlineRateExps.add(VideoOnlineRateExp);
            VideoTypeOffOnlineExp ALLfaceVideoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"1",areaDeptEnum,true);
            //卡口
            VideoTypeOffOnlineExp ALLcarVideoTypeOffOnlineExp =this.getListOfflineCountInfo(list,"2",areaDeptEnum,true);
            //视频
            VideoTypeOffOnlineExp ALLvideoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"3",areaDeptEnum,true);
            VideoOnlineRateExp ALLfaceVideoOnlineRateExp = this.getListOnLineCountInfo(list,"1",areaDeptEnum,true);
            //卡口
            VideoOnlineRateExp ALLcarVideoOnlineRateExp =this.getListOnLineCountInfo(list,"2",areaDeptEnum,true);
            //视频
            VideoOnlineRateExp ALLVideoOnlineRateExp = this.getListOnLineCountInfo(list,"3",areaDeptEnum,true);
            //添加合计数据
            allVideoTypeOffOnlineExps.add(ALLfaceVideoTypeOffOnlineExp);
            //放入当前区域的车辆设备相关详细
            allVideoTypeOffOnlineExps.add(ALLcarVideoTypeOffOnlineExp);
            //放入当前区域的视频设备相关详细
            allVideoTypeOffOnlineExps.add(ALLvideoTypeOffOnlineExp);
            allVideoOnlineRateExps.add(ALLfaceVideoOnlineRateExp);
            allVideoOnlineRateExps.add(ALLcarVideoOnlineRateExp);
            allVideoOnlineRateExps.add(ALLVideoOnlineRateExp);
        }
        videoTypeOffOnlineExps.addAll(allVideoTypeOffOnlineExps);
        videoOnlineRateExps.addAll(allVideoOnlineRateExps);
        log.error("打印计算离线的信息:{}" ,videoTypeOffOnlineExps );
        log.error("打印计在线的信息:{}" ,videoOnlineRateExps );
        //添加合计数据
        ExcelExp excelTypeOffLineExp = new ExcelExp("离线数统计", videoTypeOffOnlineExps, VideoTypeOffOnlineExp.class);
        mysheet.add(excelTypeOffLineExp);
        //添加在线率表
        ExcelExp excelOnlineRateExp = new ExcelExp("在线率统计",videoOnlineRateExps, VideoOnlineRateExp.class);
        mysheet.add(excelOnlineRateExp);
        ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
        util.exportExcelManySheet(response, mysheet);
        log.error("导出结束");
    }
    /**
     * 计算离线设备excel对象信息
     * @param videoDailyExps 传入的设备集合信息
     * @param type 设备类型 1人脸 2车辆 3视频
     * @param areaDeptEnum 区域
     * @return
     */
    public VideoTypeOffOnlineExp getListOfflineCountInfo(List<VideoDailyExp> videoDailyExps,
                                                         String type,
                                                         AreaDeptEnum areaDeptEnum,
                                                         boolean isTotal){
        VideoTypeOffOnlineExp videoTypeOffOnlineExp = new VideoTypeOffOnlineExp();
        List<VideoDailyExp> list = videoDailyExps.stream()
                .filter(device ->device.getType() != null && device.getType().contains(type)).collect(Collectors.toList());
        log.error("筛选完设备类型 :{} 后集合的大小:{}",type,list.size());
        //离线数量
        try {
            //设置离线数量 以及每日离线数量
            setVideoTypeOffOnlineExpCountAndDays(list,videoTypeOffOnlineExp,isTotal);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        //设备类型
        if(isTotal){
            if ("1".equals(type)){
                videoTypeOffOnlineExp.setType("人脸合计");
            }else if ("2".equals(type)){
                videoTypeOffOnlineExp.setType("卡口合计");
            }else if ("3".equals(type)){
                videoTypeOffOnlineExp.setType("视频合计");
            }
        }else {
            if ("1".equals(type)){
                videoTypeOffOnlineExp.setType("人脸");
            }else if ("2".equals(type)){
                videoTypeOffOnlineExp.setType("卡口");
            }else if ("3".equals(type)){
                videoTypeOffOnlineExp.setType("视频");
            }
        }
        //修改区域
        videoTypeOffOnlineExp.setArea(areaDeptEnum == null ? "未知" : areaDeptEnum.getName());
        return videoTypeOffOnlineExp;
    }
    private void setVideoTypeOffOnlineExpCountAndDays(List<VideoDailyExp> videoDailyExps,VideoTypeOffOnlineExp videoTypeOffOnlineExp,boolean isTotal)throws NoSuchFieldException, IllegalAccessException {
        //循环一个月
        //离线总数
        long AllOffLineCount = 0;
        log.error("传入集合大小:{}", videoDailyExps.size());
        for (VideoDailyExp videoDailyExp : videoDailyExps) {
            if (videoDailyExp.isAllOfflineByMonth()) {
                AllOffLineCount++;
            }
        }
        //是合计数据不需要下方数据
//        if (!isTotal) {
            for (int i = 1; i <= 31; i++) {
                //每日离线数
                long count = 0;
                String fieldName = "day" + i;
                for (VideoDailyExp videoDailyExp : videoDailyExps) {
                    // 构造字段名
                    Field field = videoDailyExp.getClass().getDeclaredField(fieldName);
                    // 确保字段是私有的可以访问
                    field.setAccessible(true);
                    // 获取字段值
                    String value = (String) field.get(videoDailyExp);
                    if ("离线".equals(value)) {
                        count++;
                    }
                }
                //反射添加到对象属性中
                Field field = videoTypeOffOnlineExp.getClass().getDeclaredField(fieldName);
                field.setAccessible(true);
                String rateStr = count + "";
                if (!"0".equals(rateStr)) {
                    field.set(videoTypeOffOnlineExp, rateStr);
                }
            }
//        }
        videoTypeOffOnlineExp.setOfflineCount(String.valueOf(AllOffLineCount));
    }
    /**
     * 计算在线设备excel对象信息
     * @param videoDailyExps 传入的设备集合信息
     * @param type 设备类型 1人脸 2车辆 3视频
     * @param areaDeptEnum 区域
     * @return
     */
    public VideoOnlineRateExp getListOnLineCountInfo(List<VideoDailyExp> videoDailyExps,
                                                         String type,
                                                         AreaDeptEnum areaDeptEnum,
                                                         boolean isTotal){
        VideoOnlineRateExp videoOnlineRateExp = new VideoOnlineRateExp();
        List<VideoDailyExp> list = videoDailyExps.stream()
                .filter(device ->device.getType() != null && device.getType().contains(type)).collect(Collectors.toList());
        log.error("筛选完设备类型 :{} 后集合的大小:{}",type,list.size());
        //离线数量
        try {
            //设置离线数量 以及每日离线数量
            setVideoOnlineRateExpCountAndDays(list,videoOnlineRateExp,isTotal);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        //设备类型
        if(isTotal) {
            if ("1".equals(type)) {
                videoOnlineRateExp.setType("人脸合计");
            } else if ("2".equals(type)) {
                videoOnlineRateExp.setType("卡口合计");
            } else if ("3".equals(type)) {
                videoOnlineRateExp.setType("视频合计");
            }
        }else {
            if ("1".equals(type)) {
                videoOnlineRateExp.setType("人脸");
            } else if ("2".equals(type)) {
                videoOnlineRateExp.setType("卡口");
            } else if ("3".equals(type)) {
                videoOnlineRateExp.setType("视频");
            }
        }
        //修改区域
        videoOnlineRateExp.setArea(areaDeptEnum == null ? "未知" : areaDeptEnum.getName());
        return videoOnlineRateExp;
    }
    private void setVideoOnlineRateExpCountAndDays(List<VideoDailyExp> videoDailyExps,VideoOnlineRateExp videoOnlineRateExp,boolean isTotal)throws NoSuchFieldException, IllegalAccessException {
        //循环一个月
        for (int i = 1;i <= 31 ;i++){
            //在线率计算
            long count = 0;
            String fieldName = "day" + i;
            for(VideoDailyExp videoDailyExp: videoDailyExps){
                // 构造字段名
                Field field = videoDailyExp.getClass().getDeclaredField(fieldName);
                // 确保字段是私有的可以访问
                field.setAccessible(true);
                // 获取字段值
                String value = (String) field.get(videoDailyExp);
                if ("在线".equals(value)) {
                    count ++;
                }
            }
            //每日在线率
            double rate = (double) count / videoDailyExps.size();
            //反射添加到对象属性中
            Field field = videoOnlineRateExp.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            String rateStr = String.format("%.2f", rate * 100) +"%";
            if (!"0.00%".equals(rateStr)){
                field.set(videoOnlineRateExp, rateStr);
            }
        }
    }
@@ -826,6 +1074,7 @@
                        Function.identity(),  // valueMapper,直接使用对象本身
                        (existing, replacement) -> existing // mergeFunction,如果有重复,保留第一个
                ));
        // 将 Map 转换为 List
        List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
        //获取动态列数据
@@ -1387,6 +1636,7 @@
    private void setOnlineDaily(VideoDailyExp videoDailyExp, TMonitorResult result, List<TMonitorResult> onlines) throws NoSuchFieldException, IllegalAccessException {
        //一个设备当月在线情况
        List<TMonitorResult> onlineResult = onlines.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
        videoDailyExp.setOnlineStateList(onlineResult);
        for (TMonitorResult monitorResult : onlineResult) {
            int dayOfMonth = monitorResult.getMongoCreateTime().getDayOfMonth();
            String online = "";
@@ -1402,6 +1652,8 @@
            field.setAccessible(true);
            field.set(videoDailyExp, online);
        }
    }
    //设置每日录像数据
ycl-server/src/main/java/com/ycl/task/UYTask.java
@@ -194,6 +194,9 @@
        } else {
            log.error("请配置离线次数,此次设置为默认值2");
        }
        // 现在需要查出状态为未知的设备
        // 先查出设备IP集合,剔除掉在线情况是未知的,并且只检测正在考核的设备避免多余工单
        List<TMonitorResult> monitorList = monitorMapper.getDistinctIP();
        //补充错误时间点
@@ -230,6 +233,7 @@
        CompletableFuture<Void> allOf = CompletableFuture.allOf(
                futureList.toArray(new CompletableFuture[0])
        );
        try {
            allOf.get(60, TimeUnit.SECONDS); // 给予额外的5秒来收集结果
        } catch (TimeoutException e) {
@@ -289,6 +293,8 @@
            Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date())));
            DeleteResult result = mongoTemplate.remove(query, TMonitorResult.class);
            //存放在mongo中
            log.error("存入同步在线mongo数据{}" , monitorList );
            mongoTemplate.insertAll(mongoList);
        }
        //工单(同一IP只生成一个工单)
ycl-server/src/main/resources/mapper/zgyw/TMonitorMapper.xml
@@ -694,9 +694,9 @@
        from t_monitor m
            left join t_yw_point p on m.serial_number = p.serial_number
            left join sys_dept d on p.dept_id = d.dept_id
        where p.online != 0 and p.examine_status = 1
        where  p.examine_status = 1
    </select>
<!--上方修改了  p.online != 0 and-->
    <update id="updateOnlineFromUyOrHk">
        <foreach collection="onlineList" item="online" separator=";">
            UPDATE