zxl
2025-02-19 002372c5cfd2c9b9881fda5e527c2b6c4ee4d599
ycl-server/src/main/java/com/ycl/task/VideoTask.java
@@ -6,19 +6,21 @@
import com.ycl.platform.domain.entity.CheckIndexVideo;
import com.ycl.platform.domain.entity.ImageResourceSecurity;
import com.ycl.platform.domain.entity.ImageResourceSecurityDetail;
import com.ycl.platform.domain.form.VideoExportForm;
import com.ycl.platform.domain.result.SYS.TMonitorResult;
import com.ycl.platform.domain.result.UY.*;
import com.ycl.platform.domain.vo.PlatformOnlineVO;
import com.ycl.platform.domain.vo.TMonitorVO;
import com.ycl.platform.mapper.CheckIndexVideoMapper;
import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper;
import com.ycl.platform.mapper.PlatformOnlineMapper;
import com.ycl.platform.mapper.TMonitorMapper;
import com.ycl.platform.mapper.*;
import com.ycl.platform.service.IImageResourceSecurityService;
import com.ycl.utils.DateUtils;
import com.ycl.utils.DictUtils;
import constant.ApiConstants;
import constant.CalculationStrategyConstants;
import constant.CheckConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
@@ -32,6 +34,7 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * 视频计算考核指标任务
@@ -51,6 +54,8 @@
    private final IImageResourceSecurityService imageResourceSecurityService;
    private final CheckIndexVideoMapper checkIndexVideoMapper;
    private final ImageResourceSecurityDetailMapper imageResourceSecurityDetailMapper;
    private final ImageResourceSecurityMapper imageResourceSecurityMapper;
    private static final BigDecimal NUM = new BigDecimal("0.15");
    public void siteOnlineTask() {
@@ -59,9 +64,13 @@
        //计算点位在线率和重点点位在线率和指挥图像在线率
        Query query = new Query();
        query.addCriteria(Criteria
                .where("mongoCreateTime").gte(DateUtils.getDayStart(yesterday)).lt(DateUtils.getDayEnd(yesterday)));
        List<VideoOnlineResult> results = mongoTemplate.find(query, VideoOnlineResult.class);
                .where("mongoCreateTime").gte(DateUtils.getDayStart(yesterday)).lt(DateUtils.getDayEnd(yesterday)));//<&== 昨天的开始时间 < 结束时间
        List<VideoOnlineResult> results = mongoTemplate.find(query, VideoOnlineResult.class);//
        //优云上有车辆和人脸的设备数据,需要过滤出视频设备
        List<String> videoIds = monitorMapper.getVideoIds();
        if(!CollectionUtils.isEmpty(results)){
            results = results.stream().filter(result -> videoIds.contains(result.getNo())).collect(Collectors.toList());
        }
        CalculationStrategy calculator = IndexCalculationFactory.getCalculator(CalculationStrategyConstants.Video_SiteOnline);
        calculator.calculate(results);
        log.info("结束计算点位在线率");
@@ -76,6 +85,11 @@
                .where("mongoCreateTime").gte(DateUtils.getDayStart(yesterday)).lt(DateUtils.getDayEnd(yesterday)));
        List<RecordMetaDSumResult> results = mongoTemplate.find(query, RecordMetaDSumResult.class);
        //优云上有车辆和人脸的设备数据,需要过滤出视频设备
        List<String> videoIds = monitorMapper.getVideoIds();
        if(!CollectionUtils.isEmpty(results)){
            results = results.stream().filter(result -> videoIds.contains(result.getNo())).collect(Collectors.toList());
        }
        CalculationStrategy calculator = IndexCalculationFactory.getCalculator(CalculationStrategyConstants.Video_Usability);
        calculator.calculate(results);
        log.info("结束计算录像可用率和重点录像可用率");
