Commit 3045271a authored by shiyu's avatar shiyu

专场自动开始

parent 63c75396
...@@ -45,4 +45,8 @@ public class SpecialPerformanceRequestDto extends BaseRequestDto implements Enti ...@@ -45,4 +45,8 @@ public class SpecialPerformanceRequestDto extends BaseRequestDto implements Enti
* 状态 * 状态
*/ */
private Integer state; private Integer state;
private Date startQueryTime;
private Date endQueryTime;
} }
package com.wwdz.ch.db.impl.distribution; package com.wwdz.ch.db.impl.distribution;
import com.github.pagehelper.PageHelper;
import com.wwdz.ch.db.dao.distribution.SpecialPerformanceDao; import com.wwdz.ch.db.dao.distribution.SpecialPerformanceDao;
import com.wwdz.ch.db.domain.distribution.SpecialPerformance; import com.wwdz.ch.db.domain.distribution.SpecialPerformance;
import com.wwdz.ch.db.domain.distribution.SpecialPerformanceExample; import com.wwdz.ch.db.domain.distribution.SpecialPerformanceExample;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceRequestDto; import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceRequestDto;
import com.wwdz.ch.db.mapper.distribution.SpecialPerformanceMapper; import com.wwdz.ch.db.mapper.distribution.SpecialPerformanceMapper;
import com.xxdxxs.db.component.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -19,7 +21,14 @@ public class SpecialPerformanceDaoImpl implements SpecialPerformanceDao { ...@@ -19,7 +21,14 @@ public class SpecialPerformanceDaoImpl implements SpecialPerformanceDao {
@Override @Override
public List<SpecialPerformance> find(SpecialPerformanceRequestDto dto) { public List<SpecialPerformance> find(SpecialPerformanceRequestDto dto) {
return null; SpecialPerformanceExample example = new SpecialPerformanceExample();
SpecialPerformanceExample.Criteria criteria = example.createCriteria();
JdbcHelper.ifPresent(dto.getType(), criteria::andTypeEqualTo);
JdbcHelper.ifPresent(dto.getState(), criteria::andStateEqualTo);
JdbcHelper.ifPresent(dto.getStartQueryTime(), criteria::andStartTimeGreaterThanOrEqualTo);
example.setOrderByClause(" start_time desc");
PageHelper.startPage(dto.getPage(), dto.getLimit());
return specialPerformanceMapper.selectByExample(example);
} }
@Override @Override
......
...@@ -23,6 +23,8 @@ import org.springframework.stereotype.Service; ...@@ -23,6 +23,8 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -49,12 +51,27 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService ...@@ -49,12 +51,27 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
@Override @Override
public Result findInfo(SpecialPerformanceRequestDto dto) { public Result findInfo(SpecialPerformanceRequestDto dto) {
try { try {
Date now = new Date();
//到时自动开始,修改状态
SpecialPerformanceRequestDto specialPerformanceRequestDto = new SpecialPerformanceRequestDto();
specialPerformanceRequestDto.setState(DistributionEnum.AuctionStateEnum.NOT_START.getCode());
List<SpecialPerformance> specialPerformanceList = specialPerformanceDao.find(specialPerformanceRequestDto);
for (SpecialPerformance notStartSpecialPerformance : specialPerformanceList) {
if (now.after(notStartSpecialPerformance.getStartTime())) {
SpecialPerformance updateDto = new SpecialPerformance();
updateDto.setId(notStartSpecialPerformance.getId());
updateDto.setState(DistributionEnum.AuctionStateEnum.IN_AUCTION.getCode());
updateDto.setUpdateTime(now);
specialPerformanceDao.update(updateDto);
}
}
SpecialPerformanceVo specialPerformanceVo = new SpecialPerformanceVo(); SpecialPerformanceVo specialPerformanceVo = new SpecialPerformanceVo();
SpecialPerformance specialPerformance = specialPerformanceDao.findByType(dto.getType()); SpecialPerformance specialPerformance = specialPerformanceDao.findByType(dto.getType());
if (specialPerformance == null) { if (specialPerformance == null) {
return Result.success(specialPerformanceVo); return Result.success(specialPerformanceVo);
} }
Date now = new Date();
if (now.after(specialPerformance.getEndTime())) { if (now.after(specialPerformance.getEndTime())) {
SpecialPerformance updateDto = new SpecialPerformance(); SpecialPerformance updateDto = new SpecialPerformance();
updateDto.setId(specialPerformance.getId()); updateDto.setId(specialPerformance.getId());
...@@ -62,13 +79,6 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService ...@@ -62,13 +79,6 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
updateDto.setUpdateTime(now); updateDto.setUpdateTime(now);
specialPerformanceDao.update(updateDto); specialPerformanceDao.update(updateDto);
specialPerformance.setState(DistributionEnum.AuctionStateEnum.END.getCode()); specialPerformance.setState(DistributionEnum.AuctionStateEnum.END.getCode());
} else if (now.after(specialPerformance.getStartTime())) {
SpecialPerformance updateDto = new SpecialPerformance();
updateDto.setId(specialPerformance.getId());
updateDto.setState(DistributionEnum.AuctionStateEnum.IN_AUCTION.getCode());
updateDto.setUpdateTime(now);
specialPerformanceDao.update(updateDto);
specialPerformance.setState(DistributionEnum.AuctionStateEnum.IN_AUCTION.getCode());
} }
int specialPerformanceId = specialPerformance.getId(); int specialPerformanceId = specialPerformance.getId();
SpecialPerformanceConfigRequestDto specialPerformanceConfigRequestDto = new SpecialPerformanceConfigRequestDto(); SpecialPerformanceConfigRequestDto specialPerformanceConfigRequestDto = new SpecialPerformanceConfigRequestDto();
......
...@@ -161,11 +161,11 @@ public class AutoSendMsgJob { ...@@ -161,11 +161,11 @@ public class AutoSendMsgJob {
handleNotPayOrderList(secondStartTime, secondEndTime, 2); handleNotPayOrderList(secondStartTime, secondEndTime, 2);
} catch (Exception e) { } catch (Exception e) {
logger.error("同步item增量数据到ES error {}", e); logger.error("自动发送拍卖通知任务执行结束 error {}", e);
} finally { } finally {
if (lock != null && lock.isHeldByCurrentThread()) { if (lock != null && lock.isHeldByCurrentThread()) {
lock.unlock(); lock.unlock();
logger.info("======================== 线程id: {} ,自动发送拍卖通知任务执行结束, 释放锁成功 ========================", Thread.currentThread().getId()); logger.info("======================== 线程id: {} , 自动发送拍卖通知任务执行结束, 释放锁成功 ========================", Thread.currentThread().getId());
} }
} }
} }
......
package com.wwdz.ch.wx.job;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.entity.AuctionOfferNoticeMsg;
import com.wwdz.ch.core.notify.AliSmsSender;
import com.wwdz.ch.core.service.SendMsgService;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.core.util.StringUtil;
import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.domain.distribution.*;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceRequestDto;
import com.wwdz.ch.wx.service.distribution.DistributionOrderService;
import com.xxdxxs.utils.DateUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 发送模板信息
*/
@Component
public class SpecialPerformanceNoticeJob {
private static final Logger logger = LoggerFactory.getLogger(SpecialPerformanceNoticeJob.class);
private final static String SPECIAL_PERFORMANCE_SEND_MSG_KEY = "SPECIAL_PERFORMANCE_SEND_MSG_KEY";
//专场即将开始提醒,标识key
private final static String SPECIAL_PERFORMANCE_START_NOTICE_KEY = "SPECIALPERFORMANCE_START_NOTICE_KEY:";
@Autowired
SpecialPerformanceDao specialPerformanceDao;
@Autowired
RedissonClient redissonClient;
@Autowired
SendMsgService sendMsgService;
@Autowired
AliSmsSender aliSmsSender;
@Autowired
RedisUtils redisUtils;
@Autowired
WxAppletApi wxAppletApi;
private final static String SPECIAL_PERFORMANCE_URL = "/pages/saleSpecialList/index";
/**
* 隔10分钟运行一次
*/
// @Scheduled(fixedDelay = 1000 * 60 * 10)
public void execute() {
RLock lock = redissonClient.getLock(SPECIAL_PERFORMANCE_SEND_MSG_KEY);
if (!lock.tryLock()) {
logger.warn("专场即将开始通知任务,当前服务实例获取锁成功: {} 获取锁失败,锁被占用不执行", Thread.currentThread().getId());
return;
}
logger.info(">>>>>>>>>>>>>>>>>>>>>>> 专场即将开始通知任务,开始执行 <<<<<<<<<<<<<<<<<<<<<");
try {
SpecialPerformanceRequestDto specialPerformanceRequestDto = new SpecialPerformanceRequestDto();
specialPerformanceRequestDto.setState(DistributionEnum.AuctionStateEnum.NOT_START.getCode());
Date now = new Date();
Instant startInstant = now.toInstant().plus(Duration.ofMinutes(20));
Date startTime = Date.from(startInstant);
specialPerformanceRequestDto.setStartQueryTime(startTime);
List<SpecialPerformance> specialPerformanceList = specialPerformanceDao.find(specialPerformanceRequestDto);
logger.info("即将开始的专场个数为 {}", specialPerformanceList.size());
if (CollectionUtils.isEmpty(specialPerformanceList)) {
return;
}
SpecialPerformance specialPerformance = specialPerformanceList.get(0);
String abortStartKey = SPECIAL_PERFORMANCE_START_NOTICE_KEY + specialPerformance.getId();
if (!redisUtils.hasKey(abortStartKey)) {
logger.info("当前即将开始的专场id:{}, 名称为 {} ", specialPerformance.getId(), specialPerformance.getTitle());
//发送短信通知
String url = wxAppletApi.getUrlLink(SPECIAL_PERFORMANCE_URL,"specialId=" + specialPerformance.getId());
String msg = specialPerformance.getTitle() + "即将开始,请前往"+ url + "查看";
// aliSmsSender.sendSms(userId, msg);
logger.info("================专场id: {}, 即将开始通知任务,提醒短信发送成功 ==============", specialPerformance.getId());
redisUtils.set(abortStartKey, specialPerformance.getId(), 3600 * 24);
}
} catch (Exception e) {
logger.error("专场即将开始通知任务 error {}", e);
} finally {
if (lock != null && lock.isHeldByCurrentThread()) {
lock.unlock();
logger.info("======================== 线程id: {} ,专场即将开始通知任务执行结束, 释放锁成功 ========================", Thread.currentThread().getId());
}
}
}
}
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