提交 ea73777a 作者: 沈振路

Merge branch 'master' into customer_service_SZlu

...@@ -12,7 +12,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -12,7 +12,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* @date 2022/9/15 18:13 * @date 2022/9/15 18:13
*/ */
@SpringBootApplication @SpringBootApplication
//@EnableScheduling @EnableScheduling
@MapperScan("com.yaoyaozw.customer.mapper") @MapperScan("com.yaoyaozw.customer.mapper")
@EnableFeignClients @EnableFeignClients
@EnableAsync @EnableAsync
......
...@@ -122,6 +122,8 @@ public class CustomerGraphics implements Serializable { ...@@ -122,6 +122,8 @@ public class CustomerGraphics implements Serializable {
public static final String COL_POST_TIME = "post_time"; public static final String COL_POST_TIME = "post_time";
public static final String COL_SEND_STATUS = "send_status";
public static final String COL_CREATE_USER = "create_user"; public static final String COL_CREATE_USER = "create_user";
public static final String COL_GMT_CREATE = "gmt_create"; public static final String COL_GMT_CREATE = "gmt_create";
......
...@@ -94,7 +94,7 @@ public class RegisterUserEntity implements Serializable { ...@@ -94,7 +94,7 @@ public class RegisterUserEntity implements Serializable {
private Date customerPublish; private Date customerPublish;
/** /**
* 延时客服发送时间 * 人群包
*/ */
@TableField(value = "in_package") @TableField(value = "in_package")
private String inPackage; private String inPackage;
......
...@@ -7,6 +7,7 @@ import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO; ...@@ -7,6 +7,7 @@ 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 org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List; import java.util.List;
@Mapper @Mapper
...@@ -58,5 +59,17 @@ public interface RegisterUserEntityMapper extends BaseMapper<RegisterUserEntity> ...@@ -58,5 +59,17 @@ public interface RegisterUserEntityMapper extends BaseMapper<RegisterUserEntity>
*/ */
List<AuthorizerInfo>existAppid(); List<AuthorizerInfo>existAppid();
/**
* 根据appid找register用户
* @param appid
* @return
*/
List<RegisterUserEntity> findAllUserWithoutSetupId(String appid); List<RegisterUserEntity> findAllUserWithoutSetupId(String appid);
/**
* 找超时客服排期的活跃用户
* @param requestDate
* @return
*/
List<RegisterUserEntity> findAllExpiredDelayPublish(@Param("requestDate")Date requestDate);
} }
\ No newline at end of file
...@@ -46,6 +46,7 @@ public class SchedulingTask { ...@@ -46,6 +46,7 @@ public class SchedulingTask {
/** /**
* 拉取付费订单(每15min一次) * 拉取付费订单(每15min一次)
*/ */
@Scheduled(cron = "0 5/15 * * * *")
public void retrieveOrderData(){ public void retrieveOrderData(){
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
......
...@@ -30,8 +30,14 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc ...@@ -30,8 +30,14 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
@Override @Override
public void activeUserByOrder(IntegrationRequestDTO integrationRequestDTO) { public void activeUserByOrder(IntegrationRequestDTO integrationRequestDTO) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(integrationRequestDTO.getRequestDate());
//间隔5min拉看板订单
calendar.add(Calendar.MINUTE,-5);
//获取runtime订单最新一版数据 //获取runtime订单最新一版数据
List<AccountOrder> runtimeOrders= baseMapper.findNewestRuntimeAccountOrder(integrationRequestDTO.getRequestDate()); List<AccountOrder> runtimeOrders= baseMapper.findNewestRuntimeAccountOrder(calendar.getTime());
Set<String> openIdSet = runtimeOrders.stream().map(AccountOrder::getOpenId).collect(Collectors.toSet()); Set<String> openIdSet = runtimeOrders.stream().map(AccountOrder::getOpenId).collect(Collectors.toSet());
...@@ -44,7 +50,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc ...@@ -44,7 +50,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
if(!userList.isEmpty()){ if(!userList.isEmpty()){
Set<String> appIdSet = userList.stream().map(RegisterUserEntity::getAppId).collect(Collectors.toSet()); Set<String> appIdSet = userList.stream().map(RegisterUserEntity::getAppId).collect(Collectors.toSet());
List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerSort(appIdSet,1); List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerSort(appIdSet,3);
Map<String, Map<Integer, Long>> delayMessageMap = allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId, Collectors.toMap(CustomerDelayItemVO::getPostSort, CustomerDelayItemVO::getTimeInterval, (v1, v2) -> v2))); Map<String, Map<Integer, Long>> delayMessageMap = allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId, Collectors.toMap(CustomerDelayItemVO::getPostSort, CustomerDelayItemVO::getTimeInterval, (v1, v2) -> v2)));
...@@ -68,7 +74,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc ...@@ -68,7 +74,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
//如果没有活跃时间,记录为首次活跃 //如果没有活跃时间,记录为首次活跃
registerUser.setFirstActive(lastFinishTime); registerUser.setFirstActive(lastFinishTime);
//排期重置 //排期重置
delayCustomerManage(registerUser,lastFinishTime,delayMessageMap); delayCustomerManage(registerUser,lastFinishTime,integrationRequestDTO.getRequestDate(),delayMessageMap);
} }
//活跃时间重置 //活跃时间重置
registerUser.setLastActive(lastFinishTime); registerUser.setLastActive(lastFinishTime);
...@@ -110,7 +116,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc ...@@ -110,7 +116,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
* 延时客服排期 * 延时客服排期
* @param registerUserPublish * @param registerUserPublish
*/ */
public void delayCustomerManage(RegisterUserEntity registerUserPublish, Date activeTime, Map<String, Map<Integer, Long>> delayMessageMap){ public void delayCustomerManage(RegisterUserEntity registerUserPublish, Date activeTime,Date currentDate, Map<String, Map<Integer, Long>> delayMessageMap){
Map<Integer, Long> integerLongMap = delayMessageMap.get(registerUserPublish.getAppId()); Map<Integer, Long> integerLongMap = delayMessageMap.get(registerUserPublish.getAppId());
...@@ -118,13 +124,30 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc ...@@ -118,13 +124,30 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
//找初始排期间隔时间 //找初始排期间隔时间
Long firstDelayMessage = integerLongMap.get(1); Long firstDelayMessage = integerLongMap.get(1);
Date publishTime = new Date(activeTime.getTime() + firstDelayMessage); Long secondDelayMessage = integerLongMap.get(2);
Long thirdDelayMessage = integerLongMap.get(3);
//如果活跃时间和当前的间隔大于首次排期间隔,则说明排1就扫不到了;
if (firstDelayMessage!=null&&currentDate.getTime()-activeTime.getTime()<firstDelayMessage){
//时间戳精确到分
Date publishTime = new Date((activeTime.getTime()/(60*1000))*60*1000 + firstDelayMessage);
registerUserPublish.setCustomerSort(1);
registerUserPublish.setCustomerPublish(publishTime);
registerUserPublish.setCustomerSort(1); }else if (secondDelayMessage!=null&&currentDate.getTime()-activeTime.getTime()<secondDelayMessage){
registerUserPublish.setCustomerPublish(publishTime); Date publishTime = new Date((activeTime.getTime()/(60*1000))*60*1000+ secondDelayMessage);
//如果活跃时间和注册时间的间隔小于首次排期间隔,则说明首次没发,从1序列开始排;否则从2序列开始排 registerUserPublish.setCustomerSort(2);
registerUserPublish.setCustomerPublish(publishTime);
}else if(thirdDelayMessage!=null){
Date publishTime = new Date((activeTime.getTime()/(60*1000))*60*1000 + thirdDelayMessage);
registerUserPublish.setCustomerSort(3);
registerUserPublish.setCustomerPublish(publishTime);
}else{
registerUserPublish.setCustomerSort(-1);
}
} }
} }
......
...@@ -48,7 +48,7 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu ...@@ -48,7 +48,7 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
if (!allPostUser.isEmpty()){ if (!allPostUser.isEmpty()){
//号-用户 //号-用户
Map<String, List<CustomerDelayPublish>> userMap = allPostUser.stream().filter(a->a.getCustomerSort()!=null).collect(Collectors.groupingBy(CustomerDelayPublish::getAppId)); Map<String, Map<String,CustomerDelayPublish>> userMap = allPostUser.stream().filter(a->a.getCustomerSort()!=null).collect(Collectors.groupingBy(CustomerDelayPublish::getAppId,Collectors.toMap(CustomerDelayPublish::getOpenId,a->a,(v1,v2)->v1)));
//获取所有延时客服 //获取所有延时客服
List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerSort(appidSet,null); List<CustomerDelayItemVO> allDelayCustomerMessage = customerGraphicsDelayService.findAllDelayCustomerSort(appidSet,null);
...@@ -62,7 +62,7 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu ...@@ -62,7 +62,7 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
Set<CustomerDelayItemVO> needUpdateCustomerDelay = new HashSet<>(); Set<CustomerDelayItemVO> needUpdateCustomerDelay = new HashSet<>();
for (Map.Entry<String, List<CustomerDelayPublish>> userEntry : userMap.entrySet()) { for (Map.Entry<String, Map<String,CustomerDelayPublish>> userEntry : userMap.entrySet()) {
String appid = userEntry.getKey(); String appid = userEntry.getKey();
//获取该号token //获取该号token
...@@ -74,8 +74,10 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu ...@@ -74,8 +74,10 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
//该号下延时客服 //该号下延时客服
Map<Integer,List<CustomerDelayItemVO>> delaySortMap = customerMap.get(appid); Map<Integer,List<CustomerDelayItemVO>> delaySortMap = customerMap.get(appid);
//所有的用户 //所有的用户
List<CustomerDelayPublish> userList = userEntry.getValue(); Map<String,CustomerDelayPublish> userPublishMap = userEntry.getValue();
//去重
List<CustomerDelayPublish> userList = new ArrayList<>(userPublishMap.values()) ;
if (delaySortMap!=null&&!delaySortMap.isEmpty()){ if (delaySortMap!=null&&!delaySortMap.isEmpty()){
//将所有待用延时客服收集 //将所有待用延时客服收集
for (CustomerDelayPublish userPublish : userList) { for (CustomerDelayPublish userPublish : userList) {
......
...@@ -97,13 +97,11 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi ...@@ -97,13 +97,11 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
return new GenericsResult<>(false, builder.toString()); return new GenericsResult<>(false, builder.toString());
} }
boolean isCreate = false;
CustomerGraphicsDelay customerGraphicsDelay = new CustomerGraphicsDelay(); CustomerGraphicsDelay customerGraphicsDelay = new CustomerGraphicsDelay();
BeanUtil.copyProperties(saveDto, customerGraphicsDelay); BeanUtil.copyProperties(saveDto, customerGraphicsDelay);
// 初始化操作信息 // 初始化操作信息
customerGraphicsDelay.initOperateInfo(tokenManager.getUserIdFromToken(), ObjectUtil.isNull(saveDto.getId())); customerGraphicsDelay.initOperateInfo(tokenManager.getUserIdFromToken(), ObjectUtil.isNull(saveDto.getId()));
if (ObjectUtil.isNull(customerGraphicsDelay.getId())) { if (ObjectUtil.isNull(customerGraphicsDelay.getId())) {
isCreate = true;
long id = snowflakeComponent.snowflakeId(); long id = snowflakeComponent.snowflakeId();
localLog.info("是新增, 新生成ID: {}", id); localLog.info("是新增, 新生成ID: {}", id);
customerGraphicsDelay.setId(id); customerGraphicsDelay.setId(id);
...@@ -115,7 +113,7 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi ...@@ -115,7 +113,7 @@ public class CustomerGraphicsDelayServiceImpl extends ServiceImpl<CustomerGraphi
referralEntity.setMaterialGraphicsId(customerGraphicsDelay.getId()); referralEntity.setMaterialGraphicsId(customerGraphicsDelay.getId());
// 非自定义获取链接 // 非自定义获取链接
if (isCreate && !referralEntity.getNewsType().equals(-1)) { if (!referralEntity.getNewsType().equals(-1)) {
try { try {
customerGraphicsDelay.setSendStatus(CustomerCommonConstant.SEND_STATUS_LINK_GETTING); customerGraphicsDelay.setSendStatus(CustomerCommonConstant.SEND_STATUS_LINK_GETTING);
localLog.info("准备获取链接"); localLog.info("准备获取链接");
......
...@@ -47,6 +47,9 @@ import com.yaoyaozw.customer.service.CustomerGraphicsService; ...@@ -47,6 +47,9 @@ import com.yaoyaozw.customer.service.CustomerGraphicsService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
/** /**
* 客户图形服务impl * 客户图形服务impl
* *
...@@ -215,16 +218,17 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap ...@@ -215,16 +218,17 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
public void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO) { public void sendCustomerMessage(IntegrationRequestDTO integrationRequestDTO) {
Date requestDate = integrationRequestDTO.getRequestDate(); Date requestDate = integrationRequestDTO.getRequestDate();
//todo:当前时刻发送的客服(需要加启用禁用)
List<CustomerGraphics> customerGraphicsList = list(new QueryWrapper<CustomerGraphics>().eq(CustomerGraphics.COL_POST_TIME, requestDate)); List<CustomerGraphics> customerGraphicsList = list(new QueryWrapper<CustomerGraphics>().eq(CustomerGraphics.COL_POST_TIME, requestDate).eq(CustomerGraphics.COL_SEND_STATUS,9));
for (CustomerGraphics customerGraphics : customerGraphicsList) { for (CustomerGraphics customerGraphics : customerGraphicsList) {
//人群包id //人群包id
Long packId = customerGraphics.getPackId(); Long packId = customerGraphics.getPackId();
//根据人群包找人,并按appId分组 //根据人群包找人,并按appId分组
List<CrowdPackageUserVO> userList = registerUserEntityService.getCurrentInPackUserList(packId, false); List<CrowdPackageUserVO> userList = registerUserEntityService.getCurrentInPackUserList(packId, false);
//去重
Map<String, List<CrowdPackageUserVO>> appidUserMap = userList.stream().collect(Collectors.groupingBy(CrowdPackageUserVO::getAppId)); Map<String, List<CrowdPackageUserVO>> appidUserMap = userList.stream().collect(Collectors.groupingBy(CrowdPackageUserVO::getAppId,
Collectors.collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparing(CrowdPackageUserVO::getOpenId))), ArrayList::new)));
//根据客服id找不同公众号的链接,并按appId分组 //根据客服id找不同公众号的链接,并按appId分组
List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId()); List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId());
......
...@@ -98,19 +98,19 @@ public class WeChatServiceImpl implements WeChatService{ ...@@ -98,19 +98,19 @@ public class WeChatServiceImpl implements WeChatService{
} }
} }
//用户首次活跃时间 //用户首次活跃时间
Long subscribeTimestamp = user.getFirstActive().getTime(); Long subscribeTimestamp = user.getFirstActive()!=null?user.getFirstActive().getTime():user.getGmtCreate().getTime();
Set<Integer> sortSet = delaySortMap.keySet(); Set<Integer> sortSet = delaySortMap.keySet();
//找最小 //找大于当前序列的最小序列
Integer newSort =sortSet.stream().filter(a->a>user.getCustomerSort()).min(Comparator.naturalOrder()).orElse(-1); Integer newSort =sortSet.stream().filter(a->a>user.getCustomerSort()).min(Comparator.naturalOrder()).orElse(-1);
user.setCustomerSort(newSort); user.setCustomerSort(newSort);
CustomerDelayItemVO customerDelayItemVO = delaySortMap.get(newSort)!=null?delaySortMap.get(newSort).get(0):null; CustomerDelayItemVO customerDelayItemVO = delaySortMap.get(newSort)!=null?delaySortMap.get(newSort).get(0):null;
//下次排期
if (customerDelayItemVO!=null&&customerDelayItemVO.getTimeInterval()!=null){ if (customerDelayItemVO!=null&&customerDelayItemVO.getTimeInterval()!=null){
//时间戳舍秒和毫秒
user.setCustomerPublish(new Date(subscribeTimestamp+customerDelayItemVO.getTimeInterval())); user.setCustomerPublish(new Date((subscribeTimestamp/(60*1000))*60*1000+customerDelayItemVO.getTimeInterval()));
} }
return new AsyncResult<>(user); return new AsyncResult<>(user);
} }
......
...@@ -121,4 +121,23 @@ ...@@ -121,4 +121,23 @@
</select> </select>
<resultMap id="updateCustomerSortMap" type="com.yaoyaozw.customer.entity.RegisterUserEntity">
<!--@mbg.generated-->
<!--@Table register_user_entity-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="app_id" jdbcType="VARCHAR" property="appId" />
<result column="customer_sort" jdbcType="INTEGER" property="customerSort" />
<result column="customer_publish" jdbcType="TIMESTAMP" property="customerPublish" />
<result column="first_active" jdbcType="TIMESTAMP" property="firstActive" />
</resultMap>
<select id="findAllExpiredDelayPublish" resultMap="updateCustomerSortMap">
select id,app_id,customer_sort,customer_publish ,first_active from register_user_entity
where customer_sort > 0 AND first_active is not null and customer_publish &lt; #{requestDate}
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论