From 97b1e0d4820606bef726f60e459b66afb1e8eab1 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期五, 21 十一月 2025 11:50:51 +0800
Subject: [PATCH] 优化与日志
---
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java | 1897 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 1,807 insertions(+), 90 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 b91b2b4..bc7a065 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
@@ -3,35 +3,77 @@
import annotation.DataScope;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.mongodb.client.AggregateIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import com.ycl.platform.domain.entity.MonitorConstruction;
import com.ycl.platform.domain.entity.TMonitor;
+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;
import com.ycl.platform.domain.query.HomeQuery;
-import com.ycl.platform.domain.result.HK.FaceDeviceInspectionResult;
-import com.ycl.platform.domain.result.HK.FaceDeviceSamplingResult;
-import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult;
-import com.ycl.platform.domain.result.HK.VehicleDeviceSamplingResult;
-import com.ycl.platform.domain.result.UY.VideoOnlineResult;
+import com.ycl.platform.domain.result.BaseResult;
+import com.ycl.platform.domain.result.HK.*;
+import com.ycl.platform.domain.result.SYS.TMonitorResult;
+import com.ycl.platform.domain.result.UY.MonitorQualifyResult;
+import com.ycl.platform.domain.result.UY.OsdCheckResult;
+import com.ycl.platform.domain.result.UY.RecordMetaDSumResult;
+import com.ycl.platform.domain.vo.DynamicColumnVO;
import com.ycl.platform.domain.vo.TMonitorVO;
+import com.ycl.platform.domain.vo.WorkOrderVO;
+import com.ycl.platform.domain.vo.home.BaseHomeVO;
+import com.ycl.platform.domain.vo.home.HomeCarVO;
+import com.ycl.platform.domain.vo.home.HomeFaceVO;
+import com.ycl.platform.domain.vo.home.HomeVideoVO;
import com.ycl.platform.domain.vo.screen.MonitorRateVO;
import com.ycl.platform.domain.vo.screen.MonitorTotalVO;
-import com.ycl.platform.mapper.TMonitorMapper;
+import com.ycl.platform.mapper.*;
+import com.ycl.platform.service.IMonitorConstructionService;
import com.ycl.platform.service.ITMonitorService;
import com.ycl.system.Result;
+import com.ycl.system.entity.SysDictData;
+import com.ycl.system.mapper.SysDictDataMapper;
import com.ycl.system.page.PageUtil;
import com.ycl.system.service.ISysConfigService;
+import com.ycl.utils.DateUtils;
import com.ycl.utils.StringUtils;
+import com.ycl.utils.poi.ExcelUtil;
+import constant.ApiConstants;
+import enumeration.general.AreaDeptEnum;
+import jakarta.servlet.http.HttpServletResponse;
+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.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
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;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static com.ycl.utils.PageUtils.startPage;
/**
* 璁惧璧勪骇Service涓氬姟灞傚鐞�
@@ -40,15 +82,26 @@
* @date 2024-03-04
*/
@Service
-public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService
-{
+@Slf4j
+public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService {
@Autowired
private TMonitorMapper tMonitorMapper;
+ @Autowired
+ private YwPointMapper pointMapper;
@Autowired
private ISysConfigService configService;
@Autowired
private MongoTemplate mongoTemplate;
-
+ @Autowired
+ private WorkOrderMapper workOrderMapper;
+ @Autowired
+ private SysDictDataMapper dictDataMapper;
+ @Autowired
+ private DynamicColumnMapper dynamicColumnMapper;
+ @Autowired
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+ @Autowired
+ private IMonitorConstructionService monitorConstructionService;
/**
* 鏌ヨ璁惧璧勪骇
*
@@ -56,90 +109,213 @@
* @return 璁惧璧勪骇
*/
@Override
- public TMonitor selectTMonitorById(Long id)
- {
+ public TMonitor selectTMonitorById(Long id) {
return tMonitorMapper.selectTMonitorById(id);
}
/**
* 鏌ヨ璁惧璧勪骇鍒楄〃
+ * 寮傚父鎭㈠鐩戞帶銆佽溅杈嗐�佷汉鑴搞�佽棰戦�氱敤鎺ュ彛
*
* @param tMonitor 璁惧璧勪骇
* @return 璁惧璧勪骇
*/
@Override
- @DataScope(deptAlias = "d",userAlias = "u")
+ @DataScope(deptAlias = "d", userAlias = "u")
public List<TMonitorVO> selectTMonitorList(TMonitorVO tMonitor) {
- List<TMonitorVO> monitors = tMonitorMapper.selectTMonitorList(tMonitor);
- // 寮傚父璁惧
+ // 寮傚父鎭㈠鐩戞帶
if (Objects.equals(tMonitor.getRecovery(), 1L)) {
String time = configService.selectConfigByKey("abnormal.equipment.continuous.attention.time");
if (StringUtils.isBlank(time)) {
throw new RuntimeException("璇烽厤缃紓甯歌澶囪繛缁叧娉ㄦ椂闂�");
}
- List<TMonitorVO> recoveryMonitors = tMonitorMapper.selectRecoveryMonitor(time);
- monitors.addAll(recoveryMonitors);
+ tMonitor.setTime(time);
}
- // 瑙嗛鐩戞帶璁惧
- if (Objects.equals(tMonitor.getCameraFunType(), "1")) {
- monitors.forEach(monitor -> {
- Query query = new Query();
- query.addCriteria(Criteria.where("deviceId").is(monitor.getSerialNumber())
- // .and("mongoCreateTime").is(LocalDate.now())
- );
- VideoOnlineResult one = mongoTemplate.findOne(query, VideoOnlineResult.class);
- if (one != null) {
- monitor.setIfmDelay(one.getIfmDelay());
- monitor.setSipDelay(one.getSipDelay());
- monitor.setVideoDelay(one.getVideoDelay());
- monitor.setMongoCreateTime(one.getMongoCreateTime());
- }
- });
+ List<TMonitorVO> monitors = new ArrayList<>();
+ if (StringUtils.isNotBlank(tMonitor.getConstructionType())){
+ List<MonitorConstruction> list =
+ monitorConstructionService.getSerialNumberListByConstructionType(tMonitor.getConstructionType());
+ log.info("鎵撳嵃鏌ヨ璁惧鏍囩鏁�:{},寤鸿绫诲瀷鏍囩:{}",list.size(), tMonitor.getConstructionType() );
+ //鑾峰緱璁惧缂栧彿闆嗗悎 閫氳繃寤鸿绫诲瀷鏍囩
+ if(!CollectionUtils.isEmpty(list)){
+ tMonitor.setIds(
+ list.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList()));
+
+ startPage();
+ monitors = tMonitorMapper.selectTMonitorListAndIds(tMonitor);
+ }
+
+ }else{
+ startPage();
+ monitors = tMonitorMapper.selectTMonitorList(tMonitor);
}
- // 杞﹁締鐩戞帶璁惧
- if (Objects.equals(tMonitor.getCameraFunType(), "2")) {
- monitors.forEach(monitor -> {
- Query query = new Query();
- query.addCriteria(Criteria.where("externalIndexCode").is(monitor.getSerialNumber())
- // .and("mongoCreateTime").is(LocalDate.now())
- );
- VehicleDeviceInspectionResult one = mongoTemplate.findOne(query, VehicleDeviceInspectionResult.class);
- VehicleDeviceSamplingResult two = mongoTemplate.findOne(query, VehicleDeviceSamplingResult.class);
- if (one != null) {
- monitor.setDataCount(one.getDataCount());
- monitor.setClockPercent(Objects.nonNull(one.getSnapClock()) ? one.getSnapClock().getClockPercent() : null);
- monitor.setMongoCreateTime(one.getMongoCreateTime());
+ // 寮傚父鎭㈠鐩戞帶
+ if (Objects.equals(tMonitor.getRecovery(), 1L)) {
+ //宸ュ崟鍙�
+ List<String> orders = monitors.stream().map(TMonitorVO::getWorkOrderNo).collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(orders)) {
+ return monitors;
}
- if (two != null) {
- monitor.setBigUsefulPercent(Objects.nonNull(two.getBigUseful()) ? two.getBigUseful().getBigUsefulPercent() : null);
- monitor.setMajorConPercent(Objects.nonNull(two.getVehDiff()) ? two.getVehDiff().getMajorConPercent() : null);
- monitor.setImportantConPercent(Objects.nonNull(two.getVehDiff()) ? two.getVehDiff().getImportantConPercent() : null);
- monitor.setMongoCreateTime(two.getMongoCreateTime());
+ List<WorkOrderVO> voList = workOrderMapper.getRecoveryInfo(orders);
+ for (TMonitorVO monitor : monitors) {
+ if (!CollectionUtils.isEmpty(voList)) {
+ for (WorkOrderVO workOrderVO : voList) {
+ if (monitor.getWorkOrderNo() != null && monitor.getWorkOrderNo().equals(workOrderVO.getWorkOrderNo())) {
+ monitor.setUnitContact(workOrderVO.getUnitContact());
+ monitor.setUnitContactPhone(workOrderVO.getUnitContactPhone());
+ monitor.setYwPeopleName(workOrderVO.getYwPeopleName());
+ monitor.setErrorType(workOrderVO.getErrorType());
+ }
+ }
+ }
}
- });
- }
- // 浜鸿劯鐩戞帶璁惧
- if (Objects.equals(tMonitor.getCameraFunType(), "3")) {
- monitors.forEach(monitor -> {
- Query query = new Query();
- query.addCriteria(Criteria.where("externalIndexCode").is(monitor.getSerialNumber())
- // .and("mongoCreateTime").is(LocalDate.now())
- );
- FaceDeviceInspectionResult one = mongoTemplate.findOne(query, FaceDeviceInspectionResult.class);
- FaceDeviceSamplingResult two = mongoTemplate.findOne(query, FaceDeviceSamplingResult.class);
- if (one != null) {
- monitor.setDataCount(one.getDataCount());
- monitor.setClockPercent(Objects.nonNull(one.getSnapClock()) ? one.getSnapClock().getClockPercent() : null);
- monitor.setMongoCreateTime(one.getMongoCreateTime());
+ return monitors;
+ }
+ //璁惧缂栧彿
+ List<String> numbers = monitors.stream().map(TMonitorVO::getSerialNumber).collect(Collectors.toList());
+ Query query = new Query();
+ Date now = new Date();
+ query.addCriteria(Criteria.where("no").in(numbers)
+ .and("mongoCreateTime").gte(DateUtils.getDayStart(now)).lt(DateUtils.getDayEnd(now))
+ );
+ //涓�鏈轰竴妗d俊鎭�
+ List<MonitorQualifyResult> monitorQualifyResults = mongoTemplate.find(query, MonitorQualifyResult.class);
+ // 瑙嗛鐩戞帶璁惧
+ if (Objects.equals(tMonitor.getCameraFunType(), "1")) {
+ //OSD淇℃伅
+ List<OsdCheckResult> osdCheckResults = mongoTemplate.find(query, OsdCheckResult.class);
+ //褰曞儚鍙敤淇℃伅
+ List<RecordMetaDSumResult> videoResults = mongoTemplate.find(query, RecordMetaDSumResult.class);
+ for (TMonitorVO monitor : monitors) {
+ monitor.setMongoCreateTime(now);
+ //涓�鏈轰竴妗�
+ setOneFile(monitorQualifyResults, monitor);
+ //褰曞儚
+ if (!CollectionUtils.isEmpty(videoResults)) {
+ for (RecordMetaDSumResult videoResult : videoResults) {
+ if (monitor.getSerialNumber().equals(videoResult.getNo())) {
+ monitor.setVideoComplete(videoResult.getRecordStatus());
+ monitor.setVideoLoseTime(videoResult.getMissDuration());
+ }
+ }
+ }
+ //OSD
+ if (!CollectionUtils.isEmpty(osdCheckResults)) {
+ for (OsdCheckResult osdCheckResult : osdCheckResults) {
+ if (monitor.getSerialNumber().equals(osdCheckResult.getNo())) {
+ monitor.setOSD(OsdCheckResult.checkOsd(osdCheckResult));
+ monitor.setOSDTime(OsdCheckResult.checkTime(osdCheckResult));
+ }
+ }
+ }
}
- if (two != null) {
- monitor.setBigUsefulPercent(Objects.nonNull(two.getBigUseful())? two.getBigUseful().getBigUsefulPercent() : null);
- monitor.setFaceEligPercent(Objects.nonNull(two.getFaceEligibility()) ? two.getFaceEligibility().getFaceEligPercent() : null);
- monitor.setMongoCreateTime(two.getMongoCreateTime());
+ }
+ // 杞﹁締鐩戞帶璁惧
+ if (Objects.equals(tMonitor.getCameraFunType(), "2")) {
+ //灞炴�т竴鑷寸巼銆佸ぇ鍥�
+ List<VehicleDeviceSamplingResult> sampleResults = mongoTemplate.find(query, VehicleDeviceSamplingResult.class);
+ List<PicAccessResult> picAccessResults = mongoTemplate.find(query, PicAccessResult.class);
+ //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
+ List<VehicleDeviceInspectionResult> inspectResults = mongoTemplate.find(query, VehicleDeviceInspectionResult.class);
+ for (TMonitorVO monitor : monitors) {
+ monitor.setMongoCreateTime(now);
+ //涓�鏈轰竴妗�
+ setOneFile(monitorQualifyResults, monitor);
+ //url
+ if (!CollectionUtils.isEmpty(sampleResults)) {
+ for (PicAccessResult picAccessResult : picAccessResults) {
+ if (monitor.getSerialNumber().equals(picAccessResult.getNo())) {
+ BigDecimal bigDecimal = PicAccessResult.calUrl(picAccessResult);
+ monitor.setUrlPercent(bigDecimal);
+ }
+ }
+ }
+ //灞炴�т竴鑷寸巼銆佸ぇ鍥�
+ if (!CollectionUtils.isEmpty(sampleResults)) {
+ for (VehicleDeviceSamplingResult sampleResult : sampleResults) {
+ if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
+ if (sampleResult.getBigUseful() != null) {
+ monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+ }
+ if (sampleResult.getVehDiff() != null) {
+ monitor.setImportantConPercent(sampleResult.getVehDiff().getImportantConPercent());
+ monitor.setMajorConPercent(sampleResult.getVehDiff().getMajorConPercent());
+ }
+ }
+ }
+ }
+ //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
+ if (!CollectionUtils.isEmpty(inspectResults)) {
+ for (VehicleDeviceInspectionResult inspectResult : inspectResults) {
+ if (monitor.getSerialNumber().equals(inspectResult.getNo())) {
+ monitor.setSnapResult(inspectResult.getSnapResult());
+ monitor.setSnapCount(inspectResult.getDataCount());
+ if (inspectResult.getSnapClock() != null)
+ monitor.setClockPercent(inspectResult.getSnapClock().getClockPercent());
+ if (inspectResult.getSnapTimely() != null)
+ monitor.setUploadPercent(inspectResult.getSnapTimely().getTimelyPercent());
+ }
+ }
+ }
}
- });
- }
+ }
+ // 浜鸿劯鐩戞帶璁惧
+ if (Objects.equals(tMonitor.getCameraFunType(), "3")) {
+ //浜鸿劯鍚堟牸銆佸ぇ鍥俱�乽rl璁块棶寮傚父
+ List<FaceDeviceSamplingResult> sampleResults = mongoTemplate.find(query, FaceDeviceSamplingResult.class);
+ //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
+ List<FaceDeviceInspectionResult> inspectResults = mongoTemplate.find(query, FaceDeviceInspectionResult.class);
+ for (TMonitorVO monitor : monitors) {
+ monitor.setMongoCreateTime(now);
+ //涓�鏈轰竴妗�
+ setOneFile(monitorQualifyResults, monitor);
+ //浜鸿劯鍚堟牸銆佸ぇ鍥�
+ if (!CollectionUtils.isEmpty(sampleResults)) {
+ for (FaceDeviceSamplingResult sampleResult : sampleResults) {
+ if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
+ if (sampleResult.getBigUseful() != null) {
+ monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+ }
+ if (sampleResult.getFaceEligibility() != null)
+ monitor.setFacePercent(sampleResult.getFaceEligibility().getFaceEligPercent());
+ }
+ }
+ }
+ //鎶撴媿閲忋�佹椂閽熴�佷笂浼犮�佸缓妯″け璐ョ巼
+ if (!CollectionUtils.isEmpty(inspectResults)) {
+ for (FaceDeviceInspectionResult inspectResult : inspectResults) {
+ if (monitor.getSerialNumber().equals(inspectResult.getNo())) {
+ monitor.setSnapResult(inspectResult.getSnapResult());
+ monitor.setSnapCount(inspectResult.getDataCount());
+ if (inspectResult.getSnapClock() != null)
+ monitor.setClockPercent(inspectResult.getSnapClock().getClockPercent());
+ if (inspectResult.getSnapTimely() != null)
+ monitor.setUploadPercent(inspectResult.getSnapTimely().getTimelyPercent());
+ if (inspectResult.getSnapValidity() != null)
+ monitor.setFailPercent(inspectResult.getSnapValidity().getFailPercent());
+ }
+ }
+ }
+ }
+ }
return monitors;
+ }
+
+ /**
+ * 琛ュ厖涓�鏈轰竴妗d俊鎭�
+ *
+ * @param monitorQualifyResults
+ * @param monitor
+ */
+ private void setOneFile(List<MonitorQualifyResult> monitorQualifyResults, TMonitorVO monitor) {
+ if (!CollectionUtils.isEmpty(monitorQualifyResults)) {
+ for (MonitorQualifyResult oneFile : monitorQualifyResults) {
+ if (monitor.getSerialNumber().equals(oneFile.getNo())) {
+ monitor.setMonitorQualify(MonitorQualifyResult.correct(oneFile));
+ monitor.setNewMonitor(oneFile.getNewDevice());
+ }
+ }
+ }
}
/**
@@ -149,8 +325,7 @@
* @return 缁撴灉
*/
@Override
- public int insertTMonitor(TMonitor tMonitor)
- {
+ public int insertTMonitor(TMonitor tMonitor) {
return tMonitorMapper.insertTMonitor(tMonitor);
}
@@ -161,8 +336,7 @@
* @return 缁撴灉
*/
@Override
- public int updateTMonitor(TMonitor tMonitor)
- {
+ public int updateTMonitor(TMonitor tMonitor) {
return tMonitorMapper.updateTMonitor(tMonitor);
}
@@ -173,8 +347,7 @@
* @return 缁撴灉
*/
@Override
- public int deleteTMonitorByIds(Long[] ids)
- {
+ public int deleteTMonitorByIds(Long[] ids) {
return tMonitorMapper.deleteTMonitorByIds(ids);
}
@@ -185,34 +358,55 @@
* @return 缁撴灉
*/
@Override
- public int deleteTMonitorById(Long id)
- {
+ public int deleteTMonitorById(Long id) {
return tMonitorMapper.deleteTMonitorById(id);
}
@Override
- @DataScope(deptAlias = "d",userAlias = "u")
- public Map<String, String> getVideoCount(TMonitor tMonitor) {
+ @DataScope(deptAlias = "d", userAlias = "u")
+ public Map<String, String> getVideoCount(TMonitorVO tMonitor) {
+
+ List<MonitorConstruction> list =
+ monitorConstructionService.getSerialNumberListByConstructionType(tMonitor.getConstructionType());
+ //鑾峰緱璁惧缂栧彿闆嗗悎 閫氳繃寤鸿绫诲瀷鏍囩
+ tMonitor.setIds(
+ list.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList()));
+
return tMonitorMapper.getVideoCount(tMonitor);
}
@Override
- public Map<String, String> recoveryException() {
- String time = configService.selectConfigByKey("abnormal.equipment.continuous.attention.time");
- return tMonitorMapper.recoveryException(time);
+ @DataScope(deptAlias = "d", userAlias = "u")
+ public Map<String, String> recoveryException(TMonitorVO monitor) {
+// String time = configService.selectConfigByKey("abnormal.equipment.continuous.attention.time");
+// monitor.setTime(time);
+ return tMonitorMapper.recoveryException(monitor);
}
+ /**
+ * 鏌ongo鏌ユ煇涓湀璁惧鎬绘暟
+ * 鏌ョ湅宸ュ崟鏁伴噺鏌ョ湅寮傚父鐨勬暟
+ *
+ * @param monitorQuery 鏌ヨ鏉′欢
+ * @return
+ */
@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);
@@ -221,9 +415,32 @@
}
@Override
- public List<MonitorTotalVO> monitorTotal(DashboardQuery dashboardQuery) {
- List<MonitorTotalVO> list = baseMapper.monitorTotal(dashboardQuery);
- return list;
+ public Map<String, List<Map<String, Object>>> monitorTotal(DashboardQuery dashboardQuery) {
+ List<MonitorTotalVO> monitorTotalVOS = baseMapper.monitorTotal(dashboardQuery);
+ /** facilityData: {
+ * video:[
+ * {value: 4589,title: '璁惧鎬绘暟'},
+ * {value: 4294,title: '璁惧姝e父鏁�'},
+ * {value: 295,title: '璁惧寮傚父鏁�'}
+ * ]} */
+ Map<String, List<Map<String, Object>>> resultMap = new HashMap<>();
+ for (MonitorTotalVO vo : monitorTotalVOS) {
+ List<Map<String, Object>> list = new ArrayList();
+ Map<String, Object> total = new HashMap<>();
+ total.put("value", vo.getTotalNum());
+ total.put("title", "璁惧鎬绘暟");
+ Map<String, Object> normal = new HashMap<>();
+ normal.put("value", vo.getNormalNum());
+ normal.put("title", "姝e父鏁�");
+ Map<String, Object> error = new HashMap<>();
+ error.put("value", vo.getErrorNum());
+ error.put("title", "寮傚父鏁�");
+ list.add(total);
+ list.add(normal);
+ list.add(error);
+ resultMap.put(vo.getType(), list);
+ }
+ return resultMap;
}
@Override
@@ -238,4 +455,1504 @@
baseMapper.assetManagement(page, query);
return Result.ok().data(page.getRecords()).total(page.getTotal());
}
+
+ /**
+ * 瀵煎嚭鎬婚噺鏁版嵁
+ */
+ @Override
+ public void exportVideoTotal(HttpServletResponse response, VideoExportForm exportForm) throws IOException {
+ //榛樿鏌ユ墍鏈夐儴闂�
+ if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
+ List<Integer> deptIds = new ArrayList<>();
+ for (AreaDeptEnum value : AreaDeptEnum.values()) {
+ deptIds.add(value.getDeptId());
+ }
+ exportForm.setDeptIds(deptIds);
+ }
+ List<ExcelExp> sheet = new ArrayList<>();
+ //閫氳繃Collections闈欐�佹柟娉曪紝鎶妉ist杞负绾跨▼瀹夊叏鐨刲ist
+ List mysheet = Collections.synchronizedList(sheet);
+ VideoExportForm.convertTags(exportForm);
+ Query query = getQuery(exportForm);
+ //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+ List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+ // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+ Map<String, TMonitorResult> uniqueResultsMap = onlineResult.stream()
+ .collect(Collectors.toMap(
+ TMonitorResult::getNo, // keyMapper锛岃繖閲屽亣璁� getNo() 杩斿洖 No 瀛楁
+ Function.identity(), // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬�
+ (existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓�
+ ));
+ // 灏� Map 杞崲涓� List
+ List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
+ YearMonth yearMonth = YearMonth.parse(exportForm.getMonth());
+ // 鑾峰彇褰撴湀鐨勭涓�澶�
+ LocalDate start = yearMonth.atDay(1);
+ // 鑾峰彇涓嬩釜鏈堢殑绗竴澶╋紙閫氳繃鍔犱笂1涓湀骞惰缃棩涓�1锛�
+ YearMonth nextMonth = yearMonth.plusMonths(1);
+ LocalDate end = nextMonth.atDay(1);
+ //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹紝褰曞儚鐢变簬鏄墠涓�澶╃殑鎵�浠ヤ笉鐢╟reateTime瀛楁
+ Query videoQuery = new Query(Criteria.where("statTime").gte(start).lt(end));
+ videoQuery.addCriteria(Criteria.where("no").in(deviceIds));
+ //鏈堜唤姣忔棩褰曞儚鏁版嵁
+ List<RecordMetaDSumResult> recordResult = mongoTemplate.find(videoQuery, RecordMetaDSumResult.class);
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String[] weeks = {"鏄熸湡涓�", "鏄熸湡浜�", "鏄熸湡涓�", "鏄熸湡鍥�", "鏄熸湡浜�", "鏄熸湡鍏�", "鏄熸湡鏃�"};
+ // 鍒涘缓涓�涓狹ap鏉ュ瓨鍌ㄦ瘡澶╃殑绱姞鏁版嵁
+ Map<String, VideoTotalExp> totalMap = new ConcurrentHashMap<>();
+ List<CompletableFuture<Void>> futures = new ArrayList<>();
+ //涓�涓儴闂ㄤ竴涓猻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();
+ date += "-" + (i < 9 ? "0" + (i + 1) : (i + 1));
+ //鎬婚噺
+ VideoTotalExp totalExp = totalMap.computeIfAbsent(date, k -> new VideoTotalExp());
+ LocalDate parseTime = LocalDate.parse(date, formatter);
+ 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();
+ }
+ }
+ AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+ ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoTotalExps, VideoTotalExp.class);
+ mysheet.add(excelExp);
+ }, threadPoolTaskExecutor);
+ futures.add(future);
+ }
+ // 绛夊緟鎵�鏈変换鍔″畬鎴�
+ 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());
+ ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoTotalExp.class);
+ mysheet.add(excelExp);
+ //瀵煎嚭
+ ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
+ util.exportExcelManySheet(response, mysheet);
+ }
+ /**
+ * 瀵煎嚭姣忔棩鍦ㄧ嚎鏁版嵁
+ */
+ @Override
+ public void exportVideoOnline(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
+ log.info("寮�濮嬪鍑烘暟鎹�");
+ log.info("浼犲叆鐨勬湀浠�:{}", exportForm.getMonth());
+
+ // 榛樿鏌ユ墍鏈夐儴闂�
+ if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
+ List<Integer> deptIds = new ArrayList<>(AreaDeptEnum.values().length);
+ for (AreaDeptEnum value : AreaDeptEnum.values()) {
+ deptIds.add(value.getDeptId());
+ }
+ exportForm.setDeptIds(deptIds);
+ }
+
+ // 浣跨敤绾跨▼瀹夊叏鐨凩ist锛岄鍏堟寚瀹氬閲�
+ List<ExcelExp> mysheet = Collections.synchronizedList(new ArrayList<>());
+ VideoExportForm.convertTags(exportForm);
+ Query query = getQuery(exportForm);//瑁呴厤鏉′欢
+ // 鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+
+ List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+ log.info("澶у皬:{}",onlineResult.size());
+ //姝ゅ闇�瑕佽繃婊ゆ帀璁惧鍏ㄦ櫙鍦ㄧ嚎 缁嗚妭涓嶅湪绾跨殑鎯呭喌 鍙互鎸� point鍒嗙粍 鍒嗘垜璁稿缁勪箣鍚庡啀鍋氬鐞�
+// Map<String, List<TMonitorResult>> ipToDevices = onlineResult.stream()
+// .collect(Collectors.groupingBy(TMonitorResult::getIp)); //閲嶈鎿嶄綔 鎸塱p鍒嗙粍
+
+// onlineResult = ipToDevices.values().stream()
+// .map(devices -> {
+// // 妫�鏌ュ垎缁勪腑鏄惁鏈� online = true 鐨勮澶�
+// List<TMonitorResult> onlineDevices = devices.stream()
+// .filter(monitor -> monitor.getOnline() == 1) // 鍋囪online瀛楁鐨刧etter鏄痠sOnline()
+// .collect(Collectors.toList());
+//
+// if (!onlineDevices.isEmpty()) {
+// // 鑻ュ瓨鍦╫nline=true鐨勮澶囷紝鍙繚鐣欑涓�涓紙鎴栧彇浠绘剰涓�涓紝鎸夐渶璋冩暣锛�
+// return onlineDevices.get(0);
+// } else {
+// // 鑻ュ叏涓簅nline=false锛屽彧淇濈暀绗竴涓�
+// return devices.get(0);
+// }
+// })
+// .collect(Collectors.toList());
+
+
+
+ log.info("鏈堜唤鍦ㄧ嚎鏁版嵁:{}鏉℃暟", onlineResult.size());
+ // 浣跨敤Collectors.toMap鍘婚噸锛屼繚鐣欐瘡涓狽o鐨勭涓�涓亣鍒扮殑鍏冪礌
+ Map<String, TMonitorResult> fullDataMap = onlineResult.stream()
+ .collect(Collectors.toMap(
+ TMonitorResult::getNo, // keyMapper锛岃繖閲屽亣璁� getNo() 杩斿洖 No 瀛楁
+ Function.identity(), // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬�
+ (existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓�
+ ));
+
+
+ // 灏� Map 杞崲涓� List 鍘婚噸鍚庡噺灏戞暟鎹簱娑堣��
+ List<TMonitorResult> tMonitorResults = new ArrayList<>(fullDataMap.values());
+// log.info("鍘婚噸鍚庡ぇ灏�:{}", tMonitorResults.size());
+
+ // 鑾峰彇鍔ㄦ�佸垪鏁版嵁骞舵瀯寤虹紦瀛楳ap
+ Map<Integer, List<DynamicColumnVO>> dynamicColumnMap = new HashMap<>();
+ if (!tMonitorResults.isEmpty()) {
+ //鑾峰彇ip闆嗗悎
+ List<Integer> pointIds = tMonitorResults.stream()
+ .map(TMonitorResult::getPointId)
+ .distinct() // 鍘婚噸锛屽噺灏戞暟鎹簱鏌ヨ
+ .collect(Collectors.toList());
+
+
+ //鑾峰彇闆嗗悎鐐逛綅鐨勮ˉ鍏呭垪淇℃伅
+ List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
+ if (!CollectionUtils.isEmpty(dynamics)) {
+ dynamicColumnMap = dynamics.stream()
+ .collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
+ }
+
+ // 琛ュ厖鍔ㄦ�佸垪鏁版嵁
+ // 鍘婚噸鍚庣殑鍔ㄦ�佸垪淇℃伅
+ for (TMonitorResult result : tMonitorResults) {
+ result.setDynamicColumnList(dynamicColumnMap.getOrDefault(result.getPointId(), Collections.emptyList()));
+ }
+ }
+ // 鎸夐儴闂ㄥ垎缁勶紝鍑忓皯鍚庣画寰幆涓殑杩囨护鎿嶄綔
+ Map<Integer, List<TMonitorResult>> deptMonitorMap = tMonitorResults.stream() //鍘婚噸鍚庢寚鍚� 姣忎釜璁惧鍙湁绗竴澶╃殑鏁版嵁
+ .collect(Collectors.groupingBy(TMonitorResult::getDeptId));
+
+ // 鎸夎澶囩紪鍙峰垎缁刼nlineResult锛屽姞閫熷悗缁煡鎵�
+ Map<String, List<TMonitorResult>> noToOnlineMap = onlineResult.stream() //杩欓噷鍊兼墍浠ユ暟鎹互璁惧鏍囧彿鍒嗙粍锛屽緱鍒板叾璇︽儏 濡� 1鍙峰埌31鍙风殑褰曞儚鎯呭喌
+ .collect(Collectors.groupingBy(TMonitorResult::getNo));
+
+ // 骞惰澶勭悊鍚勯儴闂ㄦ暟鎹�
+ List<CompletableFuture<ExcelExp>> futures = new ArrayList<>(exportForm.getDeptIds().size());//鎸夊墠绔紶鍏ョ殑 閮ㄩ棬缂栧彿 鏉ュ垽鏂渶瑕佸紑澶氬皯涓嚎绋�
+
+ Map<Integer, List<VideoDailyExp>> deptExpMap = new ConcurrentHashMap<>();
+ for (Integer deptId : exportForm.getDeptIds()) {
+ // 浣跨敤閮ㄩ棬ID鐨勬渶缁堝彉閲�
+ final Integer currentDeptId = deptId;
+ CompletableFuture<ExcelExp> future = CompletableFuture.supplyAsync(() -> {
+ // deptMonitorMap涓婇潰宸茬粡鍦ㄥ幓閲嶅悗鍒嗚繃缁勪簡锛堣繖閲屽彧鏄綋鐜颁簡鍘婚噸鐨勪綔鐢紝涓嬫柟姣忔棩鏁版嵁鏄�氳繃no鍦╪oToOnlineMap涓彇鍒扮殑锛�
+
+ List<TMonitorResult> monitors = deptMonitorMap.getOrDefault(currentDeptId, Collections.emptyList());
+
+ if (monitors.isEmpty()) {
+ return null;
+ }
+ List<VideoDailyExp> videoDailyExps = new ArrayList<>(monitors.size());
+ AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(currentDeptId);
+ String areaName = areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName();
+
+ for (TMonitorResult result : monitors) {
+ VideoDailyExp videoDailyExp = new VideoDailyExp();
+ videoDailyExp.setSerialNumber(result.getNo());
+ videoDailyExp.setDeviceName(result.getName());
+ videoDailyExp.setType(result.getMonitorType());
+ videoDailyExp.setArea(areaName);
+
+ // 鏋勫缓鏍囩瀛楃涓�
+ StringBuilder tag = new StringBuilder();
+ if (result.getProvinceTag()) tag.append("鐪佸巺銆�");
+ if (result.getImportantTag()) tag.append("閲嶇偣鐐逛綅銆�");
+ if (result.getImportantCommandImageTag()) tag.append("閲嶇偣鎸囨尌鍥惧儚銆�");
+ if (result.getDeptTag()) tag.append("閮ㄧ骇銆�");
+
+ // 澶勭悊鍔ㄦ�佸垪
+ List<DynamicColumnVO> dynamicColumns = result.getDynamicColumnList();
+ if (!dynamicColumns.isEmpty()) {
+ for (DynamicColumnVO dynamicColumnVO : dynamicColumns) {
+ tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+ }
+ }
+
+ // 绉婚櫎鏈熬鐨�"銆�"
+ if (tag.length() > 0) {
+ tag.setLength(tag.length() - 1);
+ }
+ videoDailyExp.setTag(tag.toString());
+
+ // 璁剧疆鍦ㄧ嚎鏁版嵁閲嶇偣浣嶇疆
+ try {
+ // 浠庨鏋勫缓鐨凪ap涓幏鍙栵紝閬垮厤姣忔杩囨护 姝g‘鑾峰緱鍦ㄧ嚎鏁版嵁浣嶇疆
+ List<TMonitorResult> onlines = noToOnlineMap.getOrDefault(result.getNo(), Collections.emptyList());
+ // 閲嶇偣鏌ョ湅涓嬮潰杩欎釜鏂规硶 videoDailyExp 浼犲叆闇�瑕佺粍瑁呭璞$殑 videoDailyExp 鍜� 鏁版嵁婧恟esult鍖呭惈鍔ㄦ�佸垪淇℃伅鐨勫璞� 鍜屼粬瀵瑰簲1鍒�31澶╃殑鍦ㄧ绾跨姸鎬�
+ setOnlineDaily(videoDailyExp, result, onlines);
+ } catch (Exception e) {
+ log.error("璁剧疆鍦ㄧ嚎鏁版嵁寮傚父", e);
+ }
+//
+ videoDailyExps.add(videoDailyExp);
+ }
+//
+ // 瀛樺偍缁撴灉鍒扮嚎绋嬪畨鍏ㄧ殑Map 缁撴灉濡� 鎸夊尯鍒嗗垎缁� 瀵瑰簲璁惧鐨� 1鍒�31鏃ョ殑鍦ㄧ绾胯鎯�
+ deptExpMap.put(currentDeptId, videoDailyExps);
+//
+ return new ExcelExp(areaName, videoDailyExps, VideoDailyExp.class);
+ }, threadPoolTaskExecutor);
+
+ futures.add(future);
+ }
+
+ // 绛夊緟鎵�鏈夊苟琛屼换鍔″畬鎴�
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+
+ // 鏀堕泦鎵�鏈夐儴闂ㄧ殑ExcelExp缁撴灉
+ for (CompletableFuture<ExcelExp> future : futures) {
+ ExcelExp excelExp = future.join();
+ if (excelExp != null) {
+ mysheet.add(excelExp);
+ }
+ }
+
+ // 鑾峰彇鍏ㄩ噺鏁版嵁骞舵坊鍔�"鍏ㄩ噺"sheet
+ List<VideoDailyExp> totalExps = deptExpMap.values().stream()
+ .flatMap(List::stream)
+ .collect(Collectors.toList());
+
+ mysheet.add(new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class));
+
+ // 缁熻鍚勭被鍨嬭澶囨暟閲�
+ long face = 0, car = 0, video = 0;
+ for (VideoDailyExp exp : totalExps) {
+ String type = exp.getType();
+ if (type.contains("1")) face++;
+ if (type.contains("2")) car++;
+ if (type.contains("3")) video++;
+ }
+
+ log.info("浜鸿劯鏁�:{}", face);
+ log.info("car鏁�:{}", car);
+ log.info("video鏁�:{}", video);
+
+ // 绂荤嚎鏁扮粺璁�
+ List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps = new ArrayList<>();
+ // 鍦ㄧ嚎鐜囩粺璁�
+ List<VideoOnlineRateExp> videoOnlineRateExps = new ArrayList<>();
+
+ for (Map.Entry<Integer, List<VideoDailyExp>> entry : deptExpMap.entrySet()) {
+ Integer deptId = entry.getKey();
+ List<VideoDailyExp> list = entry.getValue();
+ AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+
+ // 鎵归噺澶勭悊涓夌璁惧绫诲瀷 姣忎釜璁惧1鍒�31鍙峰湪绂荤嚎鎯呭喌
+ addDeviceStats(list, areaDeptEnum, "1", "浜鸿劯", videoTypeOffOnlineExps, videoOnlineRateExps);
+ addDeviceStats(list, areaDeptEnum, "2", "鍗″彛", videoTypeOffOnlineExps, videoOnlineRateExps);
+ addDeviceStats(list, areaDeptEnum, "3", "瑙嗛", videoTypeOffOnlineExps, videoOnlineRateExps);
+ }
+
+ // 璁$畻鍚堣鏁版嵁
+ addTotalStats(videoTypeOffOnlineExps, videoOnlineRateExps, face, car, video);
+
+ // 娣诲姞缁熻sheet
+ mysheet.add(new ExcelExp("绂荤嚎鏁扮粺璁�", videoTypeOffOnlineExps, VideoTypeOffOnlineExp.class));
+ mysheet.add(new ExcelExp("鍦ㄧ嚎鐜囩粺璁�", videoOnlineRateExps, VideoOnlineRateExp.class));
+
+ // 瀵煎嚭Excel
+ ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
+ util.exportExcelManySheet(response, mysheet);
+ log.info("瀵煎嚭缁撴潫");
+ }
+
+ // 鏂板杈呭姪鏂规硶锛氭壒閲忔坊鍔犺澶囩粺璁′俊鎭�
+ private void addDeviceStats(List<VideoDailyExp> list, AreaDeptEnum areaDeptEnum,
+ String typeCode, String typeName,
+ List<VideoTypeOffOnlineExp> offLineList,
+ List<VideoOnlineRateExp> onlineList) {
+ offLineList.add(getListOfflineCountInfo(list, typeCode, areaDeptEnum));
+ onlineList.add(getListOnLineCountInfo(list, typeCode, areaDeptEnum));
+ }
+
+ // 鏂板杈呭姪鏂规硶锛氭坊鍔犲悎璁$粺璁�
+ private void addTotalStats(List<VideoTypeOffOnlineExp> offLineList,
+ List<VideoOnlineRateExp> onlineList,
+ long face, long car, long video) throws NoSuchFieldException, IllegalAccessException {
+ // 绂荤嚎缁熻鍚堣
+ VideoTypeOffOnlineExp allFaceVideosOffline = new VideoTypeOffOnlineExp();
+ setAllVideoTypeOffOnlineExpCount(offLineList, allFaceVideosOffline, "浜鸿劯");
+
+ VideoTypeOffOnlineExp allCarVideosOffline = new VideoTypeOffOnlineExp();
+ setAllVideoTypeOffOnlineExpCount(offLineList, allCarVideosOffline, "鍗″彛");
+
+ VideoTypeOffOnlineExp allVideosOffline = new VideoTypeOffOnlineExp();
+ setAllVideoTypeOffOnlineExpCount(offLineList, allVideosOffline, "瑙嗛");
+
+ offLineList.add(allFaceVideosOffline);
+ offLineList.add(allCarVideosOffline);
+ offLineList.add(allVideosOffline);
+
+ // 鍦ㄧ嚎缁熻鍚堣
+ VideoOnlineRateExp allFaceVideosOnline = new VideoOnlineRateExp();
+ setAllVideoTypeOnlineExpCount(face, onlineList, allFaceVideosOnline, "浜鸿劯");
+
+ VideoOnlineRateExp allCarVideosOnline = new VideoOnlineRateExp();
+ setAllVideoTypeOnlineExpCount(car, onlineList, allCarVideosOnline, "鍗″彛");
+
+ VideoOnlineRateExp allVideosOnline = new VideoOnlineRateExp();
+ setAllVideoTypeOnlineExpCount(video, onlineList, allVideosOnline, "瑙嗛");
+
+ onlineList.add(allFaceVideosOnline);
+ onlineList.add(allCarVideosOnline);
+ onlineList.add(allVideosOnline);
+ }
+
+
+
+ //绂荤嚎璁惧鏁版嵁锛屽悎璁″璞★紝淇℃伅瑁呴厤
+ public void setAllVideoTypeOffOnlineExpCount(List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps,
+ VideoTypeOffOnlineExp videoTypeOffOnlineExp,
+ String type) throws NoSuchFieldException, IllegalAccessException {
+ List<VideoTypeOffOnlineExp> filterExps = videoTypeOffOnlineExps.stream().filter(exp -> type.equals(exp.getType())).collect(Collectors.toList());
+ long allCount = 0;
+ for (VideoTypeOffOnlineExp obj :filterExps){
+ //obj 瀵硅薄浠h〃浜嗚鍖� 绛涢�変簡鐨勬寚瀹歵ype鐨勮澶囩殑瀵硅薄
+ //璁$畻鎬荤殑璁惧绂荤嚎鎬绘暟
+ long count = Long.parseLong(obj.getOfflineCount());
+ allCount += count;
+ //璁$畻姣忔棩
+ for (int i =1 ;i <= 31; i++){
+ String fieldName = "day" + i;
+ Field dayField = obj.getClass().getDeclaredField(fieldName);
+ dayField.setAccessible(true);
+ Object value = dayField.get(obj); //鑾峰彇瀛楁鍊�
+ if (value != null) {
+ long newFieldValue = Long.parseLong(value.toString());
+ //鑾峰彇闇�瑕佸~鍏呯殑瀛楁
+ Field videoTypeOffOnlineExpField = videoTypeOffOnlineExp.getClass().getDeclaredField(fieldName);
+ videoTypeOffOnlineExpField.setAccessible(true);
+ //鍏堣幏鍙栦竴娆�
+ Object oldValue = videoTypeOffOnlineExpField.get(videoTypeOffOnlineExp);
+
+ //涓簄ull 绗竴娆$洿鎺ヨ璧嬪��
+ if (oldValue == null){
+ videoTypeOffOnlineExpField.set(videoTypeOffOnlineExp,newFieldValue + "");
+ }else {
+ //瀛樺湪鏃у�� 鐩稿姞瑕嗙洊
+ videoTypeOffOnlineExpField.set(videoTypeOffOnlineExp, (Long.parseLong(oldValue.toString()) + newFieldValue) + "");
+ }
+ }
+
+
+
+ }
+
+ }
+ videoTypeOffOnlineExp.setOfflineCount(String.valueOf(allCount));
+ videoTypeOffOnlineExp.setArea("鑷础甯�");
+ videoTypeOffOnlineExp.setType(type + "鍚堣");
+ }
+// 鍦ㄧ嚎璁惧鏁版嵁锛屽悎璁″璞★紝淇℃伅瑁呴厤
+ public void setAllVideoTypeOnlineExpCount(
+ long allVideoCount,List<VideoOnlineRateExp> videoOnlineRateExps,
+ VideoOnlineRateExp videoOnlineRateExp,
+ String type) throws NoSuchFieldException, IllegalAccessException{
+ List<VideoOnlineRateExp> filterExps = videoOnlineRateExps.stream().filter(item -> type.equals(item.getType())).collect(Collectors.toList());
+
+ for (VideoOnlineRateExp obj :filterExps){
+ for (int i = 1;i <= 31; i++){
+ String countFileName = "count" +i;
+ Field countField = obj.getClass().getDeclaredField(countFileName);
+ countField.setAccessible(true);
+ long newFieldValue = countField.getLong(obj);
+ Field videoOnlineRateExpField = obj.getClass().getDeclaredField(countFileName);
+ videoOnlineRateExpField.setAccessible(true);
+ Object oldValue = videoOnlineRateExpField.get(videoOnlineRateExp);
+ if (oldValue == null){
+ videoOnlineRateExpField.setLong(videoOnlineRateExp,newFieldValue);
+ }else {
+ //瀛樺湪鏃у�� 鐩稿姞瑕嗙洊
+ videoOnlineRateExpField.setLong(videoOnlineRateExp, Long.parseLong(oldValue.toString()) + newFieldValue);
+ }
+ }
+ }
+ //璁$畻瀹屾瘡鏃ュ湪绾胯澶囨暟
+ //寰幆涓�涓湀
+ for (int i = 1;i <= 31 ;i++){
+ //鍦ㄧ嚎鐜囪绠�
+ String countFileName = "count" +i;
+ Field countField = videoOnlineRateExp.getClass().getDeclaredField(countFileName);
+ countField.setAccessible(true);
+ long newFieldValue = countField.getLong(videoOnlineRateExp);
+ String fieldName = "day" + i;
+ //姣忔棩鍦ㄧ嚎鐜�
+ double rate = (double) newFieldValue / allVideoCount;
+ //鍙嶅皠娣诲姞鍒板璞″睘鎬т腑
+ 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);
+ }
+
+ }
+
+
+ videoOnlineRateExp.setArea("鑷础甯�");
+ videoOnlineRateExp.setType(type + "鍚堣");
+ }
+
+
+
+
+
+ /**
+ * 璁$畻绂荤嚎璁惧excel瀵硅薄淇℃伅
+ * @param videoDailyExps 浼犲叆鐨勮澶囬泦鍚堜俊鎭�
+ * @param type 璁惧绫诲瀷 1浜鸿劯 2杞﹁締 3瑙嗛
+ * @param areaDeptEnum 鍖哄煙
+ * @return
+ */
+ public VideoTypeOffOnlineExp getListOfflineCountInfo(List<VideoDailyExp> videoDailyExps,
+ String type,
+ AreaDeptEnum areaDeptEnum
+ ){
+ 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);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ //璁惧绫诲瀷
+ 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)throws NoSuchFieldException, IllegalAccessException {
+ //寰幆涓�涓湀
+ //绂荤嚎鎬绘暟
+ long AllOffLineCount = 0;
+ for (VideoDailyExp videoDailyExp : videoDailyExps) {
+ if (videoDailyExp.isAllOfflineByMonth()) {
+ AllOffLineCount++;
+ }
+ }
+ //鏄悎璁℃暟鎹笉闇�瑕佷笅鏂规暟鎹�
+
+ 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
+ ){
+ 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);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ //璁惧绫诲瀷
+ 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)throws NoSuchFieldException, IllegalAccessException {
+ //寰幆涓�涓湀
+ for (int i = 1;i <= 31 ;i++){
+ //鍦ㄧ嚎鐜囪绠�
+ long count = 0;
+ String fieldName = "day" + i;
+ String countName = "count" + i;
+ for(VideoDailyExp videoDailyExp: videoDailyExps){
+ try {
+ // 鏋勯�犲瓧娈靛悕
+ Field field = videoDailyExp.getClass().getDeclaredField(fieldName);
+ // 纭繚瀛楁鏄鏈夌殑鍙互璁块棶
+ field.setAccessible(true);
+ // 鑾峰彇瀛楁鍊�
+ String value = (String) field.get(videoDailyExp);
+ if ("鍦ㄧ嚎".equals(value)) {
+ count ++;
+ }
+ } catch (NoSuchFieldException e) {
+ // 瀛楁涓嶅瓨鍦ㄦ椂璺宠繃褰撳墠寰幆锛岃褰曟棩蹇�
+ log.warn("VideoDailyExp 涓嶅瓨鍦ㄥ瓧娈�: {}", fieldName, e);
+ } catch (IllegalAccessException e) {
+ // 瀛楁璁块棶寮傚父鏃惰烦杩囷紝璁板綍鏃ュ織
+ log.error("璁块棶瀛楁 {} 澶辫触", fieldName, e);
+ }
+ }
+ //姣忔棩鍦ㄧ嚎鐜�
+ double rate = (double) count / videoDailyExps.size();
+ log.info("鎵撳嵃璁$畻鍑虹殑count:{}",count);
+ //鍙嶅皠娣诲姞鍒板璞″睘鎬т腑
+ Field field = videoOnlineRateExp.getClass().getDeclaredField(fieldName);
+ Field countField = videoOnlineRateExp.getClass().getDeclaredField(countName);
+ countField.setAccessible(true);
+ //璁剧疆姣忔棩鍦ㄧ嚎璁惧璁惧鏁�
+ countField.setLong(videoOnlineRateExp, count);
+ field.setAccessible(true);
+ String rateStr = String.format("%.2f", rate * 100) +"%";
+ if (!"0.00%".equals(rateStr)){
+ field.set(videoOnlineRateExp, rateStr);
+ }
+
+ }
+ }
+
+
+ /**
+ * 瀵煎嚭姣忔棩褰曞儚鎯呭喌鏁版嵁
+ */
+ @Override
+ public void exportVideoRecord(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
+ //榛樿鏌ユ墍鏈夐儴闂�
+ if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
+ List<Integer> deptIds = new ArrayList<>();
+ for (AreaDeptEnum value : AreaDeptEnum.values()) {
+ deptIds.add(value.getDeptId());
+ }
+ exportForm.setDeptIds(deptIds);
+ }
+
+ VideoExportForm.convertTags(exportForm);
+ Query query = getQuery(exportForm);
+ //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+ List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+
+ // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+ Map<String, TMonitorResult> uniqueResultsMap = onlineResult.stream()
+ .collect(Collectors.toMap(
+ TMonitorResult::getNo, // keyMapper锛岃繖閲屽亣璁� getNo() 杩斿洖 No 瀛楁
+ Function.identity(), // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬�
+ (existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓�
+ ));
+ // 灏� Map 杞崲涓� List
+ List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ //鑾峰彇鍔ㄦ�佸垪鏁版嵁
+ List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
+ List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
+ //琛ュ厖鍔ㄦ�佸垪鏁版嵁
+ if (!CollectionUtils.isEmpty(dynamics)) {
+ Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
+ for (TMonitorResult tMonitorResult : tMonitorResults) {
+ Integer pointId = tMonitorResult.getPointId();
+ tMonitorResult.setDynamicColumnList(map.get(pointId));
+ }
+ }
+
+ // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
+ YearMonth yearMonth = YearMonth.parse(exportForm.getMonth());
+ // 鑾峰彇褰撴湀鐨勭涓�澶�
+ LocalDate start = yearMonth.atDay(1);
+ // 鑾峰彇涓嬩釜鏈堢殑绗竴澶╋紙閫氳繃鍔犱笂1涓湀骞惰缃棩涓�1锛�
+ YearMonth nextMonth = yearMonth.plusMonths(1);
+ LocalDate end = nextMonth.atDay(1);
+ //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹紝褰曞儚鐢变簬鏄墠涓�澶╃殑鎵�浠ヤ笉鐢╟reateTime瀛楁
+ Query videoQuery = new Query(Criteria.where("statTime").gte(start).lt(end));
+ videoQuery.addCriteria(Criteria.where("no").in(deviceIds));
+ //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
+ List<RecordMetaDSumResult> recordResult = mongoTemplate.find(videoQuery, RecordMetaDSumResult.class);
+
+ // 棰勫厛鎸夐儴闂↖D鍒嗙粍
+ Map<Integer, List<TMonitorResult>> monitorsByDept = tMonitorResults.stream()
+ .collect(Collectors.groupingBy(TMonitorResult::getDeptId));
+ // 棰勫厛鏋勫缓鏄犲皠
+ Map<String, List<RecordMetaDSumResult>> recordMap = recordResult.stream()
+ .collect(Collectors.groupingBy(RecordMetaDSumResult::getNo));
+ List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
+ for (Integer deptId : exportForm.getDeptIds()) {
+ CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
+ List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+ // 鑾峰彇褰撳墠閮ㄩ棬鐨勬暟鎹�
+ List<TMonitorResult> monitors = monitorsByDept.getOrDefault(deptId, Collections.emptyList());
+ if (CollectionUtils.isEmpty(monitors)) return videoDailyExps;
+ AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+ for (TMonitorResult result : monitors) {
+ VideoDailyExp videoDailyExp = new VideoDailyExp();
+ videoDailyExp.setSerialNumber(result.getNo());
+ videoDailyExp.setDeviceName(result.getName());
+ videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
+ StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+ //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
+ if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
+ List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
+ for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
+ tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+ }
+ }
+ // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+ if (tag.toString().endsWith("銆�")) {
+ tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+ }
+ videoDailyExp.setTag(tag.toString());
+ // 浣跨敤Map鐩存帴鑾峰彇璁板綍锛岄伩鍏峟ilter鎿嶄綔
+ List<RecordMetaDSumResult> recordsResult = recordMap.get(result.getNo());
+ try {
+ if (!CollectionUtils.isEmpty(recordsResult))
+ setRecordDaily(videoDailyExp, result, recordsResult);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ //鍖哄幙琛�
+ videoDailyExps.add(videoDailyExp);
+ }
+ return videoDailyExps;
+ }, threadPoolTaskExecutor);
+ futures.add(future);
+ }
+ // 绛夊緟鎵�鏈変换鍔″畬鎴�
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+ // 姣忎釜閮ㄩ棬鐨勬暟鎹崟鐙繚瀛�
+ List<List<VideoDailyExp>> results = futures.stream()
+ .map(CompletableFuture::join) // 鑾峰彇姣忎釜Future鐨勭粨鏋�
+ .collect(Collectors.toList());
+ List<VideoDailyExp> totalExps = new ArrayList<>();
+ List<ExcelExp> mysheet = new ArrayList<>();
+ for (List<VideoDailyExp> result : results) {
+ ExcelExp excelExp = new ExcelExp(
+ result.get(0).getArea() == null ? "鏈煡" : result.get(0).getArea(),
+ result,
+ VideoDailyExp.class);
+ mysheet.add(excelExp);
+ totalExps.addAll(result);
+ }
+
+ ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
+ util.exportExcelManySheet(response, mysheet);
+ }
+
+ /**
+ * 瀵煎嚭姣忔棩褰曞儚缂哄け鏃堕暱
+ */
+ @Override
+ public void exportVideoLoseTime(HttpServletResponse response, VideoExportForm exportForm) throws NoSuchFieldException, IllegalAccessException, IOException {
+ //榛樿鏌ユ墍鏈夐儴闂�
+ if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
+ List<Integer> deptIds = new ArrayList<>();
+ for (AreaDeptEnum value : AreaDeptEnum.values()) {
+ deptIds.add(value.getDeptId());
+ }
+ exportForm.setDeptIds(deptIds);
+ }
+ Query query = getQuery(exportForm);
+
+
+ //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+ List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+ // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+ Map<String, TMonitorResult> uniqueResultsMap = onlineResult.stream()
+ .collect(Collectors.toMap(
+ TMonitorResult::getNo, // keyMapper锛岃繖閲屽亣璁� getNo() 杩斿洖 No 瀛楁
+ Function.identity(), // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬�
+ (existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓�
+ ));
+
+ // 灏� Map 杞崲涓� List
+ List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
+ //鑾峰彇鍔ㄦ�佸垪鏁版嵁
+ List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
+ List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
+ //琛ュ厖鍔ㄦ�佸垪鏁版嵁
+ if (!CollectionUtils.isEmpty(dynamics)) {
+ Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
+ for (TMonitorResult tMonitorResult : tMonitorResults) {
+ Integer pointId = tMonitorResult.getPointId();
+ tMonitorResult.setDynamicColumnList(map.get(pointId));
+ }
+ }
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
+ YearMonth yearMonth = YearMonth.parse(exportForm.getMonth());
+ // 鑾峰彇褰撴湀鐨勭涓�澶�
+ LocalDate start = yearMonth.atDay(1);
+ // 鑾峰彇涓嬩釜鏈堢殑绗竴澶╋紙閫氳繃鍔犱笂1涓湀骞惰缃棩涓�1锛�
+ YearMonth nextMonth = yearMonth.plusMonths(1);
+ LocalDate end = nextMonth.atDay(1);
+ //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹紝褰曞儚鐢变簬鏄墠涓�澶╃殑鎵�浠ヤ笉鐢╟reateTime瀛楁
+ Query videoQuery = new Query(Criteria.where("statTime").gte(start).lt(end));
+ videoQuery.addCriteria(Criteria.where("no").in(deviceIds));
+ //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
+ List<RecordMetaDSumResult> recordResult = mongoTemplate.find(videoQuery, RecordMetaDSumResult.class);
+ // 棰勫厛鎸夐儴闂↖D鍒嗙粍
+ Map<Integer, List<TMonitorResult>> monitorsByDept = tMonitorResults.stream()
+ .collect(Collectors.groupingBy(TMonitorResult::getDeptId));
+ // 棰勫厛鏋勫缓鏄犲皠
+ Map<String, List<RecordMetaDSumResult>> recordMap = recordResult.stream()
+ .collect(Collectors.groupingBy(RecordMetaDSumResult::getNo));
+
+ List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
+ for (Integer deptId : exportForm.getDeptIds()) {
+ CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
+ List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+ // 鑾峰彇褰撳墠閮ㄩ棬鐨勬暟鎹�
+ List<TMonitorResult> monitors = monitorsByDept.getOrDefault(deptId, Collections.emptyList());
+ if (CollectionUtils.isEmpty(monitors)) return videoDailyExps;
+ AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+ for (TMonitorResult result : monitors) {
+ VideoDailyExp videoDailyExp = new VideoDailyExp();
+ videoDailyExp.setSerialNumber(result.getNo());
+ videoDailyExp.setDeviceName(result.getName());
+ videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
+ StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+ //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
+ if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
+ List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
+ for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
+ tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+ }
+ }
+ // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+ if (tag.toString().endsWith("銆�")) {
+ tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+ }
+ videoDailyExp.setTag(tag.toString());
+ // 浣跨敤Map鐩存帴鑾峰彇璁板綍锛岄伩鍏峟ilter鎿嶄綔
+ List<RecordMetaDSumResult> recordsResult = recordMap.get(result.getNo());
+ try {
+ if (!CollectionUtils.isEmpty(recordsResult)) setLoseDaily(videoDailyExp, recordsResult);
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ videoDailyExps.add(videoDailyExp);
+ }
+ return videoDailyExps;
+ }, threadPoolTaskExecutor);
+ futures.add(future);
+ }
+ // 绛夊緟鎵�鏈変换鍔″畬鎴�
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+
+ // 姣忎釜閮ㄩ棬鐨勬暟鎹崟鐙繚瀛�
+ List<List<VideoDailyExp>> results = futures.stream()
+ .map(CompletableFuture::join) // 鑾峰彇姣忎釜Future鐨勭粨鏋�
+ .collect(Collectors.toList());
+ List<VideoDailyExp> totalExps = new ArrayList<>();
+ List<ExcelExp> mysheet = new ArrayList<>();
+ for (List<VideoDailyExp> result : results) {
+ ExcelExp excelExp = new ExcelExp(
+ result.get(0).getArea() == null ? "鏈煡" : result.get(0).getArea(),
+ result,
+ VideoDailyExp.class);
+ mysheet.add(excelExp);
+ totalExps.addAll(result);
+ }
+ ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
+ util.exportExcelManySheet(response, mysheet);
+ }
+
+ //棣栭〉瑙嗛鎶ヨ〃
+ @Override
+ public Map<String, Object> videoHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
+ List<HomeVideoVO> results = new ArrayList<>();
+
+ String month = monitorQuery.getDate();
+ if (StringUtils.isEmpty(month)) {
+ //濡傛灉涓虹┖鏌ユ湰鏈堢殑鏁版嵁
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
+ month = simpleDateFormat.format(new Date());
+ }
+ // 鍒涘缓涓�涓猄impleDateFormat瀵硅薄鏉ヨВ鏋愭棩鏈熷瓧绗︿覆
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ Date date = sdf.parse(month);
+ // 鍒涘缓涓�涓狢alendar瀵硅薄骞惰缃椂闂翠负瑙f瀽鍑虹殑Date
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ // 璁剧疆Calendar涓烘湀浠界殑绗竴澶�
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ // 鑾峰彇鏈堜唤绗竴澶╃殑Date
+ Date startDate = calendar.getTime();
+ log.info("棣栭〉鏌ヨ寮�濮嬫棩鏈�:{}",startDate);
+ // 璁剧疆Calendar涓烘湀浠界殑鏈�鍚庝竴澶╋紙閫氳繃澧炲姞涓�涓湀浠界劧鍚庡噺鍘讳竴澶╋級
+ calendar.add(Calendar.MONTH, 1);
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ // 鑾峰彇鏈堜唤鏈�鍚庝竴澶╃殑Date
+ Date endDate = calendar.getTime();
+ log.info("棣栭〉鏌ヨ缁撴潫鏃ユ湡:{}",endDate);
+ String constructionType = monitorQuery.getConstructionType();
+ List<String> deviceNoList = new ArrayList<>();
+ if (StringUtils.isNotBlank(constructionType)){
+ List<MonitorConstruction> serialNumberListByConstructionType = monitorConstructionService.getSerialNumberListByConstructionType(constructionType);
+ if (!CollectionUtils.isEmpty(serialNumberListByConstructionType)){
+ deviceNoList = serialNumberListByConstructionType.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList());
+ }
+ }
+ if (StringUtils.isNotBlank(constructionType) && deviceNoList.isEmpty()) {
+ // 褰揷onstructionType鏈夊�间絾鏃犲搴旇澶囨椂锛岃繑鍥炲寘鍚┖鍒楄〃鐨凪ap
+ Map<String, Object> emptyResult = new HashMap<>();
+ emptyResult.put("list", results); // results姝ゆ椂涓虹┖鍒楄〃
+ emptyResult.put("baseLine", 0); // 鍙牴鎹笟鍔¢粯璁ゅ熀鍑嗙嚎鍊艰皟鏁�
+ return emptyResult;
+ }
+ //mongo鏌ュ綍鍍忕姸鎬�
+ MongoDatabase database = mongoTemplate.getDb();
+ MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
+ Integer examineTag = monitorQuery.getExamineTag();
+ String arealayerno = monitorQuery.getArea();
+ Document matchConditions = new Document("statTime", new Document("$gte", startDate).append("$lte", endDate));
+ if (!deviceNoList.isEmpty()) {
+ log.info("鎵撳嵃鍒嗗缓绫诲瀷no闆嗗悎:{}",deviceNoList);
+ matchConditions.append("no", new Document("$in", deviceNoList));
+ }
+ // 鏍规嵁examineTag鐨勫�煎姩鎬佹坊鍔犻澶栫殑鏉′欢
+ if (examineTag != null && examineTag.equals(1)) {
+ matchConditions.append("provinceTag", true);
+ } else if (examineTag != null && examineTag.equals(2)) {
+ matchConditions.append("deptTag", true);
+ } else if(StringUtils.isNotBlank(arealayerno)){
+ matchConditions.append("arealayerno",
+ new Document("$regex", "^" + arealayerno));
+ }
+ Document noExpr = new Document("$and", Arrays.asList(
+ new Document("$gte", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+ new Document("$ne", Arrays.asList(
+ new Document("$substrCP", Arrays.asList(
+ "$no",
+ new Document("$subtract", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+ 1
+ )),
+ "3"
+ ))
+ ));
+// 姝g‘娣诲姞$expr鏉′欢锛堥敭涓�"$expr"锛屽�间负涓婇潰瀹氫箟鐨勬潯浠讹級
+ matchConditions.append("$expr", noExpr);
+ // 鏋勫缓鑱氬悎绠¢亾
+ List<Document> pipeline = Arrays.asList(
+ new Document("$match", matchConditions),
+ new Document("$group", new Document("_id", "$statTime")
+ .append("normalCount", new Document("$sum",
+ new Document("$cond", Arrays.asList(
+ new Document("$eq", Arrays.asList("$recordStatus", 1)),
+ 1,
+ 0
+ ))
+ ))
+ .append("loseCount", new Document("$sum",
+ new Document("$cond", Arrays.asList(
+ new Document("$eq", Arrays.asList("$recordStatus", 0)),
+ 1,
+ 0
+ ))
+ ))
+ .append("errCount", new Document("$sum",
+ new Document("$cond", Arrays.asList(
+ new Document("$eq", Arrays.asList("$recordStatus", -1)),
+ 1,
+ 0
+ ))
+ ))
+ )
+ );
+ // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
+ AggregateIterable<Document> result = collection.aggregate(pipeline);
+ for (Document doc : result) {
+ HomeVideoVO homeVideoVO = new HomeVideoVO();
+ homeVideoVO.setCreateDate(doc.getDate("_id"));
+ homeVideoVO.setIntegrityNum(doc.getInteger("normalCount"));
+ homeVideoVO.setLoseNum(doc.getInteger("loseCount"));
+ homeVideoVO.setErrNum(doc.getInteger("errCount"));
+
+ results.add(homeVideoVO);
+ }
+
+ //mongo鏌ョ偣浣嶅湪绾�
+ MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
+ // 鏋勫缓鍩烘湰鐨�$match鏉′欢
+ List<Document> onlineMatch = new ArrayList<>();
+ onlineMatch.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
+ onlineMatch.add(new Document("monitorType", new Document("$regex", "1")));
+ if (!deviceNoList.isEmpty()) {
+ onlineMatch.add(new Document("no", new Document("$in", deviceNoList)));
+ }
+ if (examineTag != null && examineTag.equals(1)) {
+ onlineMatch.add(new Document("provinceTag", true));
+ } else if (examineTag != null && examineTag.equals(2)) {
+ onlineMatch.add(new Document("deptTag", true));
+ } else if(StringUtils.isNotBlank(arealayerno)){
+ Document noStartsWith = new Document("no", new Document("$regex", "^" + arealayerno));
+
+ // 鏋勫缓鍊掓暟绗笁浣嶄笉鏄�3鐨勬潯浠�
+ Document noThirdLastNot3 = new Document("$expr", new Document("$and", Arrays.asList(
+ new Document("$gte", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+ new Document("$ne", Arrays.asList(
+ new Document("$substrCP", Arrays.asList(
+ "$no",
+ new Document("$subtract", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+ 1
+ )),
+ "3"
+ ))
+ )));
+ // 灏嗕袱涓潯浠剁敤$and缁勫悎鍚庢坊鍔犲埌鏉′欢鍒楄〃
+ onlineMatch.add(new Document("$and", Arrays.asList(noStartsWith, noThirdLastNot3)));
+ }
+ // 鏋勫缓鑱氬悎绠¢亾
+ List<Document> onlinePipeline = Arrays.asList(
+ new Document("$match", new Document("$and", onlineMatch)),
+ new Document("$group", new Document("_id", "$mongoCreateTime")
+ .append("onlineCount", new Document("$sum",
+ new Document("$cond", Arrays.asList(
+ new Document("$eq", Arrays.asList("$online", ApiConstants.UY_OnlineSite_Online)),
+ 1,
+ 0
+ ))
+ ))
+ )
+ );
+ //鎺掗櫎鍗″彛闆嗗悎
+
+
+
+ // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
+ AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
+ for (Document doc : onlineResult) {
+ HomeVideoVO vo = findOrCreateVO(doc, results, HomeVideoVO.class);
+ vo.setOnline(doc.getInteger("onlineCount"));
+ }
+ results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
+ Map<String, Object> resultMap = new HashMap<>();
+ resultMap.put("list", results);
+ //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
+ List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
+ String condition;
+ if (examineTag != null && examineTag == 1) {
+ condition = "video_province_baseLine";
+ } else if (examineTag != null && examineTag == 2) {
+ condition = "video_dept_baseLine";
+ } else {
+ condition = "video_all_baseLine";
+ }
+ Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
+ if (first.isPresent()) {
+ SysDictData sysDictData = first.get();
+ resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
+ }
+ return resultMap;
+ }
+
+ /**
+ * 鍒楄〃瀵煎嚭
+ *
+ * @param response
+ * @param tMonitor
+ */
+ @Override
+ public void export(HttpServletResponse response, TMonitorVO tMonitor) {
+ List<TMonitorExp> monitors = tMonitorMapper.exportTMonitorList(tMonitor);
+ //杩囨护鍑鸿澶囧缓璁剧被鍨�
+ if (StringUtils.isNotBlank(tMonitor.getConstructionType())){
+ List<MonitorConstruction> list =
+ monitorConstructionService.getSerialNumberListByConstructionType(tMonitor.getConstructionType());
+ //鑾峰緱璁惧缂栧彿闆嗗悎 閫氳繃寤鸿绫诲瀷鏍囩
+ List<String> serialNumberList = list.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList());
+ monitors = monitors.stream()
+ .filter(result -> {
+ String sn = result.getSerialNumber();
+ // 浠讳竴瀛楁闈炵┖涓斿湪闆嗗悎涓嵆鍙�
+ return (sn != null && serialNumberList.contains(sn));
+ })
+ .collect(Collectors.toList());
+ }
+
+
+ //鑾峰彇鍔ㄦ�佸垪鏁版嵁
+ List<Integer> pointIds = monitors.stream().map(TMonitorExp::getPointId).collect(Collectors.toList());
+ List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
+ //琛ュ厖鍔ㄦ�佸垪鏁版嵁
+ if (!CollectionUtils.isEmpty(dynamics)) {
+ Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
+ for (TMonitorExp tMonitorResult : monitors) {
+ Integer pointId = tMonitorResult.getPointId();
+ tMonitorResult.setDynamicColumnList(map.get(pointId));
+ }
+ }
+ monitors.forEach(monitor -> {
+ String cameraFunType = monitor.getCameraFunType();
+ if (!StringUtils.isEmpty(cameraFunType)) {
+ String video = cameraFunType.replaceAll("1", "瑙嗛");
+ String car = video.replaceAll("2", "杞﹁締");
+ String type = car.replaceAll("3", "浜鸿劯");
+ monitor.setCameraFunType(type);
+ }
+ StringBuilder tag = new StringBuilder("" + (monitor.getProvinceTagVideo() ? "鐪佸巺瑙嗛銆�" : "") + (monitor.getProvinceTagCar() ? "鐪佸巺杞﹁締銆�" : "") + (monitor.getProvinceTagFace() ? "鐪佸巺浜鸿劯銆�" : "") + (monitor.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (monitor.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (monitor.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+ //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
+ if (!CollectionUtils.isEmpty(monitor.getDynamicColumnList())) {
+ List<DynamicColumnVO> dynamicColumnList = monitor.getDynamicColumnList();
+ for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
+ tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+ }
+ }
+ // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+ if (tag.toString().endsWith("銆�")) {
+ tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+ }
+ monitor.setTag(tag.toString());
+ });
+ ExcelUtil<TMonitorExp> util = new ExcelUtil<>(TMonitorExp.class);
+ String sheetName = "";
+ if ("1".equals(tMonitor.getCameraFunType())) {
+ sheetName = "瑙嗛";
+ } else if ("2".equals(tMonitor.getCameraFunType())) {
+ sheetName = "杞﹁締";
+ } else if ("3".equals(tMonitor.getCameraFunType())) {
+ 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);
+ }
+
+
+ //棣栭〉杞﹁締鎶ヨ〃
+ @Override
+ public Map<String, Object> carHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
+ List<HomeCarVO> results = new ArrayList<>();
+ String month = monitorQuery.getDate();
+ if (StringUtils.isEmpty(month)) {
+ //濡傛灉涓虹┖鏌ユ湰鏈堢殑鏁版嵁
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
+ month = simpleDateFormat.format(new Date());
+ }
+ // 鍒涘缓涓�涓猄impleDateFormat瀵硅薄鏉ヨВ鏋愭棩鏈熷瓧绗︿覆
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ Date date = sdf.parse(month);
+ // 鍒涘缓涓�涓狢alendar瀵硅薄骞惰缃椂闂翠负瑙f瀽鍑虹殑Date
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ // 璁剧疆Calendar涓烘湀浠界殑绗竴澶�
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ // 鑾峰彇鏈堜唤绗竴澶╃殑Date
+ Date startDate = calendar.getTime();
+ // 璁剧疆Calendar涓烘湀浠界殑鏈�鍚庝竴澶╋紙閫氳繃澧炲姞涓�涓湀浠界劧鍚庡噺鍘讳竴澶╋級
+ calendar.add(Calendar.MONTH, 1);
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ // 鑾峰彇鏈堜唤鏈�鍚庝竴澶╃殑Date
+ Date endDate = calendar.getTime();
+ //mongo鏌ユ姄鎷嶉噺
+ MongoDatabase database = mongoTemplate.getDb();
+ MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor");
+ Integer examineTag = monitorQuery.getExamineTag();
+ // 鏋勫缓鍩烘湰鐨�$match鏉′欢
+ List<Document> matchConditions = new ArrayList<>();
+ String arealayerno = monitorQuery.getArea();
+ matchConditions.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
+ matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR)));
+ if (examineTag != null && examineTag.equals(1)) {
+ matchConditions.add(new Document("provinceTag", true));
+ }else if(StringUtils.isNotBlank(arealayerno)){
+ matchConditions.add(new Document("orgCode",new Document("$eq", arealayerno)));
+ }
+ // 鏋勫缓鑱氬悎绠¢亾
+ List<Document> pipeline = Arrays.asList(
+ new Document("$match", new Document("$and", matchConditions)),
+ new Document("$group", new Document("_id", "$mongoCreateTime")
+ .append("dataCount", new Document("$sum", "$dataCount"))
+ )
+ );
+ // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
+ AggregateIterable<Document> result = collection.aggregate(pipeline);
+ for (Document doc : result) {
+ HomeCarVO homecarVO = new HomeCarVO();
+ homecarVO.setCreateDate(doc.getDate("_id"));
+ homecarVO.setSnapCount(doc.getInteger("dataCount"));
+ results.add(homecarVO);
+ }
+
+ MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
+ // 鏋勫缓鍩烘湰鐨�$match鏉′欢
+ List<Document> onlineMatch = new ArrayList<>();
+ onlineMatch.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
+ onlineMatch.add(new Document("monitorType", new Document("$regex", "2")));
+ if (examineTag != null && examineTag.equals(1)) {
+ onlineMatch.add(new Document("provinceTag", true));
+ }else if(StringUtils.isNotBlank(arealayerno)){
+ onlineMatch.add(new Document("no", new Document("$regex", "^" + arealayerno)));
+ }
+ // 鏋勫缓鑱氬悎绠¢亾
+ List<Document> onlinePipeline = Arrays.asList(
+ new Document("$match", new Document("$and", onlineMatch)),
+ new Document("$group", new Document("_id", "$mongoCreateTime")
+ .append("onlineCount", new Document("$sum",
+ new Document("$cond", Arrays.asList(
+ new Document("$eq", Arrays.asList("$online", ApiConstants.UY_OnlineSite_Online)),
+ 1,
+ 0
+ ))
+ ))
+ )
+ );
+ // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
+ AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
+ for (Document doc : onlineResult) {
+ HomeCarVO vo = findOrCreateVO(doc, results, HomeCarVO.class);
+ vo.setOnline(doc.getInteger("onlineCount"));
+ }
+ Map<String, Object> resultMap = new HashMap<>();
+ //鎸夋椂闂存帓搴�
+ results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
+ //濡傛灉鏄粯璁ゆ垨绱拰鍒欒繘琛岀疮鍜屼互鍙婅幏鍙栧熀鍑嗙嚎
+ if (monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
+ int snapCount = 0;
+ for (HomeCarVO vo : results) {
+ if (vo.getSnapCount() != null) {
+ snapCount += vo.getSnapCount();
+ }
+ vo.setSnapCount(snapCount);
+ }
+ //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
+ List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
+ String condition;
+ if (examineTag != null && examineTag == 1) {
+ condition = "car_province_baseLine";
+ } else if (examineTag != null && examineTag == 2) {
+ condition = "car_dept_baseLine";
+ } else {
+ condition = "car_all_baseLine";
+ }
+
+ Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
+ if (first.isPresent()) {
+ SysDictData sysDictData = first.get();
+ resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
+ }
+ }
+ resultMap.put("list", results);
+ return resultMap;
+ }
+
+ //棣栭〉浜鸿劯鎶ヨ〃
+ @Override
+ public Map<String, Object> faceHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
+ List<HomeFaceVO> results = new ArrayList<>();
+ String month = monitorQuery.getDate();
+ if (StringUtils.isEmpty(month)) {
+ //濡傛灉涓虹┖鏌ユ湰鏈堢殑鏁版嵁
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
+ month = simpleDateFormat.format(new Date());
+ }
+ // 鍒涘缓涓�涓猄impleDateFormat瀵硅薄鏉ヨВ鏋愭棩鏈熷瓧绗︿覆
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ Date date = sdf.parse(month);
+ // 鍒涘缓涓�涓狢alendar瀵硅薄骞惰缃椂闂翠负瑙f瀽鍑虹殑Date
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ // 璁剧疆Calendar涓烘湀浠界殑绗竴澶�
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ // 鑾峰彇鏈堜唤绗竴澶╃殑Date
+ Date startDate = calendar.getTime();
+ // 璁剧疆Calendar涓烘湀浠界殑鏈�鍚庝竴澶╋紙閫氳繃澧炲姞涓�涓湀浠界劧鍚庡噺鍘讳竴澶╋級
+ calendar.add(Calendar.MONTH, 1);
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
+ // 鑾峰彇鏈堜唤鏈�鍚庝竴澶╃殑Date
+ Date endDate = calendar.getTime();
+ String arealayerno = monitorQuery.getArea();
+ //mongo鏌ユ姄鎷嶉噺
+ MongoDatabase database = mongoTemplate.getDb();
+ MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor");
+ Integer examineTag = monitorQuery.getExamineTag();
+ // 鏋勫缓鍩烘湰鐨�$match鏉′欢
+ List<Document> matchConditions = new ArrayList<>();
+ matchConditions.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
+ matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_FACE)));
+ if (examineTag != null && examineTag.equals(1)) {
+ matchConditions.add(new Document("provinceTag", true));
+ }else if(StringUtils.isNotBlank(arealayerno)){
+ matchConditions.add(new Document("orgCode",new Document("$eq", arealayerno)));
+ }
+ // 鏋勫缓鑱氬悎绠¢亾
+ List<Document> pipeline = Arrays.asList(
+ new Document("$match", new Document("$and", matchConditions)),
+ new Document("$group", new Document("_id", "$mongoCreateTime")
+ .append("dataCount", new Document("$sum", "$dataCount"))
+ )
+ );
+
+ // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
+ AggregateIterable<Document> result = collection.aggregate(pipeline);
+ for (Document doc : result) {
+ HomeFaceVO homefaceVO = new HomeFaceVO();
+ homefaceVO.setCreateDate(doc.getDate("_id"));
+ homefaceVO.setSnapCount(doc.getInteger("dataCount"));
+ results.add(homefaceVO);
+ }
+
+ //mongo鏌ョ偣浣嶅湪绾�
+ MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
+ // 鏋勫缓鍩烘湰鐨�$match鏉′欢
+ List<Document> onlineMatch = new ArrayList<>();
+ onlineMatch.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
+ onlineMatch.add(new Document("monitorType", new Document("$regex", "3")));
+ if (examineTag != null && examineTag.equals(1)) {
+ onlineMatch.add(new Document("provinceTag", true));
+ }else if(StringUtils.isNotBlank(arealayerno)){
+ onlineMatch.add(new Document("no", new Document("$regex", "^" + arealayerno)));
+ }
+ // 鏋勫缓鑱氬悎绠¢亾
+ List<Document> onlinePipeline = Arrays.asList(
+ new Document("$match", new Document("$and", onlineMatch)),
+ new Document("$group", new Document("_id", "$mongoCreateTime")
+ .append("onlineCount", new Document("$sum",
+ new Document("$cond", Arrays.asList(
+ new Document("$eq", Arrays.asList("$online", ApiConstants.UY_OnlineSite_Online)),
+ 1,
+ 0
+ ))
+ ))
+ )
+ );
+ // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
+ AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
+ for (Document doc : onlineResult) {
+ HomeFaceVO vo = findOrCreateVO(doc, results, HomeFaceVO.class);
+ vo.setOnline(doc.getInteger("onlineCount"));
+ }
+ Map<String, Object> resultMap = new HashMap<>();
+ //鎸夋椂闂存帓搴�
+ results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
+ //濡傛灉鏄粯璁ゆ垨绱拰鍒欒繘琛岀疮鍜屼互鍙婅幏鍙栧熀鍑嗙嚎
+ if (monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
+ int snapCount = 0;
+ for (HomeFaceVO vo : results) {
+ if (vo.getSnapCount() != null) {
+ snapCount += vo.getSnapCount();
+ }
+ vo.setSnapCount(snapCount);
+ }
+ //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
+ List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
+ String condition;
+ if (examineTag != null && examineTag == 1) {
+ condition = "face_province_baseLine";
+ } else if (examineTag != null && examineTag == 2) {
+ condition = "face_dept_baseLine";
+ } else {
+ condition = "face_all_baseLine";
+ }
+ Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
+ if (first.isPresent()) {
+ SysDictData sysDictData = first.get();
+ resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
+ }
+ }
+ resultMap.put("list", results);
+ return resultMap;
+ }
+
+ private <T extends BaseHomeVO> T findOrCreateVO(Document doc, List<T> results, Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
+ Date createDate = doc.getDate("_id");
+ for (T vo : results) {
+ if (vo.getCreateDate().equals(createDate)) {
+ return vo;
+ }
+ }
+ // 濡傛灉娌℃湁鎵惧埌鍖归厤椤癸紝鍒欏垱寤轰竴涓柊鐨刅O
+ T vo = clazz.getDeclaredConstructor().newInstance();
+ vo.setCreateDate(createDate);
+ results.add(vo);
+ return vo;
+ }
+
+ private Query getQuery(VideoExportForm exportForm) {
+ String month = exportForm.getMonth();
+ // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
+ YearMonth yearMonth = YearMonth.parse(month);
+ // 鑾峰彇褰撴湀鐨勭涓�澶�
+ LocalDate start = yearMonth.atDay(1);
+ // 鑾峰彇涓嬩釜鏈堢殑绗竴澶╋紙閫氳繃鍔犱笂1涓湀骞惰缃棩涓�1锛�
+ YearMonth nextMonth = yearMonth.plusMonths(1);
+ LocalDate end = nextMonth.atDay(1);
+ //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹�
+ Query query = new Query(Criteria.where("mongoCreateTime").gte(start).lt(end));
+ if (!CollectionUtils.isEmpty(exportForm.getDeptIds()))
+ query.addCriteria(Criteria.where("deptId").in(exportForm.getDeptIds()));
+ if (exportForm.getDeptTag() != null) query.addCriteria(Criteria.where("deptTag").is(exportForm.getDeptTag()));
+ if (exportForm.getProvinceTag() != null)
+ query.addCriteria(Criteria.where("provinceTag").is(exportForm.getProvinceTag()));
+ if (exportForm.getImportantTag() != null)
+ query.addCriteria(Criteria.where("importantTag").is(exportForm.getImportantTag()));
+ if (exportForm.getImportantCommandImageTag() != null)
+ query.addCriteria(Criteria.where("importantCommandImageTag").is(exportForm.getImportantCommandImageTag()));
+ return query;
+ }
+
+ //璁剧疆姣忔棩鍦ㄧ嚎鏁版嵁
+ 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) {
+ //涓虹┖鐧界殑鍘熷洜 濡傝繘鍏ョ1鍙锋椂 monitorResult娌℃湁瀵瑰簲涓�鍙风殑鏁版嵁锛屽氨鏄竴鍙穖ongodb閲岄潰娌℃湁瀵瑰簲璇ヨ澶囩殑鏁版嵁
+ int dayOfMonth = monitorResult.getMongoCreateTime().getDayOfMonth();
+ String online = "";
+ if (ApiConstants.UY_OnlineSite_Online.equals(monitorResult.getOnline())) {
+ online += "鍦ㄧ嚎";
+ } else if (ApiConstants.UY_OnlineSite_Offline.equals(monitorResult.getOnline())) {
+ online += "绂荤嚎";
+ } else {
+ online += "鏈煡";
+ }
+ //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸ay+1锛�2锛�3...
+ Field field = videoDailyExp.getClass().getDeclaredField("day" + dayOfMonth);
+ field.setAccessible(true);
+ field.set(videoDailyExp, online);
+ }
+ }
+
+ //璁剧疆姣忔棩褰曞儚鏁版嵁
+ private void setRecordDaily(VideoDailyExp videoDailyExp, TMonitorResult result, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException {
+ for (RecordMetaDSumResult recordResult : recordResults) {
+ int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());
+ Integer status = recordResult.getRecordStatus();
+ String text = "";
+ if (ApiConstants.UY_RecordStatus_Interval.equals(status)) {
+ text += "闂存瓏";
+ } else if (ApiConstants.UY_RecordStatus_Abnormal.equals(status)) {
+ text += "缂哄け";
+ } else if (ApiConstants.UY_RecordStatus_Integrity.equals(status)) {
+ text += "瀹屾暣";
+ }
+ //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸ay+1锛�2锛�3...
+ Field field = videoDailyExp.getClass().getDeclaredField("day" + dayOfMonth);
+ field.setAccessible(true);
+ field.set(videoDailyExp, text);
+ }
+ }
+
+ //璁剧疆姣忔棩褰曞儚缂哄け鏃堕暱鏁版嵁
+ private void setLoseDaily(VideoDailyExp videoDailyExp, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException {
+ //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
+ for (RecordMetaDSumResult recordResult : recordResults) {
+ 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()) * 60);
+ field.set(videoDailyExp, bigDecimal.setScale(2, RoundingMode.HALF_UP).toString());
+ }
+ }
}
--
Gitblit v1.8.0