| | |
| | | import enumeration.general.WorkOrderStatusEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.dao.DataAccessException; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | |
| | | private static final Integer Offline = -1; |
| | | private static final String AuditStatus_Pass = "1"; |
| | | private static final String Remark = "系统生成"; |
| | | private static final Integer randomSize = 30; |
| | | |
| | | /** |
| | | * 合同考核 在线率每日任务检测 |
| | |
| | | .filter(calculateRuleVO -> ContractRule.CONTRACT_RULE_Online.getName().equals(calculateRuleVO.getRuleName())) |
| | | .collect(Collectors.toList()); |
| | | List<Integer> unitIds = ruleVos.stream().map(CalculateRuleVO::getUnitId).collect(Collectors.toList()); |
| | | List<YwPoint> ywPoints = ywPointMapper.selectList(new QueryWrapper<YwPoint>().in("unit_id", unitIds).eq("examine_status",1)); |
| | | List<YwPoint> ywPoints = ywPointMapper.selectList(new QueryWrapper<YwPoint>().in("unit_id", unitIds).eq("examine_status", 1)); |
| | | //key是unitId value是设备编码集合 |
| | | Map<Long, List<YwPoint>> unitMap = ywPoints.stream().filter(point -> point.getUnitId() != null) |
| | | .collect(Collectors.groupingBy( |
| | | YwPoint::getUnitId |
| | | YwPoint::getUnitId |
| | | ) |
| | | ); |
| | | //查询报备列表 |
| | |
| | | LocalDateTime endTime = LocalDateTime.now(); |
| | | // 计算30天前的日期 |
| | | LocalDateTime startTime = endTime.minusDays(30); |
| | | //需要查审核通过那条记录的时间 |
| | | List<WorkOrderVO> workOrders = workOrderMapper.selectPassOrder(startTime, endTime, WorkOrderStatusEnum.AUDITING_SUCCESS.getValue(), "审核通过"); |
| | | //自动扣分的工单故障类型 |
| | | List<String> deductErrorType = new ArrayList<>(); |
| | | deductErrorType.add(ErrorType.OSD_ERROR.getValue()); |
| | | deductErrorType.add(ErrorType.ABNORMAL_PIC.getValue()); |
| | | deductErrorType.add(ErrorType.POINT_INFO_ERROR.getValue()); |
| | | deductErrorType.add(ErrorType.CLOCK_SKEW.getValue()); |
| | | List<WorkOrderVO> workOrders = workOrderMapper.selectPassOrder(startTime, endTime, WorkOrderStatusEnum.AUDITING_SUCCESS.getValue(), deductErrorType, "审核通过"); |
| | | //存在有两种扣分的故障 只扣减第一个故障 |
| | | Map<String, WorkOrderVO> map = workOrders.stream() |
| | | .collect(Collectors.toMap( |
| | | WorkOrderVO::getWorkOrderNo, |
| | | Function.identity(), |
| | | (older, newer) -> older.getDistributeTime().compareTo(newer.getDistributeTime()) <= 0 ? older : newer |
| | | )); |
| | | workOrders = new ArrayList<>(map.values()); |
| | | List<String> workOrderNos = workOrders.stream().map(WorkOrderVO::getWorkOrderNo).collect(Collectors.toList()); |
| | | List<WorkOrderVO> auditTimeList = workOrderMapper.getAuditTimeList(workOrderNos); |
| | | Map<String, List<Date>> auditTimeMap = auditTimeList.stream() |
| | | .collect(Collectors.groupingBy( |
| | | WorkOrderVO::getWorkOrderNo, // 分组的键 |
| | | Collectors.mapping(WorkOrderVO::getAuditTime, Collectors.toList()))); |
| | | List<WorkOrderVO> handleTimeList = workOrderMapper.getHandleTimeList(workOrderNos); |
| | | Map<String, List<Date>> handleTimeMap = handleTimeList.stream() |
| | | .collect(Collectors.groupingBy( |
| | | WorkOrderVO::getWorkOrderNo, // 分组的键 |
| | | Collectors.mapping(WorkOrderVO::getHandleTime, Collectors.toList()))); |
| | | for (WorkOrderVO workOrder : workOrders) { |
| | | //检测是否报备过 |
| | | if (!CollectionUtils.isEmpty(reportNumbers)) { |
| | |
| | | // } |
| | | // } |
| | | //前端感知源治理工作(时钟同步规则、OSD规则、一机一档规则) |
| | | if (ErrorType.OSD_ERROR.getValue().equals(errorType) || ErrorType.CLOCK_SKEW.getValue().equals(errorType) || ErrorType.CLOCK_RIGHT.getValue().equals(errorType) || ErrorType.POINT_INFO_ERROR.getValue().equals(errorType)) { |
| | | if (ErrorType.OSD_ERROR.getValue().equals(errorType) || ErrorType.CLOCK_SKEW.getValue().equals(errorType) || ErrorType.POINT_INFO_ERROR.getValue().equals(errorType)) { |
| | | if (!CollectionUtils.isEmpty(monitorRuleMap)) { |
| | | monitorRuleMap.forEach((contractId, rules) -> { |
| | | Integer unitId = rules.get(0).getUnitId(); |
| | |
| | | if (workOrder.getUnitId().equals(unitId)) { |
| | | //工单下发时间 |
| | | Date createTime = workOrder.getDistributeTime(); |
| | | Date auditTime = workOrder.getAuditTime(); |
| | | double diffTime = (double) (auditTime.getTime() - createTime.getTime()) / (1000 * 60 * 60); |
| | | List<Date> auditTimes = auditTimeMap.get(workOrder.getWorkOrderNo()); |
| | | List<Date> handleTimes = handleTimeMap.get(workOrder.getWorkOrderNo()); |
| | | //拿到审核时间 |
| | | long auditDuration = getAuditDuration(auditTimes, handleTimes); |
| | | //审核通过时间 |
| | | Date passTime = Collections.max(auditTimes); |
| | | //处理花费总时长 |
| | | double diffTime = (double) (passTime.getTime() - createTime.getTime() - auditDuration) / (1000 * 60 * 60); |
| | | //找到对应规则、选择时间范围内的规则 |
| | | for (CalculateRuleVO rule : rules) { |
| | | if(ErrorType.OSD_ERROR.getValue().equals(errorType)){ |
| | | if(!rule.getRuleCondition().equals("OSD标识")) continue; |
| | | }else if(ErrorType.CLOCK_SKEW.getValue().equals(errorType)){ |
| | | if(!rule.getRuleCondition().equals("时钟同步")) continue; |
| | | }else if( ErrorType.POINT_INFO_ERROR.getValue().equals(errorType)){ |
| | | if(!rule.getRuleCondition().equals("一机一档")) continue; |
| | | if (ErrorType.OSD_ERROR.getValue().equals(errorType)) { |
| | | if (!rule.getRuleCondition().equals("OSD标识")) continue; |
| | | } else if (ErrorType.CLOCK_SKEW.getValue().equals(errorType)) { |
| | | if (!rule.getRuleCondition().equals("时钟同步")) continue; |
| | | } else if (ErrorType.POINT_INFO_ERROR.getValue().equals(errorType)) { |
| | | if (!rule.getRuleCondition().equals("一机一档")) continue; |
| | | } |
| | | |
| | | if (checkRange(rule.getMin(), rule.getMax(), new BigDecimal(diffTime))) { |
| | |
| | | if (workOrder.getUnitId().equals(unitId)) { |
| | | //工单下发时间 |
| | | Date createTime = workOrder.getDistributeTime(); |
| | | Date auditTime = workOrder.getAuditTime(); |
| | | double diffTime = (double) (auditTime.getTime() - createTime.getTime()) / (1000 * 60 * 60); |
| | | List<Date> auditTimes = auditTimeMap.get(workOrder.getWorkOrderNo()); |
| | | List<Date> handleTimes = handleTimeMap.get(workOrder.getWorkOrderNo()); |
| | | //拿到审核时间 |
| | | long auditDuration = getAuditDuration(auditTimes, handleTimes); |
| | | //审核通过时间 |
| | | Date passTime = Collections.max(auditTimes); |
| | | double diffTime = (double) (passTime.getTime() - createTime.getTime() - auditDuration) / (1000 * 60 * 60); |
| | | //选择时间范围内的规则 |
| | | for (CalculateRuleVO rule : rules) { |
| | | if (checkRange(rule.getMin(), rule.getMax(), new BigDecimal(diffTime))) { |
| | |
| | | log.info("结束执行工单扣分"); |
| | | } |
| | | |
| | | private long getAuditDuration(List<Date> auditTimes, List<Date> handleTimes) { |
| | | //计算出审核的总时间(由于故障类型会更新导致可能提交的时间点数量和审核的时间点数量不一致) |
| | | long auditDuration = 0; |
| | | for (Date auditTime : auditTimes) { |
| | | //离这次审核最近的一次提交处理时间点 |
| | | Date nearestHandleTime = null; |
| | | long minDifference = Long.MAX_VALUE; |
| | | for (Date handleTime : handleTimes) { |
| | | if (handleTime.before(auditTime)) { |
| | | long difference = Math.abs(auditTime.getTime() - handleTime.getTime()); |
| | | if (difference < minDifference) { |
| | | minDifference = difference; |
| | | nearestHandleTime = handleTime; |
| | | } |
| | | } |
| | | } |
| | | auditDuration += auditTime.getTime() - nearestHandleTime.getTime(); |
| | | } |
| | | return auditDuration; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 不定期检查数据 扣除积分 |
| | | * 每天一次随机数判断成功就执行 |
| | | * 海康取人脸车辆 |
| | | */ |
| | | public void randomDeductPic() { |
| | | Random random = new Random(); |
| | | Integer num = randomSize; |
| | | //给定随机范围 |
| | | String count = sysConfigMapper.checkConfigKeyUnique("check.contract.sample").getConfigValue(); |
| | | if (!StringUtils.isEmpty(count)) { |
| | | Integer temp = Integer.valueOf(count); |
| | | if (temp > 0) { |
| | | num = temp; |
| | | } |
| | | } |
| | | int number = random.nextInt(num); |
| | | if (number == 0) { |
| | | try { |
| | | log.info("开始抽查图片完整状态"); |
| | | //这个月随机抽取一天 |
| | | // Date date = getRandomDate(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.MONTH, -1); // 上个月 |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号 |
| | | |
| | | int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | Random random = new Random(); |
| | | int randomDay = random.nextInt(lastDay) + 1; |
| | | |
| | | calendar.set(Calendar.DAY_OF_MONTH, randomDay); |
| | | Date date = calendar.getTime(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | //准备批量打分的集合 |
| | | List<ContractScore> contractScoreList = new ArrayList<>(); |
| | | //查询报备列表 |
| | | //查询报备列表 通过审核并且创建时间在当前日期的报备id列表 |
| | | List<String> reportNumbers = reportMapper.selectNumberList(AuditStatus_Pass, DateUtils.getDate()); |
| | | Date date = new Date(); |
| | | //查图片完整性规则 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> contractMap = contractMapper.getCalculateRule(new Date()).stream() |
| | | .filter(calculateRuleVO -> ContractRule.CONTRACT_RULE_PicComplete.getName().equals(calculateRuleVO.getRuleName())) |
| | |
| | | if (deduct) { |
| | | //需要扣除的分数,此规则只有一条不需要判断范围 |
| | | Double deductScore = ruleVO.getCalcFraction(); |
| | | ContractScore contractScore = getContractScore(ruleVO, deductScore, "1", Remark + "国标码为:" + serialNumber + "时间:" + new Date() + "存在大图不可用数据"); |
| | | ContractScore contractScore = getContractScore(ruleVO, deductScore, "1", Remark + "国标码为:" + serialNumber + "时间:" + format.format(date) + "存在大图不可用数据"); |
| | | contractScoreList.add(contractScore); |
| | | } |
| | | }); |
| | | } |
| | | contractScoreService.saveBatch(contractScoreList); |
| | | log.info("结束抽查图片完整状态"); |
| | | }catch (NullPointerException e) { |
| | | log.error("空指针异常,抽查图片完整状态失败: {}", e.getMessage(), e); |
| | | } catch (DataAccessException e) { |
| | | log.error("数据库访问异常,抽查图片完整状态失败: {}", e.getMessage(), e); |
| | | } catch (IllegalArgumentException e) { |
| | | log.error("参数不合法异常,抽查图片完整状态失败: {}", e.getMessage(), e); |
| | | } catch (Exception e) { |
| | | log.error("未知异常,抽查图片完整状态失败: ", e); // 注意这里使用逗号而不是+,可以打印完整堆栈 |
| | | // 如果需要可以抛出运行时异常 |
| | | throw new RuntimeException("抽查图片完整状态失败", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 不定期检查数据 扣除积分 |
| | | * 每天一次随机数判断成功就执行 |
| | | * 优云取录像 |
| | | */ |
| | | public void randomDeductVideo() { |
| | | Random random = new Random(); |
| | | //给定随机范围 |
| | | Integer num = randomSize; |
| | | //给定随机范围 |
| | | String count = sysConfigMapper.checkConfigKeyUnique("check.contract.sample").getConfigValue(); |
| | | if (!StringUtils.isEmpty(count)) { |
| | | Integer temp = Integer.valueOf(count); |
| | | if (temp > 0) { |
| | | num = temp; |
| | | } |
| | | } |
| | | int number = random.nextInt(num); |
| | | if (number == 0) { |
| | | log.info("开始抽查录像完整状态"); |
| | | //准备批量打分的集合 |
| | | List<ContractScore> contractScoreList = new ArrayList<>(); |
| | | //查询报备列表 |
| | | List<String> reportNumbers = reportMapper.selectNumberList(AuditStatus_Pass, DateUtils.getDate()); |
| | | Date date = new Date(); |
| | | //查图片完整性规则 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> contractMap = contractMapper.getCalculateRule(new Date()).stream() |
| | | .filter(calculateRuleVO -> ContractRule.CONTRACT_RULE_VideoRecord.getName().equals(calculateRuleVO.getRuleName())) |
| | | .collect(Collectors.groupingBy(CalculateRuleVO::getContractId)); |
| | | try{ |
| | | log.info("开始抽查录像完整状态"); |
| | | //这个月随机抽取一天 |
| | | Date date = getRandomDate(); |
| | | // Calendar instance = Calendar.getInstance(); |
| | | // // 设定年、月、日(注意月份从0开始,即0代表1月,11代表12月) |
| | | // instance.set(2024, 10, 1); |
| | | // Date date = instance.getTime(); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | //准备批量打分的集合 |
| | | List<ContractScore> contractScoreList = new ArrayList<>(); |
| | | //查询报备列表 |
| | | List<String> reportNumbers = reportMapper.selectNumberList(AuditStatus_Pass, DateUtils.getDate()); |
| | | //查图片完整性规则 获取key为合同id,value为规则的map |
| | | Map<Integer, List<CalculateRuleVO>> contractMap = contractMapper.getCalculateRule(new Date()).stream() |
| | | .filter(calculateRuleVO -> ContractRule.CONTRACT_RULE_VideoRecord.getName().equals(calculateRuleVO.getRuleName())) |
| | | .collect(Collectors.groupingBy(CalculateRuleVO::getContractId)); |
| | | |
| | | //取录像数据 |
| | | Query query = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(date)).lt(DateUtils.getDayEnd(date))); |
| | | List<RecordMetaDSumResult> recordMetaDSumResults = mongoTemplate.find(query, RecordMetaDSumResult.class); |
| | | List<String> serialNumbers = recordMetaDSumResults.stream().map(RecordMetaDSumResult::getDeviceId).collect(Collectors.toList()); |
| | | QueryWrapper<YwPoint> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("serial_number", serialNumbers); |
| | | //获取公司所运维的设备集合,key为unitId value为设备国标码集合 |
| | | Map<Long, List<String>> unitMonitorMap = ywPointMapper.selectList(queryWrapper).stream() |
| | | .filter(ywPoint -> ywPoint.getUnitId() != null).collect(Collectors.groupingBy(YwPoint::getUnitId, |
| | | Collectors.mapping( |
| | | YwPoint::getSerialNumber, |
| | | Collectors.toList()))); |
| | | if (!CollectionUtils.isEmpty(contractMap)) { |
| | | contractMap.forEach((contractId, ruleList) -> { |
| | | //此规则对应的unitId均相等 |
| | | CalculateRuleVO ruleVO = ruleList.get(0); |
| | | Integer unitId = ruleVO.getUnitId(); |
| | | List<String> monitorList = unitMonitorMap.get(Long.parseLong(unitId + "")); |
| | | for (RecordMetaDSumResult result : recordMetaDSumResults) { |
| | | //判断是否报备过 |
| | | if (!CollectionUtils.isEmpty(reportNumbers)) { |
| | | if (reportNumbers.contains(result.getDeviceId())) continue; |
| | | } |
| | | //判断是否是该公司运维 |
| | | if (monitorList.contains(result.getDeviceId())) { |
| | | //录像状态不完整 |
| | | if (!Objects.equals(result.getRecordStatus(), ApiConstants.UY_RecordStatus_Integrity)) { |
| | | for (CalculateRuleVO calculateRuleVO : ruleList) { |
| | | Double max = calculateRuleVO.getMax(); |
| | | Double min = calculateRuleVO.getMin(); |
| | | //判断范围在哪个区间 单位是小时转换为分钟 |
| | | if (checkRange(min, max, BigDecimal.valueOf(result.getMissDuration() * 60))) { |
| | | if (calculateRuleVO.getNum() == null) { |
| | | calculateRuleVO.setNum(1); |
| | | } else { |
| | | calculateRuleVO.setNum(calculateRuleVO.getNum() + 1); |
| | | } |
| | | //取录像数据 |
| | | Query query = new Query(Criteria |
| | | .where("mongoCreateTime").gte(DateUtils.getDayStart(date)).lt(DateUtils.getDayEnd(date))); |
| | | List<RecordMetaDSumResult> recordMetaDSumResults = mongoTemplate.find(query, RecordMetaDSumResult.class); |
| | | List<String> serialNumbers = recordMetaDSumResults.stream().map(RecordMetaDSumResult::getDeviceId).collect(Collectors.toList()); |
| | | QueryWrapper<YwPoint> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("serial_number", serialNumbers); |
| | | //获取公司所运维的设备集合,key为unitId value为设备国标码集合 |
| | | Map<Long, List<String>> unitMonitorMap = ywPointMapper.selectList(queryWrapper).stream() |
| | | .filter(ywPoint -> ywPoint.getUnitId() != null).collect(Collectors.groupingBy(YwPoint::getUnitId, |
| | | Collectors.mapping( |
| | | YwPoint::getSerialNumber, |
| | | Collectors.toList()))); |
| | | if (!CollectionUtils.isEmpty(contractMap)) { |
| | | contractMap.forEach((contractId, ruleList) -> { |
| | | //此规则对应的unitId均相等 |
| | | CalculateRuleVO ruleVO = ruleList.get(0); |
| | | Integer unitId = ruleVO.getUnitId(); |
| | | List<String> monitorList = unitMonitorMap.get(Long.parseLong(unitId + "")); |
| | | for (RecordMetaDSumResult result : recordMetaDSumResults) { |
| | | //判断是否报备过 |
| | | if (!CollectionUtils.isEmpty(reportNumbers)) { |
| | | if (reportNumbers.contains(result.getDeviceId())) continue; |
| | | } |
| | | //判断是否是该公司运维 |
| | | if (monitorList.contains(result.getDeviceId())) { |
| | | //录像状态不完整 |
| | | if (!Objects.equals(result.getRecordStatus(), ApiConstants.UY_RecordStatus_Integrity)) { |
| | | for (CalculateRuleVO calculateRuleVO : ruleList) { |
| | | Double max = calculateRuleVO.getMax(); |
| | | Double min = calculateRuleVO.getMin(); |
| | | //判断范围在哪个区间 单位是小时转换为分钟 |
| | | if (checkRange(min, max, BigDecimal.valueOf(result.getMissDuration() * 60))) { |
| | | if (calculateRuleVO.getNum() == null) { |
| | | calculateRuleVO.setNum(1); |
| | | } else { |
| | | calculateRuleVO.setNum(calculateRuleVO.getNum() + 1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | for (CalculateRuleVO calculateRuleVO : ruleList) { |
| | | if (calculateRuleVO.getNum() != null && calculateRuleVO.getNum() > 0) { |
| | | //需要扣除的分数,此规则只有一条不需要判断范围 |
| | | double deductScore = calculateRuleVO.getCalcFraction() * calculateRuleVO.getNum(); |
| | | ContractScore contractScore = getContractScore(calculateRuleVO, deductScore, calculateRuleVO.getNum() + "", Remark + calculateRuleVO.getNum() + "路设备违反规则"); |
| | | contractScoreList.add(contractScore); |
| | | } |
| | | } |
| | | for (CalculateRuleVO calculateRuleVO : ruleList) { |
| | | if (calculateRuleVO.getNum() != null && calculateRuleVO.getNum() > 0) { |
| | | //需要扣除的分数,此规则只有一条不需要判断范围 |
| | | double deductScore = calculateRuleVO.getCalcFraction() * calculateRuleVO.getNum(); |
| | | ContractScore contractScore = getContractScore(calculateRuleVO, deductScore, calculateRuleVO.getNum() + "", Remark +"抽查时间"+format.format(date)+"存在"+ calculateRuleVO.getNum() + "路设备违反规则"); |
| | | contractScoreList.add(contractScore); |
| | | } |
| | | }); |
| | | } |
| | | contractScoreService.saveBatch(contractScoreList); |
| | | log.info("结束抽查录像完整状态"); |
| | | } |
| | | }); |
| | | } |
| | | contractScoreService.saveBatch(contractScoreList); |
| | | }catch (NullPointerException e) { |
| | | log.error("空指针异常,抽查图片完整状态失败: {}", e.getMessage(), e); |
| | | } catch (DataAccessException e) { |
| | | log.error("数据库访问异常,抽查图片完整状态失败: {}", e.getMessage(), e); |
| | | } catch (IllegalArgumentException e) { |
| | | log.error("参数不合法异常,抽查图片完整状态失败: {}", e.getMessage(), e); |
| | | } catch (Exception e) { |
| | | log.error("未知异常,抽查图片完整状态失败: ", e); // 注意这里使用逗号而不是+,可以打印完整堆栈 |
| | | // 如果需要可以抛出运行时异常 |
| | | throw new RuntimeException("抽查图片完整状态失败", e); |
| | | } |
| | | } |
| | | |
| | | private Date getRandomDate() { |
| | | // 获取当前日历实例 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | |
| | | // 获取当前日期 |
| | | Date now = calendar.getTime(); |
| | | |
| | | // 设置为当前月份的第一天 |
| | | calendar.setTime(now); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | Date firstDayOfMonth = calendar.getTime(); |
| | | |
| | | // 设置为当前月份的最后一天(下个月的第一天减一) |
| | | calendar.add(Calendar.MONTH, 1); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 0); // Calendar.DAY_OF_MONTH设为0表示上个月最后一天,但这里是为了得到本月最后一天,所以先加一月 |
| | | Date lastDayOfMonth = calendar.getTime(); |
| | | log.info("最后一天" + lastDayOfMonth); |
| | | // 计算天数差(加1因为包含起始和结束日期) |
| | | long daysBetween = (lastDayOfMonth.getTime() - firstDayOfMonth.getTime()) / (1000 * 60 * 60 * 24) + 1; |
| | | |
| | | // 生成随机数 |
| | | Random random = new Random(); |
| | | int randomDayIndex = random.nextInt((int) daysBetween); |
| | | |
| | | // 获取随机日期 |
| | | calendar.setTime(firstDayOfMonth); |
| | | calendar.add(Calendar.DAY_OF_MONTH, randomDayIndex); |
| | | Date randomDate = calendar.getTime(); |
| | | return randomDate; |
| | | } |
| | | |
| | | private boolean checkRange(Double min, Double max, BigDecimal index) { |