Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
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
haoban3.0
haoban-manage3.0
Commits
0be28b3b
Commit
0be28b3b
authored
Jun 07, 2022
by
墨竹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:企微标签打标签改为消息队列
parent
4bd8c1c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
86 deletions
+65
-86
QywxTagApiService.java
.../com/gic/haoban/manage/api/service/QywxTagApiService.java
+10
-0
QywxTagApiServiceImpl.java
...anage/service/service/out/impl/QywxTagApiServiceImpl.java
+55
-86
No files found.
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/service/QywxTagApiService.java
View file @
0be28b3b
...
@@ -162,4 +162,14 @@ public interface QywxTagApiService {
...
@@ -162,4 +162,14 @@ public interface QywxTagApiService {
*/
*/
public
void
checkQywxSync
(
String
params
);
public
void
checkQywxSync
(
String
params
);
/**
* 企微打标签
* "routerName": "qywxMarkTagMq"
*
* @param param 参数
* @author mozhu
* @date 2022-06-06 17:21:58
*/
void
qywxMarkTag
(
String
param
);
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/QywxTagApiServiceImpl.java
View file @
0be28b3b
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
out
.
impl
;
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
out
.
impl
;
import
cn.hutool.core.convert.Convert
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.commons.util.GICMQClientUtil
;
import
com.gic.commons.util.GICMQClientUtil
;
...
@@ -26,6 +28,7 @@ import com.gic.member.api.service.MemberTagService;
...
@@ -26,6 +28,7 @@ import com.gic.member.api.service.MemberTagService;
import
com.gic.member.tag.api.dto.MemberTagItemDTO
;
import
com.gic.member.tag.api.dto.MemberTagItemDTO
;
import
com.gic.member.tag.api.service.MemberTagItemApiService
;
import
com.gic.member.tag.api.service.MemberTagItemApiService
;
import
com.gic.mq.sdk.GicMQClient
;
import
com.gic.mq.sdk.GicMQClient
;
import
com.gic.redis.data.util.RedisUtil
;
import
com.gic.wechat.api.dto.qywx.QywxTagDTO
;
import
com.gic.wechat.api.dto.qywx.QywxTagDTO
;
import
com.gic.wechat.api.dto.qywx.QywxTagGroupDTO
;
import
com.gic.wechat.api.dto.qywx.QywxTagGroupDTO
;
import
com.gic.wechat.api.dto.qywx.response.QywxGetCorpTagListDTO
;
import
com.gic.wechat.api.dto.qywx.response.QywxGetCorpTagListDTO
;
...
@@ -42,6 +45,7 @@ import org.springframework.stereotype.Service;
...
@@ -42,6 +45,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
...
@@ -54,7 +58,10 @@ import static org.slf4j.LoggerFactory.getLogger;
...
@@ -54,7 +58,10 @@ import static org.slf4j.LoggerFactory.getLogger;
@Service
@Service
public
class
QywxTagApiServiceImpl
implements
QywxTagApiService
{
public
class
QywxTagApiServiceImpl
implements
QywxTagApiService
{
private
static
final
Logger
logger
=
getLogger
(
QywxTagApiServiceImpl
.
class
);
private
static
final
Logger
logger
=
getLogger
(
QywxTagApiServiceImpl
.
class
);
/**
* 限制次数
*/
private
static
final
Integer
MAX_TIMES
=
3
;
@Autowired
@Autowired
private
QywxSuiteApiService
qywxSuiteApiService
;
private
QywxSuiteApiService
qywxSuiteApiService
;
...
@@ -361,81 +368,6 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
...
@@ -361,81 +368,6 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
private
void
saveCloseTask
(
String
tagName
,
String
staffId
,
String
wxEnterpriseId
,
String
enterpriseId
)
{
private
void
saveCloseTask
(
String
tagName
,
String
staffId
,
String
wxEnterpriseId
,
String
enterpriseId
)
{
String
content
=
tagName
+
"-关闭标签同步成功"
;
String
content
=
tagName
+
"-关闭标签同步成功"
;
qywxTagSyncApiService
.
saveCloseTask
(
staffId
,
wxEnterpriseId
,
enterpriseId
,
content
,
QywxTaskStatusEnum
.
ALL_SUCCESS
.
getType
());
qywxTagSyncApiService
.
saveCloseTask
(
staffId
,
wxEnterpriseId
,
enterpriseId
,
content
,
QywxTaskStatusEnum
.
ALL_SUCCESS
.
getType
());
}
/**
* 重新同步
*
* @param wxEnterpriseId
* @param relations
* @param qywxGroupKey
* @param tabQywxTagItems
*/
private
void
reSyncTagGroupBack
(
String
wxEnterpriseId
,
List
<
TabQywxTagRelation
>
relations
,
TabQywxTag
qywxGroupKey
,
List
<
TabQywxTagItem
>
tabQywxTagItems
)
{
TabQywxTagRelation
tagRelation
=
relations
.
get
(
0
);
String
enterpriseId
=
tagRelation
.
getEnterpriseId
();
String
memberTagId
=
tagRelation
.
getMemberTagId
();
//关闭同步
qywxTagService
.
closeSync
(
wxEnterpriseId
,
memberTagId
);
qywxTagService
.
delQywxTag
(
qywxGroupKey
.
getQywxGroupKey
(),
wxEnterpriseId
);
//重新同步
Map
<
String
,
TabQywxTagRelation
>
relationMap
=
relations
.
stream
().
collect
(
Collectors
.
toMap
(
dto
->
{
if
(
dto
.
getRelationType
()
==
QywxTagRelationTypeEnum
.
TAG_GROUP
.
getType
())
{
return
dto
.
getQywxTagId
();
}
else
{
return
dto
.
getQywxTagItemId
();
}
},
dto
->
dto
));
QywxTagInfoDTO
qywxTagInfoDTO
=
new
QywxTagInfoDTO
();
qywxTagInfoDTO
.
setMemberTagId
(
memberTagId
);
qywxTagInfoDTO
.
setQywxGroupName
(
qywxGroupKey
.
getQywxGroupName
());
qywxTagInfoDTO
.
setWxEnterpriseId
(
qywxGroupKey
.
getWxEnterpriseId
());
List
<
QywxTagItemDTO
>
items
=
tabQywxTagItems
.
stream
().
map
(
item
->
{
TabQywxTagRelation
relation
=
relationMap
.
get
(
item
.
getQywxTagItemId
());
QywxTagItemDTO
mid
=
new
QywxTagItemDTO
();
mid
.
setMemberTagItemId
(
relation
.
getTagItemId
());
mid
.
setQywxTagName
(
item
.
getQywxTagName
());
return
mid
;
}).
collect
(
Collectors
.
toList
());
//同步回去
this
.
syncTagToQywx
(
wxEnterpriseId
,
enterpriseId
,
qywxTagInfoDTO
,
items
);
}
/**
* 同步标签项
*
* @param wxEnterpriseId
* @param itemRelation
*/
private
void
reSyncQywxTagItem
(
String
wxEnterpriseId
,
TabQywxTagRelation
itemRelation
)
{
TabQywxTagItem
qywxTagItem
=
qywxTagService
.
getQywxTagItemByQywxItemKey
(
wxEnterpriseId
,
itemRelation
.
getQywxTagItemId
());
//删除标签
qywxTagService
.
delQywxTagItemById
(
wxEnterpriseId
,
itemRelation
.
getQywxTagItemId
());
//同步的标签项
TabQywxTag
qywxGroupKey
=
qywxTagService
.
getQywxTagByQywxTagId
(
wxEnterpriseId
,
itemRelation
.
getQywxTagId
());
QywxTagInfoDTO
qywxTagInfoDTO
=
new
QywxTagInfoDTO
();
qywxTagInfoDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
qywxTagInfoDTO
.
setMemberTagId
(
itemRelation
.
getMemberTagId
());
qywxTagInfoDTO
.
setQywxGroupKey
(
qywxGroupKey
.
getQywxGroupKey
());
qywxTagInfoDTO
.
setOrder
(
qywxGroupKey
.
getOrder
());
List
<
QywxTagItemDTO
>
itemList
=
new
ArrayList
<>();
QywxTagItemDTO
qywxTagItemDTO
=
new
QywxTagItemDTO
();
qywxTagItemDTO
.
setMemberTagItemId
(
itemRelation
.
getTagItemId
());
qywxTagItemDTO
.
setQywxTagName
(
qywxTagItem
.
getQywxTagName
());
qywxTagItemDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
qywxTagItemDTO
.
setOrder
(
qywxTagItem
.
getOrder
());
itemList
.
add
(
qywxTagItemDTO
);
//同步
this
.
syncTagToQywx
(
wxEnterpriseId
,
itemRelation
.
getEnterpriseId
(),
qywxTagInfoDTO
,
itemList
);
}
}
@Override
@Override
...
@@ -457,7 +389,6 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
...
@@ -457,7 +389,6 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
TabQywxTagRelation
relaton
=
qywxTagService
.
getQywxTagRelationByQywxKey
(
wxEnterpriseDto
.
getWxEnterpriseId
(),
callbackDTO
.
getTagId
(),
QywxTagRelationTypeEnum
.
TAG_GROUP
.
getType
());
TabQywxTagRelation
relaton
=
qywxTagService
.
getQywxTagRelationByQywxKey
(
wxEnterpriseDto
.
getWxEnterpriseId
(),
callbackDTO
.
getTagId
(),
QywxTagRelationTypeEnum
.
TAG_GROUP
.
getType
());
if
(
null
==
relaton
)
{
if
(
null
==
relaton
)
{
logger
.
info
(
"原型不存在,不需要处理"
);
logger
.
info
(
"原型不存在,不需要处理"
);
//todo 保存
return
;
return
;
}
}
//名称同步回去
//名称同步回去
...
@@ -509,7 +440,8 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
...
@@ -509,7 +440,8 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
WxEnterpriseDTO
wxEnterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
WxEnterpriseDTO
wxEnterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
//查询外部联系人
//查询外部联系人
String
externalUseridInfo
=
qywxUserApiService
.
getExternalUseridInfo
(
wxEnterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
externalUserId
);
String
wxSuiteid
=
config
.
getWxSuiteid
();
String
externalUseridInfo
=
qywxUserApiService
.
getExternalUseridInfo
(
wxEnterprise
.
getCorpid
(),
wxSuiteid
,
externalUserId
);
if
(
StringUtils
.
isBlank
(
externalUseridInfo
))
{
if
(
StringUtils
.
isBlank
(
externalUseridInfo
))
{
logger
.
info
(
"好友不存在"
);
logger
.
info
(
"好友不存在"
);
resp
.
setCode
(
3
);
resp
.
setCode
(
3
);
...
@@ -545,18 +477,24 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
...
@@ -545,18 +477,24 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
Sets
.
SetView
<
String
>
needSetTags
=
Sets
.
difference
(
entQywxTagKeys
,
entHasSetQywxTagKeys
);
Sets
.
SetView
<
String
>
needSetTags
=
Sets
.
difference
(
entQywxTagKeys
,
entHasSetQywxTagKeys
);
//需要删除的标签
//需要删除的标签
Sets
.
SetView
<
String
>
needDelTags
=
Sets
.
difference
(
entHasSetQywxTagKeys
,
entQywxTagKeys
);
Sets
.
SetView
<
String
>
needDelTags
=
Sets
.
difference
(
entHasSetQywxTagKeys
,
entQywxTagKeys
);
if
(
CollectionUtils
.
isEmpty
(
needDelTags
)
&&
CollectionUtils
.
isEmpty
(
needSetTags
))
{
if
(
CollectionUtils
.
isEmpty
(
needDelTags
)
&&
CollectionUtils
.
isEmpty
(
needSetTags
))
{
logger
.
info
(
"不需要操作:{},{}"
,
wxUserId
,
externalUserId
);
logger
.
info
(
"不需要操作:{},{}"
,
wxUserId
,
externalUserId
);
return
;
return
;
}
}
// TODO: 2022/6/6 后续改为消息队列
QywxResponseDTO
responseDTO
=
qywxUserApiService
.
markTag
(
wxEnterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
wxUserId
,
externalUserId
,
needSetTags
,
needDelTags
);
JSONObject
jsonObject
=
new
JSONObject
();
logger
.
info
(
"操作返回:{}"
,
JSONObject
.
toJSONString
(
responseDTO
));
jsonObject
.
put
(
"corpid"
,
wxEnterprise
.
getCorpid
());
if
(
responseDTO
.
getErrcode
()
!=
0
)
{
jsonObject
.
put
(
"suiteId"
,
wxSuiteid
);
logger
.
info
(
"权限不对:{},{}"
,
wxUserId
,
externalUserId
);
jsonObject
.
put
(
"wxUserId"
,
wxUserId
);
resp
.
setMessage
(
responseDTO
.
getErrmsg
());
jsonObject
.
put
(
"externalUserId"
,
externalUserId
);
resp
.
setCode
(
responseDTO
.
getErrcode
());
jsonObject
.
put
(
"needSetTags"
,
StringUtils
.
join
(
needSetTags
,
","
));
return
;
jsonObject
.
put
(
"needDelTags"
,
StringUtils
.
join
(
needDelTags
,
","
));
GicMQClient
clientInstance
=
GICMQClientUtil
.
getClientInstance
();
try
{
clientInstance
.
sendMessage
(
"qywxMarkTagMq"
,
jsonObject
.
toJSONString
());
}
catch
(
Exception
e
)
{
logger
.
info
(
"企微标签同步qywxMarkTagMq发送失败:{}"
,
e
.
getMessage
(),
e
);
}
}
});
});
return
resp
;
return
resp
;
...
@@ -984,4 +922,35 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
...
@@ -984,4 +922,35 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
return
null
;
return
null
;
}
}
@Override
public
void
qywxMarkTag
(
String
param
)
{
JSONObject
jsonObject
=
JSON
.
parseObject
(
param
);
String
corpid
=
jsonObject
.
getString
(
"corpid"
);
String
suiteId
=
jsonObject
.
getString
(
"suiteId"
);
String
wxUserId
=
jsonObject
.
getString
(
"wxUserId"
);
String
externalUserId
=
jsonObject
.
getString
(
"externalUserId"
);
String
needSetTags
=
jsonObject
.
getString
(
"needSetTags"
);
String
needDelTags
=
jsonObject
.
getString
(
"needDelTags"
);
String
key
=
"HAOBAN:QYWX:TAG:"
+
wxUserId
+
externalUserId
;
//重试5次
Integer
currentTimes
=
Convert
.
toInt
(
RedisUtil
.
getCache
(
key
),
0
);
if
(
currentTimes
>
MAX_TIMES
)
{
logger
.
error
(
"企微打标签超过最大次数,key:{}"
,
key
);
return
;
}
QywxResponseDTO
responseDTO
=
qywxUserApiService
.
markTag
(
corpid
,
suiteId
,
wxUserId
,
externalUserId
,
new
HashSet
<>(
Arrays
.
asList
(
needSetTags
.
split
(
","
))),
new
HashSet
<>(
Arrays
.
asList
(
needDelTags
.
split
(
","
))));
logger
.
info
(
"操作返回:{}"
,
JSONObject
.
toJSONString
(
responseDTO
));
if
(
responseDTO
.
getErrcode
()
!=
0
)
{
logger
.
info
(
"权限不对,重试三次:{},{}"
,
wxUserId
,
externalUserId
);
GicMQClient
clientInstance
=
GICMQClientUtil
.
getClientInstance
();
try
{
clientInstance
.
sendMessage
(
"qywxMarkTagMq"
,
jsonObject
.
toJSONString
(),
30
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"企微标签同步qywxMarkTagMq发送失败:{}"
,
e
.
getMessage
(),
e
);
}
RedisUtil
.
setCache
(
key
,
currentTimes
+
1
,
2L
,
TimeUnit
.
HOURS
);
}
}
}
}
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