Commit a8b87e74 by 徐高华

标签同步

parent 50cf0193
......@@ -68,6 +68,8 @@ public interface QywxTagRelationMapper {
*/
int delByMemberTagId(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("memberTagId") String memberTagId);
int delById(@Param("id") String id);
/**
* 查询企业下所有同步的
*
......
......@@ -895,8 +895,9 @@ public class DealSyncOperationApiServiceImpl implements DealSyncOperationApiServ
this.syncTaskService.updateTaskStatus(taskId,4) ;
}
if(task.getCreateTime().getTime()+1000*60*60*3< System.currentTimeMillis()) {
logger.info("超过3小时taskId={},{}",taskId);
logger.info("超过3小时taskId={}",taskId);
it.remove();
RedisUtil.delLocalCache("department-list-cache-" + task.getWxEnterpriseId());
continue;
}
boolean flag = this.syncDepartmentStaffTask(taskId,type) ;
......
......@@ -111,13 +111,51 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
@Override
public ServiceResponse syncTagToQywx(String wxEnterpriseId, String enterpriseId, QywxTagInfoDTO infoDTO, List<QywxTagItemDTO> items) {
logger.info("保存标签同步");
logger.info("标签同步到企业微信,wxEnterpriseId={},memberTagId={}",wxEnterpriseId,infoDTO.getMemberTagId());
ServiceResponse ret = new ServiceResponse();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
// 如果
List<TabQywxTagRelation> list = this.qywxTagRelationMapper.listByMemberTagId(wxEnterpriseId,infoDTO.getMemberTagId()) ;
if(CollectionUtils.isNotEmpty(list) && list.size() >= items.size()) {
logger.info("标签已存在,直接处理会员");
// 判断更新
List<String> needDelList = new ArrayList<>() ;
List<QywxTagItemDTO> needAddList = new ArrayList<>() ;
List<String> memberTagItemIdList = items.stream().map(o->o.getMemberTagItemId()).collect(Collectors.toList()); ;
List<TabQywxTagRelation> relationList = this.qywxTagRelationMapper.listByMemberTagId(wxEnterpriseId,infoDTO.getMemberTagId()) ;
if(CollectionUtils.isNotEmpty(relationList)) {
String hbTagId = relationList.get(0).getQywxTagId() ;
TabQywxTag tag = this.qywxTagService.getQywxTagByQywxTagId(wxEnterpriseId,hbTagId) ;
String qwGroupKey = tag.getQywxGroupKey() ;
logger.info("已经存在企微标签,进行更新处理={}",qwGroupKey);
QywxGetCorpTagListDTO tagListDTO = this.qywxSuiteApiService.getCorpTagList(qwDTO.getThirdCorpid(),qwDTO.getSelf3thSecret(),Arrays.asList(qwGroupKey),0,qwDTO.isSelf(),qwDTO.getUrlHost()) ;
logger.info("企微侧标签={}",JSONObject.toJSONString(tagListDTO));
List<TabQywxTagItem> tagItemList = this.qywxTagService.listByQywxTagId(wxEnterpriseId,hbTagId) ;
Map<String,TabQywxTagItem> tagItemMap = tagItemList.stream().collect(Collectors.toMap(TabQywxTagItem::getQywxTagItemId,o->o,(k1,k2)->k1)) ;
// 更新赋值
infoDTO.setQywxGroupKey(qwGroupKey);
// 需要删除的标签值
for(TabQywxTagRelation relation : relationList) {
String memberTagId = relation.getTagItemId() ;
if(!memberTagItemIdList.contains(memberTagId)) {
this.qywxTagRelationMapper.deleteByPrimaryKey(relation.getQywxTagRelationId()) ;
String hbTagItemId = relation.getQywxTagItemId() ;
TabQywxTagItem tagItem = tagItemMap.get(hbTagItemId) ;
this.qywxTagService.delQywxTagItemById(wxEnterpriseId,hbTagItemId) ;
needDelList.add(tagItem.getQywxTagKey()) ;
}
}
if(CollectionUtils.isNotEmpty(needDelList)) {
this.qywxSuiteApiService.delCorpTag(qwDTO.getThirdCorpid(), qwDTO.getSelf3thSecret(), needDelList, 1, qwDTO.isSelf(),qwDTO.getUrlHost());
}
// 需要添加的标签值
List<String> existMemberTagIdList = relationList.stream().map(o->o.getTagItemId()).collect(Collectors.toList());
for(QywxTagItemDTO memberTag : items) {
if(!existMemberTagIdList.contains(memberTag.getMemberTagItemId())) {
needAddList.add(memberTag) ;
}
}
items = needAddList ;
logger.info("更新标签,删除={},新增={}",needDelList,needAddList);
}
if(CollectionUtils.isEmpty(items)) {
logger.info("没有需要处理的标签");
return ret ;
}
//调用企业微信接口保存
......@@ -140,7 +178,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
return ret;
}
//保存关联关系
saveRelation(wxEnterpriseId, enterpriseId, infoDTO, items, savePair);
this.saveRelation(wxEnterpriseId, enterpriseId, infoDTO, items, savePair);
return ret;
}
......@@ -183,7 +221,7 @@ public class QywxTagApiServiceImpl implements QywxTagApiService {
itemRelation.setMemberTagId(infoDTO.getMemberTagId());
itemRelation.setEnterpriseId(enterpriseId);
itemRelation.setQywxTagItemId(tab.getQywxTagItemId());
itemRelation.setTagItemId(orgItem.getQywxTagKey());
itemRelation.setTagItemId(orgItem.getMemberTagItemId());
return itemRelation;
}).collect(Collectors.toList());
saveRelationList.addAll(itemList);
......
......@@ -46,6 +46,7 @@ import com.gic.haoban.manage.service.service.*;
import com.gic.haoban.manage.service.service.chat.GroupChatService;
import com.gic.haoban.manage.service.service.fee.HaobanQywxFeeOrderAccountService;
import com.gic.haoban.manage.service.service.fee.HaobanQywxFeeOrderService;
import com.gic.haoban.manage.service.util.DingUtils;
import com.gic.haoban.manage.service.util.EmojiFilterUtil;
import com.gic.redis.data.util.RedisUtil;
import com.gic.thirdparty.cloudfile.CloudFileUtil;
......@@ -303,22 +304,7 @@ public class StaffApiServiceImpl implements StaffApiService {
TabHaobanStaff staff = new TabHaobanStaff();
List<StaffDTO> staffDTOList = staffService.listByUserIdsAndWxEnterpriseId(Lists.newArrayList(wxUserId,openUserid), wxEnterpriseId);
if (CollUtil.isNotEmpty(staffDTOList) && staffDTOList.size()>1) {
//只保留一个staff
for (int i =0;i<staffDTOList.size()-1;i++){
StaffDTO dto = staffDTOList.get(i);
String staffId = dto.getStaffId();
// 员工解绑
List<StaffClerkRelationDTO> staffClerkRelationDTOS = staffClerkRelationService
.listByStaffId(wxEnterpriseId, staffId);
if (CollectionUtils.isNotEmpty(staffClerkRelationDTOS)) {
for (StaffClerkRelationDTO staffClerkRelationDTO : staffClerkRelationDTOS) {
staffClerkRelationService.delBind(staffId, staffClerkRelationDTO.getClerkId(),
ChannelCodeEnum.ADMIN_UNBIND.getCode(),null, wxEnterpriseId);
}
}
this.staffService.delByStaffId(staffId);
staffDTOList.remove(i);
}
com.gic.haoban.common.utils.DingUtils.send("告警【多条重复staff】,企业ID"+wxEnterpriseId,true);
}
if (CollUtil.isNotEmpty(staffDTOList)){
staff = JSONObject.parseObject(JSONObject.toJSONString(staffDTOList.get(0)), TabHaobanStaff.class);
......@@ -352,8 +338,7 @@ public class StaffApiServiceImpl implements StaffApiService {
staff.setQrCode(qr_code);
}
//判断成员是否开启联系我
if (this.openConcatFlag(wxEnterpriseId,wxUserId,isSyncDepart)) {
logger.info("成员开启联系我");
if (this.openConcatFlag(wxEnterpriseId,wxUserId,isSyncDepart,qwDTO)) {
staff.setOpenConcatFlag(1);
}
//成员更改或更新
......@@ -373,7 +358,7 @@ public class StaffApiServiceImpl implements StaffApiService {
res.setResult(staff.getStaffName());
return res;
}
private Boolean openConcatFlag(String wxEnterpriseId,String userId , boolean isSyncDepart){
private Boolean openConcatFlag(String wxEnterpriseId,String userId , boolean isSyncDepart,WxEnterpriseQwDTO qwDTO){
List<String> wxUserIdsList = null ;
//企微已经开启联系我
Boolean flag = false;
......@@ -386,7 +371,6 @@ public class StaffApiServiceImpl implements StaffApiService {
}
}
if(null == wxUserIdsList) {
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if(qwDTO.isSelf()) {
wxUserIdsList = qywxUserApiService.listCorpExternalUserSelf(qwDTO.getDkCorpid(), qwDTO.getSelfSecret(),qwDTO.getUrlHost());
}else {
......
......@@ -27,10 +27,11 @@
<!-- from tab_haoban_qywx_tag_relation-->
<!-- where qywx_tag_relation_id = #{qywxTagRelationId,jdbcType=VARCHAR}-->
<!-- </select>-->
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from tab_haoban_qywx_tag_relation
<update id="deleteByPrimaryKey" parameterType="java.lang.String">
update tab_haoban_qywx_tag_relation set status_flag = 0 , update_time =now()
where qywx_tag_relation_id = #{qywxTagRelationId,jdbcType=VARCHAR}
</delete>
</update>
<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabQywxTagRelation">
insert into tab_haoban_qywx_tag_relation (qywx_tag_relation_id, wx_enterprise_id,
enterprise_id, member_tag_id, tag_item_id,
......
import com.alibaba.fastjson.JSON;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.manage.api.dto.QywxTagInfoDTO;
import com.gic.haoban.manage.api.dto.QywxTagItemDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.service.ExternalClerkRelatedApiService;
import com.gic.haoban.manage.api.service.QywxTagApiService;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.pojo.bo.hm.HmQrcodeBO;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.hm.HmClerkRelationService;
import com.gic.haoban.manage.service.service.hm.HmQrcodeService;
import com.gic.mq.sdk.GicMQClient;
import com.gic.redis.data.util.RedisUtil;
import com.gic.wechat.api.dto.qywx.welcome.QywxExternalcontactDTO;
import org.apache.commons.collections.CollectionUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class TagTest3 {
@Autowired
private QywxTagApiService qywxTagApiService ;
@Autowired
private HmQrcodeService hmQrcodeService ;
@Autowired
private WxEnterpriseService wxEnterpriseService ;
@Autowired
private Config config ;
@Autowired
private HmClerkRelationService hmClerkRelationService ;
@Autowired
private ExternalClerkRelatedApiService externalClerkRelatedApiService ;
@Test
public void tt() throws InterruptedException {
// String wxEnterpriseId, String enterpriseId, QywxTagInfoDTO infoDTO, List<QywxTagItemDTO> items
String wxEnterpriseId = "ca66a01b79474c40b3e7c7f93daf1a3b" ;
String enterpriseId = "ff8080815dacd3a2015dacd3ef5c0000" ;
QywxTagInfoDTO infoDTO = new QywxTagInfoDTO() ;
infoDTO.setWxEnterpriseId(wxEnterpriseId);
infoDTO.setMemberTagId("5b1db406e21748e88737a4cbe194d24f");
List<QywxTagItemDTO> items = new ArrayList<>() ;
QywxTagItemDTO mid = new QywxTagItemDTO();
mid.setMemberTagItemId("0f08ddb354654638bc8f71ce39fce688");
mid.setQywxTagName("企微1");
items.add(mid) ;
QywxTagItemDTO mid2 = new QywxTagItemDTO();
mid2.setMemberTagItemId("1e3f324af76842a0a3b7697f95419414");
mid2.setQywxTagName("企微2");
items.add(mid2) ;
QywxTagItemDTO mid3 = new QywxTagItemDTO();
mid3.setMemberTagItemId("qw5");
mid3.setQywxTagKey("qw5");
mid3.setQywxTagName("企微5");
items.add(mid3) ;
this.qywxTagApiService.syncTagToQywx(wxEnterpriseId,enterpriseId,infoDTO,items) ;
}
}
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