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 b1e380ec
authored
Apr 14, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:【优惠券需求】小程序优惠通知代码优化
1 parent
e8142515
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
101 deletions
aus-core/src/main/java/com/glsx/usedcar/converts/CouponConverter.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponAccountService.java
aus-core/src/main/java/com/glsx/usedcar/converts/CouponConverter.java
View file @
b1e380e
package
com
.
glsx
.
usedcar
.
converts
;
import
com.glsx.usedcar.module.coupon.entity.CouponAccount
;
import
com.glsx.usedcar.module.coupon.entity.CouponActivity
;
import
com.glsx.usedcar.module.coupon.entity.CouponDistributionRecord
;
import
com.glsx.usedcar.module.coupon.entity.CouponTemplate
;
import
com.glsx.usedcar.module.coupon.vo.CouponAccountRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponActivityDetailRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponActivityRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponDistributionRecordRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponPopupRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponTemplateDetailRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponTemplateRespVO
;
import
org.mapstruct.Mapper
;
...
...
@@ -87,4 +90,36 @@ public interface CouponConverter {
* @return 优惠券发放记录响应VO列表
*/
List
<
CouponDistributionRecordRespVO
>
couponDistributionRecordsMapRespVO
(
List
<
CouponDistributionRecord
>
records
);
/**
* 优惠券账户实体转换为响应VO
*
* @param coupon 优惠券账户实体
* @return 优惠券账户响应VO
*/
CouponAccountRespVO
couponAccountMapRespVO
(
CouponAccount
coupon
);
/**
* 优惠券账户实体列表转换为响应VO列表
*
* @param coupons 优惠券账户实体列表
* @return 优惠券账户响应VO列表
*/
List
<
CouponAccountRespVO
>
couponAccountsMapRespVO
(
List
<
CouponAccount
>
coupons
);
/**
* 优惠券账户实体转换为弹窗VO
*
* @param coupon 优惠券账户实体
* @return 弹窗优惠券VO
*/
CouponPopupRespVO
.
PopupCouponVO
couponAccountMapPopupCouponVO
(
CouponAccount
coupon
);
/**
* 优惠券账户实体列表转换为弹窗VO列表
*
* @param coupons 优惠券账户实体列表
* @return 弹窗优惠券VO列表
*/
List
<
CouponPopupRespVO
.
PopupCouponVO
>
couponAccountsMapPopupCouponVO
(
List
<
CouponAccount
>
coupons
);
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponAccountService.java
View file @
b1e380e
package
com
.
glsx
.
usedcar
.
module
.
coupon
.
service
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.converts.CouponConverter
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.module.coupon.dao.CouponAccountRepository
;
import
com.glsx.usedcar.module.coupon.dao.CouponPopupNotificationRepository
;
import
com.glsx.usedcar.module.coupon.entity.CouponAccount
;
import
com.glsx.usedcar.module.coupon.entity.CouponPopupNotification
;
import
com.glsx.usedcar.module.coupon.enums.CouponUserStatusEnum
;
import
com.glsx.usedcar.module.coupon.vo.CouponAccountRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponPopupRespVO
;
...
...
@@ -20,7 +20,6 @@ import org.summerframework.core.exception.BusinessCodeException;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 账户优惠券服务类
...
...
@@ -33,6 +32,7 @@ public class CouponAccountService {
private
final
CouponAccountRepository
couponAccountRepository
;
private
final
CouponPopupNotificationRepository
popupNotificationRepository
;
private
final
CouponConverter
couponConverter
;
/**
* 获取我的优惠券列表
...
...
@@ -49,9 +49,7 @@ public class CouponAccountService {
coupons
=
couponAccountRepository
.
findByAccountIdAndStatusAndDeleteFlag
(
accountId
,
status
,
"N"
);
}
return
coupons
.
stream
()
.
map
(
this
::
convertToRespVO
)
.
collect
(
Collectors
.
toList
());
return
couponConverter
.
couponAccountsMapRespVO
(
coupons
);
}
/**
...
...
@@ -60,7 +58,7 @@ public class CouponAccountService {
public
CouponAccountRespVO
getCouponDetail
(
String
couponId
)
{
CouponAccount
coupon
=
couponAccountRepository
.
findByCouponIdAndDeleteFlag
(
couponId
,
"N"
)
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
"优惠券不存在"
));
return
co
nvertTo
RespVO
(
coupon
);
return
co
uponConverter
.
couponAccountMap
RespVO
(
coupon
);
}
/**
...
...
@@ -84,9 +82,7 @@ public class CouponAccountService {
// 构建弹窗响应
CouponPopupRespVO
popupVO
=
new
CouponPopupRespVO
();
popupVO
.
setPopupType
(
determinePopupType
(
pendingCoupons
));
popupVO
.
setCouponList
(
pendingCoupons
.
stream
()
.
map
(
this
::
convertToPopupCouponVO
)
.
collect
(
Collectors
.
toList
()));
popupVO
.
setCouponList
(
couponConverter
.
couponAccountsMapPopupCouponVO
(
pendingCoupons
));
return
popupVO
;
}
...
...
@@ -109,63 +105,6 @@ public class CouponAccountService {
}
/**
* 确认弹窗已读
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
confirmPopup
(
Integer
accountId
,
String
notificationId
)
{
if
(
accountId
==
null
||
StrUtil
.
isBlank
(
notificationId
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"参数不能为空"
);
}
LocalDateTime
now
=
LocalDateTime
.
now
();
// 1. 查询弹窗通知记录
CouponPopupNotification
notification
=
popupNotificationRepository
.
findByNotificationIdAndDeleteFlag
(
notificationId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXISTS
,
"弹窗通知不存在"
));
// 2. 校验弹窗归属
if
(!
notification
.
getAccountId
().
equals
(
accountId
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"弹窗通知不属于当前用户"
);
}
// 3. 校验弹窗状态(只能确认待通知或已展示的弹窗)
if
(
notification
.
getStatus
()
!=
0
&&
notification
.
getStatus
()
!=
1
)
{
log
.
warn
(
"弹窗状态不允许确认:notificationId={}, status={}"
,
notificationId
,
notification
.
getStatus
());
return
;
}
// 4. 更新弹窗通知状态为已确认
notification
.
setStatus
(
2
);
// 2:已确认
notification
.
setConfirmTime
(
now
);
popupNotificationRepository
.
save
(
notification
);
// 5. 更新关联优惠券的通知状态
if
(
StrUtil
.
isNotBlank
(
notification
.
getCouponIds
()))
{
// 解析优惠券 ID 列表(JSON 数组格式)
String
couponIdsJson
=
notification
.
getCouponIds
();
List
<
String
>
couponIds
=
parseCouponIds
(
couponIdsJson
);
// 批量更新优惠券的通知状态
for
(
String
couponId
:
couponIds
)
{
CouponAccount
coupon
=
couponAccountRepository
.
findByCouponIdAndDeleteFlag
(
couponId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElse
(
null
);
if
(
coupon
!=
null
&&
coupon
.
getAccountId
().
equals
(
accountId
))
{
// 更新为已通知状态
coupon
.
setNotificationStatus
(
1
);
// 1:已通知
coupon
.
setNotificationTime
(
now
);
couponAccountRepository
.
save
(
coupon
);
}
}
}
log
.
info
(
"确认弹窗已读成功:accountId={}, notificationId={}, popupType={}"
,
accountId
,
notificationId
,
notification
.
getPopupType
());
}
/**
* 解析优惠券 ID 列表(JSON 数组格式)
*/
private
List
<
String
>
parseCouponIds
(
String
couponIdsJson
)
{
...
...
@@ -213,39 +152,4 @@ public class CouponAccountService {
return
3
;
// 活动下发弹窗
}
/**
* 转换为响应 VO
*/
private
CouponAccountRespVO
convertToRespVO
(
CouponAccount
coupon
)
{
CouponAccountRespVO
vo
=
new
CouponAccountRespVO
();
vo
.
setId
(
coupon
.
getId
());
vo
.
setCouponId
(
coupon
.
getCouponId
());
vo
.
setTemplateId
(
coupon
.
getTemplateId
());
vo
.
setTemplateName
(
coupon
.
getTemplateName
());
vo
.
setCouponType
(
coupon
.
getCouponType
());
vo
.
setFaceAmount
(
coupon
.
getFaceAmount
());
vo
.
setThresholdAmount
(
coupon
.
getThresholdAmount
());
vo
.
setDeductionType
(
coupon
.
getDeductionType
());
vo
.
setStatus
(
coupon
.
getStatus
());
vo
.
setValidStartTime
(
coupon
.
getValidStartTime
());
vo
.
setValidEndTime
(
coupon
.
getValidEndTime
());
vo
.
setNuclearTime
(
coupon
.
getNuclearTime
());
vo
.
setNuclearOrderId
(
coupon
.
getNuclearOrderId
());
vo
.
setDistributionType
(
coupon
.
getDistributionType
());
vo
.
setDistributionSource
(
coupon
.
getDistributionSource
());
return
vo
;
}
/**
* 转换为弹窗 VO
*/
private
CouponPopupRespVO
.
PopupCouponVO
convertToPopupCouponVO
(
CouponAccount
coupon
)
{
CouponPopupRespVO
.
PopupCouponVO
vo
=
new
CouponPopupRespVO
.
PopupCouponVO
();
vo
.
setCouponId
(
coupon
.
getCouponId
());
vo
.
setTemplateName
(
coupon
.
getTemplateName
());
vo
.
setFaceAmount
(
coupon
.
getFaceAmount
());
vo
.
setValidEndTime
(
coupon
.
getValidEndTime
());
vo
.
setDistributionSource
(
coupon
.
getDistributionSource
());
return
vo
;
}
}
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