| | |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.service.*; |
| | | import javafx.concurrent.Task; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | * @author xiaochen |
| | | * @date 2025/6/11 18:39 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class TaskUtil { |
| | | |
| | |
| | | |
| | | // 每一个小时执行一次 |
| | | // @Scheduled(cron = "0 0 0 * * ?") |
| | | @Scheduled(fixedRate = 1500000000) |
| | | // @Scheduled(fixedRate = 1500000000) |
| | | public void dayOfCreateInspection() { |
| | | try { |
| | | |
| | |
| | | // 创建任务 |
| | | createInspection(template); |
| | | }); |
| | | |
| | | // 查询前一天为执行的所有任务,改成已超时状态 |
| | | List<TTask> taskCleanList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) |
| | | .like(TTask::getImplementTime, LocalDate.now().minusDays(1)) |
| | | .eq(TTask::getStatus, 1)); |
| | | if (!CollectionUtils.isEmpty(taskCleanList)) { |
| | | taskCleanList.forEach(task -> { |
| | | task.setStatus(2); |
| | | }); |
| | | taskCleanService.updateBatchById(taskCleanList); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | // 通过模板id查询员工巡检员 |
| | | List<SysUser> sysUsers = sysUserService.selectUserByTempLateId(template.getId()); |
| | | // 创建任务 |
| | | list.forEach(detail -> { |
| | | for (TTemplateDetail detail : list) { |
| | | // 计算周期 |
| | | int cycle = detail.getCycle(); |
| | | switch (detail.getCycleType()){ |
| | |
| | | // 获取点位类型的占比 |
| | | String num4 = detail.getNum4(); |
| | | |
| | | SysUser sysUser = sysUsers.get(0); |
| | | // 未绑定员工 |
| | | if(CollectionUtils.isEmpty(sysUsers)){ |
| | | continue; |
| | | } |
| | | |
| | | int taskCount = 0; |
| | | for (SysUser sysUser : sysUsers) { |
| | | List<TProjectDept> projectDeptLists = new ArrayList<>(); |
| | | if(sysUser.getDeptType() == 1){ |
| | | TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId()); |
| | |
| | | } |
| | | int dayCleanerCount = cleanerSums / cycle; |
| | | |
| | | if((cycle - detail.getCurrentValue()) == 1 && cleanerSums % cycle != 0){ |
| | | if((cycle == detail.getCurrentValue()) && cleanerSums % cycle != 0){ |
| | | dayCleanerCount++; |
| | | } |
| | | |
| | |
| | | |
| | | // 抽取保洁员 |
| | | List<TCleaner> tCleaners = randomSelection(cleaners, dayCleanerCount); |
| | | if(CollectionUtils.isEmpty(tCleaners)){ |
| | | log.error("没有可抽取的保洁员,模板id为:{}",detail.getId()); |
| | | continue; |
| | | } |
| | | if(tCleaners.size() < dayCleanerCount){ |
| | | List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList()); |
| | | List<TCleaner> cleaners1 = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class) |
| | |
| | | detail.setCurrentValue(0); |
| | | // 将重复点位置空 |
| | | redisCache.deleteObject(detail.getId() + REPEAT_LOCATION); |
| | | // 将项目部权重置空 |
| | | redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT); |
| | | // 将保洁员权重置空 |
| | | redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT); |
| | | } |
| | | |
| | | // 创建任务 |
| | |
| | | templateCountService.save(templateCount); |
| | | |
| | | taskCleanService.saveBatch(tasks); |
| | | template.setTaskCount(tasks.size()); |
| | | taskCount = taskCount + tasks.size(); |
| | | } |
| | | template.setTaskCount(taskCount); |
| | | templateService.updateById(template); |
| | | templateDetailService.updateById(detail); |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |