fuliqi
2024-10-16 44cd2d171062c9b07a0eb047cd0ac80d06188e8c
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
@@ -3,6 +3,9 @@
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.VideoDailyExp;
import com.ycl.platform.domain.excel.VideoTotalExp;
@@ -19,14 +22,23 @@
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;
@@ -35,7 +47,10 @@
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;
@@ -47,11 +62,16 @@
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;
@@ -71,6 +91,10 @@
    private MongoTemplate mongoTemplate;
    @Autowired
    private WorkOrderMapper workOrderMapper;
    @Autowired
    private SysDictDataMapper dictDataMapper;
    @Autowired
    private DynamicColumnMapper dynamicColumnMapper;
    /**
     * 查询设备资产
@@ -386,8 +410,18 @@
     */
    @Override
    public void exportVideoTotal(HttpServletResponse response, VideoExportForm exportForm) throws IOException {
        //默认查所有部门
        if(CollectionUtils.isEmpty(exportForm.getDeptIds())){
            List<Integer> deptIds = new ArrayList<>();
            for (AreaDeptEnum value : AreaDeptEnum.values()) {
                deptIds.add(value.getDeptId());
            }
            exportForm.setDeptIds(deptIds);
        }
        List<ExcelExp> mysheet = new ArrayList<>();
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds());
        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());
        //月份每日在线数据
@@ -423,7 +457,7 @@
                if (!CollectionUtils.isEmpty(onlines)) {
                    videoExp.setTotal(onlines.size());
                    videoExp.setOnline(Integer.valueOf(onlines.stream()
                            .filter(TMonitorResult::getOnline)
                            .filter(TMonitorResult::getPingOnline)
                            .count() + ""));
                    videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline());
                }
@@ -468,12 +502,35 @@
     */
    @Override
    public void exportVideoOnline(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
        //默认查所有部门
        if(CollectionUtils.isEmpty(exportForm.getDeptIds())){
            List<Integer> deptIds = new ArrayList<>();
            for (AreaDeptEnum value : AreaDeptEnum.values()) {
                deptIds.add(value.getDeptId());
            }
            exportForm.setDeptIds(deptIds);
        }
        List<ExcelExp> mysheet = new ArrayList<>();
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds());
        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
        VideoExportForm.convertTags(exportForm);
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
        //获取动态列数据
        List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
        List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
        //补充动态列数据
        if(!CollectionUtils.isEmpty(dynamics)) {
            Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
            for (TMonitorResult tMonitorResult : tMonitorResults) {
                Integer pointId = tMonitorResult.getPointId();
                tMonitorResult.setDynamicColumnList(map.get(pointId));
            }
        }
        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
        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<>();
            //从数据库集合筛选部门数据
@@ -488,13 +545,29 @@
                videoDailyExp.setSerialNumber(result.getNo());
                videoDailyExp.setDeviceName(result.getName());
                videoDailyExp.setArea(areaDeptEnum == null ? "未知" : areaDeptEnum.getName());
                videoDailyExp.setTag("" + (result.getProvinceTag() ? "省厅" : "") + (result.getImportantTag() ? "、重点点位" : "") + (result.getImportantCommandImageTag() ? "、重点指挥图像" : "") + (result.getDeptTag() ? "、部级" : ""));
                StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "省厅、" : "") + (result.getImportantTag() ? "重点点位、" : "") + (result.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (result.getDeptTag() ? "部级、" : ""));
                //动态列处理加在标签里
                if(!CollectionUtils.isEmpty(result.getDynamicColumnList())){
                    List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
                    for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
                        tag.append(dynamicColumnVO.getColumnValue()).append("、");
                    }
                }
                // 删除字符串末尾的“、”
                if (tag.toString().endsWith("、")) {
                    tag = new StringBuilder(tag.substring(0, tag.length() - 1));
                }
                videoDailyExp.setTag(tag.toString());
                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);
    }
@@ -505,12 +578,35 @@
     */
    @Override
    public void exportVideoRecord(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
        //默认查所有部门
        if(CollectionUtils.isEmpty(exportForm.getDeptIds())){
            List<Integer> deptIds = new ArrayList<>();
            for (AreaDeptEnum value : AreaDeptEnum.values()) {
                deptIds.add(value.getDeptId());
            }
            exportForm.setDeptIds(deptIds);
        }
        List<ExcelExp> mysheet = new ArrayList<>();
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds());
        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
        VideoExportForm.convertTags(exportForm);
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
        //获取动态列数据
        List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
        List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
        //补充动态列数据
        if(!CollectionUtils.isEmpty(dynamics)) {
            Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
            for (TMonitorResult tMonitorResult : tMonitorResults) {
                Integer pointId = tMonitorResult.getPointId();
                tMonitorResult.setDynamicColumnList(map.get(pointId));
            }
        }
        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
        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<>();
            //从数据库集合筛选部门数据
