fuliqi
2024-08-21 9da24a8dfa3766cec565b092fc105f7f006de070
ycl-server/src/main/java/com/ycl/task/CheckScoreTask.java
@@ -13,6 +13,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.lang.reflect.Field;
import java.math.BigDecimal;
@@ -33,14 +34,13 @@
    @Autowired
    private CheckScoreMapper scoreMapper;
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private ICheckIndexVideoService videoService;
    @Autowired
    private ICheckIndexFaceService faceService;
    @Autowired
    private ICheckIndexCarService carService;
    //TODO:统一任务时间
    public void executeTemplate(Integer templateId) {
        CheckTemplate checkTemplate = templateMapper.selectCheckTemplateById(templateId);
        if (checkTemplate != null) {
@@ -66,7 +66,7 @@
                //根据模板的考核标签查各区县对应省厅或市局视频数据
                List<CheckIndexVideo> checkIndexVideos = videoService.selectCheckIndexVideoList(checkIndexVideo);
                for (CheckIndexVideo indexVideo : checkIndexVideos) {
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexVideo,CheckConstants.Rule_Category_Video);
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexVideo, CheckConstants.Rule_Category_Video);
                }
            } else if (CheckConstants.Rule_Category_Car.equals(examineCategory)) {
                CheckIndexCar checkIndexCar = new CheckIndexCar();
@@ -76,7 +76,7 @@
                //根据模板的考核标签查各区县对应省厅或市局车辆数据
                List<CheckIndexCar> checkIndexCars = carService.selectCheckIndexCarList(checkIndexCar);
                for (CheckIndexCar indexCar : checkIndexCars) {
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexCar,CheckConstants.Rule_Category_Car);
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexCar, CheckConstants.Rule_Category_Car);
                }
            } else if (CheckConstants.Rule_Category_Face.equals(examineCategory)) {
                CheckIndexFace checkIndexFace = new CheckIndexFace();
@@ -89,39 +89,19 @@
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexFace, CheckConstants.Rule_Category_Face);
                }
            }
            //储存分数
            scoreMapper.saveBatch(scoreList);
            log.info("模板执行完成");
            if(!CollectionUtils.isEmpty(scoreList)) {
                scoreMapper.saveBatch(scoreList);
            }
        }
        log.info("定时任务执行完成");
    }
    //查mongo数据归档到mysql
    public void dataArchiving() {
        //TODO:归档check_index_car,区分省厅市局,每个区县一条数据
        CheckIndexCar checkIndexCar = new CheckIndexCar();
        //TODO:归档check_index_face
        CheckIndexFace checkIndexFace = new CheckIndexFace();
        //TODO:归档check_index_video
        CheckIndexVideo checkIndexVideo = new CheckIndexVideo();
    }
    private <T extends CheckIndex> void addToList(Integer templateId, CheckTemplate checkTemplate, Short examineTag, List<CheckTemplateRule> templateRuleList, List<CheckScore> scoreList, T indexObject, Short checkCategory) {
        CheckScore checkScore = new CheckScore();
        BigDecimal scoreFinal = BigDecimal.ZERO;
        BigDecimal alarmScore = checkTemplate.getAlarmScore();
        for (CheckTemplateRule templateRule : templateRuleList) {
            //计算分数
            scoreFinal = getScoreFinal(indexObject, scoreFinal, templateRule);
            //TODO:根据报警分数阈值,添加报警信息
            if(scoreFinal.compareTo(alarmScore)<0){
            }
        }
        //补充checkScore
        fillCheckScore(templateId, checkTemplate, examineTag, indexObject, checkScore, scoreFinal, checkCategory);
@@ -142,7 +122,7 @@
            BigDecimal score = index.multiply(templateRule.getWeight());
            scoreFinal = scoreFinal.add(score);
        } catch (Exception e) {
            log.info("反射异常", e);
            log.info("反射异常", e.getMessage());
        }
        return scoreFinal;
    }