提交 ddc798d9 作者: gh

延时逻辑更新

上级 2f9ad24f
......@@ -75,6 +75,18 @@ public class RegisterUserEntity implements Serializable {
@TableField(value = "gmt_create")
private Date gmtCreate;
/**
* 延时客服序列
*/
@TableField(value = "customer_sort")
private Integer customerSort;
/**
* 延时客服发送时间
*/
@TableField(value = "customer_publish")
private Date customerPublish;
private static final long serialVersionUID = 1L;
......
......@@ -21,4 +21,6 @@ public interface CustomerGraphicsDelayMapper extends BaseMapper<CustomerGraphics
* @return
*/
List<CustomerDelayItemVO> findAllDelayCustomerMessage(@Param("appidList") Set<String> appidList);
List<CustomerDelayItemVO> findDelayCustomerMessageByRange(@Param("appidList")Set<String> appidList,@Param("maxSort")Integer maxSort);
}
\ No newline at end of file
package com.yaoyaozw.customer.schedules;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.constants.CrowdPackageCommonConstant;
import com.yaoyaozw.customer.dto.crowd.CrowdPackageQueryDTO;
import com.yaoyaozw.customer.entity.CrowdPackageConditionMatch;
import com.yaoyaozw.customer.service.CrowdPackageConditionMatchService;
import com.yaoyaozw.customer.service.CrowdPackageService;
import com.yaoyaozw.customer.vo.crowd.CrowdPackageListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author darker
* @date 2022/9/23 10:18
*/
@Component
public class CrowdPackageSchedule {
private final static Logger LOCAL_LOG = LoggerFactory.getLogger(CrowdPackageSchedule.class);
@Autowired
private CrowdPackageService crowdPackageService;
@Autowired
private CrowdPackageConditionMatchService matchService;
/**
* 计算人群包用户人数
*/
// @Scheduled(cron = "0 0 10 * * ?")
public void calCrowdPackageHumanNum() {
LOCAL_LOG.info("获取人群包列表");
CrowdPackageQueryDTO crowdPackageQuery = new CrowdPackageQueryDTO();
List<CrowdPackageListVO> crowdPackageList = crowdPackageService.pageList(crowdPackageQuery).getData();
// 没有人群包
if (CollectionUtil.isEmpty(crowdPackageList)) {
LOCAL_LOG.info("未找到符合条件的人群包");
return;
}
LOCAL_LOG.info("共获得人群包 {} 条", crowdPackageList.size());
// 遍历人群包,依次处理
for (CrowdPackageListVO crowdPackageVo : crowdPackageList) {
LOCAL_LOG.info("当前处理人群包: 【{}】", crowdPackageVo.getPackageName());
// 获取人群包下的条件
List<CrowdPackageConditionMatch> packageConditionList = matchService.list(new QueryWrapper<CrowdPackageConditionMatch>().eq("package_id", crowdPackageVo.getId()));
LOCAL_LOG.info("共获取人群包下条件 {} 条", packageConditionList.size());
}
}
}
......@@ -13,6 +13,7 @@ import java.util.Set;
*/
public interface CustomerGraphicsDelayService extends IService<CustomerGraphicsDelay> {
List<CustomerDelayItemVO> findAllDelayCustomerMessage(Set<String> appidList);
List<CustomerDelayItemVO> findAllDelayCustomerMessage(Set<String> appidList,Integer maxSortRage);
}
......@@ -2,9 +2,13 @@ package com.yaoyaozw.customer.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.entity.CustomerDelayPublish;
import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.service.CustomerDelayPublishService;
import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.vo.UserAvgAmountVO;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -25,6 +29,8 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
@Autowired
private RegisterUserEntityService registerUserEntityService;
@Autowired
private CustomerGraphicsDelayService customerGraphicsDelayService;
@Override
public void activeUserByOrder(IntegrationRequestDTO integrationRequestDTO) {
......@@ -37,6 +43,12 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
//获取注册用户信息
List<RegisterUserEntity> userList = registerUserEntityService.list(new QueryWrapper<RegisterUserEntity>().in(RegisterUserEntity.COL_OPEN_ID, openIdSet));
Set<String> appIdSet = userList.stream().map(RegisterUserEntity::getAppId).collect(Collectors.toSet());
List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerMessage(appIdSet,2);
Map<String, Map<Integer, Long>> delayMessageMap = allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId, Collectors.toMap(CustomerDelayItemVO::getPostSort, CustomerDelayItemVO::getTimeInterval, (v1, v2) -> v2)));
for (RegisterUserEntity registerUser : userList) {
//获取用户订单
List<AccountOrder> accountOrders = userOrderMap.get(registerUser.getOpenId());
......@@ -78,7 +90,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
//获取近一月每个用户的平均充值
List<UserAvgAmountVO> userAvgAmountVos= baseMapper.findMonthDailyAccountOrder();
Map<String, Double> userAvgAmountMap = userAvgAmountVos.stream().collect(Collectors.toMap(UserAvgAmountVO::getOpenId, UserAvgAmountVO::getAvgAmount, (v1, v2) -> v1));
//获取注册用户信息
//获取付费用户信息
List<RegisterUserEntity> userList = registerUserEntityService.list(new QueryWrapper<RegisterUserEntity>().gt(RegisterUserEntity.COL_PAY_TYPE, 0));
if (userList!=null&&!userList.isEmpty()){
......@@ -90,5 +102,42 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
}
registerUserEntityService.updateBatchById(userList);
}
/**
* 延时客服排期
* @param registerUserPublish
*/
public void delayCustomerManage(RegisterUserEntity registerUserPublish, Date activeTime, Map<String, Map<Integer, Long>> delayMessageMap){
Map<Integer, Long> integerLongMap = delayMessageMap.get(registerUserPublish.getAppId());
if (integerLongMap!=null&&!integerLongMap.isEmpty()){
Long firstDelayMessage = integerLongMap.get(1);
Long secondDelayMessage = integerLongMap.get(2);
if (activeTime.getTime()-registerUserPublish.getGmtCreate().getTime()<firstDelayMessage){
Date publishTime = new Date(activeTime.getTime() + firstDelayMessage);
registerUserPublish.setCustomerSort(1);
registerUserPublish.setCustomerPublish(publishTime);
}else{
Date publishTime = new Date(activeTime.getTime() + secondDelayMessage);
registerUserPublish.setCustomerSort(2);
registerUserPublish.setCustomerPublish(publishTime);
}
}
}
}
......@@ -24,8 +24,9 @@ import com.yaoyaozw.customer.mapper.CustomerDelayPublishMapper;
import com.yaoyaozw.customer.service.CustomerDelayPublishService;
/**
* @author wgh
* @date 2022/9/28 18:51
* 延时客服排期
* @author wgh
* @date 2022/9/28 18:51
*/
@Service
public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPublishMapper, CustomerDelayPublish> implements CustomerDelayPublishService{
......@@ -54,7 +55,7 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
//号-用户
Map<String, List<CustomerDelayPublish>> userMap = allPostUser.stream().collect(Collectors.groupingBy(CustomerDelayPublish::getAppId));
List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerMessage(appidSet);
List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerMessage(appidSet,null);
/*
List<AuthorizerToken> tokenList = authorizerTokenService.list();
Map<String, String> tokenMap = tokenList.stream().collect(Collectors.toMap(AuthorizerToken::getAuthorizerAppid, AuthorizerToken::getAuthorizerAccessToken));
......@@ -62,10 +63,10 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
if (allDelayCustomerMessage!=null&&!allDelayCustomerMessage.isEmpty()){
List<Future<CustomerDelayPublish>>futureList =new ArrayList<>();
//号-发送序列-客服id
Map<String, Map<Integer, CustomerDelayItemVO>> customerMap = allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId, Collectors.toMap(CustomerDelayItemVO::getPostSort, a -> a, (v1, v2) -> v2)));
Map<String, Map<Integer, CustomerDelayItemVO>> customerMap =
allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId,
Collectors.toMap(CustomerDelayItemVO::getPostSort, a -> a, (v1, v2) -> v2)));
for (Map.Entry<String, List<CustomerDelayPublish>> userEntry : userMap.entrySet()) {
......@@ -90,7 +91,7 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
}
}
List<CustomerDelayPublish> registerUserEntities = new ArrayList<>();
//更新下次延时排期
for (Future<CustomerDelayPublish> delayPublishFuture : futureList) {
try {
registerUserEntities.add(delayPublishFuture.get()) ;
......
......@@ -20,10 +20,15 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
@Override
public List<CustomerDelayItemVO> findAllDelayCustomerMessage(Set<String> appidList) {
public List<CustomerDelayItemVO> findAllDelayCustomerMessage(Set<String> appidList,Integer maxSortRange) {
return baseMapper.findAllDelayCustomerMessage(appidList);
if (maxSortRange!=null){
return baseMapper.findDelayCustomerMessageByRange(appidList,maxSortRange);
}else{
return baseMapper.findAllDelayCustomerMessage(appidList);
}
}
}
......@@ -46,7 +46,6 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit
}
......
......@@ -9,7 +9,6 @@ import java.util.concurrent.Future;
public interface WeChatService {
/**
* 发送延时客服消息
*/
......
......@@ -28,4 +28,10 @@
</select>
<select id="findDelayCustomerMessageByRange" resultType="com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO">
select * from customer_graphics_delay where post_sort &lt; #{maxSort}
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论