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
QianQiXiang
haoban-manage3.0
Commits
f5dffa4f
Commit
f5dffa4f
authored
Jul 23, 2021
by
fudahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
企业为西标签
parent
f641a17b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
143 additions
and
5 deletions
+143
-5
QywxTagApiService.java
.../com/gic/haoban/manage/api/service/QywxTagApiService.java
+2
-1
QywxTagItemMapper.java
...c/haoban/manage/service/dao/mapper/QywxTagItemMapper.java
+10
-0
QywxTagService.java
...com/gic/haoban/manage/service/service/QywxTagService.java
+8
-0
QywxTagServiceImpl.java
...aoban/manage/service/service/impl/QywxTagServiceImpl.java
+5
-0
QywxTagApiServiceImpl.java
...anage/service/service/out/impl/QywxTagApiServiceImpl.java
+105
-4
QywxTagItemMapper.xml
...3-service/src/main/resources/mapper/QywxTagItemMapper.xml
+13
-0
No files found.
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/service/QywxTagApiService.java
View file @
f5dffa4f
package
com
.
gic
.
haoban
.
manage
.
api
.
service
;
import
com.gic.haoban.base.api.common.ServiceResponse
;
import
com.gic.haoban.manage.api.dto.QywxTagCallbackDTO
;
import
com.gic.haoban.manage.api.dto.QywxTagInfoDTO
;
import
com.gic.haoban.manage.api.dto.QywxTagItemDTO
;
...
...
@@ -72,6 +73,6 @@ public interface QywxTagApiService {
* @param enterpriseId
* @param externalUserId
*/
public
void
syncFriendTagToQywxByExternalUserId
(
String
wxEnterpriseId
,
String
enterpriseId
,
String
externalUserId
,
String
tagItemId
);
public
ServiceResponse
syncFriendTagToQywxByExternalUserId
(
String
wxEnterpriseId
,
String
enterpriseId
,
String
externalUserId
,
List
<
String
>
tagItemIds
);
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/dao/mapper/QywxTagItemMapper.java
View file @
f5dffa4f
...
...
@@ -67,4 +67,13 @@ public interface QywxTagItemMapper {
* @return
*/
TabQywxTagItem
getByQywxTagKey
(
@Param
(
"wxEnterpriseId"
)
String
wxEnterpriseId
,
@Param
(
"qywxTagKey"
)
String
qywxTagKey
);
/**
* 根据id 获取标签项信息
*
* @param wxEnterpriseId
* @param ids
* @return
*/
List
<
TabQywxTagItem
>
listByQywxTagItemsIds
(
@Param
(
"wxEnterpriseId"
)
String
wxEnterpriseId
,
@Param
(
"ids"
)
List
<
String
>
ids
);
}
\ No newline at end of file
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/QywxTagService.java
View file @
f5dffa4f
...
...
@@ -156,6 +156,14 @@ public interface QywxTagService {
*/
public
TabQywxTagRelation
getQywxTagRelationByQywxKey
(
String
wxEnterpriseId
,
String
key
,
Integer
qywxTagRelationType
);
/**
* 根据企业微信的标签项获取 标签项列表
*
* @param wxEnterpriseId
* @param ids
* @return
*/
public
List
<
TabQywxTagItem
>
listQywxTagItemByIds
(
String
wxEnterpriseId
,
List
<
String
>
ids
);
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/impl/QywxTagServiceImpl.java
View file @
f5dffa4f
...
...
@@ -205,4 +205,9 @@ public class QywxTagServiceImpl implements QywxTagService {
return
qywxTagRelationMapper
.
getQywxTagByQywxTagItemId
(
wxEnterpriseId
,
qywxTagItem
.
getQywxTagItemId
());
}
}
@Override
public
List
<
TabQywxTagItem
>
listQywxTagItemByIds
(
String
wxEnterpriseId
,
List
<
String
>
ids
)
{
return
qywxTagItemMapper
.
listByQywxTagItemsIds
(
wxEnterpriseId
,
ids
);
}
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/QywxTagApiServiceImpl.java
View file @
f5dffa4f
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
out
.
impl
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.commons.util.ToolUtil
;
import
com.gic.haoban.base.api.common.ServiceResponse
;
import
com.gic.haoban.common.utils.EntityUtil
;
import
com.gic.haoban.manage.api.dto.*
;
import
com.gic.haoban.manage.api.enums.QywxTagRelationTypeEnum
;
...
...
@@ -12,6 +14,7 @@ import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise;
import
com.gic.haoban.manage.service.entity.TabQywxTag
;
import
com.gic.haoban.manage.service.entity.TabQywxTagItem
;
import
com.gic.haoban.manage.service.entity.TabQywxTagRelation
;
import
com.gic.haoban.manage.service.exception.WxApiLimitException
;
import
com.gic.haoban.manage.service.service.QywxTagService
;
import
com.gic.haoban.manage.service.service.WxEnterpriseService
;
import
com.gic.wechat.api.dto.qywx.QywxTagDTO
;
...
...
@@ -20,6 +23,7 @@ import com.gic.wechat.api.dto.qywx.response.QywxGetCorpTagListDTO;
import
com.gic.wechat.api.dto.qywx.response.QywxResponseDTO
;
import
com.gic.wechat.api.service.qywx.QywxSuiteApiService
;
import
com.gic.wechat.api.service.qywx.QywxUserApiService
;
import
com.google.common.collect.Sets
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.slf4j.Logger
;
...
...
@@ -27,9 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
...
...
@@ -58,6 +60,9 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
@Autowired
private
DealSyncOperationApiService
dealSyncOperationApiService
;
@Autowired
private
QywxUserApiService
qywxUserApiService
;
@Override
public
void
pullQywxTag
(
String
wxEnterpriseId
)
{
WxEnterpriseDTO
wxEnterpriseDTO
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
...
...
@@ -432,7 +437,103 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
}
@Override
public
void
syncFriendTagToQywxByExternalUserId
(
String
wxEnterpriseId
,
String
enterpriseId
,
String
externalUserId
,
String
tagItemId
)
{
public
ServiceResponse
syncFriendTagToQywxByExternalUserId
(
String
wxEnterpriseId
,
String
enterpriseId
,
String
externalUserId
,
List
<
String
>
tagItemIds
)
{
ServiceResponse
resp
=
new
ServiceResponse
();
List
<
TabQywxTagRelation
>
relations
=
qywxTagService
.
listAllQywxRelation
(
wxEnterpriseId
);
if
(
CollectionUtils
.
isEmpty
(
relations
))
{
resp
.
setCode
(
2
);
resp
.
setMessage
(
"没有需要同步的标签"
);
return
resp
;
}
List
<
String
>
syncTagItemsIds
=
relations
.
stream
()
.
filter
(
dto
->
dto
.
getRelationType
()
==
QywxTagRelationTypeEnum
.
TAG_ITEM
.
getType
()
&&
tagItemIds
.
contains
(
dto
.
getTagItemId
()))
.
map
(
dto
->
dto
.
getQywxTagItemId
()).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
syncTagItemsIds
))
{
resp
.
setCode
(
3
);
resp
.
setMessage
(
"没有同步的标签项"
);
return
resp
;
}
//同步的标签项
List
<
TabQywxTagItem
>
tagItems
=
qywxTagService
.
listQywxTagItemByIds
(
wxEnterpriseId
,
syncTagItemsIds
);
Set
<
String
>
qywxTagKes
=
tagItems
.
stream
().
map
(
dto
->
dto
.
getQywxTagKey
()).
collect
(
Collectors
.
toSet
());
WxEnterpriseDTO
wxEnterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
//查询外部联系人
String
externalUseridInfo
=
qywxUserApiService
.
getExternalUseridInfo
(
wxEnterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
externalUserId
);
if
(
StringUtils
.
isBlank
(
externalUseridInfo
))
{
logger
.
info
(
"好友不存在"
);
resp
.
setCode
(
3
);
resp
.
setMessage
(
"好友不存在"
);
return
resp
;
}
else
if
(
externalUseridInfo
.
equals
(
"1"
))
{
logger
.
info
(
"限制次数"
);
resp
.
setCode
(
45033
);
resp
.
setMessage
(
"getExternalUseridInfo接口次数限制"
);
return
resp
;
}
Map
<
String
,
Set
<
String
>>
externalTagMap
=
getExternalTagMap
(
externalUseridInfo
);
if
(
null
==
externalTagMap
)
{
logger
.
info
(
"没有好友需要同步"
);
resp
.
setCode
(
5
);
resp
.
setMessage
(
"没有好友需要同步"
);
return
resp
;
}
//同步好友
externalTagMap
.
forEach
((
wxUserId
,
haveTagKes
)
->
{
//获取需要打的标签
Sets
.
SetView
<
String
>
needSetTags
=
Sets
.
difference
(
qywxTagKes
,
haveTagKes
);
//todo 获取需要删除的标签
Set
<
String
>
needDelTags
=
new
HashSet
<>();
if
(
CollectionUtils
.
isEmpty
(
needDelTags
)
&&
CollectionUtils
.
isEmpty
(
needSetTags
))
{
logger
.
info
(
"不需要"
);
return
;
}
QywxResponseDTO
responseDTO
=
qywxUserApiService
.
markTag
(
wxEnterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
wxUserId
,
externalUserId
,
needSetTags
,
needDelTags
);
if
(
responseDTO
.
getErrcode
()
!=
0
)
{
logger
.
info
(
"权限不对"
);
resp
.
setMessage
(
responseDTO
.
getErrmsg
());
resp
.
setCode
(
responseDTO
.
getErrcode
());
return
;
}
});
return
resp
;
}
private
Map
<
String
,
Set
<
String
>>
getExternalTagMap
(
String
externalUseridInfo
)
{
Map
<
String
,
Set
<
String
>>
ret
=
new
HashMap
<>();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
externalUseridInfo
);
if
(!
jsonObject
.
containsKey
(
"external_contact"
))
{
logger
.
info
(
"用户信息不存在"
);
return
null
;
}
JSONObject
externalContact
=
jsonObject
.
getJSONObject
(
"external_contact"
);
if
(!
externalContact
.
containsKey
(
"follow_user"
))
{
logger
.
info
(
"没有相关的好友"
);
return
null
;
}
JSONArray
followUser
=
externalContact
.
getJSONArray
(
"follow_user"
);
for
(
int
i
=
0
;
i
<
followUser
.
size
();
i
++)
{
JSONObject
midUser
=
followUser
.
getJSONObject
(
i
);
String
wxUserId
=
midUser
.
getString
(
"userid"
);
Set
<
String
>
midTagIds
=
new
HashSet
<>();
if
(!
midUser
.
containsKey
(
"tags"
))
{
ret
.
put
(
wxUserId
,
midTagIds
);
continue
;
}
JSONArray
tags
=
midUser
.
getJSONArray
(
"tags"
);
for
(
int
n
=
0
;
n
<
tags
.
size
();
n
++)
{
JSONObject
tagMid
=
tags
.
getJSONObject
(
n
);
String
tagId
=
tagMid
.
getString
(
"tag_id"
);
String
tagType
=
tagMid
.
getString
(
"type"
);
if
(
tagType
.
equals
(
"1"
))
{
midTagIds
.
add
(
tagId
);
}
}
ret
.
put
(
wxUserId
,
midTagIds
);
}
return
ret
;
}
}
haoban-manage3-service/src/main/resources/mapper/QywxTagItemMapper.xml
View file @
f5dffa4f
...
...
@@ -187,4 +187,16 @@
and status_flag=1
and wx_enterprise_id=#{wxEnterpriseId}
</select>
<select
id=
"listByQywxTagItemsIds"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from tab_haoban_qywx_tag_item
where qywx_tag_item_id in
<foreach
collection=
"ids"
open=
"("
close=
")"
separator=
","
item=
"item"
>
#{item}
</foreach>
and status_flag=1
and wx_enterprise_id=#{wxEnterpriseId}
</select>
</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