| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.manager.controller.params.PakinItem; |
| | | import com.vincent.rsf.server.manager.controller.params.WaitPakinParam; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.core.parameters.P; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private LocService locService; |
| | | |
| | | /** |
| | | * @param |
| | | * @param userId |
| | | * @return |
| | | * @author Ryan |
| | | * @description 组拖 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/29 14:42 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public WaitPakin mergeItems(WaitPakinParam waitPakin) { |
| | | if (waitPakin.getItems().isEmpty()) { |
| | | public WaitPakin mergeItems(WaitPakinParam waitPakin, Long userId) { |
| | | if (Objects.isNull(waitPakin.getItems()) || waitPakin.getItems().isEmpty()) { |
| | | throw new CoolException("参数错误:物料跟踪码为空!"); |
| | | } |
| | | if (StringUtils.isBlank(waitPakin.getBarcode())) { |
| | |
| | | //状态修改为入库中 |
| | | .setIoStatus(Short.parseShort(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)) |
| | | .setAnfme(sum) |
| | | .setUpdateBy(userId) |
| | | .setCreateBy(userId) |
| | | .setBarcode(waitPakin.getBarcode()); |
| | | if (!this.save(waitPakin1)) { |
| | | throw new CoolException("主单保存失败!!"); |
| | |
| | | throw new CoolException("原单据清除失败!!"); |
| | | } |
| | | } |
| | | |
| | | LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new QueryWrapper<WarehouseAreasItem>() |
| | | .select("SUM(anfme) as anfme, track_code, asn_code, id, splr_batch, ispt_result, plat_item_id, batch, qty, work_qty, matnr_code, matnr_id, maktx") |
| | | .lambda() |
| | | .in(WarehouseAreasItem::getTrackCode, tracks) |
| | | .groupBy(WarehouseAreasItem::getSplrBatch, |
| | | WarehouseAreasItem::getTrackCode); |
| | | List<WarehouseAreasItem> warehouseAreasItems = warehouseAreasItemService.list(queryWrapper); |
| | | if (Objects.isNull(warehouseAreasItems) || warehouseAreasItems.isEmpty()) { |
| | | throw new CoolException("物料未送至收货区!!"); |
| | | } |
| | | List<WaitPakinItem> items = new ArrayList<>(); |
| | | for (WarehouseAreasItem item : warehouseAreasItems) { |
| | | WaitPakinItem pakinItem = new WaitPakinItem(); |
| | | pakinItem.setAnfme(item.getAnfme()) |
| | | .setPakinId(waitPakin1.getId()) |
| | | .setAsnId(item.getAsnId()) |
| | | .setAsnCode(item.getAsnCode()) |
| | | .setAsnItemId(item.getId()) |
| | | .setBatch(item.getSplrBatch()) |
| | | .setUnit(item.getStockUnit()) |
| | | .setFieldsIndex(item.getFieldsIndex()) |
| | | .setMatnrId(item.getMatnrId()) |
| | | .setMaktx(item.getMaktx()) |
| | | .setMatnrCode(item.getMatnrCode()); |
| | | for (PakinItem waitPakinItem : waitPakin.getItems()) { |
| | | if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) { |
| | | if (waitPakinItem.getReceiptQty() > item.getAnfme()) { |
| | | throw new CoolException("组拖数量不能大于收货数量!!"); |
| | | } |
| | | pakinItem |
| | | .setAnfme(waitPakinItem.getReceiptQty()) |
| | | .setTrackCode(waitPakinItem.getTrackCode()); |
| | | /**更新单据执行中库存*/ |
| | | // if (v.compareTo(item.getAnfme()) > 0) {throw new CoolException("执行中数量大于收货数量!!");} |
| | | // if (!asnOrderItemService.update(new LambdaUpdateWrapper<AsnOrderItem>() |
| | | // .eq(AsnOrderItem::getTrackCode, waitPakinItem.getTrackCode()).set(AsnOrderItem::getWorkQty, v))) { |
| | | // throw new CoolException("执行中库存更新失败!!"); |
| | | // } |
| | | } |
| | | if (!Objects.isNull(waitPakin.getType()) && waitPakin.getType().equals("defective")) { |
| | | List<AsnOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().in(AsnOrderItem::getTrackCode, tracks)); |
| | | if (Objects.isNull(orderItems) || orderItems.isEmpty()) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | items.add(pakinItem); |
| | | for (AsnOrderItem item : orderItems) { |
| | | WaitPakinItem pakinItem = new WaitPakinItem(); |
| | | pakinItem.setAnfme(item.getAnfme()) |
| | | .setPakinId(waitPakin1.getId()) |
| | | .setAsnId(item.getAsnId()) |
| | | .setAsnCode(item.getAsnCode()) |
| | | .setAsnItemId(item.getId()) |
| | | .setBatch(item.getSplrBatch()) |
| | | .setUnit(item.getStockUnit()) |
| | | .setFieldsIndex(item.getFieldsIndex()) |
| | | .setMatnrId(item.getMatnrId()) |
| | | .setMaktx(item.getMaktx()) |
| | | .setUpdateBy(userId) |
| | | .setCreateBy(userId) |
| | | .setMatnrCode(item.getMatnrCode()); |
| | | for (PakinItem waitPakinItem : waitPakin.getItems()) { |
| | | if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) { |
| | | if (waitPakinItem.getReceiptQty() > item.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) >= 0) { |
| | | throw new CoolException("组拖数量不能大于收货数量!!"); |
| | | } |
| | | pakinItem.setAnfme(waitPakinItem.getReceiptQty()).setTrackCode(waitPakinItem.getTrackCode()); |
| | | } |
| | | } |
| | | items.add(pakinItem); |
| | | } |
| | | } else { |
| | | LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new QueryWrapper<WarehouseAreasItem>() |
| | | .select("SUM(anfme) as anfme, track_code, asn_code, id, splr_batch, ispt_result, plat_item_id, batch, qty, work_qty, matnr_code, matnr_id, maktx") |
| | | .lambda() |
| | | .in(WarehouseAreasItem::getTrackCode, tracks) |
| | | .groupBy(WarehouseAreasItem::getSplrBatch, |
| | | WarehouseAreasItem::getTrackCode); |
| | | List<WarehouseAreasItem> warehouseAreasItems = warehouseAreasItemService.list(queryWrapper); |
| | | if (Objects.isNull(warehouseAreasItems) || warehouseAreasItems.isEmpty()) { |
| | | throw new CoolException("物料未送至收货区!!"); |
| | | } |
| | | for (WarehouseAreasItem item : warehouseAreasItems) { |
| | | WaitPakinItem pakinItem = new WaitPakinItem(); |
| | | pakinItem.setAnfme(item.getAnfme()) |
| | | .setPakinId(waitPakin1.getId()) |
| | | .setAsnId(item.getAsnId()) |
| | | .setAsnCode(item.getAsnCode()) |
| | | .setAsnItemId(item.getId()) |
| | | .setBatch(item.getSplrBatch()) |
| | | .setUnit(item.getStockUnit()) |
| | | .setFieldsIndex(item.getFieldsIndex()) |
| | | .setMatnrId(item.getMatnrId()) |
| | | .setMaktx(item.getMaktx()) |
| | | .setUpdateBy(userId) |
| | | .setCreateBy(userId) |
| | | .setMatnrCode(item.getMatnrCode()); |
| | | for (PakinItem waitPakinItem : waitPakin.getItems()) { |
| | | if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) { |
| | | if (waitPakinItem.getReceiptQty() > item.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) <= 0) { |
| | | throw new CoolException("组拖数量不能大于收货数量且不能小于零!!"); |
| | | } |
| | | pakinItem.setAnfme(waitPakinItem.getReceiptQty()).setTrackCode(waitPakinItem.getTrackCode()); |
| | | } |
| | | } |
| | | items.add(pakinItem); |
| | | } |
| | | } |
| | | double sum1 = items.stream().mapToDouble(WaitPakinItem::getAnfme).sum(); |
| | | if (!waitPakinItemService.saveBatch(items)) { |