feat(ClientCustomerOrderService): 添加增加 SKU 销售数量的功能
feat(ClientCustomerOrderService): 添加 SKU 菜品库存相关 RPC接口
Showing
7 changed files
with
382 additions
and
5 deletions
| 1 | +package com.tianting.infoloop.mapper; | ||
| 2 | + | ||
| 3 | +import com.tianting.infoloop.inject.MyBaseMapper; | ||
| 4 | +import com.tianting.infoloop.model.db.SkuSellQuantity; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | +* @author zhuyf | ||
| 8 | +* @description 针对表【sku_sell_quantities(sku售卖量)】的数据库操作Mapper | ||
| 9 | +* @createDate 2025-02-28 14:03:59 | ||
| 10 | +* @Entity com.tianting.infoloop.model.db.SkuSellQuantity | ||
| 11 | +*/ | ||
| 12 | +public interface SkuSellQuantityMapper extends MyBaseMapper<SkuSellQuantity> { | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +} |
| 1 | +package com.tianting.infoloop.model.db; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.annotation.FieldFill; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.IdType; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.TableLogic; | ||
| 8 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 9 | +import com.baomidou.mybatisplus.extension.activerecord.Model; | ||
| 10 | +import lombok.Data; | ||
| 11 | +import lombok.EqualsAndHashCode; | ||
| 12 | +import lombok.experimental.Accessors; | ||
| 13 | + | ||
| 14 | +import java.io.Serializable; | ||
| 15 | +import java.time.LocalDateTime; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * sku售卖量 | ||
| 19 | + * @TableName sku_sell_quantities | ||
| 20 | + */ | ||
| 21 | +@EqualsAndHashCode(callSuper = true) | ||
| 22 | +@Data | ||
| 23 | +@Accessors(chain = true) | ||
| 24 | +@TableName(value ="sku_sell_quantities") | ||
| 25 | +public class SkuSellQuantity extends Model<OrderDetailDb> implements Serializable { | ||
| 26 | + | ||
| 27 | + @TableId(type = IdType.AUTO) | ||
| 28 | + private Integer id; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * | ||
| 32 | + */ | ||
| 33 | + private Integer enterpriseId; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * | ||
| 37 | + */ | ||
| 38 | + private Integer stallId; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 商品ID | ||
| 42 | + */ | ||
| 43 | + private Integer skuId; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 最大可售量 | ||
| 47 | + */ | ||
| 48 | + private Integer maxSellQuantity; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 今日已售量 | ||
| 52 | + */ | ||
| 53 | + private Integer todaySellQuantity; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * | ||
| 57 | + */ | ||
| 58 | + private Integer createdBy; | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + @TableField(fill = FieldFill.INSERT) | ||
| 62 | + private LocalDateTime createdAt; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * | ||
| 66 | + */ | ||
| 67 | + private Integer creationSource; | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * | ||
| 71 | + */ | ||
| 72 | + private Integer updatedBy; | ||
| 73 | + | ||
| 74 | + | ||
| 75 | + @TableField(fill = FieldFill.INSERT_UPDATE) | ||
| 76 | + private LocalDateTime updatedAt; | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * | ||
| 80 | + */ | ||
| 81 | + private Integer updateSource; | ||
| 82 | + | ||
| 83 | + @TableLogic | ||
| 84 | + private Integer isDeleted; | ||
| 85 | + | ||
| 86 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +package com.tianting.infoloop.service; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
| 4 | +import com.tianting.infoloop.model.db.SkuSellQuantity; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | +* @author zhuyf | ||
| 8 | +* @description 针对表【sku_sell_quantities(sku售卖量)】的数据库操作Service | ||
| 9 | +* @createDate 2025-02-28 14:03:59 | ||
| 10 | +*/ | ||
| 11 | +public interface SkuSellQuantityService extends IService<SkuSellQuantity> { | ||
| 12 | + | ||
| 13 | +} |
| ... | @@ -7,12 +7,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ... | @@ -7,12 +7,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 7 | import com.baomidou.mybatisplus.core.metadata.IPage; | 7 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 8 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 8 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 10 | +import com.infoloop.tianting.clientcustomerorderservice.AddSkusSellQuantitiesRpcRequest; | ||
| 11 | +import com.infoloop.tianting.clientcustomerorderservice.AddSkusSellQuantitiesRpcResponse; | ||
| 10 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrderDetailsRpcRequest; | 12 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrderDetailsRpcRequest; |
| 11 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrderDetailsRpcResponse; | 13 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrderDetailsRpcResponse; |
| 12 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrdersRpcRequest; | 14 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrdersRpcRequest; |
| 13 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrdersRpcResponse; | 15 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateClientCustomerOrdersRpcResponse; |
| 14 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsRequest; | 16 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsRequest; |
| 15 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsResponse; | 17 | import com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsResponse; |
| 18 | +import com.infoloop.tianting.clientcustomerorderservice.BatchSaveSkuSellQuantitiesRpcRequest; | ||
| 19 | +import com.infoloop.tianting.clientcustomerorderservice.BatchSaveSkuSellQuantitiesRpcResponse; | ||
| 16 | import com.infoloop.tianting.clientcustomerorderservice.BatchUpdateClientCustomerOrderDetailsRpcRequest; | 20 | import com.infoloop.tianting.clientcustomerorderservice.BatchUpdateClientCustomerOrderDetailsRpcRequest; |
| 17 | import com.infoloop.tianting.clientcustomerorderservice.BatchUpdateClientCustomerOrderDetailsRpcResponse; | 21 | import com.infoloop.tianting.clientcustomerorderservice.BatchUpdateClientCustomerOrderDetailsRpcResponse; |
| 18 | import com.infoloop.tianting.clientcustomerorderservice.BatchUpdateClientCustomerOrdersRpcRequest; | 22 | import com.infoloop.tianting.clientcustomerorderservice.BatchUpdateClientCustomerOrdersRpcRequest; |
| ... | @@ -42,13 +46,18 @@ import com.infoloop.tianting.clientcustomerorderservice.GetOrderOperationRecords | ... | @@ -42,13 +46,18 @@ import com.infoloop.tianting.clientcustomerorderservice.GetOrderOperationRecords |
| 42 | import com.infoloop.tianting.clientcustomerorderservice.GetOrderOperationRecordsByOrderIdResponse; | 46 | import com.infoloop.tianting.clientcustomerorderservice.GetOrderOperationRecordsByOrderIdResponse; |
| 43 | import com.infoloop.tianting.clientcustomerorderservice.OrderCountByStatus; | 47 | import com.infoloop.tianting.clientcustomerorderservice.OrderCountByStatus; |
| 44 | import com.infoloop.tianting.clientcustomerorderservice.OrderOperationRecord; | 48 | import com.infoloop.tianting.clientcustomerorderservice.OrderOperationRecord; |
| 49 | +import com.infoloop.tianting.clientcustomerorderservice.OrderSourceEnum; | ||
| 45 | import com.infoloop.tianting.clientcustomerorderservice.OrderStatusEnum; | 50 | import com.infoloop.tianting.clientcustomerorderservice.OrderStatusEnum; |
| 46 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByConditionRpcRequest; | 51 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByConditionRpcRequest; |
| 47 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByConditionRpcResponse; | 52 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByConditionRpcResponse; |
| 48 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByPaginationRpcRequest; | 53 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByPaginationRpcRequest; |
| 49 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByPaginationRpcResponse; | 54 | import com.infoloop.tianting.clientcustomerorderservice.QueryClientCustomerOrdersByPaginationRpcResponse; |
| 50 | -import com.infoloop.tianting.clientcustomerorderservice.SingleClientCustomerOrderDetailRpcResponse; | 55 | +import com.infoloop.tianting.clientcustomerorderservice.QuerySkuSellQuantitiesByStallAndSkuIdsRpcRequest; |
| 51 | -import com.infoloop.tianting.clientcustomerorderservice.SingleClientCustomerOrderRpcResponse; | 56 | +import com.infoloop.tianting.clientcustomerorderservice.QuerySkuSellQuantitiesByStallAndSkuIdsRpcResponse; |
| 57 | +import com.infoloop.tianting.clientcustomerorderservice.QuerySkuSellQuantitiesByStallRpcRequest; | ||
| 58 | +import com.infoloop.tianting.clientcustomerorderservice.QuerySkuSellQuantitiesByStallRpcResponse; | ||
| 59 | +import com.infoloop.tianting.clientcustomerorderservice.SingleSkuSellQuantityRpcResponse; | ||
| 60 | +import com.infoloop.tianting.clientcustomerorderservice.SkuSellQuantityModification; | ||
| 52 | import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrderDetailRpcRequest; | 61 | import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrderDetailRpcRequest; |
| 53 | import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrderDetailRpcResponse; | 62 | import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrderDetailRpcResponse; |
| 54 | import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrderRpcRequest; | 63 | import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrderRpcRequest; |
| ... | @@ -56,9 +65,11 @@ import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrde | ... | @@ -56,9 +65,11 @@ import com.infoloop.tianting.clientcustomerorderservice.UpdateClientCustomerOrde |
| 56 | import com.tianting.infoloop.model.db.OrderDb; | 65 | import com.tianting.infoloop.model.db.OrderDb; |
| 57 | import com.tianting.infoloop.model.db.OrderDetailDb; | 66 | import com.tianting.infoloop.model.db.OrderDetailDb; |
| 58 | import com.tianting.infoloop.model.db.OrderOperationRecordDb; | 67 | import com.tianting.infoloop.model.db.OrderOperationRecordDb; |
| 68 | +import com.tianting.infoloop.model.db.SkuSellQuantity; | ||
| 59 | import com.tianting.infoloop.service.OrderDbService; | 69 | import com.tianting.infoloop.service.OrderDbService; |
| 60 | import com.tianting.infoloop.service.OrderDetailDbService; | 70 | import com.tianting.infoloop.service.OrderDetailDbService; |
| 61 | import com.tianting.infoloop.service.OrderOperationRecordDbService; | 71 | import com.tianting.infoloop.service.OrderOperationRecordDbService; |
| 72 | +import com.tianting.infoloop.service.SkuSellQuantityService; | ||
| 62 | import com.tianting.infoloop.utils.DbToProtoUtil; | 73 | import com.tianting.infoloop.utils.DbToProtoUtil; |
| 63 | import com.tianting.infoloop.utils.ProtoBeanUtil; | 74 | import com.tianting.infoloop.utils.ProtoBeanUtil; |
| 64 | import io.grpc.Status; | 75 | import io.grpc.Status; |
| ... | @@ -68,9 +79,13 @@ import lombok.extern.slf4j.Slf4j; | ... | @@ -68,9 +79,13 @@ import lombok.extern.slf4j.Slf4j; |
| 68 | import org.springframework.beans.factory.annotation.Autowired; | 79 | import org.springframework.beans.factory.annotation.Autowired; |
| 69 | import org.springframework.stereotype.Service; | 80 | import org.springframework.stereotype.Service; |
| 70 | 81 | ||
| 82 | +import java.util.ArrayList; | ||
| 83 | +import java.util.List; | ||
| 84 | +import java.util.function.Function; | ||
| 71 | import java.util.stream.Collectors; | 85 | import java.util.stream.Collectors; |
| 72 | 86 | ||
| 73 | import static com.tianting.infoloop.constants.ConfigConstants.DATA_SOURCE_MASTER; | 87 | import static com.tianting.infoloop.constants.ConfigConstants.DATA_SOURCE_MASTER; |
| 88 | +import static com.tianting.infoloop.constants.ConfigConstants.DATA_SOURCE_SLAVE; | ||
| 74 | 89 | ||
| 75 | @Slf4j | 90 | @Slf4j |
| 76 | @Service | 91 | @Service |
| ... | @@ -79,6 +94,7 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu | ... | @@ -79,6 +94,7 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu |
| 79 | private final OrderDbService orderDbService; | 94 | private final OrderDbService orderDbService; |
| 80 | private final OrderDetailDbService orderDetailDbService; | 95 | private final OrderDetailDbService orderDetailDbService; |
| 81 | private final OrderOperationRecordDbService orderOperationRecordDbService; | 96 | private final OrderOperationRecordDbService orderOperationRecordDbService; |
| 97 | + private final SkuSellQuantityService skuSellQuantityService; | ||
| 82 | 98 | ||
| 83 | @Override | 99 | @Override |
| 84 | @DS(DATA_SOURCE_MASTER) | 100 | @DS(DATA_SOURCE_MASTER) |
| ... | @@ -203,7 +219,7 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu | ... | @@ -203,7 +219,7 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu |
| 203 | int preparingCount = 0; | 219 | int preparingCount = 0; |
| 204 | int allServedCount = 0; | 220 | int allServedCount = 0; |
| 205 | int canceledCount = 0; | 221 | int canceledCount = 0; |
| 206 | - for(OrderStatusEnum status: OrderStatusEnum.values()) { | 222 | + for (OrderStatusEnum status : OrderStatusEnum.values()) { |
| 207 | LambdaQueryWrapper<OrderDb> queryCountWrapper = Wrappers.lambdaQuery(); | 223 | LambdaQueryWrapper<OrderDb> queryCountWrapper = Wrappers.lambdaQuery(); |
| 208 | if (!request.getKeyword().isEmpty()) { | 224 | if (!request.getKeyword().isEmpty()) { |
| 209 | queryCountWrapper.like(OrderDb::getMealTime, request.getKeyword()); | 225 | queryCountWrapper.like(OrderDb::getMealTime, request.getKeyword()); |
| ... | @@ -627,8 +643,7 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu | ... | @@ -627,8 +643,7 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu |
| 627 | @DS(DATA_SOURCE_MASTER) | 643 | @DS(DATA_SOURCE_MASTER) |
| 628 | public void batchCreateOrderOperationRecords( | 644 | public void batchCreateOrderOperationRecords( |
| 629 | final BatchCreateOrderOperationRecordsRequest request, | 645 | final BatchCreateOrderOperationRecordsRequest request, |
| 630 | - final StreamObserver<BatchCreateOrderOperationRecordsResponse> responseStreamObserver | 646 | + final StreamObserver<BatchCreateOrderOperationRecordsResponse> responseStreamObserver) { |
| 631 | - ) { | ||
| 632 | final var builder = BatchCreateOrderOperationRecordsResponse.newBuilder(); | 647 | final var builder = BatchCreateOrderOperationRecordsResponse.newBuilder(); |
| 633 | try { | 648 | try { |
| 634 | final var data = orderOperationRecordDbService.batchCreateOrderOperationRecords(request); | 649 | final var data = orderOperationRecordDbService.batchCreateOrderOperationRecords(request); |
| ... | @@ -641,4 +656,129 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu | ... | @@ -641,4 +656,129 @@ public class OrderGrpcService extends ClientCustomerOrderServiceRpcGrpc.ClientCu |
| 641 | responseStreamObserver.onNext(builder.build()); | 656 | responseStreamObserver.onNext(builder.build()); |
| 642 | responseStreamObserver.onCompleted(); | 657 | responseStreamObserver.onCompleted(); |
| 643 | } | 658 | } |
| 659 | + | ||
| 660 | + @Override | ||
| 661 | + @DS(DATA_SOURCE_SLAVE) | ||
| 662 | + public void querySkuSellQuantitiesByStall(final QuerySkuSellQuantitiesByStallRpcRequest request, | ||
| 663 | + final StreamObserver<QuerySkuSellQuantitiesByStallRpcResponse> responseStreamObserver) { | ||
| 664 | + final var builder = QuerySkuSellQuantitiesByStallRpcResponse.newBuilder(); | ||
| 665 | + try { | ||
| 666 | + LambdaQueryWrapper<SkuSellQuantity> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 667 | + queryWrapper.eq(SkuSellQuantity::getEnterpriseId, request.getEnterpriseId()); | ||
| 668 | + queryWrapper.eq(SkuSellQuantity::getStallId, request.getStallId()); | ||
| 669 | + final var list = skuSellQuantityService.list(queryWrapper); | ||
| 670 | + builder.addAllResponses(ProtoBeanUtil.beanListToProtoList(list, SingleSkuSellQuantityRpcResponse.class)); | ||
| 671 | + } catch (final Exception e) { | ||
| 672 | + log.error("querySkuSellQuantitiesByStall error;", e); | ||
| 673 | + responseStreamObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asException()); | ||
| 674 | + } | ||
| 675 | + responseStreamObserver.onNext(builder.build()); | ||
| 676 | + responseStreamObserver.onCompleted(); | ||
| 677 | + } | ||
| 678 | + | ||
| 679 | + @Override | ||
| 680 | + @DS(DATA_SOURCE_SLAVE) | ||
| 681 | + public void querySkuSellQuantitiesByStallAndSkuIds(final QuerySkuSellQuantitiesByStallAndSkuIdsRpcRequest request, | ||
| 682 | + final StreamObserver<QuerySkuSellQuantitiesByStallAndSkuIdsRpcResponse> responseStreamObserver) { | ||
| 683 | + final var builder = QuerySkuSellQuantitiesByStallAndSkuIdsRpcResponse.newBuilder(); | ||
| 684 | + try { | ||
| 685 | + LambdaQueryWrapper<SkuSellQuantity> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 686 | + queryWrapper.eq(SkuSellQuantity::getEnterpriseId, request.getEnterpriseId()); | ||
| 687 | + queryWrapper.eq(SkuSellQuantity::getStallId, request.getStallId()); | ||
| 688 | + queryWrapper.in(SkuSellQuantity::getSkuId, request.getSkuIdsList()); | ||
| 689 | + final var list = skuSellQuantityService.list(queryWrapper); | ||
| 690 | + builder.addAllResponses(ProtoBeanUtil.beanListToProtoList(list, SingleSkuSellQuantityRpcResponse.class)); | ||
| 691 | + } catch (final Exception e) { | ||
| 692 | + log.error("querySkuSellQuantitiesByStallAndSkuIds error;", e); | ||
| 693 | + responseStreamObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asException()); | ||
| 694 | + } | ||
| 695 | + responseStreamObserver.onNext(builder.build()); | ||
| 696 | + responseStreamObserver.onCompleted(); | ||
| 697 | + } | ||
| 698 | + | ||
| 699 | + @Override | ||
| 700 | + @DS(DATA_SOURCE_MASTER) | ||
| 701 | + public void batchSaveSkuSellQuantities(final BatchSaveSkuSellQuantitiesRpcRequest request, | ||
| 702 | + final StreamObserver<BatchSaveSkuSellQuantitiesRpcResponse> responseStreamObserver) { | ||
| 703 | + final var builder = BatchSaveSkuSellQuantitiesRpcResponse.newBuilder(); | ||
| 704 | + try { | ||
| 705 | + List<SkuSellQuantity> skuSellQuantities = new ArrayList<>(); | ||
| 706 | + for (SkuSellQuantityModification skuSellQuantityModification : request.getSkuSellQuantityModificationsList()) { | ||
| 707 | + SkuSellQuantity skuSellQuantity = new SkuSellQuantity(); | ||
| 708 | + skuSellQuantity.setId(skuSellQuantityModification.getId() == 0 ? null : skuSellQuantityModification.getId()); | ||
| 709 | + skuSellQuantity.setEnterpriseId(request.getEnterpriseId()); | ||
| 710 | + skuSellQuantity.setStallId(skuSellQuantityModification.getStallId()); | ||
| 711 | + skuSellQuantity.setSkuId(skuSellQuantityModification.getSkuId()); | ||
| 712 | + skuSellQuantity.setMaxSellQuantity(skuSellQuantityModification.getMaxSellQuantity()); | ||
| 713 | + skuSellQuantity.setCreatedBy(request.getUpdatedBy()); | ||
| 714 | + skuSellQuantity.setCreationSource(OrderSourceEnum.STALL_VALUE); | ||
| 715 | + skuSellQuantity.setUpdatedBy(request.getUpdatedBy()); | ||
| 716 | + skuSellQuantity.setUpdateSource(OrderSourceEnum.STALL_VALUE); | ||
| 717 | + skuSellQuantities.add(skuSellQuantity); | ||
| 718 | + } | ||
| 719 | + final boolean saveOrUpdateBatch = skuSellQuantityService.saveOrUpdateBatch(skuSellQuantities); | ||
| 720 | + builder.setIsSaved(saveOrUpdateBatch); | ||
| 721 | + } catch (final Exception e) { | ||
| 722 | + log.error("batchSaveSkuSellQuantities error;", e); | ||
| 723 | + responseStreamObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asException()); | ||
| 724 | + } | ||
| 725 | + responseStreamObserver.onNext(builder.build()); | ||
| 726 | + responseStreamObserver.onCompleted(); | ||
| 727 | + } | ||
| 728 | + | ||
| 729 | + @Override | ||
| 730 | + @DS(DATA_SOURCE_MASTER) | ||
| 731 | + public void addSkusSellQuantities(final AddSkusSellQuantitiesRpcRequest request, | ||
| 732 | + final StreamObserver<AddSkusSellQuantitiesRpcResponse> responseStreamObserver) { | ||
| 733 | + final var builder = AddSkusSellQuantitiesRpcResponse.newBuilder(); | ||
| 734 | + try { | ||
| 735 | + LambdaQueryWrapper<SkuSellQuantity> queryWrapper = new LambdaQueryWrapper<>(); | ||
| 736 | + queryWrapper.eq(SkuSellQuantity::getEnterpriseId, request.getEnterpriseId()); | ||
| 737 | + queryWrapper.eq(SkuSellQuantity::getStallId, request.getStallId()); | ||
| 738 | + queryWrapper.in(SkuSellQuantity::getSkuId, request.getSkuSellQuantitiesList().stream() | ||
| 739 | + .map(com.infoloop.tianting.clientcustomerorderservice.SkuSellQuantity::getSkuId) | ||
| 740 | + .collect(Collectors.toList())); | ||
| 741 | + final var list = skuSellQuantityService.list(queryWrapper.last("FOR UPDATE")); | ||
| 742 | + final var skuSellQuantityMap = list.stream().collect(Collectors.toMap(SkuSellQuantity::getSkuId, Function.identity())); | ||
| 743 | + final var updates = new ArrayList<SkuSellQuantity>(); | ||
| 744 | + for (var sellQuantity : request.getSkuSellQuantitiesList()) { | ||
| 745 | + final var skuSellQuantity = skuSellQuantityMap.get(sellQuantity.getSkuId()); | ||
| 746 | + if (skuSellQuantity == null) { | ||
| 747 | + throw new IllegalArgumentException("addSkusSellQuantities skuId not exists; " + sellQuantity.getSkuId()); | ||
| 748 | + } | ||
| 749 | + final int quantity = sellQuantity.getQuantity(); | ||
| 750 | + if (quantity < 0) { | ||
| 751 | + log.info("Negative quantity detected; skuId={}, quantity={}", sellQuantity.getSkuId(), quantity); | ||
| 752 | + } | ||
| 753 | + final int todaySellQuantity = skuSellQuantity.getTodaySellQuantity() + quantity; | ||
| 754 | + if (todaySellQuantity < 0) { | ||
| 755 | + log.error("Negative total todaySellQuantity; skuId={}, todaySellQuantity={}", sellQuantity.getSkuId(), todaySellQuantity); | ||
| 756 | + builder.setIsAdded(false); | ||
| 757 | + responseStreamObserver.onNext(builder.build()); | ||
| 758 | + responseStreamObserver.onCompleted(); | ||
| 759 | + return; | ||
| 760 | + } | ||
| 761 | + if (todaySellQuantity > skuSellQuantity.getMaxSellQuantity()) { | ||
| 762 | + log.error("addSkusSellQuantities quantity exceeds maxSellQuantity; skuId={}, quantity={}, maxSellQuantity={}", sellQuantity.getSkuId(), sellQuantity.getQuantity(), skuSellQuantity.getMaxSellQuantity()); | ||
| 763 | + builder.setIsAdded(false); | ||
| 764 | + responseStreamObserver.onNext(builder.build()); | ||
| 765 | + responseStreamObserver.onCompleted(); | ||
| 766 | + return; | ||
| 767 | + } | ||
| 768 | + updates.add(new SkuSellQuantity() | ||
| 769 | + .setId(skuSellQuantity.getId()) | ||
| 770 | + .setTodaySellQuantity(todaySellQuantity)); | ||
| 771 | + } | ||
| 772 | + if (!updates.isEmpty()) { | ||
| 773 | + builder.setIsAdded(skuSellQuantityService.updateBatchById(updates)); | ||
| 774 | + } | ||
| 775 | + } catch (final Exception e) { | ||
| 776 | + log.error("addSkusSellQuantities error;", e); | ||
| 777 | + responseStreamObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asException()); | ||
| 778 | + return; | ||
| 779 | + } | ||
| 780 | + responseStreamObserver.onNext(builder.build()); | ||
| 781 | + responseStreamObserver.onCompleted(); | ||
| 782 | + } | ||
| 783 | + | ||
| 644 | } | 784 | } | ... | ... |
| 1 | +package com.tianting.infoloop.service.impl; | ||
| 2 | + | ||
| 3 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
| 4 | +import com.tianting.infoloop.mapper.SkuSellQuantityMapper; | ||
| 5 | +import com.tianting.infoloop.model.db.SkuSellQuantity; | ||
| 6 | +import com.tianting.infoloop.service.SkuSellQuantityService; | ||
| 7 | +import org.springframework.stereotype.Service; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | +* @author zhuyf | ||
| 11 | +* @description 针对表【sku_sell_quantities(sku售卖量)】的数据库操作Service实现 | ||
| 12 | +* @createDate 2025-02-28 14:03:59 | ||
| 13 | +*/ | ||
| 14 | +@Service | ||
| 15 | +public class SkuSellQuantityServiceImpl extends ServiceImpl<SkuSellQuantityMapper, SkuSellQuantity> implements SkuSellQuantityService { | ||
| 16 | + | ||
| 17 | +} |
| ... | @@ -33,6 +33,14 @@ service ClientCustomerOrderServiceRpc { | ... | @@ -33,6 +33,14 @@ service ClientCustomerOrderServiceRpc { |
| 33 | // 操作记录 | 33 | // 操作记录 |
| 34 | rpc GetOrderOperationRecordsByOrderId (GetOrderOperationRecordsByOrderIdRequest) returns (GetOrderOperationRecordsByOrderIdResponse) {} | 34 | rpc GetOrderOperationRecordsByOrderId (GetOrderOperationRecordsByOrderIdRequest) returns (GetOrderOperationRecordsByOrderIdResponse) {} |
| 35 | rpc BatchCreateOrderOperationRecords (BatchCreateOrderOperationRecordsRequest) returns (BatchCreateOrderOperationRecordsResponse) {} | 35 | rpc BatchCreateOrderOperationRecords (BatchCreateOrderOperationRecordsRequest) returns (BatchCreateOrderOperationRecordsResponse) {} |
| 36 | + | ||
| 37 | + | ||
| 38 | + // sku菜品库存 | ||
| 39 | + rpc QuerySkuSellQuantitiesByStall(QuerySkuSellQuantitiesByStallRpcRequest) returns (QuerySkuSellQuantitiesByStallRpcResponse) {} | ||
| 40 | + rpc QuerySkuSellQuantitiesByStallAndSkuIds(QuerySkuSellQuantitiesByStallAndSkuIdsRpcRequest) returns (QuerySkuSellQuantitiesByStallAndSkuIdsRpcResponse) {} | ||
| 41 | + rpc BatchSaveSkuSellQuantities(BatchSaveSkuSellQuantitiesRpcRequest) returns (BatchSaveSkuSellQuantitiesRpcResponse) {} | ||
| 42 | + rpc AddSkusSellQuantities(AddSkusSellQuantitiesRpcRequest) returns (AddSkusSellQuantitiesRpcResponse) {} | ||
| 43 | + | ||
| 36 | } | 44 | } |
| 37 | 45 | ||
| 38 | enum OrderStatusEnum { | 46 | enum OrderStatusEnum { |
| ... | @@ -608,3 +616,71 @@ message BatchCreateOrderOperationRecordsResponse { | ... | @@ -608,3 +616,71 @@ message BatchCreateOrderOperationRecordsResponse { |
| 608 | bool isCreated = 1; | 616 | bool isCreated = 1; |
| 609 | repeated int32 ids = 2; | 617 | repeated int32 ids = 2; |
| 610 | } | 618 | } |
| 619 | + | ||
| 620 | +message SingleSkuSellQuantityRpcResponse { | ||
| 621 | + int32 id = 1; | ||
| 622 | + int32 enterpriseId = 2; | ||
| 623 | + int32 stallId = 3; | ||
| 624 | + int32 skuId = 4; | ||
| 625 | + int32 maxSellQuantity = 5; | ||
| 626 | + int32 todaySellQuantity = 6; | ||
| 627 | + int32 createdBy = 7; | ||
| 628 | + int64 createdAt = 8; | ||
| 629 | + int32 creationSource = 9; | ||
| 630 | + int32 updatedBy = 10; | ||
| 631 | + int64 updatedAt = 11; | ||
| 632 | + int32 updateSource = 12; | ||
| 633 | + bool isDeleted = 13; | ||
| 634 | +} | ||
| 635 | + | ||
| 636 | +message QuerySkuSellQuantitiesByStallRpcRequest { | ||
| 637 | + int32 enterpriseId = 1; | ||
| 638 | + int32 stallId = 2; | ||
| 639 | +} | ||
| 640 | + | ||
| 641 | +message QuerySkuSellQuantitiesByStallRpcResponse { | ||
| 642 | + repeated SingleSkuSellQuantityRpcResponse responses = 1; | ||
| 643 | +} | ||
| 644 | + | ||
| 645 | +message QuerySkuSellQuantitiesByStallAndSkuIdsRpcRequest { | ||
| 646 | + int32 enterpriseId = 1; | ||
| 647 | + int32 stallId = 2; | ||
| 648 | + repeated int32 skuIds = 3; | ||
| 649 | +} | ||
| 650 | + | ||
| 651 | +message QuerySkuSellQuantitiesByStallAndSkuIdsRpcResponse { | ||
| 652 | + repeated SingleSkuSellQuantityRpcResponse responses = 1; | ||
| 653 | +} | ||
| 654 | + | ||
| 655 | +message BatchSaveSkuSellQuantitiesRpcRequest { | ||
| 656 | + repeated SkuSellQuantityModification skuSellQuantityModifications = 1; | ||
| 657 | + int32 enterpriseId = 2; | ||
| 658 | + int32 updatedBy = 3; | ||
| 659 | + int32 updateSource = 4; | ||
| 660 | +} | ||
| 661 | + | ||
| 662 | +message SkuSellQuantityModification { | ||
| 663 | + int32 id = 1; | ||
| 664 | + int32 stallId = 2; | ||
| 665 | + int32 skuId = 3; | ||
| 666 | + int32 maxSellQuantity = 4; | ||
| 667 | +} | ||
| 668 | + | ||
| 669 | +message BatchSaveSkuSellQuantitiesRpcResponse { | ||
| 670 | + bool isSaved = 1; | ||
| 671 | +} | ||
| 672 | + | ||
| 673 | +message AddSkusSellQuantitiesRpcRequest { | ||
| 674 | + int32 enterpriseId = 1; | ||
| 675 | + int32 stallId = 2; | ||
| 676 | + repeated SkuSellQuantity skuSellQuantities = 3; | ||
| 677 | +} | ||
| 678 | + | ||
| 679 | +message SkuSellQuantity { | ||
| 680 | + int32 skuId = 1; | ||
| 681 | + int32 quantity = 2; | ||
| 682 | +} | ||
| 683 | + | ||
| 684 | +message AddSkusSellQuantitiesRpcResponse { | ||
| 685 | + bool isAdded = 1; | ||
| 686 | +} | ... | ... |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="com.tianting.infoloop.mapper.SkuSellQuantityMapper"> | ||
| 6 | + | ||
| 7 | + <resultMap id="BaseResultMap" type="com.tianting.infoloop.model.db.SkuSellQuantity"> | ||
| 8 | + <id property="id" column="id" jdbcType="INTEGER"/> | ||
| 9 | + <result property="enterpriseId" column="enterpriseId" jdbcType="INTEGER"/> | ||
| 10 | + <result property="stallId" column="stallId" jdbcType="INTEGER"/> | ||
| 11 | + <result property="skuId" column="skuId" jdbcType="INTEGER"/> | ||
| 12 | + <result property="maxSellQuantity" column="maxSellQuantity" jdbcType="INTEGER"/> | ||
| 13 | + <result property="todaySellQuantity" column="todaySellQuantity" jdbcType="INTEGER"/> | ||
| 14 | + <result property="createdBy" column="createdBy" jdbcType="INTEGER"/> | ||
| 15 | + <result property="createdAt" column="createdAt" jdbcType="TIMESTAMP"/> | ||
| 16 | + <result property="creationSource" column="creationSource" jdbcType="INTEGER"/> | ||
| 17 | + <result property="updatedBy" column="updatedBy" jdbcType="INTEGER"/> | ||
| 18 | + <result property="updatedAt" column="updatedAt" jdbcType="TIMESTAMP"/> | ||
| 19 | + <result property="updateSource" column="updateSource" jdbcType="INTEGER"/> | ||
| 20 | + <result property="isDeleted" column="isDeleted" jdbcType="TINYINT"/> | ||
| 21 | + </resultMap> | ||
| 22 | + | ||
| 23 | + <sql id="Base_Column_List"> | ||
| 24 | + id,enterpriseId,stallId, | ||
| 25 | + skuId,maxSellQuantity,todaySellQuantity, | ||
| 26 | + createdBy,createdAt,creationSource, | ||
| 27 | + updatedBy,updatedAt,updateSource, | ||
| 28 | + isDeleted | ||
| 29 | + </sql> | ||
| 30 | +</mapper> |
-
Please register or login to post a comment