zxl
4 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
ycl-server/src/main/java/com/ycl/task/CheckScoreTask.java
@@ -4,11 +4,11 @@
import com.google.common.base.CaseFormat;
import com.ycl.platform.base.CheckIndex;
import com.ycl.platform.domain.entity.*;
import com.ycl.platform.mapper.CheckScoreMapper;
import com.ycl.platform.mapper.CheckTemplateMapper;
import com.ycl.platform.mapper.CheckTemplateRuleMapper;
import com.ycl.platform.domain.vo.YwPointVO;
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;
@@ -34,18 +34,23 @@
    @Autowired
    private CheckScoreMapper scoreMapper;
    @Autowired
    private ICheckIndexVideoService videoService;
    private ICheckScoreService checkScoreService;
    @Autowired
    private ICheckIndexFaceService faceService;
    private CheckIndexVideoMapper videoMapper;
    @Autowired
    private ICheckIndexCarService carService;
    private CheckIndexFaceMapper faceMapper;
    @Autowired
    private CheckIndexCarMapper carMapper;
    @Autowired
    private YwPointMapper pointMapper;
    //公安部只有视频考核
    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();
            //用于补充数量
            List<YwPointVO> pointVOS= pointMapper.selectToCount(examineCategory, examineTag);
            //查权重
            CheckTemplateRule checkTemplateRule = new CheckTemplateRule();
            checkTemplateRule.setCheckTemplateId(templateId);
@@ -53,7 +58,6 @@
            //查今天的index指标
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String day = dateFormat.format(new Date());
            //创建score集合方便最后批量存储
            List<CheckScore> scoreList = new ArrayList<>();
            //根据考核类别和考核标签,查不同index表(区分省厅区县)
@@ -62,48 +66,63 @@
                checkIndexVideo.setExamineTag(examineTag);
                checkIndexVideo.setDay(day);
                checkIndexVideo.setDeptIds(JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class));
                //根据模板的考核标签查各区县对应省厅或市局视频数据
                List<CheckIndexVideo> checkIndexVideos = videoService.selectCheckIndexVideoList(checkIndexVideo);
                //根据模板的考核标签查各区县对应省厅或市局或公安部视频数据
                List<CheckIndexVideo> checkIndexVideos = videoMapper.getCheckIndexVideoList(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,pointVOS);
                }
            } else if (CheckConstants.Rule_Category_Car.equals(examineCategory)) {
                CheckIndexCar checkIndexCar = new CheckIndexCar();
                checkIndexCar.setDay(day);
                checkIndexCar.setExamineTag(examineTag);
                checkIndexCar.setDeptIds(JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class));
                //根据模板的考核标签查各区县对应省厅或市局车辆数据
                List<CheckIndexCar> checkIndexCars = carService.selectCheckIndexCarList(checkIndexCar);
                //根据模板的考核标签查各区县对应省厅或市局或公安部车辆数据
                List<CheckIndexCar> checkIndexCars = carMapper.getCheckIndexCarList(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,pointVOS);
                }
            } else if (CheckConstants.Rule_Category_Face.equals(examineCategory)) {
                CheckIndexFace checkIndexFace = new CheckIndexFace();
                checkIndexFace.setDay(day);
                checkIndexFace.setExamineTag(examineTag);
                checkIndexFace.setDeptIds(JSONArray.parseArray(checkTemplate.getDeptId(), Integer.class));
                //根据模板的考核标签查各区县对应省厅或市局人脸数据
                List<CheckIndexFace> checkIndexFaces = faceService.selectCheckIndexFaceList(checkIndexFace);
                //根据模板的考核标签查各区县对应省厅或市局或公安部人脸数据
                List<CheckIndexFace> checkIndexFaces = faceMapper.getCheckIndexFaceList(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,pointVOS);
                }
            }
            //查出今天生成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);
            }
        }
    }
    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, List<YwPointVO> pointVOS) {
        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,pointVOS);
        scoreList.add(checkScore);
    }
@@ -121,21 +140,23 @@
            BigDecimal score = index.multiply(templateRule.getWeight());
            scoreFinal = scoreFinal.add(score);
        } catch (Exception e) {
            log.info("反射异常", e.getMessage());
            log.error("反射异常", 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, List<YwPointVO> pointVOS) {
        //根据调整系数调整最终分数大小
        String adjustWay = checkTemplate.getAdjustWay();
        BigDecimal adjustCoefficient = checkTemplate.getAdjustCoefficient();
        if (CheckConstants.Multiply.equals(adjustWay)) {
            scoreFinal = adjustCoefficient.multiply(scoreFinal).multiply(new BigDecimal(100));
//            scoreFinal = adjustCoefficient.multiply(scoreFinal).multiply(new BigDecimal(100));
            scoreFinal = adjustCoefficient.multiply(scoreFinal);
        } 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));
            scoreFinal = scoreFinal.divide(adjustCoefficient, 4, RoundingMode.HALF_UP);
        }
        checkScore.setCreateTime(new Date());
        checkScore.setExamineTag(Integer.parseInt(examineTag + ""));
@@ -143,5 +164,10 @@
        checkScore.setDeptId(checkIndex.getDeptId());
        checkScore.setTemplateId(templateId);
        checkScore.setScore(scoreFinal);
        checkScore.setPublish(PublishType.PUBLISHED.getCode());
        if(!CollectionUtils.isEmpty(pointVOS)) {
            long count = pointVOS.stream().filter(ywPointVO -> checkIndex.getDeptId().equals(ywPointVO.getDeptId())).count();
            checkScore.setDeviceCount((int) count);
        }
    }
}