| | |
| | | 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.mapper.*; |
| | | import com.ycl.platform.service.*; |
| | | import constant.CheckConstants; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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; |
| | |
| | | @Autowired |
| | | private CheckScoreMapper scoreMapper; |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | private CheckIndexVideoMapper videoMapper; |
| | | @Autowired |
| | | private ICheckIndexVideoService videoService; |
| | | private CheckIndexFaceMapper faceMapper; |
| | | @Autowired |
| | | private ICheckIndexFaceService faceService; |
| | | @Autowired |
| | | private ICheckIndexCarService carService; |
| | | private CheckIndexCarMapper carMapper; |
| | | |
| | | public void executeTemplate(Integer templateId) { |
| | | CheckTemplate checkTemplate = templateMapper.selectCheckTemplateById(templateId); |
| | |
| | | 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); |
| | | } |
| | | } else if (CheckConstants.Rule_Category_Car.equals(examineCategory)) { |
| | | CheckIndexCar checkIndexCar = new CheckIndexCar(); |
| | |
| | | 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); |
| | | } |
| | | } else if (CheckConstants.Rule_Category_Face.equals(examineCategory)) { |
| | | CheckIndexFace checkIndexFace = new CheckIndexFace(); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | //储存分数 |
| | | 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); |
| | |
| | | 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(); |
| | | |
| | | } |
| | | } |