From 318defb5c7868a40452f8da4247806850dde0b8e Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 5 Nov 2025 21:20:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=9C=AA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../propcoupon/query/PropCouponListQryExe.java | 8 ++++++++ .../other/app/scheduler/PropCouponExpireTask.java | 13 ++++++------- .../infra/database/rds/dao/props/PropCouponDAO.java | 11 +---------- .../other/infra/gateway/PropCouponGatewayImpl.java | 7 +++---- .../src/main/resources/dao/props/PropsCouponDAO.xml | 10 ++++++++++ .../other-start/src/test/java/ApiTest.java | 3 +++ .../other-start/src/test/java/SpringTest.java | 12 ++++++++++++ 7 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/props/PropsCouponDAO.xml diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/propcoupon/query/PropCouponListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/propcoupon/query/PropCouponListQryExe.java index 00ba1d8a..f9c91398 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/propcoupon/query/PropCouponListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/propcoupon/query/PropCouponListQryExe.java @@ -12,6 +12,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -55,6 +56,13 @@ public class PropCouponListQryExe { cmd.getSize().intValue() ); + // 过期未使用的券 + propCoupons.forEach(coupon -> { + if (coupon.getStatus() == PropCouponStatus.UNUSED && coupon.getExpireTime().isBefore(LocalDateTime.now())) { + coupon.setStatus(PropCouponStatus.EXPIRED); + } + }); + // 4. 统计总数 Long total = propCouponGateway.countByUserId(userId, couponType, status); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/PropCouponExpireTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/PropCouponExpireTask.java index 76be2b64..def71100 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/PropCouponExpireTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/PropCouponExpireTask.java @@ -25,12 +25,11 @@ public class PropCouponExpireTask { */ @Scheduled(cron = "0 0 * * * ?") public void expireCoupons() { - // TODO: 实现过期逻辑 - // try { - // Integer count = propCouponGateway.expireOverdueCoupons(); - // log.info("道具券过期定时任务执行完成,过期券数量:{}", count); - // } catch (Exception e) { - // log.error("道具券过期定时任务执行失败", e); - // } + try { + Integer count = propCouponGateway.expireOverdueCoupons(); + log.info("道具券过期定时任务执行完成,过期券数量:{}", count); + } catch (Exception e) { + log.error("道具券过期定时任务执行失败", e); + } } } \ No newline at end of file diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/props/PropCouponDAO.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/props/PropCouponDAO.java index 3630eadc..5a461979 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/props/PropCouponDAO.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/props/PropCouponDAO.java @@ -4,6 +4,7 @@ import com.red.circle.framework.mybatis.dao.BaseDAO; import com.red.circle.other.infra.database.rds.entity.props.PropCouponDO; import org.apache.ibatis.annotations.Param; +import java.time.LocalDateTime; import java.util.List; /** @@ -14,16 +15,6 @@ import java.util.List; */ public interface PropCouponDAO extends BaseDAO { - /** - * 根据券编号查询(加锁) - */ - PropCouponDO selectForUpdate(@Param("couponNo") String couponNo); - - /** - * 批量插入 - */ - int batchInsert(@Param("list") List list); - /** * 批量过期券 */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/PropCouponGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/PropCouponGatewayImpl.java index 995ca05a..c9494b5d 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/PropCouponGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/PropCouponGatewayImpl.java @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -109,9 +110,7 @@ public class PropCouponGatewayImpl implements PropCouponGateway { @Override public Integer expireOverdueCoupons() { - // TODO: 实现批量过期逻辑 - // return propCouponDAO.expireOverdueCoupons(); - return 0; + return propCouponDAO.expireOverdueCoupons(); } @Override @@ -119,7 +118,7 @@ public class PropCouponGatewayImpl implements PropCouponGateway { List propCouponDOS = propCoupons.stream() .map(this::convertToDO) .collect(Collectors.toList()); - propCouponDAO.batchInsert(propCouponDOS); + propCouponDAO.insertBatchSomeColumn(propCouponDOS); } /** diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/props/PropsCouponDAO.xml b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/props/PropsCouponDAO.xml new file mode 100644 index 00000000..7f31d302 --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/props/PropsCouponDAO.xml @@ -0,0 +1,10 @@ + + + + + + UPDATE prop_coupon SET status = 2 WHERE status = 0 AND expire_time < NOW() + + + diff --git a/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java b/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java index ee4435d4..4800e32e 100644 --- a/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java +++ b/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; 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); System.out.println(strings[0]); System.out.println(strings[1]); + + System.out.println(LocalDateTime.now()); } @Test diff --git a/rc-service/rc-service-other/other-start/src/test/java/SpringTest.java b/rc-service/rc-service-other/other-start/src/test/java/SpringTest.java index 085b5579..70f18a4a 100644 --- a/rc-service/rc-service-other/other-start/src/test/java/SpringTest.java +++ b/rc-service/rc-service-other/other-start/src/test/java/SpringTest.java @@ -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.other.app.convertor.user.UserProfileAppConvertor; 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.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.rds.entity.sys.GameListConfig; 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 java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.Map; import java.util.Objects; @@ -43,6 +46,15 @@ public class SpringTest { private UserProfileGateway userProfileGateway; @Autowired private ImGroupClient imGroupClient; + @Autowired + private PropCouponGateway propCouponGateway; + + @Test + public void test() { + PropCoupon vip004 = propCouponGateway.selectByCouponNo("VIP004"); + LocalDateTime now = LocalDateTime.now(); + propCouponGateway.expireOverdueCoupons(); + } @Test public void execute() {