From eb0e29e72049bc65f943cc864929c332b07f25d0 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期一, 03 三月 2025 20:56:46 +0800
Subject: [PATCH] 导出osd问题 以及缺少小时改分钟

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java |  121 ++++++++++++++++++++++++++--------------
 1 files changed, 79 insertions(+), 42 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
index 5a5f199..f527aad 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
@@ -33,6 +33,7 @@
 import com.ycl.platform.mapper.DynamicColumnMapper;
 import com.ycl.platform.mapper.TMonitorMapper;
 import com.ycl.platform.mapper.WorkOrderMapper;
+import com.ycl.platform.mapper.YwPointMapper;
 import com.ycl.platform.service.ITMonitorService;
 import com.ycl.system.Result;
 import com.ycl.system.entity.SysDictData;
@@ -57,6 +58,7 @@
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import pojo.ExcelExp;
 import utils.poi.ExcelUtilManySheet;
@@ -65,6 +67,7 @@
 import java.lang.reflect.Field;
 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;
@@ -89,6 +92,8 @@
 public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService {
     @Autowired
     private TMonitorMapper tMonitorMapper;
+    @Autowired
+    private YwPointMapper pointMapper;
     @Autowired
     private ISysConfigService configService;
     @Autowired
@@ -368,16 +373,21 @@
      */
     @Override
     public Map<String, Object> home(HomeQuery monitorQuery) {
-
+        System.out.println(monitorQuery + "~~~~~~~~~~~~~鎵撳嵃");
         Map<String, Object> dataMap = new HashMap<>();
         Map<String, Object> monthMap1 = new HashMap<>();
         Map<String, Object> monthMap2 = new HashMap<>();
         List<Map<String, Object>> home = baseMapper.home(monitorQuery);
         if (ObjectUtils.isNotEmpty(home)) {
+            //鎷垮埌鏁版嵁搴� 寰幆鏌ヨ
+            System.out.println(home + "~~~~~~~~~~~~~鎵撳嵃");
             for (Map<String, Object> map : home) {
+                //寰楀埌map鐨� months閿殑鍊�  num1閿殑鍊� 缁勮涓烘柊瀵硅薄
                 monthMap1.put(map.get("months").toString(), map.get("num1"));
+                //寰楀埌map鐨� months閿殑鍊�  num2閿殑鍊� 缁勮涓烘柊瀵硅薄
                 monthMap2.put(map.get("months").toString(), map.get("num2"));
             }
+            //home 鐨勪笅鏍�0鐨� map鐨� name閿殑鍊�
             dataMap.put("name", home.get(0).get("name"));
             dataMap.put("state", monthMap1);
             dataMap.put("state2", monthMap2);
@@ -477,12 +487,16 @@
         //涓�涓儴闂ㄤ竴涓猻heet
         for (Integer deptId : exportForm.getDeptIds()) {
             CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
+                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                 //绛涢�夐儴闂ㄦ暟鎹�
                 Set<String> ids = onlineResult.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).map(BaseResult::getNo).collect(Collectors.toSet());
                 if (CollectionUtils.isEmpty(ids)) return;
                 //绛涢�夐儴闂ㄦ暟鎹�
                 List<TMonitorResult> onlineList = onlineResult.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
+                Map<LocalDate, List<TMonitorResult>> onlineMap = onlineList.stream()
+                        .collect(Collectors.groupingBy(TMonitorResult::getMongoCreateTime));
                 List<RecordMetaDSumResult> recordList = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
+                Map<Date, List<RecordMetaDSumResult>> recordMap = recordList.stream().collect(Collectors.groupingBy(RecordMetaDSumResult::getStatTime));
                 List<VideoTotalExp> videoTotalExps = new ArrayList<>();
                 for (int i = 0; i < 31; i++) {
                     String date = exportForm.getMonth();
@@ -490,41 +504,46 @@
                     //鎬婚噺
                     VideoTotalExp totalExp = totalMap.computeIfAbsent(date, k -> new VideoTotalExp());
                     LocalDate parseTime = LocalDate.parse(date, formatter);
-                    //鑾峰彇鏄熸湡鍑�
-                    String week = weeks[parseTime.getDayOfWeek().getValue() - 1];
-                    VideoTotalExp videoExp = new VideoTotalExp();
-                    videoExp.setDate(date);
-                    videoExp.setWeek(week);
-                    //璁剧疆鐐逛綅鍦ㄧ嚎鎬婚噺
-                    List<TMonitorResult> onlines = onlineList.stream().filter(tMonitorResult -> tMonitorResult.getMongoCreateTime().minusDays(1).equals(parseTime)).collect(Collectors.toList());
-                    if (!CollectionUtils.isEmpty(onlines)) {
-                        videoExp.setTotal(onlines.size());
-                        long count = onlines.stream()
-                                .filter(item -> ApiConstants.UY_OnlineSite_Online.equals(item.getOnline()))
-                                .count();
-                        videoExp.setOnline(Integer.valueOf(count + ""));
-                        videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline());
+                    try {
+                        Date parseDate = simpleDateFormat.parse(date);
+                        //鑾峰彇鏄熸湡鍑�
+                        String week = weeks[parseTime.getDayOfWeek().getValue() - 1];
+                        VideoTotalExp videoExp = new VideoTotalExp();
+                        videoExp.setDate(date);
+                        videoExp.setWeek(week);
+                        //璁剧疆鐐逛綅鍦ㄧ嚎鎬婚噺
+                        List<TMonitorResult> onlines = onlineMap.get(parseTime);
+                        if (!CollectionUtils.isEmpty(onlines)) {
+                            videoExp.setTotal(onlines.size());
+                            long count = onlines.stream()
+                                    .filter(item -> ApiConstants.UY_OnlineSite_Online.equals(item.getOnline()))
+                                    .count();
+                            videoExp.setOnline(Integer.valueOf(count + ""));
+                            videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline());
+                        }
+                        //璁剧疆瀛樺偍鎯呭喌
+                        List<RecordMetaDSumResult> records = recordMap.get(parseDate);
+                        if (!CollectionUtils.isEmpty(records)) {
+                            videoExp.setNoStore(Integer.valueOf(records.stream()
+                                    .filter(record -> ApiConstants.UY_RecordStatus_Abnormal.equals(record.getRecordStatus()))
+                                    .count() + ""));
+                            videoExp.setPartStore(Integer.valueOf(records.stream()
+                                    .filter(record -> ApiConstants.UY_RecordStatus_Interval.equals(record.getRecordStatus()))
+                                    .count() + ""));
+                        }
+                        videoTotalExps.add(videoExp);
+                        //绱姞浣滀负鍏ㄩ噺琛�
+                        totalExp.setDate(date);
+                        totalExp.setWeek(week);
+                        totalExp.setTotal((totalExp.getTotal() == null ? 0 : totalExp.getTotal()) + (videoExp.getTotal() == null ? 0 : videoExp.getTotal()));
+                        totalExp.setOnline((totalExp.getOnline() == null ? 0 : totalExp.getOnline()) + (videoExp.getOnline() == null ? 0 : videoExp.getOnline()));
+                        totalExp.setOffline((totalExp.getOffline() == null ? 0 : totalExp.getOffline()) + (videoExp.getOffline() == null ? 0 : videoExp.getOffline()));
+                        totalExp.setNoStore((totalExp.getNoStore() == null ? 0 : totalExp.getNoStore()) + (videoExp.getNoStore() == null ? 0 : videoExp.getNoStore()));
+                        totalExp.setPartStore((totalExp.getPartStore() == null ? 0 : totalExp.getPartStore()) + (videoExp.getPartStore() == null ? 0 : videoExp.getPartStore()));
+                        totalMap.put(date, totalExp);
+                    } catch (ParseException e) {
+                        e.printStackTrace();
                     }
-                    //璁剧疆瀛樺偍鎯呭喌
-                    List<RecordMetaDSumResult> records = recordList.stream().filter(record -> record.getMongoCreateTime().minusDays(1).equals(parseTime)).collect(Collectors.toList());
-                    if (!CollectionUtils.isEmpty(records)) {
-                        videoExp.setNoStore(Integer.valueOf(records.stream()
-                                .filter(record -> ApiConstants.UY_RecordStatus_Abnormal.equals(record.getRecordStatus()))
-                                .count() + ""));
-                        videoExp.setPartStore(Integer.valueOf(records.stream()
-                                .filter(record -> ApiConstants.UY_RecordStatus_Interval.equals(record.getRecordStatus()))
-                                .count() + ""));
-                    }
-                    videoTotalExps.add(videoExp);
-                    //绱姞浣滀负鍏ㄩ噺琛�
-                    totalExp.setDate(date);
-                    totalExp.setWeek(week);
-                    totalExp.setTotal((totalExp.getTotal() == null ? 0 : totalExp.getTotal()) + (videoExp.getTotal() == null ? 0 : videoExp.getTotal()));
-                    totalExp.setOnline((totalExp.getOnline() == null ? 0 : totalExp.getOnline()) + (videoExp.getOnline() == null ? 0 : videoExp.getOnline()));
-                    totalExp.setOffline((totalExp.getOffline() == null ? 0 : totalExp.getOffline()) + (videoExp.getOffline() == null ? 0 : videoExp.getOffline()));
-                    totalExp.setNoStore((totalExp.getNoStore() == null ? 0 : totalExp.getNoStore()) + (videoExp.getNoStore() == null ? 0 : videoExp.getNoStore()));
-                    totalExp.setPartStore((totalExp.getPartStore() == null ? 0 : totalExp.getPartStore()) + (videoExp.getPartStore() == null ? 0 : videoExp.getPartStore()));
-                    totalMap.put(date, totalExp);
                 }
                 AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
                 ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoTotalExps, VideoTotalExp.class);
@@ -535,7 +554,6 @@
         // 绛夊緟鎵�鏈変换鍔″畬鎴�
         CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
         allFutures.join(); // 杩欏皢闃诲鐩村埌鎵�鏈変换鍔″畬鎴�
-
         //娣诲姞鍏ㄩ噺琛�
         List<VideoTotalExp> totalExps = new ArrayList<>(totalMap.values());
         totalExps = totalExps.stream().sorted(Comparator.comparing(VideoTotalExp::getDate)).collect(Collectors.toList());
@@ -750,7 +768,8 @@
                     // 浣跨敤Map鐩存帴鑾峰彇璁板綍锛岄伩鍏峟ilter鎿嶄綔
                     List<RecordMetaDSumResult> recordsResult = recordMap.get(result.getNo());
                     try {
-                        if(!CollectionUtils.isEmpty(recordsResult)) setRecordDaily(videoDailyExp, result, recordsResult);
+                        if (!CollectionUtils.isEmpty(recordsResult))
+                            setRecordDaily(videoDailyExp, result, recordsResult);
                     } catch (Exception e) {
                         log.error(e.getMessage());
                     }
@@ -869,7 +888,7 @@
                     // 浣跨敤Map鐩存帴鑾峰彇璁板綍锛岄伩鍏峟ilter鎿嶄綔
                     List<RecordMetaDSumResult> recordsResult = recordMap.get(result.getNo());
                     try {
-                        if(!CollectionUtils.isEmpty(recordsResult)) setLoseDaily(videoDailyExp, recordsResult);
+                        if (!CollectionUtils.isEmpty(recordsResult)) setLoseDaily(videoDailyExp, recordsResult);
                     } catch (Exception e) {
                         log.error(e.getMessage());
                     }
@@ -952,7 +971,7 @@
                         ))
                         .append("loseCount", new Document("$sum",
                                 new Document("$cond", Arrays.asList(
-                                        new Document("$eq", Arrays.asList("$recordStatus", -1)),
+                                        new Document("$in", Arrays.asList("$recordStatus", Arrays.asList(-1, 0))),
                                         1,
                                         0
                                 ))
@@ -1073,6 +1092,24 @@
             sheetName = "浜鸿劯";
         }
         util.exportExcel(response, monitors, sheetName);
+    }
+
+    /**
+     * 娓呯悊涓�鏈轰竴妗�
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result clearMonitor() {
+      tMonitorMapper.clearMonitor();
+      pointMapper.clearMonitor();
+      return Result.ok();
+    }
+
+    @Override
+    public Result assetManagementCount(DataCenterQuery query) {
+        Map<String, String> map =tMonitorMapper.assetManagementCount();
+        return Result.ok().data(map);
     }
 
 
@@ -1383,13 +1420,13 @@
     private void setLoseDaily(VideoDailyExp videoDailyExp, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException {
         //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
         for (RecordMetaDSumResult recordResult : recordResults) {
-            int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());
+            int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());  //鑾峰彇鍚姩鏃ユ湡鏄綋鏈堢鍑犲ぉ
             //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸ay+1锛�2锛�3...
             Field field = videoDailyExp.getClass().getDeclaredField("day" + dayOfMonth);
             field.setAccessible(true);
             //闃叉杞崲涓虹瀛﹁鏁版硶
-            BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : recordResult.getMissDuration());
-            field.set(videoDailyExp, bigDecimal.toString());
+            BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : (recordResult.getMissDuration()) * 60);
+            field.set(videoDailyExp, bigDecimal.setScale(2, RoundingMode.HALF_UP).toString());
         }
     }
 }

--
Gitblit v1.8.0