| | |
| | | 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.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.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.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; |
| | | |
| | |
| | | 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<>(); |
| | | List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds()); |
| | | 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 = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"}; |
| | | // 创建一个Map来存储每天的累加数据 |
| | | Map<String, VideoTotalExp> totalMap = new HashMap<>(); |
| | | //一个部门一个sheet |
| | | 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<>(); |
| | | List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds()); |
| | | 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); |
| | | 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()); |
| | | //筛选mongo区县数据 |
| | | 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()); |
| | | videoDailyExp.setTag("" + (result.getProvinceTag() ? "省厅" : "") + (result.getImportantTag() ? "、重点点位" : "") + (result.getImportantCommandImageTag() ? "、重点指挥图像" : "") + (result.getDeptTag() ? "、部级" : "")); |
| | | setOnlineDaily(videoDailyExp, result, onlines); |
| | | videoDailyExps.add(videoDailyExp); |
| | | } |
| | | ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "未知" : areaDeptEnum.getName(), videoDailyExps, 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<>(); |
| | | List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds()); |
| | | 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); |
| | | 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()); |
| | | //筛选mongo区县数据 |
| | | 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()); |
| | | videoDailyExp.setTag("" + (result.getProvinceTag() ? "省厅" : "") + (result.getImportantTag() ? "、重点点位" : "") + (result.getImportantCommandImageTag() ? "、重点指挥图像" : "") + (result.getDeptTag() ? "、部级" : "")); |
| | | setRecordDaily(videoDailyExp, result, records); |
| | | videoDailyExps.add(videoDailyExp); |
| | | } |
| | | ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "未知" : areaDeptEnum.getName(), videoDailyExps, 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<>(); |
| | | List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds()); |
| | | 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); |
| | | 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()); |
| | | //筛选mongo区县数据 |
| | | 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()); |
| | | videoDailyExp.setTag("" + (result.getProvinceTag() ? "省厅" : "") + (result.getImportantTag() ? "、重点点位" : "") + (result.getImportantCommandImageTag() ? "、重点指挥图像" : "") + (result.getDeptTag() ? "、部级" : "")); |
| | | setLoseDaily(videoDailyExp, result, records); |
| | | videoDailyExps.add(videoDailyExp); |
| | | } |
| | | ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "未知" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class); |
| | | mysheet.add(excelExp); |
| | | } |
| | | ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet); |
| | | util.exportExcelManySheet(response, mysheet); |
| | | } |
| | | |
| | | |
| | | private Query getQuery(List<String> 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<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() ? "在线" : "离线"; |
| | | //反射赋值,字段统一定义为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<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 += "完整"; |
| | | } |
| | | //反射赋值,字段统一定义为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<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(); |
| | | //反射赋值,字段统一定义为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()); |
| | | } |
| | | } |
| | | } |