xuhy
2025-06-17 bcdde815850289c86503c037b190ccb7f2570f68
ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
@@ -18,9 +18,7 @@
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -34,6 +32,8 @@
    private static final String PROJECT_DEPT_WEIGHT = ":PROJECT_DEPT_WEIGHT";
    // 保洁员权重标识
    private static final String CLEANER_WEIGHT = ":CLEANER_WEIGHT";
    // 重复点位标识
    private static final String REPEAT_LOCATION = ":REPEAT_LOCATION";
    @Autowired
    private RedisCache redisCache;
@@ -86,7 +86,7 @@
        // 创建任务
        list.forEach(detail -> {
            // 计算周期
            long cycle = detail.getCycle();
            int cycle = detail.getCycle();
            switch (detail.getCycleType()){
                case 2:
                    cycle = cycle * 7;
@@ -156,7 +156,7 @@
                    .in(TCleaner::getProjectId, areaIds));
            int cleanerSums = num1 * Integer.parseInt(count + "");
            // 获取每天需要抽取的保洁员数,向上取整
            int dayCleanerCount = cleanerSums / detail.getCycle();
            int dayCleanerCount = cleanerSums / cycle;
            // 获取保洁员权重
            List<String> cleanerIds = redisCache.getCacheList(detail.getId() + CLEANER_WEIGHT);
@@ -218,7 +218,26 @@
                }
            }
            // TODO 抽取重复点位
            // 抽取重复点位
            Integer currentValue = detail.getCurrentValue();
            if(currentValue != cycle){
                // 周期天数加一
                detail.setCurrentValue(currentValue + 1);
                // 获取重复点位
                Set<TLocation> repeatLocation = redisCache.getCacheSet(detail.getId() + REPEAT_LOCATION);
                if(!CollectionUtils.isEmpty(repeatLocation)){
                    List<TLocation> locations = randomSelection(new ArrayList<>(tLocationList), num3);
                    tLocationList.addAll(locations);
                }
                Set<TLocation> locationSet = new HashSet<>(tLocationList);
                redisCache.setCacheSet(detail.getId() + REPEAT_LOCATION, locationSet);
            }else {
                // 设置当前周期为0
                detail.setCurrentValue(0);
                // 将重复点位置空
                redisCache.deleteObject(detail.getId() + REPEAT_LOCATION);
            }
            // 创建任务
            List<TTask> tasks = new ArrayList<>();
@@ -242,7 +261,7 @@
                tasks.add(task);
            }
            taskCleanService.saveBatch(tasks);
            templateDetailService.updateById(detail);
        });
    }