Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
9ffcfcf8
Commit
9ffcfcf8
authored
Jul 03, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
关注商品列表查询
parent
a2d4f8ff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
65 deletions
+137
-65
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/SpecialPerformanceServiceImpl.java
...h/wx/impl/distribution/SpecialPerformanceServiceImpl.java
+2
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/job/SpecialPerformanceNoticeJob.java
.../java/com/wwdz/ch/wx/job/SpecialPerformanceNoticeJob.java
+135
-65
No files found.
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/SpecialPerformanceServiceImpl.java
View file @
9ffcfcf8
...
@@ -295,6 +295,8 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
...
@@ -295,6 +295,8 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
if
(
dto
.
getSearchType
()
!=
null
&&
dto
.
getSearchType
()
==
1
)
{
if
(
dto
.
getSearchType
()
!=
null
&&
dto
.
getSearchType
()
==
1
)
{
if
(!
CollectionUtils
.
isEmpty
(
followItemList
))
{
if
(!
CollectionUtils
.
isEmpty
(
followItemList
))
{
specialPerformanceConfigRequestDto
.
setItemIdList
(
followItemList
);
specialPerformanceConfigRequestDto
.
setItemIdList
(
followItemList
);
}
else
{
return
Result
.
failed
(
"没有关注商品"
);
}
}
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/job/SpecialPerformanceNoticeJob.java
View file @
9ffcfcf8
...
@@ -59,6 +59,9 @@ public class SpecialPerformanceNoticeJob {
...
@@ -59,6 +59,9 @@ public class SpecialPerformanceNoticeJob {
//专场即将开始提醒,标识key
//专场即将开始提醒,标识key
private
final
static
String
SPECIAL_PERFORMANCE_START_NOTICE_KEY
=
"SPECIALPERFORMANCE_START_NOTICE_KEY:"
;
private
final
static
String
SPECIAL_PERFORMANCE_START_NOTICE_KEY
=
"SPECIALPERFORMANCE_START_NOTICE_KEY:"
;
//专场即将结束提醒,标识key
private
final
static
String
SPECIAL_PERFORMANCE_END_NOTICE_KEY
=
"SPECIAL_PERFORMANCE_END_NOTICE_KEY:"
;
@Autowired
@Autowired
SpecialPerformanceDao
specialPerformanceDao
;
SpecialPerformanceDao
specialPerformanceDao
;
...
@@ -112,7 +115,22 @@ public class SpecialPerformanceNoticeJob {
...
@@ -112,7 +115,22 @@ public class SpecialPerformanceNoticeJob {
logger
.
info
(
">>>>>>>>>>>>>>>>>>>>>>> 专场即将开始通知任务,开始执行 <<<<<<<<<<<<<<<<<<<<<"
);
logger
.
info
(
">>>>>>>>>>>>>>>>>>>>>>> 专场即将开始通知任务,开始执行 <<<<<<<<<<<<<<<<<<<<<"
);
try
{
try
{
autoRefreshSpecialPerformanceState
();
autoRefreshSpecialPerformanceState
();
//专场即将开始消息通知
abortToStartNotice
();
//专场即将结束消息通知
abortToEndNotice
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"专场即将开始通知任务 error {}"
,
e
);
}
finally
{
if
(
lock
!=
null
&&
lock
.
isHeldByCurrentThread
())
{
lock
.
unlock
();
logger
.
info
(
"======================== 线程id: {} ,专场即将开始通知任务执行结束, 释放锁成功 ========================"
,
Thread
.
currentThread
().
getId
());
}
}
}
public
void
abortToStartNotice
()
{
SpecialPerformanceRequestDto
specialPerformanceRequestDto
=
new
SpecialPerformanceRequestDto
();
SpecialPerformanceRequestDto
specialPerformanceRequestDto
=
new
SpecialPerformanceRequestDto
();
specialPerformanceRequestDto
.
setState
(
SpecialPerformanceEnum
.
StateEnum
.
PREVIEW
.
getCode
());
specialPerformanceRequestDto
.
setState
(
SpecialPerformanceEnum
.
StateEnum
.
PREVIEW
.
getCode
());
Date
now
=
new
Date
();
Date
now
=
new
Date
();
...
@@ -128,10 +146,10 @@ public class SpecialPerformanceNoticeJob {
...
@@ -128,10 +146,10 @@ public class SpecialPerformanceNoticeJob {
SpecialPerformance
specialPerformance
=
specialPerformanceList
.
get
(
0
);
SpecialPerformance
specialPerformance
=
specialPerformanceList
.
get
(
0
);
String
abortStartKey
=
SPECIAL_PERFORMANCE_START_NOTICE_KEY
+
specialPerformance
.
getId
();
String
abortStartKey
=
SPECIAL_PERFORMANCE_START_NOTICE_KEY
+
specialPerformance
.
getId
();
if
(!
redisUtils
.
hasKey
(
abortStartKey
))
{
if
(!
redisUtils
.
hasKey
(
abortStartKey
))
{
if
(
"dev"
.
equals
(
env
))
{
/*
if ("dev".equals(env)) {
logger.info(">>>>>>>>>>>>>>>>>>>>>>> dev环境, 不执行专场即将开始通知任务<<<<<<<<<<<<<<<<<<<<<");
logger.info(">>>>>>>>>>>>>>>>>>>>>>> dev环境, 不执行专场即将开始通知任务<<<<<<<<<<<<<<<<<<<<<");
return;
return;
}
}*/
logger
.
info
(
"当前即将开始的专场id:{}, 名称为 {} "
,
specialPerformance
.
getId
(),
specialPerformance
.
getTitle
());
logger
.
info
(
"当前即将开始的专场id:{}, 名称为 {} "
,
specialPerformance
.
getId
(),
specialPerformance
.
getTitle
());
//发送专场开始订阅通知
//发送专场开始订阅通知
...
@@ -146,23 +164,7 @@ public class SpecialPerformanceNoticeJob {
...
@@ -146,23 +164,7 @@ public class SpecialPerformanceNoticeJob {
List
<
DisposableSubscribeRecord
>
disposableSubscribeRecordList
=
disposableSubscribeRecordDao
.
findList
(
disposableSubscribeRecordRequestDto
);
List
<
DisposableSubscribeRecord
>
disposableSubscribeRecordList
=
disposableSubscribeRecordDao
.
findList
(
disposableSubscribeRecordRequestDto
);
PageInfo
pageInfo
=
new
PageInfo
(
disposableSubscribeRecordList
);
PageInfo
pageInfo
=
new
PageInfo
(
disposableSubscribeRecordList
);
for
(
DisposableSubscribeRecord
disposableSubscribeRecord
:
disposableSubscribeRecordList
)
{
for
(
DisposableSubscribeRecord
disposableSubscribeRecord
:
disposableSubscribeRecordList
)
{
AuctionOfferNoticeMsg
auctionOfferNoticeMsg
=
new
AuctionOfferNoticeMsg
();
sendSubscribeMsg
(
specialPerformance
,
disposableSubscribeRecord
,
msg
);
auctionOfferNoticeMsg
.
setSpecialPerformanceTitle
(
specialPerformance
.
getTitle
());
auctionOfferNoticeMsg
.
setSpecialPerformanceStartTime
(
DateUtils
.
toString
(
specialPerformance
.
getStartTime
()));
auctionOfferNoticeMsg
.
setOpenId
(
disposableSubscribeRecord
.
getOpenid
());
Result
result
=
sendMsgService
.
sendSpecialPerformanceStartMsg
(
auctionOfferNoticeMsg
);
if
(!
result
.
getSuccess
())
{
String
errorCode
=
JsonUtils
.
getValueByPath
(
result
.
getData
().
toString
(),
"errcode"
);
//用户为订阅消息,43101用户未订阅消息;43108并发下发消息给同一个粉丝,这两种情况表示用户不需要被通知
if
(!
"43101"
.
equals
(
errorCode
)
&&
!
"43108"
.
equals
(
errorCode
))
{
//发订阅消息送失败发短信
long
userId
=
disposableSubscribeRecord
.
getUserId
();
aliSmsSender
.
sendSms
(
userId
,
msg
);
}
}
else
{
//发送成功后订阅状态改为无效
disposableSubscribeRecordDao
.
updateInvalid
(
disposableSubscribeRecord
.
getOpenid
(),
disposableSubscribeRecord
.
getTargetId
(),
disposableSubscribeRecord
.
getTemplateId
());
}
}
}
if
(
pageInfo
.
isHasNextPage
())
{
if
(
pageInfo
.
isHasNextPage
())
{
page
=
page
+
1
;
page
=
page
+
1
;
...
@@ -178,15 +180,83 @@ public class SpecialPerformanceNoticeJob {
...
@@ -178,15 +180,83 @@ public class SpecialPerformanceNoticeJob {
}
else
{
}
else
{
logger
.
info
(
"================专场id: {}, 即将开始通知任务已经完成,无需重复发送 =============="
,
specialPerformance
.
getId
());
logger
.
info
(
"================专场id: {}, 即将开始通知任务已经完成,无需重复发送 =============="
,
specialPerformance
.
getId
());
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"专场即将开始通知任务 error {}"
,
e
);
}
finally
{
if
(
lock
!=
null
&&
lock
.
isHeldByCurrentThread
())
{
lock
.
unlock
();
logger
.
info
(
"======================== 线程id: {} ,专场即将开始通知任务执行结束, 释放锁成功 ========================"
,
Thread
.
currentThread
().
getId
());
}
}
public
void
abortToEndNotice
()
{
SpecialPerformanceRequestDto
specialPerformanceRequestDto
=
new
SpecialPerformanceRequestDto
();
specialPerformanceRequestDto
.
setState
(
SpecialPerformanceEnum
.
StateEnum
.
PROCESSING
.
getCode
());
Date
now
=
new
Date
();
Instant
startInstant
=
now
.
toInstant
().
plus
(
Duration
.
ofMinutes
(
20
));
Date
endTime
=
Date
.
from
(
startInstant
);
specialPerformanceRequestDto
.
setStartQueryEndTime
(
now
);
specialPerformanceRequestDto
.
setEndQueryEndTime
(
endTime
);
List
<
SpecialPerformance
>
specialPerformanceList
=
specialPerformanceDao
.
find
(
specialPerformanceRequestDto
);
logger
.
info
(
"即将结束的专场个数为 {}"
,
specialPerformanceList
.
size
());
if
(
CollectionUtils
.
isEmpty
(
specialPerformanceList
))
{
return
;
}
}
SpecialPerformance
specialPerformance
=
specialPerformanceList
.
get
(
0
);
String
abortEndKey
=
SPECIAL_PERFORMANCE_END_NOTICE_KEY
+
specialPerformance
.
getId
();
if
(!
redisUtils
.
hasKey
(
abortEndKey
))
{
/*if ("dev".equals(env)) {
logger.info(">>>>>>>>>>>>>>>>>>>>>>> dev环境, 不执行专场即将结束通知任务<<<<<<<<<<<<<<<<<<<<<");
return;
}*/
logger
.
info
(
"当前即将结束的专场id:{}, 名称为 {} "
,
specialPerformance
.
getId
(),
specialPerformance
.
getTitle
());
//发送专场即将结束订阅通知
DisposableSubscribeRecordRequestDto
disposableSubscribeRecordRequestDto
=
new
DisposableSubscribeRecordRequestDto
();
disposableSubscribeRecordRequestDto
.
setTargetId
(
Long
.
valueOf
(
specialPerformance
.
getId
()));
disposableSubscribeRecordRequestDto
.
setType
(
DisposableSubscribeRecordEnum
.
TypeEnum
.
PRE_END
.
getType
());
boolean
hasNextPage
=
true
;
int
page
=
1
;
String
url
=
wxAppletApi
.
getUrlLink
(
SPECIAL_PERFORMANCE_URL
,
"specialId="
+
specialPerformance
.
getId
());
String
msg
=
specialPerformance
.
getTitle
()
+
"将在"
+
DateUtils
.
toString
(
specialPerformance
.
getEndTime
())
+
"结束,请前往"
+
url
+
"查看"
;
while
(
hasNextPage
)
{
List
<
DisposableSubscribeRecord
>
disposableSubscribeRecordList
=
disposableSubscribeRecordDao
.
findList
(
disposableSubscribeRecordRequestDto
);
PageInfo
pageInfo
=
new
PageInfo
(
disposableSubscribeRecordList
);
for
(
DisposableSubscribeRecord
disposableSubscribeRecord
:
disposableSubscribeRecordList
)
{
sendSubscribeMsg
(
specialPerformance
,
disposableSubscribeRecord
,
msg
);
}
if
(
pageInfo
.
isHasNextPage
())
{
page
=
page
+
1
;
disposableSubscribeRecordRequestDto
.
setPage
(
page
);
logger
.
info
(
"要发送专场结束订阅消息的用户数据总页数为 : {}, 当前为 : {}"
,
pageInfo
.
getPages
(),
page
);
}
else
{
logger
.
info
(
"============= 发送专场结束订阅消息循环结束 ============="
);
break
;
}
}
logger
.
info
(
"================专场id: {}, 即将结束通知消息全部发送成功 =============="
,
specialPerformance
.
getId
());
redisUtils
.
set
(
abortEndKey
,
specialPerformance
.
getId
(),
3600
*
24
);
}
else
{
logger
.
info
(
"================专场id: {}, 即将结束通知任务已经完成,无需重复发送 =============="
,
specialPerformance
.
getId
());
}
}
}
private
void
sendSubscribeMsg
(
SpecialPerformance
specialPerformance
,
DisposableSubscribeRecord
disposableSubscribeRecord
,
String
msg
){
AuctionOfferNoticeMsg
auctionOfferNoticeMsg
=
new
AuctionOfferNoticeMsg
();
auctionOfferNoticeMsg
.
setSpecialPerformanceTitle
(
specialPerformance
.
getTitle
());
auctionOfferNoticeMsg
.
setSpecialPerformanceStartTime
(
DateUtils
.
toString
(
specialPerformance
.
getStartTime
()));
auctionOfferNoticeMsg
.
setOpenId
(
disposableSubscribeRecord
.
getOpenid
());
Result
result
=
sendMsgService
.
sendSpecialPerformanceStartMsg
(
auctionOfferNoticeMsg
);
if
(!
result
.
getSuccess
())
{
String
errorCode
=
JsonUtils
.
getValueByPath
(
result
.
getData
().
toString
(),
"errcode"
);
//用户为订阅消息,43101用户未订阅消息;43108并发下发消息给同一个粉丝,这两种情况表示用户不需要被通知
if
(!
"43101"
.
equals
(
errorCode
)
&&
!
"43108"
.
equals
(
errorCode
))
{
//发订阅消息送失败发短信
long
userId
=
disposableSubscribeRecord
.
getUserId
();
aliSmsSender
.
sendSms
(
userId
,
msg
);
}
}
//订阅状态改为无效
disposableSubscribeRecordDao
.
updateInvalid
(
disposableSubscribeRecord
.
getOpenid
(),
disposableSubscribeRecord
.
getTargetId
(),
disposableSubscribeRecord
.
getTemplateId
());
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment