Toggle navigation
Toggle navigation
This project
Loading...
Sign in
jiujian
/
client-customer-order-api
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhuyifan
2025-03-01 18:26:40 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c90dfac5844979dd2d492c8af582a5b09e130537
c90dfac5
1 parent
9a83017c
菜品售卖量接口
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
src/main/java/com/infoloop/tianting/exception/ErrorCodeEnum.java
src/main/java/com/infoloop/tianting/service/client/OrderServiceRpcClient.java
src/main/java/com/infoloop/tianting/exception/ErrorCodeEnum.java
View file @
c90dfac
...
...
@@ -30,7 +30,9 @@ public enum ErrorCodeEnum implements BaseEnum {
QUERY_CLIENT_CUSTOMER_ERROR
(
406000006
,
"获取当日在住客户失败"
),
SKUS_SOLD_OUT_TODAY
(
406000007
,
"下单菜品今日售罄"
),
SKUS_SOLD_OUT_TODAY
(
406000007
,
"下单菜品\n{0}\n今日已售罄"
),
SKUS_STOCK_NO_ENOUGH_TODAY
(
406000007
,
"下单菜品\n{0}\n库存不足"
),
ORDER_CANCEL
(
406000008
,
"订单已自动取消"
)
;
...
...
src/main/java/com/infoloop/tianting/service/client/OrderServiceRpcClient.java
View file @
c90dfac
package
com
.
infoloop
.
tianting
.
service
.
client
;
import
com.infoloop.tianting.SingleResponse
;
import
com.infoloop.tianting.SingleSkuResponse
;
import
com.infoloop.tianting.SingleSpecialResponse
;
import
com.infoloop.tianting.clientcustomerorderservice.AddSkusSellQuantitiesRpcRequest
;
import
com.infoloop.tianting.clientcustomerorderservice.BatchCreateOrderOperationRecordsRequest
;
...
...
@@ -73,6 +74,7 @@ import javax.annotation.Nullable;
import
java.time.LocalDate
;
import
java.time.ZoneOffset
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Function
;
...
...
@@ -222,8 +224,7 @@ public class OrderServiceRpcClient {
final
var
skuAvoids
=
rpcSkus
.
get
(
0
).
getAvoidsList
().
stream
().
map
(
SingleResponse:
:
getName
).
collect
(
Collectors
.
toList
());
final
var
tastes
=
rpcSkus
.
get
(
0
).
getTastesList
().
stream
().
map
(
SingleResponse:
:
getName
).
collect
(
Collectors
.
toList
());
final
var
efficacies
=
rpcSkus
.
get
(
0
).
getEfficaciesList
().
stream
().
map
(
SingleResponse:
:
getName
).
collect
(
Collectors
.
toList
());
final
var
allergies
=
rpcSkus
.
get
(
0
).
getAllergiesList
().
stream
().
map
(
SingleSpecialResponse:
:
getName
).
collect
(
Collectors
.
toList
());
final
var
allergies
=
rpcSkus
.
get
(
0
).
getAllergiesList
().
stream
().
map
(
SingleSpecialResponse:
:
getName
).
collect
(
Collectors
.
toList
());
final
var
skuDoctors
=
rpcSkus
.
get
(
0
).
getDoctorsList
().
stream
().
map
(
SingleSpecialResponse:
:
getName
).
collect
(
Collectors
.
toList
());
mealDetail
=
MealDetail
.
newBuilder
()
.
setBasicMaterials
(
rpcSkus
.
get
(
0
).
getBasicMaterials
())
...
...
@@ -567,15 +568,29 @@ public class OrderServiceRpcClient {
final
var
skuIds
=
createOrderDto
.
getOrderDetailDtos
().
stream
().
map
(
CreateOrderDetailDto:
:
getSkuId
).
collect
(
Collectors
.
toList
());
final
var
skuSellQuantities
=
this
.
querySkuSellQuantitiesByStallAndSkuIds
(
createOrderDto
.
getEnterpriseId
(),
createOrderDto
.
getStallId
(),
skuIds
);
final
var
skuSellQuantityMap
=
skuSellQuantities
.
stream
().
collect
(
Collectors
.
toMap
(
SingleSkuSellQuantityRpcResponse:
:
getSkuId
,
Function
.
identity
()));
final
var
skuMap
=
skuServiceRpcClient
.
getSkusByIds
(
skuIds
).
stream
().
collect
(
Collectors
.
toMap
(
SingleSkuResponse:
:
getId
,
Function
.
identity
()));
final
var
soldOutSkus
=
new
ArrayList
<
String
>();
final
var
skuStockMap
=
new
HashMap
<
String
,
Integer
>();
for
(
var
orderDetail
:
createOrderDto
.
getOrderDetailDtos
())
{
final
var
skuSellQuantityRpcResponse
=
skuSellQuantityMap
.
get
(
orderDetail
.
getSkuId
());
if
(
skuSellQuantityRpcResponse
==
null
)
{
throw
ClientEndExceptions
.
BusinessException
.
build
(
ErrorCodeEnum
.
SKUS_SOLD_OUT_TODAY
);
log
.
error
(
"skuSellQuantityRpcResponse is null; stallId:{}, skuId:{}"
,
createOrderDto
.
getStallId
(),
orderDetail
.
getSkuId
());
soldOutSkus
.
add
(
skuMap
.
get
(
orderDetail
.
getSkuId
()).
getName
());
continue
;
}
if
((
skuSellQuantityRpcResponse
.
getTodaySellQuantity
()
+
orderDetail
.
getSkuId
())
>
skuSellQuantityRpcResponse
.
getMaxSellQuantity
())
{
throw
ClientEndExceptions
.
BusinessException
.
build
(
ErrorCodeEnum
.
SKUS_SOLD_OUT_TODAY
);
if
((
skuSellQuantityRpcResponse
.
getTodaySellQuantity
()
+
orderDetail
.
getCount
())
>
skuSellQuantityRpcResponse
.
getMaxSellQuantity
())
{
log
.
error
(
"skuSellQuantityRpcResponse stock no enough; stallId:{}, skuId:{}, count:{}"
,
createOrderDto
.
getStallId
(),
orderDetail
.
getSkuId
(),
orderDetail
.
getCount
());
skuStockMap
.
put
(
skuMap
.
get
(
orderDetail
.
getSkuId
()).
getName
(),
skuSellQuantityRpcResponse
.
getMaxSellQuantity
()
-
skuSellQuantityRpcResponse
.
getTodaySellQuantity
());
continue
;
}
}
if
(!
soldOutSkus
.
isEmpty
())
{
throw
ClientEndExceptions
.
BusinessException
.
build
(
ErrorCodeEnum
.
SKUS_SOLD_OUT_TODAY
,
String
.
join
(
","
,
soldOutSkus
));
}
if
(!
skuStockMap
.
isEmpty
())
{
final
var
noEnoughSkus
=
String
.
join
(
", "
,
skuStockMap
.
keySet
());
throw
ClientEndExceptions
.
BusinessException
.
build
(
ErrorCodeEnum
.
SKUS_STOCK_NO_ENOUGH_TODAY
,
noEnoughSkus
);
}
}
final
var
orderResponse
=
orderServiceRpcBlockingStub
.
createClientCustomerOrder
(
CreateClientCustomerOrderRpcRequest
.
newBuilder
()
...
...
Please
register
or
login
to post a comment