Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ee09693a
authored
Feb 09, 2021
by
18356073052
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
群发代码修改
1 parent
1c47634c
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
273 additions
and
13 deletions
linkwe-admin/src/main/resources/mybatis/mybatis-config.xml
linkwe-common/pom.xml
linkwe-framework/src/main/java/com/linkwechat/framework/handler/GenericTypeHandler.java
linkwe-framework/src/main/java/com/linkwechat/framework/handler/ListTypeHandler.java
linkwe-quartz/src/main/java/com/linkwechat/quartz/task/RyTask.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomerMessageTimeTask.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMessageTimeTaskMapper.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerMessagePushServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeTaskFissionServiceImpl.java
linkwe-wecom/src/main/resources/mapper/wecom/WeCustomerMessageTimeTaskMapper.xml
linkwe-admin/src/main/resources/mybatis/mybatis-config.xml
View file @
ee09693
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
<typeHandlers>
<typeHandlers>
<typeHandler
handler=
"com.linkwechat.framework.handler.StringArrayJoinTypeHandler"
/>
<typeHandler
handler=
"com.linkwechat.framework.handler.StringArrayJoinTypeHandler"
/>
<typeHandler
handler=
"com.linkwechat.framework.handler.GenericTypeHandler"
/>
<typeHandler
handler=
"com.linkwechat.framework.handler.ListTypeHandler"
/>
</typeHandlers>
</typeHandlers>
</configuration>
</configuration>
linkwe-common/pom.xml
View file @
ee09693
...
@@ -69,6 +69,7 @@
...
@@ -69,6 +69,7 @@
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.56
</version>
</dependency>
</dependency>
<!-- io常用工具类 -->
<!-- io常用工具类 -->
...
...
linkwe-framework/src/main/java/com/linkwechat/framework/handler/GenericTypeHandler.java
0 → 100644
View file @
ee09693
package
com
.
linkwechat
.
framework
.
handler
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto
;
import
org.apache.ibatis.type.BaseTypeHandler
;
import
org.apache.ibatis.type.JdbcType
;
import
org.apache.ibatis.type.MappedJdbcTypes
;
import
org.apache.ibatis.type.MappedTypes
;
import
java.sql.CallableStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
/**
* 用以mysql中json格式的字段,进行转换的自定义转换器,转换为实体类的T类型 属性
* @param <T>
*/
@SuppressWarnings
(
"all"
)
@MappedTypes
(
value
=
{
JSONObject
.
class
,
CustomerMessagePushDto
.
class
})
@MappedJdbcTypes
(
value
=
{
JdbcType
.
VARCHAR
},
includeNullJdbcType
=
true
)
public
class
GenericTypeHandler
<
T
extends
Object
>
extends
BaseTypeHandler
<
T
>
{
private
Class
<
T
>
clazz
;
public
GenericTypeHandler
(
Class
<
T
>
clazz
)
{
if
(
clazz
==
null
)
{
throw
new
IllegalArgumentException
(
"Type argument cannot be null"
);
}
this
.
clazz
=
clazz
;
}
/**
* 设置非空参数
* @param ps
* @param i
* @param parameter
* @param jdbcType
* @throws SQLException
*/
@Override
public
void
setNonNullParameter
(
PreparedStatement
ps
,
int
i
,
T
parameter
,
JdbcType
jdbcType
)
throws
SQLException
{
ps
.
setString
(
i
,
JSON
.
toJSONString
(
parameter
));
}
/**
* 根据列名,获取可以为空的结果
* @param rs
* @param columnName
* @return
* @throws SQLException
*/
@Override
public
T
getNullableResult
(
ResultSet
rs
,
String
columnName
)
throws
SQLException
{
String
sqlJson
=
rs
.
getString
(
columnName
);
if
(
null
!=
sqlJson
)
{
return
JSONObject
.
parseObject
(
sqlJson
,
clazz
);
}
return
null
;
}
/**
* 根据列索引,获取可以为空的结果
* @param rs
* @param columnIndex
* @return
* @throws SQLException
*/
@Override
public
T
getNullableResult
(
ResultSet
rs
,
int
columnIndex
)
throws
SQLException
{
String
sqlJson
=
rs
.
getString
(
columnIndex
);
if
(
null
!=
sqlJson
)
{
return
JSONObject
.
parseObject
(
sqlJson
,
clazz
);
}
return
null
;
}
@Override
public
T
getNullableResult
(
CallableStatement
cs
,
int
columnIndex
)
throws
SQLException
{
String
sqlJson
=
cs
.
getString
(
columnIndex
);
if
(
null
!=
sqlJson
)
{
return
JSONObject
.
parseObject
(
sqlJson
,
clazz
);
}
return
null
;
}
}
\ No newline at end of file
\ No newline at end of file
linkwe-framework/src/main/java/com/linkwechat/framework/handler/ListTypeHandler.java
0 → 100644
View file @
ee09693
package
com
.
linkwechat
.
framework
.
handler
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.domain.WeCustomer
;
import
com.linkwechat.wecom.domain.WeGroup
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.ibatis.type.*
;
import
java.sql.*
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 处理jsonArray字符串为pojoList
* @param <T>
*/
//支持的java对象
@SuppressWarnings
(
"all"
)
@MappedTypes
(
value
=
{
WeCustomer
.
class
,
WeGroup
.
class
})
@MappedJdbcTypes
({
JdbcType
.
VARCHAR
})
public
class
ListTypeHandler
<
T
extends
Object
>
implements
TypeHandler
<
List
<
T
>>
{
private
List
<
T
>
getListByJsonArrayString
(
String
content
)
{
if
(
StringUtils
.
isEmpty
(
content
))
{
return
new
ArrayList
<>();
}
return
JSON
.
parseObject
(
content
,
new
TypeReference
<
ArrayList
>(){});
}
/**
* 用于定义在Mybatis设置参数时该如何把Java类型的参数转换为对应的数据库类型
*
* <PRE>
* PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
* SET SALARY = ? WHERE ID = ?");
* pstmt.setBigDecimal(1, 153833.00)
* pstmt.setInt(2, 110592)
* </PRE>
*
* @param preparedStatement An object that represents a precompiled SQL statement
* @param i 当前参数的位置
* @param t 当前参数的Java对象
* @param jdbcType 当前参数的数据库类型
* @throws SQLException
*/
@Override
public
void
setParameter
(
PreparedStatement
preparedStatement
,
int
i
,
List
<
T
>
t
,
JdbcType
jdbcType
)
throws
SQLException
{
if
(
CollectionUtils
.
isEmpty
(
t
))
{
preparedStatement
.
setString
(
i
,
null
);
}
else
{
preparedStatement
.
setString
(
i
,
JSON
.
toJSONString
(
t
).
replaceAll
(
"[\ud800\udc00-\udbff\udfff\ud800-\udfff]"
,
""
));
}
}
@Override
public
List
<
T
>
getResult
(
ResultSet
resultSet
,
String
s
)
throws
SQLException
{
return
getListByJsonArrayString
(
resultSet
.
getString
(
s
));
}
@Override
public
List
<
T
>
getResult
(
ResultSet
resultSet
,
int
i
)
throws
SQLException
{
return
getListByJsonArrayString
(
resultSet
.
getString
(
i
));
}
@Override
public
List
<
T
>
getResult
(
CallableStatement
callableStatement
,
int
i
)
throws
SQLException
{
return
getListByJsonArrayString
(
callableStatement
.
getString
(
i
));
}
}
\ No newline at end of file
\ No newline at end of file
linkwe-quartz/src/main/java/com/linkwechat/quartz/task/RyTask.java
View file @
ee09693
...
@@ -2,16 +2,16 @@ package com.linkwechat.quartz.task;
...
@@ -2,16 +2,16 @@ package com.linkwechat.quartz.task;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.elasticsearch.ElasticSearch
;
import
com.linkwechat.common.core.elasticsearch.ElasticSearch
;
import
com.linkwechat.common.core.redis.RedisCache
;
import
com.linkwechat.common.core.redis.RedisCache
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.domain.WeCustomer
;
import
com.linkwechat.wecom.domain.WeCustomer
;
import
com.linkwechat.wecom.service.IWeChatContactMappingService
;
import
com.linkwechat.wecom.domain.WeCustomerMessageTimeTask
;
import
com.linkwechat.wecom.service.IWeCustomerService
;
import
com.linkwechat.wecom.mapper.WeCustomerMessageTimeTaskMapper
;
import
com.linkwechat.wecom.service.IWeSensitiveActHitService
;
import
com.linkwechat.wecom.service.*
;
import
com.linkwechat.wecom.service.IWeSensitiveService
;
import
com.tencent.wework.FinanceUtils
;
import
com.tencent.wework.FinanceUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
...
@@ -48,6 +48,11 @@ public class RyTask {
...
@@ -48,6 +48,11 @@ public class RyTask {
private
IWeSensitiveActHitService
weSensitiveActHitService
;
private
IWeSensitiveActHitService
weSensitiveActHitService
;
@Autowired
@Autowired
private
IWeCustomerService
weCustomerService
;
private
IWeCustomerService
weCustomerService
;
@Autowired
private
WeCustomerMessageTimeTaskMapper
customerMessageTimeTaskMapper
;
@Autowired
private
IWeCustomerMessageService
weCustomerMessageService
;
public
void
ryMultipleParams
(
String
s
,
Boolean
b
,
Long
l
,
Double
d
,
Integer
i
)
{
public
void
ryMultipleParams
(
String
s
,
Boolean
b
,
Long
l
,
Double
d
,
Integer
i
)
{
System
.
out
.
println
(
StringUtils
.
format
(
"执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}"
,
s
,
b
,
l
,
d
,
i
));
System
.
out
.
println
(
StringUtils
.
format
(
"执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}"
,
s
,
b
,
l
,
d
,
i
));
...
@@ -130,4 +135,24 @@ public class RyTask {
...
@@ -130,4 +135,24 @@ public class RyTask {
log
.
info
(
"执行有参方法: params:{},{}"
,
corpId
,
secret
);
log
.
info
(
"执行有参方法: params:{},{}"
,
corpId
,
secret
);
}
}
public
void
messageTask
(){
//获的当前时间的毫秒数
long
currentTime
=
System
.
currentTimeMillis
();
//customerMessageTimeTaskMapper
List
<
WeCustomerMessageTimeTask
>
weCustomerMessageTimeTasks
=
customerMessageTimeTaskMapper
.
selectWeCustomerMessageTimeTaskGteSettingTime
(
currentTime
);
if
(
CollectionUtils
.
isNotEmpty
(
weCustomerMessageTimeTasks
)){
weCustomerMessageTimeTasks
.
forEach
(
s
->{
try
{
weCustomerMessageService
.
sendMessgae
(
s
.
getMessageInfo
(),
s
.
getMessageId
(),
s
.
getCustomersInfo
(),
s
.
getGroupsInfo
());
}
catch
(
JsonProcessingException
e
)
{
log
.
error
(
"定时群发消息处理异常:ex:{}"
,
e
);
e
.
printStackTrace
();
}
});
}
}
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeCustomerMessageTimeTask.java
View file @
ee09693
...
@@ -2,10 +2,13 @@ package com.linkwechat.wecom.domain;
...
@@ -2,10 +2,13 @@ package com.linkwechat.wecom.domain;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
com.linkwechat.common.core.domain.BaseEntity
;
import
com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
/**
/**
* 群发消息定时任务表
* 群发消息定时任务表
* @author Kewen
* @author Kewen
...
@@ -14,7 +17,7 @@ import lombok.NoArgsConstructor;
...
@@ -14,7 +17,7 @@ import lombok.NoArgsConstructor;
@TableName
(
"we_customer_messageTimeTask"
)
@TableName
(
"we_customer_messageTimeTask"
)
public
class
WeCustomerMessageTimeTask
extends
BaseEntity
{
public
class
WeCustomerMessageTimeTask
extends
BaseEntity
{
public
WeCustomerMessageTimeTask
(
Long
messageId
,
String
messageInfo
,
String
customersInfo
,
String
groupsInfo
,
Long
settingTime
)
{
public
WeCustomerMessageTimeTask
(
Long
messageId
,
CustomerMessagePushDto
messageInfo
,
List
<
WeCustomer
>
customersInfo
,
List
<
WeGroup
>
groupsInfo
,
Long
settingTime
)
{
this
.
messageId
=
messageId
;
this
.
messageId
=
messageId
;
this
.
messageInfo
=
messageInfo
;
this
.
messageInfo
=
messageInfo
;
this
.
customersInfo
=
customersInfo
;
this
.
customersInfo
=
customersInfo
;
...
@@ -38,17 +41,17 @@ public class WeCustomerMessageTimeTask extends BaseEntity {
...
@@ -38,17 +41,17 @@ public class WeCustomerMessageTimeTask extends BaseEntity {
/**
/**
* 消息原始信息
* 消息原始信息
*/
*/
private
String
messageInfo
;
private
CustomerMessagePushDto
messageInfo
;
/**
/**
* 客户信息列表
* 客户信息列表
*/
*/
private
String
customersInfo
;
private
List
<
WeCustomer
>
customersInfo
;
/**
/**
* 客户群组信息列表
* 客户群组信息列表
*/
*/
private
String
groupsInfo
;
private
List
<
WeGroup
>
groupsInfo
;
/**
/**
* 定时时间的毫秒数
* 定时时间的毫秒数
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/mapper/WeCustomerMessageTimeTaskMapper.java
View file @
ee09693
...
@@ -2,6 +2,9 @@ package com.linkwechat.wecom.mapper;
...
@@ -2,6 +2,9 @@ package com.linkwechat.wecom.mapper;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.linkwechat.wecom.domain.WeCustomerMessageTimeTask
;
import
com.linkwechat.wecom.domain.WeCustomerMessageTimeTask
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
/**
* 群发消息 定时任务表 Mapper接口
* 群发消息 定时任务表 Mapper接口
...
@@ -10,4 +13,21 @@ import com.linkwechat.wecom.domain.WeCustomerMessageTimeTask;
...
@@ -10,4 +13,21 @@ import com.linkwechat.wecom.domain.WeCustomerMessageTimeTask;
* @date 2021-02-09
* @date 2021-02-09
*/
*/
public
interface
WeCustomerMessageTimeTaskMapper
extends
BaseMapper
<
WeCustomerMessageTimeTask
>
{
public
interface
WeCustomerMessageTimeTaskMapper
extends
BaseMapper
<
WeCustomerMessageTimeTask
>
{
/**
* 查询群发任务列表
*
* @param timeMillis 当前时间毫秒数
* @return {@link WeCustomerMessageTimeTask}s
*/
List
<
WeCustomerMessageTimeTask
>
selectWeCustomerMessageTimeTaskGteSettingTime
(
@Param
(
"timeMillis"
)
long
timeMillis
);
/**
* 保存群发任务
*
* @param customerMessageTimeTask 群发任务信息
* @return int
*/
int
saveWeCustomerMessageTimeTask
(
WeCustomerMessageTimeTask
customerMessageTimeTask
);
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeCustomerMessagePushServiceImpl.java
View file @
ee09693
...
@@ -133,12 +133,10 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
...
@@ -133,12 +133,10 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
weCustomerMessageService
.
sendMessgae
(
customerMessagePushDto
,
messageId
,
customers
,
groups
);
weCustomerMessageService
.
sendMessgae
(
customerMessagePushDto
,
messageId
,
customers
,
groups
);
}
else
{
}
else
{
WeCustomerMessageTimeTask
timeTask
=
new
WeCustomerMessageTimeTask
(
messageId
,
JSONUtil
.
toJsonStr
(
customerMessagePushDto
),
WeCustomerMessageTimeTask
timeTask
=
new
WeCustomerMessageTimeTask
(
messageId
,
customerMessagePushDto
,
customers
,
groups
JSONUtil
.
toJsonStr
(
customers
).
replaceAll
(
"[\ud800\udc00-\udbff\udfff\ud800-\udfff]"
,
""
)
,
JSONUtil
.
toJsonStr
(
groups
).
replaceAll
(
"[\ud800\udc00-\udbff\udfff\ud800-\udfff]"
,
""
)
,
DateUtils
.
getMillionSceondsBydate
(
customerMessagePushDto
.
getSettingTime
()));
,
DateUtils
.
getMillionSceondsBydate
(
customerMessagePushDto
.
getSettingTime
()));
customerMessageTimeTaskMapper
.
insert
(
timeTask
);
customerMessageTimeTaskMapper
.
saveWeCustomerMessageTimeTask
(
timeTask
);
}
}
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeTaskFissionServiceImpl.java
View file @
ee09693
...
@@ -199,7 +199,7 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
...
@@ -199,7 +199,7 @@ public class WeTaskFissionServiceImpl implements IWeTaskFissionService {
}
}
try
{
try
{
weCustomerMessagePushService
.
addWeCustomerMessagePush
(
customerMessagePushDto
);
weCustomerMessagePushService
.
addWeCustomerMessagePush
(
customerMessagePushDto
);
}
catch
(
JsonProcessingException
e
)
{
}
catch
(
JsonProcessingException
|
ParseException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
log
.
error
(
"发送任务失败》》》》》》》》》》》params:{},ex:{}"
,
JSONObject
.
toJSONString
(
customerMessagePushDto
),
e
);
log
.
error
(
"发送任务失败》》》》》》》》》》》params:{},ex:{}"
,
JSONObject
.
toJSONString
(
customerMessagePushDto
),
e
);
}
}
...
...
linkwe-wecom/src/main/resources/mapper/wecom/WeCustomerMessageTimeTaskMapper.xml
View file @
ee09693
...
@@ -3,4 +3,53 @@
...
@@ -3,4 +3,53 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.linkwechat.wecom.mapper.WeCustomerMessageTimeTaskMapper"
>
<mapper
namespace=
"com.linkwechat.wecom.mapper.WeCustomerMessageTimeTaskMapper"
>
<resultMap
id=
"tasks"
type=
"com.linkwechat.wecom.domain.WeCustomerMessageTimeTask"
>
<id
column=
"task_id"
property=
"taskId"
/>
<result
column=
"message_id"
property=
"messageId"
/>
<result
column=
"message_info"
property=
"messageInfo"
typeHandler=
"com.linkwechat.framework.handler.GenericTypeHandler"
/>
<result
column=
"customers_info"
property=
"customersInfo"
typeHandler=
"com.linkwechat.framework.handler.ListTypeHandler"
/>
<result
column=
"groups_info"
property=
"groupsInfo"
typeHandler=
"com.linkwechat.framework.handler.ListTypeHandler"
/>
<result
column=
"setting_time"
property=
"settingTime"
/>
</resultMap>
<insert
id=
"saveWeCustomerMessageTimeTask"
>
INSERT INTO we_customer_messageTimeTask (
message_id,
message_info,
customers_info,
groups_info,
setting_time,
create_by,
create_time,
update_by,
update_time
)
VALUES
(
#{messageId},
#{messageInfo,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.GenericTypeHandler},
#{customersInfo,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.ListTypeHandler},
#{groupsInfo,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.ListTypeHandler},
#{settingTime},
#{createBy},
#{createTime},
#{updateBy},
#{updateTime}
)
</insert>
<select
id=
"selectWeCustomerMessageTimeTaskGteSettingTime"
resultMap=
"tasks"
>
SELECT
message_id,
message_info,
customers_info,
groups_info,
setting_time
FROM
we_customer_messageTimeTask
<where>
setting_time lte #{timeMillis}
</where>
</select>
</mapper>
</mapper>
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment