【缺陷修复】商城: 订单支付后记录 log error 日志,保证订单最大化可推导。

This commit is contained in:
puhui999
2024-12-09 14:43:46 +08:00
parent 4b0459501f
commit 313494400e
6 changed files with 38 additions and 20 deletions

View File

@@ -4,12 +4,11 @@ import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert;
import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum;
import cn.iocoder.yudao.module.member.service.level.MemberLevelService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.EXPERIENCE_BIZ_NOT_SUPPORT;
/**
@@ -17,6 +16,7 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.EXPERIENCE
*
* @author owen
*/
@Slf4j
@Service
@Validated
public class MemberLevelApiImpl implements MemberLevelApi {
@@ -33,7 +33,9 @@ public class MemberLevelApiImpl implements MemberLevelApi {
public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) {
MemberExperienceBizTypeEnum bizTypeEnum = MemberExperienceBizTypeEnum.getByType(bizType);
if (bizTypeEnum == null) {
throw exception(EXPERIENCE_BIZ_NOT_SUPPORT);
log.error("[addExperience][userId({}) experience({}) bizType({}) bizId({}) {}]", userId, experience, bizType,
bizId, EXPERIENCE_BIZ_NOT_SUPPORT);
return;
}
memberLevelService.addExperience(userId, experience, bizTypeEnum, bizId);
}

View File

@@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.member.api.point;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.POINT_RECORD_BIZ_NOT_SUPPORT;
@@ -16,6 +16,7 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.POINT_RECO
*
* @author owen
*/
@Slf4j
@Service
@Validated
public class MemberPointApiImpl implements MemberPointApi {
@@ -28,7 +29,9 @@ public class MemberPointApiImpl implements MemberPointApi {
Assert.isTrue(point > 0);
MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType);
if (bizTypeEnum == null) {
throw exception(POINT_RECORD_BIZ_NOT_SUPPORT);
log.error("[addPoint][userId({}) point({}) bizType({}) bizId({}) {}]", userId, point, bizType, bizId,
POINT_RECORD_BIZ_NOT_SUPPORT);
return;
}
memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId);
}
@@ -38,7 +41,9 @@ public class MemberPointApiImpl implements MemberPointApi {
Assert.isTrue(point > 0);
MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType);
if (bizTypeEnum == null) {
throw exception(POINT_RECORD_BIZ_NOT_SUPPORT);
log.error("[addPoint][userId({}) point({}) bizType({}) bizId({}) {}]", userId, point, bizType, bizId,
POINT_RECORD_BIZ_NOT_SUPPORT);
return;
}
memberPointRecordService.createPointRecord(userId, -point, bizTypeEnum, bizId);
}

View File

@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.service.point;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.point.vo.AppMemberPointRecordPageReqVO;
@@ -11,6 +10,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.point.MemberPointRecordMapper;
import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.List;
import java.util.Set;
@@ -75,13 +74,17 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
int totalPoint = userPoint + point; // 用户变动后的积分
if (totalPoint < 0) {
throw exception(USER_POINT_NOT_ENOUGH);
log.error("[createPointRecord][userId({}) point({}) bizType({}) bizId({}) {}]", userId, point, bizType, bizId,
USER_POINT_NOT_ENOUGH);
return;
}
// 2. 更新用户积分
boolean success = memberUserService.updateUserPoint(userId, point);
if (!success) {
throw exception(USER_POINT_NOT_ENOUGH);
log.error("[createPointRecord][userId({}) point({}) bizType({}) bizId({}) {}]", userId, point, bizType, bizId,
USER_POINT_NOT_ENOUGH);
return;
}
// 3. 增加积分记录