@@ -525,13 +621,30 @@
                videoDailyExp.setSerialNumber(result.getNo());
                videoDailyExp.setDeviceName(result.getName());
                videoDailyExp.setArea(areaDeptEnum == null ? "未知" : areaDeptEnum.getName());
                videoDailyExp.setTag("" + (result.getProvinceTag() ? "省厅" : "") + (result.getImportantTag() ? "、重点点位" : "") + (result.getImportantCommandImageTag() ? "、重点指挥图像" : "") + (result.getDeptTag() ? "、部级" : ""));
                StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "省厅、" : "") + (result.getImportantTag() ? "重点点位、" : "") + (result.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (result.getDeptTag() ? "部级、" : ""));
                //动态列处理加在标签里
                if(!CollectionUtils.isEmpty(result.getDynamicColumnList())){
                    List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
                    for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
                        tag.append(dynamicColumnVO.getColumnValue()).append("、");
                    }
                }
                // 删除字符串末尾的“、”
                if (tag.toString().endsWith("、")) {
                    tag = new StringBuilder(tag.substring(0, tag.length() - 1));
                }
                videoDailyExp.setTag(tag.toString());
                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);
    }
@@ -541,12 +654,35 @@
     */
    @Override
    public void exportVideoLoseTime(HttpServletResponse response, VideoExportForm exportForm) throws NoSuchFieldException, IllegalAccessException, IOException {
        //默认查所有部门
        if(CollectionUtils.isEmpty(exportForm.getDeptIds())){
            List<Integer> deptIds = new ArrayList<>();
            for (AreaDeptEnum value : AreaDeptEnum.values()) {
                deptIds.add(value.getDeptId());
            }
            exportForm.setDeptIds(deptIds);
        }
        List<ExcelExp> mysheet = new ArrayList<>();
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(CheckConstants.Rule_Category_Video, exportForm.getDeptIds());
        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
        VideoExportForm.convertTags(exportForm);
        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
        //获取动态列数据
        List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
        List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
        //补充动态列数据
        if(!CollectionUtils.isEmpty(dynamics)) {
            Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
            for (TMonitorResult tMonitorResult : tMonitorResults) {
                Integer pointId = tMonitorResult.getPointId();
                tMonitorResult.setDynamicColumnList(map.get(pointId));
            }
        }
        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
        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<>();
            //从数据库集合筛选部门数据
@@ -561,17 +697,386 @@
                videoDailyExp.setSerialNumber(result.getNo());
                videoDailyExp.setDeviceName(result.getName());
                videoDailyExp.setArea(areaDeptEnum == null ? "未知" : areaDeptEnum.getName());
                videoDailyExp.setTag("" + (result.getProvinceTag() ? "省厅" : "") + (result.getImportantTag() ? "、重点点位" : "") + (result.getImportantCommandImageTag() ? "、重点指挥图像" : "") + (result.getDeptTag() ? "、部级" : ""));
                StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "省厅、" : "") + (result.getImportantTag() ? "重点点位、" : "") + (result.getImportantCommandImageTag() ? "重点指挥图像、" : "") + (result.getDeptTag() ? "部级、" : ""));
                //动态列处理加在标签里
                if(!CollectionUtils.isEmpty(result.getDynamicColumnList())){
                    List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
                    for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
                        tag.append(dynamicColumnVO.getColumnValue()).append("、");
                    }
                }
                // 删除字符串末尾的“、”
                if (tag.toString().endsWith("、")) {
                    tag = new StringBuilder(tag.substring(0, tag.length() - 1));
                }
                videoDailyExp.setTag(tag.toString());
                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);
    }
    //首页视频报表
    @Override
    public Map<String, Object> videoHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        List<HomeVideoVO> results = new ArrayList<>();
        String month = monitorQuery.getDate();
        if (StringUtils.isEmpty(month)) {
            //如果为空查本月的数据
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
            month = simpleDateFormat.format(new Date());
        }
        // 创建一个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<Document> 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<Document> 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<Document> result = collection.aggregate(pipeline);
        for (Document doc : result) {
            HomeVideoVO homeVideoVO = new HomeVideoVO();
            homeVideoVO.setCreateDate(doc.getDate("_id"));
            homeVideoVO.setIntegrityNum(doc.getInteger("normalCount"));
            homeVideoVO.setLoseNum(doc.getInteger("loseCount"));
            results.add(homeVideoVO);
        }
        //mongo查点位在线
        MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
        // 构建基本的$match条件
        List<Document> onlineMatch = new ArrayList<>();
        onlineMatch.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
        onlineMatch.add(new Document("monitorType", new Document("$regex", "1")));
        if (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<Document> onlinePipeline = Arrays.asList(
                new Document("$match", new Document("$and", onlineMatch)),
                new Document("$group", new Document("_id", "$mongoCreateTime")
                        .append("onlineCount", new Document("$sum",
                                new Document("$cond", Arrays.asList(
                                        new Document("$eq", Arrays.asList("$online", Boolean.TRUE)),
                                        1,
                                        0
                                ))
                        ))
                )
        );
        // 执行聚合查询并获取结果
        AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
        for (Document doc : onlineResult) {
            HomeVideoVO vo = findOrCreateVO(doc, results, HomeVideoVO.class);
            vo.setOnline(doc.getInteger("onlineCount"));
        }
        results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", results);
        //从字典获取基准线
        List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
        String condition;
        if (examineTag != null && examineTag == 1) {
            condition = "video_province_baseLine";
        } else if (examineTag != null && examineTag == 2) {
            condition = "video_dept_baseLine";
        } else {
            condition = "video_all_baseLine";
        }
        Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
        if (first.isPresent()) {
            SysDictData sysDictData = first.get();
            resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
        }
        return resultMap;
    }
    //首页车辆报表
    @Override
    public Map<String, Object> carHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        List<HomeCarVO> results = new ArrayList<>();
        String month = monitorQuery.getDate();
        if (StringUtils.isEmpty(month)) {
            //如果为空查本月的数据
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
            month = simpleDateFormat.format(new Date());
        }
        // 创建一个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<Document> collection = database.getCollection("hk_snapshot_data_monitor");
        Integer examineTag = monitorQuery.getExamineTag();
        // 构建基本的$match条件
        List<Document> matchConditions = new ArrayList<>();
        matchConditions.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
        matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR)));
        if (examineTag != null && examineTag.equals(1)) {
            matchConditions.add(new Document("provinceTag", true));
        }
        // 构建聚合管道
        List<Document> pipeline = Arrays.asList(
                new Document("$match", new Document("$and", matchConditions)),
                new Document("$group", new Document("_id", "$mongoCreateTime")
                        .append("dataCount", new Document("$sum", "$dataCount"))
                )
        );
        // 执行聚合查询并获取结果
        AggregateIterable<Document> result = collection.aggregate(pipeline);
        for (Document doc : result) {
            HomeCarVO homecarVO = new HomeCarVO();
            homecarVO.setCreateDate(doc.getDate("_id"));
            homecarVO.setSnapCount(doc.getInteger("dataCount"));
            results.add(homecarVO);
        }
        //TODO:在线修改,需要把检测海康优云检测的结果存入mongo,mongo查点位在线
        MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
        // 构建基本的$match条件
        List<Document> onlineMatch = new ArrayList<>();
        onlineMatch.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
        onlineMatch.add(new Document("monitorType", new Document("$regex", "2")));
        if (examineTag != null && examineTag.equals(1)) {
            onlineMatch.add(new Document("provinceTag", true));
        }
        // 构建聚合管道
        List<Document> onlinePipeline = Arrays.asList(
                new Document("$match", new Document("$and", onlineMatch)),
                new Document("$group", new Document("_id", "$mongoCreateTime")
                        .append("onlineCount", new Document("$sum",
                                new Document("$cond", Arrays.asList(
                                        new Document("$eq", Arrays.asList("$online", Boolean.TRUE)),
                                        1,
                                        0
                                ))
                        ))
                )
        );
        // 执行聚合查询并获取结果
        AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
        for (Document doc : onlineResult) {
            HomeCarVO vo = findOrCreateVO(doc, results, HomeCarVO.class);
            vo.setOnline(doc.getInteger("onlineCount"));
        }
        Map<String, Object> resultMap = new HashMap<>();
        //按时间排序
        results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
        int snapCount = 0;
        for (HomeCarVO vo : results) {
            if (vo.getSnapCount() != null) {
                snapCount += vo.getSnapCount();
            }
            vo.setSnapCount(snapCount);
        }
        resultMap.put("list", results);
        //从字典获取基准线
        List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
        String condition;
        if (examineTag != null && examineTag == 1) {
            condition = "car_province_baseLine";
        } else if (examineTag != null && examineTag == 2) {
            condition = "car_dept_baseLine";
        } else {
            condition = "car_all_baseLine";
        }
        Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
        if (first.isPresent()) {
            SysDictData sysDictData = first.get();
            resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
        }
        return resultMap;
    }
    //首页人脸报表
    @Override
    public Map<String, Object> faceHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        List<HomeFaceVO> results = new ArrayList<>();
        String month = monitorQuery.getDate();
        if (StringUtils.isEmpty(month)) {
            //如果为空查本月的数据
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
            month = simpleDateFormat.format(new Date());
        }
        // 创建一个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<Document> collection = database.getCollection("hk_snapshot_data_monitor");
        Integer examineTag = monitorQuery.getExamineTag();
        // 构建基本的$match条件
        List<Document> matchConditions = new ArrayList<>();
        matchConditions.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
        matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_FACE)));
        if (examineTag != null && examineTag.equals(1)) {
            matchConditions.add(new Document("provinceTag", true));
        }
        // 构建聚合管道
        List<Document> pipeline = Arrays.asList(
                new Document("$match", new Document("$and", matchConditions)),
                new Document("$group", new Document("_id", "$mongoCreateTime")
                        .append("dataCount", new Document("$sum", "$dataCount"))
                )
        );
        // 执行聚合查询并获取结果
        AggregateIterable<Document> result = collection.aggregate(pipeline);
        for (Document doc : result) {
            HomeFaceVO homefaceVO = new HomeFaceVO();
            homefaceVO.setCreateDate(doc.getDate("_id"));
            homefaceVO.setSnapCount(doc.getInteger("dataCount"));
            results.add(homefaceVO);
        }
        //mongo查点位在线
        MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
        // 构建基本的$match条件
        List<Document> onlineMatch = new ArrayList<>();
        onlineMatch.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
        onlineMatch.add(new Document("monitorType", new Document("$regex", "3")));
        if (examineTag != null && examineTag.equals(1)) {
            onlineMatch.add(new Document("provinceTag", true));
        }
        // 构建聚合管道
        List<Document> onlinePipeline = Arrays.asList(
                new Document("$match", new Document("$and", onlineMatch)),
                new Document("$group", new Document("_id", "$mongoCreateTime")
                        .append("onlineCount", new Document("$sum",
                                new Document("$cond", Arrays.asList(
                                        new Document("$eq", Arrays.asList("$online", Boolean.TRUE)),
                                        1,
                                        0
                                ))
                        ))
                )
        );
        // 执行聚合查询并获取结果
        AggregateIterable<Document> 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<String, Object> resultMap = new HashMap<>();
        resultMap.put("list", results);
        //从字典获取基准线
        List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
        String condition;
        if (examineTag != null && examineTag == 1) {
            condition = "face_province_baseLine";
        } else if (examineTag != null && examineTag == 2) {
            condition = "face_dept_baseLine";
        } else {
            condition = "face_all_baseLine";
        }
        Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
        if (first.isPresent()) {
            SysDictData sysDictData = first.get();
            resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
        }
        return resultMap;
    }
    private <T extends BaseHomeVO> T findOrCreateVO(Document doc, List<T> results, Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Date createDate = doc.getDate("_id");
        for (T vo : results) {
            if (vo.getCreateDate().equals(createDate)) {
                return vo;
            }
        }
        // 如果没有找到匹配项,则创建一个新的VO
        T vo = clazz.getDeclaredConstructor().newInstance();
        vo.setCreateDate(createDate);
        results.add(vo);
        return vo;
    }
    private Query getQuery(List<String> deviceIds, String month) {
        // 将年月字符串解析为YearMonth对象
@@ -594,7 +1099,13 @@
        for (TMonitorResult monitorResult : onlineResult) {
            int dayOfMonth = monitorResult.getMongoCreateTime().getDayOfMonth();
            String online = "";
            online += monitorResult.getOnline() ? "在线" : "离线";
            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);
@@ -635,7 +1146,7 @@
            field.setAccessible(true);
            //防止转换为科学计数法
            BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : recordResult.getMissDuration());
            field.set(videoDailyExp,bigDecimal.toString());
            field.set(videoDailyExp, bigDecimal.toString());
        }
    }
}