Search in sources :

Example 1 with PurchaseOrderItem

use of com.whoiszxl.entity.PurchaseOrderItem 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 PurchaseOrderItem

use of com.whoiszxl.entity.PurchaseOrderItem in project shopzz by whoiszxl.

the class PurchaseOrderController method receive.

@PutMapping("/receive")
@ApiOperation(value = "接收采购商发送过来的货物", notes = "更新合格商品数与到货的商品数", response = ResponseResult.class)
public ResponseResult<Boolean> receive(@RequestBody ReceiveProductVO receiveProducts) {
    // 采购单状态判断
    Long purchaseOrderId = null;
    for (ReceiveProductVO.ReceiveItem receiveItem : receiveProducts.getReceiveItems()) {
        Long itemId = receiveItem.getId();
        PurchaseOrderItem purchaseOrderItem = purchaseOrderItemService.getById(itemId);
        if (purchaseOrderItem == null) {
            return ResponseResult.buildError("采购单条目不存在");
        }
        purchaseOrderId = purchaseOrderItem.getPurchaseOrderId();
        PurchaseOrder purchaseOrder = purchaseOrderService.getById(purchaseOrderId);
        if (purchaseOrder == null || !purchaseOrder.getPurchaseOrderStatus().equals(PurchaseOrderStatusConstants.WAIT_FOR_INBOUND)) {
            return ResponseResult.buildError("采购单不为待入库状态");
        }
    }
    // 更新采购入库单条目的合格数量和到货数量
    List<PurchaseOrderItem> purchaseOrderItems = BeanCopierUtils.copyListProperties(receiveProducts.getReceiveItems(), PurchaseOrderItem::new);
    boolean saveFlag = purchaseOrderItemService.updateBatchById(purchaseOrderItems);
    // 更新采购入库单的到货时间
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    purchaseOrder.setId(purchaseOrderId);
    purchaseOrder.setArrivalTime(receiveProducts.getArrivalTime());
    boolean updateFlag = purchaseOrderService.updateById(purchaseOrder);
    return ResponseResult.buildByFlag(saveFlag && updateFlag);
}
Also used : PurchaseOrderItem(com.whoiszxl.entity.PurchaseOrderItem) ReceiveProductVO(com.whoiszxl.entity.vo.ReceiveProductVO) PurchaseOrder(com.whoiszxl.entity.PurchaseOrder) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with PurchaseOrderItem

use of com.whoiszxl.entity.PurchaseOrderItem in project shopzz by whoiszxl.

the class PurchaseOrderController method batchOnShelves.

@PutMapping("/shelves/on")
@ApiOperation(value = "批量新增采购入库单的上架条目", notes = "批量新增采购入库单的上架条目", response = ResponseResult.class)
public ResponseResult<Boolean> batchOnShelves(@RequestBody List<PurchaseInboundOnItemVO> putOnItems) {
    // 采购入库单状态判断
    for (PurchaseInboundOnItemVO putOnItem : putOnItems) {
        Long purchaseOrderItemId = putOnItem.getPurchaseOrderItemId();
        PurchaseOrderItem purchaseOrderItem = purchaseOrderItemService.getById(purchaseOrderItemId);
        if (purchaseOrderItem == null) {
            return ResponseResult.buildError("采购单条目不存在");
        }
        ProductAllocation productAllocation = productAllocationService.getById(putOnItem.getProductAllocationId());
        if (productAllocation == null) {
            return ResponseResult.buildError("采购单条目上架的货位不存在");
        }
        if (putOnItem.getPutOnShelvesCount() > purchaseOrderItem.getPurchaseQuantity()) {
            return ResponseResult.buildError(putOnItem.getProductSkuId() + "上架条目数量大于采购数量");
        }
    }
    List<PurchaseInboundOnItem> items = BeanCopierUtils.copyListProperties(putOnItems, PurchaseInboundOnItem::new);
    boolean saveFlag = purchaseInboundOnItemService.saveBatch(items);
    return ResponseResult.buildByFlag(saveFlag);
}
Also used : PurchaseOrderItem(com.whoiszxl.entity.PurchaseOrderItem) PurchaseInboundOnItemVO(com.whoiszxl.entity.vo.PurchaseInboundOnItemVO) ProductAllocation(com.whoiszxl.entity.ProductAllocation) PurchaseInboundOnItem(com.whoiszxl.entity.PurchaseInboundOnItem) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with PurchaseOrderItem

