Commit 29b7d1c5 by 吕明尚

修改查询集点活动

parent 6fa9214f
package share.web.controller.system;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.system.service.PointActivitiesService;
/**
* 用户集点活动Controller
*
* @author wuwenlong
* @date 2024-11-14
*/
@RestController
@RequestMapping("/pointActivities")
public class PointActivitiesController extends BaseController {
@Autowired
private PointActivitiesService pointActivitiesService;
/**
* 查询用户集点活动列表
*/
@GetMapping("/query")
public AjaxResult selectByConsumerId() {
return success(pointActivitiesService.selectByConsumerId());
}
@GetMapping("/receivePointActivities")
public AjaxResult receivePointActivities(Long id) {
return success(pointActivitiesService.receivePointActivities(id));
}
}
...@@ -55,8 +55,8 @@ public class PointActivities extends BaseEntity { ...@@ -55,8 +55,8 @@ public class PointActivities extends BaseEntity {
/** /**
* 上次消费时间 * 上次消费时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Excel(name = "上次消费时间", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "上次消费时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm")
private Date lastConsumptionTime; private Date lastConsumptionTime;
/** /**
...@@ -86,15 +86,15 @@ public class PointActivities extends BaseEntity { ...@@ -86,15 +86,15 @@ public class PointActivities extends BaseEntity {
/** /**
* 优惠券领取日期 * 优惠券领取日期
*/ */
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Excel(name = "优惠券领取日期", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "优惠券领取日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm")
private Date receivedDate; private Date receivedDate;
/** /**
* 优惠券过期日期 * 优惠券过期日期
*/ */
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Excel(name = "优惠券过期日期", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "优惠券过期日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm")
private Date couponExpirationDate; private Date couponExpirationDate;
/** /**
......
...@@ -64,5 +64,7 @@ public interface PointActivitiesService extends IService<PointActivities> { ...@@ -64,5 +64,7 @@ public interface PointActivitiesService extends IService<PointActivities> {
public void joinPointActivities(SOrder sOrder); public void joinPointActivities(SOrder sOrder);
public void receivePointActivities(Long id); public Integer receivePointActivities(Long id);
PointActivities selectByConsumerId();
} }
...@@ -140,7 +140,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC ...@@ -140,7 +140,7 @@ public class ConsumerMonthlyCardServiceImpl extends ServiceImpl<ConsumerMonthlyC
BigDecimal freeDuration = consumerWallet.getRemainingDuration(); BigDecimal freeDuration = consumerWallet.getRemainingDuration();
if (ObjectUtil.isNotEmpty(consumerMember)) { if (ObjectUtil.isNotEmpty(consumerMember)) {
SRoom room = roomService.getById(monthlyCardRequest.getRoomId()); SRoom room = roomService.getById(monthlyCardRequest.getRoomId());
consumerMonthlyCard = baseMapper.selectOne(new LambdaQueryWrapper<ConsumerMonthlyCard>().eq(ConsumerMonthlyCard::getConsumerId, user.getId()).gt(ConsumerMonthlyCard::getFreeDuration, 0)); consumerMonthlyCard = baseMapper.selectOne(new LambdaQueryWrapper<ConsumerMonthlyCard>().eq(ConsumerMonthlyCard::getConsumerId, user.getId()).ge(ConsumerMonthlyCard::getFreeDuration, 0));
consumerSecondaryCard = consumerSecondaryCardService.list(new LambdaQueryWrapper<ConsumerSecondaryCard>() consumerSecondaryCard = consumerSecondaryCardService.list(new LambdaQueryWrapper<ConsumerSecondaryCard>()
.eq(ConsumerSecondaryCard::getConsumerId, user.getId()) .eq(ConsumerSecondaryCard::getConsumerId, user.getId())
.gt(ConsumerSecondaryCard::getNumber, 0) .gt(ConsumerSecondaryCard::getNumber, 0)
......
...@@ -2,6 +2,7 @@ package share.system.service.impl; ...@@ -2,6 +2,7 @@ package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -19,6 +20,7 @@ import share.system.service.PointActivitiesService; ...@@ -19,6 +20,7 @@ import share.system.service.PointActivitiesService;
import share.system.service.SConsumerService; import share.system.service.SConsumerService;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -90,14 +92,31 @@ public class PointActivitiesServiceImpl extends ServiceImpl<PointActivitiesMappe ...@@ -90,14 +92,31 @@ public class PointActivitiesServiceImpl extends ServiceImpl<PointActivitiesMappe
public void joinPointActivities(SOrder sOrder) { public void joinPointActivities(SOrder sOrder) {
SConsumer user = sConsumerService.getInfo(); SConsumer user = sConsumerService.getInfo();
PointActivitiesConf pointActivitiesConf = pointActivitiesConfService.list().get(0); PointActivitiesConf pointActivitiesConf = pointActivitiesConfService.list().get(0);
PointActivities oldPointActivities = pointActivitiesMapper.selectOne(new LambdaQueryWrapper<PointActivities>().eq(PointActivities::getConsumerId, user.getId())); PointActivities oldPointActivities = pointActivitiesMapper.selectOne(new LambdaQueryWrapper<PointActivities>()
.eq(PointActivities::getConsumerId, user.getId())
.eq(PointActivities::getCurrentYear, LocalDate.now().getYear())
.eq(PointActivities::getCurrentMonth, LocalDate.now().getMonthValue())
);
if (ObjectUtil.isNotEmpty(oldPointActivities)) { if (ObjectUtil.isNotEmpty(oldPointActivities)) {
oldPointActivities.setPoints(oldPointActivities.getPoints() + YesNoEnum.yes.getIndex()); if (ObjectUtil.isNotEmpty(oldPointActivities.getLastConsumptionTime())) {
oldPointActivities.setLastConsumptionTime(sOrder.getPayTime()); if (DateUtils.addHours(oldPointActivities.getLastConsumptionTime(), pointActivitiesConf.getTimeInterval()).compareTo(new Date()) >= 0
if (oldPointActivities.getPoints().equals(pointActivitiesConf.getPointsRequired())) { && !oldPointActivities.getPoints().equals(pointActivitiesConf.getPointsRequired())) {
oldPointActivities.setIsReceive(YesNoEnum.yes.getIndex()); oldPointActivities.setPoints(oldPointActivities.getPoints() + YesNoEnum.yes.getIndex());
oldPointActivities.setLastConsumptionTime(sOrder.getPayTime());
if (oldPointActivities.getPoints().equals(pointActivitiesConf.getPointsRequired())) {
oldPointActivities.setIsReceive(YesNoEnum.yes.getIndex());
}
updateById(oldPointActivities);
}
} else {
oldPointActivities.setPoints(oldPointActivities.getPoints() + YesNoEnum.yes.getIndex());
oldPointActivities.setLastConsumptionTime(sOrder.getPayTime());
if (oldPointActivities.getPoints().equals(pointActivitiesConf.getPointsRequired())) {
oldPointActivities.setIsReceive(YesNoEnum.yes.getIndex());
}
updateById(oldPointActivities);
} }
updateById(oldPointActivities);
} else { } else {
PointActivities pointActivities = new PointActivities(); PointActivities pointActivities = new PointActivities();
pointActivities.setConsumerId(user.getId()); pointActivities.setConsumerId(user.getId());
...@@ -116,18 +135,18 @@ public class PointActivitiesServiceImpl extends ServiceImpl<PointActivitiesMappe ...@@ -116,18 +135,18 @@ public class PointActivitiesServiceImpl extends ServiceImpl<PointActivitiesMappe
//领取集点活动 //领取集点活动
@Override @Override
public void receivePointActivities(Long id) { public Integer receivePointActivities(Long id) {
PointActivities pointActivities = pointActivitiesMapper.selectById(id); PointActivities pointActivities = pointActivitiesMapper.selectById(id);
PointActivitiesConf activitiesConf = pointActivitiesConfService.getById(pointActivities.getConfId()); PointActivitiesConf activitiesConf = pointActivitiesConfService.getById(pointActivities.getConfId());
//领取的时间小于领取期限(最后的时间加领取的期限) //领取的时间小于领取期限(最后的时间加领取的期限)
if (DateUtils.addDays(pointActivities.getLastConsumptionTime(), activitiesConf.getCollectionDeadline()).compareTo(new Date()) < 0 if (DateUtils.addDays(pointActivities.getLastConsumptionTime(), activitiesConf.getCollectionDeadline()).compareTo(new Date()) > 0
&& pointActivities.getPoints().equals(activitiesConf.getPointsRequired())) { && pointActivities.getPoints().equals(activitiesConf.getPointsRequired())) {
sConsumerCouponService.give(pointActivities.getConsumerId(), activitiesConf.getCouponId(), activitiesConf.getCouponDuration());
if (pointActivities.getCurrentMonth().compareTo(LocalDate.now().getMonthValue()) == 0 && pointActivities.getCurrentYear().compareTo(LocalDate.now().getYear()) == 0) { if (pointActivities.getCurrentMonth().compareTo(LocalDate.now().getMonthValue()) == 0 && pointActivities.getCurrentYear().compareTo(LocalDate.now().getYear()) == 0) {
pointActivities.setCouponReceived(YesNoEnum.yes.getIndex()); pointActivities.setCouponReceived(YesNoEnum.yes.getIndex());
pointActivities.setReceivedDate(new Date()); pointActivities.setReceivedDate(new Date());
sConsumerCouponService.give(pointActivities.getConsumerId(), activitiesConf.getCouponId(), activitiesConf.getCouponDuration());
pointActivities.setCouponExpirationDate(DateUtils.addDays(pointActivities.getReceivedDate(), activitiesConf.getCouponDuration())); pointActivities.setCouponExpirationDate(DateUtils.addDays(pointActivities.getReceivedDate(), activitiesConf.getCouponDuration()));
pointActivitiesMapper.updateById(pointActivities); return pointActivitiesMapper.updateById(pointActivities);
} else { } else {
PointActivities newPointActivities = new PointActivities(); PointActivities newPointActivities = new PointActivities();
newPointActivities.setConsumerId(pointActivities.getConsumerId()); newPointActivities.setConsumerId(pointActivities.getConsumerId());
...@@ -136,13 +155,50 @@ public class PointActivitiesServiceImpl extends ServiceImpl<PointActivitiesMappe ...@@ -136,13 +155,50 @@ public class PointActivitiesServiceImpl extends ServiceImpl<PointActivitiesMappe
newPointActivities.setPoints(YesNoEnum.no.getIndex()); newPointActivities.setPoints(YesNoEnum.no.getIndex());
newPointActivities.setCurrentMonth(LocalDate.now().getMonthValue()); newPointActivities.setCurrentMonth(LocalDate.now().getMonthValue());
newPointActivities.setCurrentYear(LocalDate.now().getYear()); newPointActivities.setCurrentYear(LocalDate.now().getYear());
pointActivitiesMapper.insert(newPointActivities); return pointActivitiesMapper.insert(newPointActivities);
} }
} else { } else {
throw new RuntimeException("领取时间超过领取期限"); throw new RuntimeException("领取时间超过领取期限");
} }
} }
@Override
public PointActivities selectByConsumerId() {
SConsumer info = sConsumerService.getInfo();
List<PointActivities> activitiesList =
pointActivitiesMapper.selectList(new LambdaQueryWrapper<PointActivities>()
.eq(PointActivities::getConsumerId, info.getId())
//当前年月,次数未到的 or 领取优惠券未领取,年月在上个月的
.eq(PointActivities::getCurrentYear, LocalDate.now().getYear())
.eq(PointActivities::getCurrentMonth, LocalDate.now().getMonthValue())
.lt(PointActivities::getPoints, 4)
.eq(PointActivities::getIsReceive, YesNoEnum.no.getIndex())
.eq(PointActivities::getCouponReceived, YesNoEnum.no.getIndex())
.or()
.eq(PointActivities::getCurrentYear, LocalDate.now().getYear())
.eq(PointActivities::getCurrentMonth, LocalDate.now().getMonthValue())
.eq(PointActivities::getPoints, 4)
.eq(PointActivities::getIsReceive, YesNoEnum.yes.getIndex())
.eq(PointActivities::getCouponReceived, YesNoEnum.no.getIndex())
.or()
//或者夸年的
.eq(PointActivities::getCurrentYear, LocalDate.now().getYear() - 1)
.eq(PointActivities::getCurrentMonth, LocalDate.now().getMonthValue() + 11)
.eq(PointActivities::getIsReceive, YesNoEnum.yes.getIndex())
.eq(PointActivities::getCouponReceived, YesNoEnum.no.getIndex())
.or()
.eq(PointActivities::getCurrentYear, LocalDate.now().getYear())
.eq(PointActivities::getCurrentMonth, LocalDate.now().getMonthValue() - 1)
.eq(PointActivities::getIsReceive, YesNoEnum.yes.getIndex())
.eq(PointActivities::getCouponReceived, YesNoEnum.no.getIndex())
);
//获取currentYear和currentMonth最大的
if (CollectionUtils.isNotEmpty(activitiesList)) {
return activitiesList.stream().max(Comparator.comparing(PointActivities::getCurrentYear).thenComparing(PointActivities::getCurrentMonth)).get();
}
return new PointActivities();
}
/** /**
* 批量删除用户集点活动 * 批量删除用户集点活动
* *
......
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