|  |  |  | 
|---|
|  |  |  | assert ioType != null; | 
|---|
|  |  |  | // 获取库位 | 
|---|
|  |  |  | LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, dto.getLocNo()).eq(LocMast::getHostId, hostId)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String barcode = locMast.getBarcode(); | 
|---|
|  |  |  | int count = wrkMastService.count(new LambdaQueryWrapper<WrkMast>().eq(WrkMast::getBarcode, barcode)); | 
|---|
|  |  |  | if (count > 0) { | 
|---|
|  |  |  | throw new CoolException("工作档已生成"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取路径 | 
|---|
|  |  |  | StaDesc staDesc = staDescService.getOne(new LambdaQueryWrapper<StaDesc>().eq(StaDesc::getTypeNo, ioType).eq(StaDesc::getStnNo, staNo).eq(StaDesc::getHostId, hostId)); | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | 
|---|
|  |  |  | wrkMast.setWrkSts(101L); // 工作状态:101.生成出库 | 
|---|
|  |  |  | wrkMast.setIoType(ioType); // 入出库状态 | 
|---|
|  |  |  | wrkMast.setIoPri(13D); // 优先级:13 | 
|---|
|  |  |  | wrkMast.setSourceStaNo(staDesc.getDeviceStn()); // 源站 | 
|---|
|  |  |  | wrkMast.setStaNo(staDesc.getStnNo()); // 目标站 | 
|---|
|  |  |  | wrkMast.setSourceStaNo(Cools.isEmpty(staDesc.getDeviceStn())? 0 : staDesc.getDeviceStn()); // 源站 | 
|---|
|  |  |  | wrkMast.setStaNo(Cools.isEmpty(staDesc.getStnNo()) ? 0:staDesc.getStnNo()); // 目标站 | 
|---|
|  |  |  | wrkMast.setSourceLocNo(dto.getLocNo()); // 源库位 | 
|---|
|  |  |  | wrkMast.setFullPlt("Y"); // 满板:Y | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setBarcode(locMast.getBarcode()); | 
|---|
|  |  |  | wrkMast.setBarcode(barcode); | 
|---|
|  |  |  | wrkMast.setAppeUser(String.valueOf(userId)); // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | wrkMast.setModiUser(String.valueOf(userId)); | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(LocMast::getHostId, hostId)); | 
|---|
|  |  |  | // 获取路径 | 
|---|
|  |  |  | int ioType = taskDto.isAll() ? 101 : 103; | 
|---|
|  |  |  | if(ioType==101){ | 
|---|
|  |  |  | staNo=102; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 获取路径 | 
|---|
|  |  |  | StaDesc staDesc = staDescService.getOne(new LambdaQueryWrapper<StaDesc>().eq(StaDesc::getTypeNo, ioType).eq(StaDesc::getDeviceStn, staNo).eq(StaDesc::getHostId, hostId)); | 
|---|
|  |  |  | StaDesc staDesc = staDescService.getOne(new LambdaQueryWrapper<StaDesc>().eq(StaDesc::getTypeNo, ioType).eq(StaDesc::getStnNo, staNo).eq(StaDesc::getHostId, hostId)); | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType)); | 
|---|
|  |  |  | // 生成工作档 | 
|---|
|  |  |  | 
|---|
|  |  |  | wrkMast.setPicking("N"); // 拣料 | 
|---|
|  |  |  | wrkMast.setExitMk("N"); // 退出 | 
|---|
|  |  |  | wrkMast.setEmptyMk("N"); // 空板 | 
|---|
|  |  |  | wrkMast.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | wrkMast.setBarcode(locMast.getBarcode()); | 
|---|
|  |  |  | wrkMast.setAppeUser(String.valueOf(userId)); // 操作人员数据 | 
|---|
|  |  |  | wrkMast.setAppeTime(now); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("保存工作档明细失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 修改订单明细 | 
|---|
|  |  |  | if (!orderDetlService.increase(orderDetl.getOrderId(), hostId, orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) { | 
|---|
|  |  |  | if (!orderDetlService.increaseWorkQty(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme(), hostId)) { | 
|---|
|  |  |  | throw new CoolException("修改订单明细数量失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orderService.updateSettle(orderDetl.getOrderId(), 2L, userId, hostId); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("当前工作状态无法取消"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 订单关联 | 
|---|
|  |  |  | List<WrkDetl> wrkDetls = wrkDetlService.list(new LambdaQueryWrapper<WrkDetl>().eq(WrkDetl::getWrkNo, wrkMast.getWrkNo()).eq(WrkDetl::getHostId, hostId)); | 
|---|
|  |  |  | for (WrkDetl wrkDetl : wrkDetls) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!orderDetlService.decrease(wrkDetl.getOrderNo(), hostId, wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) { | 
|---|
|  |  |  | throw new CoolException("订单数据回滚失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //修改订单主表状态,没有作业数量时才可以修改 | 
|---|
|  |  |  | boolean flag = true; | 
|---|
|  |  |  | List<OrderDetl> orderDetls = orderDetlService.list(new LambdaQueryWrapper<OrderDetl>() | 
|---|
|  |  |  | .eq(OrderDetl::getOrderNo, wrkDetl.getOrderNo()) | 
|---|
|  |  |  | .eq(OrderDetl::getHostId, hostId)); | 
|---|
|  |  |  | for(OrderDetl orderDetl : orderDetls){ | 
|---|
|  |  |  | if(orderDetl.getWorkQty() > 0){ | 
|---|
|  |  |  | flag = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(flag){ | 
|---|
|  |  |  | Order order = orderService.getOne(new LambdaQueryWrapper<Order>() | 
|---|
|  |  |  | .eq(Order::getOrderNo, wrkDetl.getOrderNo()) | 
|---|
|  |  |  | .eq(Order::getHostId, hostId)); | 
|---|
|  |  |  | if(!Cools.isEmpty(order) && order.getSettle()==2){ | 
|---|
|  |  |  | order.setSettle(1L); | 
|---|
|  |  |  | order.setUpdateBy(userId); | 
|---|
|  |  |  | order.setUpdateTime(new Date()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!orderService.updateById(order)){ | 
|---|
|  |  |  | throw new CoolException("修改订单状态失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 取消操作人员记录 | 
|---|