use of com.whoiszxl.entity.PurchaseOrderItem 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)

Example 5 with PurchaseOrderItem

use of com.whoiszxl.entity.PurchaseOrderItem in project shopzz by whoiszxl.

the class PurchaseOrderController method receive.

@PutMapping("/receive")
@ApiOperation(value = "接收采购商发送过来的货物", notes = "更新合格商品数与到货的商品数", response = ResponseResult.class)
public ResponseResult<Boolean> receive(@RequestBody ReceiveProductCommand receiveProductCommand) {
    // 采购单状态判断
    Long purchaseOrderId = null;
    for (ReceiveProductCommand.ReceiveItem receiveItem : receiveProductCommand.getReceiveItems()) {
        Long itemId = receiveItem.getId();
        PurchaseOrderItem purchaseOrderItem = purchaseOrderItemService.getById(itemId);
        if (purchaseOrderItem == null) {
            return ResponseResult.buildError("采购单条目不存在");
        }
        purchaseOrderId = purchaseOrderItem.getPurchaseOrderId();
        PurchaseOrder purchaseOrder = purchaseOrderService.getById(purchaseOrderId);
        if (purchaseOrder == null || !purchaseOrder.getPurchaseOrderStatus().equals(PurchaseOrderStatusConstants.WAIT_FOR_INBOUND)) {
            return ResponseResult.buildError("采购单不为待入库状态");
        }
    }
    // 更新采购入库单条目的合格数量和到货数量
    List<PurchaseOrderItem> purchaseOrderItems = dozerUtils.mapList(receiveProductCommand.getReceiveItems(), PurchaseOrderItem.class);
    boolean saveFlag = purchaseOrderItemService.updateBatchById(purchaseOrderItems);
    // 更新采购入库单的到货时间
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    purchaseOrder.setId(purchaseOrderId);
    purchaseOrder.setArrivalTime(receiveProductCommand.getArrivalTime());
    boolean updateFlag = purchaseOrderService.updateById(purchaseOrder);
    return ResponseResult.buildByFlag(saveFlag && updateFlag);
}
Also used : PurchaseOrderItem(com.whoiszxl.entity.PurchaseOrderItem) ReceiveProductCommand(com.whoiszxl.cqrs.command.ReceiveProductCommand) PurchaseOrder(com.whoiszxl.entity.PurchaseOrder) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

PurchaseOrderItem (com.whoiszxl.entity.PurchaseOrderItem)8 PurchaseOrder (com.whoiszxl.entity.PurchaseOrder)7 PurchaseOrderItemVO (com.whoiszxl.cqrs.vo.PurchaseOrderItemVO)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Transactional (org.springframework.transaction.annotation.Transactional)3 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)2 PurchaseOrderItemVO (com.whoiszxl.entity.vo.PurchaseOrderItemVO)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 ReceiveProductCommand (com.whoiszxl.cqrs.command.ReceiveProductCommand)1 PurchaseOrderResponse (com.whoiszxl.cqrs.response.PurchaseOrderResponse)1 ProductAllocation (com.whoiszxl.entity.ProductAllocation)1 PurchaseInboundOnItem (com.whoiszxl.entity.PurchaseInboundOnItem)1 PurchaseInboundOnItemVO (com.whoiszxl.entity.vo.PurchaseInboundOnItemVO)1 ReceiveProductVO (com.whoiszxl.entity.vo.ReceiveProductVO)1