xuhy
2025-07-01 dfc3e4b2dd3b648032d0a57688766bf9404cdda3
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;
@@ -150,13 +150,16 @@
                    .in(TProjectDept::getParentId, proIds));
            // 获取片区id
            List<String> areaIds = tProjectDeptList.stream().map(TProjectDept::getId).collect(Collectors.toList());
            if(CollectionUtils.isEmpty(areaIds)){
                return;
            }
            // 计算每天需要抽取多少个保洁员
            long count = cleanerService.count(Wrappers.lambdaQuery(TCleaner.class)
                    .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 +221,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<>();
@@ -239,10 +261,13 @@
                task.setLocationId(tLocation.getId());
                task.setImplementTime(LocalDateTime.now().plusDays(1));
                task.setTaskType(1);
                task.setTemplateId(detail.getId());
                tasks.add(task);
            }
            taskCleanService.saveBatch(tasks);
            template.setTaskCount(tasks.size());
            templateService.updateById(template);
            templateDetailService.updateById(detail);
        });
    }