Procházet zdrojové kódy

用户设备意向标签标记

zoujiajian před 2 roky
rodič
revize
70a966f671

+ 5 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -306,4 +306,9 @@ public interface Constant {
 	 * 有效获客
 	 */
 	String CUSTOMER_EFFECTIVE = "customer_effective";
+
+	/**
+	 * 设备意向标签组
+	 */
+	String EP_INTENTION_GROUP_NAME= "设备群发标签";
 }

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpUserFollowRelationMapper.java

@@ -21,4 +21,6 @@ public interface CorpUserFollowRelationMapper extends BaseMapper<CorpUserFollowR
 	List<CorpUserFollowRelationDto> selectCorpUserFollowRelation(@Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> service_follow_ids);
 
 	List<CorpUserFollowRelationDto> selectCorpUserNotUnderTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds, @Param("userScope") Integer userScope, @Param("consumerScope") Integer consumerScope, @Param("joinStartTime") Date joinStartTime, @Param("joinEndTime") Date joinEndTime);
+
+	CorpUserFollowRelation getCorpUserFollowRelation(@Param("unionId") String unionId, @Param("followId") String followId);
 }

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpUserTagMapper.java

@@ -28,4 +28,6 @@ public interface CorpUserTagMapper extends BaseMapper<CorpUserTag> {
 	List<UserIntentionPieView> getUserIntentionPie(@Param("tagIdStr") String tagId, @Param("thisDate") String date);
 
 	Page<CorpUserIntentionView> getCorpUserIntentionView(@Param("page") Page<CorpUserIntentionView> page, @Param("userId") Long userId, @Param("nickname") String nickname, @Param("tagIdStr") String tagId, @Param("thisDate") String date, @Param("intention") Integer intention);
+
+	List<CorpUserTag> selectIntentionUserTag(String groupName);
 }

+ 24 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpUserPayIntention.java

@@ -1,5 +1,7 @@
 package com.cyksj.model.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.ejlchina.searcher.bean.DbIgnore;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -18,4 +20,26 @@ public class CorpUserPayIntention extends BaseEntity {
 	 * 意向 0无回复 1无意向 2.问相关问题 3有意向 4很有意向
 	 */
 	private Integer intention;
+
+	@DbIgnore
+	@TableField(exist = false)
+	private String followId;
+
+
+	@Getter
+	public enum Intention {
+		whf("无回复", "etvj2DPQAA13a2LWPMwCikcmnp6T40FA"),
+		wyx("无意向", "etvj2DPQAASnQouiyPZD9el0QLLSNs8Q"),
+		wxgwt("问相关问题", "etvj2DPQAAUOcl8WGtkF27Ul_V7ixF4A"),
+		yyx("有意向", "etvj2DPQAA41WEz2wXpuLlf1XzKTnK9g"),
+		hyyx("很有意向", "etvj2DPQAAPQOeqPoY-ByfdmCrC3PDkw");
+		String tagName;
+
+		String tagId;
+
+		Intention(String tagName, String tagId) {
+			this.tagName = tagName;
+			this.tagId = tagId;
+		}
+	}
 }

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpUserTag.java

