xiangpei
2024-09-06 3848c5677aefdb201c24d615a7c2ad03fd5154e6
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;
@@ -32,8 +33,6 @@
    private CheckTemplateRuleMapper checkTemplateRuleMapper;
    @Autowired
    private CheckScoreMapper scoreMapper;
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private ICheckIndexVideoService videoService;
    @Autowired
@@ -66,7 +65,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 +75,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();
@@ -86,31 +85,31 @@
                //根据模板的考核标签查各区县对应省厅或市局人脸数据
                List<CheckIndexFace> checkIndexFaces = faceService.selectCheckIndexFaceList(checkIndexFace);
                for (CheckIndexFace indexFace : checkIndexFaces) {
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexFace,CheckConstants.Rule_Category_Face);
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexFace, CheckConstants.Rule_Category_Face);
                }
            }
            //储存分数
            scoreMapper.saveBatch(scoreList);
            //TODO:根据报警分数阈值,添加报警信息
            if(!CollectionUtils.isEmpty(scoreList)) {
                scoreMapper.saveBatch(scoreList);
            }
        }
    }
    private <T extends CheckIndex>void addToList(Integer templateId, CheckTemplate checkTemplate, Short examineTag, List<CheckTemplateRule> templateRuleList, List<CheckScore> scoreList, T indexObject,Short checkCategory) {
    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();
        checkScore.setIndexId(indexObject.getId());
        BigDecimal scoreFinal = BigDecimal.ZERO;
        for (CheckTemplateRule templateRule : templateRuleList) {
            //计算分数
            scoreFinal = getScoreFinal(indexObject, scoreFinal, templateRule);
        }
        //补充checkScore
        fillCheckScore(templateId, checkTemplate, examineTag, indexObject, checkScore, scoreFinal,checkCategory);
        fillCheckScore(templateId, checkTemplate, examineTag, indexObject, checkScore, scoreFinal, checkCategory);
        scoreList.add(checkScore);
    }
    //通用方法计算分数
    private <T>BigDecimal getScoreFinal(T object, BigDecimal scoreFinal, CheckTemplateRule templateRule) {
    private <T> BigDecimal getScoreFinal(T object, BigDecimal scoreFinal, CheckTemplateRule templateRule) {
        String ruleIndex = templateRule.getRuleIndex();
        //将a_b_c转换为aBC
        String camelRuleIndex = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, ruleIndex);
@@ -123,37 +122,27 @@
            BigDecimal score = index.multiply(templateRule.getWeight());
            scoreFinal = scoreFinal.add(score);
        } catch (Exception e) {
            log.info("反射异常",e);
            log.info("反射异常", e.getMessage());
        }
        return scoreFinal;
    }
    //设置checkScore对象
    private void fillCheckScore(Integer templateId, CheckTemplate checkTemplate, Short examineTag, CheckIndex checkIndex, CheckScore checkScore, BigDecimal scoreFinal,Short checkCategory) {
    private void fillCheckScore(Integer templateId, CheckTemplate checkTemplate, Short examineTag, CheckIndex checkIndex, CheckScore checkScore, BigDecimal scoreFinal, Short checkCategory) {
        //根据调整系数调整最终分数大小
        String adjustWay = checkTemplate.getAdjustWay();
        BigDecimal adjustCoefficient = checkTemplate.getAdjustCoefficient();
        if(CheckConstants.Multiply.equals(adjustWay)){
        if (CheckConstants.Multiply.equals(adjustWay)) {
            scoreFinal = adjustCoefficient.multiply(scoreFinal).multiply(new BigDecimal(100));
        }else if(CheckConstants.Divided.equals(adjustWay)){
        } else if (CheckConstants.Divided.equals(adjustWay)) {
            //四舍五入保留小数后四位
            scoreFinal = scoreFinal.divide(adjustCoefficient,4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
            scoreFinal = scoreFinal.divide(adjustCoefficient, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
        }
        checkScore.setCreateTime(new Date());
        checkScore.setExamineTag(Integer.parseInt(examineTag +""));
        checkScore.setExamineTag(Integer.parseInt(examineTag + ""));
        checkScore.setExamineCategory(checkCategory);
        checkScore.setDeptId(checkIndex.getDeptId());
        checkScore.setTemplateId(templateId);
        checkScore.setScore(scoreFinal);
    }
    //查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();
    }
}