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 84c033f6
authored
May 15, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:1 小程序埋点接口获取用户名 2 优惠券使用实时模板数据来抵扣
1 parent
269c5020
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
28 deletions
aus-api/src/main/java/com/glsx/usedcar/web/api/event/EventTrackingController.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
aus-api/src/main/java/com/glsx/usedcar/web/api/event/EventTrackingController.java
View file @
84c033f
...
...
@@ -2,22 +2,20 @@ package com.glsx.usedcar.web.api.event;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.enums.event.EventSourceEnum
;
import
com.glsx.usedcar.module.account.entity.Account
;
import
com.glsx.usedcar.module.event.service.EventTrackingService
;
import
com.glsx.usedcar.module.event.vo.EventTrackingBatchSaveVO
;
import
com.glsx.usedcar.module.security.entity.User
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.security.core.Authentication
;
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.springframework.web.bind.annotation.*
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
static
com
.
glsx
.
usedcar
.
web
.
WebConstants
.
LOGIN_ACCOUNT
;
/**
* 埋点事件控制器
*
...
...
@@ -27,7 +25,7 @@ import org.summerframework.core.exception.BusinessCodeException;
*/
@Slf4j
@RestController
@RequestMapping
(
"/
rest
/eventTracking"
)
@RequestMapping
(
"/
api
/eventTracking"
)
@RequiredArgsConstructor
@Tag
(
name
=
"埋点事件控制器"
,
description
=
"埋点事件控制器"
)
public
class
EventTrackingController
{
...
...
@@ -38,30 +36,28 @@ public class EventTrackingController {
* 批量保存埋点事件
*
* @param vo 请求体(包含事件列表、业务主键、扩展参数)
* @param authentication 当前登录用户
* @return 操作结果
*/
@PostMapping
(
"/batchSave"
)
@Operation
(
summary
=
"批量保存埋点事件"
,
description
=
"前端批量上报用户行为埋点事件,支持同时携带业务主键和扩展参数"
)
public
BaseResp
<
Void
>
batchSave
(
@Valid
@RequestBody
EventTrackingBatchSaveVO
vo
,
Authentication
authentication
)
{
public
BaseResp
<
Void
>
batchSave
(
@Valid
@RequestBody
EventTrackingBatchSaveVO
vo
,
@RequestAttribute
(
LOGIN_ACCOUNT
)
Account
account
)
{
log
.
info
(
"【接口请求】批量保存埋点事件,操作人={},事件数量={}"
,
getUserName
(
a
uthentication
),
vo
.
getEvents
()
==
null
?
0
:
vo
.
getEvents
().
size
());
getUserName
(
a
ccount
),
vo
.
getEvents
()
==
null
?
0
:
vo
.
getEvents
().
size
());
try
{
User
user
=
(
User
)
authentication
.
getPrincipal
();
eventTrackingService
.
batchSave
(
vo
,
String
.
valueOf
(
user
.
getUserId
()),
user
.
getUserName
(),
EventSourceEnum
.
API
.
getSource
());
eventTrackingService
.
batchSave
(
vo
,
String
.
valueOf
(
account
.
getAccountId
()),
account
.
getAccountName
(),
EventSourceEnum
.
API
.
getSource
());
return
BaseResp
.
success
();
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】批量保存埋点事件失败!操作人={},业务异常!"
,
getUserName
(
a
uthentication
),
be
);
log
.
error
(
"【接口响应】批量保存埋点事件失败!操作人={},业务异常!"
,
getUserName
(
a
ccount
),
be
);
return
BaseResp
.
fail
(
StrUtil
.
toString
(
be
.
getCode
()),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】批量保存埋点事件失败!操作人={},系统异常!"
,
getUserName
(
a
uthentication
),
e
);
log
.
error
(
"【接口响应】批量保存埋点事件失败!操作人={},系统异常!"
,
getUserName
(
a
ccount
),
e
);
return
BaseResp
.
fail
(
"系统异常: "
+
e
.
getMessage
());
}
}
private
String
getUserName
(
A
uthentication
authentication
)
{
private
String
getUserName
(
A
ccount
account
)
{
try
{
return
a
uthentication
!=
null
?
((
User
)
authentication
.
getPrincipal
()).
getUser
Name
()
:
"未知用户"
;
return
a
ccount
!=
null
?
account
.
getAccount
Name
()
:
"未知用户"
;
}
catch
(
Exception
e
)
{
return
"未知用户"
;
}
...
...
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
View file @
84c033f
...
...
@@ -64,7 +64,6 @@ public class CouponVerificationService {
*/
private
Map
<
Long
,
CouponTemplate
>
loadTemplateMapForTiered
(
List
<
CouponAccount
>
coupons
)
{
Set
<
Long
>
templateIds
=
coupons
.
stream
()
.
filter
(
c
->
CouponTypeEnum
.
TIERED_AMOUNT
.
getCode
().
equals
(
c
.
getCouponType
()))
.
map
(
CouponAccount:
:
getTemplateId
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toSet
());
...
...
@@ -100,25 +99,26 @@ public class CouponVerificationService {
* @param orderPrice 订单金额(车款),用于门槛校验
* @param targetAmount 目标抵扣金额(车款或佣金),用于限制最大抵扣金额
* @param templateMap 模板缓存(可为空,非阶梯券不需要)
* @param tierRuleMap 阶梯规则缓存(可为空,非阶梯券不需要)
* @return 实际抵扣金额(不超过目标抵扣金额)
*/
private
BigDecimal
calculateActualDeduction
(
CouponAccount
coupon
,
BigDecimal
orderPrice
,
BigDecimal
targetAmount
,
Map
<
Long
,
CouponTemplate
>
templateMap
,
Map
<
String
,
List
<
CouponTierRule
>>
tierRuleMap
)
{
BigDecimal
faceAmount
=
coupon
.
getFaceAmount
();
BigDecimal
rawDeduction
;
CouponTemplate
template
=
templateMap
.
get
(
coupon
.
getTemplateId
());
if
(
template
==
null
)
{
log
.
info
(
"优惠券模板不存在,使用面额:couponId={}"
,
coupon
.
getCouponId
());
return
BigDecimal
.
ZERO
;
}
BigDecimal
rawDeduction
;
BigDecimal
faceAmount
=
template
.
getFaceAmount
();
if
(!
CouponTypeEnum
.
TIERED_AMOUNT
.
getCode
().
equals
(
coupon
.
getCouponType
()))
{
// 固定面额券:直接使用面额
rawDeduction
=
faceAmount
;
rawDeduction
=
template
.
getFaceAmount
();
log
.
info
(
"使用固定面额券,面额:couponId={}, faceAmount={}"
,
coupon
.
getCouponId
(),
template
.
getFaceAmount
());
}
else
{
// 阶梯券:从缓存 Map 取模板和阶梯规则,门槛校验只根据订单金额(orderPrice)
CouponTemplate
template
=
templateMap
.
get
(
coupon
.
getTemplateId
());
if
(
template
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
"优惠券模板不存在"
);
}
List
<
CouponTierRule
>
tierRules
=
tierRuleMap
.
get
(
template
.
getTemplateId
());
if
(
tierRules
==
null
||
tierRules
.
isEmpty
())
{
log
.
warn
(
"阶梯券未配置阶梯规则,使用面额:templateId={}"
,
coupon
.
getTemplateId
());
...
...
@@ -445,7 +445,7 @@ public class CouponVerificationService {
String
unavailableReason
=
checkCouponUnavailableReason
(
coupon
,
orderPrice
,
commissionPrice
,
now
,
usageMap
,
actualDeduction
);
return
convertToOrderCouponVO
(
coupon
,
maxVehicleDeduction
,
maxCommissionDeduction
,
unavailableReason
,
actualDeduction
);
unavailableReason
,
actualDeduction
,
templateMap
);
})
.
toList
();
...
...
@@ -522,13 +522,19 @@ public class CouponVerificationService {
BigDecimal
maxVehicleDeduction
,
BigDecimal
maxCommissionDeduction
,
String
unavailableReason
,
BigDecimal
actualDeduction
)
{
BigDecimal
actualDeduction
,
Map
<
Long
,
CouponTemplate
>
templateMap
)
{
OrderCouponRespVO
vo
=
new
OrderCouponRespVO
();
vo
.
setCouponId
(
coupon
.
getCouponId
());
vo
.
setTemplateName
(
coupon
.
getTemplateName
());
vo
.
setCouponType
(
coupon
.
getCouponType
());
vo
.
setDeductionType
(
coupon
.
getDeductionType
());
vo
.
setFaceAmount
(
coupon
.
getFaceAmount
());
CouponTemplate
couponTemplate
=
templateMap
.
get
(
coupon
.
getTemplateId
());
if
(
couponTemplate
!=
null
)
{
vo
.
setFaceAmount
(
couponTemplate
.
getFaceAmount
());
}
else
{
vo
.
setFaceAmount
(
coupon
.
getFaceAmount
());
}
vo
.
setThresholdAmount
(
coupon
.
getThresholdAmount
());
vo
.
setValidStartTime
(
coupon
.
getValidStartTime
());
vo
.
setValidEndTime
(
coupon
.
getValidEndTime
());
...
...
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