Commit 1f80a71b by fudahua

企业微信标签同步fix

parent b4a9e650
......@@ -66,4 +66,23 @@ public interface QywxTagRelationMapper {
* @return
*/
List<TabQywxTagRelation> listByQywxTagId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("qywxTagId") String qywxTagId);
/**
* 查询企业下标签组的关联
*
* @param wxEnterpriseId
* @param qywxTagId
* @return
*/
TabQywxTagRelation getQywxGroupByQywxTagId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("qywxTagId") String qywxTagId);
/**
* 查询企业下标签项的关联
*
* @param wxEnterpriseId
* @param qywxTagItemId
* @return
*/
TabQywxTagRelation getQywxTagByQywxTagItemId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("qywxTagItemId") String qywxTagItemId);
}
\ No newline at end of file
......@@ -146,6 +146,16 @@ public interface QywxTagService {
*/
public boolean delQywxTagItemById(String wxEnterpriseId, String id);
/**
* 根据企业微信的key 查询关联关系
*
* @param wxEnterpriseId
* @param key
* @param qywxTagRelationType
* @return
*/
public TabQywxTagRelation getQywxTagRelationByQywxKey(String wxEnterpriseId, String key, Integer qywxTagRelationType);
}
......@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.service.impl;
import com.gic.commons.util.ToolUtil;
import com.gic.haoban.manage.api.dto.QywxTagInfoDTO;
import com.gic.haoban.manage.api.dto.QywxTagItemDTO;
import com.gic.haoban.manage.api.enums.QywxTagRelationTypeEnum;
import com.gic.haoban.manage.service.dao.mapper.QywxTagItemMapper;
import com.gic.haoban.manage.service.dao.mapper.QywxTagMapper;
import com.gic.haoban.manage.service.dao.mapper.QywxTagRelationMapper;
......@@ -187,4 +188,21 @@ public class QywxTagServiceImpl implements QywxTagService {
qywxTagItemMapper.updateByPrimaryKeySelective(item);
return true;
}
@Override
public TabQywxTagRelation getQywxTagRelationByQywxKey(String wxEnterpriseId, String key, Integer qywxTagRelationType) {
if (qywxTagRelationType == QywxTagRelationTypeEnum.TAG_GROUP.getType()) {
TabQywxTag qywxGroupKey = qywxTagMapper.getByQywxGroupKey(wxEnterpriseId, key);
if (null == qywxGroupKey) {
return null;
}
return qywxTagRelationMapper.getQywxGroupByQywxTagId(wxEnterpriseId, qywxGroupKey.getQywxTagId());
} else {
TabQywxTagItem qywxTagItem = qywxTagItemMapper.getByQywxTagKey(wxEnterpriseId, key);
if (null == qywxTagItem) {
return null;
}
return qywxTagRelationMapper.getQywxTagByQywxTagItemId(wxEnterpriseId, qywxTagItem.getQywxTagItemId());
}
}
}
......@@ -217,37 +217,37 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
QywxTagRelationTypeEnum relationTypeEnum = QywxTagRelationTypeEnum.getByTagType(callbackDTO.getTagType());
//标签组
if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_GROUP.getTagType()) {
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId());
if (null == qywxGroupKey) {
logger.info("原型不存在,不需要处理");
return;
}
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxGroupKey.getQywxTagId());
//没有同步的关系 删除保存企业微信标签
if (CollectionUtils.isEmpty(relations)) {
logger.info("删除保存的企业微信标签");
qywxTagService.delQywxTag(callbackDTO.getTagId(), wxEnterpriseDto.getWxEnterpriseId());
List<String> ids = new ArrayList<>();
ids.add(callbackDTO.getTagId());
QywxGetCorpTagListDTO tagDetail = qywxSuiteApiService.getCorpTagList(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), ids, QywxTagRelationTypeEnum.TAG_GROUP.getType());
if (tagDetail.getErrcode() != 0) {
logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagDetail));
return;
}
List<String> groupIds = new ArrayList<>();
groupIds.add(callbackDTO.getTagId());
qywxSuiteApiService.delCorpTag(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), groupIds, QywxTagRelationTypeEnum.TAG_GROUP.getType());
//保存标签项
qywxTagService.saveQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), tagDetail.getTagGroup().get(0));
//标签项
} else if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_ITEM.getTagType()) {
TabQywxTagItem qywxTagItem = qywxTagService.getQywxTagItemByQywxItemKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId());
if (null == qywxTagItem) {
List<String> ids = new ArrayList<>();
ids.add(callbackDTO.getTagId());
QywxGetCorpTagListDTO tagList = qywxSuiteApiService.getCorpTagList(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), ids, QywxTagRelationTypeEnum.TAG_ITEM.getType());
logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagList));
//查找对应的标签组 如果标签组关联了
List<String> ids = new ArrayList<>();
ids.add(callbackDTO.getTagId());
QywxGetCorpTagListDTO tagDetail = qywxSuiteApiService.getCorpTagList(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), ids, QywxTagRelationTypeEnum.TAG_ITEM.getType());
if (tagDetail.getErrcode() != 0) {
logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagDetail));
return;
}
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagId());
if (CollectionUtils.isEmpty(relations)) {
logger.info("直接删除标签项");
qywxTagService.delQywxTagItemById(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagItemId());
if (CollectionUtils.isEmpty(tagDetail.getTagGroup())) {
logger.info("标签组不存在:{}", JSONObject.toJSONString(tagDetail));
return;
}
QywxTagGroupDTO qywxTagGroupDTO = tagDetail.getTagGroup().get(0);
TabQywxTagRelation relationByQywxKey = qywxTagService.getQywxTagRelationByQywxKey(wxEnterpriseDto.getWxEnterpriseId(), qywxTagGroupDTO.getGroupId(), QywxTagRelationTypeEnum.TAG_GROUP.getType());
if (null == relationByQywxKey) {
logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagDetail));
return;
}
//关联的话 需要删除标签
List<String> items = new ArrayList<>();
items.add(callbackDTO.getTagId());
qywxSuiteApiService.delCorpTag(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), items, QywxTagRelationTypeEnum.TAG_ITEM.getType());
......@@ -286,19 +286,14 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
this.reSyncTagGroupBack(wxEnterpriseDto.getWxEnterpriseId(), relations, qywxGroupKey, tabQywxTagItems);
//标签项
} else if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_ITEM.getTagType()) {
TabQywxTagItem qywxTagItem = qywxTagService.getQywxTagItemByQywxItemKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId());
if (null == qywxTagItem) {
TabQywxTagRelation qywxTagRelation = qywxTagService.getQywxTagRelationByQywxKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId(), QywxTagRelationTypeEnum.TAG_ITEM.getType());
if (null == qywxTagRelation) {
logger.info("没有关联,无需操作");
return;
}
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagId());
if (CollectionUtils.isEmpty(relations)) {
logger.info("直接删除标签项");
qywxTagService.delQywxTagItemById(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagItemId());
qywxTagService.delQywxTagItemById(wxEnterpriseDto.getWxEnterpriseId(), qywxTagRelation.getQywxTagItemId());
return;
}
//同步
reSyncQywxTagItem(wxEnterpriseDto.getWxEnterpriseId(), relations, qywxTagItem);
reSyncQywxTagItem(wxEnterpriseDto.getWxEnterpriseId(), qywxTagRelation);
}
......@@ -349,21 +344,19 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
* 同步标签项
*
* @param wxEnterpriseId
* @param qywxTagItem
* @param itemRelation
*/
private void reSyncQywxTagItem(String wxEnterpriseId, List<TabQywxTagRelation> relations, TabQywxTagItem qywxTagItem) {
private void reSyncQywxTagItem(String wxEnterpriseId, TabQywxTagRelation itemRelation) {
TabQywxTagItem qywxTagItem = qywxTagService.getQywxTagItemByQywxItemKey(wxEnterpriseId, itemRelation.getQywxTagItemId());
//删除标签
qywxTagService.delQywxTagItemById(wxEnterpriseId, qywxTagItem.getQywxTagItemId());
qywxTagService.delQywxTagItemById(wxEnterpriseId, itemRelation.getQywxTagItemId());
//同步标签项
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseId, qywxTagItem.getQywxGroupKey());
//各自关联关系
TabQywxTagRelation groupRelation = relations.stream().filter(dto -> dto.getRelationType() == QywxTagRelationTypeEnum.TAG_GROUP.getType()).findFirst().get();
TabQywxTagRelation itemRelation = relations.stream().filter(dto -> (dto.getRelationType() == QywxTagRelationTypeEnum.TAG_ITEM.getType() && qywxTagItem.getQywxTagItemId().equals(dto.getQywxTagItemId()))).findFirst().orElse(null);
//同步的标签项
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxTagId(wxEnterpriseId, itemRelation.getQywxTagId());
QywxTagInfoDTO qywxTagInfoDTO = new QywxTagInfoDTO();
qywxTagInfoDTO.setWxEnterpriseId(wxEnterpriseId);
qywxTagInfoDTO.setMemberTagId(groupRelation.getMemberTagId());
qywxTagInfoDTO.setMemberTagId(itemRelation.getMemberTagId());
qywxTagInfoDTO.setQywxGroupKey(qywxGroupKey.getQywxGroupKey());
qywxTagInfoDTO.setOrder(qywxGroupKey.getOrder());
......@@ -375,7 +368,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
qywxTagItemDTO.setOrder(qywxTagItem.getOrder());
itemList.add(qywxTagItemDTO);
//同步
this.syncTagToQywx(wxEnterpriseId, groupRelation.getEnterpriseId(), qywxTagInfoDTO, itemList);
this.syncTagToQywx(wxEnterpriseId, itemRelation.getEnterpriseId(), qywxTagInfoDTO, itemList);
}
......@@ -395,19 +388,15 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
QywxTagRelationTypeEnum relationTypeEnum = QywxTagRelationTypeEnum.getByTagType(callbackDTO.getTagType());
//标签组
if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_GROUP.getTagType()) {
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId());
if (null == qywxGroupKey) {
//判断是否存在关联 存在需要同步回去
TabQywxTagRelation relaton = qywxTagService.getQywxTagRelationByQywxKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId(), QywxTagRelationTypeEnum.TAG_GROUP.getType());
if (null == relaton) {
logger.info("原型不存在,不需要处理");
return;
}
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxGroupKey.getQywxTagId());
//没有同步的关系 删除保存企业微信标签
if (CollectionUtils.isEmpty(relations)) {
logger.info("删除保存的企业微信标签");
qywxTagService.delQywxTag(callbackDTO.getTagId(), wxEnterpriseDto.getWxEnterpriseId());
//todo 保存
return;
}
//名称同步回去
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId());
QywxTagDTO qywxTagDTO = new QywxTagDTO();
qywxTagDTO.setId(callbackDTO.getTagId());
qywxTagDTO.setName(qywxGroupKey.getQywxGroupName());
......
......@@ -224,4 +224,26 @@
and status_flag=1
and sync_flag=1
</select>
<select id="getQywxGroupByQywxTagId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_qywx_tag_relation
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
and qywx_tag_id = #{qywxTagId,jdbcType=VARCHAR}
and relation_type=0
and status_flag=1
and sync_flag=1
</select>
<select id="getQywxTagByQywxTagItemId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_qywx_tag_relation
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
and qywx_tag_item_id = #{qywxTagId,jdbcType=VARCHAR}
and relation_type=1
and status_flag=1
and sync_flag=1
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment