|
@@ -2,16 +2,15 @@ package com.tzld.piaoquan.growth.common.service.Impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
|
|
|
import com.tzld.piaoquan.growth.common.common.enums.PreSpecialStatusEnum;
|
|
|
import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
|
|
|
-import com.tzld.piaoquan.growth.common.dao.mapper.StaffMapper;
|
|
|
-import com.tzld.piaoquan.growth.common.dao.mapper.StaffWithUserMapper;
|
|
|
-import com.tzld.piaoquan.growth.common.dao.mapper.UserWithTagMapper;
|
|
|
-import com.tzld.piaoquan.growth.common.dao.mapper.WeComUserMapper;
|
|
|
+import com.tzld.piaoquan.growth.common.dao.mapper.*;
|
|
|
import com.tzld.piaoquan.growth.common.dao.mapper.ext.WeComUserMapperExt;
|
|
|
import com.tzld.piaoquan.growth.common.model.bo.GroupSendWeComUserParam;
|
|
|
import com.tzld.piaoquan.growth.common.model.bo.WeComUserBo;
|
|
|
import com.tzld.piaoquan.growth.common.model.po.*;
|
|
|
+import com.tzld.piaoquan.growth.common.model.vo.UserTagParam;
|
|
|
import com.tzld.piaoquan.growth.common.model.vo.WeComUserVo;
|
|
|
import com.tzld.piaoquan.growth.common.service.WeComAccessTokenService;
|
|
|
import com.tzld.piaoquan.growth.common.service.WeComUserService;
|
|
@@ -32,6 +31,7 @@ import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.tzld.piaoquan.growth.common.common.constant.WeComConstant.GET_WE_COM_EXTERNAL_CONTACT_GET;
|
|
|
+import static com.tzld.piaoquan.growth.common.common.constant.WeComConstant.POST_WE_COM_ADD_USER_TAG;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -57,6 +57,9 @@ public class WeComUserServiceImpl implements WeComUserService {
|
|
|
@Autowired
|
|
|
private UserWithTagMapper userWithTagMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TagMapper tagMapper;
|
|
|
+
|
|
|
@Value("${needFilterTagIdConfig:[]}")
|
|
|
private String needFilterTagIdConfig;
|
|
|
|
|
@@ -359,4 +362,89 @@ public class WeComUserServiceImpl implements WeComUserService {
|
|
|
}
|
|
|
return allStaffs;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResponse<Void> addUserTag(UserTagParam userTagParam) {
|
|
|
+ if (userTagParam == null
|
|
|
+ || StringUtils.isEmpty(userTagParam.getUnionId())
|
|
|
+ || StringUtils.isEmpty(userTagParam.getTagGroupName())
|
|
|
+ || StringUtils.isEmpty(userTagParam.getTagName())) {
|
|
|
+ return CommonResponse.create(500, "参数错误");
|
|
|
+ }
|
|
|
+ TagExample example = new TagExample();
|
|
|
+ example.createCriteria().andTagGroupNameEqualTo(userTagParam.getTagGroupName())
|
|
|
+ .andTagNameEqualTo(userTagParam.getTagName())
|
|
|
+ .andIsDeleteEqualTo(0);
|
|
|
+ List<Tag> tags = tagMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(tags)) {
|
|
|
+ return CommonResponse.create(500, "标签不存在");
|
|
|
+ }
|
|
|
+ Tag tag = tags.get(0);
|
|
|
+ WeComUserExample userExample = new WeComUserExample();
|
|
|
+ userExample.createCriteria().andUnionIdEqualTo(userTagParam.getUnionId());
|
|
|
+ List<WeComUser> weComUsers = weComUserMapper.selectByExample(userExample);
|
|
|
+ if (CollectionUtils.isEmpty(weComUsers)) {
|
|
|
+ return CommonResponse.create(500, "用户不存在");
|
|
|
+ }
|
|
|
+ WeComUser weComUser = weComUsers.get(0);
|
|
|
+ UserWithTag userWithTag = new UserWithTag();
|
|
|
+ userWithTag.setTagId(tag.getId());
|
|
|
+ userWithTag.setUserId(weComUser.getId());
|
|
|
+ boolean b = addUserWithTag(userWithTag);
|
|
|
+ if (b) {
|
|
|
+ boolean b1 = addWeComTag(tag, weComUser);
|
|
|
+ if (!b1) {
|
|
|
+ UserWithTag record = new UserWithTag();
|
|
|
+ record.setStatus(2);
|
|
|
+ UserWithTagExample userWithTagExample = new UserWithTagExample();
|
|
|
+ userWithTagExample.createCriteria().andUserIdEqualTo(userWithTag.getUserId()).andTagIdEqualTo(userWithTag.getTagId());
|
|
|
+ userWithTagMapper.updateByExampleSelective(record, userWithTagExample);
|
|
|
+ LarkRobotUtil.sendMessage("企微添加标签失败 tagId=" + tag.getId() + " userId=" + weComUser.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return CommonResponse.create(500, "添加失败");
|
|
|
+ }
|
|
|
+ return CommonResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean addWeComTag(Tag tag, WeComUser weComUser) {
|
|
|
+ try {
|
|
|
+ String accessToken = weComAccessTokenService.getWeComAccessToken(weComUser.getCorpId());
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ jsonArray.add(tag.getTagId());
|
|
|
+ StaffWithUserExample staffWithUserExample = new StaffWithUserExample();
|
|
|
+ staffWithUserExample.createCriteria().andUserIdEqualTo(weComUser.getId()).andIsDeleteEqualTo(0);
|
|
|
+ List<StaffWithUser> staffWithUsers = staffWithUserMapper.selectByExample(staffWithUserExample);
|
|
|
+ if (!CollectionUtils.isEmpty(staffWithUsers)) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("userid", "ShengHuoLeQu");
|
|
|
+ jsonObject.put("external_userid", weComUser.getExternalUserId());
|
|
|
+ jsonObject.put("add_tag", jsonArray);
|
|
|
+ String url = POST_WE_COM_ADD_USER_TAG + "?access_token=" + accessToken;
|
|
|
+ String post = httpPoolClient.post(url, jsonObject.toJSONString());
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(post);
|
|
|
+ if (jsonObject1.getInteger("errcode") == 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("addWeComTag error", e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean addUserWithTag(UserWithTag userWithTag) {
|
|
|
+ try {
|
|
|
+ UserWithTagExample userWithTagExample = new UserWithTagExample();
|
|
|
+ userWithTagExample.createCriteria().andUserIdEqualTo(userWithTag.getUserId()).andTagIdEqualTo(userWithTag.getTagId());
|
|
|
+ long l = userWithTagMapper.countByExample(userWithTagExample);
|
|
|
+ if (l == 0) {
|
|
|
+ userWithTagMapper.insertSelective(userWithTag);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("addUserWithTag error", e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|