Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
usedCarAuction
/
aus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit eb4596e4
authored
May 11, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:新增获取可用的优惠券模板列表
1 parent
35d1ed01
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletions
aus-admin/src/main/java/com/glsx/usedcar/web/rest/coupon/CouponTemplateController.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/dao/CouponTemplateRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponTemplateService.java
aus-admin/src/main/java/com/glsx/usedcar/web/rest/coupon/CouponTemplateController.java
View file @
eb4596e
...
@@ -15,11 +15,16 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -15,11 +15,16 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.orm.paging.Pagination
;
import
org.summerframework.orm.paging.Pagination
;
import
java.util.List
;
/**
/**
* 优惠券模板管理后台接口
* 优惠券模板管理后台接口
*/
*/
...
@@ -134,4 +139,17 @@ public class CouponTemplateController {
...
@@ -134,4 +139,17 @@ public class CouponTemplateController {
}
}
return
BaseResp
.
success
();
return
BaseResp
.
success
();
}
}
@Operation
(
summary
=
"获取可用优惠券模板列表"
,
description
=
"获取当前可用的优惠券模板列表(状态启用、未删除、未过期、有库存/不限库存)"
)
@PostMapping
(
"/available"
)
public
BaseResp
<
List
<
CouponTemplateRespVO
>>
available
()
{
log
.
info
(
"获取可用优惠券模板列表"
);
try
{
List
<
CouponTemplateRespVO
>
list
=
couponTemplateService
.
getAvailableTemplates
();
return
BaseResp
.
success
(
list
);
}
catch
(
Exception
e
)
{
log
.
error
(
"获取可用优惠券模板列表失败!系统异常!"
,
e
);
return
BaseResp
.
fail
(
"系统异常:"
+
e
.
getMessage
());
}
}
}
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/dao/CouponTemplateRepository.java
View file @
eb4596e
...
@@ -104,6 +104,23 @@ public interface CouponTemplateRepository extends BaseRepository<CouponTemplate,
...
@@ -104,6 +104,23 @@ public interface CouponTemplateRepository extends BaseRepository<CouponTemplate,
boolean
existsByTemplateIdAndDeleteFlag
(
String
templateId
,
String
deleteFlag
);
boolean
existsByTemplateIdAndDeleteFlag
(
String
templateId
,
String
deleteFlag
);
/**
/**
* 查询当前可用的优惠券模板列表
* <p>
* 条件:状态启用、未删除、未过期/无有效期、有库存/不限库存
*
* @param now 当前时间
* @return 可用模板列表
*/
@Query
(
"""
SELECT t FROM CouponTemplate t WHERE
(t.remainingQuantity IS NULL OR t.remainingQuantity > 0)
AND (t.validEndTime IS NULL OR t.validEndTime > :now)
AND t.deleteFlag = 'N'
AND t.status = 1
"""
)
List
<
CouponTemplate
>
findAvailableTemplates
(
@Param
(
"now"
)
LocalDateTime
now
);
/**
* 原子扣减库存(防止超发)
* 原子扣减库存(防止超发)
* 使用数据库级别的原子操作,确保并发安全
* 使用数据库级别的原子操作,确保并发安全
*
*
...
...
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponTemplateService.java
View file @
eb4596e
...
@@ -875,4 +875,20 @@ public class CouponTemplateService {
...
@@ -875,4 +875,20 @@ public class CouponTemplateService {
couponTierRuleRepository
.
saveAll
(
ruleList
);
couponTierRuleRepository
.
saveAll
(
ruleList
);
log
.
info
(
"保存阶梯规则成功:templateId={}, 规则数={}"
,
templateId
,
tierRules
.
size
());
log
.
info
(
"保存阶梯规则成功:templateId={}, 规则数={}"
,
templateId
,
tierRules
.
size
());
}
}
/**
* 获取当前可用的优惠券模板列表
* <p>
* 可用条件:状态启用、未删除、未过期/无有效期、有库存/不限库存
*
* @return 可用模板 VO 列表
*/
public
List
<
CouponTemplateRespVO
>
getAvailableTemplates
()
{
LocalDateTime
now
=
LocalDateTime
.
now
();
List
<
CouponTemplate
>
templates
=
couponTemplateRepository
.
findAvailableTemplates
(
now
);
if
(
templates
.
isEmpty
())
{
return
List
.
of
();
}
return
couponConverter
.
couponTemplatesMapRespVO
(
templates
);
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment