|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.constant.Constants; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.constant.StaGroupConstant; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.LocToTaskParams; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.LocStsType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.TaskResouceType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.TaskStsType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.TaskType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.impl.DeviceSiteServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.GlobalConfigCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.entity.Config; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.ConfigService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import static com.vincent.rsf.server.system.utils.SystemAuthUtils.getLoginUserId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceSiteService deviceSiteService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/9/1 | 
|---|
|  |  |  | * @description: 自动生成盘点跑库单 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | * 自动生成库位明细 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void autoCheckOrders() { | 
|---|
|  |  |  | List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).last("limit 1")); | 
|---|
|  |  |  | locs.forEach(loc -> { | 
|---|
|  |  |  | List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); | 
|---|
|  |  |  | if (!locItems.isEmpty()) { | 
|---|
|  |  |  | DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>().eq(DeviceSite::getType, TaskType.TASK_TYPE_CHECK_OUT.type), false); | 
|---|
|  |  |  | //生成盘点任务参数 | 
|---|
|  |  |  | LocToTaskParams locToTaskParams = new LocToTaskParams(); | 
|---|
|  |  |  | locToTaskParams.setType(Constants.TASK_TYPE_OUT_CHECK) | 
|---|
|  |  |  | .setItems(locItems) | 
|---|
|  |  |  | .setSiteNo(deviceSite.getSite()) | 
|---|
|  |  |  | .setOrgLoc(loc.getCode()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | locItemService.generateTask(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val, locToTaskParams, getLoginUserId()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | //    @Scheduled(cron = "0/25 * * * * ?") | 
|---|
|  |  |  | public void insertRandomMats() { | 
|---|
|  |  |  | List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)); | 
|---|
|  |  |  | for (Loc loc : list) { | 
|---|
|  |  |  | List<LocItem> items = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); | 
|---|
|  |  |  | if (!items.isEmpty()) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | List<Matnr> matnrs = matnrService.list(new LambdaQueryWrapper<Matnr>().orderByAsc(Matnr::getBarcode).last("limit 100")); | 
|---|
|  |  |  | Collections.shuffle(matnrs); | 
|---|
|  |  |  | Matnr matnr = matnrs.stream().findFirst().get(); | 
|---|
|  |  |  | LocItem locItem = new LocItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(matnr, locItem); | 
|---|
|  |  |  | locItem.setBarcode(loc.getBarcode()) | 
|---|
|  |  |  | .setLocId(loc.getId()) | 
|---|
|  |  |  | .setMatnrCode(matnr.getCode()) | 
|---|
|  |  |  | .setMaktx(matnr.getName()) | 
|---|
|  |  |  | .setMatnrId(matnr.getId()) | 
|---|
|  |  |  | .setId(null) | 
|---|
|  |  |  | .setAnfme(45.0) | 
|---|
|  |  |  | .setLocCode(loc.getCode()); | 
|---|
|  |  |  | locItemService.save(locItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    /** | 
|---|
|  |  |  | //     * @author Ryan | 
|---|
|  |  |  | //     * @date 2025/9/1 | 
|---|
|  |  |  | //     * @description: 自动生成盘点跑库单 | 
|---|
|  |  |  | //     * @version 1.0 | 
|---|
|  |  |  | //     */ | 
|---|
|  |  |  | //    @Scheduled(cron = "0/25 * * * * ?") | 
|---|
|  |  |  | //    public void autoCheckOrders() { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | 
|---|
|  |  |  | * @description: 自动完成盘点功能 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0/25 * * * * ?") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void autoCheckComplete() { | 
|---|
|  |  |  | //获取任务列表中,为盘点出库的任务 | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .in(Task::getTaskType, Arrays.asList(TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_CHECK_IN.type))); | 
|---|
|  |  |  | .in(Task::getTaskType, Arrays.asList(TaskType.TASK_TYPE_CHECK_OUT.type, | 
|---|
|  |  |  | TaskType.TASK_TYPE_PICK_IN.type, | 
|---|
|  |  |  | TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, | 
|---|
|  |  |  | TaskType.TASK_TYPE_CHECK_IN.type))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (tasks.size() >= 5) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!tasks.isEmpty()) { | 
|---|
|  |  |  | tasks.forEach(task -> { | 
|---|
|  |  |  | if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) { | 
|---|
|  |  |  | if (task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id)) { | 
|---|
|  |  |  | task.setTaskStatus(TaskStsType.COMPLETE_IN.id); | 
|---|
|  |  |  | if (!taskService.updateById(task)) { | 
|---|
|  |  |  | throw new CoolException("盘点再入库任务完成失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.getTaskStatus().equals(TaskStsType.COMPLETE_IN.id)) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //创建出库任务状态 | 
|---|
|  |  |  | if (task.getTaskStatus().equals(TaskStsType.GENERATE_OUT.id)) { | 
|---|
|  |  |  | task.setTaskStatus(TaskStsType.COMPLETE_OUT.id); | 
|---|
|  |  |  | if (!taskService.updateById(task)) { | 
|---|
|  |  |  | throw new CoolException("盘点出库任务完成失败!!"); | 
|---|
|  |  |  | if (task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id)) { | 
|---|
|  |  |  | if (!stationService.update(new LambdaUpdateWrapper<BasStation>() | 
|---|
|  |  |  | .eq(BasStation::getStationName, task.getTargSite()) | 
|---|
|  |  |  | .set(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_R.type))) { | 
|---|
|  |  |  | log.error("站点状态修改完成失败,当前任务状态:", task.getTaskStatus()); | 
|---|
|  |  |  | //                                throw new CoolException("站点状态修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //出库已完成,等待盘点中 | 
|---|
|  |  |  | } else if (task.getTaskStatus().equals(TaskStsType.WAVE_SEED.id)) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | taskService.pickOrCheckTask(task.getId(), Constants.TASK_TYPE_OUT_CHECK); | 
|---|
|  |  |  | taskService.pickOrCheckTask(task.getId(), task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type) ? Constants.TASK_TYPE_OUT_CHECK : ""); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | log.error("error====>", e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/9/1 | 
|---|
|  |  |  | * @description: 自动生成任务 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0/15 * * * * ?") | 
|---|
|  |  |  | public void genRun() { | 
|---|
|  |  |  | Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_CHECK_ORDERS)); | 
|---|
|  |  |  | if (!Boolean.parseBoolean(config.getVal())) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer maxThread = 30; | 
|---|
|  |  |  | Config confNum = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_MOVE_THEAD_MAX)); | 
|---|
|  |  |  | if (!Objects.isNull(confNum)) { | 
|---|
|  |  |  | maxThread = Integer.valueOf(confNum.getVal()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取任务列表中,为盘点出库的任务 | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .in(Task::getTaskType, Arrays.asList(TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_CHECK_IN.type))); | 
|---|
|  |  |  | if (tasks.size() >= maxThread) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String autoRunArea = configService.getVal("AUTO_RUN_AREA", String.class); | 
|---|
|  |  |  | if (Cools.isEmpty(autoRunArea)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> array = new ArrayList<>(); | 
|---|
|  |  |  | List<String> list = new ArrayList<>(); | 
|---|
|  |  |  | for (char c : autoRunArea.toCharArray()) { | 
|---|
|  |  |  | switch (c) { | 
|---|
|  |  |  | case '1': | 
|---|
|  |  |  | this.autoRun(LocGroupConstant.FAR_RIGHT_LOC_ROW_LIST, StaGroupConstant.FAR_RIGHT_STA_ROW_LIST); | 
|---|
|  |  |  | array.addAll(LocGroupConstant.FAR_RIGHT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.FAR_RIGHT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '2': | 
|---|
|  |  |  | this.autoRun(LocGroupConstant.RIGHT_LOC_ROW_LIST, StaGroupConstant.RIGHT_STA_ROW_LIST); | 
|---|
|  |  |  | array.addAll(LocGroupConstant.RIGHT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.RIGHT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '3': | 
|---|
|  |  |  | this.autoRun(LocGroupConstant.MIDDLE_LOC_ROW_LIST, StaGroupConstant.MIDDLE_STA_ROW_LIST); | 
|---|
|  |  |  | array.addAll(LocGroupConstant.MIDDLE_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.MIDDLE_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '4': | 
|---|
|  |  |  | this.autoRun(LocGroupConstant.LEFT_LOC_ROW_LIST, StaGroupConstant.LEFT_STA_ROW_LIST); | 
|---|
|  |  |  | array.addAll(LocGroupConstant.LEFT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.LEFT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '5': | 
|---|
|  |  |  | this.autoRun(LocGroupConstant.FAR_LEFT_LOC_ROW_LIST, StaGroupConstant.FAR_LEFT_STA_ROW_LIST); | 
|---|
|  |  |  | array.addAll(LocGroupConstant.FAR_LEFT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.FAR_LEFT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.autoRun(array, list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void autoRun(List<Integer> locGroupList, List<String> staGroupList) { | 
|---|
|  |  |  | List<String> staPreNos = getStaPrefixes(staGroupList); | 
|---|
|  |  |  | String staTaskMemo = "DEMO_STA_" + String.join("-", staPreNos); | 
|---|
|  |  |  | log.error("=========>"); | 
|---|
|  |  |  | log.info(staTaskMemo); | 
|---|
|  |  |  | System.out.println(staTaskMemo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getMemo, staTaskMemo)); | 
|---|
|  |  |  | if (!Cools.isEmpty(list) && list.size() > 30) { | 
|---|
|  |  |  | if (!Cools.isEmpty(list) && list.size() >= 1) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Loc> locs = getAreaLocs(locGroupList, staGroupList, staTaskMemo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Loc loc : locs) { | 
|---|
|  |  |  | List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); | 
|---|
|  |  |  | if (!locItems.isEmpty()) { | 
|---|
|  |  |  | locItems.forEach(locItem -> { | 
|---|
|  |  |  | locItem.setOutQty(locItem.getAnfme()); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | List<BasStation> stations = stationService.list(new LambdaQueryWrapper<BasStation>() | 
|---|
|  |  |  | .eq(BasStation::getStatus, 1) | 
|---|
|  |  |  | .eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)); | 
|---|
|  |  |  | List<String> stationNames = stations.stream().map(BasStation::getStationName).collect(Collectors.toList()); | 
|---|
|  |  |  | if (Cools.isEmpty(stations)) { | 
|---|
|  |  |  | throw new CoolException("无可用站点!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>() | 
|---|
|  |  |  | .in(DeviceSite::getSite, stationNames) | 
|---|
|  |  |  | .eq(DeviceSite::getType, TaskType.TASK_TYPE_CHECK_OUT.type).last("limit 1")); | 
|---|
|  |  |  | if (Cools.isEmpty(deviceSite)) { | 
|---|
|  |  |  | throw new CoolException("无可用路径!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成盘点任务参数 | 
|---|
|  |  |  | LocToTaskParams locToTaskParams = new LocToTaskParams(); | 
|---|
|  |  |  | locToTaskParams.setType(Constants.TASK_TYPE_OUT_CHECK) | 
|---|
|  |  |  | .setItems(locItems) | 
|---|
|  |  |  | .setSiteNo(deviceSite.getSite()) | 
|---|
|  |  |  | .setOrgLoc(loc.getCode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTargSite, deviceSite.getSite())); | 
|---|
|  |  |  | if (!tasks.isEmpty()) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | locItemService.generateTask(TaskResouceType.TASK_RESOUCE_CHECK_TYPE.val, locToTaskParams, getLoginUserId()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new CoolException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 入库 应该根据工作档回去 | 
|---|
|  |  |  | this.runStaToLoc(locGroupList, staGroupList, staTaskMemo); | 
|---|
|  |  |  | //        this.runStaToLoc(locGroupList, staGroupList, staTaskMemo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 出库,需要校验工作档是否存在,存在就说明站点处于忙碌状态 | 
|---|
|  |  |  | this.runLocToSta(locGroupList, staGroupList, staTaskMemo); | 
|---|
|  |  |  | // 移库 | 
|---|
|  |  |  | this.runLocToLoc(locGroupList, staTaskMemo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 入库 | 
|---|
|  |  |  | private void runStaToLoc(List<Integer> locGroupList, List<String> staGroupList, String memo) { | 
|---|
|  |  |  | Integer startRow = Collections.min(locGroupList); | 
|---|
|  |  |  | Integer endRow = Collections.max(locGroupList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // STA IDLE | 
|---|
|  |  |  | LambdaQueryWrapper<BasStation> idleWrapper = new LambdaQueryWrapper<BasStation>().eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).in(BasStation::getStationName, staGroupList); | 
|---|
|  |  |  | List<BasStation> idleList = stationService.list(idleWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(idleList)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Collections.shuffle(idleList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // LOC STOCK | 
|---|
|  |  |  | LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type); | 
|---|
|  |  |  | if (null != startRow) { | 
|---|
|  |  |  | stockWrapper.ge(Loc::getRow, startRow); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (null != endRow) { | 
|---|
|  |  |  | stockWrapper.le(Loc::getRow, endRow); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Loc> stockList = locService.list(stockWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(stockList)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Collections.shuffle(stockList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //生成入库工作档 | 
|---|
|  |  |  | generateTask(idleList.get(0).getStationName(), stockList.get(0).getCode(), idleList.get(0).getBarcode()); | 
|---|
|  |  |  | //        // 出库,需要校验工作档是否存在,存在就说明站点处于忙碌状态 | 
|---|
|  |  |  | //        this.runLocToSta(locGroupList, staGroupList, staTaskMemo); | 
|---|
|  |  |  | //        // 移库locGroupList | 
|---|
|  |  |  | //        this.runLocToLoc(locGroupList, staTaskMemo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 出库 | 
|---|
|  |  |  | private void runLocToSta(List<Integer> locGroupList, List<String> staGroupList, String memo) { | 
|---|
|  |  |  | private List<Loc> getAreaLocs(List<Integer> locGroupList, List<String> staGroupList, String memo) { | 
|---|
|  |  |  | Integer startRow = Collections.min(locGroupList); | 
|---|
|  |  |  | Integer endRow = Collections.max(locGroupList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // STA IDLE | 
|---|
|  |  |  | LambdaQueryWrapper<BasStation> idleWrapper = new LambdaQueryWrapper<BasStation>().eq(BasStation::getUseStatus, LocStsType.LOC_STS_TYPE_O.type).in(BasStation::getStationName, staGroupList); | 
|---|
|  |  |  | List<BasStation> idleList = stationService.list(idleWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(idleList)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Collections.shuffle(idleList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // LOC STOCK | 
|---|
|  |  |  | LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Loc> stockList = locService.list(stockWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(stockList)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | return new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Collections.shuffle(stockList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Loc loc = stockList.get(0); | 
|---|
|  |  |  | List<LocItem> list = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); | 
|---|
|  |  |  | LocToTaskParams param = new LocToTaskParams(); | 
|---|
|  |  |  | param.setType(Constants.TASK_TYPE_OUT_STOCK); | 
|---|
|  |  |  | param.setTarLoc(loc.getCode()); | 
|---|
|  |  |  | param.setItems(list); | 
|---|
|  |  |  | param.setSiteNo(idleList.get(0).getStationName()); | 
|---|
|  |  |  | param.setMemo(memo); | 
|---|
|  |  |  | //生成出库工作档 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | locItemService.generateTask(TaskResouceType.TASK_RESOUCE_STOCK_TYPE.val, param, getLoginUserId()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.info("生成出库任务失败", e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return stockList; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 生成移库任务 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | // 移库 | 
|---|
|  |  |  | private void runLocToLoc(List<Integer> locGroupList, String staTaskMemo) { | 
|---|
|  |  |  | @Scheduled(cron = "0/23 * * * * ?") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void runLocToLoc() { | 
|---|
|  |  |  | Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_CHECK_ORDERS)); | 
|---|
|  |  |  | if (!Boolean.parseBoolean(config.getVal())) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String autoRunArea = configService.getVal("AUTO_RUN_AREA", String.class); | 
|---|
|  |  |  | if (Cools.isEmpty(autoRunArea)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Integer> array = new ArrayList<>(); | 
|---|
|  |  |  | List<String> list = new ArrayList<>(); | 
|---|
|  |  |  | for (char c : autoRunArea.toCharArray()) { | 
|---|
|  |  |  | switch (c) { | 
|---|
|  |  |  | case '1': | 
|---|
|  |  |  | array.addAll(LocGroupConstant.FAR_RIGHT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.FAR_RIGHT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '2': | 
|---|
|  |  |  | array.addAll(LocGroupConstant.RIGHT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.RIGHT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '3': | 
|---|
|  |  |  | array.addAll(LocGroupConstant.MIDDLE_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.MIDDLE_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '4': | 
|---|
|  |  |  | array.addAll(LocGroupConstant.LEFT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.LEFT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case '5': | 
|---|
|  |  |  | array.addAll(LocGroupConstant.FAR_LEFT_LOC_ROW_LIST); | 
|---|
|  |  |  | list.addAll(StaGroupConstant.FAR_LEFT_STA_ROW_LIST); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | xx(array); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void xx(List<Integer> locGroupList) { | 
|---|
|  |  |  | Integer startRow = Collections.min(locGroupList); | 
|---|
|  |  |  | Integer endRow = Collections.max(locGroupList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String memo = "DEMO_LOC_" + startRow + "-" + endRow; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer maxThread = 30; | 
|---|
|  |  |  | Config confNum = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.AUTO_RUN_MOVE_THEAD_MAX)); | 
|---|
|  |  |  | if (!Objects.isNull(confNum)) { | 
|---|
|  |  |  | maxThread = Integer.valueOf(confNum.getVal()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .eq(Task::getMemo,memo)); | 
|---|
|  |  |  | if (!tasks.isEmpty() && tasks.size() >= maxThread) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // STOCK | 
|---|
|  |  |  | LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type); | 
|---|
|  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.info("生成出库任务失败", e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void generateTask(String sourceStaNo, String locNo, String barcode) { | 
|---|
|  |  |  | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, null); | 
|---|
|  |  |  | if (StringUtils.isBlank(ruleCode)) { | 
|---|
|  |  |  | throw new CoolException("编码错误:请确认编码「SYS_TASK_CODE」是否已生成!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Task task = new Task(); | 
|---|
|  |  |  | task.setTaskCode(ruleCode) | 
|---|
|  |  |  | .setTaskStatus(TaskStsType.GENERATE_IN.id) | 
|---|
|  |  |  | .setTaskType(TaskType.TASK_TYPE_IN.type) | 
|---|
|  |  |  | .setResource(TaskResouceType.TASK_RESOUCE_PAKIN_TYPE.val) | 
|---|
|  |  |  | .setTargLoc(locNo) | 
|---|
|  |  |  | .setBarcode(barcode) | 
|---|
|  |  |  | .setOrgSite(sourceStaNo) | 
|---|
|  |  |  | .setCreateBy(6666L) | 
|---|
|  |  |  | .setUpdateBy(6666L); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!taskService.save(task)) { | 
|---|
|  |  |  | throw new CoolException("任务保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LambdaQueryWrapper<Matnr> wrapper = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq(Matnr::getStatus, 1); | 
|---|
|  |  |  | wrapper.orderByAsc(Matnr::getUpdateTime); | 
|---|
|  |  |  | List<Matnr> list = matnrService.page(new Page<>(1, 100), wrapper).getRecords(); | 
|---|
|  |  |  | Collections.shuffle(list); | 
|---|
|  |  |  | List<TaskItem> taskItems = new ArrayList<>(); | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | for (Matnr item : list) { | 
|---|
|  |  |  | if (i > 5) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TaskItem taskItem = new TaskItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(item, taskItem); | 
|---|
|  |  |  | taskItem.setTaskId(task.getId()) | 
|---|
|  |  |  | .setOrderType(OrderType.ORDER_IN.type) | 
|---|
|  |  |  | .setCreateBy(6666L) | 
|---|
|  |  |  | .setUpdateBy(6666L) | 
|---|
|  |  |  | .setExtendFields(item.getExtendFields()); | 
|---|
|  |  |  | taskItems.add(taskItem); | 
|---|
|  |  |  | item.setUpdateTime(new Date()); | 
|---|
|  |  |  | matnrService.updateById(item); | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taskItemService.saveBatch(taskItems); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static List<String> getStaPrefixes(List<String> staGroupList) { | 
|---|
|  |  |  | Set<String> rowSet = new HashSet<>(); | 
|---|