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 a708d82e
authored
Apr 16, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:优惠券活动分页查询新增模板列表
1 parent
8af81184
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
160 additions
and
5 deletions
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponActivityService.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponActivityRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponTemplateConfigVO.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponActivityService.java
View file @
a708d82
...
...
@@ -46,6 +46,7 @@ public class CouponActivityService {
private
final
CouponAccountRepository
couponAccountRepository
;
private
final
CouponDistributionRecordRepository
distributionRecordRepository
;
private
final
CouponVerificationRecordRepository
verificationRecordRepository
;
private
final
CouponTierRuleRepository
couponTierRuleRepository
;
private
final
AccountDao
accountDao
;
private
final
CouponConverter
couponConverter
;
...
...
@@ -350,7 +351,7 @@ public class CouponActivityService {
.
collect
(
Collectors
.
toList
());
// 5. 批量查询价格区间规则(只做一次查询)
Map
<
String
,
List
<
CouponActivityPriceRange
>>
priceRangeMap
=
new
java
.
util
.
HashMap
<>();
Map
<
String
,
List
<
CouponActivityPriceRange
>>
priceRangeMap
=
new
HashMap
<>();
if
(!
autoTriggerActivityIds
.
isEmpty
())
{
List
<
CouponActivityPriceRange
>
allPriceRanges
=
priceRangeRepository
.
findByActivityIdInAndDeleteFlag
(
autoTriggerActivityIds
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
...
...
@@ -359,8 +360,68 @@ public class CouponActivityService {
.
collect
(
Collectors
.
groupingBy
(
CouponActivityPriceRange:
:
getActivityId
));
}
// 6. DTO 转 VO(小驼峰映射)
// 6. 批量查询所有关联的优惠券模板配置(避免 N+1 查询)
// 6.1 收集直接发放活动的模板 ID
List
<
Long
>
directTemplateIds
=
dtoPage
.
getContent
().
stream
()
.
filter
(
dto
->
dto
.
getActivityType
()
!=
null
&&
dto
.
getActivityType
().
equals
(
CouponActivityTypeEnum
.
DIRECT_DISTRIBUTION
.
getCode
())
&&
dto
.
getTemplateId
()
!=
null
)
.
map
(
CouponActivityStatDTO:
:
getTemplateId
)
.
distinct
()
.
collect
(
Collectors
.
toList
());
// 6.2 收集自动触发活动的所有模板 ID(从价格区间规则中)
List
<
Long
>
autoTriggerTemplateIds
=
priceRangeMap
.
values
().
stream
()
.
flatMap
(
List:
:
stream
)
.
map
(
CouponActivityPriceRange:
:
getTemplateId
)
.
distinct
()
.
collect
(
Collectors
.
toList
());
// 6.3 合并所有需要查询的模板 ID
Set
<
Long
>
allTemplateIds
=
new
HashSet
<>();
allTemplateIds
.
addAll
(
directTemplateIds
);
allTemplateIds
.
addAll
(
autoTriggerTemplateIds
);
// 6.4 批量查询所有模板信息(只做一次查询)
Map
<
Long
,
CouponTemplate
>
templateMap
=
new
HashMap
<>();
if
(!
allTemplateIds
.
isEmpty
())
{
List
<
CouponTemplate
>
templates
=
couponTemplateRepository
.
findAllById
(
allTemplateIds
);
templateMap
=
templates
.
stream
()
.
collect
(
Collectors
.
toMap
(
CouponTemplate:
:
getId
,
t
->
t
));
}
// 6.5 收集所有阶梯满减券的模板 ID(用于查询阶梯规则)
List
<
String
>
tierTemplateIds
=
templateMap
.
values
().
stream
()
.
filter
(
t
->
CouponTypeEnum
.
TIERED_AMOUNT
.
getCode
().
equals
(
t
.
getCouponType
()))
.
map
(
CouponTemplate:
:
getTemplateId
)
.
distinct
()
.
collect
(
Collectors
.
toList
());
// 6.6 批量查询所有阶梯规则(只做一次查询)
Map
<
String
,
List
<
CouponTierRuleRespVO
>>
tierRuleMap
=
new
HashMap
<>();
if
(!
tierTemplateIds
.
isEmpty
())
{
List
<
CouponTierRule
>
allTierRules
=
couponTierRuleRepository
.
findByTemplateIdInAndDeleteFlag
(
tierTemplateIds
,
DeleteFlag
.
NOT_DELETED
.
getCode
());
tierRuleMap
=
allTierRules
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
CouponTierRule:
:
getTemplateId
,
Collectors
.
mapping
(
rule
->
{
CouponTierRuleRespVO
vo
=
new
CouponTierRuleRespVO
();
vo
.
setId
(
rule
.
getId
());
vo
.
setTemplateId
(
rule
.
getTemplateId
());
vo
.
setTierLevel
(
rule
.
getTierLevel
());
vo
.
setThresholdAmount
(
rule
.
getThresholdAmount
());
vo
.
setDeductionAmount
(
rule
.
getDeductionAmount
());
return
vo
;
},
Collectors
.
toList
())
));
}
// 7. DTO 转 VO(小驼峰映射)
final
Map
<
String
,
List
<
CouponActivityPriceRange
>>
finalPriceRangeMap
=
priceRangeMap
;
final
Map
<
Long
,
CouponTemplate
>
finalTemplateMap
=
templateMap
;
final
Map
<
String
,
List
<
CouponTierRuleRespVO
>>
finalTierRuleMap
=
tierRuleMap
;
return
dtoPage
.
map
(
dto
->
{
CouponActivityRespVO
vo
=
new
CouponActivityRespVO
();
vo
.
setId
(
dto
.
getId
());
...
...
@@ -381,8 +442,11 @@ public class CouponActivityService {
vo
.
setTemplateId
(
dto
.
getTemplateId
());
vo
.
setUsedCount
(
dto
.
getUsedCount
());
vo
.
setWriteOffRate
(
dto
.
getWriteOffRate
());
// 如果是自动触发活动,从 Map 中获取价格区间规则
// 构建优惠券模板配置列表
List
<
CouponTemplateConfigVO
>
couponTemplates
=
new
ArrayList
<>();
// 如果是自动触发活动,从 Map 中获取价格区间规则,并构建模板配置列表
if
(
dto
.
getActivityType
()
!=
null
&&
dto
.
getActivityType
().
equals
(
CouponActivityTypeEnum
.
AUTO_TRIGGER
.
getCode
()))
{
List
<
CouponActivityPriceRange
>
priceRanges
=
finalPriceRangeMap
.
get
(
dto
.
getActivityId
());
if
(
priceRanges
!=
null
&&
!
priceRanges
.
isEmpty
())
{
...
...
@@ -395,14 +459,54 @@ public class CouponActivityService {
return
prVO
;
}).
collect
(
Collectors
.
toList
());
vo
.
setPriceRanges
(
priceRangeVOs
);
// 构建模板配置列表(每个价格区间对应一个模板配置)
for
(
CouponActivityPriceRange
priceRange
:
priceRanges
)
{
CouponTemplate
template
=
finalTemplateMap
.
get
(
priceRange
.
getTemplateId
());
if
(
template
!=
null
)
{
couponTemplates
.
add
(
buildCouponTemplateConfig
(
template
,
finalTierRuleMap
));
}
}
}
}
else
if
(
dto
.
getActivityType
()
!=
null
&&
dto
.
getActivityType
().
equals
(
CouponActivityTypeEnum
.
DIRECT_DISTRIBUTION
.
getCode
()))
{
// 直接发放活动,使用活动的 templateId 查询模板配置
if
(
dto
.
getTemplateId
()
!=
null
)
{
CouponTemplate
template
=
finalTemplateMap
.
get
(
dto
.
getTemplateId
());
if
(
template
!=
null
)
{
couponTemplates
.
add
(
buildCouponTemplateConfig
(
template
,
finalTierRuleMap
));
}
}
}
vo
.
setCouponTemplates
(
couponTemplates
);
return
vo
;
});
}
/**
* 构建优惠券模板配置 VO
*/
private
CouponTemplateConfigVO
buildCouponTemplateConfig
(
CouponTemplate
template
,
Map
<
String
,
List
<
CouponTierRuleRespVO
>>
tierRuleMap
)
{
CouponTemplateConfigVO
config
=
new
CouponTemplateConfigVO
();
config
.
setId
(
template
.
getId
());
config
.
setTemplateId
(
template
.
getTemplateId
());
config
.
setTemplateName
(
template
.
getTemplateName
());
config
.
setCouponType
(
template
.
getCouponType
());
config
.
setFaceAmount
(
template
.
getFaceAmount
());
config
.
setThresholdAmount
(
template
.
getThresholdAmount
());
config
.
setDeductionType
(
template
.
getDeductionType
());
config
.
setDescription
(
template
.
getDescription
());
// 如果是阶梯满减券,设置阶梯规则
if
(
CouponTypeEnum
.
TIERED_AMOUNT
.
getCode
().
equals
(
template
.
getCouponType
()))
{
config
.
setTierRules
(
tierRuleMap
.
getOrDefault
(
template
.
getTemplateId
(),
List
.
of
()));
}
return
config
;
}
/**
* 活动详情
*/
public
CouponActivityDetailRespVO
detail
(
CouponActivityDetailReqVO
reqVO
)
{
...
...
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponActivityRespVO.java
View file @
a708d82
...
...
@@ -73,4 +73,7 @@ public class CouponActivityRespVO implements Serializable {
@Schema
(
description
=
"价格区间规则列表(仅自动触发活动)"
)
private
List
<
CouponActivityPriceRangeRespVO
>
priceRanges
;
@Schema
(
description
=
"关联的优惠券模板配置列表"
)
private
List
<
CouponTemplateConfigVO
>
couponTemplates
;
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponTemplateConfigVO.java
0 → 100644
View file @
a708d82
package
com
.
glsx
.
usedcar
.
module
.
coupon
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.util.List
;
/**
* 优惠券模板配置 VO
* 用于展示活动关联的优惠券模板配置信息
*/
@Data
@Schema
(
description
=
"优惠券模板配置信息"
)
public
class
CouponTemplateConfigVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1234567890123456789L
;
@Schema
(
description
=
"模板 ID"
)
private
Long
id
;
@Schema
(
description
=
"模板唯一 ID"
)
private
String
templateId
;
@Schema
(
description
=
"优惠券名称"
)
private
String
templateName
;
@Schema
(
description
=
"优惠券类型 (1:固定面额券;2:阶梯满减券)"
)
private
Integer
couponType
;
@Schema
(
description
=
"券面额/最高抵扣金额(元)"
)
private
BigDecimal
faceAmount
;
@Schema
(
description
=
"使用门槛(元)"
)
private
BigDecimal
thresholdAmount
;
@Schema
(
description
=
"抵扣类型 (1:抵扣车款;2:抵扣佣金)"
)
private
Integer
deductionType
;
@Schema
(
description
=
"使用说明"
)
private
String
description
;
@Schema
(
description
=
"阶梯规则列表(仅阶梯满减券有值)"
)
private
List
<
CouponTierRuleRespVO
>
tierRules
;
}
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