fuliqi
2024-11-01 b91945ea32378a71d1e57356af6e16703a1ceaa7
ycl-server/src/main/java/com/ycl/task/CheckScoreTask.java
@@ -7,6 +7,7 @@
import com.ycl.platform.mapper.*;
import com.ycl.platform.service.*;
import constant.CheckConstants;
import enumeration.general.PublishType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
@@ -24,6 +25,7 @@
@Slf4j
@Component("checkScoreTask")
//TODO:修改score、index默认发布
public class CheckScoreTask {
    @Autowired
    private CheckTemplateMapper templateMapper;
@@ -32,16 +34,17 @@
    @Autowired
    private CheckScoreMapper scoreMapper;
    @Autowired
    private ICheckScoreService checkScoreService;
    @Autowired
    private CheckIndexVideoMapper videoMapper;
    @Autowired
    private CheckIndexFaceMapper faceMapper;
    @Autowired
    private CheckIndexCarMapper carMapper;
    //公安部只有视频考核
    public void executeTemplate(Integer templateId) {
        CheckTemplate checkTemplate = templateMapper.selectCheckTemplateById(templateId);
        if (checkTemplate != null) {
            log.info("执行考核模板---------->{}", checkTemplate.getTemplateName());
            Short examineCategory = checkTemplate.getExamineCategory();
            Short examineTag = checkTemplate.getExamineTag();
            //查权重
@@ -51,7 +54,6 @@
            //查今天的index指标
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String day = dateFormat.format(new Date());
            //创建score集合方便最后批量存储
            List<CheckScore> scoreList = new ArrayList<>();
            //根据考核类别和考核标签,查不同index表(区分省厅区县)
@@ -60,7 +62,7 @@
                checkIndexVideo.setExamineTag(examineTag);
                checkIndexVideo.setDay(day);
                checkIndexVideo.setDeptIds(JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class));
                //根据模板的考核标签查各区县对应省厅或市局视频数据
                //根据模板的考核标签查各区县对应省厅或市局或公安部视频数据
                List<CheckIndexVideo> checkIndexVideos = videoMapper.getCheckIndexVideoList(checkIndexVideo);
                for (CheckIndexVideo indexVideo : checkIndexVideos) {
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexVideo, CheckConstants.Rule_Category_Video);
@@ -70,7 +72,7 @@
                checkIndexCar.setDay(day);
                checkIndexCar.setExamineTag(examineTag);
                checkIndexCar.setDeptIds(JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class));
                //根据模板的考核标签查各区县对应省厅或市局车辆数据
                //根据模板的考核标签查各区县对应省厅或市局或公安部车辆数据
                List<CheckIndexCar> checkIndexCars = carMapper.getCheckIndexCarList(checkIndexCar);
                for (CheckIndexCar indexCar : checkIndexCars) {
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexCar, CheckConstants.Rule_Category_Car);
@@ -80,15 +82,29 @@
                checkIndexFace.setDay(day);
                checkIndexFace.setExamineTag(examineTag);
                checkIndexFace.setDeptIds(JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class));
                //根据模板的考核标签查各区县对应省厅或市局人脸数据
                //根据模板的考核标签查各区县对应省厅或市局或公安部人脸数据
                List<CheckIndexFace> checkIndexFaces = faceMapper.getCheckIndexFaceList(checkIndexFace);
                for (CheckIndexFace indexFace : checkIndexFaces) {
                    addToList(templateId, checkTemplate, examineTag, templateRuleList, scoreList, indexFace, CheckConstants.Rule_Category_Face);
                }
            }
            //查出今天生成score
            List<CheckScore> todays = scoreMapper.selectToday(day);
            //遍历scoreList集合,如果今天生成过补充id
            for (CheckScore result : scoreList) {
                for (CheckScore today : todays) {
                    //根据考核标签、考核种类、部门id查询是否存在今日数据
                    if(result.getExamineTag().equals(today.getExamineTag()) && result.getExamineCategory().equals(today.getExamineCategory()) && result.getDeptId().equals(today.getDeptId())){
                        //补充id,后续根据id saveOrUpdate
                        result.setId(today.getId());
                        result.setPublish(today.getPublish());
                    }
                }
            }
            //储存分数
            if(!CollectionUtils.isEmpty(scoreList)) {
                scoreMapper.saveBatch(scoreList);
            if (!CollectionUtils.isEmpty(scoreList)) {
                checkScoreService.saveOrUpdateBatch(scoreList);
            }
        }
    }
@@ -120,7 +136,7 @@
            BigDecimal score = index.multiply(templateRule.getWeight());
            scoreFinal = scoreFinal.add(score);
        } catch (Exception e) {
            log.info("反射异常", e.getMessage());
            log.error("反射异常", e.getMessage());
        }
        return scoreFinal;
    }
@@ -142,5 +158,6 @@
        checkScore.setDeptId(checkIndex.getDeptId());
        checkScore.setTemplateId(templateId);
        checkScore.setScore(scoreFinal);
        checkScore.setPublish(PublishType.PUBLISHED.getCode());
    }
}