| | |
| | | import com.zy.asrs.entity.param.FullStoreParam; |
| | | import com.zy.asrs.entity.param.LocDetlAdjustParam; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | import com.zy.asrs.enums.LocStsType; |
| | | import com.zy.asrs.mapper.LocMastMapper; |
| | | import com.zy.asrs.entity.result.FindLocNoAttributeVo; |
| | | import com.zy.asrs.service.*; |
| | |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.web.WcsController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.binary.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | @Resource |
| | | private LocMastMapper locMastMapper; |
| | | |
| | | @Autowired |
| | | private LocAroundBindService locAroundBindService; |
| | | |
| | | @Resource |
| | | private OrderPakoutService orderPakOutService; |
| | | @Autowired |
| | | private BasDeviceServiceImpl basDeviceService; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void stockOut(BasDevp staNo, TaskDto taskDto, Long userId) { |
| | | public void stockOut(BasDevp staNo, TaskDto taskDto, String deviceNo, Long userId) { |
| | | Date now = new Date(); |
| | | List<LocDto> locDtos = taskDto.getLocDtos(); |
| | | for (LocDto locDto : locDtos) { |
| | |
| | | StaDesc staDesc = staDescService.queryCrnStnAuto(ioType, locMast.getCrnNo(), staNo.getDevNo()); |
| | | // 生成工作号 |
| | | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); |
| | | String wrkCode = null; |
| | | //TODO 如果机台号不为空,判断当前机台与当前出库库位是否在同一库区或同一台堆垛机(相同站点) |
| | | //TODO 1. 如果是同一台堆垛机,生成移库(出库)任务 2. 如果不是,生成出库任务,再生成入库任务 |
| | | //TODO 另一种方案,不管是否当前巷道,统一出库,再入库 |
| | | if (!Objects.isNull(deviceNo)) { |
| | | wrkCode = workNo + "-1"; |
| | | generateOutStock(taskDto, userId, workNo, wrkCode, now, ioType, locMast, staDesc, deviceNo); |
| | | } else { |
| | | generateOutStock(taskDto, userId, workNo, wrkCode, now, ioType, locMast, staDesc, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成出库任务 |
| | | * |
| | | * @param taskDto |
| | | * @param userId |
| | | * @param workNo |
| | | * @param wrkCode |
| | | * @param now |
| | | * @param ioType |
| | | * @param locMast |
| | | * @param staDesc |
| | | * @author Ryan |
| | | * @date 2026/1/9 20:16 |
| | | */ |
| | | private void generateOutStock(TaskDto taskDto, Long userId, int workNo, String wrkCode, Date now, int ioType, LocMast locMast, StaDesc staDesc, String deviceNo) { |
| | | // 生成工作档 |
| | | WrkMast wrkMast = new WrkMast(); |
| | | wrkMast.setWrkNo(workNo); |
| | | //用于工作站,任务分解 |
| | | wrkMast.setWrkCode(wrkCode); |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID |
| | | wrkMast.setIoType(ioType); // 入出库状态 |
| | |
| | | if (!wrkDetlService.insert(wrkDetl)) { |
| | | throw new CoolException("保存工作档明细失败"); |
| | | } |
| | | |
| | | // // 修改订单明细 |
| | | // if (!orderDetlService.increaseWorkQty(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) { |
| | | // throw new CoolException("修改订单明细数量失败"); |
| | |
| | | orderDetl.getBoxType1(), orderDetl.getBoxType2(), orderDetl.getBoxType3() |
| | | , locDto.getAnfme()); |
| | | OrderInAndOutUtil.updateOrder(Boolean.FALSE, orderDetl.getOrderId(), 2L, userId); |
| | | } |
| | | |
| | | //TODO 判断设备号,生成入库任务。没有机台号,说明是普通出库任务 |
| | | if (!Objects.isNull(deviceNo)) { |
| | | genInStock(wrkMast, deviceNo, userId); |
| | | } |
| | | // 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中 |
| | | locMast = locMastService.selectById(taskDto.getLocNo()); |
| | |
| | | @Override |
| | | @Transactional |
| | | public void completeWrkMast(String workNo, Long userId) { |
| | | WrkMast wrkMast = wrkMastService.selectById(workNo); |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", workNo)); |
| | | if (Cools.isEmpty(wrkMast)) { |
| | | throw new CoolException(workNo + "工作档不存在"); |
| | | } |
| | | if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14) { |
| | | if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14 || wrkMast.getWrkSts() == 5 || wrkMast.getWrkSts() == 15) { |
| | | throw new CoolException("当前工作档已完成"); |
| | | } |
| | | // 入库 + 库位转移 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成出库匹配的工作站入库任务 |
| | | * |
| | | * @param outMast |
| | | * @param deviceNo |
| | | * @param deviceNo |
| | | * @param userId |
| | | * @author Ryan |
| | | * @date 2026/1/9 17:39 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void genInStock(WrkMast outMast, String deviceNo, Long userId) { |
| | | if (Objects.isNull(deviceNo)) { |
| | | throw new CoolException("机台号不能为空!!"); |
| | | } |
| | | BasDevice basDevice = basDeviceService.selectOne(new EntityWrapper<BasDevice>() |
| | | .eq("status", 1) |
| | | .eq("dev_no", deviceNo)); |
| | | if (Objects.isNull(basDevice)) { |
| | | throw new CoolException("机台信息不存在或已禁用!!"); |
| | | } |
| | | List<LocAroundBind> binds = locAroundBindService.selectList(new EntityWrapper<LocAroundBind>().eq("dev_no", basDevice.getDevNo())); |
| | | if (Objects.isNull(binds) || binds.isEmpty()) { |
| | | throw new CoolException("机台未绑定工作站台!!"); |
| | | } |
| | | Set<String> locs = binds.stream().map(LocAroundBind::getBLocNo).collect(Collectors.toSet()); |
| | | |
| | | LocMast locMasts = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .in("loc_no", locs) |
| | | .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type) |
| | | .orderAsc(Arrays.asList("loc_no")) |
| | | .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY")); |
| | | |
| | | if (Objects.isNull(locMasts)) { |
| | | throw new CoolException("当前机台,无可用工作台!!"); |
| | | } |
| | | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(1)); |
| | | List<Integer> staNos = staDescService.queryOutStaNosByLocNo(locMasts.getLocNo(),1); |
| | | //TODO 1. 获取入库站点, 目标库位 3. 将出库明细添加至入库明细 |
| | | Integer staNo = staNos.stream().findFirst().get(); |
| | | |
| | | if (Objects.isNull(outMast.getWrkCode())) { |
| | | throw new CoolException("数据错误,上级任务编码为空!!"); |
| | | } |
| | | String wrkCode; |
| | | int indexOf = outMast.getWrkCode().indexOf("-"); |
| | | if (indexOf != -1) { |
| | | String substring = outMast.getWrkCode().substring(0, indexOf); |
| | | wrkCode = substring + "-2"; |
| | | } else { |
| | | throw new CoolException("数据错误,上级任务编码错误!!"); |
| | | } |
| | | WrkMast wrkMast = new WrkMast(); |
| | | // 生成工作档 |
| | | wrkMast.setWrkNo(workNo); |
| | | wrkMast.setWrkCode(wrkCode); |
| | | wrkMast.setIoTime(new Date()); |
| | | wrkMast.setWrkSts(2L); // 工作状态:生成入库ID |
| | | wrkMast.setIoType(1); // 入出库状态:1.入库 |
| | | wrkMast.setCrnNo(locMasts.getCrnNo()); |
| | | wrkMast.setSourceStaNo(outMast.getStaNo()); |
| | | // wrkMast.setStaNo(staNo + ""); |
| | | wrkMast.setLocNo(locMasts.getLocNo()); |
| | | wrkMast.setIoPri(13D); // 优先级 |
| | | wrkMast.setBarcode(outMast.getBarcode()); // 托盘码 |
| | | wrkMast.setFullPlt("Y"); // 满板:Y |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setEmptyMk("N"); // 空板 |
| | | wrkMast.setLinkMis("Y"); |
| | | wrkMast.setModiUser(userId); |
| | | wrkMast.setAppeUser(userId); |
| | | wrkMast.setCtnType(locMasts.getCtnType()); // 容器类型 |
| | | // 操作人员数据 |
| | | wrkMast.setAppeTime(new Date()); |
| | | wrkMast.setModiTime(new Date()); |
| | | boolean res = wrkMastService.insert(wrkMast); |
| | | if (!res) { |
| | | throw new CoolException("保存工作档失败"); |
| | | } |
| | | // 更新源站点信息 |
| | | // sourceStaNo.setModiTime(now); |
| | | // if (!basDevpService.updateById(sourceStaNo)) { |
| | | // throw new CoolException("更新源站失败"); |
| | | // } |
| | | // 更新目标库位状态 |
| | | // LocMast locMast = locMastService.selectById(dto.getLocNo()); |
| | | if (locMasts.getLocSts().equals("O")) { |
| | | locMasts.setLocSts("S"); // S.入库预约 |
| | | locMasts.setModiTime(new Date()); |
| | | if (!locMastService.updateById(locMasts)) { |
| | | throw new CoolException("改变库位状态失败"); |
| | | } |
| | | } else { |
| | | throw new CoolException(locMasts.getLocNo() + "目标库位已被占用"); |
| | | } |
| | | List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", outMast.getWrkNo())); |
| | | if (Objects.isNull(wrkDetls) || wrkDetls.isEmpty()) { |
| | | throw new CoolException("任务明细为空!!"); |
| | | } |
| | | wrkDetls.forEach(wrkDetl -> { |
| | | WrkDetl detl = new WrkDetl(); |
| | | BeanUtils.copyProperties(wrkDetl, detl); |
| | | detl.setWrkNo(wrkMast.getWrkNo()); |
| | | if (!wrkDetlService.insert(detl)) { |
| | | throw new CoolException("任务明细保存失败!!"); |
| | | } |
| | | }); |
| | | } |
| | | } |