Search in sources :

Example 1 with PurchaseOrderItemVO

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;
}
Also used : PurchaseOrderItem(com.whoiszxl.entity.PurchaseOrderItem) PurchaseOrderItemVO(com.whoiszxl.entity.vo.PurchaseOrderItemVO) PurchaseOrder(com.whoiszxl.entity.PurchaseOrder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PurchaseOrderItemVO

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;
}
Also used : PurchaseOrderItem(com.whoiszxl.entity.PurchaseOrderItem) PurchaseOrderItemVO(com.whoiszxl.entity.vo.PurchaseOrderItemVO) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) PurchaseOrder(com.whoiszxl.entity.PurchaseOrder) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PurchaseOrder (com.whoiszxl.entity.PurchaseOrder)2 PurchaseOrderItem (com.whoiszxl.entity.PurchaseOrderItem)2 PurchaseOrderItemVO (com.whoiszxl.entity.vo.PurchaseOrderItemVO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)1