小班进入考试周修改
优惠券修改
This commit is contained in:
@@ -13,6 +13,7 @@ import com.peanut.modules.master.service.CourseService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -58,6 +59,8 @@ public class CouponController {
|
|||||||
Page<CouponEntity> couponPage = couponService.page(new Page<>(page, limit), wrapper);
|
Page<CouponEntity> couponPage = couponService.page(new Page<>(page, limit), wrapper);
|
||||||
for (CouponEntity couponEntity : couponPage.getRecords()) {
|
for (CouponEntity couponEntity : couponPage.getRecords()) {
|
||||||
couponService.setRangeList(couponEntity);
|
couponService.setRangeList(couponEntity);
|
||||||
|
couponEntity.setGrantCount(couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||||
|
.eq(CouponHistory::getCouponId,couponEntity.getId())));
|
||||||
}
|
}
|
||||||
return R.ok().put("couponPage",couponPage);
|
return R.ok().put("couponPage",couponPage);
|
||||||
}
|
}
|
||||||
@@ -122,21 +125,13 @@ public class CouponController {
|
|||||||
//修改优惠劵
|
//修改优惠劵
|
||||||
@RequestMapping("/updateCoupon")
|
@RequestMapping("/updateCoupon")
|
||||||
public R updateCoupon(@RequestBody CouponEntity couponEntity){
|
public R updateCoupon(@RequestBody CouponEntity couponEntity){
|
||||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
|
||||||
.eq(CouponHistory::getCouponId,couponEntity.getId()));
|
|
||||||
if (count>0){
|
|
||||||
return R.error("已有用户拥有优惠券");
|
|
||||||
}
|
|
||||||
CouponEntity c = couponService.getById(couponEntity.getId());
|
|
||||||
if (c.getCurrentState()==0){
|
|
||||||
return R.error("优惠券发放中,请先结束再修改");
|
|
||||||
}
|
|
||||||
couponService.updateById(couponEntity);
|
couponService.updateById(couponEntity);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除优惠劵
|
//删除优惠劵
|
||||||
@RequestMapping("/delCoupon")
|
@RequestMapping("/delCoupon")
|
||||||
|
@Transactional
|
||||||
public R delCoupon(@RequestBody Map<String,Object> params){
|
public R delCoupon(@RequestBody Map<String,Object> params){
|
||||||
int couponId = Integer.parseInt(params.get("id").toString());
|
int couponId = Integer.parseInt(params.get("id").toString());
|
||||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||||
@@ -149,6 +144,12 @@ public class CouponController {
|
|||||||
return R.error("优惠券发放中,请先结束再删除");
|
return R.error("优惠券发放中,请先结束再删除");
|
||||||
}
|
}
|
||||||
couponService.removeById(couponId);
|
couponService.removeById(couponId);
|
||||||
|
//删除优惠券商品绑定
|
||||||
|
List<CouponToProduct> ctps = couponToProductService.list(new LambdaQueryWrapper<CouponToProduct>()
|
||||||
|
.eq(CouponToProduct::getCouponId,couponId));
|
||||||
|
for (CouponToProduct ctp:ctps){
|
||||||
|
couponToProductService.removeById(ctp.getId());
|
||||||
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public class CouponEntity {
|
|||||||
@TableLogic
|
@TableLogic
|
||||||
private Integer delFlag;
|
private Integer delFlag;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private int grantCount;
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<Object> rangeList;
|
private List<Object> rangeList;
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
|
|||||||
@@ -333,15 +333,6 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
|||||||
Date startTime = new Date();
|
Date startTime = new Date();
|
||||||
classEntity.setStartTime(startTime);
|
classEntity.setStartTime(startTime);
|
||||||
this.getBaseMapper().updateById(classEntity);
|
this.getBaseMapper().updateById(classEntity);
|
||||||
if (classModel.getIsExam()==1){
|
|
||||||
//根据设置的天数将班级状态从进行中设置成考试中
|
|
||||||
rabbitTemplate.convertAndSend(
|
|
||||||
DelayQueueConfig.COMMON_EXCHANGE,
|
|
||||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
|
||||||
"examDays"+","+classEntity.getId(),
|
|
||||||
messagePostProcessor((classModel.getDays()-classModel.getExamDays())*24*60*60*1000)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,44 +72,39 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
@Override
|
@Override
|
||||||
public R insertCouponHistory(int couponId, int userId,int getType,String remark) {
|
public R insertCouponHistory(int couponId, int userId,int getType,String remark) {
|
||||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
CouponEntity couponEntity = couponDao.selectById(couponId);
|
||||||
int historyCount = couponHistoryDao.selectCount(new LambdaQueryWrapper<CouponHistory>()
|
if (couponEntity.getCurrentState()==0){
|
||||||
.eq(CouponHistory::getCouponId,couponId));
|
int historyCount = couponHistoryDao.selectCount(new LambdaQueryWrapper<CouponHistory>()
|
||||||
//是否超出总发行量
|
|
||||||
if (historyCount<couponEntity.getTotalCirculation()){
|
|
||||||
List<CouponHistory> historyList = couponHistoryDao.selectList(new LambdaQueryWrapper<CouponHistory>()
|
|
||||||
.eq(CouponHistory::getUserId,userId)
|
|
||||||
.eq(CouponHistory::getCouponId,couponId));
|
.eq(CouponHistory::getCouponId,couponId));
|
||||||
//是否超出可持有张数
|
//是否超出总发行量
|
||||||
if (historyList.size()<couponEntity.getLimitedCollar()){
|
if (historyCount<couponEntity.getTotalCirculation()){
|
||||||
CouponHistory couponHistory = new CouponHistory();
|
List<CouponHistory> historyList = couponHistoryDao.selectList(new LambdaQueryWrapper<CouponHistory>()
|
||||||
couponHistory.setCouponId(couponId);
|
.eq(CouponHistory::getUserId,userId)
|
||||||
couponHistory.setUserId(userId);
|
.eq(CouponHistory::getCouponId,couponId));
|
||||||
couponHistory.setGetType(getType);
|
//是否超出可持有张数
|
||||||
couponHistory.setRemark(remark);
|
if (historyList.size()<couponEntity.getLimitedCollar()){
|
||||||
couponHistory.setEffectType(couponEntity.getEffectType());
|
CouponHistory couponHistory = new CouponHistory();
|
||||||
if (couponEntity.getEffectType()==1){
|
couponHistory.setCouponId(couponId);
|
||||||
couponHistory.setStartTime(new Date());
|
couponHistory.setUserId(userId);
|
||||||
couponHistory.setEndTime(DateUtils.addDateDays(new Date(),couponEntity.getValidity()));
|
couponHistory.setGetType(getType);
|
||||||
}else if (couponEntity.getEffectType()==2){
|
couponHistory.setRemark(remark);
|
||||||
couponHistory.setStartTime(couponEntity.getEffectTime());
|
couponHistory.setEffectType(couponEntity.getEffectType());
|
||||||
couponHistory.setEndTime(couponEntity.getExpireTime());
|
if (couponEntity.getEffectType()==1){
|
||||||
|
couponHistory.setStartTime(new Date());
|
||||||
|
couponHistory.setEndTime(DateUtils.addDateDays(new Date(),couponEntity.getValidity()));
|
||||||
|
}else if (couponEntity.getEffectType()==2){
|
||||||
|
couponHistory.setStartTime(couponEntity.getEffectTime());
|
||||||
|
couponHistory.setEndTime(couponEntity.getExpireTime());
|
||||||
|
}
|
||||||
|
couponHistoryDao.insert(couponHistory);
|
||||||
|
return R.ok();
|
||||||
|
}else {
|
||||||
|
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
||||||
}
|
}
|
||||||
couponHistoryDao.insert(couponHistory);
|
|
||||||
if (couponEntity.getEffectType()!=0){
|
|
||||||
//发放完优惠卷设置过期
|
|
||||||
rabbitTemplate.convertAndSend(
|
|
||||||
DelayQueueConfig.COMMON_EXCHANGE,
|
|
||||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
|
||||||
"couponExpire"+","+couponHistory.getId(),
|
|
||||||
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return R.ok();
|
|
||||||
}else {
|
}else {
|
||||||
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
return R.error("优惠券已放完");
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
return R.error("优惠券已放完");
|
return R.error("优惠券暂未开始发放");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private MessagePostProcessor messagePostProcessor(long date) {
|
private MessagePostProcessor messagePostProcessor(long date) {
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.peanut.modules.job.task;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.peanut.common.utils.DateUtils;
|
||||||
|
import com.peanut.config.DelayQueueConfig;
|
||||||
|
import com.peanut.modules.common.dao.ClassEntityDao;
|
||||||
|
import com.peanut.modules.common.dao.ClassModelDao;
|
||||||
|
import com.peanut.modules.common.entity.ClassEntity;
|
||||||
|
import com.peanut.modules.common.entity.ClassModel;
|
||||||
|
import org.springframework.amqp.AmqpException;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.core.MessagePostProcessor;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component("classToExamTask")
|
||||||
|
public class ClassToExamTask implements ITask{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ClassEntityDao classEntityDao;
|
||||||
|
@Autowired
|
||||||
|
private ClassModelDao classModelDao;
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String params) {
|
||||||
|
List<ClassEntity> classEntities = classEntityDao.selectList(new MPJLambdaWrapper<ClassEntity>()
|
||||||
|
.leftJoin(ClassModel.class,ClassModel::getId,ClassEntity::getModelId)
|
||||||
|
.selectAll(ClassEntity.class)
|
||||||
|
.eq(ClassModel::getIsExam,1)
|
||||||
|
.eq(ClassEntity::getState,1));
|
||||||
|
for (ClassEntity classEntity : classEntities) {
|
||||||
|
ClassModel classModel = classModelDao.selectById(classEntity.getModelId());
|
||||||
|
int studyDays = classModel.getDays()-classModel.getExamDays();
|
||||||
|
//考试周开始时间
|
||||||
|
Date startExamTime = DateUtils.addDateDays(classEntity.getStartTime(),studyDays);
|
||||||
|
if (startExamTime.getTime()<=new Date().getTime()){//已到考试周,调整小班状态为考试周
|
||||||
|
classEntity.setState("3");
|
||||||
|
classEntityDao.updateById(classEntity);
|
||||||
|
}else if (DateUtils.format(startExamTime).equals(DateUtils.format(new Date()))){
|
||||||
|
//当天与考试周到达天相同,加入队列
|
||||||
|
if (classModel.getIsExam()==1){
|
||||||
|
//根据设置的天数将班级状态从进行中设置成考试中
|
||||||
|
rabbitTemplate.convertAndSend(
|
||||||
|
DelayQueueConfig.COMMON_EXCHANGE,
|
||||||
|
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||||
|
"examDays" + "," + classEntity.getId(),
|
||||||
|
new MessagePostProcessor() {
|
||||||
|
@Override
|
||||||
|
public Message postProcessMessage(Message message) throws AmqpException {
|
||||||
|
message.getMessageProperties().setDelay((int)(startExamTime.getTime()-new Date().getTime()));
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.peanut.modules.job.task;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.peanut.common.utils.DateUtils;
|
||||||
|
import com.peanut.config.DelayQueueConfig;
|
||||||
|
import com.peanut.modules.common.dao.CouponDao;
|
||||||
|
import com.peanut.modules.common.dao.CouponHistoryDao;
|
||||||
|
import com.peanut.modules.common.entity.CouponEntity;
|
||||||
|
import com.peanut.modules.common.entity.CouponHistory;
|
||||||
|
import org.springframework.amqp.AmqpException;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.core.MessagePostProcessor;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component("couponEffectTask")
|
||||||
|
public class CouponEffectTask implements ITask{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CouponHistoryDao couponHistoryDao;
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String params) {
|
||||||
|
List<CouponHistory> classEntities = couponHistoryDao.selectList(new LambdaQueryWrapper<CouponHistory>()
|
||||||
|
.eq(CouponHistory::getStatus,0)
|
||||||
|
.ne(CouponHistory::getEffectType,0));
|
||||||
|
for (CouponHistory couponHistory : classEntities) {
|
||||||
|
Date endTime = couponHistory.getEndTime();
|
||||||
|
if (endTime.getTime()<=new Date().getTime()){
|
||||||
|
//优惠券到期
|
||||||
|
couponHistory.setStatus(2);
|
||||||
|
couponHistoryDao.updateById(couponHistory);
|
||||||
|
}else if (DateUtils.format(endTime).equals(DateUtils.format(new Date()))) {
|
||||||
|
//优惠券到期时间是当天
|
||||||
|
rabbitTemplate.convertAndSend(
|
||||||
|
DelayQueueConfig.COMMON_EXCHANGE,
|
||||||
|
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||||
|
"couponExpire"+","+couponHistory.getId(),
|
||||||
|
new MessagePostProcessor() {
|
||||||
|
@Override
|
||||||
|
public Message postProcessMessage(Message message) throws AmqpException {
|
||||||
|
message.getMessageProperties().setDelay((int)(endTime.getTime()-new Date().getTime()));
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user