@@ -1,5 +1,7 @@
 package com.cyksj.model.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.ejlchina.searcher.bean.DbIgnore;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -37,6 +39,14 @@ public class CorpUserTag extends BaseEntity implements Serializable {
 	 */
 	private int type;
 
+	@DbIgnore
+	@TableField(exist = false)
+	private String followId;
+
+	@DbIgnore
+	@TableField(exist = false)
+	private String externalUserId;
+
 	@Override
 	public boolean equals(Object o) {
 		if (this == o) return true;

+ 10 - 0
netflix-dao/src/main/resources/mapper/CorpUserFollowRelationMapper.xml

@@ -127,4 +127,14 @@
         </if>
         group by cufr.corp_user_id
     </select>
+
+    <select id="getCorpUserFollowRelation" resultType="com.cyksj.model.entity.CorpUserFollowRelation">
+        select cufr.id
+        from (select id
+              from corp_user
+              where unionid = #{unionId} limit 1) cu
+                 inner join corp_user_auth ca on ca.corp_user_id = cu.id
+                 inner join corp_user_follow_relation cufr on cufr.corp_user_id = ca.external_userid
+        where cufr.follow_id = #{followId}
+    </select>
 </mapper>

+ 7 - 0
netflix-dao/src/main/resources/mapper/CorpUserTagMapper.xml

@@ -125,4 +125,11 @@
             </if>
         </where>
     </select>
+
+    <select id="selectIntentionUserTag" resultType="com.cyksj.model.entity.CorpUserTag">
+        select ct.*, cufr.follow_id, cufr.corp_user_id as externalUserId
+        from corp_user_tag ct
+                 inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+        where ct.group_name = #{groupName}
+    </select>
 </mapper>

+ 65 - 4
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -1,10 +1,13 @@
 package com.cyksj.service.corp.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.StringUtil;
@@ -13,9 +16,7 @@ import com.cyksj.common.util.corp.WxCryptUtil;
 import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.dto.CorpOauth2UserInfo;
-import com.cyksj.mapper.corp.CorpCustomerAcquistionCallbackMapper;
-import com.cyksj.mapper.corp.CorpFollowMapper;
-import com.cyksj.mapper.corp.CorpUserPayIntentionMapper;
+import com.cyksj.mapper.corp.*;
 import com.cyksj.model.dto.WxCorpEncryptDto;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.corp.Attachments;
@@ -43,6 +44,7 @@ import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /*
  *项目名: netflix
@@ -82,6 +84,15 @@ public class CorpServiceImpl implements CorpService {
 	@Autowired
 	private CorpUserPayIntentionMapper corpUserPayIntentionMapper;
 
+	@Autowired
+	private CorpUserMapper corpUserMapper;
+
+	@Autowired
+	private CorpUserTagMapper corpUserTagMapper;
+
+	@Autowired
+	private CorpUserFollowRelationMapper corpUserFollowRelationMapper;
+
 	@PostConstruct
 	private void init() {
 		corpMessageRouter = new CorpMessageRouter(this)
@@ -382,8 +393,58 @@ public class CorpServiceImpl implements CorpService {
 				corpUserPayIntentionMapper.insert(corpUserPayIntention);
 			} catch (DuplicateKeyException e) {
 			}
+		} else {
+			corpUserPayIntentionMapper.updateById(corpUserPayIntention);
+		}
+		//将所属意向标签组不属于该标签的全删除
+		//并打上对应标签
+		CorpUserPayIntention.Intention intention = CorpUserPayIntention.Intention.values()[corpUserPayIntention.getIntention()];
+		String tagName = intention.getTagName();
+		String tagId = intention.getTagId();
+
+		List<CorpUserTag> corpUserTags = corpUserTagMapper.selectIntentionUserTag(Constant.EP_INTENTION_GROUP_NAME);
+		//是否存在对应标签
+		AtomicBoolean isExistIntentionTag = new AtomicBoolean(false);
+		if (CollUtil.isNotEmpty(corpUserTags)) {
+			//删除之前的意向标签
+			corpUserTags.forEach(userTag -> {
+				if (!StrUtil.equals(userTag.getTagId(), tagId)) {
+					try {
+						wxCorpOps.markTag(userTag.getExternalUserId(), userTag.getFollowId(), null, new String[]{userTag.getTagId()});
+						corpUserTagMapper.deleteById(userTag.getId());
+					} catch (Exception e) {
+					}
+				} else {
+					if (!isExistIntentionTag.get()) {
+						isExistIntentionTag.set(true);
+					}
+				}
+			});
+		}
+		if (!isExistIntentionTag.get()) {
+			insertUserIntentionTag(corpUserPayIntention, tagId, tagName);
+		}
+	}
+
+	public void insertUserIntentionTag(CorpUserPayIntention corpUserPayIntention, String tagId, String tagName) {
+		CorpUserFollowRelation corpUserFollowRelation = corpUserFollowRelationMapper.getCorpUserFollowRelation(corpUserPayIntention.getUnionId(), corpUserPayIntention.getFollowId());
+		if (corpUserFollowRelation == null) {
 			return;
 		}
-		corpUserPayIntentionMapper.updateById(corpUserPayIntention);
+		String externalUserId = corpUserFollowRelation.getCorpUserId();
+		String followId = corpUserFollowRelation.getFollowId();
+		try {
+			wxCorpOps.markTag(externalUserId, followId, new String[]{tagId}, null);
+			//新增用户标签
+			CorpUserTag corpUserTag = new CorpUserTag();
+			corpUserTag.setRelationId(corpUserFollowRelation.getId());
+			corpUserTag.setGroupName(Constant.EP_INTENTION_GROUP_NAME);
+			corpUserTag.setTagId(tagId);
+			corpUserTag.setTagName(tagName);
+			corpUserTagMapper.insert(corpUserTag);
+		} catch (Exception e) {
+			log.error("新增用户意向标签错误:{}", StringUtil.getErrorText(e));
+		}
+
 	}
 }

+ 31 - 0
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -43,6 +43,7 @@ import com.cyksj.mapper.*;
 import com.cyksj.mapper.channel.ChannelPopularizeMapper;
 import com.cyksj.mapper.channel.ShopConfigMapper;
 import com.cyksj.mapper.corp.CorpInteractiveUserOrderRelationMapper;
+import com.cyksj.mapper.corp.CorpUserTagMapper;
 import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
 import com.cyksj.mapper.manage.coupon.CouponMapper;
 import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
@@ -65,6 +66,7 @@ import com.cyksj.model.manage.views.OrderDonView;
 import com.cyksj.model.request.*;
 import com.cyksj.model.views.*;
 import com.cyksj.redis.RedisService;
+import com.cyksj.service.corp.WxCorpOps;
 import com.cyksj.service.coupon.CouponFontService;
 import com.cyksj.service.distribute.UserBusinessFrontService;
 import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
@@ -286,6 +288,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	private final OrderDonSubsidyRelateMapper orderDonSubsidyRelateMapper;
 
+	private final CorpUserTagMapper corpUserTagMapper;
+
+	private final WxCorpOps wxCorpOps;
+
 	private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
 
 	@Transactional(rollbackFor = Throwable.class)
@@ -2359,6 +2365,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				}
 				//下级渠道目标额达标 提成金额发放
 				sendSubDistributeRewards(orderDon);
+				//删除用户意向标签
+				clearEpIntentionTag(goodsDon, orderDon.getUserId());
 			} catch (Exception e) {
 				log.error("回调修改订单信息错误,orderId:{},error:{}", orderDon.getId(), StringUtil.getErrorText(e));
 			}
@@ -3085,4 +3093,27 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 		orderDon.setMoney(price);
 	}
+
+	/**
+	 * 清除用户设备意向标签
+	 */
+	public void clearEpIntentionTag(GoodsDon goodsDon, Long userId) {
+		//实物订单,用户有设备意向,删除对应标签
+		if (goodsDon != null && goodsDon.getId() == 15) {
+			User user = userMapper.selectById(userId);
+			if (user != null && StrUtil.isNotBlank(user.getUnionid())) {
+				List<CorpUserTag> corpUserTags = corpUserTagMapper.selectIntentionUserTag(Constant.EP_INTENTION_GROUP_NAME);
+				if (CollUtil.isNotEmpty(corpUserTags)) {
+					//删除之前的意向标签
+					corpUserTags.forEach(userTag -> {
+						try {
+							wxCorpOps.markTag(userTag.getExternalUserId(), userTag.getFollowId(), null, new String[]{userTag.getTagId()});
+							corpUserTagMapper.deleteById(userTag.getId());
+						} catch (Exception e) {
+						}
+					});
+				}
+			}
+		}
+	}
 }

+ 6 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/WxCorpController.java

@@ -359,11 +359,16 @@ public class WxCorpController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult(corpUserPayIntention);
 	}
 
+	/**
+	 * 修改意向
+	 */
 	@PutMapping("/update/user/intention")
 	public Result<CorpUserPayIntention> updateUserIntention(@RequestBody CorpUserPayIntention corpUserPayIntention) {
 		if (corpUserPayIntention.getUnionId() == null || corpUserPayIntention.getIntention() == null) {
 			throw BusinessRuntimeException.getInstance("缺少必填参数.");
 		}
+		String followId = getCorpUuid();
+		corpUserPayIntention.setFollowId(followId);
 		corpService.updateUserIntention(corpUserPayIntention);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(corpUserPayIntention);
 	}
@@ -383,6 +388,7 @@ public class WxCorpController {
 	 * 修改 意向
 	 */
 	@PutMapping("/upCallbackIntention")
+	@Deprecated
 	public Result<String> upCallbackIntention(@RequestBody CorpCustomerAcquistionCallback corpCustomerAcquistionCallback) {
 		log.info("修改意向:{}", corpCustomerAcquistionCallback);
 		if (corpCustomerAcquistionCallback.getId() == null || corpCustomerAcquistionCallback.getId() == 0 || corpCustomerAcquistionCallback.getIntention() == null) {