提交 d7097e5c 作者: 沈振路

延时发文 try catch

上级 a38c1573
......@@ -8,6 +8,8 @@ import com.yaoyaozw.customer.service.CustomerGraphicsDelayService;
import com.yaoyaozw.customer.service.wechat.service.WeChatService;
import com.yaoyaozw.customer.utils.YYZWDateUtil;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -29,6 +31,7 @@ import com.yaoyaozw.customer.service.CustomerDelayPublishService;
@Service
public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPublishMapper, CustomerDelayPublish> implements CustomerDelayPublishService{
private final static Logger localLog = LoggerFactory.getLogger(CustomerDelayPublishServiceImpl.class);
@Autowired
private CustomerGraphicsDelayService customerGraphicsDelayService;
......@@ -47,67 +50,66 @@ public class CustomerDelayPublishServiceImpl extends ServiceImpl<CustomerDelayPu
//涉及的appid
Set<String> appidSet = allPostUser.stream().map(CustomerDelayPublish::getAppId).collect(Collectors.toSet());
if (!allPostUser.isEmpty()){
//号-用户
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);
if (allDelayCustomerMessage!=null&&!allDelayCustomerMessage.isEmpty()){
List<Future<CustomerDelayPublish>>futureList =new ArrayList<>();
//号-发送序列-客服id
Map<String, Map<Integer, List<CustomerDelayItemVO>>> customerMap =
allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId,
Collectors.groupingBy(CustomerDelayItemVO::getPostSort)));
Set<CustomerDelayItemVO> needUpdateCustomerDelay = new HashSet<>();
for (Map.Entry<String, Map<String,CustomerDelayPublish>> userEntry : userMap.entrySet()) {
String appid = userEntry.getKey();
//获取该号token
AuthorizerToken authorizerToken = authorizerTokenService.findTokenByAppid(appid);
String token = authorizerToken.getAuthorizerAppid();
//没token过滤
if (token==null||"".equals(token)){ continue; }
//该号下延时客服
Map<Integer,List<CustomerDelayItemVO>> delaySortMap = customerMap.get(appid);
//所有的用户
Map<String,CustomerDelayPublish> userPublishMap = userEntry.getValue();
//去重
List<CustomerDelayPublish> userList = new ArrayList<>(userPublishMap.values()) ;
if (delaySortMap!=null&&!delaySortMap.isEmpty()){
//将所有待用延时客服收集
for (CustomerDelayPublish userPublish : userList) {
//发送延时客服
futureList.add(weChatService.sendCustomerDelayMessage(authorizerToken, userPublish, delaySortMap,needUpdateCustomerDelay)) ;
try {
if (!allPostUser.isEmpty()){
//号-用户
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);
if (allDelayCustomerMessage!=null&&!allDelayCustomerMessage.isEmpty()){
List<Future<CustomerDelayPublish>>futureList =new ArrayList<>();
//号-发送序列-客服id
Map<String, Map<Integer, List<CustomerDelayItemVO>>> customerMap =
allDelayCustomerMessage.stream().collect(Collectors.groupingBy(CustomerDelayItemVO::getAppId,
Collectors.groupingBy(CustomerDelayItemVO::getPostSort)));
Set<CustomerDelayItemVO> needUpdateCustomerDelay = new HashSet<>();
for (Map.Entry<String, Map<String,CustomerDelayPublish>> userEntry : userMap.entrySet()) {
String appid = userEntry.getKey();
//获取该号token
AuthorizerToken authorizerToken = authorizerTokenService.findTokenByAppid(appid);
String token = authorizerToken.getAuthorizerAppid();
//没token过滤
if (token==null||"".equals(token)){ continue; }
//该号下延时客服
Map<Integer,List<CustomerDelayItemVO>> delaySortMap = customerMap.get(appid);
//所有的用户
Map<String,CustomerDelayPublish> userPublishMap = userEntry.getValue();
//去重
List<CustomerDelayPublish> userList = new ArrayList<>(userPublishMap.values()) ;
if (delaySortMap!=null&&!delaySortMap.isEmpty()){
//将所有待用延时客服收集
for (CustomerDelayPublish userPublish : userList) {
//发送延时客服
futureList.add(weChatService.sendCustomerDelayMessage(authorizerToken, userPublish, delaySortMap,needUpdateCustomerDelay)) ;
}
}
}
}
List<CustomerDelayPublish> registerUserEntities = new ArrayList<>();
//更新下次延时排期
for (Future<CustomerDelayPublish> delayPublishFuture : futureList) {
try {
List<CustomerDelayPublish> registerUserEntities = new ArrayList<>();
//更新下次延时排期
for (Future<CustomerDelayPublish> delayPublishFuture : futureList) {
registerUserEntities.add(delayPublishFuture.get()) ;
}
if (!registerUserEntities.isEmpty()){
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
updateBatchById(registerUserEntities);
}
}
if (!registerUserEntities.isEmpty()){
//更新延时客服的发送人数数据
if (!needUpdateCustomerDelay.isEmpty()){
updateBatchById(registerUserEntities);
customerGraphicsDelayService.updateSendNumById(needUpdateCustomerDelay);
}
}
//更新延时客服的发送人数数据
if (!needUpdateCustomerDelay.isEmpty()){
customerGraphicsDelayService.updateSendNumById(needUpdateCustomerDelay);
}
}
} catch (Exception e) {
localLog.error("发生异常: {}, 位置: {}", e.getMessage(), e.getStackTrace()[0]);
}
}
}
......@@ -8,6 +8,7 @@ import com.yaoyaozw.customer.entity.CustomerDelayPublish;
import com.yaoyaozw.customer.entity.CustomerGraphics;
import com.yaoyaozw.customer.service.AuthorizerTokenService;
import com.yaoyaozw.customer.service.ReferralEntityService;
import com.yaoyaozw.customer.service.impl.CustomerDelayPublishServiceImpl;
import com.yaoyaozw.customer.service.wechat.entity.WeChatResponseEntity;
import com.yaoyaozw.customer.service.wechat.entity.customerRequest.CustomerNewsArticleItem;
import com.yaoyaozw.customer.service.wechat.entity.customerRequest.CustomerNewsItem;
......@@ -15,6 +16,8 @@ import com.yaoyaozw.customer.service.wechat.entity.customerRequest.WeChatCustome
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import com.yaoyaozw.customer.vo.customer.CustomerDelayItemVO;
import com.yaoyaozw.customer.vo.referral.ReferralEntityVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
......@@ -30,6 +33,8 @@ import java.util.stream.Collectors;
@Service
public class WeChatServiceImpl implements WeChatService{
private final static Logger localLog = LoggerFactory.getLogger(WeChatServiceImpl.class);
private String customerPath="https://api.weixin.qq.com/cgi-bin/message/custom/send";
private static final String CUSTOMER_TEXT="text";
......@@ -100,7 +105,7 @@ public class WeChatServiceImpl implements WeChatService{
return sendCustomerDelayMessage(updateToken,user,delaySortMap,needUpdateVoList);
}
} catch (Exception e) {
e.printStackTrace();
localLog.error("发生异常: {}, 位置: {}", e.getMessage(), e.getStackTrace()[0]);
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论