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.mongodb.client.AggregateIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.ycl.platform.domain.entity.TMonitor; import com.ycl.platform.domain.excel.TMonitorExp; import com.ycl.platform.domain.excel.VideoDailyExp; import com.ycl.platform.domain.excel.VideoTotalExp; import com.ycl.platform.domain.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.*; 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.DynamicColumnMapper; 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.entity.SysDictData; import com.ycl.system.mapper.SysConfigMapper; import com.ycl.system.mapper.SysDictDataMapper; import com.ycl.system.page.PageUtil; import com.ycl.system.service.ISysConfigService; import com.ycl.utils.DateUtils; import com.ycl.utils.StringUtils; import com.ycl.utils.poi.ExcelUtil; import constant.ApiConstants; import constant.CheckConstants; import enumeration.general.AreaDeptEnum; import jakarta.servlet.http.HttpServletResponse; import lombok.SneakyThrows; import org.apache.commons.lang3.ObjectUtils; import org.bson.Document; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; 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.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.YearMonth; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.stream.Collectors; /** * 设备资产Service业务层处理 * * @author ruoyi * @date 2024-03-04 */ @Service public class TMonitorServiceImpl extends ServiceImpl implements ITMonitorService { @Autowired private TMonitorMapper tMonitorMapper; @Autowired private ISysConfigService configService; @Autowired private MongoTemplate mongoTemplate; @Autowired private WorkOrderMapper workOrderMapper; @Autowired private SysDictDataMapper dictDataMapper; @Autowired private DynamicColumnMapper dynamicColumnMapper; /** * 查询设备资产 * * @param id 设备资产主键 * @return 设备资产 */ @Override public TMonitor selectTMonitorById(Long id) { return tMonitorMapper.selectTMonitorById(id); } /** * 查询设备资产列表 * 异常恢复监控、车辆、人脸、视频通用接口 * * @param tMonitor 设备资产 * @return 设备资产 */ @Override @DataScope(deptAlias = "d", userAlias = "u") public List 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("请配置异常设备连续关注时间"); } tMonitor.setTime(time); } List monitors = tMonitorMapper.selectTMonitorList(tMonitor); // 异常恢复监控 if (Objects.equals(tMonitor.getRecovery(), 1L)) { //工单号 List orders = monitors.stream().map(TMonitorVO::getWorkOrderNo).collect(Collectors.toList()); if (CollectionUtils.isEmpty(orders)) { return monitors; } List 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()); } } } } return monitors; } //设备编号 List 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)) ); //一机一档信息 List monitorQualifyResults = mongoTemplate.find(query, MonitorQualifyResult.class); // 视频监控设备 if (Objects.equals(tMonitor.getCameraFunType(), "1")) { //OSD信息 List osdCheckResults = mongoTemplate.find(query, OsdCheckResult.class); //录像可用信息 List 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")) { //属性一致率、大图 List sampleResults = mongoTemplate.find(query, VehicleDeviceSamplingResult.class); List picAccessResults = mongoTemplate.find(query, PicAccessResult.class); //抓拍量、时钟、上传 List 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")) { //人脸合格、大图、url访问异常 List sampleResults = mongoTemplate.find(query, FaceDeviceSamplingResult.class); //抓拍量、时钟、上传 List 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; } /** * 补充一机一档信息 * * @param monitorQualifyResults * @param monitor */ private void setOneFile(List 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()); } } } } /** * 新增设备资产 * * @param tMonitor 设备资产 * @return 结果 */ @Override public int insertTMonitor(TMonitor tMonitor) { return tMonitorMapper.insertTMonitor(tMonitor); } /** * 修改设备资产 * * @param tMonitor 设备资产 * @return 结果 */ @Override public int updateTMonitor(TMonitor tMonitor) { return tMonitorMapper.updateTMonitor(tMonitor); } /** * 批量删除设备资产 * * @param ids 需要删除的设备资产主键 * @return 结果 */ @Override public int deleteTMonitorByIds(Long[] ids) { return tMonitorMapper.deleteTMonitorByIds(ids); } /** * 删除设备资产信息 * * @param id 设备资产主键 * @return 结果 */ @Override public int deleteTMonitorById(Long id) { return tMonitorMapper.deleteTMonitorById(id); } @Override @DataScope(deptAlias = "d", userAlias = "u") public Map getVideoCount(TMonitorVO tMonitor) { return tMonitorMapper.getVideoCount(tMonitor); } @Override @DataScope(deptAlias = "d", userAlias = "u") public Map recoveryException(TMonitorVO monitor) { // String time = configService.selectConfigByKey("abnormal.equipment.continuous.attention.time"); // monitor.setTime(time); return tMonitorMapper.recoveryException(monitor); } @Override public Map home(HomeQuery monitorQuery) { Map dataMap = new HashMap<>(); Map monthMap1 = new HashMap<>(); Map monthMap2 = new HashMap<>(); List> home = baseMapper.home(monitorQuery); if (ObjectUtils.isNotEmpty(home)) { for (Map 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>> monitorTotal(DashboardQuery dashboardQuery) { List monitorTotalVOS = baseMapper.monitorTotal(dashboardQuery); /** facilityData: { * video:[ * {value: 4589,title: '设备总数'}, * {value: 4294,title: '设备正常数'}, * {value: 295,title: '设备异常数'} * ]} */ Map>> resultMap = new HashMap<>(); for (MonitorTotalVO vo : monitorTotalVOS) { List> list = new ArrayList(); Map total = new HashMap<>(); total.put("value", vo.getTotalNum()); total.put("title", "设备总数"); Map normal = new HashMap<>(); normal.put("value", vo.getNormalNum()); normal.put("title", "正常数"); Map 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 monitorRate(DashboardQuery dashboardQuery) { return baseMapper.monitorRate(dashboardQuery); } @Override public Result assetManagement(DataCenterQuery query) { IPage 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 { //默认查所有部门 if (CollectionUtils.isEmpty(exportForm.getDeptIds())) { List deptIds = new ArrayList<>(); for (AreaDeptEnum value : AreaDeptEnum.values()) { deptIds.add(value.getDeptId()); } exportForm.setDeptIds(deptIds); } List mysheet = new ArrayList<>(); exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + "")); VideoExportForm.convertTags(exportForm); List tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm); List deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList()); Query query = getQuery(deviceIds, exportForm.getMonth()); //月份每日在线数据 List onlineResult = mongoTemplate.find(query, TMonitorResult.class); //月份每日录像数据 List recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String[] weeks = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"}; // 创建一个Map来存储每天的累加数据 Map totalMap = new HashMap<>(); //一个部门一个sheet for (Integer deptId : exportForm.getDeptIds()) { //从数据库集合筛选部门数据 List ids = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).map(BaseResult::getNo).collect(Collectors.toList()); if (CollectionUtils.isEmpty(ids)) continue; //筛选部门数据 List onlineList = onlineResult.stream().filter(tMonitorResult -> ids.contains(tMonitorResult.getNo())).collect(Collectors.toList()); List recordList = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList()); List 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 onlines = onlineList.stream().filter(tMonitorResult -> tMonitorResult.getMongoCreateTime().minusDays(1).equals(parseTime)).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(onlines)) { videoExp.setTotal(onlines.size()); long count = onlines.stream() .filter(item -> ApiConstants.UY_OnlineSite_Online.equals(item.getOnline())) .count(); videoExp.setOnline(Integer.valueOf(count + "")); videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline()); } //设置存储情况 List 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 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> util = new ExcelUtilManySheet<>(mysheet); util.exportExcelManySheet(response, mysheet); } /** * 导出每日在线数据 */ @Override public void exportVideoOnline(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException { //默认查所有部门 if (CollectionUtils.isEmpty(exportForm.getDeptIds())) { List deptIds = new ArrayList<>(); for (AreaDeptEnum value : AreaDeptEnum.values()) { deptIds.add(value.getDeptId()); } exportForm.setDeptIds(deptIds); } List mysheet = new ArrayList<>(); exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + "")); VideoExportForm.convertTags(exportForm); List tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm); //获取动态列数据 List pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList()); List dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds); //补充动态列数据 if (!CollectionUtils.isEmpty(dynamics)) { Map> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId)); for (TMonitorResult tMonitorResult : tMonitorResults) { Integer pointId = tMonitorResult.getPointId(); tMonitorResult.setDynamicColumnList(map.get(pointId)); } } List deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList()); Query query = getQuery(deviceIds, exportForm.getMonth()); //月份每日在线数据 List onlineResult = mongoTemplate.find(query, TMonitorResult.class); //全量表 List totalExps = new ArrayList<>(); for (Integer deptId : exportForm.getDeptIds()) { List videoDailyExps = new ArrayList<>(); //从数据库集合筛选部门数据 List monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList()); if (CollectionUtils.isEmpty(monitors)) continue; List ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList()); //筛选mongo区县数据 List 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()); StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "省厅、" : "") + (result.getImportantTag() ? "重点点位、" : "") + (result.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (result.getDeptTag() ? "部级、" : "")); //动态列处理加在标签里 if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) { List 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()); 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> util = new ExcelUtilManySheet<>(mysheet); util.exportExcelManySheet(response, mysheet); } /** * 导出每日录像情况数据 */ @Override public void exportVideoRecord(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException { //默认查所有部门 if (CollectionUtils.isEmpty(exportForm.getDeptIds())) { List deptIds = new ArrayList<>(); for (AreaDeptEnum value : AreaDeptEnum.values()) { deptIds.add(value.getDeptId()); } exportForm.setDeptIds(deptIds); } List mysheet = new ArrayList<>(); exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + "")); VideoExportForm.convertTags(exportForm); List tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm); //获取动态列数据 List pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList()); List dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds); //补充动态列数据 if (!CollectionUtils.isEmpty(dynamics)) { Map> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId)); for (TMonitorResult tMonitorResult : tMonitorResults) { Integer pointId = tMonitorResult.getPointId(); tMonitorResult.setDynamicColumnList(map.get(pointId)); } } List deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList()); Query query = getQuery(deviceIds, exportForm.getMonth()); //月份每日录像线数据 List recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class); //全量表 List totalExps = new ArrayList<>(); for (Integer deptId : exportForm.getDeptIds()) { List videoDailyExps = new ArrayList<>(); //从数据库集合筛选部门数据 List monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList()); if (CollectionUtils.isEmpty(monitors)) continue; List ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList()); //筛选mongo区县数据 List 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()); StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "省厅、" : "") + (result.getImportantTag() ? "重点点位、" : "") + (result.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (result.getDeptTag() ? "部级、" : "")); //动态列处理加在标签里 if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) { List 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()); 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> 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 deptIds = new ArrayList<>(); for (AreaDeptEnum value : AreaDeptEnum.values()) { deptIds.add(value.getDeptId()); } exportForm.setDeptIds(deptIds); } List mysheet = new ArrayList<>(); exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + "")); VideoExportForm.convertTags(exportForm); List tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm); //获取动态列数据 List pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList()); List dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds); //补充动态列数据 if (!CollectionUtils.isEmpty(dynamics)) { Map> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId)); for (TMonitorResult tMonitorResult : tMonitorResults) { Integer pointId = tMonitorResult.getPointId(); tMonitorResult.setDynamicColumnList(map.get(pointId)); } } List deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList()); Query query = getQuery(deviceIds, exportForm.getMonth()); //月份每日录像线数据 List recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class); //全量表 List totalExps = new ArrayList<>(); for (Integer deptId : exportForm.getDeptIds()) { List videoDailyExps = new ArrayList<>(); //从数据库集合筛选部门数据 List monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList()); if (CollectionUtils.isEmpty(monitors)) continue; List ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList()); //筛选mongo区县数据 List 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()); StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "省厅、" : "") + (result.getImportantTag() ? "重点点位、" : "") + (result.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (result.getDeptTag() ? "部级、" : "")); //动态列处理加在标签里 if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) { List 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()); 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> util = new ExcelUtilManySheet<>(mysheet); util.exportExcelManySheet(response, mysheet); } //首页视频报表 @Override public Map videoHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { List results = new ArrayList<>(); String month = monitorQuery.getDate(); if (StringUtils.isEmpty(month)) { //如果为空查本月的数据 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); month = simpleDateFormat.format(new Date()); } // 创建一个SimpleDateFormat对象来解析日期字符串 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Date date = sdf.parse(month); // 创建一个Calendar对象并设置时间为解析出的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 collection = database.getCollection("uy_record_meta_d_sum"); Integer examineTag = monitorQuery.getExamineTag(); Document matchConditions = new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)); // 根据examineTag的值动态添加额外的条件 if (examineTag != null && examineTag.equals(1)) { matchConditions.append("provinceTag", true); } else if (examineTag != null && examineTag.equals(2)) { matchConditions.append("deptTag", true); } // 构建聚合管道 List pipeline = Arrays.asList( new Document("$match", matchConditions), new Document("$group", new Document("_id", "$mongoCreateTime") .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", -1)), 1, 0 )) )) ) ); // 执行聚合查询并获取结果 AggregateIterable 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")); results.add(homeVideoVO); } //mongo查点位在线 MongoCollection onlineCollection = database.getCollection("t_monitor_online"); // 构建基本的$match条件 List 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 (examineTag != null && examineTag.equals(1)) { onlineMatch.add(new Document("provinceTag", true)); } else if (examineTag != null && examineTag.equals(2)) { onlineMatch.add(new Document("deptTag", true)); } // 构建聚合管道 List 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 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 resultMap = new HashMap<>(); resultMap.put("list", results); //从字典获取基准线 List 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 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 monitors = tMonitorMapper.exportTMonitorList(tMonitor); //获取动态列数据 List pointIds = monitors.stream().map(TMonitorExp::getPointId).collect(Collectors.toList()); List dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds); //补充动态列数据 if (!CollectionUtils.isEmpty(dynamics)) { Map> 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.getProvinceTag() ? "省厅、" : "") + (monitor.getImportantTag() ? "重点点位、" : "") + (monitor.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (monitor.getDeptTag() ? "部级、" : "")); //动态列处理加在标签里 if (!CollectionUtils.isEmpty(monitor.getDynamicColumnList())) { List 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 util = new ExcelUtil<>(TMonitorExp.class); util.exportExcel(response, monitors, "2".equals(tMonitor.getCameraFunType()) ? "车辆" : "人脸"); } //首页车辆报表 @Override public Map carHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { List results = new ArrayList<>(); String month = monitorQuery.getDate(); if (StringUtils.isEmpty(month)) { //如果为空查本月的数据 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); month = simpleDateFormat.format(new Date()); } // 创建一个SimpleDateFormat对象来解析日期字符串 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Date date = sdf.parse(month); // 创建一个Calendar对象并设置时间为解析出的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 collection = database.getCollection("hk_snapshot_data_monitor"); Integer examineTag = monitorQuery.getExamineTag(); // 构建基本的$match条件 List 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_CAR))); if (examineTag != null && examineTag.equals(1)) { matchConditions.add(new Document("provinceTag", true)); } // 构建聚合管道 List pipeline = Arrays.asList( new Document("$match", new Document("$and", matchConditions)), new Document("$group", new Document("_id", "$mongoCreateTime") .append("dataCount", new Document("$sum", "$dataCount")) ) ); // 执行聚合查询并获取结果 AggregateIterable 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); } //TODO:在线修改,需要把检测海康优云检测的结果存入mongo,mongo查点位在线 MongoCollection onlineCollection = database.getCollection("t_monitor_online"); // 构建基本的$match条件 List 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)); } // 构建聚合管道 List 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 onlineResult = onlineCollection.aggregate(onlinePipeline); for (Document doc : onlineResult) { HomeCarVO vo = findOrCreateVO(doc, results, HomeCarVO.class); vo.setOnline(doc.getInteger("onlineCount")); } Map resultMap = new HashMap<>(); //按时间排序 results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList()); int snapCount = 0; for (HomeCarVO vo : results) { if (vo.getSnapCount() != null) { snapCount += vo.getSnapCount(); } vo.setSnapCount(snapCount); } resultMap.put("list", results); //从字典获取基准线 List 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 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; } //首页人脸报表 @Override public Map faceHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { List results = new ArrayList<>(); String month = monitorQuery.getDate(); if (StringUtils.isEmpty(month)) { //如果为空查本月的数据 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); month = simpleDateFormat.format(new Date()); } // 创建一个SimpleDateFormat对象来解析日期字符串 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Date date = sdf.parse(month); // 创建一个Calendar对象并设置时间为解析出的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 collection = database.getCollection("hk_snapshot_data_monitor"); Integer examineTag = monitorQuery.getExamineTag(); // 构建基本的$match条件 List 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)); } // 构建聚合管道 List pipeline = Arrays.asList( new Document("$match", new Document("$and", matchConditions)), new Document("$group", new Document("_id", "$mongoCreateTime") .append("dataCount", new Document("$sum", "$dataCount")) ) ); // 执行聚合查询并获取结果 AggregateIterable 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 onlineCollection = database.getCollection("t_monitor_online"); // 构建基本的$match条件 List 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)); } // 构建聚合管道 List 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 onlineResult = onlineCollection.aggregate(onlinePipeline); for (Document doc : onlineResult) { HomeFaceVO vo = findOrCreateVO(doc, results, HomeFaceVO.class); vo.setOnline(doc.getInteger("onlineCount")); } //按时间排序 results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList()); int snapCount = 0; for (HomeFaceVO vo : results) { if (vo.getSnapCount() != null) { snapCount += vo.getSnapCount(); } vo.setSnapCount(snapCount); } Map resultMap = new HashMap<>(); resultMap.put("list", results); //从字典获取基准线 List 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 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; } private T findOrCreateVO(Document doc, List results, Class clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { Date createDate = doc.getDate("_id"); for (T vo : results) { if (vo.getCreateDate().equals(createDate)) { return vo; } } // 如果没有找到匹配项,则创建一个新的VO T vo = clazz.getDeclaredConstructor().newInstance(); vo.setCreateDate(createDate); results.add(vo); return vo; } private Query getQuery(List deviceIds, String month) { // 将年月字符串解析为YearMonth对象 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 onlines) throws NoSuchFieldException, IllegalAccessException { //一个设备当月在线情况 List onlineResult = onlines.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList()); for (TMonitorResult monitorResult : onlineResult) { 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 += "未知"; } //反射赋值,字段统一定义为day+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 records) throws NoSuchFieldException, IllegalAccessException { //一个设备当月在线情况 List 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 += "完整"; } //反射赋值,字段统一定义为day+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 records) throws NoSuchFieldException, IllegalAccessException { //一个设备当月在线情况 List recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList()); for (RecordMetaDSumResult recordResult : recordResults) { int dayOfMonth = recordResult.getMongoCreateTime().getDayOfMonth(); //反射赋值,字段统一定义为day+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()); } } }