Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dingding
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
dingding
Commits
a05e24d0
提交
a05e24d0
authored
4月 30, 2020
作者:
liupengfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
钉钉通知消息
上级
72e0e579
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
246 行增加
和
4 行删除
+246
-4
Constant.java
src/main/java/com/config/Constant.java
+5
-0
URLConstant.java
src/main/java/com/config/URLConstant.java
+5
-0
CustomerController.java
...main/java/com/controller/customer/CustomerController.java
+27
-4
CustomerSaveConsumer.java
src/main/java/com/message/consumer/CustomerSaveConsumer.java
+19
-0
CustomerSaveLog.java
src/main/java/com/message/consumer/CustomerSaveLog.java
+27
-0
CustomerSaveSendDingTalk.java
...n/java/com/message/consumer/CustomerSaveSendDingTalk.java
+163
-0
没有找到文件。
src/main/java/com/config/Constant.java
浏览文件 @
a05e24d0
...
...
@@ -12,4 +12,9 @@ public class Constant {
* 开发者后台->企业自建应用->选择您创建的E应用->查看->AppSecret
*/
public
static
final
String
APP_SECRET
=
"qkRYMu5MFh3M_croU4asvAIh1XM7QOm_-gtNjTWCwNx_y4_xoxVLYo7D9zl28GGk"
;
/**
* 应用agentId
*/
public
static
final
long
AGENT_ID
=
616502456
l
;
}
src/main/java/com/config/URLConstant.java
浏览文件 @
a05e24d0
...
...
@@ -25,4 +25,9 @@ public class URLConstant {
* 获取管理员列表
*/
public
static
final
String
URL_ADMIN_LIST
=
"https://oapi.dingtalk.com/user/get_admin"
;
/**
* 发送工作通知消息
*/
public
static
final
String
URL_MESSAGE_SEND
=
"https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"
;
}
src/main/java/com/controller/customer/CustomerController.java
浏览文件 @
a05e24d0
package
com
.
controller
.
customer
;
import
java.util.Date
;
import
java.util.Map
;
import
com.util.StringUtils
;
import
com.message.consumer.CustomerSaveConsumer
;
import
com.util.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -13,9 +15,6 @@ import com.excetion.BaseException;
import
com.form.customer.QueryCustomerForm
;
import
com.model.customer.Customer
;
import
com.service.customer.CustomerService
;
import
com.util.CallBack
;
import
com.util.PageInfo
;
import
com.util.PageParam
;
import
com.vo.customer.CustomerVo
;
import
io.swagger.annotations.Api
;
...
...
@@ -29,6 +28,9 @@ public class CustomerController {
@Autowired
private
CustomerService
service
;
@Autowired
private
SpringContextUtils
springContextUtils
;
@ApiOperation
(
value
=
"保存客户信息"
,
notes
=
"保存客户信息"
)
@PostMapping
(
"/save"
)
public
CallBack
<?>
save
(
Customer
entity
){
...
...
@@ -48,6 +50,7 @@ public class CustomerController {
entity
.
setAllotTime
(
old
.
getAllotTime
());
}
service
.
updateByPrimaryKey
(
entity
);
this
.
saveAppendHandler
(
old
,
entity
);
return
CallBack
.
success
();
}
if
(
StringUtils
.
isNotEmpty
(
entity
.
getUserId
()))
{
...
...
@@ -56,12 +59,14 @@ public class CustomerController {
}
entity
.
setCreateTime
(
new
Date
());
service
.
insert
(
entity
);
this
.
saveAppendHandler
(
null
,
entity
);
return
CallBack
.
success
(
entity
.
getId
());
}
@ApiOperation
(
value
=
"查询客户信息"
,
notes
=
"查询全部客户信息"
)
@GetMapping
(
"/page"
)
public
CallBack
<
PageInfo
<
CustomerVo
>>
page
(
PageParam
pageParam
,
QueryCustomerForm
form
)
{
// TODO 访问权限验证 查看当前的用户 是否为本公司的用户
return
CallBack
.
success
(
service
.
page
(
pageParam
,
form
));
}
...
...
@@ -74,4 +79,22 @@ public class CustomerController {
}
return
CallBack
.
success
(
service
.
selectByPrimaryKey
(
id
));
}
/**
* Description: 增强 保存客户信息 逻辑,不影响操作结果
* @param
* @return void
* @author lpf
* @date 2020-04-29 16:07
*/
private
void
saveAppendHandler
(
Customer
old
,
Customer
newObj
)
{
Map
<
String
,
CustomerSaveConsumer
>
map
=
springContextUtils
.
getContext
().
getBeansOfType
(
CustomerSaveConsumer
.
class
);
if
(
map
.
isEmpty
())
{
// 无增强逻辑
return
;
}
map
.
keySet
().
parallelStream
().
map
(
map
::
get
).
forEach
(
c
->
{
// 执行增强逻辑
c
.
accept
(
old
,
newObj
);
});
}
}
src/main/java/com/message/consumer/CustomerSaveConsumer.java
0 → 100644
浏览文件 @
a05e24d0
package
com
.
message
.
consumer
;
import
com.model.customer.Customer
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
java.util.function.BiConsumer
;
/**
* Title: CustomerSaveConsumer
* Description: 客户信息保存,附加逻辑
* (oldObj, newObj) -> {}
* @author lpf
* @version V1.0
* @date 2020-04-29
*/
public
interface
CustomerSaveConsumer
extends
BiConsumer
<
Customer
,
Customer
>,
Ordered
{
}
src/main/java/com/message/consumer/CustomerSaveLog.java
0 → 100644
浏览文件 @
a05e24d0
package
com
.
message
.
consumer
;
import
com.model.customer.Customer
;
import
org.springframework.stereotype.Component
;
/**
* Title: CustomerSaveLog
* Description: 客户信息保存,保存更改负责人的提交记录
*
* @author lpf
* @version V1.0
* @date 2020-04-29
*/
@Component
public
class
CustomerSaveLog
implements
CustomerSaveConsumer
{
@Override
public
void
accept
(
Customer
old
,
Customer
newObj
)
{
// TODO
System
.
out
.
println
(
" 客户信息保存,保存更改负责人的提交记录"
);
}
@Override
public
int
getOrder
()
{
return
1
;
}
}
src/main/java/com/message/consumer/CustomerSaveSendDingTalk.java
0 → 100644
浏览文件 @
a05e24d0
package
com
.
message
.
consumer
;
import
com.config.Constant
;
import
com.config.URLConstant
;
import
com.dingtalk.api.DefaultDingTalkClient
;
import
com.dingtalk.api.DingTalkClient
;
import
com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request
;
import
com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response
;
import
com.model.customer.Customer
;
import
com.taobao.api.ApiException
;
import
com.util.AccessTokenUtil
;
import
com.util.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
/**
* Title: CustomerSaveSendDingTalk
* Description: 客户信息保存发送钉钉 工作通知消息
*
* @author lpf
* @version V1.0
* @date 2020-04-29
*/
@Component
public
class
CustomerSaveSendDingTalk
implements
CustomerSaveConsumer
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
CustomerSaveSendDingTalk
.
class
);
/** 0217504529598819 池总 */
private
final
String
ADMIN_ID_LIST
=
"0217504529598819"
;
/** 526150051021491847 lpf 测试 */
// private final String ADMIN_ID_LIST = "526150051021491847";
/**
* Description: 钉钉发送工作通知消息
* 同一个应用相同消息的内容同一个用户一天只能接收一次。
* 同一个应用给同一个用户发送消息,企业内部开发方式一天不得超过500次
* 通过设置to_all_user参数全员推送消息,一天最多3次
* 超出以上限制次数后,接口返回成功,但用户无法接收到
* 该接口是异步发送消息,接口返回成功并不表示用户一定会收到消息
* @param old
* @param newObj
* @return void
* @author lpf
* @date 2020-04-30 10:23
*/
@Override
public
void
accept
(
Customer
old
,
Customer
newObj
)
{
String
title
;
String
msg
=
"客户:"
+
newObj
.
getCompanyName
()
+
"; \n "
;
if
(
old
==
null
)
{
title
=
"客户新增"
;
if
(
StringUtils
.
isNotEmpty
(
newObj
.
getUserId
()))
{
// 负责人id不为空, 给负责人发送工作通知消息
msg
=
msg
+
"由 **"
+
newObj
.
getUserName
()
+
"** 负责; \n "
;
this
.
sendMessage
(
newObj
.
getUserId
(),
title
,
msg
);
}
}
else
{
title
=
"客户负责人更改"
;
// 修改指派时间标记,修改的用户和旧用户不一致的情况,则更新指派时间
boolean
upFlag
=
StringUtils
.
isNotEmpty
(
newObj
.
getUserId
())
&&
!
newObj
.
getUserId
().
equals
(
old
.
getUserId
());
boolean
upFlag1
=
StringUtils
.
isNotEmpty
(
old
.
getUserId
())
&&
!
old
.
getUserId
().
equals
(
newObj
.
getUserId
());
if
(!(
upFlag
||
upFlag1
))
{
// 指派人未发生改变的情况下不需要发送通知
log
.
info
(
"指派人未发生改变,不需要发送消息通知"
);
return
;
}
if
(
StringUtils
.
isNotEmpty
(
old
.
getUserId
()))
{
// 旧负责人存在,消息拼接
msg
=
msg
+
"old负责人:"
+
old
.
getUserName
()
+
"; \n "
;
}
else
{
msg
=
msg
+
"公共资源; \n "
;
}
if
(
StringUtils
.
isNotEmpty
(
newObj
.
getUserId
()))
{
// 新负责人存在,消息拼接
msg
=
msg
+
"现由 **"
+
newObj
.
getUserName
()
+
"** 负责; \n "
;
}
else
{
msg
=
msg
+
"无负责人,已存放到公共资源中; \n "
;
}
if
(
StringUtils
.
isNotEmpty
(
old
.
getUserId
()))
{
// 旧对象的 负责人id不为空 给旧的负责人发送工作通知短信
this
.
sendMessage
(
old
.
getUserId
(),
title
,
msg
);
}
if
(
StringUtils
.
isNotEmpty
(
newObj
.
getUserId
()))
{
// 新的负责人id不为空 给新负责人发送 工作通知短信
this
.
sendMessage
(
newObj
.
getUserId
(),
title
,
msg
);
}
}
// 给管理员发送通知短信
this
.
sendMessage
(
ADMIN_ID_LIST
,
title
,
msg
);
log
.
info
(
newObj
.
getId
()
+
";"
+
title
+
msg
+
";消息通知完毕"
);
}
@Override
public
int
getOrder
()
{
return
6
;
}
/**
* Description: 发送markdown文本消息
* @param userIdList
* @param title 标题
* @param text 内容
* @return void
* @author lpf
* @date 2020-04-30 9:26
*/
private
void
sendMessage
(
String
userIdList
,
String
title
,
String
text
)
{
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
msg
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
();
msg
.
setMsgtype
(
"markdown"
);
msg
.
setMarkdown
(
new
OapiMessageCorpconversationAsyncsendV2Request
.
Markdown
());
title
=
"## "
+
title
;
text
=
title
+
" \n #### "
+
text
;
log
.
info
(
"钉钉markdown消息 title: "
+
title
);
log
.
info
(
"钉钉markdown消息 text: "
+
text
);
msg
.
getMarkdown
().
setTitle
(
title
);
msg
.
getMarkdown
().
setText
(
text
);
this
.
sendMessage
(
userIdList
,
msg
);
}
/**
* Description: 发送文本消息
* @param userIdList
* @param text
* @return void
* @author lpf
* @date 2020-04-30 9:12
*/
private
void
sendMessage
(
String
userIdList
,
String
text
)
{
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
msg
=
new
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
();
msg
.
setMsgtype
(
"text"
);
msg
.
setText
(
new
OapiMessageCorpconversationAsyncsendV2Request
.
Text
());
msg
.
getText
().
setContent
(
text
);
this
.
sendMessage
(
userIdList
,
msg
);
}
private
void
sendMessage
(
String
userIdList
,
OapiMessageCorpconversationAsyncsendV2Request
.
Msg
msg
)
{
log
.
info
(
"给负责人发送短消息,消息内容:"
+
msg
);
String
accessToken
=
AccessTokenUtil
.
getToken
();
DingTalkClient
client
=
new
DefaultDingTalkClient
(
URLConstant
.
URL_MESSAGE_SEND
);
OapiMessageCorpconversationAsyncsendV2Request
request
=
new
OapiMessageCorpconversationAsyncsendV2Request
();
request
.
setUseridList
(
userIdList
);
request
.
setAgentId
(
Constant
.
AGENT_ID
);
request
.
setMsg
(
msg
);
OapiMessageCorpconversationAsyncsendV2Response
response
;
try
{
response
=
client
.
execute
(
request
,
accessToken
);
log
.
info
(
"发送短消息响应:"
+
response
.
getBody
());
}
catch
(
ApiException
e
)
{
e
.
printStackTrace
();
log
.
error
(
"发送工作通知消息失败:"
+
e
.
toString
());
// TODO 消息没有被消费wo
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论