@@ -84,12 +98,17 @@
    public void oneMonitorFileTask() {
        log.info("开始计算一机一档注册率、档案考核比");
        //计算一机一档注册率、档案考核比
        List<TMonitorVO> tMonitorVOS = monitorMapper.selectMonitorVOList();
        Date yesterday = DateUtils.addDays(new Date(), -1);
        Query query = new Query();
        query.addCriteria(Criteria
                .where("mongoCreateTime").gte(DateUtils.getDayStart(yesterday)).lt(DateUtils.getDayEnd(yesterday)));
        List<MonitorQualifyResult> results = mongoTemplate.find(query, MonitorQualifyResult.class);
        CalculationStrategy calculator = IndexCalculationFactory.getCalculator(CalculationStrategyConstants.Video_MonitorRegis_ArchiveRate);
        calculator.calculate(tMonitorVOS);
        calculator.calculate(results);
        log.info("结束计算一机一档注册率、档案考核比");
    }
    public void oneMonitorQualifyTask(){
    public void oneMonitorQualifyTask() {
        log.info("开始计算一机一档合格率");
        //计算一机一档合格率
        Date yesterday = DateUtils.addDays(new Date(), -1);
@@ -101,6 +120,7 @@
        calculator.calculate(results);
        log.info("结束计算一机一档合格率");
    }
    public void platformOnlineTask() {
        log.info("开始计算平台在线率");
        //计算平台在线率
@@ -109,14 +129,16 @@
        calculator.calculate(list);
        log.info("结束计算平台在线率");
    }
    public void osdTask() {
        log.info("开始计算Osd标注、时间准确率");
        //计算Osd标注、时间准确率
//        Date yesterday = DateUtils.addDays(new Date(), -1);
        Date yesterday = DateUtils.addDays(new Date(), -1);
        Query query = new Query();
        query.addCriteria(Criteria
                .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date())));
                .where("mongoCreateTime").gte(DateUtils.getDayStart(yesterday)).lt(DateUtils.getDayEnd(yesterday)));
        List<OsdCheckResult> results = mongoTemplate.find(query, OsdCheckResult.class);
        CalculationStrategy calculator = IndexCalculationFactory.getCalculator(CalculationStrategyConstants.Video_OsdTime);
        calculator.calculate(results);
        log.info("结束计算Osd标注、时间准确率");
@@ -125,7 +147,7 @@
    /**
     * 视频图像资源安全,需要排在平台在线率后面。
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public void videoSecurity() {
        ArrayList<ImageResourceSecurity> imageResourceSecurities = new ArrayList<>();
        List<CheckIndexVideo> list = checkIndexVideoMapper.selectAndDeptName();
@@ -151,14 +173,23 @@
                    count++;
                }
            }
            imageResourceSecurity.setWeakPassword(BigDecimal.valueOf(score).divide(new BigDecimal(100),4, RoundingMode.HALF_UP));
            imageResourceSecurity.setWeakPassword(BigDecimal.valueOf(score).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP));
            // 获取字典值-总数
            int onlineAssetsTotal = Integer.parseInt(DictUtils.getDictValue("online_assets_total", checkIndexVideo.getDeptName()));
            imageResourceSecurity.setRiskProperty(BigDecimal.valueOf(count / onlineAssetsTotal));
            imageResourceSecurity.setCreateTime(DateUtils.getNowDate());
            imageResourceSecurities.add(imageResourceSecurity);
            //获取最近一次数据手动打分
            ImageResourceSecurity latest = imageResourceSecurityMapper.getLatest(checkIndexVideo.getDeptId(),new Date());
            imageResourceSecurity.setBoundaryIntegrity(latest ==null?BigDecimal.ONE:latest.getBoundaryIntegrity());
            // 更新指标数据
            checkIndexVideo.setImageResourceSecurity(imageResourceSecurity.getPlatformOnline().add(imageResourceSecurity.getPropertyAccuracy().add(imageResourceSecurity.getWeakPassword().add(imageResourceSecurity.getRiskProperty()))).multiply(NUM));
            checkIndexVideo.setImageResourceSecurity(
                    imageResourceSecurity.getPlatformOnline()
                            .add(imageResourceSecurity.getPropertyAccuracy()
                                    .add(imageResourceSecurity.getWeakPassword()
                                            .add(imageResourceSecurity.getRiskProperty()))).multiply(NUM)
                            .add(imageResourceSecurity.getBoundaryIntegrity()).multiply(new BigDecimal("0.45"))
            );
            checkIndexVideoMapper.updateById(checkIndexVideo);
        }
        imageResourceSecurityService.saveBatch(imageResourceSecurities);