From 4a28184ee117fa3aa5bf150d3e97698fd6c3e13c Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期三, 29 四月 2026 20:35:40 +0800
Subject: [PATCH] feat:冒烟修改
---
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java | 54 +++++++++++++++++++++++++++
ruoyi-gateway/src/main/resources/logback.xml | 4 +-
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TExchangeCodePackageController.java | 9 ++++
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TExchangeCodePackageService.java | 4 ++
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/task/ExchangeCodeExpireTask.java | 19 +++++++++
5 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/ruoyi-gateway/src/main/resources/logback.xml b/ruoyi-gateway/src/main/resources/logback.xml
index f766a72..9e11c65 100644
--- a/ruoyi-gateway/src/main/resources/logback.xml
+++ b/ruoyi-gateway/src/main/resources/logback.xml
@@ -7,8 +7,8 @@
<contextName>logback</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义后,可以使“${}”来使用变量。 -->
-<!-- <property name="log.path" value="/data/log/app/ruoyi-gateway"/>-->
- <property name="log.path" value="/Users/mitao/Documents/log/mx_charging_pile/log/app/ruoyi-gateway"/>
+ <property name="log.path" value="/data/log/app/ruoyi-gateway"/>
+<!-- <property name="log.path" value="/Users/mitao/Documents/log/mx_charging_pile/log/app/ruoyi-gateway"/>-->
<!--0. 日志格式和颜色渲染 -->
<!-- 彩色日志依赖的渲染类 -->
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TExchangeCodePackageController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TExchangeCodePackageController.java
index 25e5cba..ef8eb76 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TExchangeCodePackageController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TExchangeCodePackageController.java
@@ -77,6 +77,15 @@
return AjaxResult.success();
}
+ @RequiresPermissions(value = {"/exchangeCode/update"}, logical = Logical.OR)
+ @PostMapping("/updateStatus")
+ @ApiOperation(value = "更新兑换码卡包启用状态", tags = {"管理后台-兑换码管理"})
+ @Log(title = "【兑换码管理】更新启用状态", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
+ public AjaxResult<Void> updateStatus(@RequestBody ExchangeCodePackageSaveDTO dto) {
+ exchangeCodePackageService.updatePackageStatus(dto.getId(), dto.getStatus());
+ return AjaxResult.success();
+ }
+
@RequiresPermissions(value = {"/exchangeCode/del"}, logical = Logical.OR)
@GetMapping("/delete")
@ApiOperation(value = "删除兑换码卡包", tags = {"管理后台-兑换码管理"})
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TExchangeCodePackageService.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TExchangeCodePackageService.java
index d38febd..c603c11 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TExchangeCodePackageService.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TExchangeCodePackageService.java
@@ -29,6 +29,10 @@
void updatePackage(ExchangeCodePackageSaveDTO dto);
+ void updatePackageStatus(Long id, Integer status);
+
+ void refreshExpiredPackageCodes();
+
void deletePackage(String ids);
ExchangeCodePackageDetailVO getDetail(Long id);
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java
index 8a22735..f6c5449 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TExchangeCodePackageServiceImpl.java
@@ -61,6 +61,7 @@
private static final Integer USE_RECORD_TYPE_EXCHANGE = 1;
private static final Integer USE_RECORD_TYPE_CONSUME = 2;
private static final Integer USE_RECORD_TYPE_REFUND = 3;
+ private static final String EXPIRE_INVALID_REASON = "领取截止日期已过期";
private static final DateTimeFormatter BATCH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
@Resource
@@ -112,6 +113,35 @@
}
@Override
+ public void updatePackageStatus(Long id, Integer status) {
+ if (id == null) {
+ throw new ServiceException("卡包ID不能为空");
+ }
+ if (!STATUS_ENABLE.equals(status) && !STATUS_DISABLE.equals(status)) {
+ throw new ServiceException("启用状态不正确");
+ }
+ TExchangeCodePackage old = this.getById(id);
+ if (old == null) {
+ throw new ServiceException("卡包不存在");
+ }
+ TExchangeCodePackage entity = new TExchangeCodePackage();
+ entity.setId(id);
+ entity.setStatus(status);
+ this.updateById(entity);
+ }
+
+ @Override
+ public void refreshExpiredPackageCodes() {
+ List<TExchangeCodePackage> expiredPackages = this.list(new QueryWrapper<TExchangeCodePackage>()
+ .isNotNull("expire_time")
+ .lt("expire_time", LocalDateTime.now())
+ .eq("del_flag", 0));
+ for (TExchangeCodePackage exchangePackage : expiredPackages) {
+ refreshExpiredPackageCodes(exchangePackage.getId());
+ }
+ }
+
+ @Override
@Transactional(rollbackFor = Exception.class)
public void deletePackage(String ids) {
if (!StringUtils.hasText(ids)) {
@@ -142,6 +172,7 @@
if (entity == null) {
throw new ServiceException("卡包不存在");
}
+ refreshExpiredPackageCodes(id);
refreshPackageStats(id);
entity = this.getById(id);
ExchangeCodePackageDetailVO detailVO = new ExchangeCodePackageDetailVO();
@@ -171,6 +202,7 @@
@Override
public PageInfo<ExchangeCodeDetailVO> codePage(ExchangeCodeDetailQuery query) {
+ refreshExpiredPackageCodes(query.getPackageId());
PageInfo<ExchangeCodeDetailVO> pageInfo = new PageInfo<>(query.getPageCurr(), query.getPageSize());
List<ExchangeCodeDetailVO> records = codeDetailMapper.pageList(pageInfo, query);
pageInfo.setRecords(records);
@@ -179,6 +211,7 @@
@Override
public List<ExchangeCodeDetailVO> exportCodes(ExchangeCodeDetailQuery query) {
+ refreshExpiredPackageCodes(query.getPackageId());
return codeDetailMapper.exportList(query);
}
@@ -255,6 +288,7 @@
throw new ServiceException("卡包已下架");
}
if (exchangePackage.getExpireTime() != null && exchangePackage.getExpireTime().isBefore(LocalDateTime.now())) {
+ refreshExpiredPackageCodes(exchangePackage.getId());
throw new ServiceException("已失效");
}
if (Objects.equals(detail.getStatus(), CODE_STATUS_INVALID)) {
@@ -657,6 +691,26 @@
this.baseMapper.updateById(entity);
}
+ private void refreshExpiredPackageCodes(Long packageId) {
+ if (packageId == null) {
+ return;
+ }
+ TExchangeCodePackage exchangePackage = this.getById(packageId);
+ if (exchangePackage == null || exchangePackage.getExpireTime() == null
+ || !exchangePackage.getExpireTime().isBefore(LocalDateTime.now())) {
+ return;
+ }
+ TExchangeCodeDetail detail = new TExchangeCodeDetail();
+ detail.setStatus(CODE_STATUS_INVALID);
+ detail.setInvalidTime(LocalDateTime.now());
+ detail.setInvalidReason(EXPIRE_INVALID_REASON);
+ codeDetailMapper.update(detail, new QueryWrapper<TExchangeCodeDetail>()
+ .eq("package_id", packageId)
+ .eq("status", CODE_STATUS_UNBOUND)
+ .eq("del_flag", 0));
+ refreshPackageStats(packageId);
+ }
+
private String generateCode(Long packageId, int seq) {
return "CD" + packageId + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + String.format("%03d", seq);
}
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/task/ExchangeCodeExpireTask.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/task/ExchangeCodeExpireTask.java
new file mode 100644
index 0000000..c30ab98
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/task/ExchangeCodeExpireTask.java
@@ -0,0 +1,19 @@
+package com.ruoyi.other.task;
+
+import com.ruoyi.other.service.TExchangeCodePackageService;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Component
+public class ExchangeCodeExpireTask {
+
+ @Resource
+ private TExchangeCodePackageService exchangeCodePackageService;
+
+ @Scheduled(cron = "0 */5 * * * ?")
+ public void refreshExpiredPackageCodes() {
+ exchangeCodePackageService.refreshExpiredPackageCodes();
+ }
+}
--
Gitblit v1.7.1