فهرست منبع

用户打标功能

xueyiming 2 ماه پیش
والد
کامیت
2c88139eb6

+ 7 - 0
api-module/src/main/java/com/tzld/piaoquan/api/controller/WeComUserController.java

@@ -3,6 +3,7 @@ package com.tzld.piaoquan.api.controller;
 import com.tzld.piaoquan.api.model.vo.WeComUserNameAvatarParam;
 import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
 import com.tzld.piaoquan.growth.common.model.bo.GroupSendWeComUserParam;
+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.WeComUserService;
 import com.tzld.piaoquan.growth.common.utils.page.Page;
@@ -37,4 +38,10 @@ public class WeComUserController {
         log.info("param={}", param);
         return CommonResponse.success(service.getGroupSendWeComUser(param));
     }
+
+    @PostMapping("/add/tag")
+    public CommonResponse<Void> addUserTag(@RequestBody UserTagParam userTagParam) {
+        log.info("addUserTag param={}", userTagParam);
+        return service.addUserTag(userTagParam);
+    }
 }

+ 2 - 2
api-module/src/main/java/com/tzld/piaoquan/api/dao/generator/MybatisGeneratorMain.java

@@ -20,9 +20,9 @@ public class MybatisGeneratorMain {
             throws SQLException, IOException, InterruptedException, InvalidConfigurationException, XMLParserException {
         List<String> warnings = new ArrayList<>();
 
-//        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-generator-config.xml").getFile());
+        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-generator-config.xml").getFile());
 //        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-generator-config.xml").getFile());
-        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-contentPlatform-generator-config.xml").getFile());
+//        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-contentPlatform-generator-config.xml").getFile());
         ConfigurationParser cp = new ConfigurationParser(warnings);
         Configuration config = cp.parseConfiguration(configFile);
         DefaultShellCallback callback = new DefaultShellCallback(true);

+ 3 - 1
api-module/src/main/resources/mybatis-generator-config.xml

@@ -55,9 +55,11 @@
 <!--        <table tableName="we_com_guarantees_video" domainObjectName="GuaranteesVideo" alias=""/>-->
 <!--        <table tableName="we_com_staff" domainObjectName="Staff" alias=""/>-->
 <!--        <table tableName="we_com_message_attachment" domainObjectName="MessageAttachment" alias=""/>-->
-        <table tableName="we_com_special_pre_send_message" domainObjectName="PreSpecialSendMessage" alias=""/>
+<!--        <table tableName="we_com_special_pre_send_message" domainObjectName="PreSpecialSendMessage" alias=""/>-->
 <!--        <table tableName="we_com_send_msg_result" domainObjectName="SendMsgResult" alias=""/>-->
 <!--        <table tableName="we_com_corp" domainObjectName="Corp" alias=""/>-->
+        <table tableName="we_com_user_with_tag" domainObjectName="UserWithTag" alias=""/>
+
 
     </context>
 

+ 4 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/common/constant/WeComConstant.java

@@ -37,4 +37,8 @@ public interface WeComConstant {
 
     //发送新客户欢迎语
     String POST_WE_COM_SEND_WELCOME_MSG = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg";
+
+
+    //用户增加新标签
+    String POST_WE_COM_ADD_USER_TAG = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag";
 }

+ 11 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/po/UserWithTag.java

@@ -9,6 +9,8 @@ public class UserWithTag {
 
     private Long tagId;
 
+    private Integer status;
+
     private Integer isDelete;
 
     private Date createTime;
@@ -39,6 +41,14 @@ public class UserWithTag {
         this.tagId = tagId;
     }
 
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
     public Integer getIsDelete() {
         return isDelete;
     }
@@ -72,6 +82,7 @@ public class UserWithTag {
         sb.append(", id=").append(id);
         sb.append(", userId=").append(userId);
         sb.append(", tagId=").append(tagId);
+        sb.append(", status=").append(status);
         sb.append(", isDelete=").append(isDelete);
         sb.append(", createTime=").append(createTime);
         sb.append(", updateTime=").append(updateTime);

+ 60 - 1
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/po/UserWithTagExample.java

@@ -1,7 +1,6 @@
 package com.tzld.piaoquan.growth.common.model.po;
 
 import com.tzld.piaoquan.growth.common.utils.page.Page;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -297,6 +296,66 @@ public class UserWithTagExample {
             return (Criteria) this;
         }
 
+        public Criteria andStatusIsNull() {
+            addCriterion("`status` is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusIsNotNull() {
+            addCriterion("`status` is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusEqualTo(Integer value) {
+            addCriterion("`status` =", value, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusNotEqualTo(Integer value) {
+            addCriterion("`status` <>", value, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusGreaterThan(Integer value) {
+            addCriterion("`status` >", value, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusGreaterThanOrEqualTo(Integer value) {
+            addCriterion("`status` >=", value, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusLessThan(Integer value) {
+            addCriterion("`status` <", value, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusLessThanOrEqualTo(Integer value) {
+            addCriterion("`status` <=", value, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusIn(List<Integer> values) {
+            addCriterion("`status` in", values, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusNotIn(List<Integer> values) {
+            addCriterion("`status` not in", values, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusBetween(Integer value1, Integer value2) {
+            addCriterion("`status` between", value1, value2, "status");
+            return (Criteria) this;
+        }
+
+        public Criteria andStatusNotBetween(Integer value1, Integer value2) {
+            addCriterion("`status` not between", value1, value2, "status");
+            return (Criteria) this;
+        }
+
         public Criteria andIsDeleteIsNull() {
             addCriterion("is_delete is null");
             return (Criteria) this;

+ 16 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/vo/UserTagParam.java

@@ -0,0 +1,16 @@
+package com.tzld.piaoquan.growth.common.model.vo;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class UserTagParam {
+
+    private String tagGroupName;
+
+    private String tagName;
+
+    private String unionId;
+
+}

+ 92 - 4
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/Impl/WeComUserServiceImpl.java

@@ -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;
+    }
 }

+ 7 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/WeComUserService.java

@@ -1,9 +1,12 @@
 package com.tzld.piaoquan.growth.common.service;
 
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
 import com.tzld.piaoquan.growth.common.model.bo.GroupSendWeComUserParam;
 import com.tzld.piaoquan.growth.common.model.po.Staff;
+import com.tzld.piaoquan.growth.common.model.po.UserWithTag;
 import com.tzld.piaoquan.growth.common.model.po.WeComUser;
+import com.tzld.piaoquan.growth.common.model.vo.UserTagParam;
 import com.tzld.piaoquan.growth.common.model.vo.WeComUserVo;
 import com.tzld.piaoquan.growth.common.utils.page.Page;
 
@@ -32,4 +35,8 @@ public interface WeComUserService {
     List<Long> getFilterTagId();
 
     List<Staff> getStaffByUserId(Long userId);
+
+    CommonResponse<Void> addUserTag(UserTagParam userTagParam);
+
+    boolean addUserWithTag(UserWithTag userWithTag);
 }

+ 20 - 5
common-module/src/main/resources/mapper/UserWithTagMapper.xml

@@ -5,6 +5,7 @@
     <id column="id" jdbcType="BIGINT" property="id" />
     <result column="user_id" jdbcType="BIGINT" property="userId" />
     <result column="tag_id" jdbcType="BIGINT" property="tagId" />
+    <result column="status" jdbcType="INTEGER" property="status" />
     <result column="is_delete" jdbcType="INTEGER" property="isDelete" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@@ -68,7 +69,7 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, user_id, tag_id, is_delete, create_time, update_time
+    id, user_id, tag_id, `status`, is_delete, create_time, update_time
   </sql>
   <select id="selectByExample" parameterType="com.tzld.piaoquan.growth.common.model.po.UserWithTagExample" resultMap="BaseResultMap">
     select
@@ -105,11 +106,11 @@
   </delete>
   <insert id="insert" parameterType="com.tzld.piaoquan.growth.common.model.po.UserWithTag">
     insert into we_com_user_with_tag (id, user_id, tag_id, 
-      is_delete, create_time, update_time
-      )
+      `status`, is_delete, create_time, 
+      update_time)
     values (#{id,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT}, #{tagId,jdbcType=BIGINT}, 
-      #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
-      )
+      #{status,jdbcType=INTEGER}, #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
+      #{updateTime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.tzld.piaoquan.growth.common.model.po.UserWithTag">
     insert into we_com_user_with_tag
@@ -123,6 +124,9 @@
       <if test="tagId != null">
         tag_id,
       </if>
+      <if test="status != null">
+        `status`,
+      </if>
       <if test="isDelete != null">
         is_delete,
       </if>
@@ -143,6 +147,9 @@
       <if test="tagId != null">
         #{tagId,jdbcType=BIGINT},
       </if>
+      <if test="status != null">
+        #{status,jdbcType=INTEGER},
+      </if>
       <if test="isDelete != null">
         #{isDelete,jdbcType=INTEGER},
       </if>
@@ -172,6 +179,9 @@
       <if test="record.tagId != null">
         tag_id = #{record.tagId,jdbcType=BIGINT},
       </if>
+      <if test="record.status != null">
+        `status` = #{record.status,jdbcType=INTEGER},
+      </if>
       <if test="record.isDelete != null">
         is_delete = #{record.isDelete,jdbcType=INTEGER},
       </if>
@@ -191,6 +201,7 @@
     set id = #{record.id,jdbcType=BIGINT},
       user_id = #{record.userId,jdbcType=BIGINT},
       tag_id = #{record.tagId,jdbcType=BIGINT},
+      `status` = #{record.status,jdbcType=INTEGER},
       is_delete = #{record.isDelete,jdbcType=INTEGER},
       create_time = #{record.createTime,jdbcType=TIMESTAMP},
       update_time = #{record.updateTime,jdbcType=TIMESTAMP}
@@ -207,6 +218,9 @@
       <if test="tagId != null">
         tag_id = #{tagId,jdbcType=BIGINT},
       </if>
+      <if test="status != null">
+        `status` = #{status,jdbcType=INTEGER},
+      </if>
       <if test="isDelete != null">
         is_delete = #{isDelete,jdbcType=INTEGER},
       </if>
@@ -223,6 +237,7 @@
     update we_com_user_with_tag
     set user_id = #{userId,jdbcType=BIGINT},
       tag_id = #{tagId,jdbcType=BIGINT},
+      `status` = #{status,jdbcType=INTEGER},
       is_delete = #{isDelete,jdbcType=INTEGER},
       create_time = #{createTime,jdbcType=TIMESTAMP},
       update_time = #{updateTime,jdbcType=TIMESTAMP}

+ 3 - 11
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComUserDataJob.java

@@ -65,6 +65,7 @@ public class WeComUserDataJob {
     @Autowired
     private WeComStaffService weComStaffService;
 
+
     @XxlJob("updateStaffWithUserJob")
     public ReturnT<String> updateStaffWithUser(String param) {
         XxlJobParam xxlJobParam = new XxlJobParam();
@@ -322,7 +323,7 @@ public class WeComUserDataJob {
                                 UserWithTag userWithTag = new UserWithTag();
                                 userWithTag.setUserId(userId);
                                 userWithTag.setTagId(tag.getId());
-                                addUserWithTag(userWithTag);
+                                weComUserService.addUserWithTag(userWithTag);
                             }
                         }
                     }
@@ -403,7 +404,7 @@ public class WeComUserDataJob {
                                         UserWithTag userWithTag = new UserWithTag();
                                         userWithTag.setUserId(userId);
                                         userWithTag.setTagId(tag.getId());
-                                        addUserWithTag(userWithTag);
+                                        weComUserService.addUserWithTag(userWithTag);
                                     }
                                 }
                             }
@@ -465,15 +466,6 @@ public class WeComUserDataJob {
         }
     }
 
-    private void addUserWithTag(UserWithTag userWithTag) {
-        UserWithTagExample userWithTagExample = new UserWithTagExample();
-        userWithTagExample.createCriteria().andUserIdEqualTo(userWithTag.getUserId()).andTagIdEqualTo(userWithTag.getTagId());
-        long l = userWithTagMapper.countByExample(userWithTagExample);
-        if (l == 0) {
-            userWithTagMapper.insertSelective(userWithTag);
-        }
-    }
-
     private Long addAndUpdateUser(JSONObject externalContact, Long corpId, String externalUserId, Long createAt, Long staffId, Long userId) {
         String name = externalContact.getString("name");
         String unionId = externalContact.getString("unionid");