提交 9cfb24a9 作者: 沈振路

保存人群包时过滤用户的操作转移

上级 b7825d76
......@@ -80,31 +80,13 @@ public class CustomerServiceCommonAsyncComponent {
private RabbitTemplate rabbitTemplate;
@Resource
private CompanyAcquisitionLinkService companyAcquisitionLinkService;
@Lazy
@Autowired
private CrowdPackageService crowdPackageService;
@Async("myExecutor")
public void addMatchUserIntoPackage(Long packageId, Boolean needRemove) {
// 获取人群包信息
CrowdPackage crowdPackage = crowdPackageService.getById(packageId);
if (crowdPackage == null) {
LOCAL_LOG.warn("人群包ID {} 不存在", packageId);
return;
}
// 获取符合人群包条件的用户列表
List<CrowdPackageUserVO> userList = matchService.getUserListFromPackage(packageId, null);
// 根据关注时间范围过滤用户
if (crowdPackage.getFollowDateStart() != null || crowdPackage.getFollowDateEnd() != null) {
userList = userList.stream()
.filter(item -> isUserInFollowDateRange(item, crowdPackage.getFollowDateStart(), crowdPackage.getFollowDateEnd()))
.collect(Collectors.toList());
LOCAL_LOG.info("人群包ID: {} 根据关注时间范围过滤后用户数量: {}", packageId, userList.size());
}
redisTemplate.opsForHash().put(CustomerCommonConstant.CROWD_HUMAN_NUN_REDIS_KEY, packageId.toString(), userList.size());
long startTime = System.currentTimeMillis();
String packIdStr = packageId.toString();
......@@ -706,38 +688,5 @@ public class CustomerServiceCommonAsyncComponent {
/**
* 判断用户是否在关注时间范围内
* @param user 用户信息
* @param followDateStart 关注开始日期
* @param followDateEnd 关注结束日期
* @return 是否在范围内
*/
private boolean isUserInFollowDateRange(CrowdPackageUserVO user, Date followDateStart, Date followDateEnd) {
Date userGmtCreate = user.getGmtCreate();
if (userGmtCreate == null) {
// 用户创建时间为空,不符合条件
return false;
}
// 检查是否在开始日期之后(包含)
if (followDateStart != null) {
Date startDate = DateUtil.beginOfDay(followDateStart);
if (userGmtCreate.before(startDate)) {
return false;
}
}
// 检查是否在结束日期之前(包含)
if (followDateEnd != null) {
Date endDate = DateUtil.endOfDay(followDateEnd);
if (userGmtCreate.after(endDate)) {
return false;
}
}
return true;
}
}
package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.entity.CrowdPackage;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCrowdConditionMatchMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CrowdPackageService;
import com.yaoyaozw.customer.service.CustomerServiceCommonService;
import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -36,6 +37,9 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC
private CustomerServiceCommonService commonService;
@Autowired
private RegisterUserEntityService userEntityService;
@Lazy
@Autowired
private CrowdPackageService crowdPackageService;
@Override
public List<CrowdPackageUserVO> getUserListFromPackage(Long packageId, String openId) {
......@@ -71,6 +75,19 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC
if (CollectionUtil.isEmpty(userList)) {
LOCAL_LOG.info("人群包ID {}, 没有符合条件的用户", packageId);
}
// 获取人群包信息
CrowdPackage crowdPackage = crowdPackageService.getById(packageId);
if (crowdPackage == null) {
LOCAL_LOG.warn("人群包ID {} 不存在", packageId);
return new ArrayList<>();
}
// 根据关注时间范围过滤用户
if (crowdPackage.getFollowDateStart() != null || crowdPackage.getFollowDateEnd() != null) {
userList = userList.stream()
.filter(item -> isUserInFollowDateRange(item, crowdPackage.getFollowDateStart(), crowdPackage.getFollowDateEnd()))
.collect(Collectors.toList());
LOCAL_LOG.info("人群包ID: {} 根据关注时间范围过滤后用户数量: {}", packageId, userList.size());
}
return userList;
}
......@@ -80,4 +97,37 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC
List<CrowdPackageUserVO> userList = this.getUserListFromPackage(packageId, openId);
return CollectionUtil.isNotEmpty(userList);
}
/**
* 判断用户是否在关注时间范围内
* @param user 用户信息
* @param followDateStart 关注开始日期
* @param followDateEnd 关注结束日期
* @return 是否在范围内
*/
private boolean isUserInFollowDateRange(CrowdPackageUserVO user, Date followDateStart, Date followDateEnd) {
Date userGmtCreate = user.getGmtCreate();
if (userGmtCreate == null) {
// 用户创建时间为空,不符合条件
return false;
}
// 检查是否在开始日期之后(包含)
if (followDateStart != null) {
Date startDate = DateUtil.beginOfDay(followDateStart);
if (userGmtCreate.before(startDate)) {
return false;
}
}
// 检查是否在结束日期之前(包含)
if (followDateEnd != null) {
Date endDate = DateUtil.endOfDay(followDateEnd);
return !userGmtCreate.after(endDate);
}
return true;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论