提交 b09dde25 作者: gh

Merge remote-tracking branch 'origin/master'

<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="80" name="Java" />
</Languages>
</inspection_tool>
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="date" />
</inspection_tool>
<inspection_tool class="SerializableHasSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreAnonymousInnerClasses" value="false" />
<option name="superClassString" value="java.awt.Component" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
...@@ -196,6 +196,12 @@ ...@@ -196,6 +196,12 @@
<groupId>redis.clients</groupId> <groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.12.0</version>
</dependency>
<!-- JWT --> <!-- JWT -->
<dependency> <dependency>
<groupId>io.jsonwebtoken</groupId> <groupId>io.jsonwebtoken</groupId>
......
package com.yaoyaozw.customer.components; package com.yaoyaozw.customer.components;
import cn.hutool.core.util.ObjectUtil;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author darker * @author darker
* @date 2022/9/28 15:16 * @date 2022/9/28 15:16
...@@ -10,9 +17,53 @@ import org.springframework.stereotype.Component; ...@@ -10,9 +17,53 @@ import org.springframework.stereotype.Component;
@Component @Component
public class CustomerServiceCommonAsyncComponent { public class CustomerServiceCommonAsyncComponent {
private final static Logger LOCAL_LOG = LoggerFactory.getLogger(CustomerServiceCommonAsyncComponent.class);
@Async("myExecutor")
public void addMatchUserIntoPackage(Long packageId, List<CrowdPackageUserVO> userList) {
long startTime = System.currentTimeMillis();
String packIdStr = packageId.toString();
// 筛选当前不在这个人群包的用户
List<CrowdPackageUserVO> userNotInPackageList = userList.stream()
// 保留现在不在该人群包的用户
.filter(item -> ObjectUtil.isNull(item.getInPackage()) || !item.getInPackage().contains(packIdStr))
.peek(item -> {
if (ObjectUtil.isNull(item.getInPackage())) {
item.setInPackage(packIdStr);
} else {
// 将当前人群包拼在后面
item.setInPackage(item.getInPackage() + "," + packIdStr);
}
}).collect(Collectors.toList());
LOCAL_LOG.info("人群包ID: {} 新增用户 {}个", packIdStr, userNotInPackageList.size());
long endTime = System.currentTimeMillis();
LOCAL_LOG.info("异步添加符合条件用户人群包完成, 耗时: {}ms", endTime - startTime);
}
@Async("myExecutor") @Async("myExecutor")
public void updateUserPackage() { public void removeUnMatchUserFromPackage(Long packageId, List<CrowdPackageUserVO> userList) {
long startTime = System.currentTimeMillis();
String packIdStr = packageId.toString();
// 筛选当前不在这个人群包的用户
List<CrowdPackageUserVO> userRemoveFromPackList = userList.stream()
// 移除现在在该人群包但不符合当前条件的用户
.filter(item -> ObjectUtil.isNotNull(item.getInPackage()) && item.getInPackage().contains(packIdStr))
.peek(item -> {
String removePackageStr = item.getInPackage().replace("," + packIdStr, "")
.replace(packIdStr + ",", "")
.replace(packIdStr, "");
item.setInPackage(removePackageStr);
}).collect(Collectors.toList());
LOCAL_LOG.info("人群包ID: {} 移除用户 {}个", packIdStr, userRemoveFromPackList.size());
long endTime = System.currentTimeMillis();
LOCAL_LOG.info("异步删除不符合条件用户所属人群包完成, 耗时: {}ms", endTime - startTime);
} }
......
package com.yaoyaozw.customer.configs;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.CachingConfigurationSelector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @author 10626
*/
@Configuration
@ConditionalOnClass(CachingConfigurationSelector.class)
@EnableConfigurationProperties(CacheProperties.class)
@ConditionalOnProperty(prefix = "spring.cache",name = "type",havingValue = "redis")
public class MyCatchConfig {
@Bean
public RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties) {
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
config = config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()));
config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
CacheProperties.Redis redis = cacheProperties.getRedis();
if (redis.getTimeToLive() != null) {
config = config.entryTtl(redis.getTimeToLive());
}
if (StringUtils.isNotEmpty(redis.getKeyPrefix())) {
config = config.prefixKeysWith(redis.getKeyPrefix());
}
if (!redis.isCacheNullValues()) {
config = config.disableCachingNullValues();
}
if (!redis.isUseKeyPrefix()) {
config = config.disableKeyPrefix();
}
return config;
}
}
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/
package com.yaoyaozw.customer.configs;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis配置
*
* @author Mark sunlightcs@gmail.com
*/
@Configuration
public class RedisConfig {
@Autowired
private RedisConnectionFactory factory;
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
redisTemplate.setConnectionFactory(factory);
// key的序列化类型
redisTemplate.setKeySerializer(new StringRedisSerializer());
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
// value的序列化类型
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
package com.yaoyaozw.customer.configs;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
/**
* @author 10626
*/
@Configuration
@EnableConfigurationProperties({RedisProperties.class,RedissonConfigProperties.class})
@ConditionalOnClass(RedissonClient.class)
public class RedissonConfig {
/**
* 所有对Redisson的使用都是通过RedissonClient对象
*/
@Bean(destroyMethod="shutdown")
public RedissonClient redissonClient(RedisProperties redisProperties,RedissonConfigProperties redissonConfigProperties) throws IOException {
//1、创建配置
Config config = new Config();
config.useSingleServer().setAddress("redis://"+redisProperties.getHost()+":"+redisProperties.getPort())
.setPassword(redisProperties.getPassword())
.setTimeout(redissonConfigProperties.getTimeout())
.setRetryAttempts(redissonConfigProperties.getRetryAttempts())
.setRetryInterval(redissonConfigProperties.getRetryInterval())
.setConnectionPoolSize(redissonConfigProperties.getConnectionPoolSize())
.setConnectionMinimumIdleSize(redissonConfigProperties.getConnectionMinimumIdleSize())
.setPingConnectionInterval(redissonConfigProperties.getPingConnectionInterval());
//**此项务必设置为redisson解决之前bug的timeout问题关键***** setPingConnectionInterval
//2、根据Config创建出RedissonClient示例
return Redisson.create(config);
}
}
package com.yaoyaozw.customer.configs;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author 10626
*/
@ConfigurationProperties(prefix = "spring.redisson")
@Component
@Data
public class RedissonConfigProperties {
private Integer timeout;
private Integer retryAttempts;
private Integer retryInterval;
private Integer pingConnectionInterval;
private Integer connectionPoolSize;
private Integer connectionMinimumIdleSize;
}
package com.yaoyaozw.customer.constants;
/**
* @author darker
* @date 2022/9/28 20:09
*/
public class CustomerCommonConstant {
public final static String CROWD_HUMAN_NUN_REDIS_KEY = "crowdHumanNum";
}
...@@ -75,6 +75,12 @@ public class CrowdPackageController { ...@@ -75,6 +75,12 @@ public class CrowdPackageController {
return crowdPackageService.getOptions(conditionId); return crowdPackageService.getOptions(conditionId);
} }
@ApiOperation("更新用户列表所属的人群包")
@GetMapping("/updateUserPackageBatch")
public BaseResult updateUserPackageBatch(@RequestBody List<String> openIdList) {
return crowdPackageService.updateUserPackageBatch(openIdList);
}
} }
...@@ -2,8 +2,30 @@ package com.yaoyaozw.customer.mapper; ...@@ -2,8 +2,30 @@ package com.yaoyaozw.customer.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yaoyaozw.customer.entity.RegisterUserEntity; import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper @Mapper
public interface RegisterUserEntityMapper extends BaseMapper<RegisterUserEntity> { public interface RegisterUserEntityMapper extends BaseMapper<RegisterUserEntity> {
/**
* 获取符合动态条件的用户
*
* @param dynamicExpressList 动态表达列表
* @param openId 指定openId
* @return {@link List}<{@link RegisterUserEntity}>
*/
List<CrowdPackageUserVO> getUserMatchDynamicExpress(@Param("dynamicExpressList") List<String> dynamicExpressList, @Param("openId") String openId);
/**
* 更新用户所属人群包
*
* @param openId 用户 openId
* @param packageBelong 所属人群包
*/
void updateUserPackageBelong(@Param("openId") String openId, @Param("packageBelong") String packageBelong);
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.service; ...@@ -3,6 +3,7 @@ package com.yaoyaozw.customer.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch; import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.entity.RegisterUserEntity; import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import java.util.List; import java.util.List;
...@@ -16,8 +17,17 @@ public interface CrowdPackageConditionMatchService extends IService<CrowdPackage ...@@ -16,8 +17,17 @@ public interface CrowdPackageConditionMatchService extends IService<CrowdPackage
* 从包中获取用户列表 * 从包中获取用户列表
* *
* @param packageId 包id * @param packageId 包id
* @param openId 用户openId
* @return {@link List}<{@link RegisterUserEntity}> * @return {@link List}<{@link RegisterUserEntity}>
*/ */
List<RegisterUserEntity> getUserListFromPackage(Long packageId); List<CrowdPackageUserVO> getUserListFromPackage(Long packageId, String openId);
/**
* 获取用户是否符合人群包条件
* @param packageId 人群包id
* @param openId 用户openId
* @return 结果
*/
Boolean getUserPackageBelong(Long packageId, String openId);
} }
...@@ -84,4 +84,20 @@ public interface CrowdPackageService extends IService<CrowdPackage> { ...@@ -84,4 +84,20 @@ public interface CrowdPackageService extends IService<CrowdPackage> {
* @return {@link GenericsResult}<{@link ConditionOptionResponseVO} * @return {@link GenericsResult}<{@link ConditionOptionResponseVO}
*/ */
GenericsResult<ConditionOptionResponseVO> getOptions(Long conditionId); GenericsResult<ConditionOptionResponseVO> getOptions(Long conditionId);
/**
* 更新用户所属人群包
* @param openId 用户标识
* @return 人群包id拼接
*/
BaseResult updateUserPackageBelong(String openId);
/**
* 批处理更新用户包
*
* @param openIdList 开放id列表
* @return {@link BaseResult}
*/
BaseResult updateUserPackageBatch(List<String> openIdList);
} }
...@@ -3,6 +3,10 @@ package com.yaoyaozw.customer.service; ...@@ -3,6 +3,10 @@ package com.yaoyaozw.customer.service;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO; import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.entity.RegisterUserEntity; import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import java.util.List;
public interface RegisterUserEntityService extends IService<RegisterUserEntity>{ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{
...@@ -10,5 +14,14 @@ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{ ...@@ -10,5 +14,14 @@ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{
void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO); void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO);
/**
* 获取符合动态条件的用户
*
* @param dynamicExpressList 动态表达列表
* @param openId 指定用户openId
* @return {@link List}<{@link RegisterUserEntity}>
*/
List<CrowdPackageUserVO> getUserMatchDynamicExpress(List<String> dynamicExpressList, String openId);
} }
...@@ -10,6 +10,8 @@ import com.yaoyaozw.customer.mapper.KanbanCommonMapper; ...@@ -10,6 +10,8 @@ import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCrowdConditionMatchMapper; import com.yaoyaozw.customer.mapper.MaterialCrowdConditionMatchMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService; import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CustomerServiceCommonService; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -32,9 +34,11 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC ...@@ -32,9 +34,11 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC
@Autowired @Autowired
private CustomerServiceCommonService commonService; private CustomerServiceCommonService commonService;
@Autowired
private RegisterUserEntityService userEntityService;
@Override @Override
public List<RegisterUserEntity> getUserListFromPackage(Long packageId) { public List<CrowdPackageUserVO> getUserListFromPackage(Long packageId, String openId) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
// 获取人群包下的条件 // 获取人群包下的条件
...@@ -51,7 +55,7 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC ...@@ -51,7 +55,7 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC
LOCAL_LOG.info("获取SetupId列表耗时 {}ms, setupId列表长度: {}", getSetupIdTime - getConditionTime, setupIdList.size()); LOCAL_LOG.info("获取SetupId列表耗时 {}ms, setupId列表长度: {}", getSetupIdTime - getConditionTime, setupIdList.size());
// 根据动态条件获取用户列表 // 根据动态条件获取用户列表
List<RegisterUserEntity> userList = new ArrayList<>(); List<CrowdPackageUserVO> userList = userEntityService.getUserMatchDynamicExpress(nonStaticConditionList, openId);
long dynamicUserTime = System.currentTimeMillis(); long dynamicUserTime = System.currentTimeMillis();
LOCAL_LOG.info("获取SetupId列表符合动态条件的用户耗时 {}ms, 符合动态条件的用户: {}个", dynamicUserTime - getSetupIdTime, userList.size()); LOCAL_LOG.info("获取SetupId列表符合动态条件的用户耗时 {}ms, 符合动态条件的用户: {}个", dynamicUserTime - getSetupIdTime, userList.size());
...@@ -62,6 +66,16 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC ...@@ -62,6 +66,16 @@ public class CrowdPackageConditionMatchServiceImpl extends ServiceImpl<MaterialC
long allUserTime = System.currentTimeMillis(); long allUserTime = System.currentTimeMillis();
LOCAL_LOG.info("获取符合全部条件的用户耗时: {}ms, 符合全部条件的用户: {}个", allUserTime - dynamicUserTime, userList.size()); LOCAL_LOG.info("获取符合全部条件的用户耗时: {}ms, 符合全部条件的用户: {}个", allUserTime - dynamicUserTime, userList.size());
if (CollectionUtil.isEmpty(userList)) {
LOCAL_LOG.info("人群包ID {}, 没有符合条件的用户", packageId);
}
return userList; return userList;
} }
@Override
public Boolean getUserPackageBelong(Long packageId, String openId) {
List<CrowdPackageUserVO> userList = this.getUserListFromPackage(packageId, openId);
return CollectionUtil.isNotEmpty(userList);
}
} }
...@@ -12,6 +12,7 @@ import com.yaoyaozw.customer.common.GenericsResult; ...@@ -12,6 +12,7 @@ import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.components.SnowflakeComponent; import com.yaoyaozw.customer.components.SnowflakeComponent;
import com.yaoyaozw.customer.components.TokenManager; import com.yaoyaozw.customer.components.TokenManager;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant; import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.crowd.CrowdPackageQueryDTO; import com.yaoyaozw.customer.dto.crowd.CrowdPackageQueryDTO;
import com.yaoyaozw.customer.dto.crowd.CrowdPackageConditionDTO; import com.yaoyaozw.customer.dto.crowd.CrowdPackageConditionDTO;
import com.yaoyaozw.customer.entity.CrowdPackage; import com.yaoyaozw.customer.entity.CrowdPackage;
...@@ -20,19 +21,24 @@ import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch; ...@@ -20,19 +21,24 @@ import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.enums.CrowdPackageConditionEnum; import com.yaoyaozw.customer.enums.CrowdPackageConditionEnum;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper; import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.mapper.MaterialCrowdPackageMapper; import com.yaoyaozw.customer.mapper.MaterialCrowdPackageMapper;
import com.yaoyaozw.customer.mapper.RegisterUserEntityMapper;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService; import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CrowdPackageConditionService; import com.yaoyaozw.customer.service.CrowdPackageConditionService;
import com.yaoyaozw.customer.service.CrowdPackageService; import com.yaoyaozw.customer.service.CrowdPackageService;
import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.vo.CommonOptionResponseVO; import com.yaoyaozw.customer.vo.CommonOptionResponseVO;
import com.yaoyaozw.customer.vo.crowd.*; import com.yaoyaozw.customer.vo.crowd.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -53,6 +59,10 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap ...@@ -53,6 +59,10 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
private TokenManager tokenManager; private TokenManager tokenManager;
@Autowired @Autowired
private CrowdPackageConditionMatchService matchService; private CrowdPackageConditionMatchService matchService;
@Autowired
private RegisterUserEntityMapper userEntityMapper;
@Autowired
private RedisTemplate redisTemplate;
@Override @Override
...@@ -131,6 +141,11 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap ...@@ -131,6 +141,11 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
if (CollectionUtil.isEmpty(pageList)) { if (CollectionUtil.isEmpty(pageList)) {
return new GenericsResult<>(false, "暂无数据"); return new GenericsResult<>(false, "暂无数据");
} }
HashMap<String, Integer> entries = (HashMap<String, Integer>) redisTemplate.boundHashOps(CustomerCommonConstant.CROWD_HUMAN_NUN_REDIS_KEY).entries();
if (CollectionUtil.isNotEmpty(entries)) {
pageList.forEach(item -> item.setNumOfCrowdInPackage(entries.get(item.getId().toString())));
}
return new GenericsResult<>(pageList); return new GenericsResult<>(pageList);
} }
...@@ -186,6 +201,43 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap ...@@ -186,6 +201,43 @@ public class CrowdPackageServiceImpl extends ServiceImpl<MaterialCrowdPackageMap
return new GenericsResult<>(new ConditionOptionResponseVO(conditionItem.getFrontType(), result)); return new GenericsResult<>(new ConditionOptionResponseVO(conditionItem.getFrontType(), result));
} }
@Override
public BaseResult updateUserPackageBelong(String openId) {
List<CrowdPackage> packageList = super.list();
StringBuilder packageConcatResult = new StringBuilder();
boolean isFirst = true;
for (CrowdPackage crowdPackage : packageList) {
Boolean matchPackage = matchService.getUserPackageBelong(crowdPackage.getId(), openId);
if (matchPackage) {
// 用户符合人群包条件
if (!isFirst) {
// 除了第一个,其他的要在数字前拼上逗号
packageConcatResult.append(",");
}
packageConcatResult.append(crowdPackage.getId());
isFirst = false;
}
}
String packageStr = packageConcatResult.toString();
userEntityMapper.updateUserPackageBelong(openId, StringUtils.isBlank(packageStr) ? null : packageStr);
LOCAL_LOG.info("用户openId: {} 人群包更新完成", openId);
return new BaseResult().success();
}
@Override
public BaseResult updateUserPackageBatch(List<String> openIdList) {
List<CrowdPackage> packageList = super.list();
return null;
}
/** /**
* 构造操作符 * 构造操作符
* *
......
...@@ -2,11 +2,16 @@ package com.yaoyaozw.customer.service.impl; ...@@ -2,11 +2,16 @@ package com.yaoyaozw.customer.service.impl;
import com.yaoyaozw.customer.common.BaseResult; import com.yaoyaozw.customer.common.BaseResult;
import com.yaoyaozw.customer.common.GenericsResult; import com.yaoyaozw.customer.common.GenericsResult;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO; import com.yaoyaozw.customer.dto.customer.CustomerMessageQueryDTO;
import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO; import com.yaoyaozw.customer.dto.customer.CustomerMessageSaveDTO;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerMessageListVO; import com.yaoyaozw.customer.vo.customer.CustomerMessageListVO;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -25,15 +30,23 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -25,15 +30,23 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
private final static Logger LOCAL_LOG = LoggerFactory.getLogger(CustomerGraphicsServiceImpl.class); private final static Logger LOCAL_LOG = LoggerFactory.getLogger(CustomerGraphicsServiceImpl.class);
@Autowired
private CrowdPackageConditionMatchService matchService;
@Autowired
private RedisTemplate redisTemplate;
@Override @Override
public BaseResult insertCustomerMessage(CustomerMessageSaveDTO saveDto) { public BaseResult insertCustomerMessage(CustomerMessageSaveDTO saveDto) {
Long packageId = saveDto.getPackageId();
LOCAL_LOG.info("根据人群包找到符合条件的用户数据"); LOCAL_LOG.info("根据人群包 {} 找符合条件的用户数据", packageId);
List<CrowdPackageUserVO> userList = matchService.getUserListFromPackage(packageId, null);
redisTemplate.opsForHash().put(CustomerCommonConstant.CROWD_HUMAN_NUN_REDIS_KEY, packageId.toString(), userList.size());
// TODO: 2022/9/28 根据人群包找到下面的人所在的公众号,进行链接获取 // TODO: 2022/9/28 根据人群包找到下面的人所在的公众号,进行链接获取
return null; return new BaseResult().success();
} }
@Override @Override
......
...@@ -8,6 +8,7 @@ import com.yaoyaozw.customer.service.AuthorizerTokenService; ...@@ -8,6 +8,7 @@ import com.yaoyaozw.customer.service.AuthorizerTokenService;
import com.yaoyaozw.customer.service.CustomerGraphicsDelayService; import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.CustomerGraphicsService; import com.yaoyaozw.customer.service.CustomerGraphicsService;
import com.yaoyaozw.customer.service.wechat.service.WeChatService; import com.yaoyaozw.customer.service.wechat.service.WeChatService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO; import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -49,4 +50,10 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit ...@@ -49,4 +50,10 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit
} }
@Override
public List<CrowdPackageUserVO> getUserMatchDynamicExpress(List<String> dynamicExpressList, String openId) {
return baseMapper.getUserMatchDynamicExpress(dynamicExpressList, openId);
}
} }
package com.yaoyaozw.customer.vo.customer;
import lombok.Data;
import java.io.Serializable;
/**
* @author darker
* @date 2022/9/28 19:20
*/
@Data
public class CrowdPackageUserVO implements Serializable {
private static final long serialVersionUID = 6564547615107105008L;
private Long id;
private String accountId;
private String openId;
private Long setupId;
private String inPackage;
}
...@@ -4,7 +4,7 @@ spring: ...@@ -4,7 +4,7 @@ spring:
application: application:
name: customer-service name: customer-service
profiles: profiles:
active: pro active: dev
--- ---
spring: spring:
profiles: dev profiles: dev
......
...@@ -20,4 +20,39 @@ ...@@ -20,4 +20,39 @@
id, app_id, open_id, setup_id, pay_type, pay_num, pay_amount, avg_month, last_active, id, app_id, open_id, setup_id, pay_type, pay_num, pay_amount, avg_month, last_active,
gmt_create, customer_sort, customer_publish gmt_create, customer_sort, customer_publish
</sql> </sql>
<select id="getUserMatchDynamicExpress" resultType="com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO">
select
rue.id,
ai.account_id as accountId,
rue.setup_id as setupId,
rue.open_id as openId,
rue.in_package as inPackage
from register_user_entity rue
left join authorizer_info ai
on rue.app_id = ai.appid
where
<if test="openId != null and openId != ''">
rue.open_id = #{openId} and
</if>
timestampdiff(HOUR, rue.last_active, now()) &lt; 48
<if test="dynamicExpressList != null and dynamicExpressList.size() != 0">
<foreach collection="dynamicExpressList" open=" and " item="express" separator=" and ">
${express}
</foreach>
</if>
</select>
<update id="updateUserPackageBelong">
update register_user_entity
set in_package = #{packageBelong}
where open_id = #{openId}
</update>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论