提交 ec70a097 作者: gh

定时刷新过期的延时客服

上级 c6cfdc61
...@@ -81,6 +81,26 @@ public class SchedulingTask { ...@@ -81,6 +81,26 @@ public class SchedulingTask {
customerDelayPublishService.sendCustomerDelayMessage(integrationRequestDTO); customerDelayPublishService.sendCustomerDelayMessage(integrationRequestDTO);
} }
/**
* 每天跑两次扫过期延时客服
*/
@Scheduled(cron = "0 3 9/12 * * *")
public void refreshExpiredDelayCustomer(){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE,-5);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
customerDelayPublishService.updateExpiredCustomerDelayMessage(calendar.getTime());
}
/** /**
* 从redis中更新人群包人数 * 从redis中更新人群包人数
*/ */
......
...@@ -4,14 +4,24 @@ import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO; ...@@ -4,14 +4,24 @@ import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.entity.CustomerDelayPublish; import com.yaoyaozw.customer.entity.CustomerDelayPublish;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
/** import java.util.Date;
/**
* @author wgh * @author wgh
* @date 2022/9/28 18:51 * @date 2022/9/28 18:51
*/ */
public interface CustomerDelayPublishService extends IService<CustomerDelayPublish>{ public interface CustomerDelayPublishService extends IService<CustomerDelayPublish> {
/** /**
* 延时客服发送 * 延时客服发送
* @param integrationRequestDTO * @param integrationRequestDTO
*/ */
public void sendCustomerDelayMessage(IntegrationRequestDTO integrationRequestDTO); public void sendCustomerDelayMessage(IntegrationRequestDTO integrationRequestDTO);
/**
* 更新过期的延时客服
* @param requestDate
*/
public void updateExpiredCustomerDelayMessage(Date requestDate);
} }
...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO; import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Date;
import java.util.List; import java.util.List;
public interface RegisterUserEntityService extends IService<RegisterUserEntity>{ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{
...@@ -37,5 +38,10 @@ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{ ...@@ -37,5 +38,10 @@ public interface RegisterUserEntityService extends IService<RegisterUserEntity>{
List<CrowdPackageUserVO> getCurrentInPackUserList(Long packageId,Boolean isLeftJoin); List<CrowdPackageUserVO> getCurrentInPackUserList(Long packageId,Boolean isLeftJoin);
/**
* 找超时的延时客服排期
* @param requestDate 请求时刻
* @return
*/
List<RegisterUserEntity> getAllExpiredDelayPublish(Date requestDate);
} }
package com.yaoyaozw.customer.service.impl; package com.yaoyaozw.customer.service.impl;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO; import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.service.CustomerGraphicsDelayService; import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.RegisterUserEntityService;
import com.yaoyaozw.customer.service.wechat.service.WeChatService; import com.yaoyaozw.customer.service.wechat.service.WeChatService;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO; import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -42,6 +44,8 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu ...@@ -42,6 +44,8 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
@Autowired @Autowired
private WeChatService weChatService; private WeChatService weChatService;
@Autowired
private RegisterUserEntityService registerUserEntityService;
@Override @Override
public void sendCustomerDelayMessage(IntegrationRequestDTO integrationRequestDTO) { public void sendCustomerDelayMessage(IntegrationRequestDTO integrationRequestDTO) {
...@@ -115,4 +119,55 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu ...@@ -115,4 +119,55 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
localLog.error("发生异常: {}, 位置: {}", e.getMessage(), e.getStackTrace()[0]); localLog.error("发生异常: {}, 位置: {}", e.getMessage(), e.getStackTrace()[0]);
} }
} }
@Override
public void updateExpiredCustomerDelayMessage(Date requestDate) {
//超时的延时排期
List<RegisterUserEntity> allExpiredDelayPublish = registerUserEntityService.getAllExpiredDelayPublish(requestDate);
Set<String> appidList = allExpiredDelayPublish.stream().map(RegisterUserEntity::getAppId).collect(Collectors.toSet());
//获取所有延时客服
List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerSort(appidList,null);
Map<String, Map<Long, Integer>> collect = allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId, Collectors.toMap(CustomerDelayItemVO::getTimeInterval, CustomerDelayItemVO::getPostSort, (v1, v2) -> v1)));
Date currentDate = new Date();
for (RegisterUserEntity expiredUser : allExpiredDelayPublish) {
try {
Map<Long, Integer> longIntegerMap = collect.get(expiredUser.getAppId());
if (longIntegerMap!=null&&!longIntegerMap.isEmpty()){
Date firstActive = expiredUser.getFirstActive();
ArrayList<Long> timeList = new ArrayList<>(longIntegerMap.keySet());
List<Long> sortTimeList = timeList.stream().sorted().collect(Collectors.toList());
for (Long aLong : sortTimeList) {
Date publishTime = new Date(((firstActive.getTime() + aLong) / 60000) * 60000);
if(publishTime.compareTo(currentDate)>0){
expiredUser.setCustomerPublish(publishTime);
expiredUser.setCustomerSort(longIntegerMap.get(aLong));
break;
}
expiredUser.setCustomerSort(-1);
}
}else{
expiredUser.setCustomerSort(-1);
}
}catch (Exception e){
log.error(e.getStackTrace()[0].toString());
}
}
registerUserEntityService.updateBatchById(allExpiredDelayPublish);
}
} }
package com.yaoyaozw.customer.service.impl; 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.AuthorizerToken;
import com.yaoyaozw.customer.entity.CustomerDelayPublish;
import com.yaoyaozw.customer.service.AuthorizerTokenService;
import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.CustomerGraphicsService;
import com.yaoyaozw.customer.service.wechat.service.WeChatService;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO; import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaoyaozw.customer.mapper.RegisterUserEntityMapper; import com.yaoyaozw.customer.mapper.RegisterUserEntityMapper;
import com.yaoyaozw.customer.entity.RegisterUserEntity; import com.yaoyaozw.customer.entity.RegisterUserEntity;
import com.yaoyaozw.customer.service.RegisterUserEntityService; import com.yaoyaozw.customer.service.RegisterUserEntityService;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
@Service @Service
...@@ -56,4 +43,9 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit ...@@ -56,4 +43,9 @@ public class RegisterUserEntityServiceImpl extends ServiceImpl<RegisterUserEntit
} }
} }
@Override
public List<RegisterUserEntity> getAllExpiredDelayPublish(Date requestDate){
return baseMapper.findAllExpiredDelayPublish(requestDate);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论