Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
indicators
Overview
Overview
Details
Activity
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
zhangkb
indicators
Commits
355307d8
Commit
355307d8
authored
Jun 21, 2021
by
hzc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
集成企业微信消息通知
parent
8a7fa600
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
3 deletions
+109
-3
NoticeInfoCtrl.java
...om/keymobile/indicators/api/hytobacco/NoticeInfoCtrl.java
+4
-1
RoleRefUserModel.java
...m/keymobile/indicators/model/entity/RoleRefUserModel.java
+3
-0
SystemAuthService.java
...a/com/keymobile/indicators/service/SystemAuthService.java
+8
-1
TaskServiceImpl.java
...le/indicators/service/dataenter/impl/TaskServiceImpl.java
+1
-0
NoticeInfoServiceImpl.java
...mobile/indicators/service/impl/NoticeInfoServiceImpl.java
+93
-1
No files found.
src/main/java/com/keymobile/indicators/api/hytobacco/NoticeInfoCtrl.java
View file @
355307d8
...
@@ -74,7 +74,10 @@ public class NoticeInfoCtrl {
...
@@ -74,7 +74,10 @@ public class NoticeInfoCtrl {
@ApiOperation
(
"创建消息"
)
@ApiOperation
(
"创建消息"
)
@PostMapping
(
"createNotice"
)
@PostMapping
(
"createNotice"
)
public
Result
createNotice
(
@RequestBody
NoticeInfo
noticeInfo
){
public
Result
createNotice
(
@RequestBody
NoticeInfo
noticeInfo
){
noticeInfoService
.
insertNotice
(
noticeInfo
);
List
<
NoticeInfo
>
noticeInfos
=
new
ArrayList
<>();
noticeInfos
.
add
(
noticeInfo
);
//noticeInfoService.insertNotice(noticeInfo);
noticeInfoService
.
createNotices
(
noticeInfos
);
return
Result
.
genOkResult
();
return
Result
.
genOkResult
();
}
}
@ApiOperation
(
"批量创建消息(异步)"
)
@ApiOperation
(
"批量创建消息(异步)"
)
...
...
src/main/java/com/keymobile/indicators/model/entity/RoleRefUserModel.java
View file @
355307d8
...
@@ -21,6 +21,9 @@ public class RoleRefUserModel {
...
@@ -21,6 +21,9 @@ public class RoleRefUserModel {
@ApiModelProperty
(
"在此角色里面对应的指标归属部门"
)
@ApiModelProperty
(
"在此角色里面对应的指标归属部门"
)
private
String
refIndDept
;
private
String
refIndDept
;
@ApiModelProperty
(
"登录账号"
)
private
String
userId
;
@Override
@Override
public
boolean
equals
(
Object
o
)
{
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
if
(
this
==
o
)
{
...
...
src/main/java/com/keymobile/indicators/service/SystemAuthService.java
View file @
355307d8
package
com
.
keymobile
.
indicators
.
service
;
package
com
.
keymobile
.
indicators
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
@@ -73,5 +74,11 @@ public interface SystemAuthService {
...
@@ -73,5 +74,11 @@ public interface SystemAuthService {
*/
*/
@GetMapping
(
"/smartBi/clearAllPools"
)
@GetMapping
(
"/smartBi/clearAllPools"
)
void
clearAllPools
();
void
clearAllPools
();
/**
* 根据用户ID获取登录账号
*
* @return 登录账号用|分隔
*/
@GetMapping
(
"/user/getUserById"
)
String
getUserByIds
(
@RequestParam
List
<
String
>
userIds
)
;
}
}
src/main/java/com/keymobile/indicators/service/dataenter/impl/TaskServiceImpl.java
View file @
355307d8
...
@@ -739,6 +739,7 @@ public class TaskServiceImpl implements TaskService {
...
@@ -739,6 +739,7 @@ public class TaskServiceImpl implements TaskService {
user
.
setId
(
jo
.
getString
(
"id"
));
user
.
setId
(
jo
.
getString
(
"id"
));
user
.
setDisName
(
jo
.
getString
(
"disname"
));
user
.
setDisName
(
jo
.
getString
(
"disname"
));
user
.
setRefIndDept
(
jo
.
getString
(
"refIndDept"
));
user
.
setRefIndDept
(
jo
.
getString
(
"refIndDept"
));
user
.
setUserId
(
jo
.
getString
(
"userId"
));
String
refIndDept
=
user
.
getRefIndDept
();
String
refIndDept
=
user
.
getRefIndDept
();
if
(
StringUtils
.
isBlank
(
refIndDept
))
{
if
(
StringUtils
.
isBlank
(
refIndDept
))
{
continue
;
continue
;
...
...
src/main/java/com/keymobile/indicators/service/impl/NoticeInfoServiceImpl.java
View file @
355307d8
package
com
.
keymobile
.
indicators
.
service
.
impl
;
package
com
.
keymobile
.
indicators
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.keymobile.indicators.constant.Constants
;
import
com.keymobile.indicators.constant.Constants
;
import
com.keymobile.indicators.model.entity.NoticeInfo
;
import
com.keymobile.indicators.model.entity.NoticeInfo
;
import
com.keymobile.indicators.model.mapper.indicators.NoticeInfoMapper
;
import
com.keymobile.indicators.model.mapper.indicators.NoticeInfoMapper
;
import
com.keymobile.indicators.service.NoticeInfoService
;
import
com.keymobile.indicators.service.NoticeInfoService
;
import
com.keymobile.indicators.service.SystemAuthService
;
import
com.keymobile.indicators.utils.HttpUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.BooleanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@Slf4j
@Service
@Service
public
class
NoticeInfoServiceImpl
implements
NoticeInfoService
{
public
class
NoticeInfoServiceImpl
implements
NoticeInfoService
{
@Autowired
@Autowired
private
NoticeInfoMapper
noticeInfoMapper
;
private
NoticeInfoMapper
noticeInfoMapper
;
@Value
(
"${weChart.url}"
)
private
String
weChart_url
;
@Value
(
"${weChart.corpID}"
)
private
String
weChart_corpID
;
@Value
(
"${weChart.secret}"
)
private
String
weChart_secret
;
@Value
(
"${weChart.agentId}"
)
private
String
weChart_agentId
;
@Value
(
"${weChart.isSend}"
)
private
Boolean
isSend
;
@Autowired
private
SystemAuthService
systemAuthService
;
@Override
@Override
public
void
insertNotice
(
NoticeInfo
noticeInfo
)
{
public
void
insertNotice
(
NoticeInfo
noticeInfo
)
{
...
@@ -26,6 +49,50 @@ public class NoticeInfoServiceImpl implements NoticeInfoService {
...
@@ -26,6 +49,50 @@ public class NoticeInfoServiceImpl implements NoticeInfoService {
@Override
@Override
@Async
@Async
public
void
createNotices
(
List
<
NoticeInfo
>
notices
)
{
public
void
createNotices
(
List
<
NoticeInfo
>
notices
)
{
//
if
(
BooleanUtils
.
isTrue
(
isSend
)){
log
.
info
(
"准备发送湘烟通消息"
);
try
{
String
weChartToken
=
getWeChartToken
();
if
(
weChartToken
!=
null
){
//获取用户id,用于查登录账号
List
<
String
>
users
=
new
ArrayList
<>();
notices
.
stream
().
forEach
(
item
->{
users
.
add
(
item
.
getToUserId
());
});
String
weChartContent
=
getWeChartContent
(
notices
.
get
(
0
));
Map
<
String
,
String
>
textMap
=
new
HashMap
<>();
textMap
.
put
(
"content"
,
weChartContent
);
JSONObject
jsonObject
=
new
JSONObject
();
//获取用户--已经封装好格式-userid|userId
String
toUsers
=
systemAuthService
.
getUserByIds
(
users
);
// users.stream().collect(Collectors.joining("|"));
jsonObject
.
put
(
"touser"
,
toUsers
);
jsonObject
.
put
(
"msgtype"
,
"text"
);
jsonObject
.
put
(
"agentid"
,
weChart_agentId
);
jsonObject
.
put
(
"toparty"
,
""
);
jsonObject
.
put
(
"totag"
,
""
);
jsonObject
.
put
(
"text"
,
textMap
);
StringBuilder
url
=
new
StringBuilder
(
weChart_url
);
url
.
append
(
"cgi-bin/message/send?access_token="
);
url
.
append
(
weChartToken
);
log
.
info
(
"开始发送消息->url:{}"
,
url
);
log
.
info
(
"发送消息->param:{}"
,
jsonObject
.
toString
());
String
resp
=
HttpUtil
.
jsonPost
(
url
.
toString
(),
jsonObject
.
toString
());
JSONObject
respJson
=
JSONObject
.
parseObject
(
resp
);
Integer
errcode
=
respJson
.
getInteger
(
"errcode"
);
if
(
errcode
==
0
){
log
.
info
(
"========发送成功========="
);
}
else
{
log
.
info
(
"发送失败:获取JSON:{}"
,
respJson
);
}
}
}
catch
(
Exception
e
){
log
.
info
(
"发送湘烟通接口失败==="
);
e
.
printStackTrace
();
}
}
log
.
info
(
"开始发pc端消息。。。。"
);
noticeInfoMapper
.
batchInsert
(
notices
);
noticeInfoMapper
.
batchInsert
(
notices
);
}
}
...
@@ -67,4 +134,29 @@ public class NoticeInfoServiceImpl implements NoticeInfoService {
...
@@ -67,4 +134,29 @@ public class NoticeInfoServiceImpl implements NoticeInfoService {
params
.
put
(
"noticeClass"
,
noticeClass
);
params
.
put
(
"noticeClass"
,
noticeClass
);
noticeInfoMapper
.
updateToReadByToUsersAndTaskIdAndNoticeClass
(
params
);
noticeInfoMapper
.
updateToReadByToUsersAndTaskIdAndNoticeClass
(
params
);
}
}
private
String
getWeChartToken
(){
String
url
=
weChart_url
+
"cgi-bin/gettoken"
;
String
param
=
"corpid="
+
weChart_corpID
+
"&corpsecret="
+
weChart_secret
;
log
.
info
(
"获取token->url:{}"
,
url
);
log
.
info
(
"获取token->param:{}"
,
param
);
String
s
=
HttpUtil
.
sendGet
(
url
,
param
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
s
);
String
access_token
=
jsonObject
.
getString
(
"access_token"
);
log
.
info
(
"weChartToken:{}"
,
access_token
);
return
access_token
;
}
private
String
getWeChartContent
(
NoticeInfo
noticeInfo
){
StringBuilder
content
=
new
StringBuilder
(
"【对标系统】"
);
String
title
=
noticeInfo
.
getTitle
();
Map
<
Integer
,
String
>
noticeClassMap
=
new
HashMap
<>();
noticeClassMap
.
put
(
1
,
"数据填报"
);
noticeClassMap
.
put
(
2
,
"数据审核"
);
noticeClassMap
.
put
(
3
,
"对标对象锁定"
);
String
noticeClass
=
noticeClassMap
.
get
(
noticeInfo
.
getNoticeClass
());
content
.
append
(
noticeClass
);
content
.
append
(
"<br>"
);
content
.
append
(
title
);
return
content
.
toString
();
}
}
}
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