From bdb38c41572091f38469f26695cada8e7341e9cc Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 22 Aug 2023 11:23:09 +0800 Subject: [PATCH 01/26] =?UTF-8?q?=E4=BC=9A=E5=91=98:=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=AD=89=E7=BA=A7=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E7=9A=84=E8=A1=A8=E5=8D=95=E3=80=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/member_level.sql | 4 +++ .../member/enums/ErrorCodeConstants.java | 1 - .../admin/user/MemberUserController.java | 9 ++++++ .../user/vo/MemberUserUpdateLevelReqVO.java | 31 +++++++++++++++++++ .../admin/user/vo/MemberUserUpdateReqVO.java | 3 -- .../dal/mysql/user/MemberUserMapper.java | 3 +- .../service/level/MemberLevelService.java | 9 ++---- .../service/level/MemberLevelServiceImpl.java | 31 ++++++++++--------- .../service/user/MemberUserServiceImpl.java | 8 ----- 9 files changed, 64 insertions(+), 35 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateLevelReqVO.java diff --git a/sql/mysql/member_level.sql b/sql/mysql/member_level.sql index cdb8618e5..dfab05eb9 100644 --- a/sql/mysql/member_level.sql +++ b/sql/mysql/member_level.sql @@ -92,3 +92,7 @@ INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, com VALUES ('会员等级更新', 'member:level:update', 3, 3, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('会员等级删除', 'member:level:delete', 3, 4, @parentId, '', '', '', 0); + +-- 会员用户管理: 增加按钮权限 +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('用户等级修改', 'member:user:update-level', 3, 5, 2309, '', '', '', 0); \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index 3959c616f..c2278b136 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -50,7 +50,6 @@ public interface ErrorCodeConstants { ErrorCode LEVEL_LOG_NOT_EXISTS = new ErrorCode(1004011100, "用户等级记录不存在"); ErrorCode EXPERIENCE_LOG_NOT_EXISTS = new ErrorCode(1004011200, "用户经验记录不存在"); - ErrorCode LEVEL_REASON_NOT_EXISTS = new ErrorCode(1004011300, "用户等级调整原因不能为空"); //========== 用户分组 1004012000 ========== ErrorCode GROUP_NOT_EXISTS = new ErrorCode(1004012000, "用户分组不存在"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java index a12d114b2..ccb9d5da5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO; +import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO; import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO; @@ -52,6 +53,14 @@ public class MemberUserController { return success(true); } + @PutMapping("/update-level") + @Operation(summary = "更新会员用户等级") + @PreAuthorize("@ss.hasPermission('member:user:update-level')") + public CommonResult updateUserLevel(@Valid @RequestBody MemberUserUpdateLevelReqVO updateReqVO) { + memberLevelService.updateUserLevel(updateReqVO); + return success(true); + } + @GetMapping("/get") @Operation(summary = "获得会员用户") @Parameter(name = "id", description = "编号", required = true, example = "1024") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateLevelReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateLevelReqVO.java new file mode 100644 index 000000000..a2ca91135 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateLevelReqVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.member.controller.admin.user.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 会员用户 修改等级 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MemberUserUpdateLevelReqVO extends MemberUserBaseVO { + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23788") + @NotNull(message = "用户编号不能为空") + private Long id; + + /** + * 取消用户等级时,值为空 + */ + @Schema(description = "用户等级编号", example = "1") + private Long levelId; + + @Schema(description = "修改原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "推广需要") + @NotBlank(message = "修改原因不能为空") + private String reason; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateReqVO.java index f4920aa1b..c6a92758d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserUpdateReqVO.java @@ -17,7 +17,4 @@ public class MemberUserUpdateReqVO extends MemberUserBaseVO { @NotNull(message = "编号不能为空") private Long id; - @Schema(description = "会员级别修改原因", requiredMode = Schema.RequiredMode.REQUIRED, example = "推广需要") - private String levelReason; - } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index d85b5d0e5..630c7a989 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -50,14 +50,13 @@ public interface MemberUserMapper extends BaseMapperX { .orderByDesc(MemberUserDO::getId)); } - // TODO @疯狂:命名可以改成 updateUserLevelToNull;db 侧的操作,尽量无业务含义,更多是 select、update、insert 操作 /** * 取消会员的等级 * * @param userId 会员编号 * @return 受影响的行数 */ - default int cancelUserLevel(Long userId) { + default int updateUserLevelToNull(Long userId) { return update(null, new LambdaUpdateWrapper() .eq(MemberUserDO::getId, userId) .set(MemberUserDO::getExperience, 0) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java index a9f876071..e604435a3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java @@ -5,11 +5,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; -import javax.annotation.Nullable; import javax.validation.Valid; import java.util.Collection; import java.util.List; @@ -89,11 +88,9 @@ public interface MemberLevelService { /** * 修改会员的等级 * - * @param user 会员 - * @param levelId 要修改的等级编号,编号为空时,代表取消会员的等级 - * @param levelReason 修改原因 + * @param updateReqVO 修改参数 */ - void updateUserLevel(MemberUserDO user, @Nullable Long levelId, String levelReason); + void updateUserLevel(MemberUserUpdateLevelReqVO updateReqVO); /** * 增加会员经验 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index 947d100f9..71678d470 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -4,11 +4,11 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO; import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; @@ -180,41 +180,42 @@ public class MemberLevelServiceImpl implements MemberLevelService { @Transactional(rollbackFor = Exception.class) @Override - public void updateUserLevel(MemberUserDO user, Long levelId, String reason) { + public void updateUserLevel(MemberUserUpdateLevelReqVO updateReqVO) { + MemberUserDO user = memberUserMapper.selectById(updateReqVO.getId()); + if (user == null) { + throw exception(USER_NOT_EXISTS); + } + // 未调整的情况1 - if (user.getLevelId() == null && levelId == null) { + if (user.getLevelId() == null && updateReqVO.getLevelId() == null) { return; } // 未调整的情况2 - if (ObjUtil.equal(user.getLevelId(), levelId)) { + if (ObjUtil.equal(user.getLevelId(), updateReqVO.getLevelId())) { return; } - // 需要后台用户填写为什么调整会员的等级 - if (StrUtil.isBlank(reason)) { - throw exception(LEVEL_REASON_NOT_EXISTS); - } - int experience; int totalExperience = 0; // 记录等级变动 - if (levelId == null) { + if (updateReqVO.getLevelId() == null) { + // 取消用户等级时,为扣减经验 experience = -user.getExperience(); // 取消了会员的等级 - memberLevelLogService.createCancelLog(user.getId(), reason); - memberUserMapper.cancelUserLevel(user.getId()); + memberLevelLogService.createCancelLog(user.getId(), updateReqVO.getReason()); + memberUserMapper.updateUserLevelToNull(user.getId()); } else { - MemberLevelDO level = validateLevelExists(levelId); + MemberLevelDO level = validateLevelExists(updateReqVO.getLevelId()); // 变动经验值 = 等级的升级经验 - 会员当前的经验;正数为增加经验,负数为扣减经验 experience = level.getExperience() - user.getExperience(); // 会员当前的经验 = 等级的升级经验 totalExperience = level.getExperience(); - memberLevelLogService.createAdjustLog(user, level, experience, reason); + memberLevelLogService.createAdjustLog(user, level, experience, updateReqVO.getReason()); // 更新会员表上的等级编号、经验值 - updateUserLevelIdAndExperience(user.getId(), levelId, totalExperience); + updateUserLevelIdAndExperience(user.getId(), updateReqVO.getLevelId(), totalExperience); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 880aa792b..421cf5b90 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -15,7 +15,6 @@ import cn.iocoder.yudao.module.member.convert.auth.AuthConvert; import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; -import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; @@ -56,9 +55,6 @@ public class MemberUserServiceImpl implements MemberUserService { @Resource private PasswordEncoder passwordEncoder; - @Resource - private MemberLevelService memberLevelService; - @Override public MemberUserDO getUserByMobile(String mobile) { return memberUserMapper.selectByMobile(mobile); @@ -195,10 +191,6 @@ public class MemberUserServiceImpl implements MemberUserService { // 更新 MemberUserDO updateObj = MemberUserConvert.INSTANCE.convert(updateReqVO); memberUserMapper.updateById(updateObj); - - // 会员级别修改 - // TODO @疯狂:修改用户等级,要不要单独一个前端操作 + 接口;因为它是个相对严肃独立的动作 - memberLevelService.updateUserLevel(user, updateReqVO.getLevelId(), updateReqVO.getLevelReason()); } @VisibleForTesting From ca51056c00c238d6b0a9e164c1c1493278c4e803 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 22 Aug 2023 20:49:25 +0800 Subject: [PATCH 02/26] =?UTF-8?q?=E4=BC=9A=E5=91=98:=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7=E8=AE=B0=E5=BD=95=E3=80=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=8F=E9=AA=8C=E8=AE=B0=E5=BD=95=20?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/member_level.sql | 10 +++--- ... => MemberExperienceRecordController.java} | 33 +++++++++---------- ....java => MemberLevelRecordController.java} | 33 +++++++++---------- ...java => MemberExperienceRecordBaseVO.java} | 2 +- ...a => MemberExperienceRecordPageReqVO.java} | 2 +- ...java => MemberExperienceRecordRespVO.java} | 2 +- ...seVO.java => MemberLevelRecordBaseVO.java} | 2 +- ...O.java => MemberLevelRecordPageReqVO.java} | 2 +- ...spVO.java => MemberLevelRecordRespVO.java} | 2 +- .../level/MemberExperienceLogConvert.java | 27 --------------- .../level/MemberExperienceRecordConvert.java | 27 +++++++++++++++ .../convert/level/MemberLevelLogConvert.java | 27 --------------- .../level/MemberLevelRecordConvert.java | 27 +++++++++++++++ ...gDO.java => MemberExperienceRecordDO.java} | 6 ++-- ...velLogDO.java => MemberLevelRecordDO.java} | 6 ++-- .../level/MemberExperienceLogMapper.java | 28 ---------------- .../level/MemberExperienceRecordMapper.java | 28 ++++++++++++++++ ...pper.java => MemberLevelRecordMapper.java} | 18 +++++----- ...ava => MemberExperienceRecordService.java} | 12 +++---- ...=> MemberExperienceRecordServiceImpl.java} | 18 +++++----- ...ice.java => MemberLevelRecordService.java} | 12 +++---- ...java => MemberLevelRecordServiceImpl.java} | 24 +++++++------- .../service/level/MemberLevelServiceImpl.java | 14 ++++---- .../level/MemberLevelServiceImplTest.java | 4 +-- 24 files changed, 182 insertions(+), 184 deletions(-) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/{MemberExperienceLogController.java => MemberExperienceRecordController.java} (58%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/{MemberLevelLogController.java => MemberLevelRecordController.java} (54%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/{MemberExperienceLogBaseVO.java => MemberExperienceRecordBaseVO.java} (97%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/{MemberExperienceLogPageReqVO.java => MemberExperienceRecordPageReqVO.java} (94%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/{MemberExperienceLogRespVO.java => MemberExperienceRecordRespVO.java} (88%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/{MemberLevelLogBaseVO.java => MemberLevelRecordBaseVO.java} (97%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/{MemberLevelLogPageReqVO.java => MemberLevelRecordPageReqVO.java} (94%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/{MemberLevelLogRespVO.java => MemberLevelRecordRespVO.java} (89%) delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceLogConvert.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelLogConvert.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/{MemberExperienceLogDO.java => MemberExperienceRecordDO.java} (81%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/{MemberLevelLogDO.java => MemberLevelRecordDO.java} (82%) delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceLogMapper.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceRecordMapper.java rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/{MemberLevelLogMapper.java => MemberLevelRecordMapper.java} (50%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/{MemberExperienceLogService.java => MemberExperienceRecordService.java} (81%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/{MemberExperienceLogServiceImpl.java => MemberExperienceRecordServiceImpl.java} (76%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/{MemberLevelLogService.java => MemberLevelRecordService.java} (84%) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/{MemberLevelLogServiceImpl.java => MemberLevelRecordServiceImpl.java} (81%) diff --git a/sql/mysql/member_level.sql b/sql/mysql/member_level.sql index dfab05eb9..50008e990 100644 --- a/sql/mysql/member_level.sql +++ b/sql/mysql/member_level.sql @@ -22,7 +22,7 @@ create table member_level ) comment '会员等级'; -create table member_level_log +create table member_level_record ( id bigint auto_increment comment '编号' primary key, user_id bigint default 0 not null comment '用户编号', @@ -42,9 +42,9 @@ create table member_level_log ) comment '会员等级记录'; -create index idx_user_id on member_level_log (user_id) comment '会员等级记录-用户编号'; +create index idx_user_id on member_level_record (user_id) comment '会员等级记录-用户编号'; -create table member_experience_log +create table member_experience_record ( id bigint auto_increment comment '编号' primary key, user_id bigint default 0 not null comment '用户编号', @@ -63,8 +63,8 @@ create table member_experience_log ) comment '会员经验记录'; -create index idx_user_id on member_experience_log (user_id) comment '会员经验记录-用户编号'; -create index idx_user_biz_type on member_experience_log (user_id, biz_type) comment '会员经验记录-用户业务类型'; +create index idx_user_id on member_experience_record (user_id) comment '会员经验记录-用户编号'; +create index idx_user_biz_type on member_experience_record (user_id, biz_type) comment '会员经验记录-用户业务类型'; -- 增加字典 insert system_dict_type(name, type) values ('会员经验业务类型', 'member_experience_biz_type'); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceLogController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java similarity index 58% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceLogController.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java index 3bc63004d..81c61df42 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceLogController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.member.controller.admin.level; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceLogPageReqVO; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceLogRespVO; -import cn.iocoder.yudao.module.member.convert.level.MemberExperienceLogConvert; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceLogDO; -import cn.iocoder.yudao.module.member.service.level.MemberExperienceLogService; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordRespVO; +import cn.iocoder.yudao.module.member.convert.level.MemberExperienceRecordConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceRecordDO; +import cn.iocoder.yudao.module.member.service.level.MemberExperienceRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -22,31 +22,30 @@ import javax.validation.Valid; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -// TODO @疯狂:要不 Log 改成 Record,和 PointRecord 保持一致 @Tag(name = "管理后台 - 会员经验记录") @RestController -@RequestMapping("/member/experience-log") +@RequestMapping("/member/experience-record") @Validated -public class MemberExperienceLogController { +public class MemberExperienceRecordController { @Resource - private MemberExperienceLogService experienceLogService; + private MemberExperienceRecordService experienceLogService; @GetMapping("/get") @Operation(summary = "获得会员经验记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('member:experience-log:query')") - public CommonResult getExperienceLog(@RequestParam("id") Long id) { - MemberExperienceLogDO experienceLog = experienceLogService.getExperienceLog(id); - return success(MemberExperienceLogConvert.INSTANCE.convert(experienceLog)); + @PreAuthorize("@ss.hasPermission('member:experience-record:query')") + public CommonResult getExperienceLog(@RequestParam("id") Long id) { + MemberExperienceRecordDO experienceLog = experienceLogService.getExperienceLog(id); + return success(MemberExperienceRecordConvert.INSTANCE.convert(experienceLog)); } @GetMapping("/page") @Operation(summary = "获得会员经验记录分页") - @PreAuthorize("@ss.hasPermission('member:experience-log:query')") - public CommonResult> getExperienceLogPage(@Valid MemberExperienceLogPageReqVO pageVO) { - PageResult pageResult = experienceLogService.getExperienceLogPage(pageVO); - return success(MemberExperienceLogConvert.INSTANCE.convertPage(pageResult)); + @PreAuthorize("@ss.hasPermission('member:experience-record:query')") + public CommonResult> getExperienceLogPage(@Valid MemberExperienceRecordPageReqVO pageVO) { + PageResult pageResult = experienceLogService.getExperienceLogPage(pageVO); + return success(MemberExperienceRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelLogController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java similarity index 54% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelLogController.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java index c4eb1497f..d81bf4893 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelLogController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.member.controller.admin.level; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelLogPageReqVO; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelLogRespVO; -import cn.iocoder.yudao.module.member.convert.level.MemberLevelLogConvert; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelLogDO; -import cn.iocoder.yudao.module.member.service.level.MemberLevelLogService; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordRespVO; +import cn.iocoder.yudao.module.member.convert.level.MemberLevelRecordConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; +import cn.iocoder.yudao.module.member.service.level.MemberLevelRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -22,30 +22,29 @@ import javax.validation.Valid; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -// TODO @疯狂:是不是不用这个 controller;因为日志只是为了记录,db 可以查询、和审计即可,目前暂时不需要开放出来; @Tag(name = "管理后台 - 会员等级记录") @RestController -@RequestMapping("/member/level-log") +@RequestMapping("/member/level-record") @Validated -public class MemberLevelLogController { +public class MemberLevelRecordController { @Resource - private MemberLevelLogService levelLogService; + private MemberLevelRecordService levelLogService; @GetMapping("/get") @Operation(summary = "获得会员等级记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('member:level-log:query')") - public CommonResult getLevelLog(@RequestParam("id") Long id) { - MemberLevelLogDO levelLog = levelLogService.getLevelLog(id); - return success(MemberLevelLogConvert.INSTANCE.convert(levelLog)); + @PreAuthorize("@ss.hasPermission('member:level-record:query')") + public CommonResult getLevelLog(@RequestParam("id") Long id) { + MemberLevelRecordDO levelLog = levelLogService.getLevelLog(id); + return success(MemberLevelRecordConvert.INSTANCE.convert(levelLog)); } @GetMapping("/page") @Operation(summary = "获得会员等级记录分页") - @PreAuthorize("@ss.hasPermission('member:level-log:query')") - public CommonResult> getLevelLogPage(@Valid MemberLevelLogPageReqVO pageVO) { - PageResult pageResult = levelLogService.getLevelLogPage(pageVO); - return success(MemberLevelLogConvert.INSTANCE.convertPage(pageResult)); + @PreAuthorize("@ss.hasPermission('member:level-record:query')") + public CommonResult> getLevelLogPage(@Valid MemberLevelRecordPageReqVO pageVO) { + PageResult pageResult = levelLogService.getLevelLogPage(pageVO); + return success(MemberLevelRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordBaseVO.java similarity index 97% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogBaseVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordBaseVO.java index b7906a672..7c71f8270 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordBaseVO.java @@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull; * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class MemberExperienceLogBaseVO { +public class MemberExperienceRecordBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3638") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordPageReqVO.java similarity index 94% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogPageReqVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordPageReqVO.java index a92dcda11..d18201d7c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogPageReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberExperienceLogPageReqVO extends PageParam { +public class MemberExperienceRecordPageReqVO extends PageParam { @Schema(description = "用户编号", example = "3638") private Long userId; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordRespVO.java similarity index 88% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogRespVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordRespVO.java index fb3779d1e..5e652fcf0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceLogRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/experience/MemberExperienceRecordRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberExperienceLogRespVO extends MemberExperienceLogBaseVO { +public class MemberExperienceRecordRespVO extends MemberExperienceRecordBaseVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19610") private Long id; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordBaseVO.java similarity index 97% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogBaseVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordBaseVO.java index 845b02435..4538988db 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordBaseVO.java @@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull; * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class MemberLevelLogBaseVO { +public class MemberLevelRecordBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25923") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordPageReqVO.java similarity index 94% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogPageReqVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordPageReqVO.java index 526503bed..2c7337b47 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogPageReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberLevelLogPageReqVO extends PageParam { +public class MemberLevelRecordPageReqVO extends PageParam { @Schema(description = "用户编号", example = "25923") private Long userId; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordRespVO.java similarity index 89% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogRespVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordRespVO.java index dfb2adb0a..290340a8e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelLogRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/log/MemberLevelRecordRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberLevelLogRespVO extends MemberLevelLogBaseVO { +public class MemberLevelRecordRespVO extends MemberLevelRecordBaseVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8741") private Long id; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceLogConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceLogConvert.java deleted file mode 100644 index 288ec094a..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceLogConvert.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.module.member.convert.level; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceLogRespVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 会员经验记录 Convert - * - * @author owen - */ -@Mapper -public interface MemberExperienceLogConvert { - - MemberExperienceLogConvert INSTANCE = Mappers.getMapper(MemberExperienceLogConvert.class); - - MemberExperienceLogRespVO convert(MemberExperienceLogDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java new file mode 100644 index 000000000..6902fccfd --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.member.convert.level; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordRespVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceRecordDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 会员经验记录 Convert + * + * @author owen + */ +@Mapper +public interface MemberExperienceRecordConvert { + + MemberExperienceRecordConvert INSTANCE = Mappers.getMapper(MemberExperienceRecordConvert.class); + + MemberExperienceRecordRespVO convert(MemberExperienceRecordDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelLogConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelLogConvert.java deleted file mode 100644 index 133f71209..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelLogConvert.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.module.member.convert.level; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelLogRespVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 会员等级记录 Convert - * - * @author owen - */ -@Mapper -public interface MemberLevelLogConvert { - - MemberLevelLogConvert INSTANCE = Mappers.getMapper(MemberLevelLogConvert.class); - - MemberLevelLogRespVO convert(MemberLevelLogDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java new file mode 100644 index 000000000..3770cc3d4 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.member.convert.level; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordRespVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 会员等级记录 Convert + * + * @author owen + */ +@Mapper +public interface MemberLevelRecordConvert { + + MemberLevelRecordConvert INSTANCE = Mappers.getMapper(MemberLevelRecordConvert.class); + + MemberLevelRecordRespVO convert(MemberLevelRecordDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberExperienceLogDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberExperienceRecordDO.java similarity index 81% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberExperienceLogDO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberExperienceRecordDO.java index 5324ac328..a8a7bef17 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberExperienceLogDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberExperienceRecordDO.java @@ -12,15 +12,15 @@ import lombok.*; * * @author owen */ -@TableName("member_experience_log") -@KeySequence("member_experience_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@TableName("member_experience_record") +@KeySequence("member_experience_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @Builder @NoArgsConstructor @AllArgsConstructor -public class MemberExperienceLogDO extends BaseDO { +public class MemberExperienceRecordDO extends BaseDO { /** * 编号 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelLogDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java similarity index 82% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelLogDO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java index 8ab63b18f..289dae983 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelLogDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java @@ -13,15 +13,15 @@ import lombok.*; * * @author owen */ -@TableName("member_level_log") -@KeySequence("member_level_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@TableName("member_level_record") +@KeySequence("member_level_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @Builder @NoArgsConstructor @AllArgsConstructor -public class MemberLevelLogDO extends BaseDO { +public class MemberLevelRecordDO extends BaseDO { /** * 编号 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceLogMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceLogMapper.java deleted file mode 100644 index 956e61cf6..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceLogMapper.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.member.dal.mysql.level; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceLogPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceLogDO; -import org.apache.ibatis.annotations.Mapper; - -/** - * 会员经验记录 Mapper - * - * @author owen - */ -@Mapper -public interface MemberExperienceLogMapper extends BaseMapperX { - - default PageResult selectPage(MemberExperienceLogPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(MemberExperienceLogDO::getUserId, reqVO.getUserId()) - .eqIfPresent(MemberExperienceLogDO::getBizId, reqVO.getBizId()) - .eqIfPresent(MemberExperienceLogDO::getBizType, reqVO.getBizType()) - .eqIfPresent(MemberExperienceLogDO::getTitle, reqVO.getTitle()) - .betweenIfPresent(MemberExperienceLogDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(MemberExperienceLogDO::getId)); - } - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceRecordMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceRecordMapper.java new file mode 100644 index 000000000..8e5065472 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberExperienceRecordMapper.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.member.dal.mysql.level; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceRecordDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 会员经验记录 Mapper + * + * @author owen + */ +@Mapper +public interface MemberExperienceRecordMapper extends BaseMapperX { + + default PageResult selectPage(MemberExperienceRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MemberExperienceRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(MemberExperienceRecordDO::getBizId, reqVO.getBizId()) + .eqIfPresent(MemberExperienceRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(MemberExperienceRecordDO::getTitle, reqVO.getTitle()) + .betweenIfPresent(MemberExperienceRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberExperienceRecordDO::getId)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelLogMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelRecordMapper.java similarity index 50% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelLogMapper.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelRecordMapper.java index d4bdbc3f4..d10b1690b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelLogMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelRecordMapper.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.member.dal.mysql.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelLogPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelLogDO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; import org.apache.ibatis.annotations.Mapper; /** @@ -13,14 +13,14 @@ import org.apache.ibatis.annotations.Mapper; * @author owen */ @Mapper -public interface MemberLevelLogMapper extends BaseMapperX { +public interface MemberLevelRecordMapper extends BaseMapperX { - default PageResult selectPage(MemberLevelLogPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(MemberLevelLogDO::getUserId, reqVO.getUserId()) - .eqIfPresent(MemberLevelLogDO::getLevelId, reqVO.getLevelId()) - .betweenIfPresent(MemberLevelLogDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(MemberLevelLogDO::getId)); + default PageResult selectPage(MemberLevelRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MemberLevelRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(MemberLevelRecordDO::getLevelId, reqVO.getLevelId()) + .betweenIfPresent(MemberLevelRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberLevelRecordDO::getId)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceLogService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java similarity index 81% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceLogService.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java index 0cb4389dc..92b34b365 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceLogService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.member.service.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceLogPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceLogDO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceRecordDO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import java.util.Collection; @@ -13,7 +13,7 @@ import java.util.List; * * @author owen */ -public interface MemberExperienceLogService { +public interface MemberExperienceRecordService { /** * 获得会员经验记录 @@ -21,7 +21,7 @@ public interface MemberExperienceLogService { * @param id 编号 * @return 会员经验记录 */ - MemberExperienceLogDO getExperienceLog(Long id); + MemberExperienceRecordDO getExperienceLog(Long id); /** * 获得会员经验记录列表 @@ -29,7 +29,7 @@ public interface MemberExperienceLogService { * @param ids 编号 * @return 会员经验记录列表 */ - List getExperienceLogList(Collection ids); + List getExperienceLogList(Collection ids); /** * 获得会员经验记录分页 @@ -37,7 +37,7 @@ public interface MemberExperienceLogService { * @param pageReqVO 分页查询 * @return 会员经验记录分页 */ - PageResult getExperienceLogPage(MemberExperienceLogPageReqVO pageReqVO); + PageResult getExperienceLogPage(MemberExperienceRecordPageReqVO pageReqVO); /** * 创建 手动调整 经验变动记录 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceLogServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java similarity index 76% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceLogServiceImpl.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java index f049d308f..ca0b96b6d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceLogServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.member.service.level; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceLogPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceLogDO; -import cn.iocoder.yudao.module.member.dal.mysql.level.MemberExperienceLogMapper; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceRecordDO; +import cn.iocoder.yudao.module.member.dal.mysql.level.MemberExperienceRecordMapper; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -20,24 +20,24 @@ import java.util.List; */ @Service @Validated -public class MemberExperienceLogServiceImpl implements MemberExperienceLogService { +public class MemberExperienceRecordServiceImpl implements MemberExperienceRecordService { @Resource - private MemberExperienceLogMapper experienceLogMapper; + private MemberExperienceRecordMapper experienceLogMapper; @Override - public MemberExperienceLogDO getExperienceLog(Long id) { + public MemberExperienceRecordDO getExperienceLog(Long id) { return experienceLogMapper.selectById(id); } @Override - public List getExperienceLogList(Collection ids) { + public List getExperienceLogList(Collection ids) { return experienceLogMapper.selectBatchIds(ids); } @Override - public PageResult getExperienceLogPage(MemberExperienceLogPageReqVO pageReqVO) { + public PageResult getExperienceLogPage(MemberExperienceRecordPageReqVO pageReqVO) { return experienceLogMapper.selectPage(pageReqVO); } @@ -50,7 +50,7 @@ public class MemberExperienceLogServiceImpl implements MemberExperienceLogServic @Override public void createBizLog(Long userId, int experience, int totalExperience, MemberExperienceBizTypeEnum bizType, String bizId) { - MemberExperienceLogDO experienceLogDO = new MemberExperienceLogDO(); + MemberExperienceRecordDO experienceLogDO = new MemberExperienceRecordDO(); experienceLogDO.setUserId(userId); experienceLogDO.setExperience(experience); experienceLogDO.setTotalExperience(totalExperience); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelLogService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java similarity index 84% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelLogService.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java index cfb84d684..7dfd2c830 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelLogService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.member.service.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelLogPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelLogDO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import java.util.Collection; @@ -14,7 +14,7 @@ import java.util.List; * * @author owen */ -public interface MemberLevelLogService { +public interface MemberLevelRecordService { /** * 删除会员等级记录 @@ -29,7 +29,7 @@ public interface MemberLevelLogService { * @param id 编号 * @return 会员等级记录 */ - MemberLevelLogDO getLevelLog(Long id); + MemberLevelRecordDO getLevelLog(Long id); /** * 获得会员等级记录列表 @@ -37,7 +37,7 @@ public interface MemberLevelLogService { * @param ids 编号 * @return 会员等级记录列表 */ - List getLevelLogList(Collection ids); + List getLevelLogList(Collection ids); /** * 获得会员等级记录分页 @@ -45,7 +45,7 @@ public interface MemberLevelLogService { * @param pageReqVO 分页查询 * @return 会员等级记录分页 */ - PageResult getLevelLogPage(MemberLevelLogPageReqVO pageReqVO); + PageResult getLevelLogPage(MemberLevelRecordPageReqVO pageReqVO); /** * 创建记录: 取消等级 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelLogServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java similarity index 81% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelLogServiceImpl.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java index 2031c70fb..8a81dcf43 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelLogServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.module.member.service.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelLogPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelLogDO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; -import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelLogMapper; +import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelRecordMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -23,10 +23,10 @@ import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.LEVEL_LOG_ */ @Service @Validated -public class MemberLevelLogServiceImpl implements MemberLevelLogService { +public class MemberLevelRecordServiceImpl implements MemberLevelRecordService { @Resource - private MemberLevelLogMapper levelLogMapper; + private MemberLevelRecordMapper levelLogMapper; @Override public void deleteLevelLog(Long id) { @@ -43,23 +43,23 @@ public class MemberLevelLogServiceImpl implements MemberLevelLogService { } @Override - public MemberLevelLogDO getLevelLog(Long id) { + public MemberLevelRecordDO getLevelLog(Long id) { return levelLogMapper.selectById(id); } @Override - public List getLevelLogList(Collection ids) { + public List getLevelLogList(Collection ids) { return levelLogMapper.selectBatchIds(ids); } @Override - public PageResult getLevelLogPage(MemberLevelLogPageReqVO pageReqVO) { + public PageResult getLevelLogPage(MemberLevelRecordPageReqVO pageReqVO) { return levelLogMapper.selectPage(pageReqVO); } @Override public void createCancelLog(Long userId, String reason) { - MemberLevelLogDO levelLogDO = new MemberLevelLogDO(); + MemberLevelRecordDO levelLogDO = new MemberLevelRecordDO(); levelLogDO.setUserId(userId); levelLogDO.setRemark(reason); levelLogDO.setDescription("管理员取消"); @@ -71,7 +71,7 @@ public class MemberLevelLogServiceImpl implements MemberLevelLogService { @Override public void createAdjustLog(MemberUserDO user, MemberLevelDO level, int experience, String reason) { - MemberLevelLogDO levelLogDO = new MemberLevelLogDO(); + MemberLevelRecordDO levelLogDO = new MemberLevelRecordDO(); levelLogDO.setUserId(user.getId()); levelLogDO.setLevelId(level.getId()); levelLogDO.setLevel(level.getLevel()); @@ -88,7 +88,7 @@ public class MemberLevelLogServiceImpl implements MemberLevelLogService { @Override public void createAutoUpgradeLog(MemberUserDO user, MemberLevelDO level) { - MemberLevelLogDO levelLogDO = new MemberLevelLogDO(); + MemberLevelRecordDO levelLogDO = new MemberLevelRecordDO(); levelLogDO.setUserId(user.getId()); levelLogDO.setLevelId(level.getId()); levelLogDO.setLevel(level.getLevel()); @@ -102,7 +102,7 @@ public class MemberLevelLogServiceImpl implements MemberLevelLogService { notifyMember(user.getId(), levelLogDO); } - private void notifyMember(Long userId, MemberLevelLogDO level) { + private void notifyMember(Long userId, MemberLevelRecordDO level) { //todo: 给会员发消息 } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index 71678d470..1364e7dbb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -42,9 +42,9 @@ public class MemberLevelServiceImpl implements MemberLevelService { @Resource private MemberLevelMapper levelMapper; @Resource - private MemberLevelLogService memberLevelLogService; + private MemberLevelRecordService memberLevelRecordService; @Resource - private MemberExperienceLogService memberExperienceLogService; + private MemberExperienceRecordService memberExperienceRecordService; @Resource private MemberUserMapper memberUserMapper; @@ -203,7 +203,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { experience = -user.getExperience(); // 取消了会员的等级 - memberLevelLogService.createCancelLog(user.getId(), updateReqVO.getReason()); + memberLevelRecordService.createCancelLog(user.getId(), updateReqVO.getReason()); memberUserMapper.updateUserLevelToNull(user.getId()); } else { MemberLevelDO level = validateLevelExists(updateReqVO.getLevelId()); @@ -212,7 +212,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { // 会员当前的经验 = 等级的升级经验 totalExperience = level.getExperience(); - memberLevelLogService.createAdjustLog(user, level, experience, updateReqVO.getReason()); + memberLevelRecordService.createAdjustLog(user, level, experience, updateReqVO.getReason()); // 更新会员表上的等级编号、经验值 updateUserLevelIdAndExperience(user.getId(), updateReqVO.getLevelId(), totalExperience); @@ -220,7 +220,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { // 记录会员经验变动 - memberExperienceLogService.createAdjustLog(user.getId(), experience, totalExperience); + memberExperienceRecordService.createAdjustLog(user.getId(), experience, totalExperience); } @Transactional(rollbackFor = Exception.class) @@ -239,7 +239,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { int userExperience = NumberUtil.max(user.getExperience() + experience, 0); // 创建经验记录 - memberExperienceLogService.createBizLog(userId, experience, userExperience, bizType, bizId); + memberExperienceRecordService.createBizLog(userId, experience, userExperience, bizType, bizId); // 计算会员等级 Long levelId = calcLevel(user, userExperience); @@ -284,7 +284,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { } // 保存等级变更记录 - memberLevelLogService.createAutoUpgradeLog(user, matchLevel); + memberLevelRecordService.createAutoUpgradeLog(user, matchLevel); return matchLevel.getId(); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java index e05dde443..9763c2f6f 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java +++ b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java @@ -41,9 +41,9 @@ public class MemberLevelServiceImplTest extends BaseDbUnitTest { private MemberLevelMapper levelMapper; @MockBean - private MemberLevelLogService memberLevelLogService; + private MemberLevelRecordService memberLevelRecordService; @MockBean - private MemberExperienceLogService memberExperienceLogService; + private MemberExperienceRecordService memberExperienceRecordService; @Test public void testCreateLevel_success() { From dc382d80bb4a2460694f6e9657b17d0284c41e9d Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 23 Aug 2023 10:02:00 +0800 Subject: [PATCH 03/26] =?UTF-8?q?=E4=BC=9A=E5=91=98:=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=AD=89=E7=BA=A7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/api/level/MemberLevelApi.java | 4 +- .../member/enums/ErrorCodeConstants.java | 1 + .../member/api/level/MemberLevelApiImpl.java | 14 +++- .../MemberExperienceRecordController.java | 4 +- .../level/MemberLevelRecordController.java | 4 +- .../level/MemberExperienceRecordConvert.java | 3 + .../level/MemberLevelRecordConvert.java | 10 +++ .../dataobject/level/MemberLevelRecordDO.java | 1 - .../dal/mysql/user/MemberUserMapper.java | 14 ---- .../level/MemberExperienceRecordService.java | 28 ++----- .../MemberExperienceRecordServiceImpl.java | 32 +++---- .../level/MemberLevelRecordService.java | 50 ++--------- .../level/MemberLevelRecordServiceImpl.java | 64 ++------------ .../service/level/MemberLevelService.java | 2 +- .../service/level/MemberLevelServiceImpl.java | 84 +++++++++++-------- .../service/user/MemberUserService.java | 8 ++ .../service/user/MemberUserServiceImpl.java | 12 +++ 17 files changed, 130 insertions(+), 205 deletions(-) diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java index 28ebef94e..b758633c8 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java @@ -14,8 +14,8 @@ public interface MemberLevelApi { * * @param userId 会员ID * @param experience 经验 - * @param bizType 业务类型 + * @param bizType 业务类型 {@link MemberExperienceBizTypeEnum} * @param bizId 业务编号 */ - void plusExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId); + void plusExperience(Long userId, Integer experience, Integer bizType, String bizId); } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index c2278b136..b9df654f2 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -50,6 +50,7 @@ public interface ErrorCodeConstants { ErrorCode LEVEL_LOG_NOT_EXISTS = new ErrorCode(1004011100, "用户等级记录不存在"); ErrorCode EXPERIENCE_LOG_NOT_EXISTS = new ErrorCode(1004011200, "用户经验记录不存在"); + ErrorCode EXPERIENCE_BIZ_NOT_SUPPORT = new ErrorCode(1004011201, "用户经验业务类型不支持"); //========== 用户分组 1004012000 ========== ErrorCode GROUP_NOT_EXISTS = new ErrorCode(1004012000, "用户分组不存在"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index 615539cef..c7c7f0d1e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -1,11 +1,16 @@ package cn.iocoder.yudao.module.member.api.level; +import cn.hutool.core.util.EnumUtil; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.Objects; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.EXPERIENCE_BIZ_NOT_SUPPORT; /** * 会员等级 API 实现类 @@ -19,7 +24,12 @@ public class MemberLevelApiImpl implements MemberLevelApi { @Resource private MemberLevelService memberLevelService; - public void plusExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId) { - memberLevelService.plusExperience(userId, experience, bizType, bizId); + public void plusExperience(Long userId, Integer experience, Integer bizType, String bizId) { + MemberExperienceBizTypeEnum bizTypeEnum = EnumUtil.getBy(MemberExperienceBizTypeEnum.class, e -> Objects.equals(bizType, e.getValue())); + if (bizTypeEnum == null) { + throw exception(EXPERIENCE_BIZ_NOT_SUPPORT); + } + + memberLevelService.addExperience(userId, experience, bizTypeEnum, bizId); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java index 81c61df42..be3efc5ba 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java @@ -36,7 +36,7 @@ public class MemberExperienceRecordController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('member:experience-record:query')") public CommonResult getExperienceLog(@RequestParam("id") Long id) { - MemberExperienceRecordDO experienceLog = experienceLogService.getExperienceLog(id); + MemberExperienceRecordDO experienceLog = experienceLogService.getExperienceRecord(id); return success(MemberExperienceRecordConvert.INSTANCE.convert(experienceLog)); } @@ -44,7 +44,7 @@ public class MemberExperienceRecordController { @Operation(summary = "获得会员经验记录分页") @PreAuthorize("@ss.hasPermission('member:experience-record:query')") public CommonResult> getExperienceLogPage(@Valid MemberExperienceRecordPageReqVO pageVO) { - PageResult pageResult = experienceLogService.getExperienceLogPage(pageVO); + PageResult pageResult = experienceLogService.getExperienceRecordPage(pageVO); return success(MemberExperienceRecordConvert.INSTANCE.convertPage(pageResult)); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java index d81bf4893..4ee2f1a08 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java @@ -36,7 +36,7 @@ public class MemberLevelRecordController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('member:level-record:query')") public CommonResult getLevelLog(@RequestParam("id") Long id) { - MemberLevelRecordDO levelLog = levelLogService.getLevelLog(id); + MemberLevelRecordDO levelLog = levelLogService.getLevelRecord(id); return success(MemberLevelRecordConvert.INSTANCE.convert(levelLog)); } @@ -44,7 +44,7 @@ public class MemberLevelRecordController { @Operation(summary = "获得会员等级记录分页") @PreAuthorize("@ss.hasPermission('member:level-record:query')") public CommonResult> getLevelLogPage(@Valid MemberLevelRecordPageReqVO pageVO) { - PageResult pageResult = levelLogService.getLevelLogPage(pageVO); + PageResult pageResult = levelLogService.getLevelRecordPage(pageVO); return success(MemberLevelRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java index 6902fccfd..cd51ba50e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberExperienceRecordConvert.java @@ -24,4 +24,7 @@ public interface MemberExperienceRecordConvert { PageResult convertPage(PageResult page); + MemberExperienceRecordDO convert(Long userId, Integer experience, Integer totalExperience, + String bizId, Integer bizType, + String title, String description); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java index 3770cc3d4..406e037c8 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.member.convert.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordRespVO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -24,4 +25,13 @@ public interface MemberLevelRecordConvert { PageResult convertPage(PageResult page); + default MemberLevelRecordDO copyTo(MemberLevelDO from, MemberLevelRecordDO to) { + if (from != null) { + to.setLevelId(from.getId()); + to.setLevel(from.getLevel()); + to.setDiscount(from.getDiscount()); + to.setExperience(from.getExperience()); + } + return to; + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java index b341daf00..289dae983 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/level/MemberLevelRecordDO.java @@ -52,7 +52,6 @@ public class MemberLevelRecordDO extends BaseDO { * 会员此时的经验 */ private Integer userExperience; - // TODO @疯狂:是不是 remark 和 description 可以合并成 description 就够了 /** * 备注 */ diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 630c7a989..902057272 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -50,19 +49,6 @@ public interface MemberUserMapper extends BaseMapperX { .orderByDesc(MemberUserDO::getId)); } - /** - * 取消会员的等级 - * - * @param userId 会员编号 - * @return 受影响的行数 - */ - default int updateUserLevelToNull(Long userId) { - return update(null, new LambdaUpdateWrapper() - .eq(MemberUserDO::getId, userId) - .set(MemberUserDO::getExperience, 0) - .set(MemberUserDO::getLevelId, null)); - } - default Long selectCountByGroupId(Long groupId) { return selectCount(MemberUserDO::getGroupId, groupId); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java index 56efbb3f9..b06464c28 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordService.java @@ -21,7 +21,7 @@ public interface MemberExperienceRecordService { * @param id 编号 * @return 会员经验记录 */ - MemberExperienceRecordDO getExperienceLog(Long id); + MemberExperienceRecordDO getExperienceRecord(Long id); /** * 获得会员经验记录列表 @@ -29,7 +29,7 @@ public interface MemberExperienceRecordService { * @param ids 编号 * @return 会员经验记录列表 */ - List getExperienceLogList(Collection ids); + List getExperienceRecordList(Collection ids); /** * 获得会员经验记录分页 @@ -37,26 +37,7 @@ public interface MemberExperienceRecordService { * @param pageReqVO 分页查询 * @return 会员经验记录分页 */ - PageResult getExperienceLogPage(MemberExperienceRecordPageReqVO pageReqVO); - - /** - * 获得会员经验记录列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 会员经验记录列表 - */ - List getExperienceLogList(MemberExperienceLogExportReqVO exportReqVO); - - // TODO @疯狂:类似 MemberLevelLogService 的方法,这里也需要提供一个通用的方法,用于创建经验变动记录 - - /** - * 创建 手动调整 经验变动记录 - * - * @param userId 会员编号 - * @param experience 变动经验值 - * @param totalExperience 会员当前的经验 - */ - void createAdjustLog(Long userId, int experience, int totalExperience); + PageResult getExperienceRecordPage(MemberExperienceRecordPageReqVO pageReqVO); /** * 根据业务类型, 创建 经验变动记录 @@ -67,5 +48,6 @@ public interface MemberExperienceRecordService { * @param bizType 业务类型 * @param bizId 业务ID */ - void createBizLog(Long userId, int experience, int totalExperience, MemberExperienceBizTypeEnum bizType, String bizId); + void createExperienceRecord(Long userId, Integer experience, Integer totalExperience, + MemberExperienceBizTypeEnum bizType, String bizId); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java index ca0b96b6d..9653928a4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.service.level; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.experience.MemberExperienceRecordPageReqVO; +import cn.iocoder.yudao.module.member.convert.level.MemberExperienceRecordConvert; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberExperienceRecordDO; import cn.iocoder.yudao.module.member.dal.mysql.level.MemberExperienceRecordMapper; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; @@ -27,38 +28,29 @@ public class MemberExperienceRecordServiceImpl implements MemberExperienceRecord @Override - public MemberExperienceRecordDO getExperienceLog(Long id) { + public MemberExperienceRecordDO getExperienceRecord(Long id) { return experienceLogMapper.selectById(id); } @Override - public List getExperienceLogList(Collection ids) { + public List getExperienceRecordList(Collection ids) { return experienceLogMapper.selectBatchIds(ids); } @Override - public PageResult getExperienceLogPage(MemberExperienceRecordPageReqVO pageReqVO) { + public PageResult getExperienceRecordPage(MemberExperienceRecordPageReqVO pageReqVO) { return experienceLogMapper.selectPage(pageReqVO); } @Override - public void createAdjustLog(Long userId, int experience, int totalExperience) { - // 管理员调整时, 没有业务编号, 记录对应的枚举值 - String bizId = MemberExperienceBizTypeEnum.ADMIN.getValue() + ""; - this.createBizLog(userId, experience, totalExperience, MemberExperienceBizTypeEnum.ADMIN, bizId); - } - - @Override - public void createBizLog(Long userId, int experience, int totalExperience, MemberExperienceBizTypeEnum bizType, String bizId) { - MemberExperienceRecordDO experienceLogDO = new MemberExperienceRecordDO(); - experienceLogDO.setUserId(userId); - experienceLogDO.setExperience(experience); - experienceLogDO.setTotalExperience(totalExperience); - experienceLogDO.setBizId(bizId); - experienceLogDO.setBizType(bizType.getValue()); - experienceLogDO.setTitle(bizType.getTitle()); - experienceLogDO.setDescription(StrUtil.format(bizType.getDesc(), experience)); - experienceLogMapper.insert(experienceLogDO); + public void createExperienceRecord(Long userId, Integer experience, Integer totalExperience, + MemberExperienceBizTypeEnum bizType, String bizId) { + String description = StrUtil.format(bizType.getDesc(), experience); + MemberExperienceRecordDO recordDO = MemberExperienceRecordConvert.INSTANCE.convert(userId, + experience, totalExperience, + bizId, bizType.getValue(), bizType.getTitle(), + description); + experienceLogMapper.insert(recordDO); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java index 7cc2dd359..cdee7ddc7 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java @@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.member.service.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import java.util.Collection; import java.util.List; @@ -16,20 +14,13 @@ import java.util.List; */ public interface MemberLevelRecordService { - /** - * 删除会员等级记录 - * - * @param id 编号 - */ - void deleteLevelLog(Long id); - /** * 获得会员等级记录 * * @param id 编号 * @return 会员等级记录 */ - MemberLevelRecordDO getLevelLog(Long id); + MemberLevelRecordDO getLevelRecord(Long id); /** * 获得会员等级记录列表 @@ -37,7 +28,7 @@ public interface MemberLevelRecordService { * @param ids 编号 * @return 会员等级记录列表 */ - List getLevelLogList(Collection ids); + List getLevelRecordList(Collection ids); /** * 获得会员等级记录分页 @@ -45,41 +36,12 @@ public interface MemberLevelRecordService { * @param pageReqVO 分页查询 * @return 会员等级记录分页 */ - PageResult getLevelLogPage(MemberLevelRecordPageReqVO pageReqVO); + PageResult getLevelRecordPage(MemberLevelRecordPageReqVO pageReqVO); /** - * 获得会员等级记录列表, 用于 Excel 导出 + * 创建会员等级记录 * - * @param exportReqVO 查询条件 - * @return 会员等级记录列表 + * @param levelRecord 会员等级记录 */ - List getLevelLogList(MemberLevelLogExportReqVO exportReqVO); - - // TODO @疯狂:把 createCancelLog、createAdjustLog、createAutoUpgradeLog 几个日志合并成一个通用的日志方法;整体的内容,交给 MemberLevelService 去做;以及对应的 level 变化的通知; - - /** - * 创建记录: 取消等级 - * - * @param userId 会员编号 - * @param reason 调整原因 - */ - void createCancelLog(Long userId, String reason); - - /** - * 创建记录: 手动调整 - * - * @param user 会员 - * @param level 等级 - * @param experience 变动经验值 - * @param reason 调整原因 - */ - void createAdjustLog(MemberUserDO user, MemberLevelDO level, int experience, String reason); - - /** - * 创建记录: 自动升级 - * - * @param user 会员 - * @param level 等级 - */ - void createAutoUpgradeLog(MemberUserDO user, MemberLevelDO level); + void createLevelRecord(MemberLevelRecordDO levelRecord); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java index 8a81dcf43..83926cd98 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java @@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.member.service.level; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelRecordMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -28,14 +26,6 @@ public class MemberLevelRecordServiceImpl implements MemberLevelRecordService { @Resource private MemberLevelRecordMapper levelLogMapper; - @Override - public void deleteLevelLog(Long id) { - // 校验存在 - validateLevelLogExists(id); - // 删除 - levelLogMapper.deleteById(id); - } - private void validateLevelLogExists(Long id) { if (levelLogMapper.selectById(id) == null) { throw exception(LEVEL_LOG_NOT_EXISTS); @@ -43,67 +33,23 @@ public class MemberLevelRecordServiceImpl implements MemberLevelRecordService { } @Override - public MemberLevelRecordDO getLevelLog(Long id) { + public MemberLevelRecordDO getLevelRecord(Long id) { return levelLogMapper.selectById(id); } @Override - public List getLevelLogList(Collection ids) { + public List getLevelRecordList(Collection ids) { return levelLogMapper.selectBatchIds(ids); } @Override - public PageResult getLevelLogPage(MemberLevelRecordPageReqVO pageReqVO) { + public PageResult getLevelRecordPage(MemberLevelRecordPageReqVO pageReqVO) { return levelLogMapper.selectPage(pageReqVO); } @Override - public void createCancelLog(Long userId, String reason) { - MemberLevelRecordDO levelLogDO = new MemberLevelRecordDO(); - levelLogDO.setUserId(userId); - levelLogDO.setRemark(reason); - levelLogDO.setDescription("管理员取消"); - levelLogMapper.insert(levelLogDO); - - // 给会员发送等级变动消息 - notifyMember(userId, levelLogDO); - } - - @Override - public void createAdjustLog(MemberUserDO user, MemberLevelDO level, int experience, String reason) { - MemberLevelRecordDO levelLogDO = new MemberLevelRecordDO(); - levelLogDO.setUserId(user.getId()); - levelLogDO.setLevelId(level.getId()); - levelLogDO.setLevel(level.getLevel()); - levelLogDO.setDiscount(level.getDiscount()); - levelLogDO.setUserExperience(level.getExperience()); - levelLogDO.setExperience(experience); - levelLogDO.setRemark(reason); - levelLogDO.setDescription("管理员调整为:" + level.getName()); - levelLogMapper.insert(levelLogDO); - - // 给会员发送等级变动消息 - notifyMember(user.getId(), levelLogDO); - } - - @Override - public void createAutoUpgradeLog(MemberUserDO user, MemberLevelDO level) { - MemberLevelRecordDO levelLogDO = new MemberLevelRecordDO(); - levelLogDO.setUserId(user.getId()); - levelLogDO.setLevelId(level.getId()); - levelLogDO.setLevel(level.getLevel()); - levelLogDO.setDiscount(level.getDiscount()); - levelLogDO.setExperience(level.getExperience()); - levelLogDO.setUserExperience(user.getExperience()); - levelLogDO.setDescription("成为:" + level.getName()); - levelLogMapper.insert(levelLogDO); - - // 给会员发送等级变动消息 - notifyMember(user.getId(), levelLogDO); - } - - private void notifyMember(Long userId, MemberLevelRecordDO level) { - //todo: 给会员发消息 + public void createLevelRecord(MemberLevelRecordDO levelRecord) { + levelLogMapper.insert(levelRecord); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java index e604435a3..e59e205c9 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java @@ -100,5 +100,5 @@ public interface MemberLevelService { * @param bizType 业务类型 * @param bizId 业务编号 */ - void plusExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId); + void addExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index dd6815bac..1cc7f474c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -10,11 +10,14 @@ import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLeve import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO; import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert; +import cn.iocoder.yudao.module.member.convert.level.MemberLevelRecordConvert; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; +import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelMapper; import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; +import cn.iocoder.yudao.module.member.service.user.MemberUserService; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -47,6 +50,8 @@ public class MemberLevelServiceImpl implements MemberLevelService { private MemberExperienceRecordService memberExperienceRecordService; @Resource private MemberUserMapper memberUserMapper; + @Resource + private MemberUserService memberUserService; @Override public Long createLevel(MemberLevelCreateReqVO createReqVO) { @@ -189,68 +194,73 @@ public class MemberLevelServiceImpl implements MemberLevelService { return; } - int experience; - int totalExperience = 0; - // 记录等级变动 + MemberLevelRecordDO levelRecord = new MemberLevelRecordDO() + .setUserId(user.getId()) + .setRemark(updateReqVO.getReason()); + MemberLevelDO memberLevel = null; if (updateReqVO.getLevelId() == null) { // 取消用户等级时,为扣减经验 - experience = -user.getExperience(); - - // 取消了会员的等级 - memberLevelRecordService.createCancelLog(user.getId(), updateReqVO.getReason()); - memberUserMapper.updateUserLevelToNull(user.getId()); + levelRecord.setExperience(-user.getExperience()); + levelRecord.setDescription("管理员取消了等级"); } else { - MemberLevelDO level = validateLevelExists(updateReqVO.getLevelId()); + memberLevel = validateLevelExists(updateReqVO.getLevelId()); + // 复制等级配置 + MemberLevelRecordConvert.INSTANCE.copyTo(memberLevel, levelRecord); // 变动经验值 = 等级的升级经验 - 会员当前的经验;正数为增加经验,负数为扣减经验 - experience = level.getExperience() - user.getExperience(); + levelRecord.setExperience(memberLevel.getExperience() - user.getExperience()); // 会员当前的经验 = 等级的升级经验 - totalExperience = level.getExperience(); - - memberLevelRecordService.createAdjustLog(user, level, experience, updateReqVO.getReason()); - - // 更新会员表上的等级编号、经验值 - updateUserLevelIdAndExperience(user.getId(), updateReqVO.getLevelId(), totalExperience); + levelRecord.setUserExperience(memberLevel.getExperience()); + levelRecord.setDescription("管理员调整为:" + memberLevel.getName()); } + // 记录等级变动 + memberLevelRecordService.createLevelRecord(levelRecord); + // 记录会员经验变动 - memberExperienceRecordService.createAdjustLog(user.getId(), experience, totalExperience); + memberExperienceRecordService.createExperienceRecord(user.getId(), + levelRecord.getExperience(), levelRecord.getUserExperience(), + MemberExperienceBizTypeEnum.ADMIN, MemberExperienceBizTypeEnum.ADMIN.getValue() + ""); + + // 更新会员表上的等级编号、经验值 + memberUserService.updateLevelIdAndExperience(user.getId(), updateReqVO.getLevelId(), levelRecord.getUserExperience()); + + // 给会员发送等级变动消息 + notifyMemberLevelChange(user.getId(), memberLevel); } - // TODO @疯狂:方法名,建议改成 increase 或者 add 经验,和项目更统一一些 - // TODO @疯狂:bizType 改成具体数值,主要是枚举在 api 不好传递,rpc 情况下 @Override @Transactional(rollbackFor = Exception.class) - public void plusExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId) { + public void addExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId) { if (experience == 0) { return; } MemberUserDO user = memberUserMapper.selectById(userId); - // 防止扣出负数 int userExperience = NumberUtil.max(user.getExperience() + experience, 0); + MemberLevelRecordDO levelRecord = new MemberLevelRecordDO() + .setUserId(user.getId()) + .setExperience(experience) + // 防止扣出负数 + .setUserExperience(userExperience); + // 创建经验记录 - memberExperienceRecordService.createBizLog(userId, experience, userExperience, bizType, bizId); + memberExperienceRecordService.createExperienceRecord(userId, experience, userExperience, + bizType, bizId); // 计算会员等级 MemberLevelDO newLevel = calculateNewLevel(user, userExperience); - Long newLevelId = null; if (newLevel != null) { - newLevelId = newLevel.getId(); + // 复制等级配置 + MemberLevelRecordConvert.INSTANCE.copyTo(newLevel, levelRecord); // 保存等级变更记录 - memberLevelRecordService.createAutoUpgradeLog(user, newLevel); + memberLevelRecordService.createLevelRecord(levelRecord); + // 给会员发送等级变动消息 + notifyMemberLevelChange(userId, newLevel); } // 更新会员表上的等级编号、经验值 - updateUserLevelIdAndExperience(user.getId(), newLevelId, userExperience); - } - - // TODO @疯狂:让 memberUserService 那开个方法;每个模块,不直接操作对方的 mapper; - private void updateUserLevelIdAndExperience(Long userId, Long levelId, Integer experience) { - memberUserMapper.updateById(new MemberUserDO() - .setId(userId) - .setLevelId(levelId).setExperience(experience) - ); + memberUserService.updateLevelIdAndExperience(user.getId(), levelRecord.getLevelId(), userExperience); } /** @@ -258,7 +268,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { * * @param user 会员 * @param userExperience 会员当前的经验值 - * @return 会员等级编号,null表示无变化 + * @return 会员新的等级,null表示无变化 */ private MemberLevelDO calculateNewLevel(MemberUserDO user, int userExperience) { List list = getEnableLevelList(); @@ -283,4 +293,8 @@ public class MemberLevelServiceImpl implements MemberLevelService { return matchLevel; } + + private void notifyMemberLevelChange(Long userId, MemberLevelDO level) { + //todo: 给会员发消息 + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index b48acc0d1..8b7d7460a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -126,4 +126,12 @@ public interface MemberUserService { */ PageResult getUserPage(MemberUserPageReqVO pageReqVO); + /** + * 更新用户的等级和经验 + * + * @param id 用户编号 + * @param levelId 用户等级 + * @param experience 用户经验 + */ + void updateLevelIdAndExperience(Long id, Long levelId, Integer experience); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 421cf5b90..c2918fd39 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -228,4 +228,16 @@ public class MemberUserServiceImpl implements MemberUserService { return memberUserMapper.selectPage(pageReqVO); } + @Override + public void updateLevelIdAndExperience(Long id, Long levelId, Integer experience) { + if (levelId == null) { + // 0 代表无等级:防止UpdateById时,会被过滤掉的问题 + levelId = 0L; + } + memberUserMapper.updateById(new MemberUserDO() + .setId(id) + .setLevelId(levelId).setExperience(experience) + ); + } + } From 4132cf14371289628375102955e588cb3c096898 Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 23 Aug 2023 10:12:21 +0800 Subject: [PATCH 04/26] =?UTF-8?q?=E4=BC=9A=E5=91=98:=20=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E5=8F=96=E6=B6=88=E5=88=86=E9=A1=B5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/level/MemberLevelController.java | 12 +++++------- ...evelPageReqVO.java => MemberLevelListReqVO.java} | 5 +---- .../member/convert/level/MemberLevelConvert.java | 3 --- .../member/dal/mysql/level/MemberLevelMapper.java | 7 +++---- .../member/service/level/MemberLevelService.java | 11 +++++------ .../service/level/MemberLevelServiceImpl.java | 7 +++---- .../service/level/MemberLevelServiceImplTest.java | 13 ++++++------- 7 files changed, 23 insertions(+), 35 deletions(-) rename yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/{MemberLevelPageReqVO.java => MemberLevelListReqVO.java} (71%) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelController.java index af4153b22..5a031321f 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelController.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.member.controller.admin.level; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.*; import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; @@ -70,13 +69,12 @@ public class MemberLevelController { return success(MemberLevelConvert.INSTANCE.convertSimpleList(list)); } - // TODO @疯狂:是不是不做分页,直接 list 就好啦;返回的时候,按照经验排序下哈; - @GetMapping("/page") - @Operation(summary = "获得会员等级分页") + @GetMapping("/list") + @Operation(summary = "获得会员等级列表") @PreAuthorize("@ss.hasPermission('member:level:query')") - public CommonResult> getLevelPage(@Valid MemberLevelPageReqVO pageVO) { - PageResult pageResult = levelService.getLevelPage(pageVO); - return success(MemberLevelConvert.INSTANCE.convertPage(pageResult)); + public CommonResult> getLevelList(@Valid MemberLevelListReqVO pageVO) { + List result = levelService.getLevelList(pageVO); + return success(MemberLevelConvert.INSTANCE.convertList(result)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java similarity index 71% rename from yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelPageReqVO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java index d9a6b5b66..87502b278 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelPageReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java @@ -1,16 +1,13 @@ package cn.iocoder.yudao.module.member.controller.admin.level.vo.level; -import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.ToString; @Schema(description = "管理后台 - 会员等级分页 Request VO") @Data -@EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberLevelPageReqVO extends PageParam { +public class MemberLevelListReqVO { @Schema(description = "等级名称", example = "芋艿") private String name; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java index ec2549462..4788bf365 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.member.convert.level; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelRespVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelSimpleRespVO; @@ -29,7 +28,5 @@ public interface MemberLevelConvert { List convertList(List list); - PageResult convertPage(PageResult page); - List convertSimpleList(List list); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelMapper.java index b0eb77d12..a7be2fd64 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/level/MemberLevelMapper.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.member.dal.mysql.level; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelListReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import org.apache.ibatis.annotations.Mapper; @@ -17,8 +16,8 @@ import java.util.List; @Mapper public interface MemberLevelMapper extends BaseMapperX { - default PageResult selectPage(MemberLevelPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() + default List selectList(MemberLevelListReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() .likeIfPresent(MemberLevelDO::getName, reqVO.getName()) .eqIfPresent(MemberLevelDO::getStatus, reqVO.getStatus()) .orderByAsc(MemberLevelDO::getLevel)); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java index e59e205c9..11c75cd65 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.member.service.level; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelListReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; @@ -59,12 +58,12 @@ public interface MemberLevelService { List getLevelList(Collection ids); /** - * 获得会员等级分页 + * 获得会员等级列表 * - * @param pageReqVO 分页查询 - * @return 会员等级分页 + * @param listReqVO 查询参数 + * @return 会员等级列表 */ - PageResult getLevelPage(MemberLevelPageReqVO pageReqVO); + List getLevelList(MemberLevelListReqVO listReqVO); /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index 1cc7f474c..6120b711a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -4,9 +4,8 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelListReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateLevelReqVO; import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert; @@ -173,8 +172,8 @@ public class MemberLevelServiceImpl implements MemberLevelService { } @Override - public PageResult getLevelPage(MemberLevelPageReqVO pageReqVO) { - return levelMapper.selectPage(pageReqVO); + public List getLevelList(MemberLevelListReqVO listReqVO) { + return levelMapper.selectList(listReqVO); } @Override diff --git a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java index 9763c2f6f..abcf5ff8d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java +++ b/yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImplTest.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; -import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelListReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelUpdateReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelMapper; @@ -121,7 +121,7 @@ public class MemberLevelServiceImplTest extends BaseDbUnitTest { } @Test - public void testGetLevelPage() { + public void testGetLevelList() { // mock 数据 MemberLevelDO dbLevel = randomPojo(MemberLevelDO.class, o -> { // 等会查询到 o.setName("黄金会员"); @@ -133,16 +133,15 @@ public class MemberLevelServiceImplTest extends BaseDbUnitTest { // 测试 status 不匹配 levelMapper.insert(cloneIgnoreId(dbLevel, o -> o.setStatus(0))); // 准备参数 - MemberLevelPageReqVO reqVO = new MemberLevelPageReqVO(); + MemberLevelListReqVO reqVO = new MemberLevelListReqVO(); reqVO.setName("黄金会员"); reqVO.setStatus(1); // 调用 - PageResult pageResult = levelService.getLevelPage(reqVO); + List list = levelService.getLevelList(reqVO); // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbLevel, pageResult.getList().get(0)); + assertEquals(1, list.size()); + assertPojoEquals(dbLevel, list.get(0)); } @Test From da8b2eab6da53da5a8eaa05af53561aad159f210 Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 23 Aug 2023 10:24:01 +0800 Subject: [PATCH 05/26] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/member_level.sql | 58 +++++++++---------- .../level/MemberLevelRecordConvert.java | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/sql/mysql/member_level.sql b/sql/mysql/member_level.sql index 50008e990..c7a02bbb0 100644 --- a/sql/mysql/member_level.sql +++ b/sql/mysql/member_level.sql @@ -5,40 +5,40 @@ alter table member_user add column level_id bigint comment '等级编号'; -- 增加3张表 create table member_level ( - id bigint auto_increment comment '编号' primary key, - name varchar(30) default '' not null comment '等级名称', - experience int default 0 not null comment '升级经验', - level int default 0 not null comment '等级', - discount tinyint default 100 not null comment '享受折扣', - icon varchar(255) default '' not null comment '等级图标', - background_url varchar(255) default '' not null comment '等级背景图', - status tinyint default 0 not null comment '状态', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' + id bigint auto_increment comment '编号' primary key, + name varchar(30) default '' not null comment '等级名称', + experience int default 0 not null comment '升级经验', + level int default 0 not null comment '等级', + discount_percent tinyint default 100 not null comment '享受折扣', + icon varchar(255) default '' not null comment '等级图标', + background_url varchar(255) default '' not null comment '等级背景图', + status tinyint default 0 not null comment '状态', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' ) comment '会员等级'; create table member_level_record ( - id bigint auto_increment comment '编号' primary key, - user_id bigint default 0 not null comment '用户编号', - level_id bigint default 0 not null comment '等级编号', - level int default 0 not null comment '会员等级', - discount tinyint default 100 not null comment '享受折扣', - experience int default 0 not null comment '升级经验', - user_experience int default 0 not null comment '会员此时的经验', - remark varchar(255) default '' not null comment '备注', - description varchar(255) default '' not null comment '描述', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' + id bigint auto_increment comment '编号' primary key, + user_id bigint default 0 not null comment '用户编号', + level_id bigint default 0 not null comment '等级编号', + level int default 0 not null comment '会员等级', + discount_percent tinyint default 100 not null comment '享受折扣', + experience int default 0 not null comment '升级经验', + user_experience int default 0 not null comment '会员此时的经验', + remark varchar(255) default '' not null comment '备注', + description varchar(255) default '' not null comment '描述', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' ) comment '会员等级记录'; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java index 406e037c8..9c167930c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelRecordConvert.java @@ -29,7 +29,7 @@ public interface MemberLevelRecordConvert { if (from != null) { to.setLevelId(from.getId()); to.setLevel(from.getLevel()); - to.setDiscount(from.getDiscount()); + to.setDiscountPercent(from.getDiscountPercent()); to.setExperience(from.getExperience()); } return to; From b119aadba5de1452edc8c7110d24f0ca7c898f41 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Wed, 23 Aug 2023 11:37:08 +0800 Subject: [PATCH 06/26] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=20=E6=9D=A1?= =?UTF-8?q?=E7=A0=81=E6=94=AF=E4=BB=98=20Client=20=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/alipay/AlipayBarPayClientTest.java | 157 ++++++++++++++++++ .../impl/alipay/AlipayPcPayClientTest.java | 14 +- 2 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java new file mode 100644 index 000000000..b6f24e136 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java @@ -0,0 +1,157 @@ +package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; + +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderDisplayModeEnum; +import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum; +import com.alipay.api.AlipayApiException; +import com.alipay.api.domain.AlipayTradePayModel; +import com.alipay.api.request.AlipayTradePayRequest; +import com.alipay.api.response.AlipayTradePayResponse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentMatcher; +import org.mockito.InjectMocks; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.CLOSED; +import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.WAITING; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.when; + +/** + * {@link AlipayBarPayClient} 单元测试 + * + * @author jason + */ +public class AlipayBarPayClientTest extends AbstractAlipayClientTest { + + @InjectMocks + private AlipayBarPayClient client = new AlipayBarPayClient(randomLongId(), config); + + @Override + @BeforeEach + public void setUp() { + setClient(client); + } + + @Test + @DisplayName("支付宝条码支付,非免密码支付下单成功") + public void test_unified_order_success() throws AlipayApiException { + String outTradeNo = randomString(); + String notifyUrl = randomURL(); + Integer price = randomInteger(); + String authCode = randomString(); + // 准备返回对象 + AlipayTradePayResponse response = randomPojo(AlipayTradePayResponse.class, o -> o.setSubCode("")); + + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> { + assertInstanceOf(AlipayTradePayModel.class, request.getBizModel()); + assertEquals(notifyUrl, request.getNotifyUrl()); + AlipayTradePayModel model = (AlipayTradePayModel) request.getBizModel(); + assertEquals(outTradeNo, model.getOutTradeNo()); + assertEquals(String.valueOf(price / 100.0), model.getTotalAmount()); + assertEquals(authCode, model.getAuthCode()); + return true; + }))).thenReturn(response); + // 准备请求参数 + PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); + // 设置条码 + Map extraParam = new HashMap<>(); + extraParam.put("auth_code", authCode); + reqDTO.setChannelExtras(extraParam); + // 下单请求 + PayOrderRespDTO resp = client.unifiedOrder(reqDTO); + // 断言 + assertEquals(WAITING.getStatus(), resp.getStatus()); + assertEquals(PayOrderDisplayModeEnum.BAR_CODE.getMode(), resp.getDisplayMode()); + assertEquals(outTradeNo, resp.getOutTradeNo()); + assertEquals("", resp.getDisplayContent()); + assertSame(response, resp.getRawData()); + } + + @Test + @DisplayName("支付宝条码支付,免密码支付下单成功") + public void test_unified_order_code_10000_success() throws AlipayApiException { + String outTradeNo = randomString(); + String channelNo = randomString(); + String channelUserId = randomString(); + Date payTime = randomDate(); + // 准备返回对象 + AlipayTradePayResponse response = randomPojo(AlipayTradePayResponse.class, o -> { + o.setSubCode(""); + o.setCode("10000"); + o.setOutTradeNo(outTradeNo); + o.setTradeNo(channelNo); + o.setBuyerUserId(channelUserId); + o.setGmtPayment(payTime); + }); + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) + .thenReturn(response); + // 准备请求参数 + String authCode = randomString(); + PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), outTradeNo, randomInteger()); + // 设置条码 + Map extraParam = new HashMap<>(); + extraParam.put("auth_code", authCode); + reqDTO.setChannelExtras(extraParam); + // 下单请求 + PayOrderRespDTO resp = client.unifiedOrder(reqDTO); + // 断言 + assertEquals(PayOrderStatusRespEnum.SUCCESS.getStatus(), resp.getStatus()); + assertEquals(outTradeNo, resp.getOutTradeNo()); + assertEquals(channelNo, resp.getChannelOrderNo()); + assertEquals(channelUserId, resp.getChannelUserId()); + assertEquals(LocalDateTimeUtil.of(payTime), resp.getSuccessTime()); + assertSame(response, resp.getRawData()); + } + + @Test + @DisplayName("支付宝条码支付,没有传条码") + public void test_unified_order_empty_auth_code() { + PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), randomString(), randomInteger()); + // 断言 + assertThrows(ServiceException.class, () -> client.unifiedOrder(reqDTO)); + } + + @Test + @DisplayName("支付宝条码支付,渠道返回失败") + public void test_unified_order_channel_failed() throws AlipayApiException { + // 准备响应对象 + String subCode = randomString(); + String subMsg = randomString(); + AlipayTradePayResponse response = randomPojo(AlipayTradePayResponse.class, o -> { + o.setSubCode(subCode); + o.setSubMsg(subMsg); + }); + // mock + when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) + .thenReturn(response); + // 准备请求参数 + String authCode = randomString(); + String outTradeNo = randomString(); + PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), outTradeNo, randomInteger()); + // 设置条码 + Map extraParam = new HashMap<>(); + extraParam.put("auth_code", authCode); + reqDTO.setChannelExtras(extraParam); + // 下单请求 + PayOrderRespDTO resp = client.unifiedOrder(reqDTO); + // 断言 + assertEquals(CLOSED.getStatus(), resp.getStatus()); + assertEquals(subCode, resp.getChannelErrorCode()); + assertEquals(subMsg, resp.getChannelErrorMsg()); + assertSame(response, resp.getRawData()); + + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java index 3d6b6f46e..9dfa6acc1 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java @@ -23,6 +23,8 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; /** + * {@link AlipayPcPayClient} 单元测试 + * * @author jason */ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { @@ -41,15 +43,13 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { public void test_unified_order_url_display_mode_success() throws AlipayApiException { // 准备返回对象 String notifyUrl = randomURL(); - Integer price = randomInteger(); - AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> { - o.setSubCode(""); - }); + AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); // mock when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher) request -> true), eq(Method.GET.name()))).thenReturn(response); // 准备请求参数 String outTradeNo = randomString(); + Integer price = randomInteger(); PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); // 设置 displayMode 为 null. reqDTO.setDisplayMode(null); @@ -67,15 +67,13 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { public void test_unified_order_form_display_mode_success() throws AlipayApiException { // 准备返回对象 String notifyUrl = randomURL(); - Integer price = randomInteger(); - AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> { - o.setSubCode(""); - }); + AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); // mock when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher) request -> true), eq(Method.POST.name()))).thenReturn(response); // 准备请求参数 String outTradeNo = randomString(); + Integer price = randomInteger(); PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); reqDTO.setDisplayMode(PayOrderDisplayModeEnum.FORM.getMode()); From 55cae6d2aa8d3a5e333010d64f2fc835fe56916e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=AE=E6=A2=A6?= Date: Wed, 23 Aug 2023 16:51:14 +0800 Subject: [PATCH 07/26] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?areaName=20=E5=AD=97=E6=AE=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/admin/user/vo/MemberUserBaseVO.java | 3 +++ .../yudao/module/member/convert/user/MemberUserConvert.java | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java index f411c5a16..90743042c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java @@ -43,6 +43,9 @@ public class MemberUserBaseVO { @Schema(description = "所在地", example = "4371") private Long areaId; + @Schema(description = "所在地可视化显示", example = "4371") + private String areaName; + @Schema(description = "出生日期", example = "2023-03-12") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) private LocalDateTime birthday; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java index 63e28b2f1..b95557dcf 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java @@ -5,9 +5,11 @@ import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserInfoRespVO; +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -16,7 +18,7 @@ import java.util.Map; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; -@Mapper +@Mapper(uses = {AddressConvert.class}) public interface MemberUserConvert { MemberUserConvert INSTANCE = Mappers.getMapper(MemberUserConvert.class); @@ -31,6 +33,7 @@ public interface MemberUserConvert { PageResult convertPage(PageResult page); + @Mapping(source = "areaId", target = "areaName", qualifiedByName = "convertAreaIdToAreaName") MemberUserRespVO convert03(MemberUserDO bean); default PageResult convertPage(PageResult pageResult, From 9b6f5bd5030d3c06b5e41dff9af46403576a776c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 24 Aug 2023 00:53:09 +0800 Subject: [PATCH 08/26] =?UTF-8?q?code=20review=EF=BC=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/member_level.sql | 98 ------------------- .../member/api/level/MemberLevelApi.java | 5 +- .../member/enums/ErrorCodeConstants.java | 2 - .../enums/MemberExperienceBizTypeEnum.java | 18 ++-- .../member/api/level/MemberLevelApiImpl.java | 9 +- .../MemberExperienceRecordController.java | 5 +- .../level/MemberLevelRecordController.java | 6 +- .../level/vo/level/MemberLevelListReqVO.java | 2 +- .../admin/user/MemberUserController.java | 21 ++-- .../convert/user/MemberUserConvert.java | 3 +- .../service/group/MemberGroupServiceImpl.java | 1 + .../MemberExperienceRecordServiceImpl.java | 12 +-- .../level/MemberLevelRecordService.java | 12 +-- .../level/MemberLevelRecordServiceImpl.java | 16 --- .../service/level/MemberLevelService.java | 3 +- .../service/level/MemberLevelServiceImpl.java | 19 ++-- .../service/user/MemberUserService.java | 3 +- .../service/user/MemberUserServiceImpl.java | 9 +- 18 files changed, 63 insertions(+), 181 deletions(-) delete mode 100644 sql/mysql/member_level.sql diff --git a/sql/mysql/member_level.sql b/sql/mysql/member_level.sql deleted file mode 100644 index c7a02bbb0..000000000 --- a/sql/mysql/member_level.sql +++ /dev/null @@ -1,98 +0,0 @@ --- 会员表增加字段 -alter table member_user add column experience int not null default 0 comment '经验'; -alter table member_user add column level_id bigint comment '等级编号'; - --- 增加3张表 -create table member_level -( - id bigint auto_increment comment '编号' primary key, - name varchar(30) default '' not null comment '等级名称', - experience int default 0 not null comment '升级经验', - level int default 0 not null comment '等级', - discount_percent tinyint default 100 not null comment '享受折扣', - icon varchar(255) default '' not null comment '等级图标', - background_url varchar(255) default '' not null comment '等级背景图', - status tinyint default 0 not null comment '状态', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' -) - comment '会员等级'; - -create table member_level_record -( - id bigint auto_increment comment '编号' primary key, - user_id bigint default 0 not null comment '用户编号', - level_id bigint default 0 not null comment '等级编号', - level int default 0 not null comment '会员等级', - discount_percent tinyint default 100 not null comment '享受折扣', - experience int default 0 not null comment '升级经验', - user_experience int default 0 not null comment '会员此时的经验', - remark varchar(255) default '' not null comment '备注', - description varchar(255) default '' not null comment '描述', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' -) - comment '会员等级记录'; - -create index idx_user_id on member_level_record (user_id) comment '会员等级记录-用户编号'; - -create table member_experience_record -( - id bigint auto_increment comment '编号' primary key, - user_id bigint default 0 not null comment '用户编号', - biz_id varchar(64) default '' not null comment '业务编号', - biz_type tinyint default 0 not null comment '业务类型', - title varchar(30) default '' not null comment '标题', - experience int default 0 not null comment '经验', - total_experience int default 0 not null comment '变更后的经验', - description varchar(512) default '' not null comment '描述', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' -) - comment '会员经验记录'; - -create index idx_user_id on member_experience_record (user_id) comment '会员经验记录-用户编号'; -create index idx_user_biz_type on member_experience_record (user_id, biz_type) comment '会员经验记录-用户业务类型'; - --- 增加字典 -insert system_dict_type(name, type) values ('会员经验业务类型', 'member_experience_biz_type'); -insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '管理员调整', '0', 0); -insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '邀新奖励', '1', 1); -insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '下单奖励', '2', 2); -insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '退单扣除', '3', 3); -insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '签到奖励', '4', 4); -insert system_dict_data(dict_type, label, value, sort) values ('member_experience_biz_type', '抽奖奖励', '5', 5); - --- 菜单 SQL -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status, component_name) -VALUES ('会员等级', '', 2, 3, 2262, 'level', '', 'member/level/index', 0, 'MemberLevel'); - --- 按钮父菜单ID --- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 -SELECT @parentId := LAST_INSERT_ID(); - --- 按钮 SQL -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('会员等级查询', 'member:level:query', 3, 1, @parentId, '', '', '', 0); -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('会员等级创建', 'member:level:create', 3, 2, @parentId, '', '', '', 0); -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('会员等级更新', 'member:level:update', 3, 3, @parentId, '', '', '', 0); -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('会员等级删除', 'member:level:delete', 3, 4, @parentId, '', '', '', 0); - --- 会员用户管理: 增加按钮权限 -INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) -VALUES ('用户等级修改', 'member:user:update-level', 3, 5, 2309, '', '', '', 0); \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java index b758633c8..2091189a2 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.member.api.level; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; /** - * 会员等级 API接口 + * 会员等级 API 接口 * * @author owen */ @@ -17,5 +17,6 @@ public interface MemberLevelApi { * @param bizType 业务类型 {@link MemberExperienceBizTypeEnum} * @param bizId 业务编号 */ - void plusExperience(Long userId, Integer experience, Integer bizType, String bizId); + void addExperience(Long userId, Integer experience, Integer bizType, String bizId); + } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index b9df654f2..724ba0c5e 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -48,8 +48,6 @@ public interface ErrorCodeConstants { ErrorCode LEVEL_EXPERIENCE_MAX = new ErrorCode(1004011004, "升级经验必须小于下一个等级[{}]设置的升级经验[{}]"); ErrorCode LEVEL_HAS_USER = new ErrorCode(1004011005, "用户等级下存在用户,无法删除"); - ErrorCode LEVEL_LOG_NOT_EXISTS = new ErrorCode(1004011100, "用户等级记录不存在"); - ErrorCode EXPERIENCE_LOG_NOT_EXISTS = new ErrorCode(1004011200, "用户经验记录不存在"); ErrorCode EXPERIENCE_BIZ_NOT_SUPPORT = new ErrorCode(1004011201, "用户经验业务类型不支持"); //========== 用户分组 1004012000 ========== diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java index 93cb886fb..d8cb54132 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java @@ -11,18 +11,20 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum MemberExperienceBizTypeEnum { + /** * 管理员调整、邀请新用户、下单、退单、签到、抽奖 */ - ADMIN(0, "管理员调整","管理员调整获得{}经验"), - INVITE_REGISTER(1, "邀新奖励","邀请好友获得{}经验"), - ORDER(2, "下单奖励", "下单获得{}经验"), - REFUND(3, "退单扣除","退单获得{}经验"), - SIGN_IN(4, "签到奖励","签到获得{}经验"), - LOTTERY(5, "抽奖奖励","抽奖获得{}经验"), + ADMIN(0, "管理员调整","管理员调整获得 {} 经验"), + INVITE_REGISTER(1, "邀新奖励","邀请好友获得 {} 经验"), + ORDER(2, "下单奖励", "下单获得 {} 经验"), + REFUND(3, "退单扣除","退单获得 {} 经验"), + SIGN_IN(4, "签到奖励","签到获得 {} 经验"), + LOTTERY(5, "抽奖奖励","抽奖获得 {} 经验"), ; - private final int value; + private final int type; private final String title; - private final String desc; + private final String description; + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index c7c7f0d1e..3d89663e7 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -24,12 +24,15 @@ public class MemberLevelApiImpl implements MemberLevelApi { @Resource private MemberLevelService memberLevelService; - public void plusExperience(Long userId, Integer experience, Integer bizType, String bizId) { - MemberExperienceBizTypeEnum bizTypeEnum = EnumUtil.getBy(MemberExperienceBizTypeEnum.class, e -> Objects.equals(bizType, e.getValue())); + @Override + public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) { + // TODO @疯狂:可以在 MemberExperienceBizTypeEnum 增加一个方法,获得哈。 + MemberExperienceBizTypeEnum bizTypeEnum = EnumUtil.getBy(MemberExperienceBizTypeEnum.class, + e -> Objects.equals(bizType, e.getType())); if (bizTypeEnum == null) { throw exception(EXPERIENCE_BIZ_NOT_SUPPORT); } - memberLevelService.addExperience(userId, experience, bizTypeEnum, bizId); } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java index be3efc5ba..cdbd76046 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberExperienceRecordController.java @@ -35,7 +35,7 @@ public class MemberExperienceRecordController { @Operation(summary = "获得会员经验记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('member:experience-record:query')") - public CommonResult getExperienceLog(@RequestParam("id") Long id) { + public CommonResult getExperienceRecord(@RequestParam("id") Long id) { MemberExperienceRecordDO experienceLog = experienceLogService.getExperienceRecord(id); return success(MemberExperienceRecordConvert.INSTANCE.convert(experienceLog)); } @@ -43,7 +43,8 @@ public class MemberExperienceRecordController { @GetMapping("/page") @Operation(summary = "获得会员经验记录分页") @PreAuthorize("@ss.hasPermission('member:experience-record:query')") - public CommonResult> getExperienceLogPage(@Valid MemberExperienceRecordPageReqVO pageVO) { + public CommonResult> getExperienceRecordPage( + @Valid MemberExperienceRecordPageReqVO pageVO) { PageResult pageResult = experienceLogService.getExperienceRecordPage(pageVO); return success(MemberExperienceRecordConvert.INSTANCE.convertPage(pageResult)); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java index 4ee2f1a08..05d133cbd 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/MemberLevelRecordController.java @@ -35,7 +35,7 @@ public class MemberLevelRecordController { @Operation(summary = "获得会员等级记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('member:level-record:query')") - public CommonResult getLevelLog(@RequestParam("id") Long id) { + public CommonResult getLevelRecord(@RequestParam("id") Long id) { MemberLevelRecordDO levelLog = levelLogService.getLevelRecord(id); return success(MemberLevelRecordConvert.INSTANCE.convert(levelLog)); } @@ -43,8 +43,10 @@ public class MemberLevelRecordController { @GetMapping("/page") @Operation(summary = "获得会员等级记录分页") @PreAuthorize("@ss.hasPermission('member:level-record:query')") - public CommonResult> getLevelLogPage(@Valid MemberLevelRecordPageReqVO pageVO) { + public CommonResult> getLevelRecordPage( + @Valid MemberLevelRecordPageReqVO pageVO) { PageResult pageResult = levelLogService.getLevelRecordPage(pageVO); return success(MemberLevelRecordConvert.INSTANCE.convertPage(pageResult)); } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java index 87502b278..348e78e8e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/level/vo/level/MemberLevelListReqVO.java @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.ToString; -@Schema(description = "管理后台 - 会员等级分页 Request VO") +@Schema(description = "管理后台 - 会员等级列表筛选 Request VO") @Data @ToString(callSuper = true) public class MemberLevelListReqVO { diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java index ccb9d5da5..e93aa0fde 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/MemberUserController.java @@ -25,10 +25,14 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 会员用户") @RestController @@ -79,26 +83,19 @@ public class MemberUserController { return success(PageResult.empty()); } - Set groupIds = new HashSet<>(pageResult.getList().size()); - // 处理用户标签返显 Set tagIds = pageResult.getList().stream() - .peek(m -> { - if (m.getGroupId() != null) { - groupIds.add(m.getGroupId()); - } - }) .map(MemberUserDO::getTagIds) .filter(Objects::nonNull) .flatMap(Collection::stream) .collect(Collectors.toSet()); List tags = memberTagService.getTagList(tagIds); - // 处理用户级别返显 - List levels = memberLevelService.getEnableLevelList(); + List levels = memberLevelService.getLevelList( + convertSet(pageResult.getList(), MemberUserDO::getLevelId)); // 处理用户分组返显 - List groups = memberGroupService.getGroupList(groupIds); - + List groups = memberGroupService.getGroupList( + convertSet(pageResult.getList(), MemberUserDO::getGroupId)); return success(MemberUserConvert.INSTANCE.convertPage(pageResult, tags, levels, groups)); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java index 73adc2dfd..21a67103d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java @@ -42,12 +42,10 @@ public interface MemberUserConvert { List levels, List groups) { PageResult result = convertPage(pageResult); - // 处理关联数据 Map tagMap = convertMap(tags, MemberTagDO::getId, MemberTagDO::getName); Map levelMap = convertMap(levels, MemberLevelDO::getId, MemberLevelDO::getName); Map groupMap = convertMap(groups, MemberGroupDO::getId, MemberGroupDO::getName); - // 填充关联数据 for (MemberUserRespVO vo : result.getList()) { vo.setTagNames(convertList(vo.getTagIds(), tagMap::get)); @@ -56,4 +54,5 @@ public interface MemberUserConvert { } return result; } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java index 93c241886..e0e24c776 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java @@ -69,6 +69,7 @@ public class MemberGroupServiceImpl implements MemberGroupService { } } + // TODO @疯狂:不要直接调用 memberUserMapper,需要对方 service 提供方法 void validateGroupHasUser(Long id) { Long count = memberUserMapper.selectCountByGroupId(id); if (count > 0) { diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java index 9653928a4..8e75acfac 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberExperienceRecordServiceImpl.java @@ -26,7 +26,6 @@ public class MemberExperienceRecordServiceImpl implements MemberExperienceRecord @Resource private MemberExperienceRecordMapper experienceLogMapper; - @Override public MemberExperienceRecordDO getExperienceRecord(Long id) { return experienceLogMapper.selectById(id); @@ -45,12 +44,11 @@ public class MemberExperienceRecordServiceImpl implements MemberExperienceRecord @Override public void createExperienceRecord(Long userId, Integer experience, Integer totalExperience, MemberExperienceBizTypeEnum bizType, String bizId) { - String description = StrUtil.format(bizType.getDesc(), experience); - MemberExperienceRecordDO recordDO = MemberExperienceRecordConvert.INSTANCE.convert(userId, - experience, totalExperience, - bizId, bizType.getValue(), bizType.getTitle(), - description); - experienceLogMapper.insert(recordDO); + String description = StrUtil.format(bizType.getDescription(), experience); + MemberExperienceRecordDO record = MemberExperienceRecordConvert.INSTANCE.convert( + userId, experience, totalExperience, + bizId, bizType.getType(), bizType.getTitle(), description); + experienceLogMapper.insert(record); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java index cdee7ddc7..d89ad3505 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordService.java @@ -4,9 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.level.vo.log.MemberLevelRecordPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; -import java.util.Collection; -import java.util.List; - /** * 会员等级记录 Service 接口 * @@ -22,14 +19,6 @@ public interface MemberLevelRecordService { */ MemberLevelRecordDO getLevelRecord(Long id); - /** - * 获得会员等级记录列表 - * - * @param ids 编号 - * @return 会员等级记录列表 - */ - List getLevelRecordList(Collection ids); - /** * 获得会员等级记录分页 * @@ -44,4 +33,5 @@ public interface MemberLevelRecordService { * @param levelRecord 会员等级记录 */ void createLevelRecord(MemberLevelRecordDO levelRecord); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java index 83926cd98..2f7f542d4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelRecordServiceImpl.java @@ -8,11 +8,6 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.LEVEL_LOG_NOT_EXISTS; /** * 会员等级记录 Service 实现类 @@ -26,22 +21,11 @@ public class MemberLevelRecordServiceImpl implements MemberLevelRecordService { @Resource private MemberLevelRecordMapper levelLogMapper; - private void validateLevelLogExists(Long id) { - if (levelLogMapper.selectById(id) == null) { - throw exception(LEVEL_LOG_NOT_EXISTS); - } - } - @Override public MemberLevelRecordDO getLevelRecord(Long id) { return levelLogMapper.selectById(id); } - @Override - public List getLevelRecordList(Collection ids) { - return levelLogMapper.selectBatchIds(ids); - } - @Override public PageResult getLevelRecordPage(MemberLevelRecordPageReqVO pageReqVO) { return levelLogMapper.selectPage(pageReqVO); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java index 11c75cd65..76d46e5c3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelService.java @@ -65,7 +65,6 @@ public interface MemberLevelService { */ List getLevelList(MemberLevelListReqVO listReqVO); - /** * 获得指定状态的会员等级列表 * @@ -74,7 +73,6 @@ public interface MemberLevelService { */ List getLevelListByStatus(Integer status); - /** * 获得开启状态的会员等级列表 * @@ -100,4 +98,5 @@ public interface MemberLevelService { * @param bizId 业务编号 */ void addExperience(Long userId, Integer experience, MemberExperienceBizTypeEnum bizType, String bizId); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index 6120b711a..fb9d5c663 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -25,6 +25,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -153,11 +154,12 @@ public class MemberLevelServiceImpl implements MemberLevelService { validateExperienceOutRange(list, id, level, experience); } + // TODO 有 Service 提供接口哈,不直接调用对方的 memberUserMapper @VisibleForTesting void validateLevelHasUser(Long id) { Long count = memberUserMapper.selectCountByLevelId(id); if (count > 0) { - throw exception(GROUP_HAS_USER); + throw exception(LEVEL_HAS_USER); } } @@ -168,6 +170,9 @@ public class MemberLevelServiceImpl implements MemberLevelService { @Override public List getLevelList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } return levelMapper.selectBatchIds(ids); } @@ -184,7 +189,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { @Override @Transactional(rollbackFor = Exception.class) public void updateUserLevel(MemberUserUpdateLevelReqVO updateReqVO) { - MemberUserDO user = memberUserMapper.selectById(updateReqVO.getId()); + MemberUserDO user = memberUserService.getUser(updateReqVO.getId()); if (user == null) { throw exception(USER_NOT_EXISTS); } @@ -193,6 +198,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { return; } + // 记录等级变动 MemberLevelRecordDO levelRecord = new MemberLevelRecordDO() .setUserId(user.getId()) .setRemark(updateReqVO.getReason()); @@ -211,17 +217,16 @@ public class MemberLevelServiceImpl implements MemberLevelService { levelRecord.setUserExperience(memberLevel.getExperience()); levelRecord.setDescription("管理员调整为:" + memberLevel.getName()); } - - // 记录等级变动 memberLevelRecordService.createLevelRecord(levelRecord); // 记录会员经验变动 memberExperienceRecordService.createExperienceRecord(user.getId(), levelRecord.getExperience(), levelRecord.getUserExperience(), - MemberExperienceBizTypeEnum.ADMIN, MemberExperienceBizTypeEnum.ADMIN.getValue() + ""); + MemberExperienceBizTypeEnum.ADMIN, String.valueOf(MemberExperienceBizTypeEnum.ADMIN.getType())); // 更新会员表上的等级编号、经验值 - memberUserService.updateLevelIdAndExperience(user.getId(), updateReqVO.getLevelId(), levelRecord.getUserExperience()); + memberUserService.updateUserLevel(user.getId(), updateReqVO.getLevelId(), + levelRecord.getUserExperience()); // 给会员发送等级变动消息 notifyMemberLevelChange(user.getId(), memberLevel); @@ -259,7 +264,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { } // 更新会员表上的等级编号、经验值 - memberUserService.updateLevelIdAndExperience(user.getId(), levelRecord.getLevelId(), userExperience); + memberUserService.updateUserLevel(user.getId(), levelRecord.getLevelId(), userExperience); } /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 8b7d7460a..2b8155184 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -133,5 +133,6 @@ public interface MemberUserService { * @param levelId 用户等级 * @param experience 用户经验 */ - void updateLevelIdAndExperience(Long id, Long levelId, Integer experience); + void updateUserLevel(Long id, Long levelId, Integer experience); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index c2918fd39..cfaaf22de 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.member.service.user; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -229,11 +230,9 @@ public class MemberUserServiceImpl implements MemberUserService { } @Override - public void updateLevelIdAndExperience(Long id, Long levelId, Integer experience) { - if (levelId == null) { - // 0 代表无等级:防止UpdateById时,会被过滤掉的问题 - levelId = 0L; - } + public void updateUserLevel(Long id, Long levelId, Integer experience) { + // 0 代表无等级:防止UpdateById时,会被过滤掉的问题 + levelId = ObjectUtil.defaultIfNull(levelId, 0L); memberUserMapper.updateById(new MemberUserDO() .setId(id) .setLevelId(levelId).setExperience(experience) From 65eddc63aff153078d6af3f35d2b93601145d961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=AE=E6=A2=A6?= Date: Thu, 24 Aug 2023 17:04:08 +0800 Subject: [PATCH 09/26] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=90=8E=E5=8F=B0=E7=94=A8=E6=88=B7=E6=94=B6=E4=BB=B6?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/address/AddressController.java | 102 ++++++++++++++++++ .../admin/address/vo/AddressBaseVO.java | 37 +++++++ .../admin/address/vo/AddressCreateReqVO.java | 14 +++ .../admin/address/vo/AddressExcelVO.java | 40 +++++++ .../admin/address/vo/AddressExportReqVO.java | 38 +++++++ .../admin/address/vo/AddressPageReqVO.java | 40 +++++++ .../admin/address/vo/AddressRespVO.java | 19 ++++ .../admin/address/vo/AddressUpdateReqVO.java | 18 ++++ .../convert/address/AddressConvert.java | 16 +++ .../dal/mysql/address/AddressMapper.java | 26 +++++ .../service/address/AddressService.java | 59 ++++++++++ .../service/address/AddressServiceImpl.java | 58 ++++++++++ 12 files changed, 467 insertions(+) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java new file mode 100644 index 000000000..3e6919e83 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.member.controller.admin.address; + +import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.member.controller.admin.address.vo.*; +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; +import cn.iocoder.yudao.module.member.service.address.AddressService; + +@Tag(name = "管理后台 - 用户收件地址") +@RestController +@RequestMapping("/member/address") +@Validated +public class AddressController { + + @Resource + private AddressService addressService; + + @PostMapping("/create") + @Operation(summary = "创建用户收件地址") + @PreAuthorize("@ss.hasPermission('member:address:create')") + public CommonResult createAddress(@Valid @RequestBody AddressCreateReqVO createReqVO) { + return success(addressService.createAddress(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新用户收件地址") + @PreAuthorize("@ss.hasPermission('member:address:update')") + public CommonResult updateAddress(@Valid @RequestBody AddressUpdateReqVO updateReqVO) { + addressService.updateAddress(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除用户收件地址") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('member:address:delete')") + public CommonResult deleteAddress(@RequestParam("id") Long id) { + addressService.deleteAddress(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得用户收件地址") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('member:address:query')") + public CommonResult getAddress(@RequestParam("id") Long id) { + MemberAddressDO address = addressService.getAddress(id); + return success(AddressConvert.INSTANCE.convert2(address)); + } + + @GetMapping("/list") + @Operation(summary = "获得用户收件地址列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('member:address:query')") + public CommonResult> getAddressList(@RequestParam("ids") Collection ids) { + List list = addressService.getAddressList(ids); + return success(AddressConvert.INSTANCE.convertList2(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得用户收件地址分页") + @PreAuthorize("@ss.hasPermission('member:address:query')") + public CommonResult> getAddressPage(@Valid AddressPageReqVO pageVO) { + PageResult pageResult = addressService.getAddressPage(pageVO); + return success(AddressConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出用户收件地址 Excel") + @PreAuthorize("@ss.hasPermission('member:address:export')") + @OperateLog(type = EXPORT) + public void exportAddressExcel(@Valid AddressExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = addressService.getAddressList(exportReqVO); + // 导出 Excel + List datas = AddressConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "用户收件地址.xls", "数据", AddressExcelVO.class, datas); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java new file mode 100644 index 000000000..5fa2d1ed9 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressBaseVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.util.*; +import javax.validation.constraints.*; + +/** + * 用户收件地址 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class AddressBaseVO { + + @Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @NotNull(message = "收件人名称不能为空") + private String name; + + @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "手机号不能为空") + private String mobile; + + @Schema(description = "地区编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "15716") + @NotNull(message = "地区编码不能为空") + private Long areaId; + + @Schema(description = "收件详细地址", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "收件详细地址不能为空") + private String detailAddress; + + @Schema(description = "是否默认", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "是否默认不能为空") + private Boolean defaultStatus; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java new file mode 100644 index 000000000..ac0833ba7 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户收件地址创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressCreateReqVO extends AddressBaseVO { + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java new file mode 100644 index 000000000..8a0543247 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 用户收件地址 Excel VO + * + * @author 绮梦 + */ +@Data +public class AddressExcelVO { + + @ExcelProperty("收件地址编号") + private Long id; + + @ExcelProperty("收件人名称") + private String name; + + @ExcelProperty("手机号") + private String mobile; + + @ExcelProperty("地区编码") + private Long areaId; + + @ExcelProperty("收件详细地址") + private String detailAddress; + + @ExcelProperty("是否默认") + private Boolean defaultStatus; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java new file mode 100644 index 000000000..214bf952b --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import java.time.LocalDateTime; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户收件地址 Excel 导出 Request VO,参数和 AddressPageReqVO 是一致的") +@Data +public class AddressExportReqVO { + + @Schema(description = "用户编号", example = "20369") + private Long userId; + + @Schema(description = "收件人名称", example = "张三") + private String name; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "地区编码", example = "15716") + private Long areaId; + + @Schema(description = "收件详细地址") + private String detailAddress; + + @Schema(description = "是否默认", example = "2") + private Boolean defaultStatus; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java new file mode 100644 index 000000000..32b059448 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户收件地址分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressPageReqVO extends PageParam { + + @Schema(description = "用户编号", example = "20369") + private Long userId; + + @Schema(description = "收件人名称", example = "张三") + private String name; + + @Schema(description = "手机号") + private String mobile; + + @Schema(description = "地区编码", example = "15716") + private Long areaId; + + @Schema(description = "收件详细地址") + private String detailAddress; + + @Schema(description = "是否默认", example = "2") + private Boolean defaultStatus; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java new file mode 100644 index 000000000..26a4988af --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 用户收件地址 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressRespVO extends AddressBaseVO { + + @Schema(description = "收件地址编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7380") + private Long id; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java new file mode 100644 index 000000000..4e91579e4 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.member.controller.admin.address.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户收件地址更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AddressUpdateReqVO extends AddressBaseVO { + + @Schema(description = "收件地址编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7380") + @NotNull(message = "收件地址编号不能为空") + private Long id; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java index 8e62de604..e6f56a022 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java @@ -1,7 +1,12 @@ package cn.iocoder.yudao.module.member.convert.address; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExcelVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressRespVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressRespVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; @@ -39,4 +44,15 @@ public interface AddressConvert { return AreaUtils.format(areaId); } + MemberAddressDO convert(AddressCreateReqVO bean); + + MemberAddressDO convert(AddressUpdateReqVO bean); + + AddressRespVO convert2(MemberAddressDO bean); + + List convertList2(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java index db824f6f5..9beb025c0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.member.dal.mysql.address; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import org.apache.ibatis.annotations.Mapper; @@ -18,5 +21,28 @@ public interface AddressMapper extends BaseMapperX { return selectList(new LambdaQueryWrapperX().eq(MemberAddressDO::getUserId, userId) .eqIfPresent(MemberAddressDO::getDefaultStatus, defaulted)); } + default PageResult selectPage(AddressPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MemberAddressDO::getUserId, reqVO.getUserId()) + .likeIfPresent(MemberAddressDO::getName, reqVO.getName()) + .eqIfPresent(MemberAddressDO::getMobile, reqVO.getMobile()) + .eqIfPresent(MemberAddressDO::getAreaId, reqVO.getAreaId()) + .eqIfPresent(MemberAddressDO::getDetailAddress, reqVO.getDetailAddress()) + .eqIfPresent(MemberAddressDO::getDefaultStatus, reqVO.getDefaultStatus()) + .betweenIfPresent(MemberAddressDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberAddressDO::getId)); + } + + default List selectList(AddressExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(MemberAddressDO::getUserId, reqVO.getUserId()) + .likeIfPresent(MemberAddressDO::getName, reqVO.getName()) + .eqIfPresent(MemberAddressDO::getMobile, reqVO.getMobile()) + .eqIfPresent(MemberAddressDO::getAreaId, reqVO.getAreaId()) + .eqIfPresent(MemberAddressDO::getDetailAddress, reqVO.getDetailAddress()) + .eqIfPresent(MemberAddressDO::getDefaultStatus, reqVO.getDefaultStatus()) + .betweenIfPresent(MemberAddressDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(MemberAddressDO::getId)); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java index 099c49c42..260ab7987 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java @@ -1,10 +1,16 @@ package cn.iocoder.yudao.module.member.service.address; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import javax.validation.Valid; +import java.util.Collection; import java.util.List; /** @@ -64,4 +70,57 @@ public interface AddressService { */ MemberAddressDO getDefaultUserAddress(Long userId); + /** + * 创建用户收件地址 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createAddress(@Valid AddressCreateReqVO createReqVO); + + /** + * 更新用户收件地址 + * + * @param updateReqVO 更新信息 + */ + void updateAddress(@Valid AddressUpdateReqVO updateReqVO); + + /** + * 删除用户收件地址 + * + * @param id 编号 + */ + void deleteAddress(Long id); + + /** + * 获得用户收件地址 + * + * @param id 编号 + * @return 用户收件地址 + */ + MemberAddressDO getAddress(Long id); + + /** + * 获得用户收件地址列表 + * + * @param ids 编号 + * @return 用户收件地址列表 + */ + List getAddressList(Collection ids); + + /** + * 获得用户收件地址分页 + * + * @param pageReqVO 分页查询 + * @return 用户收件地址分页 + */ + PageResult getAddressPage(AddressPageReqVO pageReqVO); + + /** + * 获得用户收件地址列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 用户收件地址列表 + */ + List getAddressList(AddressExportReqVO exportReqVO); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java index 2689177ea..79f129b75 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java @@ -1,6 +1,11 @@ package cn.iocoder.yudao.module.member.service.address; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.convert.address.AddressConvert; @@ -11,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -94,4 +100,56 @@ public class AddressServiceImpl implements AddressService { return CollUtil.getFirst(addresses); } + @Override + public Long createAddress(AddressCreateReqVO createReqVO) { + // 插入 + MemberAddressDO address = AddressConvert.INSTANCE.convert(createReqVO); + addressMapper.insert(address); + // 返回 + return address.getId(); + } + + @Override + public void updateAddress(AddressUpdateReqVO updateReqVO) { + // 校验存在 + validateAddressExists(updateReqVO.getId()); + // 更新 + MemberAddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO); + addressMapper.updateById(updateObj); + } + + @Override + public void deleteAddress(Long id) { + // 校验存在 + validateAddressExists(id); + // 删除 + addressMapper.deleteById(id); + } + + private void validateAddressExists(Long id) { + if (addressMapper.selectById(id) == null) { + throw exception(ADDRESS_NOT_EXISTS); + } + } + + @Override + public MemberAddressDO getAddress(Long id) { + return addressMapper.selectById(id); + } + + @Override + public List getAddressList(Collection ids) { + return addressMapper.selectBatchIds(ids); + } + + @Override + public PageResult getAddressPage(AddressPageReqVO pageReqVO) { + return addressMapper.selectPage(pageReqVO); + } + + @Override + public List getAddressList(AddressExportReqVO exportReqVO) { + return addressMapper.selectList(exportReqVO); + } + } From 2132de9dd1e2edfa849794404f707700b0df679b Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 25 Aug 2023 21:02:49 +0800 Subject: [PATCH 10/26] =?UTF-8?q?=E5=95=86=E5=93=81=EF=BC=9A=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=90=8E=E5=8F=B0=E5=95=86=E5=93=81=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/ProductCommentController.java | 14 ++++++-- .../comment/vo/ProductCommentBaseVO.java | 2 -- .../comment/vo/ProductCommentRespVO.java | 2 ++ .../comment/ProductCommentConvert.java | 36 +++++++++++++++++-- .../mysql/comment/ProductCommentMapper.java | 1 + .../comment/ProductCommentServiceImpl.java | 30 ++++++++++------ .../service/sku/ProductSkuServiceImpl.java | 4 +++ 7 files changed, 73 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index 91020a51c..bac915a0f 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; +import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; @@ -14,8 +16,10 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - 商品评价") @@ -26,13 +30,19 @@ public class ProductCommentController { @Resource private ProductCommentService productCommentService; + @Resource + private ProductSkuService productSkuService; @GetMapping("/page") @Operation(summary = "获得商品评价分页") @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { PageResult pageResult = productCommentService.getCommentPage(pageVO); - return success(ProductCommentConvert.INSTANCE.convertPage(pageResult)); + + List skuList = productSkuService.getSkuList( + convertSet(pageResult.getList(), ProductCommentDO::getSkuId)); + + return success(ProductCommentConvert.INSTANCE.convertPage(pageResult, skuList)); } @PutMapping("/update-visible") @@ -51,7 +61,7 @@ public class ProductCommentController { return success(true); } - @PutMapping("/create") + @PostMapping("/create") @Operation(summary = "添加自评") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java index 24d6a5456..f88f5ed68 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java @@ -11,11 +11,9 @@ import java.util.List; public class ProductCommentBaseVO { @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868") - @NotNull(message = "评价人不能为空") private Long userId; @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292") - @NotNull(message = "评价订单项不能为空") private Long orderItemId; @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java index 9205e34cc..8e3c732a5 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java @@ -52,4 +52,6 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { @NotNull(message = "商品 SPU 名称不能为空") private String spuName; + @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg") + private String skuPicUrl; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index cabc79a7d..216212b2e 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.convert.comment; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; @@ -23,6 +22,11 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; /** * 商品评价 Convert @@ -60,7 +64,7 @@ public interface ProductCommentConvert { item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); } // 设置 SKU 规格值 - MapUtils.findAndThen(skuMap, item.getSkuId(), + findAndThen(skuMap, item.getSkuId(), sku -> item.setSkuProperties(convertList01(sku.getProperties()))); }); return page; @@ -101,6 +105,8 @@ public interface ProductCommentConvert { return commentDO; } + @Mapping(target = "visible", constant = "true") + @Mapping(target = "replyStatus", constant = "false") @Mapping(target = "userId", constant = "0L") @Mapping(target = "orderId", constant = "0L") @Mapping(target = "orderItemId", constant = "0L") @@ -111,4 +117,30 @@ public interface ProductCommentConvert { List convertList02(List list); + default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO) { + ProductCommentDO commentDO = convert(createReq); + if (spuDO != null) { + commentDO.setSpuId(spuDO.getId()); + commentDO.setSpuName(spuDO.getName()); + } + return commentDO; + } + + default PageResult convertPage(PageResult pageResult, List skuList) { + Map skuMap = convertMap(skuList, ProductSkuDO::getId); + + PageResult result = convertPage(pageResult); + for (ProductCommentRespVO vo : result.getList()) { + findAndThen(skuMap, vo.getSkuId(), sku -> { + String propertyNames = sku.getProperties().stream() + .map(ProductSkuDO.Property::getValueName) + .filter(Objects::nonNull) + .collect(Collectors.joining(" ")); + + vo.setSkuPicUrl(sku.getPicUrl()); + vo.setSpuName(vo.getSpuName() + " " + propertyNames); + }); + } + return result; + } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java index c933c4370..095cd655b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java @@ -20,6 +20,7 @@ public interface ProductCommentMapper extends BaseMapperX { .eqIfPresent(ProductCommentDO::getOrderId, reqVO.getOrderId()) .eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId()) .eqIfPresent(ProductCommentDO::getScores, reqVO.getScores()) + .eqIfPresent(ProductCommentDO::getReplyStatus, reqVO.getReplyStatus()) .betweenIfPresent(ProductCommentDO::getCreateTime, reqVO.getCreateTime()) .likeIfPresent(ProductCommentDO::getSpuName, reqVO.getSpuName()) .orderByDesc(ProductCommentDO::getId)); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index 97a3d1562..05d5b02cd 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java @@ -80,23 +80,18 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override @Transactional(rollbackFor = Exception.class) public void createComment(ProductCommentCreateReqVO createReqVO) { - // 校验评论 - validateComment(createReqVO.getSkuId(), createReqVO.getUserId(), createReqVO.getOrderItemId()); + // 校验商品 + ProductSpuDO spuDO = validateProduct(createReqVO.getSkuId()); - ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO); + ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO); productCommentMapper.insert(commentDO); } @Override @Transactional(rollbackFor = Exception.class) public Long createComment(ProductCommentCreateReqDTO createReqDTO) { - // 通过 sku ID 拿到 spu 相关信息 - ProductSkuDO sku = productSkuService.getSku(createReqDTO.getSkuId()); - if (sku == null) { - throw exception(SKU_NOT_EXISTS); - } - // 校验 spu 如果存在返回详情 - ProductSpuDO spuDO = validateSpu(sku.getSpuId()); + // 校验商品 + ProductSpuDO spuDO = validateProduct(createReqDTO.getSkuId()); // 校验评论 validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId()); // 获取用户详细信息 @@ -116,6 +111,21 @@ public class ProductCommentServiceImpl implements ProductCommentService { } } + private ProductSpuDO validateProduct(Long skuId) { + // 通过 sku ID 拿到 spu 相关信息 + ProductSkuDO sku = validateSku(skuId); + // 校验 spu 如果存在返回详情 + return validateSpu(sku.getSpuId()); + } + + private ProductSkuDO validateSku(Long skuId) { + ProductSkuDO sku = productSkuService.getSku(skuId); + if (sku == null) { + throw exception(SKU_NOT_EXISTS); + } + return sku; + } + private ProductSpuDO validateSpu(Long spuId) { ProductSpuDO spu = productSpuService.getSpu(spuId); if (null == spu) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 7c6c5030e..cd0ba6b46 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.product.service.sku; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; @@ -74,6 +75,9 @@ public class ProductSkuServiceImpl implements ProductSkuService { @Override public List getSkuList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return ListUtil.empty(); + } return productSkuMapper.selectBatchIds(ids); } From 9aee08ee0e8bdccfeca29c5711082608d9374362 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 25 Aug 2023 21:12:31 +0800 Subject: [PATCH 11/26] =?UTF-8?q?=E4=BC=9A=E5=91=98=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9Review=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/MemberExperienceBizTypeEnum.java | 17 ++++++--- .../member/api/level/MemberLevelApiImpl.java | 6 +-- .../service/group/MemberGroupServiceImpl.java | 7 ++-- .../service/level/MemberLevelServiceImpl.java | 7 +--- .../service/tag/MemberTagServiceImpl.java | 6 +-- .../service/user/MemberUserService.java | 37 +++++++++++++++---- .../service/user/MemberUserServiceImpl.java | 15 ++++++++ 7 files changed, 66 insertions(+), 29 deletions(-) diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java index d8cb54132..fcd0f6e7a 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.module.member.enums; +import cn.hutool.core.util.EnumUtil; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Objects; + /** * 会员经验 - 业务类型 * @@ -15,16 +18,20 @@ public enum MemberExperienceBizTypeEnum { /** * 管理员调整、邀请新用户、下单、退单、签到、抽奖 */ - ADMIN(0, "管理员调整","管理员调整获得 {} 经验"), - INVITE_REGISTER(1, "邀新奖励","邀请好友获得 {} 经验"), + ADMIN(0, "管理员调整", "管理员调整获得 {} 经验"), + INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验"), ORDER(2, "下单奖励", "下单获得 {} 经验"), - REFUND(3, "退单扣除","退单获得 {} 经验"), - SIGN_IN(4, "签到奖励","签到获得 {} 经验"), - LOTTERY(5, "抽奖奖励","抽奖获得 {} 经验"), + REFUND(3, "退单扣除", "退单获得 {} 经验"), + SIGN_IN(4, "签到奖励", "签到获得 {} 经验"), + LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验"), ; private final int type; private final String title; private final String description; + public static MemberExperienceBizTypeEnum getByType(Integer type) { + return EnumUtil.getBy(MemberExperienceBizTypeEnum.class, + e -> Objects.equals(type, e.getType())); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index 3d89663e7..3cd2cad65 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.member.api.level; -import cn.hutool.core.util.EnumUtil; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.EXPERIENCE_BIZ_NOT_SUPPORT; @@ -26,9 +24,7 @@ public class MemberLevelApiImpl implements MemberLevelApi { @Override public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) { - // TODO @疯狂:可以在 MemberExperienceBizTypeEnum 增加一个方法,获得哈。 - MemberExperienceBizTypeEnum bizTypeEnum = EnumUtil.getBy(MemberExperienceBizTypeEnum.class, - e -> Objects.equals(bizType, e.getType())); + MemberExperienceBizTypeEnum bizTypeEnum = MemberExperienceBizTypeEnum.getByType(bizType); if (bizTypeEnum == null) { throw exception(EXPERIENCE_BIZ_NOT_SUPPORT); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java index e0e24c776..98ec3cc85 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/group/MemberGroupServiceImpl.java @@ -9,7 +9,7 @@ import cn.iocoder.yudao.module.member.controller.admin.group.vo.MemberGroupUpdat import cn.iocoder.yudao.module.member.convert.group.MemberGroupConvert; import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO; import cn.iocoder.yudao.module.member.dal.mysql.group.MemberGroupMapper; -import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; +import cn.iocoder.yudao.module.member.service.user.MemberUserService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -33,7 +33,7 @@ public class MemberGroupServiceImpl implements MemberGroupService { @Resource private MemberGroupMapper groupMapper; @Resource - private MemberUserMapper memberUserMapper; + private MemberUserService memberUserService; @Override public Long createGroup(MemberGroupCreateReqVO createReqVO) { @@ -69,9 +69,8 @@ public class MemberGroupServiceImpl implements MemberGroupService { } } - // TODO @疯狂:不要直接调用 memberUserMapper,需要对方 service 提供方法 void validateGroupHasUser(Long id) { - Long count = memberUserMapper.selectCountByGroupId(id); + Long count = memberUserService.getUserCountByGroupId(id); if (count > 0) { throw exception(GROUP_HAS_USER); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index fb9d5c663..d46465554 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelRecordDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.level.MemberLevelMapper; -import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.member.service.user.MemberUserService; import com.google.common.annotations.VisibleForTesting; @@ -49,8 +48,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { @Resource private MemberExperienceRecordService memberExperienceRecordService; @Resource - private MemberUserMapper memberUserMapper; - @Resource private MemberUserService memberUserService; @Override @@ -157,7 +154,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { // TODO 有 Service 提供接口哈,不直接调用对方的 memberUserMapper @VisibleForTesting void validateLevelHasUser(Long id) { - Long count = memberUserMapper.selectCountByLevelId(id); + Long count = memberUserService.getUserCountByLevelId(id); if (count > 0) { throw exception(LEVEL_HAS_USER); } @@ -239,7 +236,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { return; } - MemberUserDO user = memberUserMapper.selectById(userId); + MemberUserDO user = memberUserService.getUser(userId); int userExperience = NumberUtil.max(user.getExperience() + experience, 0); MemberLevelRecordDO levelRecord = new MemberLevelRecordDO() diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java index 93e09d747..d176bcabb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/tag/MemberTagServiceImpl.java @@ -10,7 +10,7 @@ import cn.iocoder.yudao.module.member.controller.admin.tag.vo.MemberTagUpdateReq import cn.iocoder.yudao.module.member.convert.tag.MemberTagConvert; import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO; import cn.iocoder.yudao.module.member.dal.mysql.tag.MemberTagMapper; -import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; +import cn.iocoder.yudao.module.member.service.user.MemberUserService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -33,7 +33,7 @@ public class MemberTagServiceImpl implements MemberTagService { @Resource private MemberTagMapper tagMapper; @Resource - private MemberUserMapper memberUserMapper; + private MemberUserService memberUserService; @Override public Long createTag(MemberTagCreateReqVO createReqVO) { @@ -92,7 +92,7 @@ public class MemberTagServiceImpl implements MemberTagService { } void validateTagHasUser(Long id) { - Long count = memberUserMapper.selectCountByTagId(id); + Long count = memberUserService.getUserCountByTagId(id); if (count > 0) { throw exception(TAG_HAS_USER); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 2b8155184..7a0c13380 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -5,9 +5,9 @@ import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserResetPasswordReqVO; +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateMobileReqVO; import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdatePasswordReqVO; import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateReqVO; -import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateMobileReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import javax.validation.Valid; @@ -41,7 +41,7 @@ public interface MemberUserService { * 基于手机号创建用户。 * 如果用户已经存在,则直接进行返回 * - * @param mobile 手机号 + * @param mobile 手机号 * @param registerIp 注册 IP * @return 用户对象 */ @@ -50,7 +50,7 @@ public interface MemberUserService { /** * 更新用户的最后登陆信息 * - * @param id 用户编号 + * @param id 用户编号 * @param loginIp 登陆 IP */ void updateUserLogin(Long id, String loginIp); @@ -75,7 +75,7 @@ public interface MemberUserService { * 【会员】修改基本信息 * * @param userId 用户编号 - * @param reqVO 基本信息 + * @param reqVO 基本信息 */ void updateUser(Long userId, AppMemberUserUpdateReqVO reqVO); @@ -83,7 +83,7 @@ public interface MemberUserService { * 【会员】修改手机 * * @param userId 用户编号 - * @param reqVO 请求信息 + * @param reqVO 请求信息 */ void updateUserMobile(Long userId, AppMemberUserUpdateMobileReqVO reqVO); @@ -91,7 +91,7 @@ public interface MemberUserService { * 【会员】修改密码 * * @param userId 用户编号 - * @param reqVO 请求信息 + * @param reqVO 请求信息 */ void updateUserPassword(Long userId, AppMemberUserUpdatePasswordReqVO reqVO); @@ -105,7 +105,7 @@ public interface MemberUserService { /** * 判断密码是否匹配 * - * @param rawPassword 未加密的密码 + * @param rawPassword 未加密的密码 * @param encodedPassword 加密后的密码 * @return 是否匹配 */ @@ -135,4 +135,27 @@ public interface MemberUserService { */ void updateUserLevel(Long id, Long levelId, Integer experience); + /** + * 获得指定用户分组下的用户数量 + * + * @param groupId 用户分组编号 + * @return 用户数量 + */ + Long getUserCountByGroupId(Long groupId); + + /** + * 获得指定用户等级下的用户数量 + * + * @param levelId 用户等级编号 + * @return 用户数量 + */ + Long getUserCountByLevelId(Long levelId); + + /** + * 获得指定会员标签下的用户数量 + * + * @param tagId 用户标签编号 + * @return 用户数量 + */ + Long getUserCountByTagId(Long tagId); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index cfaaf22de..152f87cad 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -239,4 +239,19 @@ public class MemberUserServiceImpl implements MemberUserService { ); } + @Override + public Long getUserCountByGroupId(Long groupId) { + return memberUserMapper.selectCountByGroupId(groupId); + } + + @Override + public Long getUserCountByLevelId(Long levelId) { + return memberUserMapper.selectCountByLevelId(levelId); + } + + @Override + public Long getUserCountByTagId(Long tagId) { + return memberUserMapper.selectCountByTagId(tagId); + } + } From 1ffbd9399ebd0f04f13be28da5f3d9d90a5a11d1 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Fri, 25 Aug 2023 11:14:59 +0800 Subject: [PATCH 12/26] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=BE=97?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=92=B1=E5=8C=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 44 ++++++++++ ...tegoryEnum.java => WalletBizTypeEnum.java} | 13 +-- ...erateTypeEnum.java => WalletTypeEnum.java} | 9 +- .../app/wallet/AppPayWalletController.java | 41 +++++++++ .../app/wallet/vo/AppPayWalletRespVO.java | 21 +++++ .../pay/convert/wallet/PayWalletConvert.java | 14 +++ .../member/MemberWalletTransactionDO.java | 86 ------------------- .../PayWalletDO.java} | 22 +++-- .../wallet/PayWalletTransactionDO.java | 79 +++++++++++++++++ .../dal/mysql/member/MemberWalletMapper.java | 15 ---- .../member/MemberWalletTransactionMapper.java | 15 ---- .../pay/dal/mysql/wallet/PayWalletMapper.java | 18 ++++ .../wallet/PayWalletTransactionMapper.java | 15 ++++ .../pay/service/wallet/PayWalletService.java | 18 ++++ .../service/wallet/PayWalletServiceImpl.java | 24 ++++++ 15 files changed, 299 insertions(+), 135 deletions(-) create mode 100644 sql/mysql/pay_wallet.sql rename yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/{WalletTransactionGategoryEnum.java => WalletBizTypeEnum.java} (54%) rename yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/{WalletOperateTypeEnum.java => WalletTypeEnum.java} (58%) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletRespVO.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletConvert.java delete mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletTransactionDO.java rename yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/{member/MemberWalletDO.java => wallet/PayWalletDO.java} (55%) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java delete mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletMapper.java delete mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletTransactionMapper.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql new file mode 100644 index 000000000..4be65ffdd --- /dev/null +++ b/sql/mysql/pay_wallet.sql @@ -0,0 +1,44 @@ +-- ---------------------------- +-- 支付-钱包表 +-- ---------------------------- +DROP TABLE IF EXISTS `pay_wallet`; +CREATE TABLE `pay_wallet` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `user_id` bigint NOT NULL COMMENT '用户 id', + `user_type` tinyint NOT NULL DEFAULT 0 COMMENT '用户类型', + `balance` int NOT NULL DEFAULT 0 COMMENT '余额, 单位分', + `total_expense` bigint NOT NULL DEFAULT 0 COMMENT '累计支出, 单位分', + `total_recharge` bigint NOT NULL DEFAULT 0 COMMENT '累计充值, 单位分', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB COMMENT='支付钱包表'; + +-- ---------------------------- +-- 支付- 钱包余额明细表 +-- ---------------------------- +DROP TABLE IF EXISTS `pay_wallet_transaction`; +CREATE TABLE `pay_wallet_transaction` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', + `user_id` bigint NOT NULL COMMENT '用户 id', + `biz_type` tinyint NOT NULL COMMENT '关联类型', + `biz_id` bigint NOT NULL COMMENT '关联业务编号', + `no` varchar(64) NOT NULL COMMENT '流水号', + `description` varchar(255) COMMENT '操作说明', + `amount` int NOT NULL COMMENT '交易金额, 单位分', + `balance` int NOT NULL COMMENT '余额, 单位分', + `transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB COMMENT='支付钱包余额明细表'; \ No newline at end of file diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionGategoryEnum.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java similarity index 54% rename from yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionGategoryEnum.java rename to yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java index fe950991d..b39ed9d09 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionGategoryEnum.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java @@ -4,20 +4,21 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * 钱包交易大类枚举 + * 钱包交易业务分类 * * @author jason */ @AllArgsConstructor @Getter -public enum WalletTransactionGategoryEnum { - TOP_UP(1, "充值"), - SPENDING(2, "支出"); +public enum WalletBizTypeEnum { + RECHARGE(1, "充值"), + RECHARGE_REFUND(2, "充值退款"); + // TODO 后续增加 /** - * 分类 + * 业务分类 */ - private final Integer category; + private final Integer bizType; /** * 说明 diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletOperateTypeEnum.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java similarity index 58% rename from yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletOperateTypeEnum.java rename to yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java index 896e90ef9..87cd1b96b 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletOperateTypeEnum.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java @@ -4,16 +4,15 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * 钱包操作类型枚举 + * 钱包交易大分类 * * @author jason */ @AllArgsConstructor @Getter -public enum WalletOperateTypeEnum { - TOP_UP_INC(1, "充值增加"), - ORDER_DEC(2, "订单消费扣除"); - // TODO 其它类型 +public enum WalletTypeEnum { + RECHARGE(1, "充值"), + EXPENSE(2, "消费"); private final Integer type; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java new file mode 100644 index 000000000..98417876b --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet; + +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletRespVO; +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; + +/** + * @author jason + */ +@Tag(name = "用户 APP - 支付钱包") +@RestController +@RequestMapping("/pay/wallet") +@Validated +@Slf4j +public class AppPayWalletController { + + @Resource + private PayWalletService payWalletService; + + @GetMapping("/get") + @Operation(summary = "获取支付钱包") + public CommonResult getPayWallet() { + PayWalletDO payWallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); + return success(PayWalletConvert.INSTANCE.convert(payWallet)); + } +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletRespVO.java new file mode 100644 index 000000000..508c565aa --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @author jason + */ +@Schema(description = "用户 APP - 获取用户钱包 Response VO") +@Data +public class AppPayWalletRespVO { + + @Schema(description = "钱包余额,单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private Integer balance; + + @Schema(description = "累计支出, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + private Long totalExpense; + + @Schema(description = "累计充值, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + private Long totalRecharge; +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletConvert.java new file mode 100644 index 000000000..49ec734be --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletConvert.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.pay.convert.wallet; + +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletRespVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PayWalletConvert { + + PayWalletConvert INSTANCE = Mappers.getMapper(PayWalletConvert.class); + + AppPayWalletRespVO convert(PayWalletDO bean); +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletTransactionDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletTransactionDO.java deleted file mode 100644 index 82ede2915..000000000 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletTransactionDO.java +++ /dev/null @@ -1,86 +0,0 @@ -package cn.iocoder.yudao.module.pay.dal.dataobject.member; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.pay.enums.member.WalletOperateTypeEnum; -import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionGategoryEnum; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 支付-会员钱包明细 DO - * - * @author jason - */ -@TableName(value ="pay_member_wallet_transaction") -@KeySequence("pay_member_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -public class MemberWalletTransactionDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - - /** - * 会员钱包 id - * - * 关联 {@link MemberWalletDO#getId()} - */ - private Long walletId; - - /** - * 用户 id - * - * 关联 MemberUserDO 的 id 编号 - */ - private Long userId; - - /** - * 交易单号 @芋艿 这里是关联交易单号, 还是订单号 , 退款单号! ?? - */ - private String tradeNo; - - /** - * 交易分类 - * - * 枚举 {@link WalletTransactionGategoryEnum#getCategory()} - */ - private Integer category; - - /** - * 操作分类 - * - * 枚举 {@link WalletOperateTypeEnum#getType()} - */ - private Integer operateType; - - /** - * 操作详情 - */ - private String operateDesc; - - /** - * 交易金额, 单位分 - */ - private Integer price; - - /** - * 余额, 单位分 - */ - private Integer balance; - - /** - * 备注 - */ - private String mark; - - /** - * 交易时间 - */ - private LocalDateTime transactionTime; -} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java similarity index 55% rename from yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletDO.java rename to yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java index e6e92bf82..d914c2f14 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/member/MemberWalletDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java @@ -1,21 +1,21 @@ -package cn.iocoder.yudao.module.pay.dal.dataobject.member; +package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; -// TODO @jason:修改 MemberWalletDO 为 PayWalletDO /** * 支付 - 会员钱包 DO * * @author jason */ -@TableName(value ="pay_member_wallet") -@KeySequence("pay_member_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@TableName(value ="pay_wallet") +@KeySequence("pay_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data -public class MemberWalletDO extends BaseDO { +public class PayWalletDO extends BaseDO { /** * 编号 @@ -23,7 +23,6 @@ public class MemberWalletDO extends BaseDO { @TableId private Long id; - // TODO @jaosn:增加 userType 字段; /** * 用户 id * @@ -32,6 +31,13 @@ public class MemberWalletDO extends BaseDO { */ private Long userId; + /** + * 用户类型, 预留 多商户转帐可能需要用到 + * + * 关联 {@link UserTypeEnum} + */ + private Integer userType; + /** * 余额, 单位分 */ @@ -40,10 +46,10 @@ public class MemberWalletDO extends BaseDO { /** * 累计支出, 单位分 */ - private Integer totalSpending; + private Long totalExpense; /** * 累计充值, 单位分 */ - private Integer totalTopUp; + private Long totalRecharge; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java new file mode 100644 index 000000000..c8340badc --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 支付-会员钱包明细 DO + * + * @author jason + */ +@TableName(value ="pay_wallet_transaction") +@KeySequence("pay_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +public class PayWalletTransactionDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + + /** + * 会员钱包 id + * + * 关联 {@link PayWalletDO#getId()} + */ + private Long walletId; + + /** + * 用户 id + * + * 关联 MemberUserDO 的 id 编号 + */ + private Long userId; + + /** + * 关联业务 + * + * 枚举 {@link WalletBizTypeEnum#getBizType()} + */ + private Integer bizType; + + /** + * 关联业务编号 + */ + private Long bizId; + + /** + * 流水号 + */ + private String no; + + /** + * 附加说明 + */ + private String description; + + /** + * 交易金额, 单位分 + * 正值表示余额增加,负值表示余额减少 + */ + private Integer amount; + + /** + * 交易后余额,单位分 + */ + private Integer balance; + + /** + * 交易时间 + */ + private LocalDateTime transactionTime; +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletMapper.java deleted file mode 100644 index 46e80df8e..000000000 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletMapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.pay.dal.mysql.member; - - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.pay.dal.dataobject.member.MemberWalletDO; -import org.apache.ibatis.annotations.Mapper; - -@Mapper -public interface MemberWalletMapper extends BaseMapperX { - -} - - - - diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletTransactionMapper.java deleted file mode 100644 index a6cb541d1..000000000 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/member/MemberWalletTransactionMapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.pay.dal.mysql.member; - - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.pay.dal.dataobject.member.MemberWalletTransactionDO; -import org.apache.ibatis.annotations.Mapper; - -@Mapper -public interface MemberWalletTransactionMapper extends BaseMapperX { - -} - - - - diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java new file mode 100644 index 000000000..d7d00a111 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.pay.dal.mysql.wallet; + + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface PayWalletMapper extends BaseMapperX { + + default PayWalletDO selectByUserIdAndType(Long userId, Integer userType) { + return selectOne(PayWalletDO::getUserId, userId, PayWalletDO::getUserType, userType); + } +} + + + + diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java new file mode 100644 index 000000000..5e9ab5301 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.pay.dal.mysql.wallet; + + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface PayWalletTransactionMapper extends BaseMapperX { + +} + + + + diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java new file mode 100644 index 000000000..7db829cf1 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.pay.service.wallet; + +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; + +/** + * 支付钱包 Service 接口 + * + * @author jason + */ +public interface PayWalletService { + + /** + * 得到用户的支付钱包 + * @param userId 用户 id + * @param userType 用户类型 + */ + PayWalletDO getPayWallet(Long userId, Integer userType); +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java new file mode 100644 index 000000000..34ae5613b --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.pay.service.wallet; + +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 支付钱包 Service 实现类 + * + * @author jason + */ +@Service +public class PayWalletServiceImpl implements PayWalletService { + + @Resource + private PayWalletMapper payWalletMapper; + + @Override + public PayWalletDO getPayWallet(Long userId, Integer userType) { + return payWalletMapper.selectByUserIdAndType(userId, userType); + } +} From f33b66558c3b2047827cab1b155a16d518c9b0ed Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Fri, 25 Aug 2023 22:08:30 +0800 Subject: [PATCH 13/26] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E4=BD=99=E9=A2=9D=E6=98=8E=E7=BB=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 2 +- .../module/pay/enums/ErrorCodeConstants.java | 3 ++ .../WalletTransactionQueryTypeEnum.java | 35 +++++++++++++++ .../pay/enums/member/WalletTypeEnum.java | 20 --------- .../app/wallet/AppPayWalletController.java | 4 +- .../AppPayWalletTransactionController.java | 43 +++++++++++++++++++ .../vo/AppPayWalletTransactionPageReqVO.java | 16 +++++++ .../vo/AppPayWalletTransactionRespVO.java | 19 ++++++++ .../wallet/PayWalletTransactionConvert.java | 15 +++++++ .../wallet/PayWalletTransactionDO.java | 13 +----- .../wallet/PayWalletTransactionMapper.java | 18 ++++++++ .../pay/service/wallet/PayWalletService.java | 4 +- .../service/wallet/PayWalletServiceImpl.java | 2 +- .../wallet/PayWalletTransactionService.java | 23 ++++++++++ .../PayWalletTransactionServiceImpl.java | 41 ++++++++++++++++++ 15 files changed, 221 insertions(+), 37 deletions(-) create mode 100644 yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionQueryTypeEnum.java delete mode 100644 yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletTransactionController.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionPageReqVO.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionRespVO.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index 4be65ffdd..c0df14857 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -27,7 +27,6 @@ CREATE TABLE `pay_wallet_transaction` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', - `user_id` bigint NOT NULL COMMENT '用户 id', `biz_type` tinyint NOT NULL COMMENT '关联类型', `biz_id` bigint NOT NULL COMMENT '关联业务编号', `no` varchar(64) NOT NULL COMMENT '流水号', @@ -35,6 +34,7 @@ CREATE TABLE `pay_wallet_transaction` `amount` int NOT NULL COMMENT '交易金额, 单位分', `balance` int NOT NULL COMMENT '余额, 单位分', `transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java index 65f80d7eb..b319f006f 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java @@ -41,6 +41,9 @@ public interface ErrorCodeConstants { ErrorCode REFUND_NOT_FOUND = new ErrorCode(1007006004, "支付退款单不存在"); ErrorCode REFUND_STATUS_IS_NOT_WAITING = new ErrorCode(1007006005, "支付退款单不处于待退款"); + // ========== 钱包模块(退款) 1007007000 ========== + ErrorCode WALLET_NOT_FOUND = new ErrorCode(1007007000, "用户钱包不存在"); + // ========== 示例订单 1007900000 ========== ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在"); ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007900001, "示例订单更新支付状态失败,订单不是【未支付】状态"); diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionQueryTypeEnum.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionQueryTypeEnum.java new file mode 100644 index 000000000..776b860c4 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionQueryTypeEnum.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.pay.enums.member; + +import cn.hutool.core.util.ArrayUtil; +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * 钱包明细查询类型 + * + * @author jason + */ +@AllArgsConstructor +@Getter +public enum WalletTransactionQueryTypeEnum implements IntArrayValuable { + RECHARGE(1, "充值"), + EXPENSE(2, "消费"); + + private final Integer type; + + private final String desc; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(WalletTransactionQueryTypeEnum::getType).toArray(); + + @Override + public int[] array() { + return ARRAYS; + } + + public static WalletTransactionQueryTypeEnum valueOf(Integer type) { + return ArrayUtil.firstMatch(o -> o.getType().equals(type), values()); + } +} diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java deleted file mode 100644 index 87cd1b96b..000000000 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.pay.enums.member; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 钱包交易大分类 - * - * @author jason - */ -@AllArgsConstructor -@Getter -public enum WalletTypeEnum { - RECHARGE(1, "充值"), - EXPENSE(2, "消费"); - - private final Integer type; - - private final String desc; -} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java index 98417876b..3cd5c511d 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java @@ -22,7 +22,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti /** * @author jason */ -@Tag(name = "用户 APP - 支付钱包") +@Tag(name = "用户 APP - 钱包") @RestController @RequestMapping("/pay/wallet") @Validated @@ -33,7 +33,7 @@ public class AppPayWalletController { private PayWalletService payWalletService; @GetMapping("/get") - @Operation(summary = "获取支付钱包") + @Operation(summary = "获取钱包") public CommonResult getPayWallet() { PayWalletDO payWallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); return success(PayWalletConvert.INSTANCE.convert(payWallet)); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletTransactionController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletTransactionController.java new file mode 100644 index 000000000..783362db1 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletTransactionController.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet; + +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionRespVO; +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; + +@Tag(name = "用户 APP - 钱包余额明细") +@RestController +@RequestMapping("/pay/wallet-transaction") +@Validated +@Slf4j +public class AppPayWalletTransactionController { + + @Resource + private PayWalletTransactionService payWalletTransactionService; + + @GetMapping("/page") + @Operation(summary = "获得钱包余额明细分页") + public CommonResult> pageWalletTransaction( + @Valid AppPayWalletTransactionPageReqVO pageVO) { + PageResult result = payWalletTransactionService.getWalletTransactionPage(getLoginUserId(), + UserTypeEnum.MEMBER.getValue(), pageVO); + return success(PayWalletTransactionConvert.INSTANCE.convertPage(result)); + } +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionPageReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionPageReqVO.java new file mode 100644 index 000000000..22a4cad7e --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionPageReqVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 APP - 钱包余额明细分页 Request VO") +@Data +public class AppPayWalletTransactionPageReqVO extends PageParam { + + @Schema(description = "余额明细查询分类", example = "1") + @InEnum(value = WalletTransactionQueryTypeEnum.class, message = "查询类型必须是 {value}") + private Integer type; +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionRespVO.java new file mode 100644 index 000000000..dac2109d8 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户 APP - 钱包余额明细分页 Response VO") +@Data +public class AppPayWalletTransactionRespVO { + @Schema(description = "交易金额, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private Integer amount; + + @Schema(description = "业务分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer bizType; + + @Schema(description = "交易时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private LocalDateTime transactionTime; +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java new file mode 100644 index 000000000..99d8c7544 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.pay.convert.wallet; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionRespVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PayWalletTransactionConvert { + + PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class); + + PageResult convertPage(PageResult page); +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java index c8340badc..c03a7f224 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java @@ -27,22 +27,13 @@ public class PayWalletTransactionDO extends BaseDO { /** * 会员钱包 id - * * 关联 {@link PayWalletDO#getId()} */ private Long walletId; /** - * 用户 id - * - * 关联 MemberUserDO 的 id 编号 - */ - private Long userId; - - /** - * 关联业务 - * - * 枚举 {@link WalletBizTypeEnum#getBizType()} + * 钱包交易业务分类 + * 关联枚举 {@link WalletBizTypeEnum#getBizType()} */ private Integer bizType; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java index 5e9ab5301..28b4a62e0 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java @@ -1,13 +1,31 @@ package cn.iocoder.yudao.module.pay.dal.mysql.wallet; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; import org.apache.ibatis.annotations.Mapper; @Mapper public interface PayWalletTransactionMapper extends BaseMapperX { + default PageResult selectPageByWalletIdAndQueryType(Long walletId, + WalletTransactionQueryTypeEnum queryType, + PageParam pageParam) { + LambdaQueryWrapperX query = new LambdaQueryWrapperX() + .eq(PayWalletTransactionDO::getWalletId, walletId); + if (WalletTransactionQueryTypeEnum.RECHARGE == queryType ) { + query.ge(PayWalletTransactionDO::getAmount, 0); + } + if (WalletTransactionQueryTypeEnum.EXPENSE == queryType ) { + query.lt(PayWalletTransactionDO::getAmount, 0); + } + query.orderByDesc(PayWalletTransactionDO::getTransactionTime); + return selectPage(pageParam, query); + } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 7db829cf1..3d99e5258 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -3,14 +3,14 @@ package cn.iocoder.yudao.module.pay.service.wallet; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; /** - * 支付钱包 Service 接口 + * 钱包 Service 接口 * * @author jason */ public interface PayWalletService { /** - * 得到用户的支付钱包 + * 获取钱包信息 * @param userId 用户 id * @param userType 用户类型 */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 34ae5613b..7d29b613e 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; /** - * 支付钱包 Service 实现类 + * 钱包 Service 实现类 * * @author jason */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java new file mode 100644 index 000000000..a9bc91ab5 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.pay.service.wallet; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; + +/** + * 钱包余额明细 Service 接口 + * + * @author jason + */ +public interface PayWalletTransactionService { + + /** + * 查询钱包余额明细, 分页 + * + * @param userId 用户 id + * @param userType 用户类型 + * @param pageVO 分页查询参数 + */ + PageResult getWalletTransactionPage(Long userId, Integer userType, + AppPayWalletTransactionPageReqVO pageVO); +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java new file mode 100644 index 000000000..f574b779f --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.pay.service.wallet; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper; +import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND; + +/** + * 钱包余额明细 Service 实现类 + * + * @author jason + */ +@Service +@Slf4j +public class PayWalletTransactionServiceImpl implements PayWalletTransactionService{ + @Resource + private PayWalletService payWalletService; + @Resource + private PayWalletTransactionMapper payWalletTransactionMapper; + + @Override + public PageResult getWalletTransactionPage(Long userId, Integer userType, + AppPayWalletTransactionPageReqVO pageVO) { + PayWalletDO payWallet = payWalletService.getPayWallet(userId, userType); + if (payWallet == null) { + log.error("[pageWalletTransaction] 用户 {} 钱包不存在", userId); + throw exception(WALLET_NOT_FOUND); + } + return payWalletTransactionMapper.selectPageByWalletIdAndQueryType(payWallet.getId(), + WalletTransactionQueryTypeEnum.valueOf(pageVO.getType()), pageVO); + } +} From dad56fd0963e46eb866923a5f39bcef3fc237b42 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 25 Aug 2023 22:21:14 +0800 Subject: [PATCH 14/26] =?UTF-8?q?trade:=201.=E6=94=AF=E4=BB=98=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=90=8E=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=8F=E9=AA=8C=EF=BC=9B2.=E9=80=80=E6=AC=BE=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=90=8E=EF=BC=8C=E6=89=A3=E5=87=8F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=8F=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderUpdateServiceImpl.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index dd119a64e..2de660131 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,8 +12,10 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; @@ -29,10 +31,10 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUp import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; -import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdatePriceReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdatePriceReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; @@ -57,6 +59,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -101,8 +104,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private AddressApi addressApi; @Resource private CouponApi couponApi; + @Resource private MemberUserApi memberUserApi; + @Resource + private MemberLevelApi memberLevelApi; + @Resource private ProductCommentApi productCommentApi; @Resource @@ -336,6 +343,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:发送站内信 // TODO 芋艿:OrderLog + + // todo 增加用户积分 + + // 增加用户经验 + addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); } /** @@ -602,6 +614,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // TODO 芋艿:未来如果有分佣,需要更新相关分佣订单为已失效 + + // todo 取消用户积分 + + // 取消用户经验 + reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); } @Override @@ -649,4 +666,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())); } + @Async + protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) { + int bizType = MemberExperienceBizTypeEnum.ORDER.getType(); + memberLevelApi.addExperience(userId, payPrice, bizType, String.valueOf(orderId)); + } + + @Async + protected void reduceUserExperienceAsync(Long userId, Integer refundPrice, Long afterSaleId){ + int bizType = MemberExperienceBizTypeEnum.REFUND.getType(); + memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); + } } From d4acacec60c137aa3ab916357f176f65b406d0f8 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 25 Aug 2023 23:07:54 +0800 Subject: [PATCH 15/26] =?UTF-8?q?trade:=201.=E6=94=AF=E4=BB=98=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=90=8E=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A7=AF=E5=88=86=EF=BC=9B2.=E9=80=80=E6=AC=BE=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=90=8E=EF=BC=8C=E6=89=A3=E5=87=8F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderUpdateServiceImpl.java | 25 ++++++++++---- .../module/member/api/user/MemberUserApi.java | 10 ++++++ .../member/enums/ErrorCodeConstants.java | 3 +- .../enums/MemberExperienceBizTypeEnum.java | 25 ++++++++++---- .../enums/point/MemberPointBizTypeEnum.java | 23 +++++++++++-- .../member/api/user/MemberUserApiImpl.java | 17 ++++++++++ .../service/level/MemberLevelServiceImpl.java | 3 ++ .../point/MemberPointRecordService.java | 10 ++++++ .../point/MemberPointRecordServiceImpl.java | 33 +++++++++++++++++++ .../service/user/MemberUserService.java | 8 +++++ .../service/user/MemberUserServiceImpl.java | 5 +++ 11 files changed, 146 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 2de660131..a9f61f198 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; @@ -344,8 +345,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:OrderLog - // todo 增加用户积分 - + // 增加用户积分 + addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户经验 addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); } @@ -615,9 +616,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:未来如果有分佣,需要更新相关分佣订单为已失效 - // todo 取消用户积分 - - // 取消用户经验 + // 扣减用户积分 + reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); + // 扣减用户经验 reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); } @@ -673,8 +674,20 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } @Async - protected void reduceUserExperienceAsync(Long userId, Integer refundPrice, Long afterSaleId){ + protected void reduceUserExperienceAsync(Long userId, Integer refundPrice, Long afterSaleId) { int bizType = MemberExperienceBizTypeEnum.REFUND.getType(); memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + + @Async + protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) { + int bizType = MemberPointBizTypeEnum.ORDER_BUY.getType(); + memberUserApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); + } + + @Async + protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { + int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType(); + memberUserApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); + } } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java index 5743493e3..90445ffa6 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.member.api.user; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import java.util.Collection; import java.util.List; @@ -57,4 +58,13 @@ public interface MemberUserApi { */ MemberUserRespDTO getUserByMobile(String mobile); + /** + * 增加用户积分 + * + * @param userId 用户编号 + * @param point 积分 + * @param bizType 业务类型 {@link MemberPointBizTypeEnum} + * @param bizId 业务编号 + */ + void addPoint(Long userId, Integer point, Integer bizType, String bizId); } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index 724ba0c5e..ba283ab0c 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; /** * Member 错误码枚举类 - * + *

* member 系统,使用 1-004-000-000 段 */ public interface ErrorCodeConstants { @@ -32,6 +32,7 @@ public interface ErrorCodeConstants { //========== 积分配置 1004007000 ========== //========== 积分记录 1004008000 ========== + ErrorCode POINT_RECORD_BIZ_NOT_SUPPORT = new ErrorCode(1004008000, "用户积分记录业务类型不支持"); //========== 签到配置 1004009000 ========== ErrorCode SIGN_IN_CONFIG_NOT_EXISTS = new ErrorCode(1004009000, "签到天数规则不存在"); diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java index fcd0f6e7a..a287b0cdc 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java @@ -18,17 +18,30 @@ public enum MemberExperienceBizTypeEnum { /** * 管理员调整、邀请新用户、下单、退单、签到、抽奖 */ - ADMIN(0, "管理员调整", "管理员调整获得 {} 经验"), - INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验"), - ORDER(2, "下单奖励", "下单获得 {} 经验"), - REFUND(3, "退单扣除", "退单获得 {} 经验"), - SIGN_IN(4, "签到奖励", "签到获得 {} 经验"), - LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验"), + ADMIN(0, "管理员调整", "管理员调整获得 {} 经验", false), + INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验", false), + ORDER(2, "下单奖励", "下单获得 {} 经验", false), + REFUND(3, "退单扣除", "退单获得 {} 经验", true), + SIGN_IN(4, "签到奖励", "签到获得 {} 经验", false), + LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验", false), ; + /** + * 业务类型 + */ private final int type; + /** + * 标题 + */ private final String title; + /** + * 描述 + */ private final String description; + /** + * 是否为扣减积分 + */ + private final boolean isReduce; public static MemberExperienceBizTypeEnum getByType(Integer type) { return EnumUtil.getBy(MemberExperienceBizTypeEnum.class, diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java index 65e4c6c34..80d8fd767 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java @@ -1,9 +1,12 @@ package cn.iocoder.yudao.module.member.enums.point; +import cn.hutool.core.util.EnumUtil; import cn.iocoder.yudao.framework.common.core.IntArrayValuable; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Objects; + /** * 会员积分的业务类型枚举 * @@ -13,9 +16,9 @@ import lombok.Getter; @Getter public enum MemberPointBizTypeEnum implements IntArrayValuable { - SIGN(1, "签到"), - ORDER_BUY(10, "订单消费"), - ORDER_CANCEL(11, "订单取消"); // 退回积分 + SIGN(1, "签到", "签到获得 {} 积分", false), + ORDER_BUY(10, "订单消费", "下单获得 {} 积分", false), + ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", true); // 退回积分 /** * 类型 @@ -25,10 +28,24 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable { * 名字 */ private final String name; + /** + * 描述 + */ + private final String description; + /** + * 是否为扣减积分 + */ + private final boolean isReduce; @Override public int[] array() { return new int[0]; } + + public static MemberPointBizTypeEnum getByType(Integer type) { + return EnumUtil.getBy(MemberPointBizTypeEnum.class, + e -> Objects.equals(type, e.getType())); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java index 8da857c6d..898b7fe9c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.member.api.user; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; +import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -11,6 +13,9 @@ import javax.annotation.Resource; import java.util.Collection; import java.util.List; +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; + /** * 会员用户的 API 实现类 * @@ -23,6 +28,9 @@ public class MemberUserApiImpl implements MemberUserApi { @Resource private MemberUserService userService; + @Resource + private MemberPointRecordService memberPointRecordService; + @Override public MemberUserRespDTO getUser(Long id) { MemberUserDO user = userService.getUser(id); @@ -44,4 +52,13 @@ public class MemberUserApiImpl implements MemberUserApi { return MemberUserConvert.INSTANCE.convert2(userService.getUserByMobile(mobile)); } + @Override + public void addPoint(Long userId, Integer point, Integer bizType, String bizId) { + MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType); + if (bizTypeEnum == null) { + throw exception(POINT_RECORD_BIZ_NOT_SUPPORT); + } + memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index d46465554..9169b04fd 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -235,6 +235,9 @@ public class MemberLevelServiceImpl implements MemberLevelService { if (experience == 0) { return; } + if (bizType.isReduce() && experience > 0) { + experience = -experience; + } MemberUserDO user = memberUserService.getUser(userId); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordService.java index 971cb7274..74e91880f 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordService.java @@ -4,6 +4,7 @@ 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.dal.dataobject.point.MemberPointRecordDO; +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; /** * 用户积分记录 Service 接口 @@ -29,4 +30,13 @@ public interface MemberPointRecordService { */ PageResult getPointRecordPage(Long userId, PageParam pageVO); + /** + * 创建用户积分记录 + * + * @param userId 用户ID + * @param point 变动积分 + * @param bizType 业务类型 + * @param bizId 业务编号 + */ + void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index 52257183d..9516981bb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -1,12 +1,18 @@ package cn.iocoder.yudao.module.member.service.point; +import cn.hutool.core.util.NumberUtil; +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.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO; +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 org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -33,6 +39,8 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { @Resource private MemberUserApi memberUserApi; + @Resource + private MemberUserService memberUserService; @Override public PageResult getPointRecordPage(MemberPointRecordPageReqVO pageReqVO) { @@ -55,4 +63,29 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { return recordMapper.selectPage(userId, pageVO); } + @Override + public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) { + if (bizType.isReduce() && point > 0) { + point = -point; + } + + MemberUserDO user = memberUserService.getUser(userId); + Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); + // 用户变动后的积分,防止扣出负数 + Integer totalPoint = NumberUtil.max(userPoint + point, 0); + // 增加积分记录 + MemberPointRecordDO recordDO = new MemberPointRecordDO() + .setUserId(userId) + .setBizId(bizId) + .setBizType(bizType.getType()) + .setTitle(bizType.getName()) + .setDescription(StrUtil.format(bizType.getDescription(), point)) + .setPoint(point) + .setTotalPoint(totalPoint); + recordMapper.insert(recordDO); + + // 更新用户积分 + memberUserService.updateUserPoint(userId, totalPoint); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 7a0c13380..a1161d668 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -158,4 +158,12 @@ public interface MemberUserService { * @return 用户数量 */ Long getUserCountByTagId(Long tagId); + + /** + * 更新用户的积分 + * + * @param userId 用户ID + * @param point 积分数量 + */ + void updateUserPoint(Long userId, Integer point); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 152f87cad..c5b674cc8 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -254,4 +254,9 @@ public class MemberUserServiceImpl implements MemberUserService { return memberUserMapper.selectCountByTagId(tagId); } + @Override + public void updateUserPoint(Long userId, Integer point) { + memberUserMapper.updateById(new MemberUserDO().setId(userId).setPoint(point)); + } + } From fd126ba2f7ed54111ea9d2187aa86d7a39983d85 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 25 Aug 2023 23:14:27 +0800 Subject: [PATCH 16/26] =?UTF-8?q?member:=20=E6=A0=B9=E6=8D=AE=E7=A7=AF?= =?UTF-8?q?=E5=88=86=E9=85=8D=E7=BD=AE=E7=9A=84=E6=AF=94=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?=E6=8D=A2=E7=AE=97=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/MemberPointRecordServiceImpl.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index 9516981bb..1ffc38809 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -8,11 +8,13 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO; 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 lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -30,12 +32,15 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. * * @author QingX */ +@Slf4j @Service @Validated public class MemberPointRecordServiceImpl implements MemberPointRecordService { @Resource private MemberPointRecordMapper recordMapper; + @Resource + private MemberPointConfigService memberPointConfigService; @Resource private MemberUserApi memberUserApi; @@ -65,6 +70,15 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { @Override public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) { + MemberPointConfigDO pointConfig = memberPointConfigService.getPointConfig(); + if (pointConfig == null || pointConfig.getTradeGivePoint() == null) { + log.warn("增加积分失败:积分配置”1 元赠送多少分“未设置, userId={}, point={}, bizType={}, bizId={}", + userId, point, bizType.getType(), bizId); + return; + } + + // 根据配置的比例,换算实际的积分 + point = point * pointConfig.getTradeGivePoint(); if (bizType.isReduce() && point > 0) { point = -point; } From 583d34a801e111b185f61f88a70a7ddb0ecf90d9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 26 Aug 2023 01:51:47 +0800 Subject: [PATCH 17/26] =?UTF-8?q?code=20review=EF=BC=9A=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=94=B6=E4=BB=B6=E5=9C=B0=E5=9D=80=E5=A4=9A=E4=BD=99=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/address/AddressController.java | 101 ++++-------------- .../admin/address/vo/AddressCreateReqVO.java | 14 --- .../admin/address/vo/AddressExcelVO.java | 40 ------- .../admin/address/vo/AddressExportReqVO.java | 38 ------- .../admin/address/vo/AddressPageReqVO.java | 40 ------- .../admin/address/vo/AddressUpdateReqVO.java | 18 ---- .../admin/user/vo/MemberUserBaseVO.java | 4 +- .../convert/address/AddressConvert.java | 13 --- .../convert/user/MemberUserConvert.java | 16 ++- .../dal/mysql/address/AddressMapper.java | 26 ----- .../service/address/AddressService.java | 59 ---------- .../service/address/AddressServiceImpl.java | 58 ---------- 12 files changed, 29 insertions(+), 398 deletions(-) delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java index 3e6919e83..0363634c5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/AddressController.java @@ -1,32 +1,24 @@ package cn.iocoder.yudao.module.member.controller.admin.address; -import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.member.controller.admin.address.vo.*; +import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressRespVO; import cn.iocoder.yudao.module.member.convert.address.AddressConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import cn.iocoder.yudao.module.member.service.address.AddressService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 用户收件地址") @RestController @@ -37,66 +29,13 @@ public class AddressController { @Resource private AddressService addressService; - @PostMapping("/create") - @Operation(summary = "创建用户收件地址") - @PreAuthorize("@ss.hasPermission('member:address:create')") - public CommonResult createAddress(@Valid @RequestBody AddressCreateReqVO createReqVO) { - return success(addressService.createAddress(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新用户收件地址") - @PreAuthorize("@ss.hasPermission('member:address:update')") - public CommonResult updateAddress(@Valid @RequestBody AddressUpdateReqVO updateReqVO) { - addressService.updateAddress(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除用户收件地址") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('member:address:delete')") - public CommonResult deleteAddress(@RequestParam("id") Long id) { - addressService.deleteAddress(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得用户收件地址") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('member:address:query')") - public CommonResult getAddress(@RequestParam("id") Long id) { - MemberAddressDO address = addressService.getAddress(id); - return success(AddressConvert.INSTANCE.convert2(address)); - } - @GetMapping("/list") @Operation(summary = "获得用户收件地址列表") - @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") - @PreAuthorize("@ss.hasPermission('member:address:query')") - public CommonResult> getAddressList(@RequestParam("ids") Collection ids) { - List list = addressService.getAddressList(ids); + @Parameter(name = "userId", description = "用户编号", required = true) + @PreAuthorize("@ss.hasPermission('member:user:query')") + public CommonResult> getAddressList(@RequestParam("userId") Long userId) { + List list = addressService.getAddressList(userId); return success(AddressConvert.INSTANCE.convertList2(list)); } - @GetMapping("/page") - @Operation(summary = "获得用户收件地址分页") - @PreAuthorize("@ss.hasPermission('member:address:query')") - public CommonResult> getAddressPage(@Valid AddressPageReqVO pageVO) { - PageResult pageResult = addressService.getAddressPage(pageVO); - return success(AddressConvert.INSTANCE.convertPage(pageResult)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出用户收件地址 Excel") - @PreAuthorize("@ss.hasPermission('member:address:export')") - @OperateLog(type = EXPORT) - public void exportAddressExcel(@Valid AddressExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = addressService.getAddressList(exportReqVO); - // 导出 Excel - List datas = AddressConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "用户收件地址.xls", "数据", AddressExcelVO.class, datas); - } - } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java deleted file mode 100644 index ac0833ba7..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.admin.address.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 用户收件地址创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class AddressCreateReqVO extends AddressBaseVO { - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java deleted file mode 100644 index 8a0543247..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExcelVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.admin.address.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import java.time.LocalDateTime; -import java.time.LocalDateTime; - -import com.alibaba.excel.annotation.ExcelProperty; - -/** - * 用户收件地址 Excel VO - * - * @author 绮梦 - */ -@Data -public class AddressExcelVO { - - @ExcelProperty("收件地址编号") - private Long id; - - @ExcelProperty("收件人名称") - private String name; - - @ExcelProperty("手机号") - private String mobile; - - @ExcelProperty("地区编码") - private Long areaId; - - @ExcelProperty("收件详细地址") - private String detailAddress; - - @ExcelProperty("是否默认") - private Boolean defaultStatus; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java deleted file mode 100644 index 214bf952b..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressExportReqVO.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.admin.address.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import java.time.LocalDateTime; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 用户收件地址 Excel 导出 Request VO,参数和 AddressPageReqVO 是一致的") -@Data -public class AddressExportReqVO { - - @Schema(description = "用户编号", example = "20369") - private Long userId; - - @Schema(description = "收件人名称", example = "张三") - private String name; - - @Schema(description = "手机号") - private String mobile; - - @Schema(description = "地区编码", example = "15716") - private Long areaId; - - @Schema(description = "收件详细地址") - private String detailAddress; - - @Schema(description = "是否默认", example = "2") - private Boolean defaultStatus; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java deleted file mode 100644 index 32b059448..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressPageReqVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.admin.address.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 用户收件地址分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class AddressPageReqVO extends PageParam { - - @Schema(description = "用户编号", example = "20369") - private Long userId; - - @Schema(description = "收件人名称", example = "张三") - private String name; - - @Schema(description = "手机号") - private String mobile; - - @Schema(description = "地区编码", example = "15716") - private Long areaId; - - @Schema(description = "收件详细地址") - private String detailAddress; - - @Schema(description = "是否默认", example = "2") - private Boolean defaultStatus; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java deleted file mode 100644 index 4e91579e4..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/vo/AddressUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.admin.address.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 用户收件地址更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class AddressUpdateReqVO extends AddressBaseVO { - - @Schema(description = "收件地址编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7380") - @NotNull(message = "收件地址编号不能为空") - private Long id; - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java index ba5d961bc..e20963e5e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserBaseVO.java @@ -40,10 +40,10 @@ public class MemberUserBaseVO { @Schema(description = "用户性别", example = "1") private Byte sex; - @Schema(description = "所在地", example = "4371") + @Schema(description = "所在地编号", example = "4371") private Long areaId; - @Schema(description = "所在地可视化显示", example = "4371") + @Schema(description = "所在地全程", example = "上海上海市普陀区") private String areaName; @Schema(description = "出生日期", example = "2023-03-12") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java index e6f56a022..fd5198e14 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/address/AddressConvert.java @@ -1,12 +1,8 @@ package cn.iocoder.yudao.module.member.convert.address; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExcelVO; import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressRespVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressRespVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; @@ -44,15 +40,6 @@ public interface AddressConvert { return AreaUtils.format(areaId); } - MemberAddressDO convert(AddressCreateReqVO bean); - - MemberAddressDO convert(AddressUpdateReqVO bean); - - AddressRespVO convert2(MemberAddressDO bean); - List convertList2(List list); - PageResult convertPage(PageResult page); - - List convertList02(List list); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java index d07c3ddc5..5b963be69 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/user/MemberUserConvert.java @@ -1,15 +1,13 @@ package cn.iocoder.yudao.module.member.convert.user; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserInfoRespVO; +import cn.iocoder.yudao.module.member.convert.address.AddressConvert; import cn.iocoder.yudao.module.member.dal.dataobject.group.MemberGroupDO; import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO; -import cn.iocoder.yudao.module.member.convert.address.AddressConvert; import cn.iocoder.yudao.module.member.dal.dataobject.tag.MemberTagDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import org.mapstruct.Mapper; @@ -37,7 +35,7 @@ public interface MemberUserConvert { PageResult convertPage(PageResult page); - @Mapping(source = "areaId", target = "areaName", qualifiedByName = "convertAreaIdToAreaName") + @Mapping(source = "areaId", target = "areaName", qualifiedByName = "convertAreaIdToAreaName") MemberUserRespVO convert03(MemberUserDO bean); default PageResult convertPage(PageResult pageResult, @@ -50,11 +48,11 @@ public interface MemberUserConvert { Map levelMap = convertMap(levels, MemberLevelDO::getId, MemberLevelDO::getName); Map groupMap = convertMap(groups, MemberGroupDO::getId, MemberGroupDO::getName); // 填充关联数据 - for (MemberUserRespVO vo : result.getList()) { - vo.setTagNames(convertList(vo.getTagIds(), tagMap::get)); - vo.setLevelName(MapUtil.getStr(levelMap, vo.getLevelId(), StrUtil.EMPTY)); - vo.setGroupName(MapUtil.getStr(groupMap, vo.getGroupId(), StrUtil.EMPTY)); - } + result.getList().forEach(user -> { + user.setTagNames(convertList(user.getTagIds(), tagMap::get)); + user.setLevelName(levelMap.get(user.getLevelId())); + user.setGroupName(groupMap.get(user.getGroupId())); + }); return result; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java index 9beb025c0..db824f6f5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java @@ -1,10 +1,7 @@ package cn.iocoder.yudao.module.member.dal.mysql.address; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import org.apache.ibatis.annotations.Mapper; @@ -21,28 +18,5 @@ public interface AddressMapper extends BaseMapperX { return selectList(new LambdaQueryWrapperX().eq(MemberAddressDO::getUserId, userId) .eqIfPresent(MemberAddressDO::getDefaultStatus, defaulted)); } - default PageResult selectPage(AddressPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(MemberAddressDO::getUserId, reqVO.getUserId()) - .likeIfPresent(MemberAddressDO::getName, reqVO.getName()) - .eqIfPresent(MemberAddressDO::getMobile, reqVO.getMobile()) - .eqIfPresent(MemberAddressDO::getAreaId, reqVO.getAreaId()) - .eqIfPresent(MemberAddressDO::getDetailAddress, reqVO.getDetailAddress()) - .eqIfPresent(MemberAddressDO::getDefaultStatus, reqVO.getDefaultStatus()) - .betweenIfPresent(MemberAddressDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(MemberAddressDO::getId)); - } - - default List selectList(AddressExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(MemberAddressDO::getUserId, reqVO.getUserId()) - .likeIfPresent(MemberAddressDO::getName, reqVO.getName()) - .eqIfPresent(MemberAddressDO::getMobile, reqVO.getMobile()) - .eqIfPresent(MemberAddressDO::getAreaId, reqVO.getAreaId()) - .eqIfPresent(MemberAddressDO::getDetailAddress, reqVO.getDetailAddress()) - .eqIfPresent(MemberAddressDO::getDefaultStatus, reqVO.getDefaultStatus()) - .betweenIfPresent(MemberAddressDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(MemberAddressDO::getId)); - } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java index 260ab7987..099c49c42 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java @@ -1,16 +1,10 @@ package cn.iocoder.yudao.module.member.service.address; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.address.MemberAddressDO; import javax.validation.Valid; -import java.util.Collection; import java.util.List; /** @@ -70,57 +64,4 @@ public interface AddressService { */ MemberAddressDO getDefaultUserAddress(Long userId); - /** - * 创建用户收件地址 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createAddress(@Valid AddressCreateReqVO createReqVO); - - /** - * 更新用户收件地址 - * - * @param updateReqVO 更新信息 - */ - void updateAddress(@Valid AddressUpdateReqVO updateReqVO); - - /** - * 删除用户收件地址 - * - * @param id 编号 - */ - void deleteAddress(Long id); - - /** - * 获得用户收件地址 - * - * @param id 编号 - * @return 用户收件地址 - */ - MemberAddressDO getAddress(Long id); - - /** - * 获得用户收件地址列表 - * - * @param ids 编号 - * @return 用户收件地址列表 - */ - List getAddressList(Collection ids); - - /** - * 获得用户收件地址分页 - * - * @param pageReqVO 分页查询 - * @return 用户收件地址分页 - */ - PageResult getAddressPage(AddressPageReqVO pageReqVO); - - /** - * 获得用户收件地址列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 用户收件地址列表 - */ - List getAddressList(AddressExportReqVO exportReqVO); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java index 79f129b75..2689177ea 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java @@ -1,11 +1,6 @@ package cn.iocoder.yudao.module.member.service.address; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressCreateReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressExportReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressPageReqVO; -import cn.iocoder.yudao.module.member.controller.admin.address.vo.AddressUpdateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressCreateReqVO; import cn.iocoder.yudao.module.member.controller.app.address.vo.AppAddressUpdateReqVO; import cn.iocoder.yudao.module.member.convert.address.AddressConvert; @@ -16,7 +11,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -100,56 +94,4 @@ public class AddressServiceImpl implements AddressService { return CollUtil.getFirst(addresses); } - @Override - public Long createAddress(AddressCreateReqVO createReqVO) { - // 插入 - MemberAddressDO address = AddressConvert.INSTANCE.convert(createReqVO); - addressMapper.insert(address); - // 返回 - return address.getId(); - } - - @Override - public void updateAddress(AddressUpdateReqVO updateReqVO) { - // 校验存在 - validateAddressExists(updateReqVO.getId()); - // 更新 - MemberAddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO); - addressMapper.updateById(updateObj); - } - - @Override - public void deleteAddress(Long id) { - // 校验存在 - validateAddressExists(id); - // 删除 - addressMapper.deleteById(id); - } - - private void validateAddressExists(Long id) { - if (addressMapper.selectById(id) == null) { - throw exception(ADDRESS_NOT_EXISTS); - } - } - - @Override - public MemberAddressDO getAddress(Long id) { - return addressMapper.selectById(id); - } - - @Override - public List getAddressList(Collection ids) { - return addressMapper.selectBatchIds(ids); - } - - @Override - public PageResult getAddressPage(AddressPageReqVO pageReqVO) { - return addressMapper.selectPage(pageReqVO); - } - - @Override - public List getAddressList(AddressExportReqVO exportReqVO) { - return addressMapper.selectList(exportReqVO); - } - } From b75d777670d6f4fdd9c1b4e381f8aa57a4219532 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 26 Aug 2023 10:54:45 +0800 Subject: [PATCH 18/26] =?UTF-8?q?code=20review=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E3=80=81=E8=AE=A2=E5=8D=95=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/ProductCommentController.java | 3 +- .../comment/ProductCommentConvert.java | 16 ++-- .../mysql/comment/ProductCommentMapper.java | 6 +- .../comment/ProductCommentService.java | 64 ++++++------- .../comment/ProductCommentServiceImpl.java | 92 +++++++++---------- .../order/TradeOrderUpdateServiceImpl.java | 1 + .../module/member/api/user/MemberUserApi.java | 2 + .../enums/point/MemberPointBizTypeEnum.java | 2 +- .../service/level/MemberLevelServiceImpl.java | 38 ++++---- .../point/MemberPointRecordServiceImpl.java | 10 +- .../service/user/MemberUserService.java | 2 +- 11 files changed, 114 insertions(+), 122 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index bac915a0f..d8a779aa3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -38,10 +38,9 @@ public class ProductCommentController { @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { PageResult pageResult = productCommentService.getCommentPage(pageVO); - + // 拼接返回 List skuList = productSkuService.getSkuList( convertSet(pageResult.getList(), ProductCommentDO::getSkuId)); - return success(ProductCommentConvert.INSTANCE.convertPage(pageResult, skuList)); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index 216212b2e..94edc20bf 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -117,26 +117,26 @@ public interface ProductCommentConvert { List convertList02(List list); - default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO) { + default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu) { ProductCommentDO commentDO = convert(createReq); - if (spuDO != null) { - commentDO.setSpuId(spuDO.getId()); - commentDO.setSpuName(spuDO.getName()); + if (spu != null) { + commentDO.setSpuId(spu.getId()).setSpuName(spu.getName()); } return commentDO; } - default PageResult convertPage(PageResult pageResult, List skuList) { - Map skuMap = convertMap(skuList, ProductSkuDO::getId); - + default PageResult convertPage(PageResult pageResult, + List skus) { PageResult result = convertPage(pageResult); + // 拼接数据 + Map skuMap = convertMap(skus, ProductSkuDO::getId); for (ProductCommentRespVO vo : result.getList()) { findAndThen(skuMap, vo.getSkuId(), sku -> { String propertyNames = sku.getProperties().stream() .map(ProductSkuDO.Property::getValueName) .filter(Objects::nonNull) .collect(Collectors.joining(" ")); - + // TODO @疯狂:要不写入评论的时候,把商品图片、商品属性,都冗余进去。因为这种东西有“快照”的需求。商品后续会编辑掉 vo.setSkuPicUrl(sku.getPicUrl()); vo.setSpuName(vo.getSpuName() + " " + propertyNames); }); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java index 095cd655b..387a3736b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.product.dal.mysql.comment; - import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -54,11 +53,10 @@ public interface ProductCommentMapper extends BaseMapperX { return selectPage(reqVO, queryWrapper); } - default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long skuId) { + default ProductCommentDO selectByUserIdAndOrderItemId(Long userId, Long orderItemId) { return selectOne(new LambdaQueryWrapperX() .eq(ProductCommentDO::getUserId, userId) - .eq(ProductCommentDO::getOrderItemId, orderItemId) - .eq(ProductCommentDO::getSpuId, skuId)); + .eq(ProductCommentDO::getOrderItemId, orderItemId)); } default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java index 2c2b35197..e531f5513 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java @@ -24,38 +24,6 @@ import java.util.List; @Validated public interface ProductCommentService { - /** - * 获得商品评价分页 - * - * @param pageReqVO 分页查询 - * @return 商品评价分页 - */ - PageResult getCommentPage(ProductCommentPageReqVO pageReqVO); - - /** - * 修改评论是否可见 - * - * @param updateReqVO 修改评论可见 - */ - void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO); - - /** - * 商家回复 - * - * @param replyVO 商家回复 - * @param loginUserId 管理后台商家登陆人 ID - */ - void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId); - - /** - * 获得商品评价分页 - * - * @param pageVO 分页查询 - * @param visible 是否可见 - * @return 商品评价分页 - */ - PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); - /** * 创建商品评论 * 后台管理员创建评论使用 @@ -73,6 +41,38 @@ public interface ProductCommentService { */ Long createComment(ProductCommentCreateReqDTO createReqDTO); + /** + * 修改评论是否可见 + * + * @param updateReqVO 修改评论可见 + */ + void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO); + + /** + * 商家回复 + * + * @param replyVO 商家回复 + * @param userId 管理后台商家登陆人 ID + */ + void replyComment(ProductCommentReplyReqVO replyVO, Long userId); + + /** + * 【管理员】获得商品评价分页 + * + * @param pageReqVO 分页查询 + * @return 商品评价分页 + */ + PageResult getCommentPage(ProductCommentPageReqVO pageReqVO); + + /** + * 【会员】获得商品评价分页 + * + * @param pageVO 分页查询 + * @param visible 是否可见 + * @return 商品评价分页 + */ + PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); + /** * 获得商品的评价统计 * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index 05d5b02cd..fe2a01a93 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java @@ -20,7 +20,6 @@ import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -53,71 +52,43 @@ public class ProductCommentServiceImpl implements ProductCommentService { private MemberUserApi memberUserApi; @Override - @Transactional(rollbackFor = Exception.class) - public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { - // 校验评论是否存在 - ProductCommentDO productCommentDO = validateCommentExists(updateReqVO.getId()); - productCommentDO.setVisible(updateReqVO.getVisible()); - - // 更新可见状态 - productCommentMapper.updateById(productCommentDO); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId) { - // 校验评论是否存在 - ProductCommentDO productCommentDO = validateCommentExists(replyVO.getId()); - productCommentDO.setReplyTime(LocalDateTime.now()); - productCommentDO.setReplyUserId(loginUserId); - productCommentDO.setReplyStatus(Boolean.TRUE); - productCommentDO.setReplyContent(replyVO.getReplyContent()); - - // 回复评论 - productCommentMapper.updateById(productCommentDO); - } - - @Override - @Transactional(rollbackFor = Exception.class) public void createComment(ProductCommentCreateReqVO createReqVO) { // 校验商品 - ProductSpuDO spuDO = validateProduct(createReqVO.getSkuId()); + ProductSpuDO spu = validateSpuBySkuId(createReqVO.getSkuId()); - ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO); - productCommentMapper.insert(commentDO); + // 创建评论 + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spu); + productCommentMapper.insert(comment); } @Override - @Transactional(rollbackFor = Exception.class) public Long createComment(ProductCommentCreateReqDTO createReqDTO) { // 校验商品 - ProductSpuDO spuDO = validateProduct(createReqDTO.getSkuId()); + ProductSpuDO spuDO = validateSpuBySkuId(createReqDTO.getSkuId()); // 校验评论 - validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId()); + validateCommentExists(createReqDTO.getUserId(), createReqDTO.getOrderId()); // 获取用户详细信息 MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId()); // 创建评论 - ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user); - productCommentMapper.insert(commentDO); - return commentDO.getId(); + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user); + productCommentMapper.insert(comment); + return comment.getId(); } - private void validateComment(Long skuId, Long userId, Long orderItemId) { - // 判断当前订单的当前商品用户是否评价过 - ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, skuId); - if (null != exist) { + /** + * 判断当前订单的当前商品用户是否评价过 + * + * @param userId 用户编号 + * @param orderItemId 订单项编号 + */ + private void validateCommentExists(Long userId, Long orderItemId) { + ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemId(userId, orderItemId); + if (exist != null) { throw exception(COMMENT_ORDER_EXISTS); } } - private ProductSpuDO validateProduct(Long skuId) { - // 通过 sku ID 拿到 spu 相关信息 - ProductSkuDO sku = validateSku(skuId); - // 校验 spu 如果存在返回详情 - return validateSpu(sku.getSpuId()); - } - private ProductSkuDO validateSku(Long skuId) { ProductSkuDO sku = productSkuService.getSku(skuId); if (sku == null) { @@ -134,6 +105,33 @@ public class ProductCommentServiceImpl implements ProductCommentService { return spu; } + private ProductSpuDO validateSpuBySkuId(Long skuId) { + // 通过 sku ID 拿到 spu 相关信息 + ProductSkuDO sku = validateSku(skuId); + // 校验 spu 如果存在返回详情 + return validateSpu(sku.getSpuId()); + } + + @Override + public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { + // 校验评论是否存在 + validateCommentExists(updateReqVO.getId()); + + // 更新可见状态 + productCommentMapper.updateById(new ProductCommentDO().setId(updateReqVO.getId()) + .setVisible(true)); + } + + @Override + public void replyComment(ProductCommentReplyReqVO replyVO, Long userId) { + // 校验评论是否存在 + validateCommentExists(replyVO.getId()); + // 回复评论 + productCommentMapper.updateById(new ProductCommentDO().setId(replyVO.getId()) + .setReplyTime(LocalDateTime.now()).setReplyUserId(userId) + .setReplyStatus(Boolean.TRUE).setReplyContent(replyVO.getReplyContent())); + } + private ProductCommentDO validateCommentExists(Long id) { ProductCommentDO productComment = productCommentMapper.selectById(id); if (productComment == null) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index a9f61f198..85e35f78a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -667,6 +667,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())); } + // TODO @疯狂:直接 this 调用,async 不生效哈。全局搜下 getSelf(); @Async protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) { int bizType = MemberExperienceBizTypeEnum.ORDER.getType(); diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java index 90445ffa6..296868709 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java @@ -58,6 +58,7 @@ public interface MemberUserApi { */ MemberUserRespDTO getUserByMobile(String mobile); + // TODO @疯狂:是不是新的类,MemberPointApi? /** * 增加用户积分 * @@ -67,4 +68,5 @@ public interface MemberUserApi { * @param bizId 业务编号 */ void addPoint(Long userId, Integer point, Integer bizType, String bizId); + } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java index 80d8fd767..e5f7839d8 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java @@ -32,6 +32,7 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable { * 描述 */ private final String description; + // TODO @疯狂:改成 add 会好点。一个是属性我们尽量不要 isXXX;另外尽量正向思维,不取反; /** * 是否为扣减积分 */ @@ -42,7 +43,6 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable { return new int[0]; } - public static MemberPointBizTypeEnum getByType(Integer type) { return EnumUtil.getBy(MemberPointBizTypeEnum.class, e -> Objects.equals(type, e.getType())); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index 9169b04fd..f8bd8b82a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -99,7 +99,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { if (ObjUtil.notEqual(levelDO.getName(), name)) { continue; } - if (id == null || !id.equals(levelDO.getId())) { throw exception(LEVEL_NAME_EXISTS, levelDO.getName()); } @@ -151,7 +150,6 @@ public class MemberLevelServiceImpl implements MemberLevelService { validateExperienceOutRange(list, id, level, experience); } - // TODO 有 Service 提供接口哈,不直接调用对方的 memberUserMapper @VisibleForTesting void validateLevelHasUser(Long id) { Long count = memberUserService.getUserCountByLevelId(id); @@ -195,37 +193,36 @@ public class MemberLevelServiceImpl implements MemberLevelService { return; } - // 记录等级变动 + // 1. 记录等级变动 MemberLevelRecordDO levelRecord = new MemberLevelRecordDO() - .setUserId(user.getId()) - .setRemark(updateReqVO.getReason()); + .setUserId(user.getId()).setRemark(updateReqVO.getReason()); MemberLevelDO memberLevel = null; if (updateReqVO.getLevelId() == null) { - // 取消用户等级时,为扣减经验 + // 取消用户等级时,需要扣减经验 levelRecord.setExperience(-user.getExperience()); + // TODO @疯狂:这里是不是也要设置下 setUserExperience 属性; levelRecord.setDescription("管理员取消了等级"); } else { - memberLevel = validateLevelExists(updateReqVO.getLevelId()); // 复制等级配置 + memberLevel = validateLevelExists(updateReqVO.getLevelId()); MemberLevelRecordConvert.INSTANCE.copyTo(memberLevel, levelRecord); // 变动经验值 = 等级的升级经验 - 会员当前的经验;正数为增加经验,负数为扣减经验 levelRecord.setExperience(memberLevel.getExperience() - user.getExperience()); - // 会员当前的经验 = 等级的升级经验 - levelRecord.setUserExperience(memberLevel.getExperience()); + levelRecord.setUserExperience(memberLevel.getExperience()); // 会员当前的经验 = 等级的升级经验 levelRecord.setDescription("管理员调整为:" + memberLevel.getName()); } memberLevelRecordService.createLevelRecord(levelRecord); - // 记录会员经验变动 + // 2. 记录会员经验变动 memberExperienceRecordService.createExperienceRecord(user.getId(), levelRecord.getExperience(), levelRecord.getUserExperience(), MemberExperienceBizTypeEnum.ADMIN, String.valueOf(MemberExperienceBizTypeEnum.ADMIN.getType())); - // 更新会员表上的等级编号、经验值 + // 3. 更新会员表上的等级编号、经验值 memberUserService.updateUserLevel(user.getId(), updateReqVO.getLevelId(), levelRecord.getUserExperience()); - // 给会员发送等级变动消息 + // 4. 给会员发送等级变动消息 notifyMemberLevelChange(user.getId(), memberLevel); } @@ -239,31 +236,27 @@ public class MemberLevelServiceImpl implements MemberLevelService { experience = -experience; } + // 1. 创建经验记录 MemberUserDO user = memberUserService.getUser(userId); - - int userExperience = NumberUtil.max(user.getExperience() + experience, 0); + int userExperience = NumberUtil.max(user.getExperience() + experience, 0); // 防止扣出负数 MemberLevelRecordDO levelRecord = new MemberLevelRecordDO() .setUserId(user.getId()) .setExperience(experience) - // 防止扣出负数 .setUserExperience(userExperience); - - // 创建经验记录 memberExperienceRecordService.createExperienceRecord(userId, experience, userExperience, bizType, bizId); - // 计算会员等级 + // 2.1 保存等级变更记录 MemberLevelDO newLevel = calculateNewLevel(user, userExperience); if (newLevel != null) { - // 复制等级配置 MemberLevelRecordConvert.INSTANCE.copyTo(newLevel, levelRecord); - // 保存等级变更记录 memberLevelRecordService.createLevelRecord(levelRecord); - // 给会员发送等级变动消息 + + // 2.2 给会员发送等级变动消息 notifyMemberLevelChange(userId, newLevel); } - // 更新会员表上的等级编号、经验值 + // 3. 更新会员表上的等级编号、经验值 memberUserService.updateUserLevel(user.getId(), levelRecord.getLevelId(), userExperience); } @@ -301,4 +294,5 @@ public class MemberLevelServiceImpl implements MemberLevelService { private void notifyMemberLevelChange(Long userId, MemberLevelDO level) { //todo: 给会员发消息 } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index 1ffc38809..6bb7bcac7 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -72,22 +72,22 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) { MemberPointConfigDO pointConfig = memberPointConfigService.getPointConfig(); if (pointConfig == null || pointConfig.getTradeGivePoint() == null) { - log.warn("增加积分失败:积分配置”1 元赠送多少分“未设置, userId={}, point={}, bizType={}, bizId={}", + log.error("[createPointRecord][增加积分失败:tradeGivePoint 未配置,userId({}) point({}) bizType({}) bizId({})]", userId, point, bizType.getType(), bizId); return; } - // 根据配置的比例,换算实际的积分 + // 1. 根据配置的比例,换算实际的积分 point = point * pointConfig.getTradeGivePoint(); if (bizType.isReduce() && point > 0) { point = -point; } + // 2. 增加积分记录 MemberUserDO user = memberUserService.getUser(userId); Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); - // 用户变动后的积分,防止扣出负数 + // 用户变动后的积分,防止扣出负数 TODO 疯狂:积分是不是允许扣到负数。因为它是跟有钱有关的东西,不能让商家出现资金损失 Integer totalPoint = NumberUtil.max(userPoint + point, 0); - // 增加积分记录 MemberPointRecordDO recordDO = new MemberPointRecordDO() .setUserId(userId) .setBizId(bizId) @@ -98,7 +98,7 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { .setTotalPoint(totalPoint); recordMapper.insert(recordDO); - // 更新用户积分 + // 3. 更新用户积分 memberUserService.updateUserPoint(userId, totalPoint); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index a1161d668..f1a0a7265 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -162,7 +162,7 @@ public interface MemberUserService { /** * 更新用户的积分 * - * @param userId 用户ID + * @param userId 用户编号 * @param point 积分数量 */ void updateUserPoint(Long userId, Integer point); From f6f33a07d06cbd5c87d28b979106fa5105ba7bf8 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 26 Aug 2023 11:19:43 +0800 Subject: [PATCH 19/26] =?UTF-8?q?code=20review=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E3=80=81=E8=AE=A2=E5=8D=95=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/point/MemberPointRecordServiceImpl.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index 6bb7bcac7..d3699aff6 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -5,8 +5,6 @@ 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.api.user.MemberUserApi; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO; @@ -42,8 +40,6 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { @Resource private MemberPointConfigService memberPointConfigService; - @Resource - private MemberUserApi memberUserApi; @Resource private MemberUserService memberUserService; @@ -52,12 +48,12 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { // 根据用户昵称查询出用户 ids Set userIds = null; if (StringUtils.isNotBlank(pageReqVO.getNickname())) { - List users = memberUserApi.getUserListByNickname(pageReqVO.getNickname()); + List users = memberUserService.getUserListByNickname(pageReqVO.getNickname()); // 如果查询用户结果为空直接返回无需继续查询 if (CollectionUtils.isEmpty(users)) { return PageResult.empty(); } - userIds = convertSet(users, MemberUserRespDTO::getId); + userIds = convertSet(users, MemberUserDO::getId); } // 执行查询 return recordMapper.selectPage(pageReqVO, userIds); From f10b638caf17d94430469c5743c7580b411515d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=AE=E6=A2=A6?= Date: Sat, 26 Aug 2023 12:55:11 +0800 Subject: [PATCH 20/26] =?UTF-8?q?feat:=20=E8=8E=B7=E5=BE=97=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E7=94=A8=E6=88=B7=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=BB=8F=E9=AA=8C=E5=80=BC=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/admin/user/vo/MemberUserRespVO.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java index b4d925f90..eef95a647 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java @@ -43,4 +43,7 @@ public class MemberUserRespVO extends MemberUserBaseVO { @Schema(description = "用户分组", example = "购物达人") private String groupName; + @Schema(description = "用户经验值", example = "100") + private Integer experience; + } From 02abe86253527b1b39414e00e7fd00f1a91beab5 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 26 Aug 2023 13:52:20 +0800 Subject: [PATCH 21/26] =?UTF-8?q?member:=201.=E7=94=A8=E6=88=B7=E7=A7=AF?= =?UTF-8?q?=E5=88=86=E5=8F=98=E5=8A=A8=E6=96=B9=E6=B3=95,=20=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E5=8D=95=E7=8B=AC=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=AD=202.=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderUpdateServiceImpl.java | 27 +++++++++++---- .../member/api/point/MemberPointApi.java | 22 ++++++++++++ .../module/member/api/user/MemberUserApi.java | 13 ------- .../enums/MemberExperienceBizTypeEnum.java | 14 ++++---- .../enums/point/MemberPointBizTypeEnum.java | 9 +++-- .../member/api/point/MemberPointApiImpl.java | 34 +++++++++++++++++++ .../member/api/user/MemberUserApiImpl.java | 17 ---------- .../service/level/MemberLevelServiceImpl.java | 2 +- .../point/MemberPointRecordServiceImpl.java | 7 ++-- 9 files changed, 91 insertions(+), 54 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 85e35f78a..87092b4a6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; @@ -13,6 +14,7 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; @@ -110,6 +112,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private MemberUserApi memberUserApi; @Resource private MemberLevelApi memberLevelApi; + @Resource + private MemberPointApi memberPointApi; @Resource private ProductCommentApi productCommentApi; @@ -346,9 +350,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:OrderLog // 增加用户积分 - addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); + getSelf().addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户经验 - addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); + getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); } /** @@ -617,9 +621,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:未来如果有分佣,需要更新相关分佣订单为已失效 // 扣减用户积分 - reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); + getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 扣减用户经验 - reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); + getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); } @Override @@ -667,7 +671,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())); } - // TODO @疯狂:直接 this 调用,async 不生效哈。全局搜下 getSelf(); @Async protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) { int bizType = MemberExperienceBizTypeEnum.ORDER.getType(); @@ -683,12 +686,22 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) { int bizType = MemberPointBizTypeEnum.ORDER_BUY.getType(); - memberUserApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); + memberPointApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); } @Async protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType(); - memberUserApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); + memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + + /** + * 获得自身的代理对象,解决 AOP 生效问题 + * + * @return 自己 + */ + private TradeOrderUpdateServiceImpl getSelf() { + return SpringUtil.getBean(getClass()); + } + } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java new file mode 100644 index 000000000..5181211f2 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.member.api.point; + +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; + +/** + * 用户积分的 API 接口 + * + * @author owen + */ +public interface MemberPointApi { + + /** + * 增加用户积分 + * + * @param userId 用户编号 + * @param point 积分 + * @param bizType 业务类型 {@link MemberPointBizTypeEnum} + * @param bizId 业务编号 + */ + void addPoint(Long userId, Integer point, Integer bizType, String bizId); + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java index 296868709..3d2130e18 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.member.api.user; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import java.util.Collection; import java.util.List; @@ -57,16 +56,4 @@ public interface MemberUserApi { * @return 用户信息 */ MemberUserRespDTO getUserByMobile(String mobile); - - // TODO @疯狂:是不是新的类,MemberPointApi? - /** - * 增加用户积分 - * - * @param userId 用户编号 - * @param point 积分 - * @param bizType 业务类型 {@link MemberPointBizTypeEnum} - * @param bizId 业务编号 - */ - void addPoint(Long userId, Integer point, Integer bizType, String bizId); - } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java index a287b0cdc..c719ab79f 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java @@ -18,12 +18,12 @@ public enum MemberExperienceBizTypeEnum { /** * 管理员调整、邀请新用户、下单、退单、签到、抽奖 */ - ADMIN(0, "管理员调整", "管理员调整获得 {} 经验", false), - INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验", false), - ORDER(2, "下单奖励", "下单获得 {} 经验", false), - REFUND(3, "退单扣除", "退单获得 {} 经验", true), - SIGN_IN(4, "签到奖励", "签到获得 {} 经验", false), - LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验", false), + ADMIN(0, "管理员调整", "管理员调整获得 {} 经验", true), + INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验", true), + ORDER(2, "下单奖励", "下单获得 {} 经验", true), + REFUND(3, "退单扣除", "退单获得 {} 经验", false), + SIGN_IN(4, "签到奖励", "签到获得 {} 经验", true), + LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验", true), ; /** @@ -41,7 +41,7 @@ public enum MemberExperienceBizTypeEnum { /** * 是否为扣减积分 */ - private final boolean isReduce; + private final boolean add; public static MemberExperienceBizTypeEnum getByType(Integer type) { return EnumUtil.getBy(MemberExperienceBizTypeEnum.class, diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java index e5f7839d8..3d314a4a2 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java @@ -16,9 +16,9 @@ import java.util.Objects; @Getter public enum MemberPointBizTypeEnum implements IntArrayValuable { - SIGN(1, "签到", "签到获得 {} 积分", false), - ORDER_BUY(10, "订单消费", "下单获得 {} 积分", false), - ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", true); // 退回积分 + SIGN(1, "签到", "签到获得 {} 积分", true), + ORDER_BUY(10, "订单消费", "下单获得 {} 积分", true), + ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", false); // 退回积分 /** * 类型 @@ -32,11 +32,10 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable { * 描述 */ private final String description; - // TODO @疯狂:改成 add 会好点。一个是属性我们尽量不要 isXXX;另外尽量正向思维,不取反; /** * 是否为扣减积分 */ - private final boolean isReduce; + private final boolean add; @Override public int[] array() { diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java new file mode 100644 index 000000000..81eec0782 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.member.api.point; + +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; +import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.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; + +/** + * 用户积分的 API 实现类 + * + * @author owen + */ +@Service +@Validated +public class MemberPointApiImpl implements MemberPointApi { + + @Resource + private MemberPointRecordService memberPointRecordService; + + @Override + public void addPoint(Long userId, Integer point, Integer bizType, String bizId) { + MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType); + if (bizTypeEnum == null) { + throw exception(POINT_RECORD_BIZ_NOT_SUPPORT); + } + memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java index 898b7fe9c..8da857c6d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApiImpl.java @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.member.api.user; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; -import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; -import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -13,9 +11,6 @@ import javax.annotation.Resource; import java.util.Collection; import java.util.List; -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; - /** * 会员用户的 API 实现类 * @@ -28,9 +23,6 @@ public class MemberUserApiImpl implements MemberUserApi { @Resource private MemberUserService userService; - @Resource - private MemberPointRecordService memberPointRecordService; - @Override public MemberUserRespDTO getUser(Long id) { MemberUserDO user = userService.getUser(id); @@ -52,13 +44,4 @@ public class MemberUserApiImpl implements MemberUserApi { return MemberUserConvert.INSTANCE.convert2(userService.getUserByMobile(mobile)); } - @Override - public void addPoint(Long userId, Integer point, Integer bizType, String bizId) { - MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType); - if (bizTypeEnum == null) { - throw exception(POINT_RECORD_BIZ_NOT_SUPPORT); - } - memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId); - } - } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index f8bd8b82a..6d4f713dc 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -232,7 +232,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { if (experience == 0) { return; } - if (bizType.isReduce() && experience > 0) { + if (!bizType.isAdd() && experience > 0) { experience = -experience; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index d3699aff6..a107cabe3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.member.service.point; -import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -75,15 +74,15 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { // 1. 根据配置的比例,换算实际的积分 point = point * pointConfig.getTradeGivePoint(); - if (bizType.isReduce() && point > 0) { + if (!bizType.isAdd() && point > 0) { point = -point; } // 2. 增加积分记录 MemberUserDO user = memberUserService.getUser(userId); Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); - // 用户变动后的积分,防止扣出负数 TODO 疯狂:积分是不是允许扣到负数。因为它是跟有钱有关的东西,不能让商家出现资金损失 - Integer totalPoint = NumberUtil.max(userPoint + point, 0); + // 用户变动后的积分 + Integer totalPoint = userPoint + point; MemberPointRecordDO recordDO = new MemberPointRecordDO() .setUserId(userId) .setBizId(bizId) From 1e2c83d90f2fa6e4c95c9541559b00eae5efa772 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 26 Aug 2023 14:40:16 +0800 Subject: [PATCH 22/26] =?UTF-8?q?mall:=20=E5=95=86=E5=93=81=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=86=97=E4=BD=99=20SKU=20?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87=E5=9C=B0=E5=9D=80,=20=E8=A7=84?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/product_comment.sql | 14 ++++++++ .../comment/ProductCommentController.java | 11 +----- .../comment/ProductCommentConvert.java | 34 ++++++++++++------- .../dataobject/comment/ProductCommentDO.java | 9 +++++ .../comment/ProductCommentServiceImpl.java | 25 ++++++-------- .../service/level/MemberLevelServiceImpl.java | 2 +- 6 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 sql/mysql/product_comment.sql diff --git a/sql/mysql/product_comment.sql b/sql/mysql/product_comment.sql new file mode 100644 index 000000000..f567e2923 --- /dev/null +++ b/sql/mysql/product_comment.sql @@ -0,0 +1,14 @@ +-- 1.冗余 SKU 图片地址, 规格 +alter table product_comment + add column sku_pic_url varchar(256) not null comment '图片地址' after sku_id; + +alter table product_comment + add column sku_properties varchar(512) null + comment '属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]' after sku_pic_url; + +-- 2.修复已有数据 +update product_comment pc + join product_sku ps on pc.spu_id = ps.spu_id +set pc.sku_pic_url = ps.pic_url, + pc.sku_properties = ps.properties +where pc.sku_id is not null; \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index d8a779aa3..f44acd4ab 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -5,9 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; -import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; @@ -16,10 +14,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - 商品评价") @@ -30,18 +26,13 @@ public class ProductCommentController { @Resource private ProductCommentService productCommentService; - @Resource - private ProductSkuService productSkuService; @GetMapping("/page") @Operation(summary = "获得商品评价分页") @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { PageResult pageResult = productCommentService.getCommentPage(pageVO); - // 拼接返回 - List skuList = productSkuService.getSkuList( - convertSet(pageResult.getList(), ProductCommentDO::getSkuId)); - return success(ProductCommentConvert.INSTANCE.convertPage(pageResult, skuList)); + return success(ProductCommentConvert.INSTANCE.convertPage2(pageResult)); } @PutMapping("/update-visible") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index 94edc20bf..6fac8823c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.convert.comment; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; @@ -91,7 +92,7 @@ public interface ProductCommentConvert { @Mapping(target = "scores", expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))") - default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, ProductSpuDO spuDO, MemberUserRespDTO user) { + default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, ProductSpuDO spuDO, ProductSkuDO skuDO, MemberUserRespDTO user) { ProductCommentDO commentDO = convert(createReqDTO); if (user != null) { commentDO.setUserId(user.getId()); @@ -102,6 +103,10 @@ public interface ProductCommentConvert { commentDO.setSpuId(spuDO.getId()); commentDO.setSpuName(spuDO.getName()); } + if (skuDO != null) { + commentDO.setSkuPicUrl(skuDO.getPicUrl()); + commentDO.setSkuProperties(skuDO.getProperties()); + } return commentDO; } @@ -117,27 +122,32 @@ public interface ProductCommentConvert { List convertList02(List list); - default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu) { + default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO, ProductSkuDO skuDO) { ProductCommentDO commentDO = convert(createReq); - if (spu != null) { - commentDO.setSpuId(spu.getId()).setSpuName(spu.getName()); + if (spuDO != null) { + commentDO.setSpuId(spuDO.getId()); + commentDO.setSpuName(spuDO.getName()); + } + if (skuDO != null) { + commentDO.setSkuPicUrl(skuDO.getPicUrl()); + commentDO.setSkuProperties(skuDO.getProperties()); } return commentDO; } - default PageResult convertPage(PageResult pageResult, - List skus) { + default PageResult convertPage2(PageResult pageResult) { + Map> propertiesMap = convertMap(pageResult.getList(), + ProductCommentDO::getId, + // 这里会有NULL异常, 需要处理一下 + comment -> CollUtil.emptyIfNull(comment.getSkuProperties())); + PageResult result = convertPage(pageResult); - // 拼接数据 - Map skuMap = convertMap(skus, ProductSkuDO::getId); for (ProductCommentRespVO vo : result.getList()) { - findAndThen(skuMap, vo.getSkuId(), sku -> { - String propertyNames = sku.getProperties().stream() + findAndThen(propertiesMap, vo.getId(), properties -> { + String propertyNames = properties.stream() .map(ProductSkuDO.Property::getValueName) .filter(Objects::nonNull) .collect(Collectors.joining(" ")); - // TODO @疯狂:要不写入评论的时候,把商品图片、商品属性,都冗余进去。因为这种东西有“快照”的需求。商品后续会编辑掉 - vo.setSkuPicUrl(sku.getPicUrl()); vo.setSpuName(vo.getSpuName() + " " + propertyNames); }); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java index 366b237a2..ff4e78468 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java @@ -86,6 +86,15 @@ public class ProductCommentDO extends BaseDO { * 关联 {@link ProductSkuDO#getId()} */ private Long skuId; + /** + * 商品 SKU 图片地址 + */ + private String skuPicUrl; + /** + * 属性数组,JSON 格式 + */ + @TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class) + private List skuProperties; /** * 是否可见 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index fe2a01a93..934946109 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java @@ -53,25 +53,29 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override public void createComment(ProductCommentCreateReqVO createReqVO) { - // 校验商品 - ProductSpuDO spu = validateSpuBySkuId(createReqVO.getSkuId()); + // 校验 SKU + ProductSkuDO skuDO = validateSku(createReqVO.getSkuId()); + // 校验 SPU + ProductSpuDO spuDO = validateSpu(skuDO.getSpuId()); // 创建评论 - ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spu); + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO, skuDO); productCommentMapper.insert(comment); } @Override public Long createComment(ProductCommentCreateReqDTO createReqDTO) { - // 校验商品 - ProductSpuDO spuDO = validateSpuBySkuId(createReqDTO.getSkuId()); + // 校验 SKU + ProductSkuDO skuDO = validateSku(createReqDTO.getSkuId()); + // 校验 SPU + ProductSpuDO spuDO = validateSpu(skuDO.getSpuId()); // 校验评论 validateCommentExists(createReqDTO.getUserId(), createReqDTO.getOrderId()); // 获取用户详细信息 MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId()); // 创建评论 - ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user); + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, skuDO, user); productCommentMapper.insert(comment); return comment.getId(); } @@ -79,7 +83,7 @@ public class ProductCommentServiceImpl implements ProductCommentService { /** * 判断当前订单的当前商品用户是否评价过 * - * @param userId 用户编号 + * @param userId 用户编号 * @param orderItemId 订单项编号 */ private void validateCommentExists(Long userId, Long orderItemId) { @@ -105,13 +109,6 @@ public class ProductCommentServiceImpl implements ProductCommentService { return spu; } - private ProductSpuDO validateSpuBySkuId(Long skuId) { - // 通过 sku ID 拿到 spu 相关信息 - ProductSkuDO sku = validateSku(skuId); - // 校验 spu 如果存在返回详情 - return validateSpu(sku.getSpuId()); - } - @Override public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { // 校验评论是否存在 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java index 6d4f713dc..d42f86ec0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/level/MemberLevelServiceImpl.java @@ -200,7 +200,7 @@ public class MemberLevelServiceImpl implements MemberLevelService { if (updateReqVO.getLevelId() == null) { // 取消用户等级时,需要扣减经验 levelRecord.setExperience(-user.getExperience()); - // TODO @疯狂:这里是不是也要设置下 setUserExperience 属性; + levelRecord.setUserExperience(0); levelRecord.setDescription("管理员取消了等级"); } else { // 复制等级配置 From 99dd33c4080082244ebfbb50a8ff44aaa4dfa6bc Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 26 Aug 2023 20:57:49 +0800 Subject: [PATCH 23/26] =?UTF-8?q?code=20review=EF=BC=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E7=9A=84=E8=AF=A6=E6=83=85=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=20totalPoint=20=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/admin/user/vo/MemberUserRespVO.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java index eef95a647..1cd228335 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/MemberUserRespVO.java @@ -31,9 +31,12 @@ public class MemberUserRespVO extends MemberUserBaseVO { // ========== 其它信息 ========== - @Schema(description = "积分", example = "100") + @Schema(description = "积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer point; + @Schema(description = "总积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000") + private Integer totalPoint; + @Schema(description = "会员标签", example = "[红色, 快乐]") private List tagNames; @@ -43,7 +46,7 @@ public class MemberUserRespVO extends MemberUserBaseVO { @Schema(description = "用户分组", example = "购物达人") private String groupName; - @Schema(description = "用户经验值", example = "100") + @Schema(description = "用户经验值", requiredMode = Schema.RequiredMode.REQUIRED, example = "200") private Integer experience; } From f5c5d383032efdd1e5bbc5d03a0778cc4eef8ddc Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 26 Aug 2023 21:23:01 +0800 Subject: [PATCH 24/26] =?UTF-8?q?code=20review=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/product_comment.sql | 14 ------ .../comment/ProductCommentController.java | 2 +- .../comment/vo/ProductCommentRespVO.java | 10 ++++- .../admin/sku/ProductSkuController.java | 45 +------------------ .../admin/sku/vo/ProductSkuOptionRespVO.java | 30 ------------- .../comment/ProductCommentConvert.java | 34 +++----------- .../convert/sku/ProductSkuConvert.java | 3 -- .../dataobject/comment/ProductCommentDO.java | 7 +++ .../point/MemberPointRecordServiceImpl.java | 17 +++---- 9 files changed, 28 insertions(+), 134 deletions(-) delete mode 100644 sql/mysql/product_comment.sql delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuOptionRespVO.java diff --git a/sql/mysql/product_comment.sql b/sql/mysql/product_comment.sql deleted file mode 100644 index f567e2923..000000000 --- a/sql/mysql/product_comment.sql +++ /dev/null @@ -1,14 +0,0 @@ --- 1.冗余 SKU 图片地址, 规格 -alter table product_comment - add column sku_pic_url varchar(256) not null comment '图片地址' after sku_id; - -alter table product_comment - add column sku_properties varchar(512) null - comment '属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]' after sku_pic_url; - --- 2.修复已有数据 -update product_comment pc - join product_sku ps on pc.spu_id = ps.spu_id -set pc.sku_pic_url = ps.pic_url, - pc.sku_properties = ps.properties -where pc.sku_id is not null; \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index f44acd4ab..70e95cd9a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -32,7 +32,7 @@ public class ProductCommentController { @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { PageResult pageResult = productCommentService.getCommentPage(pageVO); - return success(ProductCommentConvert.INSTANCE.convertPage2(pageResult)); + return success(ProductCommentConvert.INSTANCE.convertPage(pageResult)); } @PutMapping("/update-visible") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java index 8e3c732a5..d03359f7f 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.controller.admin.comment.vo; +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -7,6 +8,7 @@ import lombok.ToString; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.List; @Schema(description = "管理后台 - 商品评价 Response VO") @Data @@ -23,10 +25,10 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428") private Long orderId; - @Schema(description = "是否可见:[true:显示 false:隐藏]", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED) private Boolean visible; - @Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED) private Boolean replyStatus; @Schema(description = "回复管理员编号", example = "9527") @@ -54,4 +56,8 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg") private String skuPicUrl; + + @Schema(description = "商品 SKU 规格值数组") + private List skuProperties; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java index 038642db1..9acbacd66 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java @@ -1,57 +1,14 @@ package cn.iocoder.yudao.module.product.controller.admin.sku; -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO; -import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; -import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; -import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; -import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; -import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; - -@Tag(name = "管理后台 - 商品 sku") +@Tag(name = "管理后台 - 商品 SKU") @RestController @RequestMapping("/product/sku") @Validated public class ProductSkuController { - @Resource - private ProductSkuService productSkuService; - @Resource - private ProductSpuService productSpuService; - - @GetMapping("/get-option-list") - @Operation(summary = "获得商品 SKU 选项的列表") -// @PreAuthorize("@ss.hasPermission('product:sku:query')") - public CommonResult> getSkuOptionList() { - // 获得 SKU 列表 - List skus = productSkuService.getSkuList(); - if (CollUtil.isEmpty(skus)) { - return success(Collections.emptyList()); - } - - // 获得对应的 SPU 映射 - Map spuMap = productSpuService.getSpuMap(convertSet(skus, ProductSkuDO::getSpuId)); - // 转换为返回结果 - List skuVOs = ProductSkuConvert.INSTANCE.convertList05(skus); - skuVOs.forEach(sku -> MapUtils.findAndThen(spuMap, sku.getSpuId(), - spu -> sku.setSpuId(spu.getId()).setSpuName(spu.getName()))); - return success(skuVOs); - } - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuOptionRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuOptionRespVO.java deleted file mode 100644 index f06ecc358..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuOptionRespVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.sku.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - 商品 SKU 选项 Response VO") // 用于前端 SELECT 选项 -@Data -public class ProductSkuOptionRespVO { - - @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - - @Schema(description = "商品 SKU 名字", example = "红色") - private String name; - - @Schema(description = "销售价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private String price; - - @Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private Integer stock; - - // ========== 商品 SPU 信息 ========== - - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long spuId; - - @Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "iPhone 11") - private String spuName; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index 6fac8823c..944eb2bc2 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.product.convert.comment; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; @@ -23,10 +22,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; /** @@ -122,35 +118,15 @@ public interface ProductCommentConvert { List convertList02(List list); - default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO, ProductSkuDO skuDO) { + default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) { ProductCommentDO commentDO = convert(createReq); - if (spuDO != null) { - commentDO.setSpuId(spuDO.getId()); - commentDO.setSpuName(spuDO.getName()); + if (spu != null) { + commentDO.setSpuId(spu.getId()).setSpuName(spu.getName()); } - if (skuDO != null) { - commentDO.setSkuPicUrl(skuDO.getPicUrl()); - commentDO.setSkuProperties(skuDO.getProperties()); + if (sku != null) { + commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties()); } return commentDO; } - default PageResult convertPage2(PageResult pageResult) { - Map> propertiesMap = convertMap(pageResult.getList(), - ProductCommentDO::getId, - // 这里会有NULL异常, 需要处理一下 - comment -> CollUtil.emptyIfNull(comment.getSkuProperties())); - - PageResult result = convertPage(pageResult); - for (ProductCommentRespVO vo : result.getList()) { - findAndThen(propertiesMap, vo.getId(), properties -> { - String propertyNames = properties.stream() - .map(ProductSkuDO.Property::getValueName) - .filter(Objects::nonNull) - .collect(Collectors.joining(" ")); - vo.setSpuName(vo.getSpuName() + " " + propertyNames); - }); - } - return result; - } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java index 2b78a00ef..5065a9c40 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java @@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import org.mapstruct.Mapper; @@ -44,8 +43,6 @@ public interface ProductSkuConvert { List convertList04(List list); - List convertList05(List skus); - /** * 获得 SPU 的库存变化 Map * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java index ff4e78468..40b04caf0 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java @@ -73,11 +73,14 @@ public class ProductCommentDO extends BaseDO { /** * 商品 SPU 编号 + * * 关联 {@link ProductSpuDO#getId()} */ private Long spuId; /** * 商品 SPU 名称 + * + * 关联 {@link ProductSpuDO#getName()} */ private String spuName; /** @@ -88,10 +91,14 @@ public class ProductCommentDO extends BaseDO { private Long skuId; /** * 商品 SKU 图片地址 + * + * 关联 {@link ProductSkuDO#getPicUrl()} */ private String skuPicUrl; /** * 属性数组,JSON 格式 + * + * 关联 {@link ProductSkuDO#getProperties()} */ @TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class) private List skuProperties; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index a107cabe3..8801ef33d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -81,17 +81,12 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { // 2. 增加积分记录 MemberUserDO user = memberUserService.getUser(userId); Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); - // 用户变动后的积分 - Integer totalPoint = userPoint + point; - MemberPointRecordDO recordDO = new MemberPointRecordDO() - .setUserId(userId) - .setBizId(bizId) - .setBizType(bizType.getType()) - .setTitle(bizType.getName()) - .setDescription(StrUtil.format(bizType.getDescription(), point)) - .setPoint(point) - .setTotalPoint(totalPoint); - recordMapper.insert(recordDO); + Integer totalPoint = userPoint + point; // 用户变动后的积分 + MemberPointRecordDO record = new MemberPointRecordDO() + .setUserId(userId).setBizId(bizId).setBizType(bizType.getType()) + .setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), point)) + .setPoint(point).setTotalPoint(totalPoint); + recordMapper.insert(record); // 3. 更新用户积分 memberUserService.updateUserPoint(userId, totalPoint); From 35c1ba44d32e5da4df3429eeda1a06d09248515e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 27 Aug 2023 16:15:41 +0800 Subject: [PATCH 25/26] =?UTF-8?q?=E4=BC=98=E5=8C=96=20AbstractAlipayClient?= =?UTF-8?q?Test=E3=80=81AlipayBarPayClientTest=20=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=91=BD=E5=90=8D=EF=BC=8C=E8=A1=A5=E5=85=A8=20assert?= =?UTF-8?q?=20=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/alipay/AbstractAlipayPayClient.java | 2 + .../impl/alipay/AlipayBarPayClient.java | 8 +- .../impl/alipay/AbstractAlipayClientTest.java | 90 ++++++++++--------- .../impl/alipay/AlipayBarPayClientTest.java | 61 ++++++++----- 4 files changed, 94 insertions(+), 67 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java index 5e52e8e8e..b1edf87ac 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java @@ -27,6 +27,7 @@ import com.alipay.api.request.AlipayTradeRefundRequest; import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse; import com.alipay.api.response.AlipayTradeQueryResponse; import com.alipay.api.response.AlipayTradeRefundResponse; +import lombok.Getter; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -47,6 +48,7 @@ import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMATTER; @Slf4j public abstract class AbstractAlipayPayClient extends AbstractPayClient { + @Getter // 仅用于单测场景 protected DefaultAlipayClient client; public AbstractAlipayPayClient(Long channelId, String channelCode, AlipayPayClientConfig config) { diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java index 5254bc8c9..94644430f 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java @@ -13,6 +13,8 @@ import com.alipay.api.request.AlipayTradePayRequest; import com.alipay.api.response.AlipayTradePayResponse; import lombok.extern.slf4j.Slf4j; +import java.time.LocalDateTime; + import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0; @@ -63,8 +65,10 @@ public class AlipayBarPayClient extends AbstractAlipayPayClient { return buildClosedPayOrderRespDTO(reqDTO, response); } if ("10000".equals(response.getCode())) { // 免密支付 - return PayOrderRespDTO.successOf(response.getTradeNo(), response.getBuyerUserId(), LocalDateTimeUtil.of(response.getGmtPayment()), - response.getOutTradeNo(), response); + LocalDateTime successTime = LocalDateTimeUtil.of(response.getGmtPayment()); + return PayOrderRespDTO.successOf(response.getTradeNo(), response.getBuyerUserId(), successTime, + response.getOutTradeNo(), response) + .setDisplayMode(displayMode).setDisplayContent(""); } // 大额支付,需要用户输入密码,所以返回 waiting。此时,前端一般会进行轮询 return PayOrderRespDTO.waitingOf(displayMode, "", diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClientTest.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClientTest.java index 664a3ce52..57d629021 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClientTest.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClientTest.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.ReflectUtil; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; @@ -18,6 +17,7 @@ import com.alipay.api.DefaultSigner; import com.alipay.api.domain.AlipayTradeRefundModel; import com.alipay.api.request.AlipayTradeRefundRequest; import com.alipay.api.response.AlipayTradeRefundResponse; +import lombok.Setter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -34,25 +34,26 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.when; /** + * 支付宝 Client 的测试基类 + * * @author jason */ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { - private final String privateKey = randomString(); - - protected AlipayPayClientConfig config = randomPojo(AlipayPayClientConfig.class, t -> { - t.setServerUrl(randomURL()); - t.setPrivateKey(privateKey); - t.setMode(MODE_PUBLIC_KEY); - t.setSignType(AlipayPayClientConfig.SIGN_TYPE_DEFAULT); - t.setAppCertContent(""); - t.setAlipayPublicCertContent(""); - t.setRootCertContent(""); + protected AlipayPayClientConfig config = randomPojo(AlipayPayClientConfig.class, o -> { + o.setServerUrl(randomURL()); + o.setPrivateKey(randomString()); + o.setMode(MODE_PUBLIC_KEY); + o.setSignType(AlipayPayClientConfig.SIGN_TYPE_DEFAULT); + o.setAppCertContent(""); + o.setAlipayPublicCertContent(""); + o.setRootCertContent(""); }); @Mock protected DefaultAlipayClient defaultAlipayClient; + @Setter private AbstractAlipayPayClient client; /** @@ -61,24 +62,22 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { @BeforeEach public abstract void setUp(); - public void setClient(AbstractAlipayPayClient client) { - this.client = client; - } - @Test @DisplayName("支付宝 Client 初始化") - public void test_do_init() { + public void testDoInit() { + // 调用 client.doInit(); - DefaultAlipayClient realClient = (DefaultAlipayClient) ReflectUtil.getFieldValue(client, "client"); + // 断言 + DefaultAlipayClient realClient = client.getClient(); assertNotSame(defaultAlipayClient, realClient); assertInstanceOf(DefaultSigner.class, realClient.getSigner()); - assertEquals(privateKey, ((DefaultSigner) realClient.getSigner()).getPrivateKey()); + assertEquals(config.getPrivateKey(), ((DefaultSigner) realClient.getSigner()).getPrivateKey()); } @Test - @DisplayName("支付宝 Client 统一退款成功") - public void test_unified_refund_success() throws AlipayApiException { - // 准备返回对象 + @DisplayName("支付宝 Client 统一退款:成功") + public void testUnifiedRefund_success() throws AlipayApiException { + // mock 方法 String notifyUrl = randomURL(); Date refundTime = randomDate(); String outRefundNo = randomString(); @@ -88,7 +87,6 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { o.setSubCode(""); o.setGmtRefundPay(refundTime); }); - // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> { assertInstanceOf(AlipayTradeRefundModel.class, request.getBizModel()); AlipayTradeRefundModel bizModel = (AlipayTradeRefundModel) request.getBizModel(); @@ -104,19 +102,23 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { o.setNotifyUrl(notifyUrl); o.setRefundPrice(refundAmount); }); + + // 调用 PayRefundRespDTO resp = client.unifiedRefund(refundReqDTO); // 断言 assertEquals(PayRefundStatusRespEnum.SUCCESS.getStatus(), resp.getStatus()); + assertEquals(outRefundNo, resp.getOutRefundNo()); assertNull(resp.getChannelRefundNo()); assertEquals(LocalDateTimeUtil.of(refundTime), resp.getSuccessTime()); - assertEquals(outRefundNo, resp.getOutRefundNo()); assertSame(response, resp.getRawData()); + assertNull(resp.getChannelErrorCode()); + assertNull(resp.getChannelErrorMsg()); } @Test - @DisplayName("支付宝 Client 统一退款,渠道返回失败") + @DisplayName("支付宝 Client 统一退款:渠道返回失败") public void test_unified_refund_channel_failed() throws AlipayApiException { - // 准备返回对象 + // mock 方法 String notifyUrl = randomURL(); String subCode = randomString(); String subMsg = randomString(); @@ -124,7 +126,6 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { o.setSubCode(subCode); o.setSubMsg(subMsg); }); - // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> { assertInstanceOf(AlipayTradeRefundModel.class, request.getBizModel()); return true; @@ -137,59 +138,64 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { o.setOutTradeNo(outTradeNo); o.setNotifyUrl(notifyUrl); }); + + // 调用 PayRefundRespDTO resp = client.unifiedRefund(refundReqDTO); // 断言 assertEquals(PayRefundStatusRespEnum.FAILURE.getStatus(), resp.getStatus()); + assertEquals(outRefundNo, resp.getOutRefundNo()); assertNull(resp.getChannelRefundNo()); + assertNull(resp.getSuccessTime()); + assertSame(response, resp.getRawData()); assertEquals(subCode, resp.getChannelErrorCode()); assertEquals(subMsg, resp.getChannelErrorMsg()); - assertNull(resp.getSuccessTime()); - assertEquals(outRefundNo, resp.getOutRefundNo()); - assertSame(response, resp.getRawData()); } @Test - @DisplayName("支付宝 Client 统一退款,参数校验不通过") - public void test_unified_refund_param_validate() { + @DisplayName("支付宝 Client 统一退款:参数校验不通过") + public void testUnifiedRefund_paramInvalidate() { // 准备请求参数 String notifyUrl = randomURL(); PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> { o.setOutTradeNo(""); o.setNotifyUrl(notifyUrl); }); - // 断言 + + // 调用,并断言 assertThrows(ConstraintViolationException.class, () -> client.unifiedRefund(refundReqDTO)); } @Test - @DisplayName("支付宝 Client 统一退款,抛出业务异常") - public void test_unified_refund_throw_service_exception() throws AlipayApiException { + @DisplayName("支付宝 Client 统一退款:抛出业务异常") + public void testUnifiedRefund_throwServiceException() throws AlipayApiException { // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) .thenThrow(ServiceExceptionUtil.exception(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR)); // 准备请求参数 String notifyUrl = randomURL(); PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> o.setNotifyUrl(notifyUrl)); - // 断言 + + // 调用,并断言 assertThrows(ServiceException.class, () -> client.unifiedRefund(refundReqDTO)); } @Test - @DisplayName("支付宝 Client 统一退款,抛出系统异常") - public void test_unified_refund_throw_pay_exception() throws AlipayApiException { + @DisplayName("支付宝 Client 统一退款:抛出系统异常") + public void testUnifiedRefund_throwPayException() throws AlipayApiException { // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) .thenThrow(new RuntimeException("系统异常")); // 准备请求参数 String notifyUrl = randomURL(); PayRefundUnifiedReqDTO refundReqDTO = randomPojo(PayRefundUnifiedReqDTO.class, o -> o.setNotifyUrl(notifyUrl)); - // 断言 + + // 调用,并断言 assertThrows(PayException.class, () -> client.unifiedRefund(refundReqDTO)); } @Test - @DisplayName("支付宝 Client 统一下单, 参数校验不通过") - public void test_unified_order_param_validate() { + @DisplayName("支付宝 Client 统一下单:参数校验不通过") + public void testUnifiedOrder_paramInvalidate() { // 准备请求参数 String outTradeNo = randomString(); String notifyUrl = randomURL(); @@ -197,7 +203,8 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { o.setOutTradeNo(outTradeNo); o.setNotifyUrl(notifyUrl); }); - // 断言 + + // 调用,并断言 assertThrows(ConstraintViolationException.class, () -> client.unifiedOrder(reqDTO)); } @@ -210,4 +217,5 @@ public abstract class AbstractAlipayClientTest extends BaseMockitoUnitTest { o.setBody(RandomUtil.randomString(32)); }); } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java index b6f24e136..47f10081c 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClientTest.java @@ -28,7 +28,7 @@ import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.when; /** - * {@link AlipayBarPayClient} 单元测试 + * {@link AlipayBarPayClient} 单元测试 * * @author jason */ @@ -44,16 +44,14 @@ public class AlipayBarPayClientTest extends AbstractAlipayClientTest { } @Test - @DisplayName("支付宝条码支付,非免密码支付下单成功") - public void test_unified_order_success() throws AlipayApiException { + @DisplayName("支付宝条码支付:非免密码支付下单成功") + public void testUnifiedOrder_success() throws AlipayApiException { + // mock 方法 String outTradeNo = randomString(); String notifyUrl = randomURL(); Integer price = randomInteger(); String authCode = randomString(); - // 准备返回对象 AlipayTradePayResponse response = randomPojo(AlipayTradePayResponse.class, o -> o.setSubCode("")); - - // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> { assertInstanceOf(AlipayTradePayModel.class, request.getBizModel()); assertEquals(notifyUrl, request.getNotifyUrl()); @@ -65,28 +63,33 @@ public class AlipayBarPayClientTest extends AbstractAlipayClientTest { }))).thenReturn(response); // 准备请求参数 PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); - // 设置条码 Map extraParam = new HashMap<>(); extraParam.put("auth_code", authCode); reqDTO.setChannelExtras(extraParam); - // 下单请求 + + // 调用方法 PayOrderRespDTO resp = client.unifiedOrder(reqDTO); // 断言 assertEquals(WAITING.getStatus(), resp.getStatus()); - assertEquals(PayOrderDisplayModeEnum.BAR_CODE.getMode(), resp.getDisplayMode()); assertEquals(outTradeNo, resp.getOutTradeNo()); + assertNull(resp.getChannelOrderNo()); + assertNull(resp.getChannelUserId()); + assertNull(resp.getSuccessTime()); + assertEquals(PayOrderDisplayModeEnum.BAR_CODE.getMode(), resp.getDisplayMode()); assertEquals("", resp.getDisplayContent()); assertSame(response, resp.getRawData()); + assertNull(resp.getChannelErrorCode()); + assertNull(resp.getChannelErrorMsg()); } @Test - @DisplayName("支付宝条码支付,免密码支付下单成功") - public void test_unified_order_code_10000_success() throws AlipayApiException { + @DisplayName("支付宝条码支付:免密码支付下单成功") + public void testUnifiedOrder_code10000Success() throws AlipayApiException { + // mock 方法 String outTradeNo = randomString(); String channelNo = randomString(); String channelUserId = randomString(); Date payTime = randomDate(); - // 准备返回对象 AlipayTradePayResponse response = randomPojo(AlipayTradePayResponse.class, o -> { o.setSubCode(""); o.setCode("10000"); @@ -95,16 +98,15 @@ public class AlipayBarPayClientTest extends AbstractAlipayClientTest { o.setBuyerUserId(channelUserId); o.setGmtPayment(payTime); }); - // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) .thenReturn(response); // 准备请求参数 String authCode = randomString(); PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), outTradeNo, randomInteger()); - // 设置条码 Map extraParam = new HashMap<>(); extraParam.put("auth_code", authCode); reqDTO.setChannelExtras(extraParam); + // 下单请求 PayOrderRespDTO resp = client.unifiedOrder(reqDTO); // 断言 @@ -113,45 +115,56 @@ public class AlipayBarPayClientTest extends AbstractAlipayClientTest { assertEquals(channelNo, resp.getChannelOrderNo()); assertEquals(channelUserId, resp.getChannelUserId()); assertEquals(LocalDateTimeUtil.of(payTime), resp.getSuccessTime()); + assertEquals(PayOrderDisplayModeEnum.BAR_CODE.getMode(), resp.getDisplayMode()); + assertEquals("", resp.getDisplayContent()); assertSame(response, resp.getRawData()); + assertNull(resp.getChannelErrorCode()); + assertNull(resp.getChannelErrorMsg()); } @Test - @DisplayName("支付宝条码支付,没有传条码") - public void test_unified_order_empty_auth_code() { + @DisplayName("支付宝条码支付:没有传条码") + public void testUnifiedOrder_emptyAuthCode() { + // 准备参数 PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), randomString(), randomInteger()); - // 断言 + + // 调用,并断言 assertThrows(ServiceException.class, () -> client.unifiedOrder(reqDTO)); } @Test - @DisplayName("支付宝条码支付,渠道返回失败") + @DisplayName("支付宝条码支付:渠道返回失败") public void test_unified_order_channel_failed() throws AlipayApiException { - // 准备响应对象 + // mock 方法 String subCode = randomString(); String subMsg = randomString(); AlipayTradePayResponse response = randomPojo(AlipayTradePayResponse.class, o -> { o.setSubCode(subCode); o.setSubMsg(subMsg); }); - // mock when(defaultAlipayClient.execute(argThat((ArgumentMatcher) request -> true))) .thenReturn(response); // 准备请求参数 String authCode = randomString(); String outTradeNo = randomString(); PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), outTradeNo, randomInteger()); - // 设置条码 Map extraParam = new HashMap<>(); extraParam.put("auth_code", authCode); reqDTO.setChannelExtras(extraParam); - // 下单请求 + + // 调用方法 PayOrderRespDTO resp = client.unifiedOrder(reqDTO); // 断言 assertEquals(CLOSED.getStatus(), resp.getStatus()); + assertEquals(outTradeNo, resp.getOutTradeNo()); + assertNull(resp.getChannelOrderNo()); + assertNull(resp.getChannelUserId()); + assertNull(resp.getSuccessTime()); + assertNull(resp.getDisplayMode()); + assertNull(resp.getDisplayContent()); + assertSame(response, resp.getRawData()); assertEquals(subCode, resp.getChannelErrorCode()); assertEquals(subMsg, resp.getChannelErrorMsg()); - assertSame(response, resp.getRawData()); - } + } From 1baa7f4aee6ab958961fa804d9adeb10c171045e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 27 Aug 2023 16:33:19 +0800 Subject: [PATCH 26/26] =?UTF-8?q?=E4=BC=98=E5=8C=96=20AlipayPcPayClientTes?= =?UTF-8?q?t=20=E7=9A=84=E6=96=B9=E6=B3=95=E5=91=BD=E5=90=8D=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=20assert=20=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/alipay/AlipayPcPayClientTest.java | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java index 9dfa6acc1..b94ae7148 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java @@ -16,8 +16,8 @@ import org.mockito.InjectMocks; import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.CLOSED; import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.WAITING; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -39,36 +39,40 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { } @Test - @DisplayName("支付宝 PC 网站支付 URL Display Mode 下单成功") - public void test_unified_order_url_display_mode_success() throws AlipayApiException { - // 准备返回对象 + @DisplayName("支付宝 PC 网站支付:URL Display Mode 下单成功") + public void testUnifiedOrder_urlSuccess() throws AlipayApiException { + // mock 方法 String notifyUrl = randomURL(); AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); - // mock when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher) request -> true), eq(Method.GET.name()))).thenReturn(response); // 准备请求参数 String outTradeNo = randomString(); Integer price = randomInteger(); PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); - // 设置 displayMode 为 null. reqDTO.setDisplayMode(null); + // 调用 PayOrderRespDTO resp = client.unifiedOrder(reqDTO); // 断言 assertEquals(WAITING.getStatus(), resp.getStatus()); - assertEquals(PayOrderDisplayModeEnum.URL.getMode(), resp.getDisplayMode()); assertEquals(outTradeNo, resp.getOutTradeNo()); + assertNull(resp.getChannelOrderNo()); + assertNull(resp.getChannelUserId()); + assertNull(resp.getSuccessTime()); + assertEquals(PayOrderDisplayModeEnum.URL.getMode(), resp.getDisplayMode()); + assertEquals(response.getBody(), resp.getDisplayContent()); assertSame(response, resp.getRawData()); + assertNull(resp.getChannelErrorCode()); + assertNull(resp.getChannelErrorMsg()); } @Test - @DisplayName("支付宝 PC 网站支付 FORM Display Mode 下单成功") - public void test_unified_order_form_display_mode_success() throws AlipayApiException { - // 准备返回对象 + @DisplayName("支付宝 PC 网站支付:Form Display Mode 下单成功") + public void testUnifiedOrder_formSuccess() throws AlipayApiException { + // mock String notifyUrl = randomURL(); AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); - // mock when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher) request -> true), eq(Method.POST.name()))).thenReturn(response); // 准备请求参数 @@ -77,36 +81,51 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); reqDTO.setDisplayMode(PayOrderDisplayModeEnum.FORM.getMode()); + // 调用 PayOrderRespDTO resp = client.unifiedOrder(reqDTO); // 断言 assertEquals(WAITING.getStatus(), resp.getStatus()); - assertEquals(PayOrderDisplayModeEnum.FORM.getMode(), resp.getDisplayMode()); assertEquals(outTradeNo, resp.getOutTradeNo()); + assertNull(resp.getChannelOrderNo()); + assertNull(resp.getChannelUserId()); + assertNull(resp.getSuccessTime()); + assertEquals(PayOrderDisplayModeEnum.FORM.getMode(), resp.getDisplayMode()); + assertEquals(response.getBody(), resp.getDisplayContent()); assertSame(response, resp.getRawData()); + assertNull(resp.getChannelErrorCode()); + assertNull(resp.getChannelErrorMsg()); } @Test - @DisplayName("支付宝 PC 网站支付,渠道返回失败") - public void test_unified_order_channel_failed() throws AlipayApiException { - // 准备响应对象 + @DisplayName("支付宝 PC 网站支付:渠道返回失败") + public void testUnifiedOrder_channelFailed() throws AlipayApiException { + // mock String subCode = randomString(); String subMsg = randomString(); AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> { o.setSubCode(subCode); o.setSubMsg(subMsg); }); - // mock when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher) request -> true), eq(Method.GET.name()))).thenReturn(response); // 准备请求参数 - PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), randomString(), randomInteger()); + String outTradeNo = randomString(); + PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), outTradeNo, randomInteger()); reqDTO.setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()); + // 调用 PayOrderRespDTO resp = client.unifiedOrder(reqDTO); // 断言 assertEquals(CLOSED.getStatus(), resp.getStatus()); + assertEquals(outTradeNo, resp.getOutTradeNo()); + assertNull(resp.getChannelOrderNo()); + assertNull(resp.getChannelUserId()); + assertNull(resp.getSuccessTime()); + assertNull(resp.getDisplayMode()); + assertNull(resp.getDisplayContent()); + assertSame(response, resp.getRawData()); assertEquals(subCode, resp.getChannelErrorCode()); assertEquals(subMsg, resp.getChannelErrorMsg()); - assertSame(response, resp.getRawData()); } + }