package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.zy.asrs.domain.enums.TaskStatusType; import com.zy.asrs.domain.enums.WorkNoType; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.TaskWrk; import com.zy.asrs.service.LocMastService; import com.zy.asrs.service.TaskWrkService; import com.zy.asrs.utils.Utils; import com.zy.common.service.CommonService; import com.zy.system.entity.Config; import com.zy.system.service.ConfigService; 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 org.springframework.stereotype.Component; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.List; @Slf4j @Component public class SameLayerTransferScheduler { @Autowired private TaskWrkService taskWrkService; @Autowired private LocMastService locMastService; @Autowired private CommonService commonService; @Autowired private ConfigService configService; /** * 自动生成移库任务 * * @throws IOException */ @Scheduled(cron = "0/3 * * * * ? ") public void execute() throws IOException { Config config=configService.selectByCode("autoRemove"); if (config.getValue().equals("true")) { List taskWrks = taskWrkService.selectList(new EntityWrapper()); if (taskWrks.size() < 3) { List locMasts = locMastService.selectList(new EntityWrapper().eq("loc_sts", "F")); for (LocMast locMast : locMasts) { TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper().eq("start_point",locMast.getLocNo())); if(!Cools.isEmpty(taskWrk1)){ continue; } List list = locMastService.selectList(new EntityWrapper().eq("loc_sts", "O").eq("lev1", locMast.getLev1())); String[] locMs = new String[list.size()]; int i = 0; for (LocMast locMast1 : list) { locMs[i] = locMast1.getLocNo(); i++; } double v = Math.random() * list.size(); int m = (int) v; //目标库位 String locNo = locMs[m]; HashMap map = new HashMap<>(); Date now = new Date(); TaskWrk taskWrk = new TaskWrk(); int workNo1 = commonService.getWorkNo(WorkNoType.PAKOUT.type);//获取入库工作号 taskWrk.setTaskNo(workNo1+"");//任务号 taskWrk.setWrkNo(workNo1); taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 taskWrk.setCreateTime(now); taskWrk.setIoType(3);//任务类型 taskWrk.setIoPri(10);//优先级 taskWrk.setBarcode("123");//条码 taskWrk.setCrnNo(locMast.getCrnNo()); taskWrk.setWrkSts(1); taskWrk.setStartPoint(locMast.getLocNo());//起点 taskWrk.setTargetPoint(locNo);//重点 if (!taskWrkService.insert(taskWrk)) { } else { } break; } } } } }