Commit 1f80a71b by fudahua

企业微信标签同步fix

parent b4a9e650
...@@ -66,4 +66,23 @@ public interface QywxTagRelationMapper { ...@@ -66,4 +66,23 @@ public interface QywxTagRelationMapper {
* @return * @return
*/ */
List<TabQywxTagRelation> listByQywxTagId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("qywxTagId") String qywxTagId); 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 { ...@@ -146,6 +146,16 @@ public interface QywxTagService {
*/ */
public boolean delQywxTagItemById(String wxEnterpriseId, String id); 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; ...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.service.impl;
import com.gic.commons.util.ToolUtil; import com.gic.commons.util.ToolUtil;
import com.gic.haoban.manage.api.dto.QywxTagInfoDTO; import com.gic.haoban.manage.api.dto.QywxTagInfoDTO;
import com.gic.haoban.manage.api.dto.QywxTagItemDTO; 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.QywxTagItemMapper;
import com.gic.haoban.manage.service.dao.mapper.QywxTagMapper; import com.gic.haoban.manage.service.dao.mapper.QywxTagMapper;
import com.gic.haoban.manage.service.dao.mapper.QywxTagRelationMapper; import com.gic.haoban.manage.service.dao.mapper.QywxTagRelationMapper;
...@@ -187,4 +188,21 @@ public class QywxTagServiceImpl implements QywxTagService { ...@@ -187,4 +188,21 @@ public class QywxTagServiceImpl implements QywxTagService {
qywxTagItemMapper.updateByPrimaryKeySelective(item); qywxTagItemMapper.updateByPrimaryKeySelective(item);
return true; 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 { ...@@ -217,37 +217,37 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
QywxTagRelationTypeEnum relationTypeEnum = QywxTagRelationTypeEnum.getByTagType(callbackDTO.getTagType()); QywxTagRelationTypeEnum relationTypeEnum = QywxTagRelationTypeEnum.getByTagType(callbackDTO.getTagType());
//标签组 //标签组
if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_GROUP.getTagType()) { if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_GROUP.getTagType()) {
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId()); List<String> ids = new ArrayList<>();
if (null == qywxGroupKey) { ids.add(callbackDTO.getTagId());
logger.info("原型不存在,不需要处理"); QywxGetCorpTagListDTO tagDetail = qywxSuiteApiService.getCorpTagList(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), ids, QywxTagRelationTypeEnum.TAG_GROUP.getType());
return; if (tagDetail.getErrcode() != 0) {
} logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagDetail));
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxGroupKey.getQywxTagId());
//没有同步的关系 删除保存企业微信标签
if (CollectionUtils.isEmpty(relations)) {
logger.info("删除保存的企业微信标签");
qywxTagService.delQywxTag(callbackDTO.getTagId(), wxEnterpriseDto.getWxEnterpriseId());
return; return;
} }
List<String> groupIds = new ArrayList<>(); //保存标签项
groupIds.add(callbackDTO.getTagId()); qywxTagService.saveQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), tagDetail.getTagGroup().get(0));
qywxSuiteApiService.delCorpTag(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), groupIds, QywxTagRelationTypeEnum.TAG_GROUP.getType());
//标签项 //标签项
} else if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_ITEM.getTagType()) { } else if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_ITEM.getTagType()) {
TabQywxTagItem qywxTagItem = qywxTagService.getQywxTagItemByQywxItemKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId()); //查找对应的标签组 如果标签组关联了
if (null == qywxTagItem) { List<String> ids = new ArrayList<>();
List<String> ids = new ArrayList<>(); ids.add(callbackDTO.getTagId());
ids.add(callbackDTO.getTagId()); QywxGetCorpTagListDTO tagDetail = qywxSuiteApiService.getCorpTagList(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), ids, QywxTagRelationTypeEnum.TAG_ITEM.getType());
QywxGetCorpTagListDTO tagList = qywxSuiteApiService.getCorpTagList(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), ids, QywxTagRelationTypeEnum.TAG_ITEM.getType()); if (tagDetail.getErrcode() != 0) {
logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagList)); logger.info("没有关联,无需操作:{}", JSONObject.toJSONString(tagDetail));
return; return;
} }
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagId()); if (CollectionUtils.isEmpty(tagDetail.getTagGroup())) {
if (CollectionUtils.isEmpty(relations)) { logger.info("标签组不存在:{}", JSONObject.toJSONString(tagDetail));
logger.info("直接删除标签项"); return;
qywxTagService.delQywxTagItemById(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagItemId()); }
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; return;
} }
//关联的话 需要删除标签
List<String> items = new ArrayList<>(); List<String> items = new ArrayList<>();
items.add(callbackDTO.getTagId()); items.add(callbackDTO.getTagId());
qywxSuiteApiService.delCorpTag(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), items, QywxTagRelationTypeEnum.TAG_ITEM.getType()); qywxSuiteApiService.delCorpTag(wxEnterpriseDto.getCorpid(), config.getWxSuiteid(), items, QywxTagRelationTypeEnum.TAG_ITEM.getType());
...@@ -286,19 +286,14 @@ public class QywxTagApiServiceImpl implements QywxTagApiService { ...@@ -286,19 +286,14 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
this.reSyncTagGroupBack(wxEnterpriseDto.getWxEnterpriseId(), relations, qywxGroupKey, tabQywxTagItems); this.reSyncTagGroupBack(wxEnterpriseDto.getWxEnterpriseId(), relations, qywxGroupKey, tabQywxTagItems);
//标签项 //标签项
} else if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_ITEM.getTagType()) { } else if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_ITEM.getTagType()) {
TabQywxTagItem qywxTagItem = qywxTagService.getQywxTagItemByQywxItemKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId()); TabQywxTagRelation qywxTagRelation = qywxTagService.getQywxTagRelationByQywxKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId(), QywxTagRelationTypeEnum.TAG_ITEM.getType());
if (null == qywxTagItem) { if (null == qywxTagRelation) {
logger.info("没有关联,无需操作"); logger.info("没有关联,无需操作");
return; qywxTagService.delQywxTagItemById(wxEnterpriseDto.getWxEnterpriseId(), qywxTagRelation.getQywxTagItemId());
}
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagId());
if (CollectionUtils.isEmpty(relations)) {
logger.info("直接删除标签项");
qywxTagService.delQywxTagItemById(wxEnterpriseDto.getWxEnterpriseId(), qywxTagItem.getQywxTagItemId());
return; return;
} }
//同步 //同步
reSyncQywxTagItem(wxEnterpriseDto.getWxEnterpriseId(), relations, qywxTagItem); reSyncQywxTagItem(wxEnterpriseDto.getWxEnterpriseId(), qywxTagRelation);
} }
...@@ -349,21 +344,19 @@ public class QywxTagApiServiceImpl implements QywxTagApiService { ...@@ -349,21 +344,19 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
* 同步标签项 * 同步标签项
* *
* @param wxEnterpriseId * @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()); TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxTagId(wxEnterpriseId, itemRelation.getQywxTagId());
//各自关联关系
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);
QywxTagInfoDTO qywxTagInfoDTO = new QywxTagInfoDTO(); QywxTagInfoDTO qywxTagInfoDTO = new QywxTagInfoDTO();
qywxTagInfoDTO.setWxEnterpriseId(wxEnterpriseId); qywxTagInfoDTO.setWxEnterpriseId(wxEnterpriseId);
qywxTagInfoDTO.setMemberTagId(groupRelation.getMemberTagId()); qywxTagInfoDTO.setMemberTagId(itemRelation.getMemberTagId());
qywxTagInfoDTO.setQywxGroupKey(qywxGroupKey.getQywxGroupKey()); qywxTagInfoDTO.setQywxGroupKey(qywxGroupKey.getQywxGroupKey());
qywxTagInfoDTO.setOrder(qywxGroupKey.getOrder()); qywxTagInfoDTO.setOrder(qywxGroupKey.getOrder());
...@@ -375,7 +368,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService { ...@@ -375,7 +368,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
qywxTagItemDTO.setOrder(qywxTagItem.getOrder()); qywxTagItemDTO.setOrder(qywxTagItem.getOrder());
itemList.add(qywxTagItemDTO); 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 { ...@@ -395,19 +388,15 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
QywxTagRelationTypeEnum relationTypeEnum = QywxTagRelationTypeEnum.getByTagType(callbackDTO.getTagType()); QywxTagRelationTypeEnum relationTypeEnum = QywxTagRelationTypeEnum.getByTagType(callbackDTO.getTagType());
//标签组 //标签组
if (relationTypeEnum.getTagType() == QywxTagRelationTypeEnum.TAG_GROUP.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("原型不存在,不需要处理"); logger.info("原型不存在,不需要处理");
return; //todo 保存
}
List<TabQywxTagRelation> relations = qywxTagService.listQywxTagRelationByQywxTagId(wxEnterpriseDto.getWxEnterpriseId(), qywxGroupKey.getQywxTagId());
//没有同步的关系 删除保存企业微信标签
if (CollectionUtils.isEmpty(relations)) {
logger.info("删除保存的企业微信标签");
qywxTagService.delQywxTag(callbackDTO.getTagId(), wxEnterpriseDto.getWxEnterpriseId());
return; return;
} }
//名称同步回去 //名称同步回去
TabQywxTag qywxGroupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseDto.getWxEnterpriseId(), callbackDTO.getTagId());
QywxTagDTO qywxTagDTO = new QywxTagDTO(); QywxTagDTO qywxTagDTO = new QywxTagDTO();
qywxTagDTO.setId(callbackDTO.getTagId()); qywxTagDTO.setId(callbackDTO.getTagId());
qywxTagDTO.setName(qywxGroupKey.getQywxGroupName()); qywxTagDTO.setName(qywxGroupKey.getQywxGroupName());
......
...@@ -224,4 +224,26 @@ ...@@ -224,4 +224,26 @@
and status_flag=1 and status_flag=1
and sync_flag=1 and sync_flag=1
</select> </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> </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