过期未使用的券

This commit is contained in:
tianfeng 2025-11-05 21:20:37 +08:00
parent 607ac75210
commit 318defb5c7
7 changed files with 43 additions and 21 deletions

View File

@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -55,6 +56,13 @@ public class PropCouponListQryExe {
cmd.getSize().intValue() cmd.getSize().intValue()
); );
// 过期未使用的券
propCoupons.forEach(coupon -> {
if (coupon.getStatus() == PropCouponStatus.UNUSED && coupon.getExpireTime().isBefore(LocalDateTime.now())) {
coupon.setStatus(PropCouponStatus.EXPIRED);
}
});
// 4. 统计总数 // 4. 统计总数
Long total = propCouponGateway.countByUserId(userId, couponType, status); Long total = propCouponGateway.countByUserId(userId, couponType, status);

View File

@ -25,12 +25,11 @@ public class PropCouponExpireTask {
*/ */
@Scheduled(cron = "0 0 * * * ?") @Scheduled(cron = "0 0 * * * ?")
public void expireCoupons() { public void expireCoupons() {
// TODO: 实现过期逻辑 try {
// try { Integer count = propCouponGateway.expireOverdueCoupons();
// Integer count = propCouponGateway.expireOverdueCoupons(); log.info("道具券过期定时任务执行完成,过期券数量:{}", count);
// log.info("道具券过期定时任务执行完成,过期券数量:{}", count); } catch (Exception e) {
// } catch (Exception e) { log.error("道具券过期定时任务执行失败", e);
// log.error("道具券过期定时任务执行失败", e); }
// }
} }
} }

View File

@ -4,6 +4,7 @@ import com.red.circle.framework.mybatis.dao.BaseDAO;
import com.red.circle.other.infra.database.rds.entity.props.PropCouponDO; import com.red.circle.other.infra.database.rds.entity.props.PropCouponDO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -14,16 +15,6 @@ import java.util.List;
*/ */
public interface PropCouponDAO extends BaseDAO<PropCouponDO> { public interface PropCouponDAO extends BaseDAO<PropCouponDO> {
/**
* 根据券编号查询加锁
*/
PropCouponDO selectForUpdate(@Param("couponNo") String couponNo);
/**
* 批量插入
*/
int batchInsert(@Param("list") List<PropCouponDO> list);
/** /**
* 批量过期券 * 批量过期券
*/ */

View File

@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -109,9 +110,7 @@ public class PropCouponGatewayImpl implements PropCouponGateway {
@Override @Override
public Integer expireOverdueCoupons() { public Integer expireOverdueCoupons() {
// TODO: 实现批量过期逻辑 return propCouponDAO.expireOverdueCoupons();
// return propCouponDAO.expireOverdueCoupons();
return 0;
} }
@Override @Override
@ -119,7 +118,7 @@ public class PropCouponGatewayImpl implements PropCouponGateway {
List<PropCouponDO> propCouponDOS = propCoupons.stream() List<PropCouponDO> propCouponDOS = propCoupons.stream()
.map(this::convertToDO) .map(this::convertToDO)
.collect(Collectors.toList()); .collect(Collectors.toList());
propCouponDAO.batchInsert(propCouponDOS); propCouponDAO.insertBatchSomeColumn(propCouponDOS);
} }
/** /**

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.red.circle.other.infra.database.rds.dao.props.PropCouponDAO">
<update id="expireOverdueCoupons">
UPDATE prop_coupon SET status = 2 WHERE status = 0 AND expire_time &lt; NOW()
</update>
</mapper>

View File

@ -5,6 +5,7 @@ import org.junit.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils.getCalcBillBelong; import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils.getCalcBillBelong;
@ -16,6 +17,8 @@ public class ApiTest {
String[] strings = TeamBillCycleUtils.parseBillBelongToDateRange(20251001); String[] strings = TeamBillCycleUtils.parseBillBelongToDateRange(20251001);
System.out.println(strings[0]); System.out.println(strings[0]);
System.out.println(strings[1]); System.out.println(strings[1]);
System.out.println(LocalDateTime.now());
} }
@Test @Test

View File

@ -8,8 +8,10 @@ import com.red.circle.external.inner.model.enums.message.GroupMessageTypeEnum;
import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.util.OfficialNoticeUtils; import com.red.circle.other.app.util.OfficialNoticeUtils;
import com.red.circle.other.domain.gateway.PropCouponGateway;
import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.gateway.user.ability.InviteUserGateway; import com.red.circle.other.domain.gateway.user.ability.InviteUserGateway;
import com.red.circle.other.domain.propcoupon.PropCoupon;
import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService;
import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig; import com.red.circle.other.infra.database.rds.entity.sys.GameListConfig;
import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService; import com.red.circle.other.infra.database.rds.service.sys.GameListConfigService;
@ -22,6 +24,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -43,6 +46,15 @@ public class SpringTest {
private UserProfileGateway userProfileGateway; private UserProfileGateway userProfileGateway;
@Autowired @Autowired
private ImGroupClient imGroupClient; private ImGroupClient imGroupClient;
@Autowired
private PropCouponGateway propCouponGateway;
@Test
public void test() {
PropCoupon vip004 = propCouponGateway.selectByCouponNo("VIP004");
LocalDateTime now = LocalDateTime.now();
propCouponGateway.expireOverdueCoupons();
}
@Test @Test
public void execute() { public void execute() {