| | |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R createByPo(Map<String, Object> params) { |
| | | Long purchaseId = Long.parseLong(params.get("purchaseId").toString()); |
| | | List<PurchaseItem> itemList = JSONArray.parseArray(JSONObject.toJSONString(params.get("items")), PurchaseItem.class); |
| | |
| | | if (StringUtils.isBlank(trackCode)) { |
| | | throw new CoolException("单据跟踪码生成失败:请检查「sys_asn_mantr_label」是否配置完成!!"); |
| | | } |
| | | |
| | | PurchaseItem service = purchaseItemService.getById(item.getId()); |
| | | Double qty = service.getQty() + item.getAnfme(); |
| | | if (qty.compareTo(service.getAnfme()) > 0) { |
| | | throw new CoolException("新建单据数量不能大于计划数量!!"); |
| | | } |
| | | orderItem.setAnfme(item.getAnfme()) |
| | | .setAsnId(order.getId()) |
| | | .setSplrName(item.getSplrName()) |
| | |
| | | .setMatnrId(matnr.getId()); |
| | | orderItems.add(orderItem); |
| | | |
| | | |
| | | // purchaseItemService.update(new LambdaUpdateWrapper<>().set(PurchaseItem::getAnfme, )); |
| | | |
| | | PurchaseItem purchaseItem = purchaseItemService.getOne(new LambdaQueryWrapper<PurchaseItem>().eq(PurchaseItem::getId, item.getId())); |
| | | if (Objects.isNull(purchaseItem)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | purchaseItem.setQty(purchaseItem.getQty() + item.getAnfme()); |
| | | if (!purchaseItemService.updateById(purchaseItem)) { |
| | | throw new CoolException("PO单明细修改失败!!"); |
| | | } |
| | | } |
| | | |
| | | double sum = orderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum(); |
| | |
| | | } |
| | | //任务执行完成,修改已完成数量和PO单执行状态 |
| | | purchase.setQty(sum + purchase.getQty()) |
| | | .setAnfme(purchase.getAnfme() - sum) |
| | | .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); |
| | | |
| | | if (!purchaseService.saveOrUpdate(purchase)) { |
| | |
| | | list.forEach(item -> { |
| | | PurchaseItem purchaseItem = purchaseItemService.getById(item.getPoDetlId()); |
| | | if (!Objects.isNull(purchaseItem)) { |
| | | purchaseItem.setQty(purchaseItem.getQty() - item.getAnfme()) |
| | | .setAnfme(purchaseItem.getAnfme() + item.getAnfme()); |
| | | purchaseItem.setQty(purchaseItem.getQty() - item.getAnfme()); |
| | | } |
| | | if (!purchaseItemService.updateById(purchaseItem)) { |
| | | throw new CoolException("PO单明细更新失败!!"); |
| | |
| | | Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>() |
| | | .eq(Purchase::getCode, list.stream().findFirst().get().getPoCode())); |
| | | purchase.setQty(purchase.getQty() - sum) |
| | | .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val) |
| | | .setAnfme(purchase.getAnfme() + sum); |
| | | .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val); |
| | | |
| | | if (!purchaseService.updateById(purchase)) { |
| | | throw new CoolException("PO单据更新失败!!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | if (!asnOrderItemService.remove(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .in(AsnOrderItem::getAsnId, ids))) { |
| | | throw new CoolException("Details Delete Fail"); |
| | | } |
| | | |
| | | if (!this.remove(new LambdaQueryWrapper<AsnOrder>() |
| | | .in(AsnOrder::getId, ids) |
| | | .eq(AsnOrder::getExceStatus, AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val))) { |
| | | throw new CoolException("任务中单据不可删除!!"); |
| | | } |
| | | |
| | | |
| | | if (!asnOrderItemService.remove(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .in(AsnOrderItem::getAsnId, ids))) { |
| | | // throw new CoolException("Details Delete Fail"); |
| | | } |
| | | |
| | | return R.ok("操作成功!!"); |
| | | } |
| | | |