Commit 8ea975a9 authored by shiyu's avatar shiyu

订阅消息

parent 929298f7
......@@ -45,7 +45,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
"/wx/returnOrder/**", "/wx/distributionOrder/confirmSigned", "/wx/distributionOrder/delivery", "/wx/distributionOrder/cancel",
"/wx/distributionOrder/refund",
"/wx/supplierItem/findItemsOfCurrentDistributor", "/wx/selfPage/updateSwitch", "/wx/supplierItem/findHomePage",
"/wx/specialPerformance/sendMsg"
"/wx/specialPerformance/sendMsg", "/wx/specialPerformance/sendMsgTest"
//下列路径上线注释
/*,"/wx/specialPerformance/**"
, "/wx/supplierItem/**", "/wx/shareRecord/**", "/wx/distributionOrder/**", "/wx/selfPage/**", "/wx/auctionRecord/**",
......
......@@ -6,8 +6,10 @@ import com.wwdz.ch.core.consts.AuctionEnum;
import com.wwdz.ch.core.consts.DisposableSubscribeRecordEnum;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.SpecialPerformanceEnum;
import com.wwdz.ch.core.entity.AuctionOfferNoticeMsg;
import com.wwdz.ch.core.entity.SupplierItemVo;
import com.wwdz.ch.core.notify.AliSmsSender;
import com.wwdz.ch.core.service.SendMsgService;
import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.MediaUtil;
......@@ -78,6 +80,9 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
@Autowired
SpecialPerformanceItemFollowDao specialPerformanceItemFollowDao;
@Autowired
SendMsgService sendMsgService;
private final static String SPECIAL_PERFORMANCE_URL = "/pages/saleSpecialList/index";
private final static String SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY = "SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY:";
......@@ -510,6 +515,72 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
}
return Result.failed();
}
@Override
public void sendMsgTest() {
SpecialPerformanceRequestDto specialPerformanceRequestDto = new SpecialPerformanceRequestDto();
specialPerformanceRequestDto.setState(SpecialPerformanceEnum.StateEnum.PREVIEW.getCode());
Date now = new Date();
Instant startInstant = now.toInstant().plus(Duration.ofMinutes(20));
Date startTime = Date.from(startInstant);
specialPerformanceRequestDto.setStartQueryTime(startTime);
specialPerformanceRequestDto.setEndQueryTime(now);
List<SpecialPerformance> specialPerformanceList = specialPerformanceDao.find(specialPerformanceRequestDto);
logger.info("test------------------ 即将开始的专场个数为 {}", specialPerformanceList.size());
if (CollectionUtils.isEmpty(specialPerformanceList)) {
return;
}
SpecialPerformance specialPerformance = specialPerformanceList.get(0);
logger.info("当前即将开始的专场id:{}, 名称为 {} ", specialPerformance.getId(), specialPerformance.getTitle());
//发送专场开始订阅通知
DisposableSubscribeRecordRequestDto disposableSubscribeRecordRequestDto = new DisposableSubscribeRecordRequestDto();
disposableSubscribeRecordRequestDto.setTargetId(Long.valueOf(specialPerformance.getId()));
disposableSubscribeRecordRequestDto.setType(DisposableSubscribeRecordEnum.TypeEnum.PRE_START.getType());
boolean hasNextPage = true;
int page = 1;
String url = wxAppletApi.getUrlLink(SPECIAL_PERFORMANCE_URL,"specialId=" + specialPerformance.getId());
String msg = specialPerformance.getTitle() + "将在" + DateUtils.toString(specialPerformance.getStartTime()) + "开始,请前往"+ url + "查看";
while (hasNextPage) {
List<DisposableSubscribeRecord> disposableSubscribeRecordList = disposableSubscribeRecordDao.findList(disposableSubscribeRecordRequestDto);
PageInfo pageInfo = new PageInfo(disposableSubscribeRecordList);
for (DisposableSubscribeRecord disposableSubscribeRecord : disposableSubscribeRecordList) {
sendStartSubscribeMsg(specialPerformance, disposableSubscribeRecord, msg);
}
if (pageInfo.isHasNextPage()) {
page = page + 1;
disposableSubscribeRecordRequestDto.setPage(page);
logger.info("要发送专场开始订阅消息的用户数据总页数为 : {}, 当前为 : {}", pageInfo.getPages(), page);
} else {
logger.info("============= 发送专场开始订阅消息循环结束 =============");
break;
}
}
logger.info("================专场id: {}, 即将开始通知消息全部发送成功 ==============", specialPerformance.getId());
}
private void sendStartSubscribeMsg(SpecialPerformance specialPerformance, DisposableSubscribeRecord disposableSubscribeRecord, String msg){
AuctionOfferNoticeMsg auctionOfferNoticeMsg = new AuctionOfferNoticeMsg();
auctionOfferNoticeMsg.setSpecialPerformanceTitle(specialPerformance.getTitle());
auctionOfferNoticeMsg.setSpecialPerformanceStartTime(DateUtils.toString(specialPerformance.getStartTime()));
auctionOfferNoticeMsg.setOpenId(disposableSubscribeRecord.getOpenid());
auctionOfferNoticeMsg.setSpecialId(specialPerformance.getId());
Result result = sendMsgService.sendSpecialPerformanceStartMsg(auctionOfferNoticeMsg);
if (!result.getSuccess()) {
String errorCode = JsonUtils.getValueByPath(result.getData().toString(), "errcode");
//用户为订阅消息,43101用户未订阅消息;43108并发下发消息给同一个粉丝,这两种情况表示用户不需要被通知
if (!"43101".equals(errorCode) && !"43108".equals(errorCode)) {
//发订阅消息送失败发短信
long userId = disposableSubscribeRecord.getUserId();
aliSmsSender.sendSms(userId, msg);
}
}
//订阅状态改为无效
disposableSubscribeRecordDao.updateInvalid(disposableSubscribeRecord.getOpenid(), disposableSubscribeRecord.getTargetId(), disposableSubscribeRecord.getTemplateId());
}
}
......@@ -43,6 +43,7 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
......@@ -125,7 +126,7 @@ public class SpecialPerformanceNoticeJob {
} finally {
if (lock != null && lock.isHeldByCurrentThread()) {
lock.unlock();
logger.info("======================== 线程id: {} ,专场即将开始通知任务执行结束, 释放锁成功 ========================", Thread.currentThread().getId());
logger.info("======================== 线程id: {} ,专场通知任务执行结束, 释放锁成功 ========================", Thread.currentThread().getId());
}
}
}
......@@ -164,7 +165,7 @@ public class SpecialPerformanceNoticeJob {
List<DisposableSubscribeRecord> disposableSubscribeRecordList = disposableSubscribeRecordDao.findList(disposableSubscribeRecordRequestDto);
PageInfo pageInfo = new PageInfo(disposableSubscribeRecordList);
for (DisposableSubscribeRecord disposableSubscribeRecord : disposableSubscribeRecordList) {
sendSubscribeMsg(specialPerformance, disposableSubscribeRecord, msg);
sendStartSubscribeMsg(specialPerformance, disposableSubscribeRecord, msg);
}
if (pageInfo.isHasNextPage()) {
page = page + 1;
......@@ -218,7 +219,7 @@ public class SpecialPerformanceNoticeJob {
List<DisposableSubscribeRecord> disposableSubscribeRecordList = disposableSubscribeRecordDao.findList(disposableSubscribeRecordRequestDto);
PageInfo pageInfo = new PageInfo(disposableSubscribeRecordList);
for (DisposableSubscribeRecord disposableSubscribeRecord : disposableSubscribeRecordList) {
sendSubscribeMsg(specialPerformance, disposableSubscribeRecord, msg);
sendEndSubscribeMsg(specialPerformance, disposableSubscribeRecord, msg);
}
if (pageInfo.isHasNextPage()) {
page = page + 1;
......@@ -237,11 +238,12 @@ public class SpecialPerformanceNoticeJob {
}
private void sendSubscribeMsg(SpecialPerformance specialPerformance, DisposableSubscribeRecord disposableSubscribeRecord, String msg){
private void sendStartSubscribeMsg(SpecialPerformance specialPerformance, DisposableSubscribeRecord disposableSubscribeRecord, String msg){
AuctionOfferNoticeMsg auctionOfferNoticeMsg = new AuctionOfferNoticeMsg();
auctionOfferNoticeMsg.setSpecialPerformanceTitle(specialPerformance.getTitle());
auctionOfferNoticeMsg.setSpecialPerformanceStartTime(DateUtils.toString(specialPerformance.getStartTime()));
auctionOfferNoticeMsg.setOpenId(disposableSubscribeRecord.getOpenid());
auctionOfferNoticeMsg.setSpecialId(specialPerformance.getId());
Result result = sendMsgService.sendSpecialPerformanceStartMsg(auctionOfferNoticeMsg);
if (!result.getSuccess()) {
String errorCode = JsonUtils.getValueByPath(result.getData().toString(), "errcode");
......@@ -257,6 +259,33 @@ public class SpecialPerformanceNoticeJob {
}
private void sendEndSubscribeMsg(SpecialPerformance specialPerformance, DisposableSubscribeRecord disposableSubscribeRecord, String msg){
AuctionOfferNoticeMsg auctionOfferNoticeMsg = new AuctionOfferNoticeMsg();
auctionOfferNoticeMsg.setSpecialPerformanceTitle(specialPerformance.getTitle());
auctionOfferNoticeMsg.setSpecialPerformanceStartTime(DateUtils.toString(specialPerformance.getStartTime()));
auctionOfferNoticeMsg.setSpecialPerformanceEndTime(DateUtils.toString(specialPerformance.getEndTime()));
Date now = new Date();
long minutes = specialPerformance.getEndTime().getTime() - now.getTime();
long surplusMinutes = TimeUnit.MINUTES.convert(minutes, TimeUnit.MILLISECONDS);
auctionOfferNoticeMsg.setSpecialPerformanceSurplusTime("距离专场结束还有" + surplusMinutes + "分钟");
auctionOfferNoticeMsg.setOpenId(disposableSubscribeRecord.getOpenid());
auctionOfferNoticeMsg.setSpecialId(specialPerformance.getId());
Result result = sendMsgService.sendSpecialPerformanceEndMsg(auctionOfferNoticeMsg);
if (!result.getSuccess()) {
String errorCode = JsonUtils.getValueByPath(result.getData().toString(), "errcode");
//用户为订阅消息,43101用户未订阅消息;43108并发下发消息给同一个粉丝,这两种情况表示用户不需要被通知
if (!"43101".equals(errorCode) && !"43108".equals(errorCode)) {
//发订阅消息送失败发短信
long userId = disposableSubscribeRecord.getUserId();
aliSmsSender.sendSms(userId, msg);
}
}
//订阅状态改为无效
disposableSubscribeRecordDao.updateInvalid(disposableSubscribeRecord.getOpenid(), disposableSubscribeRecord.getTargetId(), disposableSubscribeRecord.getTemplateId());
}
/**
......
......@@ -33,5 +33,7 @@ public interface SpecialPerformanceService {
*/
Result sendMsg();
void sendMsgTest();
}
......@@ -86,5 +86,19 @@ public class SpecialPerformanceController {
}
@ApiOperation(value = "发送专场订阅消息测试")
@GetMapping("/sendMsgTest")
public Result sendMsgTest() {
logger.info(">>>>>>>>>>> 发送专场订阅消息测试 <<<<<<<<<<<<<");
try {
specialPerformanceService.sendMsgTest();
return Result.success();
} catch (Exception e) {
logger.info("发送专场订阅消息测试 error :{}", e);
}
return Result.failed();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment