| | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.*; |
| | | import com.zy.asrs.enums.LocStsType; |
| | | import com.zy.asrs.enums.TaskIOType; |
| | | import com.zy.asrs.mapper.BasDevpMapper; |
| | | import com.zy.asrs.mapper.BasStationMapper; |
| | | import com.zy.asrs.mapper.LocMastMapper; |
| | | import com.zy.asrs.mapper.ManLocDetlMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.asrs.utils.OrderInAndOutUtil; |
| | | import com.zy.common.constant.ApiInterfaceConstant; |
| | | import com.zy.common.constant.MesConstant; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.model.MesCombParam; |
| | | import com.zy.common.model.enums.WorkNoType; |
| | | import com.zy.common.properties.AgvProperties; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.AgvUtils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 移动端服务核心类 |
| | |
| | | private MatService matService; |
| | | @Autowired |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | |
| | | @Resource |
| | | private OrderDetlPakoutService orderDetlPakoutService; |
| | | |
| | | @Autowired |
| | | private LocCacheService locCacheService; |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Autowired |
| | | private TaskDetlService taskDetlService; |
| | | @Autowired |
| | | private BasStationService basStationService; |
| | | @Autowired |
| | | private BasContainerService basContainerService; |
| | | |
| | | @Resource |
| | | private BasStationMapper basStationMapper; |
| | | |
| | | @Resource |
| | | private BasDevpMapper basDevpMapper; |
| | | |
| | | @Resource |
| | | private AgvProperties agvProperties; |
| | | |
| | | @Autowired |
| | | private com.zy.asrs.task.handler.AgvHandler agvHandler; |
| | | |
| | | /** |
| | | * 站点轮询计数器,用于平均分配站点 |
| | | * Key: 站点组标识(如 "east" 或 "west"),Value: 当前轮询索引 |
| | | */ |
| | | private final Map<String, AtomicInteger> siteRoundRobinCounters = new ConcurrentHashMap<>(); |
| | | |
| | | @Override |
| | | public R inLocCallAgv(CallAgvParam param,Long userId) { |
| | | int type = param.getType(); |
| | | String sourceSite = param.getSourceSite(); |
| | | String barcode = param.getBarcode(); |
| | | |
| | | // 检查托盘码和暂存位编码是否相同 |
| | | if (barcode != null && sourceSite != null && barcode.trim().equals(sourceSite.trim())) { |
| | | throw new CoolException("托盘码和暂存位编码不能相同"); |
| | | } |
| | | |
| | | int ioType; |
| | | // 查询源站点(库位)信息,但不检查是否存在,允许下单成功 |
| | | // 站点不存在的检查将在定时任务(AgvHandler.callAgv)中进行 |
| | | LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>().eq("loc_no", sourceSite)); |
| | | switch (type) { |
| | | case 1: |
| | | // 判断有没有组托 |
| | | int count = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (count == 0) { |
| | | throw new CoolException("条码未组托:" + barcode); |
| | | } |
| | | ioType = 1; // AGV容器入库(实托入库) |
| | | |
| | | // 如果库位存在,更新状态为入库预约;不存在则跳过,由定时任务处理 |
| | | if (locCache != null) { |
| | | locCache.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.入库预约 |
| | | locCacheService.updateById(locCache); |
| | | } |
| | | break; |
| | | case 2: |
| | | // 判断是拣选回库托盘 |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", barcode)); |
| | | if (wrkMast == null) { |
| | | throw new CoolException("条码不存在:" + barcode); |
| | | } |
| | | if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 107) { |
| | | throw new CoolException("条码不需要回库:" + barcode); |
| | | } |
| | | ioType = wrkMast.getIoType() - 50; // 103->53(拣料入库), 107->57(盘点入库) |
| | | |
| | | // 如果库位存在,更新状态为入库预约;不存在则跳过,由定时任务处理 |
| | | if (locCache != null) { |
| | | locCache.setLocSts(LocStsType.LOC_STS_TYPE_S.type); // S.入库预约(容器回库是入库操作) |
| | | locCacheService.updateById(locCache); |
| | | } |
| | | break; |
| | | case 3: |
| | | // 判断是否为空托入库:检查条码在wms中不存在,确认为空托盘 |
| | | log.info("开始判断是否为空托入库,条码:{}", barcode); |
| | | |
| | | // 检查是否已组托 |
| | | int waitPakInCount = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (waitPakInCount != 0) { |
| | | log.warn("条码组托档已存在,不是空托盘:{}", barcode); |
| | | throw new CoolException("条码组托档已存在:" + barcode); |
| | | } |
| | | |
| | | // 检查是否有任务 |
| | | int wrkMastCount = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("barcode", barcode)); |
| | | if (wrkMastCount != 0) { |
| | | log.warn("条码任务档已存在,不是空托盘:{}", barcode); |
| | | throw new CoolException("条码任务档已存在:" + barcode); |
| | | } |
| | | |
| | | // 检查是否有库存 |
| | | int locDetlCount = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", barcode)); |
| | | if (locDetlCount != 0) { |
| | | log.warn("条码库存已存在,不是空托盘:{}", barcode); |
| | | throw new CoolException("条码库存已存在:" + barcode); |
| | | } |
| | | |
| | | // 通过所有检查,确认为空托盘,设置为空托入库 |
| | | ioType = 10; |
| | | log.info("确认为空托盘,设置为空托入库,条码:{},ioType:{}", barcode, ioType); |
| | | break; |
| | | default: |
| | | throw new CoolException("入库类型错误,type:" + type); |
| | | } |
| | | // 条码存在agv任务 |
| | | int count = taskService.selectCount(new EntityWrapper<Task>().eq("barcode", barcode).eq("is_deleted", 0)); |
| | | if (count > 0) { |
| | | throw new CoolException(barcode+ ":条码存在agv搬运任务!"); |
| | | } |
| | | |
| | | // 根据whs_type确定机器人组(站点分配完全由定时任务处理) |
| | | // 如果库位不存在,使用默认逻辑(根据type判断) |
| | | Long whsType = locCache != null ? locCache.getWhsType() : null; |
| | | String robotGroup; |
| | | |
| | | if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) { |
| | | // whs_type = 1: 入库区,使用Group-001 |
| | | robotGroup = agvProperties.getRobotGroupEast(); |
| | | log.info("库位whs_type={},使用入库区配置({})", whsType, robotGroup); |
| | | } else if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getCacheArea())) { |
| | | // whs_type = 2: 缓存区,使用Group-002 |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | log.info("库位whs_type={},使用缓存区配置({})", whsType, robotGroup); |
| | | } else { |
| | | // whs_type为空或其他值,根据type判断(兼容旧逻辑) |
| | | // 如果库位不存在,也使用此逻辑 |
| | | if (type == 1) { |
| | | robotGroup = agvProperties.getRobotGroupEast(); |
| | | } else { |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | } |
| | | if (locCache == null) { |
| | | log.warn("源站点(库位){}不存在,使用type={}的默认逻辑,机器人组:{},站点分配将在定时任务中进行", sourceSite, type, robotGroup); |
| | | } else { |
| | | log.warn("库位whs_type={}未配置或不在映射范围内,使用type={}的默认逻辑,机器人组:{}", whsType, type, robotGroup); |
| | | } |
| | | } |
| | | |
| | | // 站点分配完全由定时任务处理,此处不分配站点,只创建任务 |
| | | log.info("创建AGV任务,站点分配将在定时任务中处理,机器人组:{}", robotGroup); |
| | | |
| | | |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.PICK.type); |
| | | // 生成AGV工作号 |
| | | String agvWrkNo = AgvUtils.generateAgvWrkNo(workNo); |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | Date now = new Date(); |
| | | task.setWrkNo(workNo) |
| | | .setAgvWrkNo(agvWrkNo) // 设置AGV工作号 |
| | | .setIoTime(now) |
| | | .setWrkSts(7L) // 工作状态:11.生成出库ID |
| | | .setIoType(ioType) // 入出库状态: 1.入库 |
| | | .setTaskType("agv") |
| | | .setIoPri(10D) |
| | | .setStaNo(null) // 站点分配完全由定时任务处理 |
| | | .setSourceStaNo(sourceSite) // 设置源站点 |
| | | .setInvWh(robotGroup) // 根据whs_type设置机器人组 |
| | | .setFullPlt(ioType == 10 ? "N" : "Y")// 空托入库(ioType=10)设置为N,其他入库设置为Y(满板) |
| | | .setPicking("N") // 拣料 |
| | | .setExitMk("N")// 退出 |
| | | .setSourceLocNo(locCache != null ? locCache.getLocNo() : sourceSite) // 设置源库位编号,用于AGV fromBin,如果库位不存在则使用sourceSite |
| | | .setEmptyMk(ioType == 10 ? "Y" : "N")// 空托入库(ioType=10)设置为Y,其他设置为N |
| | | .setBarcode(barcode)// 托盘码 |
| | | .setLinkMis("N") |
| | | .setAppeTime(now) |
| | | .setModiTime(now); |
| | | if (!taskService.insert(task)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | // 如果库位存在,根据ioType更新暂存位状态:入库任务设置为S(入库预约),出库任务设置为R(出库预约) |
| | | if (locCache != null) { |
| | | String locSts = (ioType < 100) ? "S" : "R"; // 入库任务(ioType < 100)设置为S,出库任务设置为R |
| | | basStationMapper.updateLocStsBatch( Collections.singletonList(String.valueOf(sourceSite)), locSts); |
| | | } |
| | | return R.ok("agv任务生成成功!"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public R WarehouseOutPickMergeV1(WarehouseOutPickMergeParam param, Long hostId, Long userId) { |
| | |
| | | wrkMast.setIoType(8); // 入出库状态:8.拣料途中并板 |
| | | wrkMast.setIoPri(13D); // 优先级 |
| | | wrkMast.setCrnNo(1); |
| | | wrkMast.setSourceStaNo(1); |
| | | wrkMast.setStaNo(1); |
| | | wrkMast.setSourceStaNo(1 + ""); |
| | | wrkMast.setStaNo(1 + ""); |
| | | wrkMast.setLocNo(param.getLocNo()); |
| | | wrkMast.setBarcode(param.getBarcode()); // 托盘码 |
| | | wrkMast.setFullPlt("Y"); // 满板:Y |
| | |
| | | wrkMast.setWrkSts(11L); // 工作状态:101.生成出库 |
| | | wrkMast.setIoType(104); // 入出库状态 |
| | | wrkMast.setIoPri(13D); // 优先级:13 |
| | | wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 |
| | | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 |
| | | wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站 |
| | | wrkMast.setStaNo(staDesc.getStnNo() + ""); // 目标站 |
| | | wrkMast.setSourceLocNo(param.getLocNo()); // 源库位 |
| | | wrkMast.setFullPlt("Y"); // 满板:Y |
| | | wrkMast.setPicking("Y"); // 拣料 |
| | |
| | | continue; |
| | | } |
| | | if (orderPakout.getSettle() == 1) { |
| | | OrderInAndOutUtil.updateOrder(false, orderPakout.getId(), 2L, 9527L); |
| | | orderPakoutService.updateSettle(orderPakout.getId(), 2L, 9527L); |
| | | } |
| | | OrderDetlPakout orderDetlPakout = orderDetlPakoutService.selectItem(orderPakout.getId(), combMat.getMatnr(), combMat.getBatch(), |
| | | combMat.getBrand(), combMat.getStandby1(), combMat.getStandby2(), combMat.getStandby3(), combMat.getBoxType1(), combMat.getBoxType2(), combMat.getBoxType3()); |
| | |
| | | wrkMast.setIoType(108); // 入出库状态:出库,拣料入库 |
| | | wrkMast.setIoPri(13D); // 优先级 |
| | | wrkMast.setCrnNo(1); |
| | | wrkMast.setSourceStaNo(1); |
| | | wrkMast.setStaNo(1); |
| | | wrkMast.setSourceStaNo(1 + ""); |
| | | wrkMast.setStaNo(1 + ""); |
| | | wrkMast.setSourceLocNo(combParam.getLocNo()); |
| | | wrkMast.setBarcode(combParam.getBarcode()); // 托盘码 |
| | | wrkMast.setFullPlt("Y"); // 满板:Y |
| | |
| | | typeList.add(docType.getDocId()); |
| | | } |
| | | |
| | | Wrapper<Order> wrapper = new EntityWrapper<>(); |
| | | Wrapper<OrderPakin> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("status", 1); |
| | | wrapper.in("doc_type", typeList); |
| | | List<Order> orders = orderService.selectList(wrapper); |
| | | List<OrderPakin> orders = orderPakinService.selectList(wrapper); |
| | | |
| | | ArrayList<Long> orderIds = new ArrayList<>(); |
| | | for (Order order : orders) { |
| | | for (OrderPakin order : orders) { |
| | | orderIds.add(order.getId()); |
| | | } |
| | | |
| | | //搜索明细 |
| | | Wrapper<OrderDetl> wrapper1 = new EntityWrapper<>(); |
| | | Wrapper<OrderDetlPakin> wrapper1 = new EntityWrapper<>(); |
| | | wrapper1.eq("status", 1); |
| | | wrapper1.in("order_id", orderIds); |
| | | wrapper1.orderBy("create_time", false); |
| | |
| | | if (!Cools.isEmpty(orderNo)) { |
| | | wrapper1.like("order_no", orderNo); |
| | | } |
| | | List<OrderDetl> list = orderDetlService.selectList(wrapper1); |
| | | List<OrderDetlPakin> list = orderDetlPakinService.selectList(wrapper1); |
| | | |
| | | ArrayList<PickMatParam> maps = new ArrayList<>(); |
| | | for (OrderDetl orderDetl : list) { |
| | | for (OrderDetlPakin orderDetl : list) { |
| | | //剩余可用数量 |
| | | double count = orderDetl.getAnfme() - orderDetl.getWorkQty(); |
| | | if (count <= 0) { |
| | |
| | | if (Cools.isEmpty(param.getBarcode(), param.getCombMats())) { |
| | | throw new CoolException(BaseRes.PARAM); |
| | | } |
| | | if (param.getCombMats().size() > 1) { |
| | | if (param.getCombMats().size() < 1) { |
| | | throw new CoolException("请提取一个商品,或者刷新重新组托!"); |
| | | } |
| | | // 判断是否有相同条码的数据 |
| | | if (waitPakinService.selectCount(new EntityWrapper<WaitPakin>(). |
| | | eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) { |
| | | eq("zpallet", param.getBarcode()) |
| | | .eq("io_status", "N")) > 0) { |
| | | throw new CoolException(param.getBarcode() + "数据正在进行入库"); |
| | | } |
| | | |
| | | if (param.getBarcode().length() != 8) { |
| | | throw new CoolException("条码长度不是8位===>>" + param.getBarcode()); |
| | | } |
| | | if (param.getCombMats().size() > 1) { |
| | | throw new CoolException("不允许混料===>>" + param.getBarcode()); |
| | | } |
| | | |
| | | int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet", param.getBarcode())); |
| | |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | |
| | | // 无单组托 |
| | | if (Cools.isEmpty(param.getOrderNo())) { |
| | | |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | |
| | | } |
| | | }); |
| | | |
| | | |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | // if (mat.getUpQty().compareTo(detlDto.getAnfme()) < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + "单次最大组托上限为:" + mat.getUpQty()); |
| | | // } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | BeanUtils.copyProperties(mat, waitPakin); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | | waitPakin.setAnfme(detlDto.getAnfme()); // 数量 |
| | | waitPakin.setStatus("Y"); // 状态 |
| | | waitPakin.setZpallet(param.getBarcode()); |
| | | waitPakin.setIoStatus("N"); |
| | | waitPakin.setAnfme(detlDto.getAnfme()); |
| | | waitPakin.setStatus("Y"); |
| | | waitPakin.setAppeUser(userId); |
| | | waitPakin.setAppeTime(now); |
| | | waitPakin.setModiUser(userId); |
| | |
| | | } |
| | | // 关联组托 |
| | | } else { |
| | | // Order order = orderService.selectByNo(param.getOrderNo()); |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo()); |
| | | if (Cools.isEmpty(order) || order.getSettle() > 2) { |
| | | throw new CoolException("单据编号已过期"); |
| | | } |
| | | // 生成入库通知档 |
| | | List<DetlDto> detlDtos = new ArrayList<>(); |
| | | param.getCombMats().forEach(elem -> { |
| | | |
| | | // 订单明细数量校验 |
| | | // OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), elem.getMatnr(), elem.getBatch()); |
| | | OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3()); |
| | | if (elem.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | OrderPakin order = orderPakinService.selectByNo(elem.getOrderNo()); |
| | | if (Cools.isEmpty(order) || order.getSettle() > 2) { |
| | | throw new CoolException("单据正在作业中"); |
| | | } |
| | | // 修改订单作业数量 |
| | | // if (!orderDetlService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getAnfme())) { |
| | | // throw new CoolException("修改单据作业数量失败"); |
| | | // } |
| | | OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | // 订单明细数量校验 |
| | | OrderDetlPakin detls = orderDetlPakinService.selectOne(new EntityWrapper<OrderDetlPakin>() |
| | | .eq("order_id", order.getId()) |
| | | .eq("matnr", elem.getMatnr())); |
| | | |
| | | if (Objects.isNull(detls)) { |
| | | throw new CoolException("数据错误:单据明细不存在!!"); |
| | | } |
| | | |
| | | if (elem.getAnfme() > detls.getEnableQty()) { |
| | | throw new CoolException(detls.getMatnr() + "入库数量不合法"); |
| | | } |
| | | orderDetlPakinService.increaseWorkQty(order.getId(), elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); |
| | | DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getBrand(), elem.getStandby1(), elem.getStandby2(), elem.getStandby3(), |
| | | elem.getBoxType1(), elem.getBoxType2(), elem.getBoxType3(), elem.getAnfme()); |
| | | detlDto.setOrderId(order.getId()); |
| | | detlDto.setOrderNo(order.getOrderNo()); |
| | | if (DetlDto.has(detlDtos, detlDto)) { |
| | | DetlDto one = DetlDto.findDto(detlDtos, detlDto); |
| | | assert one != null; |
| | |
| | | detlDtos.add(detlDto); |
| | | } |
| | | }); |
| | | |
| | | // BasContainer container = basContainerService.selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode())); |
| | | // if (Objects.isNull(container)) { |
| | | // throw new CoolException("数据错误:容器码不存在!!"); |
| | | // } |
| | | // if (container.getMixMax() < detlDtos.size()) { |
| | | // throw new CoolException("超出容器最大混装数量,当前容器最大数量为:" + container.getMixMax() + "!!"); |
| | | // } |
| | | // Set<String> matnrs = detlDtos.stream().map(DetlDto::getMatnr).collect(Collectors.toSet()); |
| | | // List<Mat> mats = matService.selectList(new EntityWrapper<Mat>().in("matnr", matnrs)); |
| | | // Set<Long> tagIds = mats.stream().map(Mat::getTagId).collect(Collectors.toSet()); |
| | | // if (tagIds.size() > 1) { |
| | | // throw new CoolException("组托物料类型不一致,只有相同的物料分类才可以组托!!"); |
| | | // } |
| | | // //还可以放入多少种物料 |
| | | // Integer suplus = container.getMixMax(); |
| | | for (DetlDto detlDto : detlDtos) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | // //最多可放数量 |
| | | // Double singleMax = mat.getUpQty() * suplus; |
| | | // if (singleMax.compareTo(detlDto.getAnfme()) < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + "单次组托上限为:" + mat.getUpQty() + ",当前总量超出托盘装载上限!!"); |
| | | // } |
| | | // BigDecimal decimal = new BigDecimal(detlDto.getAnfme() / mat.getUpQty()); |
| | | // //当前物料需要占用料箱格数 |
| | | // Integer curr = decimal.setScale(0, RoundingMode.CEILING).intValue(); |
| | | // suplus = suplus - curr; |
| | | // if (suplus < 0) { |
| | | // throw new CoolException("物料:" + detlDto.getMatnr() + ", 超出当前托盘装载上限!!"); |
| | | // } |
| | | |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(order.getOrderNo()); // 单据编号 |
| | | BeanUtils.copyProperties(mat, waitPakin); |
| | | // waitPakin.sync(mat); |
| | | waitPakin.setOrderNo(detlDto.getOrderNo()); // 单据编号 |
| | | waitPakin.setOrderId(detlDto.getOrderId()); |
| | | waitPakin.setBatch(detlDto.getBatch()); // 序列码 |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | | waitPakin.setIoStatus("N"); // 入出状态 |
| | |
| | | throw new CoolException("保存入库通知档失败"); |
| | | } |
| | | } |
| | | // orderService.updateSettle(order.getId(), 2L, userId); |
| | | OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId); |
| | | |
| | | Set<String> stringSet = param.getCombMats().stream().map(CombParam.CombMat::getOrderNo).collect(Collectors.toSet()); |
| | | stringSet.forEach(orderNo -> { |
| | | OrderPakin order = orderPakinService.selectByNo(orderNo); |
| | | orderPakinService.updateSettle(order.getId(), 2L, userId); |
| | | }); |
| | | } |
| | | |
| | | } |
| | |
| | | boolean success = false; |
| | | try { |
| | | response = new HttpHandler.Builder() |
| | | .setUri(MesConstant.URL) |
| | | .setUri(MesConstant.URI) |
| | | .setPath(MesConstant.PACK_DOWN_URL) |
| | | .setJson(JSON.toJSONString(mesCombParam)) |
| | | .build() |
| | |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | success = true; |
| | | } else if (jsonObject.getInteger("code").equals(500)) { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | throw new CoolException(jsonObject.getString("msg")); |
| | | } else { |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URL + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | log.error("请求接口失败!!!url:{};request:{};response:{}", MesConstant.URI + MesConstant.PACK_DOWN_URL, JSON.toJSONString(mesCombParam), response); |
| | | throw new CoolException("上报mes系统失败"); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | "打包下线帮托上报", |
| | | MesConstant.URL + MesConstant.PACK_DOWN_URL, |
| | | MesConstant.URI + MesConstant.PACK_DOWN_URL, |
| | | null, |
| | | "127.0.0.1", |
| | | JSON.toJSONString(mesCombParam), |
| | |
| | | openParam.setOrderType("打包入库单"); |
| | | openParam.setOrderDetails(detlDtos); |
| | | openService.pakinOrderCreate(openParam); |
| | | // Order order = orderService.selectByNo(orderNo); |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.TRUE, param.getOrderNo()); |
| | | OrderPakin order = orderPakinService.selectByNo(param.getOrderNo()); |
| | | |
| | | if (null == order) { |
| | | throw new CoolException("生成单据失败"); |
| | | } |
| | | // if (!orderService.updateSettle(order.getId(), 2L, userId)) { |
| | | // throw new CoolException("修改单据状态失败"); |
| | | // } |
| | | OrderInAndOutUtil.updateOrder(Boolean.TRUE, order.getId(), 2L, userId); |
| | | |
| | | if (!orderPakinService.updateSettle(order.getId(), 2L, userId)) { |
| | | throw new CoolException("修改单据状态失败"); |
| | | } |
| | | // 生成入库通知档 |
| | | for (DetlDto detlDto : detlDtos) { |
| | | |
| | | // 修改作业数量 ---------------------------------------- |
| | | // 订单明细数量校验 |
| | | // OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch()); |
| | | OrderDetl orderDetl = OrderInAndOutUtil.selectItem(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | OrderDetlPakin orderDetlPakin = orderDetlPakinService.selectItem(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3()); |
| | | if (detlDto.getAnfme() > orderDetl.getEnableQty()) { |
| | | throw new CoolException(orderDetl.getMatnr() + "入库数量不合法"); |
| | | if (detlDto.getAnfme() > orderDetlPakin.getEnableQty()) { |
| | | throw new CoolException(orderDetlPakin.getMatnr() + "入库数量不合法"); |
| | | } |
| | | // 修改订单作业数量 |
| | | // if (!orderDetlService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getAnfme())) { |
| | | // throw new CoolException("修改单据作业数量失败"); |
| | | // } |
| | | OrderInAndOutUtil.increaseWorkQty(Boolean.TRUE, order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme()); |
| | | if (!orderDetlPakinService.increaseWorkQty(order.getId(), detlDto.getMatnr(), detlDto.getBatch(), detlDto.getBrand(), detlDto.getStandby1(), detlDto.getStandby2(), detlDto.getStandby3() |
| | | , detlDto.getBoxType1(), detlDto.getBoxType2(), detlDto.getBoxType3(), detlDto.getAnfme())) { |
| | | throw new CoolException("修改单据作业数量失败"); |
| | | } |
| | | // 保存入库通知档 |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "商品档案不存在"); |
| | | } |
| | | WaitPakin waitPakin = new WaitPakin(); |
| | | waitPakin.sync(mat); |
| | | BeanUtils.copyProperties(mat, waitPakin); |
| | | waitPakin.setOrderNo(orderNo); |
| | | waitPakin.setBatch(detlDto.getBatch()); |
| | | waitPakin.setZpallet(param.getBarcode()); // 托盘码 |
| | |
| | | |
| | | BasDevp sta = basDevpService.checkSiteStatus(staNo); |
| | | //根据订单号生成出库任务工作档 |
| | | Order order = OrderInAndOutUtil.selectByNo(Boolean.FALSE, orderNo); |
| | | // Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo)); |
| | | OrderPakout order = orderPakoutService.selectOne(new EntityWrapper<OrderPakout>().eq("order_no", orderNo)); |
| | | if (order.getSettle() != 1 && order.getSettle() != 2) { |
| | | throw new CoolException("该订单已处理"); |
| | | } |
| | | |
| | | // List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); |
| | | List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(Boolean.FALSE, order.getId()); |
| | | List<OrderDetlPakout> orderDetls = orderDetlPakoutService.selectByOrderId(order.getId()); |
| | | |
| | | Date now = new Date(); |
| | | for (OrderDetl orderDetl : orderDetls) { |
| | | for (OrderDetlPakout orderDetl : orderDetls) { |
| | | //查询所有库位状态为F的库位信息 |
| | | List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(), orderDetl.getBatch(), null, null); |
| | | if (locDetls.size() == 0) { |
| | |
| | | order.setSettle(2L); |
| | | order.setUpdateBy(userId); |
| | | order.setUpdateTime(now); |
| | | // if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){ |
| | | // throw new CoolException("更新订单状态失败"); |
| | | // } |
| | | OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(), order.getId(), 2L, userId); |
| | | if (!orderPakoutService.update(order, new EntityWrapper<OrderPakout>().eq("order_no", orderNo))) { |
| | | throw new CoolException("更新订单状态失败"); |
| | | } |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty); |
| | | orderDetl.setUpdateBy(userId); |
| | | orderDetl.setUpdateTime(now); |
| | |
| | | if (!Cools.isEmpty(orderDetl.getBatch())) { |
| | | wrapper.eq("batch", orderDetl.getBatch()); |
| | | } |
| | | // if(!orderDetlService.update(orderDetl, wrapper)){ |
| | | // throw new CoolException("更新订单明细失败"); |
| | | // } |
| | | OrderInAndOutUtil.updateOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl); |
| | | if (!orderDetlPakoutService.update(orderDetl, wrapper)) { |
| | | throw new CoolException("更新订单明细失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl, |
| | | public void stockOut(OrderDetlPakout orderDetl, BasDevp staNo, LocDetl locDetl, |
| | | Double curOutQty, Integer ioType, Long userId, Date now) { |
| | | // 获取库位 |
| | | LocMast locMast = locMastService.selectById(locDetl.getLocNo()); |
| | |
| | | wrkMast.setIoType(ioType); // 入出库状态 |
| | | wrkMast.setIoPri(13D); // 优先级:13 |
| | | wrkMast.setCrnNo(locMast.getCrnNo()); |
| | | wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站 |
| | | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 |
| | | wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站 |
| | | wrkMast.setStaNo(staDesc.getStnNo() + ""); // 目标站 |
| | | wrkMast.setSourceLocNo(locDetl.getLocNo()); // 源库位 |
| | | wrkMast.setFullPlt("Y"); // 满板:Y |
| | | wrkMast.setPicking("N"); // 拣料 |
| | |
| | | throw new CoolException(locDetl.getLocNo() + "库位不是在库状态"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/9/22 |
| | | * @description: 获取缓冲区库位信息 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public R getCacheLocs() { |
| | | return R.ok().add(locCacheService.selectList(new EntityWrapper<LocCache>() |
| | | .eq("frozen", 0) |
| | | .ne("full_plt", "Y") |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type).orderAsc(Arrays.asList("row1")))); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/9/22 |
| | | * @description: 呼叫AGV搬运 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public R callAgvMove(AgvCallParams params, Long userId) { |
| | | if (Objects.isNull(params.getOrgSite())) { |
| | | throw new CoolException("源站点不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getBarcode())) { |
| | | throw new CoolException("托盘码不能为空!!"); |
| | | } |
| | | |
| | | String callType = params.getCallType(); |
| | | if (callType == null || callType.isEmpty()) { |
| | | callType = "manual"; // 默认手动输入 |
| | | } |
| | | |
| | | if ("manual".equals(callType)) { |
| | | // 手动输入:需要目标站点 |
| | | if (Objects.isNull(params.getTarSite())) { |
| | | throw new CoolException("手动输入模式下,目标站点不能为空!!"); |
| | | } |
| | | LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>() |
| | | .eq("frozen", 0) |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type) |
| | | .eq("loc_no", params.getTarSite()) |
| | | .orderAsc(Arrays.asList("loc_no")) |
| | | .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")); |
| | | if (Objects.isNull(locCache)) { |
| | | throw new CoolException("请检查目标库位是否闲置中!!"); |
| | | } |
| | | generateAgvTask("agv", locCache, params.getOrgSite(), params.getBarcode(), userId); |
| | | } else if ("outbound".equals(callType)) { |
| | | // 起点+出库:自动分配站点和缓存位 |
| | | generateOutboundAgvTask(params.getOrgSite(), params.getBarcode(), userId); |
| | | } else if ("inbound".equals(callType)) { |
| | | // 起点+入库:自动分配站点,库位手动输入 |
| | | if (Objects.isNull(params.getTarLoc())) { |
| | | throw new CoolException("入库模式下,目标库位不能为空!!"); |
| | | } |
| | | LocCache locCache = locCacheService.selectOne(new EntityWrapper<LocCache>() |
| | | .eq("frozen", 0) |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type) |
| | | .eq("loc_no", params.getTarLoc()) |
| | | .orderAsc(Arrays.asList("loc_no")) |
| | | .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")); |
| | | if (Objects.isNull(locCache)) { |
| | | throw new CoolException("请检查目标库位是否闲置中!!"); |
| | | } |
| | | generateInboundAgvTask(locCache, params.getOrgSite(), params.getBarcode(), userId); |
| | | } else { |
| | | throw new CoolException("不支持的呼叫类型:" + callType); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/9/24 |
| | | * @description: 获取订单物料信息 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public R getMatsByQRcode(PakinMatsByQRParams params) { |
| | | if (Objects.isNull(params)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(params.getOrderNo())) { |
| | | throw new CoolException("单号不能为空!!"); |
| | | } |
| | | OrderPakin orderPakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>().eq("order_no", params.getOrderNo())); |
| | | if (Objects.isNull(orderPakin)) { |
| | | throw new CoolException("数据错误:单据不存在!!"); |
| | | } |
| | | List<OrderDetlPakin> detlPakins = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>() |
| | | .eq(!Cools.isEmpty(params.getMatnr()), "matnr", params.getMatnr()) |
| | | .eq("order_id", orderPakin.getId())); |
| | | if (Objects.isNull(detlPakins) || detlPakins.isEmpty()) { |
| | | throw new CoolException("数据错误: 单据明细不存在!!"); |
| | | } |
| | | |
| | | return R.ok().add(detlPakins); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/9/24 |
| | | * @description: AGV呼叫搬运 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | public R OutCallAgv(AgvCallParams params, Long userId) { |
| | | LocCache locCaches = locCacheService.selectOne(new EntityWrapper<LocCache>() |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_F.type) |
| | | .eq("frozen", 0) |
| | | .orderDesc(Arrays.asList("sort", "first_time")) |
| | | .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")); |
| | | if (Objects.isNull(locCaches)) { |
| | | throw new CoolException("暂无满足需求库位!"); |
| | | } |
| | | BasStation station = basStationService.selectOne(new EntityWrapper<BasStation>() |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type) |
| | | .eq("dev_no", params.getTarSite())); |
| | | if (Objects.isNull(station)) { |
| | | throw new CoolException("站点正在执行任务!!"); |
| | | } |
| | | |
| | | generateOutTask(station, locCaches, userId); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/9/25 |
| | | * @description: 呼叫AGV生成出库任务 |
| | | * @version 1.0 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generateOutTask(BasStation station, LocCache loc, Long userId) { |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.PICK.type); |
| | | // 生成AGV工作号 |
| | | String agvWrkNo = AgvUtils.generateAgvWrkNo(workNo); |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | task.setWrkNo(workNo) |
| | | .setAgvWrkNo(agvWrkNo) |
| | | .setIoTime(new Date()) |
| | | .setWrkSts(11L) // 工作状态:11.生成出库ID |
| | | .setIoType(101) // 入出库状态: 11.库格移载 |
| | | .setTaskType("agv") |
| | | .setIoPri(10D) |
| | | .setFullPlt("Y") // 满板:Y |
| | | .setPicking("N") // 拣料 |
| | | .setExitMk("N")// 退出 |
| | | .setStaNo(station.getDevNo()) |
| | | .setSourceLocNo(loc.getLocNo()) |
| | | .setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N")// 空板 |
| | | .setBarcode(loc.getBarcode())// 托盘码 |
| | | .setLinkMis("N") |
| | | .setAppeUser(userId) |
| | | .setAppeTime(new Date()) |
| | | .setModiUser(userId) |
| | | .setModiTime(new Date()); |
| | | if (!taskService.insert(task)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | List<LocDetl> detls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_id", loc.getId())); |
| | | if (Objects.isNull(detls) || detls.isEmpty()) { |
| | | throw new CoolException("数据错误:库位明细为空!!"); |
| | | } |
| | | List<TaskDetl> taskDetls = new ArrayList<>(); |
| | | detls.forEach(pakin -> { |
| | | TaskDetl wrkDetl = new TaskDetl(); |
| | | BeanUtils.copyProperties(pakin, wrkDetl); |
| | | wrkDetl.setWrkNo(workNo) |
| | | .setIoTime(new Date()) |
| | | .setOrderNo(pakin.getOrderNo()) |
| | | .setAnfme(pakin.getAnfme()) |
| | | .setZpallet(pakin.getZpallet()) |
| | | .setBatch(pakin.getBatch()) |
| | | .setMatnr(pakin.getMatnr()) |
| | | .setMaktx(pakin.getMaktx()) |
| | | .setAppeUser(userId) |
| | | .setUnit(pakin.getUnit()) |
| | | .setModel(pakin.getModel()) |
| | | .setAppeTime(new Date()) |
| | | .setModiUser(userId); |
| | | taskDetls.add(wrkDetl); |
| | | }); |
| | | |
| | | //保存工作档明细 |
| | | if (!taskDetlService.insertBatch(taskDetls)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | |
| | | loc.setLocSts(LocStsType.LOC_STS_TYPE_R.type); |
| | | loc.setModiUser(userId); |
| | | loc.setModiTime(new Date()); |
| | | |
| | | if (!locCacheService.updateById(loc)) { |
| | | throw new CoolException("更新库位状态信息!!"); |
| | | } |
| | | |
| | | // 修改目标站点信息 |
| | | if (station.getLocSts().equals("O")) { |
| | | station.setLocSts("S"); // S.入库预约 |
| | | station.setModiTime(new Date()); |
| | | station.setModiUser(userId); |
| | | if (!basStationService.updateById(station)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败,目标库位状态:" + station.getLocSts()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/9/22 |
| | | * @description: 生成AGV搬运任务 |
| | | * @version 1.0 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generateAgvTask(String type, LocCache loc, String orgSite, String barcode, Long userId) { |
| | | List<WaitPakin> pakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (Objects.isNull(pakins) || pakins.isEmpty()) { |
| | | throw new CoolException("组托信息不存在!!"); |
| | | } |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.PICK.type); |
| | | // 生成AGV工作号 |
| | | String agvWrkNo = AgvUtils.generateAgvWrkNo(workNo); |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | Date now = new Date(); |
| | | task.setWrkNo(workNo) |
| | | .setAgvWrkNo(agvWrkNo) // 设置AGV工作号 |
| | | .setIoTime(now) |
| | | .setWrkSts(7L) // 工作状态:7.待呼叫AGV(与自动创建保持一致,由定时任务分配站点并呼叫) |
| | | .setIoType(1) // 入出库状态: 11.库格移载 |
| | | .setTaskType("agv") |
| | | .setIoPri(10D) |
| | | .setLocNo(loc.getLocNo()) // 目标库位 |
| | | .setStaNo(null) // 站点分配由定时任务处理(与自动创建保持一致) |
| | | .setFullPlt("Y") // 满板:Y |
| | | .setPicking("N") // 拣料 |
| | | .setExitMk("N")// 退出 |
| | | .setSourceStaNo(orgSite) |
| | | .setEmptyMk(loc.getLocSts().equals("D") ? "Y" : "N")// 空板 |
| | | .setBarcode(barcode)// 托盘码 |
| | | .setLinkMis("N") |
| | | .setAppeUser(userId) |
| | | .setAppeTime(now) |
| | | .setModiUser(userId) |
| | | .setModiTime(now); |
| | | if (!taskService.insert(task)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | List<TaskDetl> taskDetls = new ArrayList<>(); |
| | | pakins.forEach(pakin -> { |
| | | TaskDetl wrkDetl = new TaskDetl(); |
| | | BeanUtils.copyProperties(pakin, wrkDetl); |
| | | wrkDetl.setWrkNo(workNo) |
| | | .setIoTime(new Date()) |
| | | .setOrderNo(pakin.getOrderNo()) |
| | | .setAnfme(pakin.getAnfme()) |
| | | .setZpallet(pakin.getZpallet()) |
| | | .setBatch(pakin.getBatch()) |
| | | .setMatnr(pakin.getMatnr()) |
| | | .setMaktx(pakin.getMaktx()) |
| | | .setAppeUser(userId) |
| | | .setUnit(pakin.getUnit()) |
| | | .setModel(pakin.getModel()) |
| | | .setAppeTime(new Date()) |
| | | .setModiUser(userId); |
| | | taskDetls.add(wrkDetl); |
| | | }); |
| | | |
| | | //保存工作档明细 |
| | | if (!taskDetlService.insertBatch(taskDetls)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | // 修改目标库位状态 |
| | | if (loc.getLocSts().equals("O")) { |
| | | loc.setLocSts("S"); // S.入库预约 |
| | | loc.setModiTime(new Date()); |
| | | loc.setModiUser(userId); |
| | | if (!locCacheService.updateById(loc)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败,目标库位状态:" + loc.getLocSts$()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成出库AGV任务(起点+出库,自动分配站点和缓存位) |
| | | * @param orgSite 源站点 |
| | | * @param barcode 托盘码 |
| | | * @param userId 用户ID |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generateOutboundAgvTask(String orgSite, String barcode, Long userId) { |
| | | // 根据源站点判断是东侧还是西侧,确定缓存区站点和whs_type |
| | | List<String> eastStations = agvProperties.getEastStations(); |
| | | List<String> westStations = agvProperties.getWestStations(); |
| | | List<String> cacheStations; |
| | | Long targetWhsType; |
| | | String robotGroup; |
| | | String cacheAreaPrefix = agvProperties.getLocationPrefix().getCacheArea(); |
| | | boolean isEmptyPallet = false; // 默认满板出库,可根据需要调整 |
| | | |
| | | if (eastStations.contains(orgSite)) { |
| | | // 东侧出库站点,查找东侧WA库位(whs_type=1) |
| | | cacheStations = agvProperties.getEastStations(); |
| | | robotGroup = agvProperties.getRobotGroupEast(); |
| | | targetWhsType = agvProperties.getWhsTypeMapping().getInboundArea(); // whs_type=1 |
| | | } else if (westStations.contains(orgSite)) { |
| | | // 西侧出库站点,查找西侧WA库位(whs_type=2) |
| | | cacheStations = agvProperties.getWestStations(); |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | targetWhsType = agvProperties.getWhsTypeMapping().getCacheArea(); // whs_type=2 |
| | | } else { |
| | | // 默认使用西侧 |
| | | cacheStations = agvProperties.getWestStations(); |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | targetWhsType = agvProperties.getWhsTypeMapping().getCacheArea(); |
| | | log.warn("源站点{}不在配置的站点列表中,使用默认西侧配置", orgSite); |
| | | } |
| | | |
| | | // 自动分配缓存位(使用优先级分配逻辑) |
| | | LocCache locCache = allocateCacheLocationByPriority(targetWhsType, cacheAreaPrefix, isEmptyPallet); |
| | | if (Objects.isNull(locCache)) { |
| | | throw new CoolException("暂无满足需求的缓存位!"); |
| | | } |
| | | |
| | | // 自动分配站点(使用出库到缓存区的分配策略) |
| | | String allocatedSite = allocateCacheStationForOutbound(cacheStations, 101); |
| | | if (allocatedSite == null) { |
| | | throw new CoolException("无法分配缓存区站点,所有站点都在使用中!"); |
| | | } |
| | | |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.PICK.type); |
| | | // 生成AGV工作号 |
| | | String agvWrkNo = AgvUtils.generateAgvWrkNo(workNo); |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | Date now = new Date(); |
| | | task.setWrkNo(workNo) |
| | | .setAgvWrkNo(agvWrkNo) |
| | | .setIoTime(now) |
| | | .setWrkSts(7L) // 工作状态:7.待呼叫AGV(站点已分配) |
| | | .setIoType(101) // 入出库状态:101.全板出库 |
| | | .setTaskType("agv") |
| | | .setIoPri(10D) |
| | | .setStaNo(allocatedSite) // 站点已自动分配 |
| | | .setLocNo(locCache.getLocNo()) // 目标缓存位 |
| | | .setFullPlt("Y") // 满板:Y |
| | | .setPicking("N") // 拣料 |
| | | .setExitMk("N")// 退出 |
| | | .setSourceStaNo(orgSite) // 源站点 |
| | | .setSourceLocNo(locCache.getLocNo()) // 源库位(缓存位) |
| | | .setEmptyMk(locCache.getLocSts().equals("D") ? "Y" : "N")// 空板 |
| | | .setBarcode(barcode)// 托盘码 |
| | | .setLinkMis("N") |
| | | .setInvWh(robotGroup) // 根据源站点设置机器人组 |
| | | .setAppeUser(userId) |
| | | .setAppeTime(now) |
| | | .setModiUser(userId) |
| | | .setModiTime(now); |
| | | if (!taskService.insert(task)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | // 更新缓存位状态:O(闲置)-> R(出库预约) |
| | | locCache.setLocSts(LocStsType.LOC_STS_TYPE_R.type); |
| | | locCache.setModiUser(userId); |
| | | locCache.setModiTime(now); |
| | | if (!locCacheService.updateById(locCache)) { |
| | | throw new CoolException("更新缓存位状态失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成入库AGV任务(起点+入库,自动分配站点,库位手动指定) |
| | | * @param locCache 目标库位 |
| | | * @param orgSite 源站点 |
| | | * @param barcode 托盘码 |
| | | * @param userId 用户ID |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generateInboundAgvTask(LocCache locCache, String orgSite, String barcode, Long userId) { |
| | | // 判断是否是空托入库:库位状态为"D"(空桶/空栈板)表示空托入库 |
| | | boolean isEmptyPallet = LocStsType.LOC_STS_TYPE_D.type.equals(locCache.getLocSts()); |
| | | Integer ioType = isEmptyPallet ? 10 : 1; // 10=空托入库,1=实托入库 |
| | | |
| | | // 只有实托入库才需要组托信息 |
| | | List<WaitPakin> pakins = null; |
| | | if (!isEmptyPallet) { |
| | | // 实托入库:检查组托信息是否存在 |
| | | pakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode)); |
| | | if (Objects.isNull(pakins) || pakins.isEmpty()) { |
| | | throw new CoolException("组托信息不存在!!"); |
| | | } |
| | | } |
| | | |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.PICK.type); |
| | | // 生成AGV工作号 |
| | | String agvWrkNo = AgvUtils.generateAgvWrkNo(workNo); |
| | | // 保存工作档 |
| | | Task task = new Task(); |
| | | Date now = new Date(); |
| | | |
| | | // 根据库位whs_type确定机器人组 |
| | | Long whsType = locCache.getWhsType(); |
| | | String robotGroup; |
| | | if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getInboundArea())) { |
| | | robotGroup = agvProperties.getRobotGroupEast(); |
| | | } else if (whsType != null && whsType.equals(agvProperties.getWhsTypeMapping().getCacheArea())) { |
| | | robotGroup = agvProperties.getRobotGroupWest(); |
| | | } else { |
| | | robotGroup = agvProperties.getRobotGroupEast(); // 默认东侧 |
| | | } |
| | | |
| | | task.setWrkNo(workNo) |
| | | .setAgvWrkNo(agvWrkNo) // 设置AGV工作号 |
| | | .setIoTime(now) |
| | | .setWrkSts(7L) // 工作状态:7.待呼叫AGV(站点将自动分配) |
| | | .setIoType(ioType) // 入出库状态:10=空托入库,1=实托入库 |
| | | .setTaskType("agv") |
| | | .setIoPri(10D) |
| | | .setLocNo(locCache.getLocNo()) // 目标库位 |
| | | .setStaNo(null) // 站点将自动分配 |
| | | .setFullPlt(isEmptyPallet ? "N" : "Y") // 空托入库设置为N,实托入库设置为Y |
| | | .setPicking("N") // 拣料 |
| | | .setExitMk("N")// 退出 |
| | | .setSourceStaNo(orgSite) // 源站点 |
| | | .setSourceLocNo(orgSite) // 源库位(使用源站点) |
| | | .setEmptyMk(isEmptyPallet ? "Y" : "N")// 空板:空托入库为Y,实托入库为N |
| | | .setBarcode(barcode)// 托盘码 |
| | | .setLinkMis("N") |
| | | .setInvWh(robotGroup) // 根据whs_type设置机器人组 |
| | | .setAppeUser(userId) |
| | | .setAppeTime(now) |
| | | .setModiUser(userId) |
| | | .setModiTime(now); |
| | | if (!taskService.insert(task)) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | |
| | | // 立即分配站点(跟随入库逻辑) |
| | | String errorMsg = agvHandler.allocateSiteForTask(task); |
| | | if (errorMsg != null) { |
| | | throw new CoolException("分配站点失败:" + errorMsg); |
| | | } |
| | | // 重新查询任务以获取分配后的站点 |
| | | task = taskService.selectById(task.getId()); |
| | | if (task.getStaNo() == null || task.getStaNo().isEmpty() || task.getStaNo().equals("0")) { |
| | | throw new CoolException("站点分配失败,无法继续!"); |
| | | } |
| | | |
| | | // 只有实托入库才需要保存工作档明细 |
| | | if (!isEmptyPallet && pakins != null && !pakins.isEmpty()) { |
| | | List<TaskDetl> taskDetls = new ArrayList<>(); |
| | | pakins.forEach(pakin -> { |
| | | TaskDetl wrkDetl = new TaskDetl(); |
| | | BeanUtils.copyProperties(pakin, wrkDetl); |
| | | wrkDetl.setWrkNo(workNo) |
| | | .setIoTime(new Date()) |
| | | .setOrderNo(pakin.getOrderNo()) |
| | | .setAnfme(pakin.getAnfme()) |
| | | .setZpallet(pakin.getZpallet()) |
| | | .setBatch(pakin.getBatch()) |
| | | .setMatnr(pakin.getMatnr()) |
| | | .setMaktx(pakin.getMaktx()) |
| | | .setAppeUser(userId) |
| | | .setUnit(pakin.getUnit()) |
| | | .setModel(pakin.getModel()) |
| | | .setAppeTime(new Date()) |
| | | .setModiUser(userId); |
| | | taskDetls.add(wrkDetl); |
| | | }); |
| | | |
| | | if (!taskDetlService.insertBatch(taskDetls)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | } |
| | | |
| | | // 修改目标库位状态:O(闲置)-> S(入库预约) |
| | | if (locCache.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) { |
| | | locCache.setLocSts(LocStsType.LOC_STS_TYPE_S.type); |
| | | locCache.setModiTime(now); |
| | | locCache.setModiUser(userId); |
| | | if (!locCacheService.updateById(locCache)) { |
| | | throw new CoolException("更新目标库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException("移转失败,目标库位状态:" + locCache.getLocSts()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 按优先级分配缓存库位(跟随出库逻辑) |
| | | * @param whsType 库区类型 |
| | | * @param cacheAreaPrefix 缓存区库位前缀(如"WA") |
| | | * @param isEmptyPallet 是否空托 |
| | | * @return 分配的缓存库位,如果无法分配则返回null |
| | | */ |
| | | private LocCache allocateCacheLocationByPriority(Long whsType, String cacheAreaPrefix, boolean isEmptyPallet) { |
| | | // 查询所有符合条件的空库位 |
| | | List<LocCache> allLocations = locCacheService.selectList(new EntityWrapper<LocCache>() |
| | | .eq("whs_type", whsType) |
| | | .like("loc_no", cacheAreaPrefix + "%") |
| | | .eq("frozen", 0) |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type) // O.闲置 |
| | | .ne("full_plt", isEmptyPallet ? "Y" : "N") // 空托不选满板库位,满托不选空板库位 |
| | | ); |
| | | |
| | | if (allLocations == null || allLocations.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | // 按row1分组 |
| | | Map<Integer, List<LocCache>> locationsByRow = allLocations.stream() |
| | | .filter(loc -> loc.getRow1() != null) |
| | | .collect(Collectors.groupingBy(LocCache::getRow1)); |
| | | |
| | | if (locationsByRow.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | // 优先级1:分配第三列(bay1=3),且该排的1、2、3列都是空的 |
| | | for (Map.Entry<Integer, List<LocCache>> entry : locationsByRow.entrySet()) { |
| | | Integer row = entry.getKey(); |
| | | List<LocCache> rowLocs = entry.getValue(); |
| | | |
| | | // 检查该排的1、2、3列是否都有空库位 |
| | | boolean hasBay1 = rowLocs.stream().anyMatch(loc -> loc.getBay1() != null && loc.getBay1() == 1); |
| | | boolean hasBay2 = rowLocs.stream().anyMatch(loc -> loc.getBay1() != null && loc.getBay1() == 2); |
| | | boolean hasBay3 = rowLocs.stream().anyMatch(loc -> loc.getBay1() != null && loc.getBay1() == 3); |
| | | |
| | | if (hasBay1 && hasBay2 && hasBay3) { |
| | | // 该排的1、2、3列都是空的,分配第三列 |
| | | List<LocCache> bay3Locs = rowLocs.stream() |
| | | .filter(loc -> loc.getBay1() != null && loc.getBay1() == 3) |
| | | .sorted(Comparator.comparing(loc -> loc.getLev1() != null ? loc.getLev1() : 0)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!bay3Locs.isEmpty()) { |
| | | log.debug("优先级1:分配排{}的第三列,库位:{}", row, bay3Locs.get(0).getLocNo()); |
| | | return bay3Locs.get(0); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 优先级2:分配第二列(bay1=2),且该排的1、2列都是空的 |
| | | for (Map.Entry<Integer, List<LocCache>> entry : locationsByRow.entrySet()) { |
| | | Integer row = entry.getKey(); |
| | | List<LocCache> rowLocs = entry.getValue(); |
| | | |
| | | boolean hasBay1 = rowLocs.stream().anyMatch(loc -> loc.getBay1() != null && loc.getBay1() == 1); |
| | | boolean hasBay2 = rowLocs.stream().anyMatch(loc -> loc.getBay1() != null && loc.getBay1() == 2); |
| | | |
| | | if (hasBay1 && hasBay2) { |
| | | List<LocCache> bay2Locs = rowLocs.stream() |
| | | .filter(loc -> loc.getBay1() != null && loc.getBay1() == 2) |
| | | .sorted(Comparator.comparing(loc -> loc.getLev1() != null ? loc.getLev1() : 0)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!bay2Locs.isEmpty()) { |
| | | log.debug("优先级2:分配排{}的第二列,库位:{}", row, bay2Locs.get(0).getLocNo()); |
| | | return bay2Locs.get(0); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 优先级3:分配第一列(bay1=1) |
| | | for (Map.Entry<Integer, List<LocCache>> entry : locationsByRow.entrySet()) { |
| | | Integer row = entry.getKey(); |
| | | List<LocCache> rowLocs = entry.getValue(); |
| | | |
| | | List<LocCache> bay1Locs = rowLocs.stream() |
| | | .filter(loc -> loc.getBay1() != null && loc.getBay1() == 1) |
| | | .sorted(Comparator.comparing(loc -> loc.getLev1() != null ? loc.getLev1() : 0)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!bay1Locs.isEmpty()) { |
| | | log.debug("优先级3:分配排{}的第一列,库位:{}", row, bay1Locs.get(0).getLocNo()); |
| | | return bay1Locs.get(0); |
| | | } |
| | | } |
| | | |
| | | // 优先级4:分配第二列(不要求该排的1、2列都是空的) |
| | | for (Map.Entry<Integer, List<LocCache>> entry : locationsByRow.entrySet()) { |
| | | Integer row = entry.getKey(); |
| | | List<LocCache> rowLocs = entry.getValue(); |
| | | |
| | | List<LocCache> bay2Locs = rowLocs.stream() |
| | | .filter(loc -> loc.getBay1() != null && loc.getBay1() == 2) |
| | | .sorted(Comparator.comparing(loc -> loc.getLev1() != null ? loc.getLev1() : 0)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!bay2Locs.isEmpty()) { |
| | | log.debug("优先级4:分配排{}的第二列,库位:{}", row, bay2Locs.get(0).getLocNo()); |
| | | return bay2Locs.get(0); |
| | | } |
| | | } |
| | | |
| | | // 优先级5:分配第三列(不要求该排的1、2、3列都是空的) |
| | | for (Map.Entry<Integer, List<LocCache>> entry : locationsByRow.entrySet()) { |
| | | Integer row = entry.getKey(); |
| | | List<LocCache> rowLocs = entry.getValue(); |
| | | |
| | | List<LocCache> bay3Locs = rowLocs.stream() |
| | | .filter(loc -> loc.getBay1() != null && loc.getBay1() == 3) |
| | | .sorted(Comparator.comparing(loc -> loc.getLev1() != null ? loc.getLev1() : 0)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!bay3Locs.isEmpty()) { |
| | | log.debug("优先级5:分配排{}的第三列,库位:{}", row, bay3Locs.get(0).getLocNo()); |
| | | return bay3Locs.get(0); |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 为出库到缓存区的任务分配站点(跟随出库逻辑) |
| | | * @param cacheStations 缓存区站点列表 |
| | | * @param ioType 任务类型(101=全板出库,110=空板出库) |
| | | * @return 分配的站点编号,如果无法分配则返回null |
| | | */ |
| | | private String allocateCacheStationForOutbound(List<String> cacheStations, Integer ioType) { |
| | | if (cacheStations == null || cacheStations.isEmpty()) { |
| | | log.warn("缓存区站点列表为空,无法分配站点"); |
| | | return null; |
| | | } |
| | | |
| | | // 将站点字符串列表转换为整数列表 |
| | | List<Integer> siteIntList = cacheStations.stream() |
| | | .map(Integer::parseInt) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 查询所有缓存区站点的设备信息(包含任务数) |
| | | List<BasDevp> devList = basDevpMapper.selectList(new EntityWrapper<BasDevp>() |
| | | .in("dev_no", siteIntList) |
| | | ); |
| | | |
| | | if (devList.isEmpty()) { |
| | | log.warn("缓存区站点{}在设备表中不存在", cacheStations); |
| | | return cacheStations.get(0); // 降级:返回第一个站点 |
| | | } |
| | | |
| | | // 按入库任务数排序(出库到缓存区也使用in_qty字段) |
| | | devList.sort(Comparator.comparing(BasDevp::getInQty)); |
| | | |
| | | // 获取最少任务数 |
| | | int minInQty = devList.get(0).getInQty(); |
| | | |
| | | // 筛选出任务数最少的站点列表 |
| | | List<BasDevp> minTaskSites = devList.stream() |
| | | .filter(dev -> dev.getInQty() == minInQty) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 根据配置选择分配策略 |
| | | String strategy = agvProperties.getSiteAllocation().getStrategy(); |
| | | boolean enableRoundRobin = agvProperties.getSiteAllocation().isEnableRoundRobin(); |
| | | |
| | | List<BasDevp> orderedSites = new ArrayList<>(); |
| | | String groupKey = "west"; // 缓存区使用西侧 |
| | | |
| | | if (minTaskSites.size() > 1 && enableRoundRobin && "round-robin".equals(strategy)) { |
| | | // 轮询分配 |
| | | AtomicInteger counter = siteRoundRobinCounters.computeIfAbsent(groupKey, k -> new AtomicInteger(0)); |
| | | int startIndex = counter.get() % minTaskSites.size(); |
| | | orderedSites.addAll(minTaskSites.subList(startIndex, minTaskSites.size())); |
| | | orderedSites.addAll(minTaskSites.subList(0, startIndex)); |
| | | orderedSites.addAll(devList.stream() |
| | | .filter(dev -> dev.getInQty() > minInQty) |
| | | .collect(Collectors.toList())); |
| | | counter.getAndIncrement(); |
| | | log.debug("使用轮询分配策略,站点组:{},轮询起始索引:{}", groupKey, startIndex); |
| | | } else if (minTaskSites.size() > 1 && enableRoundRobin && "random".equals(strategy)) { |
| | | // 随机分配 |
| | | List<BasDevp> shuffledMinSites = new ArrayList<>(minTaskSites); |
| | | Collections.shuffle(shuffledMinSites); |
| | | orderedSites.addAll(shuffledMinSites); |
| | | orderedSites.addAll(devList.stream() |
| | | .filter(dev -> dev.getInQty() > minInQty) |
| | | .collect(Collectors.toList())); |
| | | log.debug("使用随机分配策略"); |
| | | } else { |
| | | // 默认:按入库任务数排序 |
| | | orderedSites = devList; |
| | | } |
| | | |
| | | // 依次检查每个站点是否在搬运,找到第一个空闲站点就分配 |
| | | String selectedSite = null; |
| | | List<Integer> checkIoTypes = Arrays.asList(101, 110); // 出库到缓存区的任务类型 |
| | | |
| | | for (BasDevp dev : orderedSites) { |
| | | String staNo = String.valueOf(dev.getDevNo()); |
| | | |
| | | // 检查该站点是否有正在搬运的同类型任务 |
| | | List<Task> transportingTasks = taskService.selectList( |
| | | new EntityWrapper<Task>() |
| | | .eq("sta_no", staNo) |
| | | .eq("task_type", "agv") |
| | | .eq("wrk_sts", 8L) // 只检查正在搬运状态的任务 |
| | | .in("io_type", checkIoTypes) |
| | | .eq("is_deleted", 0) |
| | | ); |
| | | |
| | | if (!transportingTasks.isEmpty()) { |
| | | log.debug("缓存区站点{}有{}个正在搬运的出库AGV任务,检查下一个站点", |
| | | staNo, transportingTasks.size()); |
| | | continue; // 该站点正在搬运,检查下一个站点 |
| | | } |
| | | |
| | | // 找到第一个空闲站点,分配 |
| | | selectedSite = staNo; |
| | | log.info("出库到缓存区任务按规则应分配到站点{},该站点空闲,分配成功", staNo); |
| | | break; |
| | | } |
| | | |
| | | // 如果所有站点都在搬运,则不分配站点 |
| | | if (selectedSite == null) { |
| | | return null; |
| | | } |
| | | |
| | | // 更新站点任务数(出库到缓存区也使用in_qty字段) |
| | | basDevpMapper.incrementInQty(Integer.parseInt(selectedSite)); |
| | | |
| | | return selectedSite; |
| | | } |
| | | } |