fuliqi
2025-02-14 c6976365d5bfb39a32db8b541b1fe3ceb30c7826
ycl-server/src/main/java/com/ycl/task/ContractTask.java
@@ -32,6 +32,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
@@ -65,7 +66,6 @@
    private static final Integer Offline = -1;
    private static final String AuditStatus_Pass = "1";
    private static final String Remark = "系统生成";
    private static final Integer randomSize = 30;
    /**
     * 合同考核 在线率每日任务检测
@@ -362,28 +362,17 @@
    /**
     * 不定期检查数据 扣除积分
     * 每天一次随机数判断成功就执行
     * 海康取人脸车辆
     */
    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) {
            log.info("开始抽查图片完整状态");
        //这个月随机抽取一天
        Date date = getRandomDate();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            //准备批量打分的集合
            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_PicComplete.getName().equals(calculateRuleVO.getRuleName()))
@@ -428,7 +417,7 @@
                    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);
                    }
                });
@@ -436,34 +425,25 @@
            contractScoreService.saveBatch(contractScoreList);
            log.info("结束抽查图片完整状态");
        }
    }
    /**
     * 不定期检查数据 扣除积分
     * 每天一次随机数判断成功就执行
     * 优云取录像
     */
    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("开始抽查录像完整状态");
        //这个月随机抽取一天
        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());
            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()))
@@ -516,15 +496,44 @@
                        if (calculateRuleVO.getNum() != null && calculateRuleVO.getNum() > 0) {
                            //需要扣除的分数,此规则只有一条不需要判断范围
                            double deductScore = calculateRuleVO.getCalcFraction() * calculateRuleVO.getNum();
                            ContractScore contractScore = getContractScore(calculateRuleVO, deductScore, calculateRuleVO.getNum() + "", Remark + calculateRuleVO.getNum() + "路设备违反规则");
                        ContractScore contractScore = getContractScore(calculateRuleVO, deductScore, calculateRuleVO.getNum() + "", Remark +"抽查时间"+format.format(date)+"存在"+ calculateRuleVO.getNum() + "路设备违反规则");
                            contractScoreList.add(contractScore);
                        }
                    }
                });
            }
            contractScoreService.saveBatch(contractScoreList);
            log.info("结束抽查录像完整状态");
        }
    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) {