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 7e1feea1
authored
Apr 14, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:【优惠券需求】小程序新增获取优惠券活动接口
1 parent
f84c6843
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
2 deletions
aus-api/src/main/java/com/glsx/usedcar/web/api/coupon/CouponAccountController.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/dao/CouponActivityRepository.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponActivityService.java
aus-api/src/main/java/com/glsx/usedcar/web/api/coupon/CouponAccountController.java
View file @
7e1feea
...
...
@@ -4,8 +4,10 @@ import com.glsx.usedcar.module.account.entity.Account;
import
com.glsx.usedcar.module.auction.entity.AuctionOrder
;
import
com.glsx.usedcar.module.auction.service.AuctionOrderService
;
import
com.glsx.usedcar.module.coupon.service.CouponAccountService
;
import
com.glsx.usedcar.module.coupon.service.CouponActivityService
;
import
com.glsx.usedcar.module.coupon.service.CouponVerificationService
;
import
com.glsx.usedcar.module.coupon.vo.CouponAccountRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponActivityRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponPopupRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponVerifyReqVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponVerifyRespVO
;
...
...
@@ -37,6 +39,7 @@ public class CouponAccountController {
private
final
CouponAccountService
couponAccountService
;
private
final
CouponVerificationService
couponVerificationService
;
private
final
CouponActivityService
couponActivityService
;
private
final
AuctionOrderService
auctionOrderService
;
@Operation
(
summary
=
"获取我的优惠券列表"
,
description
=
"查询当前登录用户的优惠券列表,支持按状态筛选"
)
...
...
@@ -95,8 +98,8 @@ public class CouponAccountController {
}
}
//
@Operation(summary = "统计各状态优惠券数量", description = "统计用户待使用、已核销、已过期优惠券数量")
//
@GetMapping("/count")
@Operation
(
summary
=
"统计各状态优惠券数量"
,
description
=
"统计用户待使用、已核销、已过期优惠券数量"
)
@GetMapping
(
"/count"
)
public
BaseResp
<
CouponAccountRespVO
.
CouponCountVO
>
countCoupons
(
@RequestAttribute
(
value
=
LOGIN_ACCOUNT
,
required
=
false
)
Account
account
)
{
log
.
info
(
"【接口请求】统计各状态优惠券数量"
);
try
{
...
...
@@ -186,4 +189,23 @@ public class CouponAccountController {
return
BaseResp
.
fail
(
"系统异常:获取优惠券列表失败"
);
}
}
@Operation
(
summary
=
"获取最新可用活动"
,
description
=
"查询创建时间最新的可用优惠券活动"
)
@GetMapping
(
"/latest-activity"
)
public
BaseResp
<
CouponActivityRespVO
>
getLatestAvailableActivity
()
{
log
.
info
(
"【接口请求】获取最新可用活动"
);
try
{
CouponActivityRespVO
result
=
couponActivityService
.
getLatestAvailableActivity
();
if
(
result
==
null
)
{
return
BaseResp
.
success
(
null
);
}
return
BaseResp
.
success
(
result
);
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】获取最新可用活动失败"
,
be
);
return
BaseResp
.
fail
(
be
.
getCode
().
toString
(),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】获取最新可用活动异常"
,
e
);
return
BaseResp
.
fail
(
"系统异常:获取最新活动失败"
);
}
}
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/dao/CouponActivityRepository.java
View file @
7e1feea
...
...
@@ -214,5 +214,31 @@ public interface CouponActivityRepository extends BaseRepository<CouponActivity,
Pageable
pageable
);
/**
* 查询创建时间最新的可用活动(状态为进行中,未删除)
*
* @param status 活动状态
* @param deleteFlag 删除标识
* @return 最新的可用活动
*/
Optional
<
CouponActivity
>
findTopByStatusAndDeleteFlagOrderByCreateTimeDesc
(
Integer
status
,
String
deleteFlag
);
/**
* 查询创建时间最新的、在有效期内的活动
* 条件:状态为进行中、未删除、当前时间在有效期内
*
* @param status 活动状态
* @param deleteFlag 删除标识
* @param now 当前时间
* @return 最新的在有效期内的活动
*/
@Query
(
"SELECT a FROM CouponActivity a WHERE a.status = :status AND a.deleteFlag = :deleteFlag "
+
"AND a.validStartTime <= :now AND a.validEndTime >= :now ORDER BY a.createTime DESC"
)
Optional
<
CouponActivity
>
findTopAvailableActivityInValidTime
(
@Param
(
"status"
)
Integer
status
,
@Param
(
"deleteFlag"
)
String
deleteFlag
,
@Param
(
"now"
)
LocalDateTime
now
);
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponActivityService.java
View file @
7e1feea
...
...
@@ -1207,4 +1207,54 @@ public class CouponActivityService {
}
}
}
/**
* 获取创建时间最新的可用活动(在有效期内)
*
* @return 最新的在有效期内的活动,如果不存在则返回 null
*/
public
CouponActivityRespVO
getLatestAvailableActivity
()
{
LocalDateTime
now
=
LocalDateTime
.
now
();
// 查询创建时间最新的、在有效期内的进行中活动
Optional
<
CouponActivity
>
activityOpt
=
couponActivityRepository
.
findTopAvailableActivityInValidTime
(
CouponActivityStatusEnum
.
IN_PROGRESS
.
getCode
(),
DeleteFlag
.
NOT_DELETED
.
getCode
(),
now
);
if
(
activityOpt
.
isEmpty
())
{
log
.
info
(
"当前没有正在有效期内进行中的活动"
);
return
null
;
}
CouponActivity
activity
=
activityOpt
.
get
();
// 转换为 VO
CouponActivityRespVO
respVO
=
couponConverter
.
couponActivityMapRespVO
(
activity
);
// 如果是自动触发活动,查询价格区间规则
if
(
activity
.
getActivityType
()
!=
null
&&
activity
.
getActivityType
().
equals
(
CouponActivityTypeEnum
.
AUTO_TRIGGER
.
getCode
()))
{
List
<
CouponActivityPriceRange
>
priceRanges
=
priceRangeRepository
.
findByActivityIdAndDeleteFlag
(
activity
.
getActivityId
(),
DeleteFlag
.
NOT_DELETED
.
getCode
());
if
(
priceRanges
!=
null
&&
!
priceRanges
.
isEmpty
())
{
List
<
CouponActivityPriceRangeRespVO
>
priceRangeVOS
=
priceRanges
.
stream
().
map
(
pr
->
{
CouponActivityPriceRangeRespVO
vo
=
new
CouponActivityPriceRangeRespVO
();
vo
.
setId
(
pr
.
getId
());
vo
.
setPriceMin
(
pr
.
getPriceMin
());
vo
.
setPriceMax
(
pr
.
getPriceMax
());
vo
.
setTemplateId
(
pr
.
getTemplateId
());
return
vo
;
}).
collect
(
Collectors
.
toList
());
respVO
.
setPriceRanges
(
priceRangeVOS
);
}
}
log
.
info
(
"获取最新可用活动成功:activityId={}, activityName={}, validTime=[{} ~ {}]"
,
activity
.
getActivityId
(),
activity
.
getActivityName
(),
activity
.
getValidStartTime
(),
activity
.
getValidEndTime
());
return
respVO
;
}
}
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