Search in sources :

Example 1 with ReceiveProductCommand

use of com.whoiszxl.cqrs.command.ReceiveProductCommand 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

ReceiveProductCommand (com.whoiszxl.cqrs.command.ReceiveProductCommand)1 PurchaseOrder (com.whoiszxl.entity.PurchaseOrder)1 PurchaseOrderItem (com.whoiszxl.entity.PurchaseOrderItem)1 ApiOperation (io.swagger.annotations.ApiOperation)1