Commit 6e8239a3 by fudahua

企业微信标签同步

parent c850417c
......@@ -7,6 +7,7 @@ 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.wechat.api.dto.qywx.QywxTagGroupDTO;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
......@@ -49,7 +50,7 @@ public interface QywxTagService {
* @param groupDTO
* @return
*/
public void saveQywxTagByQywxGroupKey(String wxEnterpriseId, QywxTagGroupDTO groupDTO);
public Pair<TabQywxTag, List<TabQywxTagItem>> saveQywxTagByQywxGroupKey(String wxEnterpriseId, QywxTagGroupDTO groupDTO);
/**
......
......@@ -12,6 +12,7 @@ import com.gic.haoban.manage.service.entity.TabQywxTagRelation;
import com.gic.haoban.manage.service.service.QywxTagService;
import com.gic.wechat.api.dto.qywx.QywxTagDTO;
import com.gic.wechat.api.dto.qywx.QywxTagGroupDTO;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
......@@ -52,7 +53,7 @@ public class QywxTagServiceImpl implements QywxTagService {
}
@Override
public void saveQywxTagByQywxGroupKey(String wxEnterpriseId, QywxTagGroupDTO groupDTO) {
public Pair<TabQywxTag, List<TabQywxTagItem>> saveQywxTagByQywxGroupKey(String wxEnterpriseId, QywxTagGroupDTO groupDTO) {
//判断保存 分组
TabQywxTag qywxTag = this.getQywxTagByQywxGroupKey(wxEnterpriseId, groupDTO.getGroupId());
if (null == qywxTag) {
......@@ -75,7 +76,7 @@ public class QywxTagServiceImpl implements QywxTagService {
List<QywxTagDTO> dtos = groupDTO.getTag();
if (CollectionUtils.isEmpty(dtos)) {
return;
return null;
}
Map<String, TabQywxTagItem> itemMap = new HashMap<>();
List<TabQywxTagItem> orgItems = this.listByQywxTagId(wxEnterpriseId, qywxTag.getQywxTagId());
......@@ -108,6 +109,7 @@ public class QywxTagServiceImpl implements QywxTagService {
}
items.add(qywxTagItem);
}
return Pair.of(qywxTag, items);
}
@Override
......
......@@ -21,6 +21,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 org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -93,9 +94,13 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
List<QywxTagGroupDTO> tagGroup = resp.getTagGroup();
QywxTagGroupDTO groupDTO = tagGroup.get(0);
//保存企业微信标签信息
qywxTagService.saveQywxTagByQywxGroupKey(wxEnterpriseId, groupDTO);
Pair<TabQywxTag, List<TabQywxTagItem>> savePair = qywxTagService.saveQywxTagByQywxGroupKey(wxEnterpriseId, groupDTO);
if (null == savePair) {
logger.info("保存失败:{}", JSONObject.toJSONString(groupDTO));
return;
}
//保存关联关系
saveRelation(wxEnterpriseId, enterpriseId, infoDTO, items);
saveRelation(wxEnterpriseId, enterpriseId, infoDTO, items, savePair);
//todo 后续处理 比如同步会员标签等
......@@ -108,11 +113,11 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
* @param enterpriseId
* @param infoDTO
*/
private void saveRelation(String wxEnterpriseId, String enterpriseId, QywxTagInfoDTO infoDTO, List<QywxTagItemDTO> items) {
private void saveRelation(String wxEnterpriseId, String enterpriseId, QywxTagInfoDTO infoDTO, List<QywxTagItemDTO> items, Pair<TabQywxTag, List<TabQywxTagItem>> localQywxTagPair) {
Map<String, QywxTagItemDTO> orgMap = items.stream().collect(Collectors.toMap(item -> item.getQywxTagName(), dto -> dto));
//设置关联关系
TabQywxTag groupKey = qywxTagService.getQywxTagByQywxGroupKey(wxEnterpriseId, infoDTO.getQywxGroupKey());
List<TabQywxTagItem> tabQywxTagItems = qywxTagService.listByQywxTagId(wxEnterpriseId, groupKey.getQywxTagId());
TabQywxTag groupKey = localQywxTagPair.getKey();
List<TabQywxTagItem> tabQywxTagItems = localQywxTagPair.getRight();
List<TabQywxTagRelation> saveRelationList = new ArrayList<>();
TabQywxTagRelation groupRelation = new TabQywxTagRelation();
......@@ -154,7 +159,6 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
*/
private QywxGetCorpTagListDTO saveQywxTag(WxEnterpriseDTO wxEnterpriseDTO, QywxTagInfoDTO infoDTO, List<QywxTagItemDTO> items) {
QywxTagGroupDTO qywxTagGroupDTO = new QywxTagGroupDTO();
qywxTagGroupDTO.setGroupId(infoDTO.getQywxGroupKey());
qywxTagGroupDTO.setGroupName("GIC" + infoDTO.getQywxGroupName());
qywxTagGroupDTO.setOrder(infoDTO.getOrder());
......
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