Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
push-message
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liucheng
push-message
Commits
4bcc1405
Commit
4bcc1405
authored
Jul 04, 2022
by
zuoadmin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bug' into 'master'
1,定时推送电费充值 See merge request
!26
parents
08d6c093
f9f1cfc9
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
350 additions
and
6 deletions
+350
-6
Constant.java
src/main/java/com/weface/common/utils/Constant.java
+4
-0
DateUtils.java
src/main/java/com/weface/common/utils/DateUtils.java
+16
-0
GeTuiService.java
src/main/java/com/weface/component/GeTuiService.java
+62
-0
MobPushService.java
src/main/java/com/weface/component/MobPushService.java
+2
-2
PushLogDao.java
src/main/java/com/weface/dao/PushLogDao.java
+24
-0
NavigateConfigEntity.java
src/main/java/com/weface/entity/NavigateConfigEntity.java
+82
-0
PushLogService.java
src/main/java/com/weface/service/PushLogService.java
+24
-0
PushLogServiceImpl.java
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
+45
-0
UserTagsTask.java
src/main/java/com/weface/task/UserTagsTask.java
+59
-4
PushLogDao.xml
src/main/resources/mapper/PushLogDao.xml
+32
-0
No files found.
src/main/java/com/weface/common/utils/Constant.java
View file @
4bcc1405
...
@@ -48,6 +48,10 @@ public class Constant {
...
@@ -48,6 +48,10 @@ public class Constant {
* redis缓存前缀
* redis缓存前缀
*/
*/
public
static
final
String
PUSH_TASK_INFO
=
"push_task_info"
;
public
static
final
String
PUSH_TASK_INFO
=
"push_task_info"
;
/**
* 推送配置名称
*/
public
static
final
String
TIMING_PUSH_CONFIG_NAME
=
"timingPushConfig"
;
/**
/**
* http 请求
* http 请求
...
...
src/main/java/com/weface/common/utils/DateUtils.java
View file @
4bcc1405
...
@@ -7,6 +7,7 @@ import org.joda.time.format.DateTimeFormat;
...
@@ -7,6 +7,7 @@ import org.joda.time.format.DateTimeFormat;
import
org.joda.time.format.DateTimeFormatter
;
import
org.joda.time.format.DateTimeFormatter
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
...
@@ -155,4 +156,19 @@ public class DateUtils {
...
@@ -155,4 +156,19 @@ public class DateUtils {
DateTime
dateTime
=
new
DateTime
(
date
);
DateTime
dateTime
=
new
DateTime
(
date
);
return
dateTime
.
plusYears
(
years
).
toDate
();
return
dateTime
.
plusYears
(
years
).
toDate
();
}
}
/**
* 判断是否为当天
*
* @param day 日期
* @return 是否为当天
*/
public
static
boolean
isToday
(
int
day
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
//时间,可以为具体的某一时间
Date
today
=
new
Date
();
calendar
.
setTime
(
today
);
int
monthDay
=
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
);
return
day
==
monthDay
;
}
}
}
src/main/java/com/weface/component/GeTuiService.java
View file @
4bcc1405
...
@@ -435,6 +435,68 @@ public class GeTuiService {
...
@@ -435,6 +435,68 @@ public class GeTuiService {
return
CommonResult
.
failed
();
return
CommonResult
.
failed
();
}
}
/**
* 创建消息拿到任务id
*
* @param informForm 推送内容
* @return 任务id
*/
public
String
pushListMessage
(
InformForm
informForm
,
boolean
alias
)
{
try
{
String
type
=
informForm
.
getEquipmentType
();
String
appId
=
getAppId
(
type
);
String
pushToken
=
getPushToken
(
type
);
if
(
StringUtils
.
isBlank
(
pushToken
))
{
return
null
;
}
informForm
.
setUrl
(
HtmlUtil
.
unescape
(
informForm
.
getUrl
()));
MessageTemplate
template
=
getTemplate
(
informForm
);
template
.
setGroup_name
(
"toListMessage"
);
Map
<
String
,
Object
>
map
=
convertBeanToMap
(
informForm
.
getDevice
(),
true
,
0
,
template
);
//请求url
String
url
=
GE_TUI_BASE_URL
+
appId
+
"/push/list/message"
;
String
result
=
generalPost
(
url
,
pushToken
,
map
);
if
(
StringUtils
.
isEmpty
(
result
))
{
return
null
;
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
if
(
jsonObject
.
containsKey
(
"code"
)
&&
jsonObject
.
getInteger
(
"code"
)
==
0
)
{
String
taskId
=
jsonObject
.
getJSONObject
(
"data"
).
getString
(
"taskid"
);
String
[]
split
=
informForm
.
getCid
().
split
(
","
);
String
pushUrl
;
Map
<
String
,
Object
>
data
=
new
HashMap
<>(
1
);
if
(
alias
)
{
pushUrl
=
GE_TUI_BASE_URL
+
getAppId
(
type
)
+
"/push/list/alias"
;
data
.
put
(
"alias"
,
split
);
}
else
{
pushUrl
=
GE_TUI_BASE_URL
+
getAppId
(
type
)
+
"/push/list/cid"
;
data
.
put
(
"cid"
,
split
);
}
Map
<
String
,
Object
>
reqMap
=
new
HashMap
<>(
3
);
reqMap
.
put
(
"audience"
,
data
);
reqMap
.
put
(
"taskid"
,
taskId
);
reqMap
.
put
(
"is_async"
,
false
);
String
pushResult
=
generalPost
(
pushUrl
,
pushToken
,
reqMap
);
log
.
error
(
"个推批量推送结果:{}"
,
pushResult
);
if
(
StringUtils
.
isEmpty
(
pushResult
))
{
return
null
;
}
JSONObject
pushJson
=
JSONObject
.
parseObject
(
pushResult
);
if
((
pushJson
.
containsKey
(
"code"
)
&&
pushJson
.
getInteger
(
"code"
)
==
0
))
{
JSONObject
pushData
=
pushJson
.
getJSONObject
(
"data"
);
if
(
pushData
!=
null
)
{
//保存单推结果
pushLogService
.
saveLog
(
pushData
,
informForm
,
appId
);
}
return
pushResult
;
}
}
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
/**
* 将内容转为推送模板
* 将内容转为推送模板
*
*
...
...
src/main/java/com/weface/component/MobPushService.java
View file @
4bcc1405
...
@@ -454,13 +454,13 @@ public class MobPushService {
...
@@ -454,13 +454,13 @@ public class MobPushService {
}
else
{
}
else
{
request
=
JSONObject
.
toJSONString
(
map
);
request
=
JSONObject
.
toJSONString
(
map
);
}
}
log
.
info
(
"
推送内容:{}"
,
request
);
log
.
error
(
"mob
推送内容:{}"
,
request
);
HttpRequest
post
=
HttpUtil
.
createPost
(
url
);
HttpRequest
post
=
HttpUtil
.
createPost
(
url
);
post
.
header
(
"Content-Type"
,
"application/json"
);
post
.
header
(
"Content-Type"
,
"application/json"
);
post
.
header
(
"key"
,
APP_KEY
);
post
.
header
(
"key"
,
APP_KEY
);
post
.
header
(
"sign"
,
getSign
(
request
));
post
.
header
(
"sign"
,
getSign
(
request
));
String
body
=
post
.
body
(
request
).
execute
().
body
();
String
body
=
post
.
body
(
request
).
execute
().
body
();
log
.
info
(
"
推送结果:{}"
,
body
);
log
.
error
(
"mob
推送结果:{}"
,
body
);
if
(
JSONUtil
.
isJson
(
body
))
{
if
(
JSONUtil
.
isJson
(
body
))
{
JSONObject
json
=
JSONObject
.
parseObject
(
body
);
JSONObject
json
=
JSONObject
.
parseObject
(
body
);
if
(
json
.
containsKey
(
"status"
)
&&
json
.
getInteger
(
"status"
).
equals
(
200
))
if
(
json
.
containsKey
(
"status"
)
&&
json
.
getInteger
(
"status"
).
equals
(
200
))
...
...
src/main/java/com/weface/dao/PushLogDao.java
View file @
4bcc1405
package
com
.
weface
.
dao
;
package
com
.
weface
.
dao
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.weface.entity.NavigateConfigEntity
;
import
com.weface.entity.PushLogEntity
;
import
com.weface.entity.PushLogEntity
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
...
@@ -21,4 +22,27 @@ public interface PushLogDao extends BaseMapper<PushLogEntity> {
...
@@ -21,4 +22,27 @@ public interface PushLogDao extends BaseMapper<PushLogEntity> {
* @return 推送日志
* @return 推送日志
*/
*/
List
<
PushLogEntity
>
getPushLogByTime
(
@Param
(
"time"
)
Integer
time
);
List
<
PushLogEntity
>
getPushLogByTime
(
@Param
(
"time"
)
Integer
time
);
/**
* 以下借助推送日志类查询
* 获取已缴费用户id
*
* @return 用户id列表
*/
List
<
String
>
getOrderUidList
();
/**
* 查询当月1-14号没有交费记录的用户id
*
* @return 未缴费用户id
*/
List
<
String
>
getPayCostRecord
();
/**
* 根据配置名称获取配置信息 并缓存30分钟
*
* @param configName 配置名称
* @return 配置信息
*/
List
<
NavigateConfigEntity
>
getConfigByName
(
@Param
(
"configName"
)
String
configName
);
}
}
src/main/java/com/weface/entity/NavigateConfigEntity.java
0 → 100644
View file @
4bcc1405
package
com
.
weface
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
public
class
NavigateConfigEntity
implements
Serializable
{
/**
* id
*/
private
Integer
id
;
/**
* 配置名称
*/
private
String
configName
;
/**
* 描述
*/
private
String
description
;
/**
* 配置内容
*/
private
String
configContent
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 状态
*/
private
Integer
status
;
private
static
final
long
serialVersionUID
=
1L
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getConfigName
()
{
return
configName
;
}
public
void
setConfigName
(
String
configName
)
{
this
.
configName
=
configName
==
null
?
null
:
configName
.
trim
();
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
==
null
?
null
:
description
.
trim
();
}
public
String
getConfigContent
()
{
return
configContent
;
}
public
void
setConfigContent
(
String
configContent
)
{
this
.
configContent
=
configContent
==
null
?
null
:
configContent
.
trim
();
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Integer
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Integer
status
)
{
this
.
status
=
status
;
}
}
\ No newline at end of file
src/main/java/com/weface/service/PushLogService.java
View file @
4bcc1405
...
@@ -3,6 +3,7 @@ package com.weface.service;
...
@@ -3,6 +3,7 @@ package com.weface.service;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
com.weface.entity.NavigateConfigEntity
;
import
com.weface.entity.PushLogEntity
;
import
com.weface.entity.PushLogEntity
;
import
java.util.List
;
import
java.util.List
;
...
@@ -45,5 +46,28 @@ public interface PushLogService extends IService<PushLogEntity> {
...
@@ -45,5 +46,28 @@ public interface PushLogService extends IService<PushLogEntity> {
* @return 推送日志
* @return 推送日志
*/
*/
public
List
<
PushLogEntity
>
getPushLogByTime
(
Integer
time
);
public
List
<
PushLogEntity
>
getPushLogByTime
(
Integer
time
);
/**
* 以下借助推送日志类查询
* 获取已缴费用户id
*
* @return 用户id列表
*/
public
List
<
String
>
getOrderUidList
();
/**
* 查询当月1-14号记录的用户id
*
* @return 未缴费用户id
*/
public
List
<
String
>
getPayCostRecord
();
/**
* 根据配置名称获取配置信息
*
* @param configName 配置名称
* @return 配置信息
*/
public
NavigateConfigEntity
getConfigByName
(
String
configName
);
}
}
src/main/java/com/weface/serviceimpl/PushLogServiceImpl.java
View file @
4bcc1405
...
@@ -9,6 +9,7 @@ import com.weface.common.utils.RedisUtil;
...
@@ -9,6 +9,7 @@ import com.weface.common.utils.RedisUtil;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.common.utils.SnowIdUtil
;
import
com.weface.dao.PushLogDao
;
import
com.weface.dao.PushLogDao
;
import
com.weface.dto.InformForm
;
import
com.weface.dto.InformForm
;
import
com.weface.entity.NavigateConfigEntity
;
import
com.weface.entity.PushLogEntity
;
import
com.weface.entity.PushLogEntity
;
import
com.weface.service.PushLogService
;
import
com.weface.service.PushLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -124,4 +125,48 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
...
@@ -124,4 +125,48 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
public
List
<
PushLogEntity
>
getPushLogByTime
(
Integer
time
)
{
public
List
<
PushLogEntity
>
getPushLogByTime
(
Integer
time
)
{
return
this
.
baseMapper
.
getPushLogByTime
(
time
);
return
this
.
baseMapper
.
getPushLogByTime
(
time
);
}
}
/**
* 获取已缴费用户id
*
* @return 用户id列表
*/
@Override
public
List
<
String
>
getOrderUidList
()
{
return
this
.
baseMapper
.
getOrderUidList
();
}
/**
* 查询当月1-14号交费记录的用户id
*
* @return 未缴费用户id
*/
@Override
public
List
<
String
>
getPayCostRecord
()
{
return
this
.
baseMapper
.
getPayCostRecord
();
}
/**
* 根据配置名称获取配置信息 并缓存10分钟
*
* @param configName 配置名称
* @return 配置信息
*/
@Override
public
NavigateConfigEntity
getConfigByName
(
String
configName
)
{
NavigateConfigEntity
config
;
String
key
=
"population:navigateConfig:"
+
configName
;
String
configBody
=
RedisUtil
.
StringOps
.
get
(
key
);
if
(
StringUtils
.
isEmpty
(
configBody
))
{
List
<
NavigateConfigEntity
>
list
=
this
.
baseMapper
.
getConfigByName
(
configName
);
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
null
;
}
config
=
list
.
get
(
0
);
RedisUtil
.
StringOps
.
setEx
(
key
,
JSONObject
.
toJSONString
(
config
),
10
,
TimeUnit
.
MINUTES
);
}
else
{
config
=
JSONObject
.
parseObject
(
configBody
,
NavigateConfigEntity
.
class
);
}
return
config
;
}
}
}
\ No newline at end of file
src/main/java/com/weface/task/UserTagsTask.java
View file @
4bcc1405
...
@@ -2,14 +2,14 @@ package com.weface.task;
...
@@ -2,14 +2,14 @@ package com.weface.task;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.weface.common.utils.*
;
import
com.weface.common.utils.*
;
import
com.weface.component.GeTuiService
;
import
com.weface.component.MenuService
;
import
com.weface.component.MenuService
;
import
com.weface.component.MobPushService
;
import
com.weface.component.MobPushService
;
import
com.weface.config.RedisExpireData
;
import
com.weface.config.RedisExpireData
;
import
com.weface.entity.MenuTagsEntity
;
import
com.weface.dto.InformForm
;
import
com.weface.entity.PushLogEntity
;
import
com.weface.entity.*
;
import
com.weface.entity.UserMenusEntity
;
import
com.weface.entity.UserTagEntity
;
import
com.weface.service.MenuTagsService
;
import
com.weface.service.MenuTagsService
;
import
com.weface.service.PushLogService
;
import
com.weface.service.PushLogService
;
import
com.weface.service.UserMenusService
;
import
com.weface.service.UserMenusService
;
...
@@ -61,12 +61,67 @@ public class UserTagsTask {
...
@@ -61,12 +61,67 @@ public class UserTagsTask {
private
PushLogService
pushLogService
;
private
PushLogService
pushLogService
;
@Autowired
@Autowired
private
MobPushService
mobPushService
;
private
MobPushService
mobPushService
;
@Autowired
private
GeTuiService
geTuiService
;
/**
/**
* 查询推送日志时间
* 查询推送日志时间
*/
*/
private
static
final
Integer
TIME
=
2
;
private
static
final
Integer
TIME
=
2
;
/**
* 定时推送电费花费提醒
*/
@Scheduled
(
cron
=
"0 0 8 1,15 * ?"
)
public
void
timingPush
()
{
//判断当前是否为当月1/15号
if
(
DateUtils
.
isToday
(
1
)
||
DateUtils
.
isToday
(
15
))
{
//获取推送配置信息
NavigateConfigEntity
configByName
=
pushLogService
.
getConfigByName
(
Constant
.
TIMING_PUSH_CONFIG_NAME
);
if
(
Objects
.
isNull
(
configByName
))
{
return
;
}
String
configContent
=
configByName
.
getConfigContent
();
if
(
StringUtils
.
isEmpty
(
configContent
))
{
return
;
}
//查询老用户
List
<
String
>
list
=
pushLogService
.
getOrderUidList
().
stream
().
filter
(
org
.
apache
.
commons
.
lang3
.
StringUtils
::
isNumeric
).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
//将推送配置json转为推送实体类
InformForm
form
=
JSONObject
.
parseObject
(
configContent
,
InformForm
.
class
);
//当天是否为15号
if
(
DateUtils
.
isToday
(
15
))
{
//查询14天前至今有缴费记录用户
List
<
String
>
record
=
pushLogService
.
getPayCostRecord
().
stream
().
filter
(
org
.
apache
.
commons
.
lang3
.
StringUtils
::
isNumeric
).
collect
(
Collectors
.
toList
());
//过滤已缴费用户
if
(!
CollectionUtils
.
isEmpty
(
record
))
{
list
.
removeAll
(
record
);
}
}
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
//分割集合
List
<
List
<
String
>>
lists
=
CommonUtil
.
fixedGrouping
(
list
,
1000
);
for
(
List
<
String
>
strings
:
lists
)
{
//处理推送目标
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
s
:
strings
)
{
sb
.
append
(
"kksh_"
).
append
(
s
).
append
(
","
);
}
String
cid
=
sb
.
substring
(
0
,
sb
.
length
()
-
1
);
form
.
setCid
(
cid
);
//mob批量推送
mobPushService
.
mobPush
(
form
,
Constant
.
PushTarget
.
ALIAS
);
//个推批量推送
geTuiService
.
pushListMessage
(
form
,
true
);
}
}
}
}
}
/**
/**
* 查询未推送消息成功记录,发送短信通知
* 查询未推送消息成功记录,发送短信通知
*/
*/
...
...
src/main/resources/mapper/PushLogDao.xml
View file @
4bcc1405
...
@@ -31,4 +31,36 @@
...
@@ -31,4 +31,36 @@
INTERVAL #{time} HOUR)
INTERVAL #{time} HOUR)
</select>
</select>
<select
id=
"getOrderUidList"
resultType=
"string"
>
SELECT DISTINCT
uid
FROM
electric_charge_order UNION ALL
SELECT DISTINCT
uid
FROM
qmm_mobile_charge
</select>
<select
id=
"getPayCostRecord"
resultType=
"string"
>
SELECT DISTINCT
uid
FROM
electric_charge_order
WHERE
create_time >= DATE_SUB( CURDATE(), INTERVAL 14 DAY ) UNION ALL
SELECT DISTINCT
uid
FROM
qmm_mobile_charge
WHERE
create_time >= DATE_SUB(
CURDATE(),
INTERVAL 14 DAY)
</select>
<select
id=
"getConfigByName"
resultType=
"com.weface.entity.NavigateConfigEntity"
>
SELECT * FROM t_navigate_config WHERE `status` = 0 AND config_name = #{configName}
</select>
</mapper>
</mapper>
\ No newline at end of file
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