use of com.whoiszxl.entity.vo.PurchaseOrderItemVO in project shopzz by whoiszxl.
the class PurchaseOrderServiceImpl method savePurchaseOrder.
@Transactional
@Override
public boolean savePurchaseOrder(PurchaseOrderVO purchaseOrderVO) {
// 1. 新增采购订单
purchaseOrderVO.setPurchaseOrderStatus(PurchaseOrderStatusEnum.EDITING.getCode());
PurchaseOrder purchaseOrder = purchaseOrderVO.clone(PurchaseOrder.class);
boolean orderFlag = this.save(purchaseOrder);
// 2. 新增采购订单中的商品详情
List<PurchaseOrderItemVO> items = purchaseOrderVO.getItems();
for (PurchaseOrderItemVO item : items) {
item.setPurchaseOrderId(purchaseOrder.getId());
}
List<PurchaseOrderItem> purchaseOrderItems = BeanCopierUtils.copyListProperties(items, PurchaseOrderItem::new);
boolean itemFlag = purchaseOrderItemService.saveBatch(purchaseOrderItems);
return orderFlag && itemFlag;
}
use of com.whoiszxl.entity.vo.PurchaseOrderItemVO in project shopzz by whoiszxl.
the class PurchaseOrderServiceImpl method updatePurchaseOrder.
@Transactional
@Override
public Boolean updatePurchaseOrder(PurchaseOrderVO purchaseOrderVO) {
// 1. 更新采购订单
purchaseOrderVO.setPurchaseOrderStatus(PurchaseOrderStatusEnum.EDITING.getCode());
PurchaseOrder purchaseOrder = purchaseOrderVO.clone(PurchaseOrder.class);
boolean orderFlag = this.updateById(purchaseOrder);
// 2. 删除原来的订单商品详情
boolean removeFlag = purchaseOrderItemService.remove(new UpdateWrapper<PurchaseOrderItem>().eq("purchase_order_id", purchaseOrderVO.getId()));
// 2. 新增订单商品详情
List<PurchaseOrderItemVO> items = purchaseOrderVO.getItems();
items.forEach(item -> item.setPurchaseOrderId(purchaseOrder.getId()));
List<PurchaseOrderItem> purchaseOrderItems = BeanCopierUtils.copyListProperties(items, PurchaseOrderItem::new);
boolean itemFlag = purchaseOrderItemService.saveBatch(purchaseOrderItems);
if (!orderFlag || !removeFlag || !itemFlag) {
ExceptionCatcher.catchDatabaseFailEx();
}
return true;
}
Aggregations