|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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("主单保存失败!!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | .setFieldsIndex(item.getFieldsIndex()) | 
|---|
|  |  |  | .setMatnrId(item.getMatnrId()) | 
|---|
|  |  |  | .setMaktx(item.getMaktx()) | 
|---|
|  |  |  | .setUpdateBy(userId) | 
|---|
|  |  |  | .setCreateBy(userId) | 
|---|
|  |  |  | .setMatnrCode(item.getMatnrCode()); | 
|---|
|  |  |  | AsnOrder order = asnOrderService.getById(item.getAsnId()); | 
|---|
|  |  |  | if (!Objects.isNull(order)) { | 
|---|
|  |  |  | pakinItem.setType(null == order.getType() ?  null :order.getType()) | 
|---|
|  |  |  | .setWkType(null == order.getWkType() ? null : Short.parseShort(order.getWkType()) ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (PakinItem waitPakinItem : waitPakin.getItems()) { | 
|---|
|  |  |  | if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) { | 
|---|
|  |  |  | if (waitPakinItem.getReceiptQty() > item.getAnfme()) { | 
|---|
|  |  |  | if (waitPakinItem.getReceiptQty() > item.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) >= 0) { | 
|---|
|  |  |  | throw new CoolException("组拖数量不能大于收货数量!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pakinItem.setAnfme(waitPakinItem.getReceiptQty()).setTrackCode(waitPakinItem.getTrackCode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | .setFieldsIndex(item.getFieldsIndex()) | 
|---|
|  |  |  | .setMatnrId(item.getMatnrId()) | 
|---|
|  |  |  | .setMaktx(item.getMaktx()) | 
|---|
|  |  |  | .setUpdateBy(userId) | 
|---|
|  |  |  | .setCreateBy(userId) | 
|---|
|  |  |  | .setMatnrCode(item.getMatnrCode()); | 
|---|
|  |  |  | AsnOrder order = asnOrderService.getById(item.getAsnId()); | 
|---|
|  |  |  | if (!Objects.isNull(order)) { | 
|---|
|  |  |  | pakinItem.setType(null == order.getType() ?  null :order.getType()) | 
|---|
|  |  |  | .setWkType(null == order.getWkType() ? null : Short.parseShort(order.getWkType()) ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (PakinItem waitPakinItem : waitPakin.getItems()) { | 
|---|
|  |  |  | if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) { | 
|---|
|  |  |  | if (waitPakinItem.getReceiptQty() > item.getAnfme()) { | 
|---|
|  |  |  | throw new CoolException("组拖数量不能大于收货数量!!"); | 
|---|
|  |  |  | if (waitPakinItem.getReceiptQty() > item.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) <= 0) { | 
|---|
|  |  |  | throw new CoolException("组拖数量不能大于收货数量且不能小于零!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pakinItem.setAnfme(waitPakinItem.getReceiptQty()).setTrackCode(waitPakinItem.getTrackCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!this.updateById(waitPakin1)) { | 
|---|
|  |  |  | throw new CoolException("组拖数量修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //TODO 组拖完成后,扣减收货区库存 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return pakin; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|