From 9b55891e6dd57bc244e6c5654434b32e05c83496 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期三, 25 九月 2024 15:10:25 +0800
Subject: [PATCH] 异常监控排除已经审核过的工单作为状态
---
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java | 610 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 584 insertions(+), 26 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 4a241b1..710cd87 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
@@ -1,19 +1,59 @@
package com.ycl.platform.service.impl;
import annotation.DataScope;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.platform.domain.entity.TMonitor;
+import com.ycl.platform.domain.excel.VideoDailyExp;
+import com.ycl.platform.domain.excel.VideoTotalExp;
+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.BaseResult;
+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.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.TMonitorVO;
+import com.ycl.platform.domain.vo.WorkOrderVO;
+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.WorkOrderMapper;
import com.ycl.platform.service.ITMonitorService;
+import com.ycl.system.Result;
+import com.ycl.system.page.PageUtil;
import com.ycl.system.service.ISysConfigService;
+import com.ycl.utils.DateUtils;
import com.ycl.utils.StringUtils;
+import constant.ApiConstants;
+import constant.CheckConstants;
+import enumeration.general.AreaDeptEnum;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.commons.lang3.ObjectUtils;
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.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import pojo.ExcelExp;
+import utils.poi.ExcelUtilManySheet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 璁惧璧勪骇Service涓氬姟灞傚鐞�
@@ -22,12 +62,15 @@
* @date 2024-03-04
*/
@Service
-public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService
-{
+public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService {
@Autowired
private TMonitorMapper tMonitorMapper;
@Autowired
private ISysConfigService configService;
+ @Autowired
+ private MongoTemplate mongoTemplate;
+ @Autowired
+ private WorkOrderMapper workOrderMapper;
/**
* 鏌ヨ璁惧璧勪骇
@@ -36,31 +79,188 @@
* @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")
- public List<TMonitorVO> selectTMonitorList(TMonitor tMonitor)
- {
- List<TMonitorVO> monitors = tMonitorMapper.selectTMonitorList(tMonitor);
+ @DataScope(deptAlias = "d", userAlias = "u")
+ public List<TMonitorVO> selectTMonitorList(TMonitorVO 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);
+ }
+ List<TMonitorVO> monitors = tMonitorMapper.selectTMonitorList(tMonitor);
+ // 寮傚父鎭㈠鐩戞帶
+ if (Objects.equals(tMonitor.getRecovery(), 1L)) {
+ //宸ュ崟鍙�
+ List<String> orders = monitors.stream().map(TMonitorVO::getWorkOrderNo).collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(orders)) {
+ return monitors;
+ }
+ List<WorkOrderVO> voList = workOrderMapper.getRecoveryInfo(orders);
+ for (TMonitorVO monitor : monitors) {
+ if (!CollectionUtils.isEmpty(voList)) {
+ for (WorkOrderVO workOrderVO : voList) {
+ if (monitor.getWorkOrderNo().equals(workOrderVO.getWorkOrderNo())) {
+ monitor.setUnitContact(workOrderVO.getUnitContact());
+ monitor.setUnitContactPhone(workOrderVO.getUnitContactPhone());
+ monitor.setYwPeopleName(workOrderVO.getYwPeopleName());
+ monitor.setErrorType(workOrderVO.getErrorType());
+ }
+ }
+ }
+ }
+ 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 (Objects.equals(tMonitor.getCameraFunType(), "2")) {
+ //灞炴�т竴鑷寸巼銆佸ぇ鍥俱�乽rl
+ List<VehicleDeviceSamplingResult> sampleResults = mongoTemplate.find(query, VehicleDeviceSamplingResult.class);
+ //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
+ List<VehicleDeviceInspectionResult> inspectResults = mongoTemplate.find(query, VehicleDeviceInspectionResult.class);
+ for (TMonitorVO monitor : monitors) {
+ monitor.setMongoCreateTime(now);
+ //涓�鏈轰竴妗�
+ setOneFile(monitorQualifyResults, monitor);
+ //灞炴�т竴鑷寸巼銆佸ぇ鍥俱�乽rl
+ if (!CollectionUtils.isEmpty(sampleResults)) {
+ for (VehicleDeviceSamplingResult sampleResult : sampleResults) {
+ if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
+ if (sampleResult.getBigUseful() != null) {
+ monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+ monitor.setUrlPercent(VehicleDeviceSamplingResult.BigUsefulness.calUrl(sampleResult.getBigUseful()));
+ }
+ 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);
+ //浜鸿劯鍚堟牸銆佸ぇ鍥俱�乽rl璁块棶寮傚父
+ if (!CollectionUtils.isEmpty(sampleResults)) {
+ for (FaceDeviceSamplingResult sampleResult : sampleResults) {
+ if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
+ if (sampleResult.getBigUseful() != null) {
+ monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+ monitor.setUrlPercent(FaceDeviceSamplingResult.BigUsefulness.calUrl(sampleResult.getBigUseful()));
+ }
+ 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());
+ }
+ }
+ }
}
/**
@@ -70,8 +270,7 @@
* @return 缁撴灉
*/
@Override
- public int insertTMonitor(TMonitor tMonitor)
- {
+ public int insertTMonitor(TMonitor tMonitor) {
return tMonitorMapper.insertTMonitor(tMonitor);
}
@@ -82,8 +281,7 @@
* @return 缁撴灉
*/
@Override
- public int updateTMonitor(TMonitor tMonitor)
- {
+ public int updateTMonitor(TMonitor tMonitor) {
return tMonitorMapper.updateTMonitor(tMonitor);
}
@@ -94,8 +292,7 @@
* @return 缁撴灉
*/
@Override
- public int deleteTMonitorByIds(Long[] ids)
- {
+ public int deleteTMonitorByIds(Long[] ids) {
return tMonitorMapper.deleteTMonitorByIds(ids);
}
@@ -106,20 +303,381 @@
* @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) {
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);
+ }
+
+ @Override
+ public Map<String, Object> home(HomeQuery 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)) {
+ for (Map<String, Object> map : home) {
+ monthMap1.put(map.get("months").toString(), map.get("num1"));
+ monthMap2.put(map.get("months").toString(), map.get("num2"));
+ }
+ dataMap.put("name", home.get(0).get("name"));
+ dataMap.put("state", monthMap1);
+ dataMap.put("state2", monthMap2);
+ }
+ return dataMap;
+ }
+
+ @Override
+ 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
+ public List<MonitorRateVO> monitorRate(DashboardQuery dashboardQuery) {
+ return baseMapper.monitorRate(dashboardQuery);
+ }
+
+
+ @Override
+ public Result assetManagement(DataCenterQuery query) {
+ IPage<TMonitorVO> page = PageUtil.getPage(query, TMonitorVO.class);
+ baseMapper.assetManagement(page, query);
+ return Result.ok().data(page.getRecords()).total(page.getTotal());
+ }
+
+ /**
+ * 瀵煎嚭鎬婚噺鏁版嵁
+ */
+ @Override
+ public void exportVideoTotal(HttpServletResponse response, VideoExportForm exportForm) throws IOException {
+ List<ExcelExp> mysheet = new ArrayList<>();
+ exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video+""));
+ VideoExportForm.convertTags(exportForm);
+ List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ Query query = getQuery(deviceIds, exportForm.getMonth());
+ //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+ List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+ //鏈堜唤姣忔棩褰曞儚鏁版嵁
+ List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ String[] weeks = {"鏄熸湡涓�", "鏄熸湡浜�", "鏄熸湡涓�", "鏄熸湡鍥�", "鏄熸湡浜�", "鏄熸湡鍏�", "鏄熸湡鏃�"};
+ // 鍒涘缓涓�涓狹ap鏉ュ瓨鍌ㄦ瘡澶╃殑绱姞鏁版嵁
+ Map<String, VideoTotalExp> totalMap = new HashMap<>();
+ //涓�涓儴闂ㄤ竴涓猻heet
+ for (Integer deptId : exportForm.getDeptIds()) {
+ //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
+ List<String> ids = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).map(BaseResult::getNo).collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(ids)) continue;
+ //绛涢�夐儴闂ㄦ暟鎹�
+ List<TMonitorResult> onlineList = onlineResult.stream().filter(tMonitorResult -> ids.contains(tMonitorResult.getNo())).collect(Collectors.toList());
+ List<RecordMetaDSumResult> recordList = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
+ 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);
+ //鑾峰彇鏄熸湡鍑�
+ 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());
+ videoExp.setOnline(Integer.valueOf(onlines.stream()
+ .filter(TMonitorResult::getOnline)
+ .count() + ""));
+ videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline());
+ }
+ //璁剧疆瀛樺偍鎯呭喌
+ 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);
+ mysheet.add(excelExp);
+ }
+ //娣诲姞鍏ㄩ噺琛�
+ 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 {
+ List<ExcelExp> mysheet = new ArrayList<>();
+ exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video+""));
+ VideoExportForm.convertTags(exportForm);
+ List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ Query query = getQuery(deviceIds, exportForm.getMonth());
+ //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+ List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+ //鍏ㄩ噺琛�
+ List<VideoDailyExp> totalExps = new ArrayList<>();
+ for (Integer deptId : exportForm.getDeptIds()) {
+ List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+ //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
+ List<TMonitorResult> monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(monitors)) continue;
+ List<String> ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ //绛涢�塵ongo鍖哄幙鏁版嵁
+ List<TMonitorResult> onlines = onlineResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
+ 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());
+ String tag ="" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : "");
+ // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+ if (tag.endsWith("銆�")) {
+ tag = tag.substring(0, tag.length() - 1);
+ }
+ videoDailyExp.setTag(tag);
+ setOnlineDaily(videoDailyExp, result, onlines);
+ videoDailyExps.add(videoDailyExp);
+ //鍏ㄩ噺琛�
+ totalExps.add(videoDailyExp);
+ }
+ ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ }
+ ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
+ util.exportExcelManySheet(response, mysheet);
+ }
+
+
+ /**
+ * 瀵煎嚭姣忔棩褰曞儚鎯呭喌鏁版嵁
+ */
+ @Override
+ public void exportVideoRecord(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
+ List<ExcelExp> mysheet = new ArrayList<>();
+ exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video+""));
+ VideoExportForm.convertTags(exportForm);
+ List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ Query query = getQuery(deviceIds, exportForm.getMonth());
+ //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
+ List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
+ //鍏ㄩ噺琛�
+ List<VideoDailyExp> totalExps = new ArrayList<>();
+ for (Integer deptId : exportForm.getDeptIds()) {
+ List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+ //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
+ List<TMonitorResult> monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(monitors)) continue;
+ List<String> ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ //绛涢�塵ongo鍖哄幙鏁版嵁
+ List<RecordMetaDSumResult> records = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
+ 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());
+ String tag ="" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : "");
+ // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+ if (tag.endsWith("銆�")) {
+ tag = tag.substring(0, tag.length() - 1);
+ }
+ videoDailyExp.setTag(tag);
+ setRecordDaily(videoDailyExp, result, records);
+ //鍖哄幙琛�
+ videoDailyExps.add(videoDailyExp);
+ //鍏ㄩ噺琛�
+ totalExps.add(videoDailyExp);
+ }
+ ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ }
+ 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 {
+ List<ExcelExp> mysheet = new ArrayList<>();
+ exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video+""));
+ VideoExportForm.convertTags(exportForm);
+ List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+ List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ Query query = getQuery(deviceIds, exportForm.getMonth());
+ //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
+ List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
+ //鍏ㄩ噺琛�
+ List<VideoDailyExp> totalExps = new ArrayList<>();
+ for (Integer deptId : exportForm.getDeptIds()) {
+ List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+ //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
+ List<TMonitorResult> monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(monitors)) continue;
+ List<String> ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList());
+ //绛涢�塵ongo鍖哄幙鏁版嵁
+ List<RecordMetaDSumResult> records = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
+ 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());
+ String tag ="" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : "");
+ // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+ if (tag.endsWith("銆�")) {
+ tag = tag.substring(0, tag.length() - 1);
+ }
+ videoDailyExp.setTag(tag);
+ setLoseDaily(videoDailyExp, result, records);
+ videoDailyExps.add(videoDailyExp);
+ //鍏ㄩ噺琛�
+ totalExps.add(videoDailyExp);
+ }
+ ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ }
+ ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
+ mysheet.add(excelExp);
+ ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
+ util.exportExcelManySheet(response, mysheet);
+ }
+
+
+ private Query getQuery(List<String> deviceIds, String month) {
+ // 灏嗗勾鏈堝瓧绗︿覆瑙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));
+ query.addCriteria(Criteria.where("no").in(deviceIds));
+ 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());
+ for (TMonitorResult monitorResult : onlineResult) {
+ int dayOfMonth = monitorResult.getMongoCreateTime().getDayOfMonth();
+ String online = "";
+ online += monitorResult.getOnline() ? "鍦ㄧ嚎" : "绂荤嚎";
+ //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸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> records) throws NoSuchFieldException, IllegalAccessException {
+ //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
+ List<RecordMetaDSumResult> recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
+ for (RecordMetaDSumResult recordResult : recordResults) {
+ int dayOfMonth = recordResult.getMongoCreateTime().getDayOfMonth();
+ 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, TMonitorResult result, List<RecordMetaDSumResult> records) throws NoSuchFieldException, IllegalAccessException {
+ //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
+ List<RecordMetaDSumResult> recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
+ for (RecordMetaDSumResult recordResult : recordResults) {
+ int dayOfMonth = recordResult.getMongoCreateTime().getDayOfMonth();
+ //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸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());
+ }
}
}
--
Gitblit v1.8.0