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-04-15 13:49:01 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
171a6e112d62fd290d042832f84869271f76f4af
171a6e11
1 parent
30f81e13
自动创建餐单
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
26 deletions
src/main/java/com/infoloop/tianting/logic/task/AutoCreateMealOrderTask.java
src/main/java/com/infoloop/tianting/service/client/MealOrderServiceRpcClient.java
src/main/java/com/infoloop/tianting/service/impl/MealOrderServiceImpl.java
src/main/java/com/infoloop/tianting/service/impl/MenuServiceImpl.java
src/main/proto/MealOrderService.proto
src/main/java/com/infoloop/tianting/logic/task/AutoCreateMealOrderTask.java
0 → 100644
View file @
171a6e1
package
com
.
infoloop
.
tianting
.
logic
.
task
;
import
com.infoloop.tianting.clientinventoryservice.SingleClientRpcResponse
;
import
com.infoloop.tianting.context.LoginContextHolder
;
import
com.infoloop.tianting.enums.LoginSourceEnum
;
import
com.infoloop.tianting.mealorderservice.MealOrderCreation
;
import
com.infoloop.tianting.mealorderservice.MealOrderOrderMethodEnum
;
import
com.infoloop.tianting.mealorderservice.MenuSchedule
;
import
com.infoloop.tianting.mealorderservice.SingleDinerRpcResponse
;
import
com.infoloop.tianting.mealorderservice.SingleGradeClassRpcResponse
;
import
com.infoloop.tianting.mealorderservice.SingleMealMenuRecordRpcResponse
;
import
com.infoloop.tianting.mealorderservice.SingleMealOrderRpcResponse
;
import
com.infoloop.tianting.service.client.ClientInventoryServiceRpcClient
;
import
com.infoloop.tianting.service.client.MealOrderServiceRpcClient
;
import
com.infoloop.tianting.utils.DateUtil
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.time.DayOfWeek
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.LocalTime
;
import
java.util.ArrayList
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@Slf4j
@Component
@RequiredArgsConstructor
public
class
AutoCreateMealOrderTask
{
private
final
MealOrderServiceRpcClient
mealOrderServiceRpcClient
;
private
final
ClientInventoryServiceRpcClient
clientInventoryServiceRpcClient
;
@Scheduled
(
cron
=
"0 0 13 ? * WED"
)
public
void
executeTask
()
{
int
enterpriseId
=
449
;
final
var
today
=
LocalDate
.
now
();
final
var
zonedDateTime
=
today
.
with
(
DayOfWeek
.
MONDAY
).
atStartOfDay
().
atZone
(
DateUtil
.
CHINA_ZONE
);
final
var
startTimestamp
=
zonedDateTime
.
toInstant
().
toEpochMilli
();
final
var
endTimestamp
=
today
.
with
(
DayOfWeek
.
SUNDAY
).
atTime
(
LocalTime
.
MAX
).
atZone
(
DateUtil
.
CHINA_ZONE
).
toInstant
().
toEpochMilli
();
final
var
mealOrders
=
mealOrderServiceRpcClient
.
queryMealOrdersByCondition
(
449
,
null
,
startTimestamp
,
endTimestamp
);
final
var
dinerIds
=
mealOrders
.
stream
().
map
(
SingleMealOrderRpcResponse:
:
getDinerId
).
toList
();
final
var
allDiners
=
mealOrderServiceRpcClient
.
queryDinersByCondition
(
enterpriseId
,
null
,
null
,
null
);
final
var
notReservedDiners
=
allDiners
.
stream
().
filter
(
diner
->
!
dinerIds
.
contains
(
diner
.
getId
())).
toList
();
final
var
clientIds
=
notReservedDiners
.
stream
().
map
(
SingleDinerRpcResponse:
:
getClientId
).
distinct
().
toList
();
final
var
clientMap
=
clientInventoryServiceRpcClient
.
getClientsByIds
(
enterpriseId
,
clientIds
).
getClientsList
().
stream
().
collect
(
Collectors
.
toMap
(
SingleClientRpcResponse:
:
getId
,
Function
.
identity
()));
final
var
gradeClassMap
=
mealOrderServiceRpcClient
.
getGradeClassesByIds
(
enterpriseId
,
notReservedDiners
.
stream
().
map
(
SingleDinerRpcResponse:
:
getClassId
).
distinct
().
toList
()).
stream
().
collect
(
Collectors
.
toMap
(
SingleGradeClassRpcResponse:
:
getId
,
Function
.
identity
()));
final
var
latestMealMenuRecordMap
=
mealOrderServiceRpcClient
.
queryLatestMealMenuRecordsByClientIds
(
enterpriseId
,
clientIds
).
stream
().
collect
(
Collectors
.
toMap
(
SingleMealMenuRecordRpcResponse:
:
getClientId
,
Function
.
identity
()));
final
var
creations
=
new
ArrayList
<
MealOrderCreation
>();
for
(
var
diner
:
notReservedDiners
)
{
final
var
mealMenuRecordRpcResponse
=
latestMealMenuRecordMap
.
get
(
diner
.
getClientId
());
if
(
mealMenuRecordRpcResponse
==
null
)
{
continue
;
}
final
var
singleClientRpcResponse
=
clientMap
.
get
(
diner
.
getClientId
());
if
(
singleClientRpcResponse
==
null
)
{
continue
;
}
final
var
singleGradeClassRpcResponse
=
gradeClassMap
.
get
(
diner
.
getClassId
());
if
(
singleGradeClassRpcResponse
==
null
)
{
continue
;
}
MealOrderCreation
.
newBuilder
()
.
setClientId
(
diner
.
getClientId
())
.
setMenuId
(
mealMenuRecordRpcResponse
.
getId
())
.
setAccountId
(
0
)
.
setOrderMethod
(
MealOrderOrderMethodEnum
.
MEAL_ORDER_METHOD_SYSTEM
)
.
setDinerId
(
diner
.
getId
())
.
setDinerName
(
diner
.
getName
())
.
setClientName
(
singleClientRpcResponse
.
getName
())
.
setGradeName
(
singleGradeClassRpcResponse
.
getGradeName
())
.
setClassName
(
singleGradeClassRpcResponse
.
getClassName
())
.
setStudentNo
(
diner
.
getStudentNo
())
.
setReserveDate
(
Instant
.
now
().
toEpochMilli
())
.
addMeals
(
MenuSchedule
.
newBuilder
().
setDate
(
zonedDateTime
.
format
(
DateUtil
.
YYYY_MM_DD_LEFT_SYMBOL
)).
setMenu
(
"A"
).
build
())
.
addMeals
(
MenuSchedule
.
newBuilder
().
setDate
(
zonedDateTime
.
plusDays
(
1
).
format
(
DateUtil
.
YYYY_MM_DD_LEFT_SYMBOL
)).
setMenu
(
"A"
).
build
())
.
addMeals
(
MenuSchedule
.
newBuilder
().
setDate
(
zonedDateTime
.
plusDays
(
2
).
format
(
DateUtil
.
YYYY_MM_DD_LEFT_SYMBOL
)).
setMenu
(
"A"
).
build
())
.
addMeals
(
MenuSchedule
.
newBuilder
().
setDate
(
zonedDateTime
.
plusDays
(
3
).
format
(
DateUtil
.
YYYY_MM_DD_LEFT_SYMBOL
)).
setMenu
(
"A"
).
build
())
.
addMeals
(
MenuSchedule
.
newBuilder
().
setDate
(
zonedDateTime
.
plusDays
(
4
).
format
(
DateUtil
.
YYYY_MM_DD_LEFT_SYMBOL
)).
setMenu
(
"A"
).
build
())
.
build
();
}
final
var
loginInfo
=
LoginContextHolder
.
LoginInfo
.
builder
()
.
id
(
0
)
.
enterpriseId
(
enterpriseId
)
.
loginSource
(
LoginSourceEnum
.
MINI_PROGRAM
)
.
build
();
mealOrderServiceRpcClient
.
batchCreateMealOrders
(
loginInfo
,
creations
);
}
}
src/main/java/com/infoloop/tianting/service/client/MealOrderServiceRpcClient.java
View file @
171a6e1
...
...
@@ -33,7 +33,7 @@ import com.infoloop.tianting.mealorderservice.MpAccountDinerRefCreation;
import
com.infoloop.tianting.mealorderservice.MpAccountModification
;
import
com.infoloop.tianting.mealorderservice.QueryDinersByConditionRpcRequest
;
import
com.infoloop.tianting.mealorderservice.QueryGradeClassesByConditionRpcRequest
;
import
com.infoloop.tianting.mealorderservice.QueryLatestMealMenuRecord
ByClientId
RpcRequest
;
import
com.infoloop.tianting.mealorderservice.QueryLatestMealMenuRecord
sByClientIds
RpcRequest
;
import
com.infoloop.tianting.mealorderservice.QueryMealOrdersByConditionRpcRequest
;
import
com.infoloop.tianting.mealorderservice.QueryMpAccountDinerRefsByConditionRpcRequest
;
import
com.infoloop.tianting.mealorderservice.QueryReserveMealOrdersByDinerIdsRpcRequest
;
...
...
@@ -48,10 +48,13 @@ import com.infoloop.tianting.mealorderservice.UpdateDinerRpcResponse;
import
com.infoloop.tianting.mealorderservice.UpdateMpAccountRpcRequest
;
import
com.infoloop.tianting.mealorderservice.UpdateMpAccountRpcResponse
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Nullable
;
import
java.util.Collections
;
import
java.util.List
;
@Service
...
...
@@ -129,9 +132,9 @@ public class MealOrderServiceRpcClient {
public
List
<
SingleDinerRpcResponse
>
queryDinersByCondition
(
int
enterpriseId
,
List
<
Integer
>
clientIds
,
List
<
Integer
>
gradeClassIds
,
@Nullable
String
studentNo
)
{
return
mealOrderServiceRpcBlockingStub
.
queryDinersByCondition
(
QueryDinersByConditionRpcRequest
.
newBuilder
()
.
setEnterpriseId
(
enterpriseId
)
.
setShouldFilterClientIds
(
!
clientIds
.
isEmpty
()).
addAllClientIds
(
clientIds
)
.
setShouldFilterClassIds
(
!
gradeClassIds
.
isEmpty
()).
addAllClassIds
(
gradeClassIds
)
.
setShouldFilterStudentNo
(
studentNo
!=
null
).
setStudentNo
(
studentNo
==
null
?
""
:
studentNo
)
.
setShouldFilterClientIds
(
CollectionUtils
.
isNotEmpty
(
clientIds
)).
addAllClientIds
(
CollectionUtils
.
isEmpty
(
clientIds
)
?
Collections
.
emptyList
()
:
clientIds
)
.
setShouldFilterClassIds
(
CollectionUtils
.
isNotEmpty
(
gradeClassIds
)).
addAllClassIds
(
CollectionUtils
.
isNotEmpty
(
gradeClassIds
)
?
gradeClassIds
:
Collections
.
emptyList
()
)
.
setShouldFilterStudentNo
(
StringUtils
.
isNotEmpty
(
studentNo
)).
setStudentNo
(
StringUtils
.
isNotEmpty
(
studentNo
)
?
studentNo
:
""
)
.
build
()).
getResponsesList
();
}
...
...
@@ -211,16 +214,11 @@ public class MealOrderServiceRpcClient {
.
build
()).
getResponsesList
();
}
@Nullable
public
SingleMealMenuRecordRpcResponse
queryLatestMealMenuRecordByClientId
(
int
enterpriseId
,
int
id
)
{
final
var
queryLatestMealMenuRecordByClientIdRpcResponse
=
mealOrderServiceRpcBlockingStub
.
queryLatestMealMenuRecordByClientId
(
QueryLatestMealMenuRecordByClientIdRpcRequest
.
newBuilder
()
public
List
<
SingleMealMenuRecordRpcResponse
>
queryLatestMealMenuRecordsByClientIds
(
int
enterpriseId
,
List
<
Integer
>
ids
)
{
return
mealOrderServiceRpcBlockingStub
.
queryLatestMealMenuRecordsByClientIds
(
QueryLatestMealMenuRecordsByClientIdsRpcRequest
.
newBuilder
()
.
setEnterpriseId
(
enterpriseId
)
.
setClientId
(
id
)
.
build
());
if
(!
queryLatestMealMenuRecordByClientIdRpcResponse
.
hasResponse
())
{
return
null
;
}
return
queryLatestMealMenuRecordByClientIdRpcResponse
.
getResponse
();
.
addAllClientId
(
ids
)
.
build
()).
getResponsesList
();
}
@Nullable
...
...
@@ -253,10 +251,12 @@ public class MealOrderServiceRpcClient {
.
build
());
}
public
List
<
SingleMealOrderRpcResponse
>
queryMealOrdersByCondition
(
int
enterpriseId
,
int
accountI
d
)
{
public
List
<
SingleMealOrderRpcResponse
>
queryMealOrdersByCondition
(
int
enterpriseId
,
Integer
accountId
,
Long
reserveDateStart
,
Long
reserveDateEn
d
)
{
return
mealOrderServiceRpcBlockingStub
.
queryMealOrdersByCondition
(
QueryMealOrdersByConditionRpcRequest
.
newBuilder
()
.
setEnterpriseId
(
enterpriseId
)
.
setShouldFilterAccountIds
(
true
).
addAccountIds
(
accountId
)
.
setShouldFilterAccountIds
(
accountId
!=
null
).
addAccountIds
(
accountId
==
null
?
0
:
accountId
)
.
setShouldFilterReserveDateStart
(
true
).
setReserveDateStart
(
reserveDateStart
==
null
?
0
:
reserveDateStart
)
.
setShouldFilterReserveDateEnd
(
true
).
setReserveDateEnd
(
reserveDateEnd
==
null
?
0
:
reserveDateEnd
)
.
build
()).
getResponsesList
();
}
}
...
...
src/main/java/com/infoloop/tianting/service/impl/MealOrderServiceImpl.java
View file @
171a6e1
...
...
@@ -39,7 +39,7 @@ public class MealOrderServiceImpl implements MealOrderService {
@Override
public
List
<
MealOrderVO
>
queryMealOrders
(
MealOrderDTO
.
QueryMealOrderDTO
queryMealOrderDTO
)
{
final
var
loginInfo
=
LoginContextHolder
.
getLoginInfo
();
var
mealOrderRpcResponses
=
mealOrderServiceRpcClient
.
queryMealOrdersByCondition
(
loginInfo
.
getEnterpriseId
(),
loginInfo
.
getId
());
var
mealOrderRpcResponses
=
mealOrderServiceRpcClient
.
queryMealOrdersByCondition
(
loginInfo
.
getEnterpriseId
(),
loginInfo
.
getId
()
,
null
,
null
);
final
var
today
=
LocalDate
.
now
();
final
var
startTimestamp
=
today
.
with
(
DayOfWeek
.
MONDAY
).
atStartOfDay
().
atZone
(
DateUtil
.
CHINA_ZONE
).
toInstant
().
toEpochMilli
();
final
var
endTimestamp
=
today
.
with
(
DayOfWeek
.
SUNDAY
).
atTime
(
LocalTime
.
MAX
).
atZone
(
DateUtil
.
CHINA_ZONE
).
toInstant
().
toEpochMilli
();
...
...
@@ -75,13 +75,13 @@ public class MealOrderServiceImpl implements MealOrderService {
if
(
gradeClassById
==
null
)
{
throw
ClientEndExceptions
.
IncorrectRequestValue
.
build
(
ErrorCodeEnum
.
GRADE_CLASS_NOT_FOUND
);
}
final
var
latestMealMenuRecord
=
mealOrderServiceRpcClient
.
queryLatestMealMenuRecordByClientId
(
loginInfo
.
getEnterpriseId
(),
dinerById
.
getClientId
(
));
if
(
latestMealMenuRecord
==
null
)
{
final
var
latestMealMenuRecord
s
=
mealOrderServiceRpcClient
.
queryLatestMealMenuRecordsByClientIds
(
loginInfo
.
getEnterpriseId
(),
Collections
.
singletonList
(
dinerById
.
getClientId
()
));
if
(
latestMealMenuRecord
s
.
isEmpty
()
)
{
throw
ClientEndExceptions
.
IncorrectRequestValue
.
build
(
ErrorCodeEnum
.
MEAL_MENU_NOT_FOUND
);
}
final
var
mealOrder
=
mealOrderServiceRpcClient
.
createMealOrder
(
loginInfo
,
MealOrderCreation
.
newBuilder
()
.
setClientId
(
dinerById
.
getClientId
())
.
setMenuId
(
latestMealMenuRecord
.
getId
())
.
setMenuId
(
latestMealMenuRecord
s
.
get
(
0
)
.
getId
())
.
setAccountId
(
loginInfo
.
getId
())
.
setOrderMethod
(
MealOrderOrderMethodEnum
.
MEAL_ORDER_METHOD_MICRO
)
.
setDinerId
(
createMealOrderDTO
.
getDinerId
())
...
...
src/main/java/com/infoloop/tianting/service/impl/MenuServiceImpl.java
View file @
171a6e1
...
...
@@ -215,8 +215,8 @@ public class MenuServiceImpl implements MenuService {
@Override
public
String
queryClientLatestMealMenuRecord
(
SingleClientRpcResponse
client
)
{
final
var
singleMealMenuRecordRpcResponse
=
mealOrderServiceRpcClient
.
queryLatestMealMenuRecordByClientId
(
LoginContextHolder
.
getEnterpriseId
(),
client
.
getId
(
));
return
singleMealMenuRecordRpcResponse
==
null
?
""
:
singleMealMenuRecordRpcResponse
.
getImageUrl
();
final
var
singleMealMenuRecordRpcResponse
s
=
mealOrderServiceRpcClient
.
queryLatestMealMenuRecordsByClientIds
(
LoginContextHolder
.
getEnterpriseId
(),
List
.
of
(
client
.
getId
()
));
return
singleMealMenuRecordRpcResponse
s
.
isEmpty
()
?
""
:
singleMealMenuRecordRpcResponses
.
get
(
0
)
.
getImageUrl
();
}
...
...
src/main/proto/MealOrderService.proto
View file @
171a6e1
...
...
@@ -51,7 +51,7 @@ service MealOrderServiceRpc {
rpc
GetMealMenuRecordsByIds
(
GetMealMenuRecordsByIdsRpcRequest
)
returns
(
GetMealMenuRecordsByIdsRpcResponse
)
{}
rpc
QueryMealMenuRecordsByCondition
(
QueryMealMenuRecordsByConditionRpcRequest
)
returns
(
QueryMealMenuRecordsByConditionRpcResponse
)
{}
rpc
CreateMealMenuRecord
(
CreateMealMenuRecordRpcRequest
)
returns
(
CreateMealMenuRecordRpcResponse
)
{}
rpc
QueryLatestMealMenuRecord
ByClientId
(
QueryLatestMealMenuRecordByClientIdRpcRequest
)
returns
(
QueryLatestMealMenuRecordByClientId
RpcResponse
)
{}
rpc
QueryLatestMealMenuRecord
sByClientIds
(
QueryLatestMealMenuRecordsByClientIdsRpcRequest
)
returns
(
QueryLatestMealMenuRecordsByClientIds
RpcResponse
)
{}
}
enum
MealOrderOrderMethodEnum
{
...
...
@@ -788,11 +788,11 @@ message CreateMealMenuRecordRpcResponse {
bool
isCreated
=
2
;
}
message
QueryLatestMealMenuRecord
ByClientId
RpcRequest
{
message
QueryLatestMealMenuRecord
sByClientIds
RpcRequest
{
int32
enterpriseId
=
1
;
int32
clientId
=
2
;
repeated
int32
clientId
=
2
;
}
message
QueryLatestMealMenuRecord
ByClientId
RpcResponse
{
SingleMealMenuRecordRpcResponse
response
=
1
;
message
QueryLatestMealMenuRecord
sByClientIds
RpcResponse
{
repeated
SingleMealMenuRecordRpcResponse
responses
=
1
;
}
...
...
Please
register
or
login
to post a comment