提交 2c7e25f2 作者: 沈振路

Merge remote-tracking branch 'origin/master'

......@@ -63,8 +63,9 @@ public class SchedulingTask {
}
/**
* 更新付费用户近一月平均充值(每天一次)
* 更新付费用户近一月平均充值(每天一次:4点10分
*/
@Scheduled(cron = "0 10 4 * * *")
public void retrieveMonthOrder(){
Calendar calendar = Calendar.getInstance();
......@@ -85,6 +86,7 @@ public class SchedulingTask {
/**
* 每10min扫描一次正常客服
*/
@Scheduled(cron = "0 0/10 * * * *")
public void publishCustomerMessage(){
Calendar calendar = Calendar.getInstance();
......
package com.yaoyaozw.customer.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.entity.RegisterUserEntity;
......@@ -43,6 +44,7 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
Map<String, List<AccountOrder>> userOrderMap = runtimeOrders.stream().collect(Collectors.groupingBy(AccountOrder::getOpenId));
Calendar instance = Calendar.getInstance();
if (!openIdSet.isEmpty()){
//获取注册用户信息
List<RegisterUserEntity> userList = registerUserEntityService.list(new QueryWrapper<RegisterUserEntity>().in(RegisterUserEntity.COL_OPEN_ID, openIdSet));
......@@ -63,8 +65,11 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
Double sum=registerUser.getPayAmount()!=null?registerUser.getPayAmount():0;
for (AccountOrder accountOrder : accountOrders) {
//下单时间推5min
instance.setTime(accountOrder.getFinishTime());
instance.add(Calendar.MINUTE,5);
//最近活跃时间
lastFinishTime = (lastFinishTime != null && lastFinishTime.compareTo(accountOrder.getFinishTime()) > 0) ? lastFinishTime : accountOrder.getFinishTime();
lastFinishTime = (lastFinishTime != null && lastFinishTime.compareTo(accountOrder.getFinishTime()) > 0) ? lastFinishTime : instance.getTime();
//最大类型
type = Math.max(accountOrder.getType() + 1, type);
sum += accountOrder.getProfit();
......@@ -96,18 +101,21 @@ public class AccountOrderServiceImpl extends ServiceImpl<AccountOrderMapper, Acc
public void calculateAvgMonth(IntegrationRequestDTO integrationRequestDTO) {
//获取近一月每个用户的平均充值
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(!userAvgAmountVos.isEmpty()){
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()){
if (userList!=null&&!userList.isEmpty()){
for (RegisterUserEntity registerUserEntity : userList) {
for (RegisterUserEntity registerUserEntity : userList) {
registerUserEntity.setAvgMonth(userAvgAmountMap.get(registerUserEntity.getOpenId()));
registerUserEntity.setAvgMonth(userAvgAmountMap.get(registerUserEntity.getOpenId()));
}
}
registerUserEntityService.updateBatchById(userList);
}
registerUserEntityService.updateBatchById(userList);
}
......
......@@ -6,6 +6,7 @@ import com.yaoyaozw.customer.entity.AuthorizerToken;
import com.yaoyaozw.customer.service.AuthorizerTokenService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......
......@@ -221,39 +221,41 @@ public class CustomerGraphicsServiceImpl extends ServiceImpl<CustomerGraphicsMap
List<CustomerGraphics> customerGraphicsList = list(new QueryWrapper<CustomerGraphics>().eq(CustomerGraphics.COL_POST_TIME, requestDate).eq(CustomerGraphics.COL_SEND_STATUS,9));
for (CustomerGraphics customerGraphics : customerGraphicsList) {
//人群包id
Long packId = customerGraphics.getPackId();
//根据人群包找人,并按appId分组
List<CrowdPackageUserVO> userList = registerUserEntityService.getCurrentInPackUserList(packId, false);
//去重
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分组
List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId());
Map<String, List<ReferralEntityVo>> referralMap = referralList.stream().collect(Collectors.groupingBy(ReferralEntityVo::getAppid));
//循环该客服下的所有素材
for (Map.Entry<String, List<ReferralEntityVo>> referralEntry : referralMap.entrySet()) {
String appid = referralEntry.getKey();
//获取token
AuthorizerToken authorizerToken = authorizerTokenService.findTokenByAppid(appid);
if (authorizerToken!=null&&authorizerToken.getAuthorizerAccessToken()!=null){
//获取该号的链接实体
List<ReferralEntityVo> referralEntityVo = referralMap.get(appid);
//获取该号的openid
List<CrowdPackageUserVO> packageUserVo = appidUserMap.get(appid);
if (referralEntityVo!=null&&!referralEntityVo.isEmpty()){
weChatService.sendCustomerMessage(appid,authorizerToken,customerGraphics,packageUserVo,referralEntityVo);
if(!customerGraphicsList.isEmpty()){
for (CustomerGraphics customerGraphics : customerGraphicsList) {
//人群包id
Long packId = customerGraphics.getPackId();
//根据人群包找人,并按appId分组
List<CrowdPackageUserVO> userList = registerUserEntityService.getCurrentInPackUserList(packId, false);
//去重
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分组
List<ReferralEntityVo> referralList = referralEntityService.findReferralByCustomerGraphicsId(customerGraphics.getId());
Map<String, List<ReferralEntityVo>> referralMap = referralList.stream().collect(Collectors.groupingBy(ReferralEntityVo::getAppid));
//循环该客服下的所有素材
for (Map.Entry<String, List<ReferralEntityVo>> referralEntry : referralMap.entrySet()) {
String appid = referralEntry.getKey();
//获取token
AuthorizerToken authorizerToken = authorizerTokenService.findTokenByAppid(appid);
if (authorizerToken!=null&&authorizerToken.getAuthorizerAccessToken()!=null){
//获取该号的链接实体
List<ReferralEntityVo> referralEntityVo = referralMap.get(appid);
//获取该号的openid
List<CrowdPackageUserVO> packageUserVo = appidUserMap.get(appid);
if (referralEntityVo!=null&&!referralEntityVo.isEmpty()){
weChatService.sendCustomerMessage(appid,authorizerToken,customerGraphics,packageUserVo,referralEntityVo);
}
}
}
}
updateBatchById(customerGraphicsList);
}
updateBatchById(customerGraphicsList);
}
private BaseResult checkExtendBook(String storeType, CrowdPackageConditionMatch storeConditionMatch) {
......
......@@ -41,6 +41,8 @@ public class WeChatServiceImpl implements WeChatService{
private static final Integer EXPIRED_CODE=40001;
private static final Integer FORBID_Time=6;
private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(20, 100, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(2),new ThreadPoolExecutor.CallerRunsPolicy());
private final static Object CUSTOMER_LOCK=new Object();
......@@ -57,42 +59,48 @@ public class WeChatServiceImpl implements WeChatService{
public Future<CustomerDelayPublish> sendCustomerDelayMessage( AuthorizerToken authorizerToken, CustomerDelayPublish user,
Map<Integer,List<CustomerDelayItemVO>> delaySortMap,
Set<CustomerDelayItemVO> needUpdateVoList) {
//token
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(customerPath).queryParam("access_token",authorizerToken.getAuthorizerAccessToken());
//找到延时序列
List<CustomerDelayItemVO> sendCustomerDelays = delaySortMap.get(user.getCustomerSort());
//获取当前小时数
Calendar instance = Calendar.getInstance();
int i = instance.get(Calendar.HOUR_OF_DAY);
//早上0-6点不发
if (i<FORBID_Time){
//token
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(customerPath).queryParam("access_token",authorizerToken.getAuthorizerAccessToken());
//找到延时序列
List<CustomerDelayItemVO> sendCustomerDelays = delaySortMap.get(user.getCustomerSort());
if (sendCustomerDelays!=null){
//找付费类型
List<CustomerDelayItemVO> collect = sendCustomerDelays.stream().filter(a -> a.getIsPay().equals(-1)||user.getPayType().equals(a.getIsPay()) ).collect(Collectors.toList());
if (sendCustomerDelays!=null){
//找付费类型
List<CustomerDelayItemVO> collect = sendCustomerDelays.stream().filter(a -> a.getIsPay().equals(-1)||user.getPayType().equals(a.getIsPay()) ).collect(Collectors.toList());
if (!collect.isEmpty()){
if (!collect.isEmpty()){
CustomerDelayItemVO sendCustomerDelay = collect.get(0);
CustomerDelayItemVO sendCustomerDelay = collect.get(0);
needUpdateVoList.add(sendCustomerDelay);
//构建请求参数
WeChatCustomerRequestEntity customerRequest = buildCustomerRequest(sendCustomerDelay);
needUpdateVoList.add(sendCustomerDelay);
//构建请求参数
WeChatCustomerRequestEntity customerRequest = buildCustomerRequest(sendCustomerDelay);
if (customerRequest!=null){
if (customerRequest!=null){
customerRequest.setTouser(user.getOpenId());
//System.err.println(user.getOpenId());
try {
WeChatResponseEntity response=(WeChatResponseEntity)weChatRestService.httpPostRequest(uriComponentsBuilder, customerRequest,WeChatResponseEntity.class);
//System.err.println(response);
if(SUCCESS_CODE.equals(response.getErrcode())){
//发送成功计数
sendCustomerDelay.updateSendNum();
customerRequest.setTouser(user.getOpenId());
//System.err.println(user.getOpenId());
try {
WeChatResponseEntity response=(WeChatResponseEntity)weChatRestService.httpPostRequest(uriComponentsBuilder, customerRequest,WeChatResponseEntity.class);
//System.err.println(response);
if(SUCCESS_CODE.equals(response.getErrcode())){
//发送成功计数
sendCustomerDelay.updateSendNum();
}else if(EXPIRED_CODE.equals(response.getErrcode()) ){
//token过期重新取一下
AuthorizerToken updateToken = authorizerTokenService.findTokenByAppid(authorizerToken.getAuthorizerAppid());
}else if(EXPIRED_CODE.equals(response.getErrcode()) ){
//token过期重新取一下
AuthorizerToken updateToken = authorizerTokenService.findTokenByAppid(authorizerToken.getAuthorizerAppid());
return sendCustomerDelayMessage(updateToken,user,delaySortMap,needUpdateVoList);
return sendCustomerDelayMessage(updateToken,user,delaySortMap,needUpdateVoList);
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论