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);
}
Aggregations