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
d6ee16bd
Commit
d6ee16bd
authored
Dec 12, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
签到提醒
parent
a163d0e5
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
263 additions
and
0 deletions
+263
-0
ch-core/src/main/java/com/wwdz/ch/core/consts/CommConsts.java
...ore/src/main/java/com/wwdz/ch/core/consts/CommConsts.java
+5
-0
ch-core/src/main/java/com/wwdz/ch/core/consts/DisposableSubscribeRecordEnum.java
...om/wwdz/ch/core/consts/DisposableSubscribeRecordEnum.java
+1
-0
ch-core/src/main/java/com/wwdz/ch/core/entity/SignInNoticeMsg.java
...rc/main/java/com/wwdz/ch/core/entity/SignInNoticeMsg.java
+23
-0
ch-core/src/main/java/com/wwdz/ch/core/impl/SendMsgServiceImpl.java
...c/main/java/com/wwdz/ch/core/impl/SendMsgServiceImpl.java
+36
-0
ch-core/src/main/java/com/wwdz/ch/core/service/SendMsgService.java
...rc/main/java/com/wwdz/ch/core/service/SendMsgService.java
+8
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserSigninServiceImpl.java
.../main/java/com/wwdz/ch/wx/impl/UserSigninServiceImpl.java
+10
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/DisposableSubscribeRecordServiceImpl.java
...pl/distribution/DisposableSubscribeRecordServiceImpl.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/job/SignInNoticeJob.java
...api/src/main/java/com/wwdz/ch/wx/job/SignInNoticeJob.java
+179
-0
No files found.
ch-core/src/main/java/com/wwdz/ch/core/consts/CommConsts.java
View file @
d6ee16bd
...
@@ -215,6 +215,11 @@ public interface CommConsts {
...
@@ -215,6 +215,11 @@ public interface CommConsts {
*/
*/
public
final
static
double
CHANNEL_COST_REBATE
=
0.01
;
public
final
static
double
CHANNEL_COST_REBATE
=
0.01
;
/**
* 一次性订阅消息,签到提醒targetId为0
*/
public
final
static
Long
SIGN_IN_TARGET_ID
=
0L
;
/**
/**
* 自测账号,不发送短信
* 自测账号,不发送短信
*/
*/
...
...
ch-core/src/main/java/com/wwdz/ch/core/consts/DisposableSubscribeRecordEnum.java
View file @
d6ee16bd
...
@@ -15,6 +15,7 @@ public class DisposableSubscribeRecordEnum {
...
@@ -15,6 +15,7 @@ public class DisposableSubscribeRecordEnum {
GROUPPURASE_SURPLUS_AMOUNT_PAY
(
4
,
"e6-VlkWBST_sN3PQ2Yx3iuPkxQL5Hf6cfMia3MDNinc"
,
"尾款支付提醒"
),
GROUPPURASE_SURPLUS_AMOUNT_PAY
(
4
,
"e6-VlkWBST_sN3PQ2Yx3iuPkxQL5Hf6cfMia3MDNinc"
,
"尾款支付提醒"
),
GROUPPURASE_CLOSER_TO_SUCCESS
(
5
,
"ekZ3s3OL6ZlWnORvvMOONfWNZsbm6DTlMNyv_2j2ijk"
,
"拼团待成团提醒"
),
GROUPPURASE_CLOSER_TO_SUCCESS
(
5
,
"ekZ3s3OL6ZlWnORvvMOONfWNZsbm6DTlMNyv_2j2ijk"
,
"拼团待成团提醒"
),
GROUPPURASE_RATE
(
6
,
"nmpPtwVrFo261tcRbMvCK8NeAztDnrUubwh-04J4_Ow"
,
"拼团进度提醒"
),
GROUPPURASE_RATE
(
6
,
"nmpPtwVrFo261tcRbMvCK8NeAztDnrUubwh-04J4_Ow"
,
"拼团进度提醒"
),
SIGN_IN_REMIND
(
7
,
"bFVaiBLSMYQBfIrDpYZpwuWzh8IriIVhSdZrY0ewlWk"
,
"签到提醒"
),
;
;
private
int
type
;
private
int
type
;
...
...
ch-core/src/main/java/com/wwdz/ch/core/entity/SignInNoticeMsg.java
0 → 100644
View file @
d6ee16bd
package
com.wwdz.ch.core.entity
;
import
com.xxdxxs.entity.Entity
;
import
lombok.Data
;
@Data
public
class
SignInNoticeMsg
implements
Entity
{
/**
* 用户id
*/
private
Long
userId
;
/**
* 用户openid
*/
private
String
openId
;
/**
* 消息内容
*/
private
String
content
;
}
ch-core/src/main/java/com/wwdz/ch/core/impl/SendMsgServiceImpl.java
View file @
d6ee16bd
...
@@ -1077,4 +1077,40 @@ public class SendMsgServiceImpl implements SendMsgService {
...
@@ -1077,4 +1077,40 @@ public class SendMsgServiceImpl implements SendMsgService {
}
}
return
Result
.
failed
();
return
Result
.
failed
();
}
}
@Override
public
Result
sendSignInNoticeMsg
(
SignInNoticeMsg
signInNoticeMsg
)
{
String
openId
=
signInNoticeMsg
.
getOpenId
();
String
token
=
wxAppletApi
.
getAppletAccessToken
();
String
url
=
SEND_SUBSCRIBE_MSG_URL
+
"?access_token="
+
token
;
OkHttpUtil
okHttpUtil
=
OkHttpUtil
.
builder
().
url
(
url
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"touser"
,
openId
);
map
.
put
(
"template_id"
,
DisposableSubscribeRecordEnum
.
TypeEnum
.
SIGN_IN_REMIND
.
getTemplateId
());
Map
<
String
,
Object
>
miniprogramMap
=
new
HashMap
<>();
miniprogramMap
.
put
(
"appid"
,
APPLET_APPID
);
map
.
put
(
"page"
,
CommConsts
.
HOMEPAGE_URL
);
Map
<
String
,
Object
>
paramMap
=
new
LinkedHashMap
<>();
paramMap
.
put
(
"thing10"
,
new
HashMap
()
{{
put
(
"value"
,
"今天尚未签到"
);
}});
paramMap
.
put
(
"thing4"
,
new
HashMap
()
{{
put
(
"value"
,
signInNoticeMsg
.
getContent
());
}});
map
.
put
(
"data"
,
paramMap
);
logger
.
info
(
"============ 拼团签到提醒订阅消息内容 : {}"
,
JsonUtils
.
fromMap
(
map
));
okHttpUtil
.
addParams
(
map
);
okHttpUtil
.
post
(
true
);
String
responseStr
=
okHttpUtil
.
async
();
logger
.
info
(
"openid : {}, 发送签到进度提醒订阅消息 response :{}"
,
openId
,
responseStr
);
String
errorCode
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errcode"
);
String
errmsg
=
JsonUtils
.
getValueByPath
(
responseStr
,
"errmsg"
);
if
(!
"0"
.
equals
(
errorCode
))
{
logger
.
error
(
"openid : {}, 发送签到提醒订阅消息, errorCode : {}, errmsg : {} "
,
openId
,
errorCode
,
errmsg
);
return
Result
.
failed
(
responseStr
);
}
logger
.
info
(
"============= 发送签到提醒订阅消息内容成功 ==========="
);
return
Result
.
success
();
}
}
}
ch-core/src/main/java/com/wwdz/ch/core/service/SendMsgService.java
View file @
d6ee16bd
...
@@ -147,4 +147,12 @@ public interface SendMsgService {
...
@@ -147,4 +147,12 @@ public interface SendMsgService {
* @return
* @return
*/
*/
Result
exchangeNoticeMsg
(
ExchangeNoticeMsg
exchangeNoticeMsg
);
Result
exchangeNoticeMsg
(
ExchangeNoticeMsg
exchangeNoticeMsg
);
/**
* 签到提醒
* @param signInNoticeMsg
* @return
*/
Result
sendSignInNoticeMsg
(
SignInNoticeMsg
signInNoticeMsg
);
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserSigninServiceImpl.java
View file @
d6ee16bd
...
@@ -2,12 +2,14 @@ package com.wwdz.ch.wx.impl;
...
@@ -2,12 +2,14 @@ package com.wwdz.ch.wx.impl;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.DisposableSubscribeRecordEnum
;
import
com.wwdz.ch.core.consts.DistributionEnum
;
import
com.wwdz.ch.core.consts.DistributionEnum
;
import
com.wwdz.ch.core.consts.SigninEnum
;
import
com.wwdz.ch.core.consts.SigninEnum
;
import
com.wwdz.ch.core.entity.SignDateRecord
;
import
com.wwdz.ch.core.entity.SignDateRecord
;
import
com.wwdz.ch.core.entity.SupplierItemVo
;
import
com.wwdz.ch.core.entity.SupplierItemVo
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.*
;
import
com.wwdz.ch.core.util.*
;
import
com.wwdz.ch.db.dao.DisposableSubscribeRecordDao
;
import
com.wwdz.ch.db.dao.SignInShareImageDao
;
import
com.wwdz.ch.db.dao.SignInShareImageDao
;
import
com.wwdz.ch.db.dao.UserSignInDao
;
import
com.wwdz.ch.db.dao.UserSignInDao
;
import
com.wwdz.ch.db.dao.distribution.DistributionOrderDao
;
import
com.wwdz.ch.db.dao.distribution.DistributionOrderDao
;
...
@@ -61,6 +63,9 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -61,6 +63,9 @@ public class UserSigninServiceImpl implements UserSigninService {
@Autowired
@Autowired
RedisUtils
redisUtils
;
RedisUtils
redisUtils
;
@Autowired
DisposableSubscribeRecordDao
disposableSubscribeRecordDao
;
@Override
@Override
public
Result
signIn
(
UserSignInRequestDto
dto
)
{
public
Result
signIn
(
UserSignInRequestDto
dto
)
{
try
{
try
{
...
@@ -425,6 +430,11 @@ public class UserSigninServiceImpl implements UserSigninService {
...
@@ -425,6 +430,11 @@ public class UserSigninServiceImpl implements UserSigninService {
DayOfWeek
dayOfWeek
=
today
.
getDayOfWeek
();
DayOfWeek
dayOfWeek
=
today
.
getDayOfWeek
();
String
weekDay
=
dayOfWeek
.
getDisplayName
(
java
.
time
.
format
.
TextStyle
.
FULL
,
java
.
util
.
Locale
.
CHINESE
);
String
weekDay
=
dayOfWeek
.
getDisplayName
(
java
.
time
.
format
.
TextStyle
.
FULL
,
java
.
util
.
Locale
.
CHINESE
);
map
.
put
(
"weekDay"
,
weekDay
);
map
.
put
(
"weekDay"
,
weekDay
);
if
(
disposableSubscribeRecordDao
.
isSubscribed
(
dto
.
getUserId
(),
CommConsts
.
SIGN_IN_TARGET_ID
,
DisposableSubscribeRecordEnum
.
TypeEnum
.
SIGN_IN_REMIND
.
getType
()))
{
map
.
put
(
"isSubscribed"
,
true
);
}
else
{
map
.
put
(
"isSubscribed"
,
false
);
}
return
Result
.
success
(
map
);
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取分享信息失败 error : {}"
,
e
);
logger
.
error
(
"获取分享信息失败 error : {}"
,
e
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/DisposableSubscribeRecordServiceImpl.java
View file @
d6ee16bd
...
@@ -41,6 +41,7 @@ public class DisposableSubscribeRecordServiceImpl implements DisposableSubscribe
...
@@ -41,6 +41,7 @@ public class DisposableSubscribeRecordServiceImpl implements DisposableSubscribe
DisposableSubscribeRecord
disposableSubscribeRecord
=
new
DisposableSubscribeRecord
();
DisposableSubscribeRecord
disposableSubscribeRecord
=
new
DisposableSubscribeRecord
();
EntityMapper
.
copyAttribute
(
dto
,
disposableSubscribeRecord
);
EntityMapper
.
copyAttribute
(
dto
,
disposableSubscribeRecord
);
disposableSubscribeRecord
.
setType
(
DisposableSubscribeRecordEnum
.
TypeEnum
.
getTypeByTemplateId
(
templateId
));
disposableSubscribeRecord
.
setType
(
DisposableSubscribeRecordEnum
.
TypeEnum
.
getTypeByTemplateId
(
templateId
));
//签到消息订阅,targetId前端固定传0
disposableSubscribeRecord
.
setOpenid
(
openid
);
disposableSubscribeRecord
.
setOpenid
(
openid
);
disposableSubscribeRecord
.
setIsValid
(
true
);
disposableSubscribeRecord
.
setIsValid
(
true
);
disposableSubscribeRecord
.
setCreateTime
(
new
Date
());
disposableSubscribeRecord
.
setCreateTime
(
new
Date
());
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/job/SignInNoticeJob.java
0 → 100644
View file @
d6ee16bd
package
com.wwdz.ch.wx.job
;
import
com.github.pagehelper.PageInfo
;
import
com.wwdz.ch.core.api.WxAppletApi
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.DisposableSubscribeRecordEnum
;
import
com.wwdz.ch.core.consts.DistributionEnum
;
import
com.wwdz.ch.core.entity.AuctionOfferNoticeMsg
;
import
com.wwdz.ch.core.entity.SignInNoticeMsg
;
import
com.wwdz.ch.core.notify.AliSmsSender
;
import
com.wwdz.ch.core.service.SendMsgService
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.db.dao.DisposableSubscribeRecordDao
;
import
com.wwdz.ch.db.dao.FollowFansRecordDao
;
import
com.wwdz.ch.db.dao.UserSignInDao
;
import
com.wwdz.ch.db.dao.distribution.ShopWhiteListDao
;
import
com.wwdz.ch.db.dao.distribution.SupplierItemDao
;
import
com.wwdz.ch.db.domain.FollowFansRecord
;
import
com.wwdz.ch.db.domain.UserSignIn
;
import
com.wwdz.ch.db.domain.distribution.DisposableSubscribeRecord
;
import
com.wwdz.ch.db.domain.distribution.SpecialPerformance
;
import
com.wwdz.ch.db.domain.distribution.SupplierItem
;
import
com.wwdz.ch.db.dto.request.FollowFansRecordRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.DisposableSubscribeRecordRequestDto
;
import
com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto
;
import
com.xxdxxs.utils.DateUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 藏品上新通知
*/
@Component
public
class
SignInNoticeJob
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SignInNoticeJob
.
class
);
private
final
static
String
SIGN_IN_NOTICE_KEY
=
"SIGN_IN_NOTICE_KEY"
;
@Autowired
RedissonClient
redissonClient
;
@Autowired
RedisUtils
redisUtils
;
@Autowired
DisposableSubscribeRecordDao
disposableSubscribeRecordDao
;
@Autowired
UserSignInDao
userSignInDao
;
@Autowired
WxAppletApi
wxAppletApi
;
@Autowired
SendMsgService
sendMsgService
;
@Value
(
"${spring.profiles.active}"
)
private
String
env
;
/**
* 每天下午两点执行一次
*/
@Scheduled
(
cron
=
"0 0 14 * * ?"
)
public
void
execute
()
{
/* if ("dev".equals(env)) {
logger.info(">>>>>>>>>>>>>>>>>>>>>>> dev环境, 不执行发送签到提醒通知定时作业<<<<<<<<<<<<<<<<<<<<<");
return;
}*/
RLock
lock
=
redissonClient
.
getLock
(
SIGN_IN_NOTICE_KEY
);
if
(!
lock
.
tryLock
())
{
logger
.
warn
(
"发送签到提醒通知,当前服务实例获取锁成功: {} 获取锁失败,锁被占用不执行"
,
Thread
.
currentThread
().
getId
());
return
;
}
logger
.
info
(
">>>>>>>>>>>>>>>>>>>>>>> 发送商品上新通知定时作业, 开始执行 <<<<<<<<<<<<<<<<<<<<<"
);
try
{
//发送专场开始订阅通知
DisposableSubscribeRecordRequestDto
disposableSubscribeRecordRequestDto
=
new
DisposableSubscribeRecordRequestDto
();
disposableSubscribeRecordRequestDto
.
setType
(
DisposableSubscribeRecordEnum
.
TypeEnum
.
SIGN_IN_REMIND
.
getType
());
boolean
hasNextPage
=
true
;
int
page
=
1
;
while
(
hasNextPage
)
{
List
<
DisposableSubscribeRecord
>
disposableSubscribeRecordList
=
disposableSubscribeRecordDao
.
findList
(
disposableSubscribeRecordRequestDto
);
PageInfo
pageInfo
=
new
PageInfo
(
disposableSubscribeRecordList
);
for
(
DisposableSubscribeRecord
disposableSubscribeRecord
:
disposableSubscribeRecordList
)
{
long
userId
=
disposableSubscribeRecord
.
getUserId
();
int
needConsecutiveDays
=
7
;
int
consecutiveDays
=
0
;
//检查昨天是否打过卡
UserSignIn
yesterdaySignIn
=
userSignInDao
.
findYesterdayRecord
(
userId
);
//查询今天的打卡记录
UserSignIn
todayRecord
=
userSignInDao
.
findTodayRecord
(
userId
);
if
(
yesterdaySignIn
==
null
&&
todayRecord
==
null
)
{
//连续签到天数
consecutiveDays
=
0
;
needConsecutiveDays
=
7
;
}
else
if
(
yesterdaySignIn
==
null
&&
todayRecord
!=
null
)
{
consecutiveDays
=
todayRecord
.
getConsecutiveDays
();
needConsecutiveDays
=
6
;
}
else
{
if
(
todayRecord
!=
null
)
{
consecutiveDays
=
todayRecord
.
getConsecutiveDays
();
}
else
{
consecutiveDays
=
yesterdaySignIn
.
getConsecutiveDays
();
}
if
(
consecutiveDays
<
7
)
{
needConsecutiveDays
=
7
-
consecutiveDays
;
}
else
if
(
consecutiveDays
>=
7
&&
consecutiveDays
<
14
)
{
needConsecutiveDays
=
14
-
consecutiveDays
;
}
else
if
(
consecutiveDays
>=
14
&&
consecutiveDays
<
21
)
{
needConsecutiveDays
=
21
-
consecutiveDays
;
}
else
{
needConsecutiveDays
=
7
;
}
}
if
(
todayRecord
==
null
)
{
String
content
=
"您再签到"
+
needConsecutiveDays
+
"天,即可获取奖励"
;
sendSignInNoticeMsg
(
disposableSubscribeRecord
.
getTemplateId
(),
disposableSubscribeRecord
.
getOpenid
(),
content
);
}
}
if
(
pageInfo
.
isHasNextPage
())
{
page
=
page
+
1
;
disposableSubscribeRecordRequestDto
.
setPage
(
page
);
hasNextPage
=
pageInfo
.
isHasNextPage
();
logger
.
info
(
"要发送专场开始订阅消息的用户数据总页数为 : {}, 当前为 : {}"
,
pageInfo
.
getPages
(),
page
);
}
else
{
logger
.
info
(
"============= 发送专场开始订阅消息循环结束 ============="
);
break
;
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"商品上新通知定时作业 error {}"
,
e
);
}
finally
{
if
(
lock
!=
null
&&
lock
.
isHeldByCurrentThread
())
{
lock
.
unlock
();
logger
.
info
(
"======================== 线程id: {} , 发送商品上新通知定时作业执行完毕, 释放锁成功 ========================"
,
Thread
.
currentThread
().
getId
());
}
}
}
private
void
sendSignInNoticeMsg
(
String
templateId
,
String
openId
,
String
msg
){
try
{
SignInNoticeMsg
signInNoticeMsg
=
new
SignInNoticeMsg
();
signInNoticeMsg
.
setOpenId
(
openId
);
signInNoticeMsg
.
setContent
(
msg
);
Result
result
=
sendMsgService
.
sendSignInNoticeMsg
(
signInNoticeMsg
);
if
(!
result
.
getSuccess
())
{
String
errorCode
=
JsonUtils
.
getValueByPath
(
result
.
getErrmsg
(),
"errcode"
);
//用户为订阅消息,43101用户未订阅消息;43108并发下发消息给同一个粉丝,这两种情况表示用户不需要被通知
if
(!
"43101"
.
equals
(
errorCode
)
&&
!
"43108"
.
equals
(
errorCode
))
{
logger
.
error
(
"发送签到订阅消息失败"
);
}
}
//订阅状态改为无效
disposableSubscribeRecordDao
.
updateInvalid
(
openId
,
CommConsts
.
SIGN_IN_TARGET_ID
,
templateId
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"发送签到订阅消息失败:{}"
,
e
);
}
}
}
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