| | |
| | | import com.ycl.platform.domain.entity.WorkOrder; |
| | | import com.ycl.platform.domain.entity.YwPoint; |
| | | import com.ycl.platform.domain.result.HK.PicAccessResult; |
| | | import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult; |
| | | import com.ycl.platform.domain.result.SYS.TMonitorResult; |
| | | import com.ycl.platform.domain.result.UY.RecordMetaDSumResult; |
| | | import com.ycl.platform.domain.result.UY.VideoOnlineResult; |
| | | import com.ycl.platform.domain.vo.CalculateRuleVO; |
| | | import com.ycl.platform.domain.vo.WorkOrderVO; |
| | | import com.ycl.platform.mapper.*; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | |
| | | */ |
| | | @Slf4j |
| | | @Component("contractTask") |
| | | //TODO:重新看下逻辑 |
| | | public class ContractTask { |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | |
| | | * 合同考核 在线率每日任务检测 |
| | | * 查生效的合同关联的公司,获取unitId集合 |
| | | * 根据unitId查询对应点位获取各个公司管理的设备Ids |
| | | * 查询三种设备在线不在线情况,封装为一个map<国标码,在线状态> |
| | | * 计算每日每家公司的在线率存入mysql |
| | | * 月底计算平均值,根据在线率和合同标准扣减分数 |
| | | */ |
| | |
| | | List<Integer> unitIds = ruleVos.stream().map(CalculateRuleVO::getUnitId).collect(Collectors.toList()); |
| | | List<YwPoint> ywPoints = ywPointMapper.selectList(new QueryWrapper<YwPoint>().in("unit_id", unitIds)); |
| | | //key是unitId value是设备编码集合 |
| | | Map<Long, List<String>> unitMap = ywPoints.stream() |
| | | Map<Long, List<YwPoint>> unitMap = ywPoints.stream().filter(point -> point.getUnitId() != null) |
| | | .collect(Collectors.groupingBy( |
| | | YwPoint::getUnitId, |
| | | Collectors.mapping( |
| | | YwPoint::getSerialNumber, |
| | | Collectors.toList() |
| | | YwPoint::getUnitId |
| | | ) |
| | | )); |
| | | Map<String, Integer> onlineStatusMap = new HashMap<>(); |
| | | Date date = new Date(); |
| | | //车辆、人脸 |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(date)).lt(DateUtils.getDayEnd(date))); |
| | | List<TMonitorResult> tMonitorResults = mongoTemplate.find(query, TMonitorResult.class); |
| | | for (TMonitorResult result : tMonitorResults) { |
| | | if(result.getPingOnline()){ |
| | | onlineStatusMap.put(result.getNo(), Online); |
| | | }else { |
| | | onlineStatusMap.put(result.getNo(), Offline); |
| | | } |
| | | } |
| | | |
| | | ); |
| | | //查询报备列表 |
| | | List<String> reportNumbers = reportMapper.selectNumberList(AuditStatus_Pass, DateUtils.getDate()); |
| | | //计算每个公司的点位在线率 |
| | | List<ContractRuleRecord> ruleRecordList = new ArrayList<>(); |
| | | unitMap.forEach((unitId, serialNumberList) -> { |
| | | unitMap.forEach((unitId, pointList) -> { |
| | | int totalSite = 0; |
| | | int onlineSite = 0; |
| | | for (String number : serialNumberList) { |
| | | for (YwPoint point : pointList) { |
| | | //报备过不纳入计算 |
| | | if (!CollectionUtils.isEmpty(reportNumbers) && reportNumbers.contains(number)) continue; |
| | | Integer status = onlineStatusMap.get(number); |
| | | if (!CollectionUtils.isEmpty(reportNumbers) && reportNumbers.contains(point.getSerialNumber())) |
| | | continue; |
| | | totalSite++; |
| | | if (Online.equals(status)) { |
| | | if (ApiConstants.UY_OnlineSite_Online.equals(point.getOnline())) { |
| | | onlineSite++; |
| | | } |
| | | } |
| | | BigDecimal online = new BigDecimal(onlineSite).divide(new BigDecimal(totalSite), 2, RoundingMode.DOWN); |
| | | BigDecimal online = BigDecimal.ONE; |
| | | if (totalSite != 0) { |
| | | online = new BigDecimal(onlineSite).divide(new BigDecimal(totalSite), 2, RoundingMode.DOWN); |
| | | } |
| | | ContractRuleRecord contractRuleRecord = new ContractRuleRecord(); |
| | | contractRuleRecord.setSiteOnline(online); |
| | | contractRuleRecord.setCreateTime(new Date()); |
| | |
| | | public void calculateOnlineScore() { |
| | | //TODO:检查表 |
| | | log.info("开始计算合同点位在线率分数"); |
| | | //如果是月底,需要统计平均在线率然后进行积分扣除 |
| | | // String now = DateUtils.getDate(); |
| | | //月底需要统计平均在线率然后进行积分扣除 |
| | | String mouthStart = DateUtils.getMouthStart(new Date()); |
| | | String mouthEnd = DateUtils.getMouthEnd(new Date()); |
| | | // if (now.equals(mouthEnd)) { |
| | | //查一个月的记录 |
| | | List<ContractRuleRecord> ruleMonthRecords = recordMapper.selectMonth(mouthStart, mouthEnd); |
| | | //通过unitId分单位 |
| | | //通过unitId分单位,获取当月数据map |
| | | Map<Long, List<ContractRuleRecord>> unitMap = ruleMonthRecords.stream().collect(Collectors.groupingBy(ContractRuleRecord::getUnitId)); |
| | | //查在线率规则 获取key为合同id,value为在线率规则的map |
| | | //查在线率规则 获取key为合同id,value为在线率规则集合 |
| | | Map<Integer, List<CalculateRuleVO>> contractMap = contractMapper.getCalculateRule(new Date()).stream() |
| | | .filter(calculateRuleVO -> ContractRule.CONTRACT_RULE_Online.getName().equals(calculateRuleVO.getRuleName())) |
| | | .collect(Collectors.groupingBy(CalculateRuleVO::getContractId)); |
| | |
| | | CalculateRuleVO calculateRuleVO = ruleList.get(0); |
| | | Integer unitId = calculateRuleVO.getUnitId(); |
| | | List<ContractRuleRecord> ruleRecordList = unitMap.get(Long.parseLong(unitId + "")); |
| | | if (!CollectionUtils.isEmpty(ruleMonthRecords)) { |
| | | if (!CollectionUtils.isEmpty(ruleRecordList)) { |
| | | BigDecimal siteOnlineTotal = ruleRecordList.stream().map(ContractRuleRecord::getSiteOnline).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal siteOnline = siteOnlineTotal.divide(new BigDecimal(ruleRecordList.size()), 2, RoundingMode.DOWN); |
| | | for (CalculateRuleVO ruleVO : ruleList) { |
| | |
| | | } |
| | | } |
| | | }); |
| | | // } |
| | | contractScoreService.saveBatch(contractScoreList); |
| | | log.info("结束计算合同点位在线率分数"); |
| | | } |
| | |
| | | )); |
| | | //前端感知源治理工作(时钟同步规则、OSD规则、一机一档规则) 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> monitorRuleMap = ruleMap.get(ContractRule.CONTRACT_RULE_Monitor.getName()); |
| | | //存储故障(24小时以内,48小时以内) 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> storeRuleMap = ruleMap.get(ContractRule.CONTRACT_RULE_Store.getName()); |
| | | //存储故障(24小时以内,48小时以内) 获取key为合同id,value为规则的map (改成手动的了) |
| | | // Map<Integer, List<CalculateRuleVO>> storeRuleMap = ruleMap.get(ContractRule.CONTRACT_RULE_Store.getName()); |
| | | //点位异常情况处理 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> siteRuleMap = ruleMap.get(ContractRule.CONTRACT_RULE_Site.getName()); |
| | | //查询报备列表 |
| | |
| | | if (reportNumbers.contains(workOrder.getSerialNumber())) continue; |
| | | } |
| | | String errorType = workOrder.getErrorType(); |
| | | //存储故障 录像或图片访问异常 |
| | | //存储故障 录像或图片访问异常 (改成手动打分了) |
| | | // if (ErrorType.VIDEO_NONE.getValue().equals(errorType) || ErrorType.PIC_URLABNORMAL.getValue().equals(errorType)) { |
| | | // if (!CollectionUtils.isEmpty(storeRuleMap)) { |
| | | // storeRuleMap.forEach((contractId, rules) -> { |
| | |
| | | // } |
| | | // } |
| | | //前端感知源治理工作(时钟同步规则、OSD规则、一机一档规则) |
| | | if (ErrorType.POINT_INFO_ERROR.getValue().equals(errorType) || ErrorType.OSD_ERROR.getValue().equals(errorType) || ErrorType.CLOCK_SKEW.getValue().equals(errorType)) { |
| | | if (ErrorType.OSD_ERROR.getValue().equals(errorType) || ErrorType.CLOCK_SKEW.getValue().equals(errorType) || ErrorType.CLOCK_RIGHT.getValue().equals(errorType)) { |
| | | if (!CollectionUtils.isEmpty(monitorRuleMap)) { |
| | | monitorRuleMap.forEach((contractId, rules) -> { |
| | | Integer unitId = rules.get(0).getUnitId(); |
| | |
| | | } |
| | | } |
| | | //点位异常情况处理(镜头异常、摄像头遮挡等) |
| | | if (ErrorType.SCREEN_COLOR_DEVIATION.getValue().equals(errorType) || ErrorType.SNOW_STORM.getValue().equals(errorType) || ErrorType.STRIPE_INTERFERENCE.getValue().equals(errorType) || ErrorType.SCREEN_OCCLUSION.getValue().equals(errorType) || ErrorType.ABNORMAL_CLARITY.getValue().equals(errorType) || ErrorType.ABNORMAL_BRIGHTNESS.getValue().equals(errorType)) { |
| | | if (ErrorType.SCREEN_OCCLUSION.getValue().equals(errorType)) { |
| | | if (!CollectionUtils.isEmpty(monitorRuleMap)) { |
| | | siteRuleMap.forEach((contractId, rules) -> { |
| | | Integer unitId = rules.get(0).getUnitId(); |
| | |
| | | for (CalculateRuleVO rule : rules) { |
| | | if (checkRange(rule.getMin(), rule.getMax(), new BigDecimal(diffTime))) { |
| | | double deductScore = 0d; |
| | | if (ContractRule.CONTRACT_RULE_Store_48H.getName().equals(rule.getRuleCondition())) { |
| | | if (ContractRule.CONTRACT_RULE_Site_Error48.getName().equals(rule.getRuleCondition())) { |
| | | //计算超时天数 |
| | | int day = (int) ((diffTime - 48) / 24 + 1); |
| | | deductScore = rule.getCalcFraction() * (day); |
| | |
| | | } |
| | | //判断是否是该公司运维 |
| | | if (monitorList.contains(picAccessResult.getExternalIndexCode())) { |
| | | //存在大图不可用数据量,需要扣减 |
| | | if (picAccessResult.getBigDisableCount() > 0) { |
| | | //存在图片访问异常数据量,需要扣减 |
| | | if (picAccessResult.getExpCount() > 0) { |
| | | deduct = true; |
| | | serialNumber = picAccessResult.getExternalIndexCode(); |
| | | break; |
| | |
| | | List<ContractScore> contractScoreList = new ArrayList<>(); |
| | | //查询报备列表 |
| | | List<String> reportNumbers = reportMapper.selectNumberList(AuditStatus_Pass, DateUtils.getDate()); |
| | | //TODO:测试日期 |
| | | Date date = DateUtils.getDay(2024, 7, 13); |
| | | //查图片完整性规则 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> contractMap = contractMapper.getCalculateRule(new Date()).stream() |