From 75afab1f86c00f4e465ea6fd94de7fbd66bb5a5b Mon Sep 17 00:00:00 2001 From: chenchen <934298133@qq.com> Date: Sun, 25 Jun 2023 23:08:07 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=94=AE=E5=90=8E=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/aftersale/AfterSaleOperateTypeEnum.java | 15 +++++++++------ .../dataobject/aftersale/TradeAfterSaleLogDO.java | 1 - ...iguration.java => AfterSaleConfiguration.java} | 5 ++--- .../aftersalelog/core/aop/AfterSaleLogAspect.java | 7 ++++--- .../aftersale/TradeAfterSaleServiceImpl.java | 11 +---------- 5 files changed, 16 insertions(+), 23 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/{AfterSaleLogConfiguration.java => AfterSaleConfiguration.java} (76%) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java index da41c2b93..7e374e335 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/AfterSaleOperateTypeEnum.java @@ -1,26 +1,29 @@ package cn.iocoder.yudao.module.trade.enums.aftersale; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + /** * 售后操作类型的枚举 * * @author 陈賝 * @since 2023/6/13 13:53 */ -// TODO @chenchen:可以 lombok 简化构造方法,和 get 方法 +@RequiredArgsConstructor +@Getter public enum AfterSaleOperateTypeEnum { /** * 用户申请 */ - APPLY("用户申请"), + APPLY(0, "用户申请"), ; + // 类型 + private final Integer type; + // 描述 private final String description; - AfterSaleOperateTypeEnum(String description) { - this.description = description; - } - public String description() { return description; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java index 56a0f0f32..168eb741f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java @@ -49,7 +49,6 @@ public class TradeAfterSaleLogDO extends BaseDO { * 关联 {@link TradeAfterSaleDO#getId()} */ private Long afterSaleId; - // todo @CHENCHEN: 改成 Integer 哈;主要未来改文案,不好洗 log 存的字段; /** * 操作类型 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleConfiguration.java similarity index 76% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleConfiguration.java index 1c382d24f..7c7fc7f4f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleLogConfiguration.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/config/AfterSaleConfiguration.java @@ -4,15 +4,14 @@ import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLo import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -// TODO @chenchen:改成 aftersale 好点哈; /** - * trade 模块的 afterSaleLog 组件的 Configuration + * trade 模块的 afterSale 组件的 Configuration * * @author 陈賝 * @since 2023/6/18 11:09 */ @Configuration(proxyBeanMethods = false) -public class AfterSaleLogConfiguration { +public class AfterSaleConfiguration { @Bean public AfterSaleLogAspect afterSaleLogAspect() { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java index 93186edf1..5ff16d38a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java @@ -31,12 +31,13 @@ import static java.util.Arrays.asList; @Aspect public class AfterSaleLogAspect { + private final static String OPERATE_TYPE = "operateType"; + private final static String ID = "id"; + private final static String CONTENT = "content"; + @Resource private AfterSaleLogService afterSaleLogService; - // TODO chenchen: 这个分 3 行把; - private final static String OPERATE_TYPE = "operateType", ID = "id", CONTENT = "content"; - /** * 切面存入日志 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index fc86f230a..a5fa11c9e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -398,14 +398,6 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa this.createLog(logDTO); } - // TODO @CHENCHEN:这个注释,写在接口就好了,补充重复写哈;@date 应该是 @since - /** - * 日志记录 - * - * @param logDTO 日志记录 - * @author 陈賝 - * @date 2023/6/12 14:18 - */ @Override @Async public void createLog(TradeAfterSaleLogCreateReqDTO logDTO) { @@ -417,8 +409,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa .setOperateType(logDTO.getOperateType()) .setContent(logDTO.getContent()); tradeAfterSaleLogMapper.insert(afterSaleLog); - // TODO @CHENCHEN:代码排版哈;空格要正确 - }catch (Exception exception){ + } catch (Exception exception) { log.error("[createLog][request({}) 日志记录错误]", toJsonString(logDTO), exception); } } From 2865c28a9f8768f805db262da10fdc5bdbb71477 Mon Sep 17 00:00:00 2001 From: chenchen <934298133@qq.com> Date: Tue, 27 Jun 2023 23:07:06 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E5=94=AE=E5=90=8E=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8Cmap->=E6=8A=BD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aftersale/TradeAfterSaleLogDO.java | 2 +- .../core/aop/AfterSaleLogAspect.java | 65 +++++++++++++------ .../dto/TradeAfterSaleLogCreateReqDTO.java | 2 +- .../aftersale/TradeAfterSaleServiceImpl.java | 2 +- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java index 168eb741f..1e18bf6e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/aftersale/TradeAfterSaleLogDO.java @@ -54,7 +54,7 @@ public class TradeAfterSaleLogDO extends BaseDO { * * 枚举 {@link AfterSaleOperateTypeEnum} */ - private String operateType; + private Integer operateType; /** * 操作明细 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java index 5ff16d38a..cdb2c0a48 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java @@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; @@ -47,13 +48,12 @@ public class AfterSaleLogAspect { // 日志对象拼接 Integer userType = WebFrameworkUtils.getLoginUserType(); Long id = WebFrameworkUtils.getLoginUserId(); - Map formatObj = spelFormat(joinPoint, info); TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO() .setUserId(id) .setUserType(userType) - .setAfterSaleId(MapUtil.getLong(formatObj, ID)) - .setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE)) - .setContent(MapUtil.getStr(formatObj, CONTENT)); + .setAfterSaleId(getAfterSaleId(joinPoint, info, afterSaleLog.id())) + .setOperateType(afterSaleLog.operateType().getType()) + .setContent(getContent(joinPoint, info, afterSaleLog)); // 异步存入数据库 afterSaleLogService.createLog(dto); } catch (Exception exception) { @@ -64,26 +64,49 @@ public class AfterSaleLogAspect { /** * 获取描述信息 */ - public static Map spelFormat(JoinPoint joinPoint, Object info) { + private static Map spelFormat(JoinPoint joinPoint, Object info) { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); - HashMap result = Maps.newHashMapWithExpectedSize(2); - Map spelMap = SpringExpressionUtils.parseExpression(joinPoint, info, + return SpringExpressionUtils.parseExpression(joinPoint, info, asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); - // TODO @chenchen:是不是抽成 3 个方法好点;毕竟 map 太抽象了;; - // 售后ID - String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id()); - result.put(ID, id); - // 操作类型 - String operateType = afterSaleLogPoint.operateType().description(); - result.put(OPERATE_TYPE, operateType); - // 日志内容 - String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content()); - if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) { - content += operateType; - } - result.put(CONTENT, content); - return result; } + /** + * 获取售后ID + */ + private static Long getAfterSaleId(JoinPoint joinPoint, Object info, String spel) { + Map spelMap = spelFormat(joinPoint, info); + return MapUtil.getLong(spelMap, spel); + } + + /** + * 获取解析后的日志内容 + */ + private static String getContent(JoinPoint joinPoint, Object info, AfterSaleLog afterSaleLog) { + Map spelMap = spelFormat(joinPoint, info); + StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLog.content())); + AfterSaleOperateTypeEnum afterSaleOperateTypeEnum = afterSaleLog.operateType(); + return ObjectUtil.isNotNull(afterSaleOperateTypeEnum) ? + content.append(afterSaleOperateTypeEnum.getDescription()).toString() : content.toString(); + } + + // public static Map spelFormat(JoinPoint joinPoint, Object info) { + // MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + // AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); + // HashMap result = Maps.newHashMapWithExpectedSize(2); + // Map spelMap = SpringExpressionUtils.parseExpression(joinPoint, info, + // asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); + // + // // 售后ID + // result.put(ID, MapUtil.getLong(spelMap, afterSaleLogPoint.id())); + // // 操作类型 + // result.put(OPERATE_TYPE, afterSaleLogPoint.operateType().getType()); + // // 日志内容 + // StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLogPoint.content())); + // + // result.put(CONTENT, ObjectUtil.isNotNull(afterSaleLogPoint.operateType()) ? + // content.append(afterSaleLogPoint.operateType().getDescription()).toString() : content.toString()); + // return result; + // } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java index 7beac68cf..1b2c640a2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogCreateReqDTO.java @@ -37,7 +37,7 @@ public class TradeAfterSaleLogCreateReqDTO { /** * 操作类型 */ - private String operateType; + private Integer operateType; /** * 操作明细 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index a5fa11c9e..1ebfe5664 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -393,7 +393,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa .setUserId(userId) .setUserType(userType) .setAfterSaleId(afterSale.getId()) - .setOperateType(afterStatus.toString()); + .setOperateType(afterStatus); // TODO 废弃,待删除 this.createLog(logDTO); } From eaeb435459a42826980184a3fdf9ba7a810a4d56 Mon Sep 17 00:00:00 2001 From: chenchen <934298133@qq.com> Date: Thu, 29 Jun 2023 21:44:36 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E4=BA=A4=E6=98=93=E6=97=A5=E5=BF=97sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/optional/mall_trade_log.sql | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 sql/mysql/optional/mall_trade_log.sql diff --git a/sql/mysql/optional/mall_trade_log.sql b/sql/mysql/optional/mall_trade_log.sql new file mode 100644 index 000000000..b3367416b --- /dev/null +++ b/sql/mysql/optional/mall_trade_log.sql @@ -0,0 +1,62 @@ +/* + Navicat Premium Data Transfer + + + Source Server : 127.0.0.1 MySQL + Source Server Type : MySQL + Source Server Version : 80030 + Source Host : localhost:3306 + + Target Server Type : MySQL + Target Server Version : 80030 + File Encoding : 65001 + + Date: 29/06/2023 21:05:23 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for trade_after_sale_log +-- ---------------------------- +DROP TABLE IF EXISTS `trade_after_sale_log`; +CREATE TABLE `trade_after_sale_log` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `after_sale_id` bigint NOT NULL COMMENT '售后服务单号', + `content` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT '售后服务信息', + `operate_type` varchar(255) NOT NULL COMMENT '操作类型', + `user_id` bigint NOT NULL COMMENT '创建者ID', + `user_type` int NOT NULL COMMENT '创建者类型', + `creator` varchar(255) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 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 DEFAULT CHARSET=utf8mb4 COMMENT='售后日志'; + +-- ---------------------------- +-- Table structure for trade_order_log +-- ---------------------------- +DROP TABLE IF EXISTS `trade_order_log`; +CREATE TABLE `trade_order_log` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `order_id` bigint NOT NULL COMMENT '订单号', + `content` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT '订单日志信息', + `operate_type` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT '操作类型', + `user_id` bigint NOT NULL COMMENT '创建者ID', + `user_type` int NOT NULL COMMENT '创建者类型', + `creator` varchar(255) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) CHARACTER SET utf8mb4 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`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单日志'; + +SET FOREIGN_KEY_CHECKS = 1; From f492797fba881ccdffb11a624e79ccb7c3f988ca Mon Sep 17 00:00:00 2001 From: chenchen <934298133@qq.com> Date: Thu, 6 Jul 2023 16:04:18 +0800 Subject: [PATCH 04/12] =?UTF-8?q?update=20=E5=94=AE=E5=90=8E=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/aop/AfterSaleLogAspect.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java index cdb2c0a48..68444936e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/aop/AfterSaleLogAspect.java @@ -32,10 +32,6 @@ import static java.util.Arrays.asList; @Aspect public class AfterSaleLogAspect { - private final static String OPERATE_TYPE = "operateType"; - private final static String ID = "id"; - private final static String CONTENT = "content"; - @Resource private AfterSaleLogService afterSaleLogService; @@ -90,23 +86,4 @@ public class AfterSaleLogAspect { content.append(afterSaleOperateTypeEnum.getDescription()).toString() : content.toString(); } - // public static Map spelFormat(JoinPoint joinPoint, Object info) { - // MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - // AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class); - // HashMap result = Maps.newHashMapWithExpectedSize(2); - // Map spelMap = SpringExpressionUtils.parseExpression(joinPoint, info, - // asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); - // - // // 售后ID - // result.put(ID, MapUtil.getLong(spelMap, afterSaleLogPoint.id())); - // // 操作类型 - // result.put(OPERATE_TYPE, afterSaleLogPoint.operateType().getType()); - // // 日志内容 - // StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLogPoint.content())); - // - // result.put(CONTENT, ObjectUtil.isNotNull(afterSaleLogPoint.operateType()) ? - // content.append(afterSaleLogPoint.operateType().getDescription()).toString() : content.toString()); - // return result; - // } - } From 284506b3561205a8bb68631a464c3c2adb59a985 Mon Sep 17 00:00:00 2001 From: chenchen <934298133@qq.com> Date: Fri, 7 Jul 2023 14:06:32 +0800 Subject: [PATCH 05/12] =?UTF-8?q?mall=20=E4=B8=8B=E5=8D=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/aftersale/OrderOperateTypeEnum.java | 30 +++++++ .../app/order/AppTradeOrderController.java | 5 ++ .../dal/dataobject/order/OrderLogDO.java | 51 +++++++++++ .../trade/dal/mysql/order/OrderLogMapper.java | 16 ++++ .../order/config/TradeOrderConfig.java | 9 ++ .../order/core/annotations/OrderLog.java | 33 +++++++ .../order/core/aop/OrderLogAspect.java | 86 +++++++++++++++++++ .../core/dto/TradeOrderLogCreateReqDTO.java | 46 ++++++++++ .../order/core/service/OrderLogService.java | 22 +++++ .../service/order/TradeOrderServiceImpl.java | 31 ++++++- 10 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/OrderOperateTypeEnum.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/OrderLogDO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/OrderLogMapper.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/annotations/OrderLog.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/OrderLogAspect.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/dto/TradeOrderLogCreateReqDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/service/OrderLogService.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/OrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/OrderOperateTypeEnum.java new file mode 100644 index 000000000..04b137f8a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/aftersale/OrderOperateTypeEnum.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.enums.aftersale; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * 订单操作类型的枚举 + * + * @author 陈賝 + * @since 2023/7/6 15:31 + */ +@RequiredArgsConstructor +@Getter +public enum OrderOperateTypeEnum { + + /** + * 用户下单 + */ + ORDER(0, "用户下单"), + ; + + // 类型 + private final Integer type; + // 描述 + private final String description; + + public String description() { + return description; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 6567e3169..2428922e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -14,8 +14,12 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderI import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; +import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum; +import cn.iocoder.yudao.module.trade.enums.aftersale.OrderOperateTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; +import cn.iocoder.yudao.module.trade.framework.order.core.annotations.OrderLog; import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; @@ -66,6 +70,7 @@ public class AppTradeOrderController { @PostMapping("/create") @Operation(summary = "创建订单") @PreAuthenticated + @OrderLog(id = "#info.id", content = "'创建订单:支付订单编号['+#info.payOrderId+'], 订单编号['+#info.id+'], '", operateType = OrderOperateTypeEnum.ORDER) public CommonResult createOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO) { TradeOrderDO order = tradeOrderService.createOrder(getLoginUserId(), getClientIP(), createReqVO); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/OrderLogDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/OrderLogDO.java new file mode 100644 index 000000000..c65acfe06 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/OrderLogDO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.trade.dal.dataobject.order; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 订单日志 DO + * + * @author 陈賝 + */ +@TableName("trade_order_log") +@KeySequence("trade_order_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OrderLogDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 订单号 + */ + private Long orderId; + /** + * 订单日志信息 + */ + private String content; + /** + * 操作类型 + */ + private Integer operateType; + /** + * 创建者ID + */ + private Long userId; + /** + * 创建者类型 + */ + private Integer userType; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/OrderLogMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/OrderLogMapper.java new file mode 100644 index 000000000..868a962d5 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/OrderLogMapper.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.order; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.OrderLogDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 订单日志 Mapper + * + * @author 陈賝 + */ +@Mapper +public interface OrderLogMapper extends BaseMapperX { + + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/config/TradeOrderConfig.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/config/TradeOrderConfig.java index 715169275..86466fa92 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/config/TradeOrderConfig.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/config/TradeOrderConfig.java @@ -1,9 +1,13 @@ package cn.iocoder.yudao.module.trade.framework.order.config; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect; +import cn.iocoder.yudao.module.trade.framework.order.core.aop.OrderLogAspect; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; // TODO @LeeYan9: 可以直接给 TradeOrderProperties 一个 @Component生效哈 + /** * @author LeeYan9 * @since 2022-09-15 @@ -11,4 +15,9 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableConfigurationProperties(TradeOrderProperties.class) public class TradeOrderConfig { + + @Bean + public OrderLogAspect orderLogAspect() { + return new OrderLogAspect(); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/annotations/OrderLog.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/annotations/OrderLog.java new file mode 100644 index 000000000..994a6a368 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/annotations/OrderLog.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.trade.framework.order.core.annotations; + +import cn.iocoder.yudao.module.trade.enums.aftersale.OrderOperateTypeEnum; + +import java.lang.annotation.*; + +/** + * 订单日志AOP注解 + * + * @author 陈賝 + * @since 2023/7/6 15:37 + */ +@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface OrderLog { + + /** + * 日志内容 + */ + String content(); + + /** + * 订单编号 + */ + String id(); + + /** + * 操作类型 + */ + OrderOperateTypeEnum operateType(); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/OrderLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/OrderLogAspect.java new file mode 100644 index 000000000..460649c43 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/OrderLogAspect.java @@ -0,0 +1,86 @@ +package cn.iocoder.yudao.module.trade.framework.order.core.aop; + + +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; +import cn.iocoder.yudao.module.trade.enums.aftersale.OrderOperateTypeEnum; +import cn.iocoder.yudao.module.trade.framework.order.core.annotations.OrderLog; +import cn.iocoder.yudao.module.trade.framework.order.core.dto.TradeOrderLogCreateReqDTO; +import cn.iocoder.yudao.module.trade.framework.order.core.service.OrderLogService; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.reflect.MethodSignature; + +import javax.annotation.Resource; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; +import static java.util.Arrays.asList; + +/** + * 记录订单操作日志的 AOP 切面 + * + * @author 陈賝 + * @since 2023/6/13 13:54 + */ +@Slf4j +@Aspect +public class OrderLogAspect { + + @Resource + private OrderLogService orderLogService; + + @AfterReturning(pointcut = "@annotation(orderLog)", returning = "info") + public void doAfterReturning(JoinPoint joinPoint, OrderLog orderLog, Object info) { + try { + // 日志对象拼接 + Integer userType = WebFrameworkUtils.getLoginUserType(); + Long id = WebFrameworkUtils.getLoginUserId(); + TradeOrderLogCreateReqDTO dto = new TradeOrderLogCreateReqDTO() + .setUserId(id) + .setUserType(userType) + .setOrderId(getAfterSaleId(joinPoint, info, orderLog.id())) + .setOperateType(orderLog.operateType().getType()) + .setContent(getContent(joinPoint, info, orderLog)); + // 异步存入数据库 + orderLogService.createLog(dto); + } catch (Exception exception) { + log.error("[doAfterReturning][orderLog({}) 订单日志错误]", toJsonString(orderLog), exception); + } + } + + /** + * 获取描述信息 + */ + private static Map spelFormat(JoinPoint joinPoint, Object info) { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + OrderLog afterSaleLogPoint = signature.getMethod().getAnnotation(OrderLog.class); + return SpringExpressionUtils.parseExpression(joinPoint, info, + asList(afterSaleLogPoint.id(), afterSaleLogPoint.content())); + } + + + /** + * 获取订单ID + */ + private static Long getAfterSaleId(JoinPoint joinPoint, Object info, String spel) { + Map spelMap = spelFormat(joinPoint, info); + return MapUtil.getLong(spelMap, spel); + } + + /** + * 获取解析后的日志内容 + */ + private static String getContent(JoinPoint joinPoint, Object info, OrderLog afterSaleLog) { + Map spelMap = spelFormat(joinPoint, info); + StringBuilder content = new StringBuilder().append(MapUtil.getStr(spelMap, afterSaleLog.content())); + OrderOperateTypeEnum operateTypeEnum = afterSaleLog.operateType(); + return ObjectUtil.isNotNull(operateTypeEnum) ? + content.append(operateTypeEnum.getDescription()).toString() : content.toString(); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/dto/TradeOrderLogCreateReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/dto/TradeOrderLogCreateReqDTO.java new file mode 100644 index 000000000..81d87711f --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/dto/TradeOrderLogCreateReqDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.trade.framework.order.core.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 订单日志的创建 Request DTO + * + * @author 陈賝 + * @since 2023/7/6 15:27 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeOrderLogCreateReqDTO { + + /** + * 编号 + */ + private Long id; + /** + * 用户编号 + *

+ * 关联 1:AdminUserDO 的 id 字段 + * 关联 2:MemberUserDO 的 id 字段 + */ + private Long userId; + /** + * 用户类型 + */ + private Integer userType; + /** + * 订单编号 + */ + private Long orderId; + /** + * 操作类型 + */ + private Integer operateType; + /** + * 操作明细 + */ + private String content; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/service/OrderLogService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/service/OrderLogService.java new file mode 100644 index 000000000..0b7541ee6 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/service/OrderLogService.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.framework.order.core.service; + +import cn.iocoder.yudao.module.trade.framework.order.core.dto.TradeOrderLogCreateReqDTO; + +/** + * 交易下单日志 Service 接口 + * + * @author 陈賝 + * @since 2023/7/6 15:44 + */ +public interface OrderLogService { + + /** + * 创建交易下单日志 + * + * @param logDTO 日志记录 + * @author 陈賝 + * @since 2023/7/6 15:45 + */ + void createLog(TradeOrderLogCreateReqDTO logDTO); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index d06987ba6..f79732891 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -31,16 +31,21 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageRe import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.OrderLogDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; +import cn.iocoder.yudao.module.trade.dal.mysql.order.OrderLogMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; +import cn.iocoder.yudao.module.trade.framework.order.core.dto.TradeOrderLogCreateReqDTO; +import cn.iocoder.yudao.module.trade.framework.order.core.service.OrderLogService; import cn.iocoder.yudao.module.trade.service.cart.TradeCartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.price.TradePriceService; @@ -57,6 +62,7 @@ import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; @@ -68,11 +74,13 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; */ @Service @Slf4j -public class TradeOrderServiceImpl implements TradeOrderService { +public class TradeOrderServiceImpl implements TradeOrderService, OrderLogService { @Resource private TradeOrderMapper tradeOrderMapper; @Resource + private OrderLogMapper orderLogMapper; + @Resource private TradeOrderItemMapper tradeOrderItemMapper; @Resource @@ -568,4 +576,25 @@ public class TradeOrderServiceImpl implements TradeOrderService { TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())); } + /** + * 创建交易下单日志 + * + * @param logDTO 日志记录 + * @author 陈賝 + * @since 2023/7/6 15:45 + */ + @Override + public void createLog(TradeOrderLogCreateReqDTO logDTO) { + try { + OrderLogDO orderLogDO = new OrderLogDO() + .setUserId(logDTO.getUserId()) + .setUserType(logDTO.getUserType()) + .setOrderId(logDTO.getOrderId()) + .setOperateType(logDTO.getOperateType()) + .setContent(logDTO.getContent()); + orderLogMapper.insert(orderLogDO); + } catch (Exception exception) { + log.error("[createLog][request({}) 日志记录错误]", toJsonString(logDTO), exception); + } + } } From bcb3b19418ee81e27f23c14ef4c68d60dd5e24dc Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Wed, 13 Sep 2023 17:28:42 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=85=85=E5=80=BC=20?= =?UTF-8?q?=E8=A1=A8=E7=BB=93=E6=9E=84=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 55 +++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index 7d092ef45..9fab83c0e 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -4,18 +4,18 @@ DROP TABLE IF EXISTS `pay_wallet`; CREATE TABLE `pay_wallet` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', - `user_id` bigint NOT NULL COMMENT '用户编号', - `user_type` tinyint NOT NULL DEFAULT 0 COMMENT '用户类型', - `balance` int NOT NULL DEFAULT 0 COMMENT '余额,单位分', - `total_expense` int NOT NULL DEFAULT 0 COMMENT '累计支出,单位分', - `total_recharge` int 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 '租户编号', + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `user_id` bigint NOT NULL COMMENT '用户编号', + `user_type` tinyint NOT NULL DEFAULT 0 COMMENT '用户类型', + `balance` int NOT NULL DEFAULT 0 COMMENT '余额,单位分', + `total_expense` int NOT NULL DEFAULT 0 COMMENT '累计支出,单位分', + `total_recharge` int 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='会员钱包表'; @@ -41,3 +41,34 @@ CREATE TABLE `pay_wallet_transaction` `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB COMMENT='会员钱包流水表'; + +-- ---------------------------- +-- 会员钱包充值 +-- ---------------------------- +DROP TABLE IF EXISTS `pay_wallet_recharge`; +CREATE TABLE `pay_wallet_recharge` +( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', + `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', + `price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', + `pay_price` int NOT NULL COMMENT '实际支付金额', + `wallet_bonus` int NOT NULL COMMENT '钱包赠送金额', + `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]', + `pay_order_id` bigint NULL COMMENT '支付订单编号', + `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道', + `pay_time` datetime NULL COMMENT '订单支付时间', + `wallet_transaction_id` bigint NULL COMMENT '充值钱包流水', + `pay_refund_id` bigint NULL COMMENT '支付退款单编号', + `refund_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', + `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额', + `refund_wallet_bonus` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', + `refund_wallet_transaction_id` bigint NULL 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='会员钱包充值'; + From 0e1b8126dd6cd28e1cd55224810fb60c7b8eb08e Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Thu, 14 Sep 2023 16:55:31 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=92=B1=E5=8C=85?= =?UTF-8?q?=E5=85=85=E5=80=BC=E3=80=82=E5=90=AF=E5=8A=A8=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 3 +- .../api/combination/CombinationApiImpl.java | 2 + .../CombinationRecordServiceImpl.java | 1 + .../module/pay/enums/ErrorCodeConstants.java | 5 + .../AppPayWalletRechargeController.java | 55 +++++++ .../AppPayWalletTransactionController.java | 1 - .../AppPayWalletRechargeCreateReqVO.java | 22 +++ .../AppPayWalletRechargeCreateRespVO.java | 15 ++ .../wallet/PayWalletRechargeConvert.java | 27 ++++ .../pay/dal/mysql/wallet/PayWalletMapper.java | 13 ++ .../wallet/PayWalletRechargeService.java | 29 ++++ .../wallet/PayWalletRechargeServiceImpl.java | 135 ++++++++++++++++++ .../pay/service/wallet/PayWalletService.java | 14 +- .../service/wallet/PayWalletServiceImpl.java | 27 +++- 14 files changed, 335 insertions(+), 14 deletions(-) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index 9fab83c0e..e9cc6a288 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -57,12 +57,11 @@ CREATE TABLE `pay_wallet_recharge` `pay_order_id` bigint NULL COMMENT '支付订单编号', `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道', `pay_time` datetime NULL COMMENT '订单支付时间', - `wallet_transaction_id` bigint NULL COMMENT '充值钱包流水', `pay_refund_id` bigint NULL COMMENT '支付退款单编号', `refund_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额', `refund_wallet_bonus` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', - `refund_wallet_transaction_id` bigint NULL COMMENT '充值退款钱包流水', + `refund_time` datetime NULL 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 '更新者', diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java index 767b2e680..6c8ac989d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationApiImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.api.combination; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationActivityUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; +import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -10,6 +11,7 @@ import javax.annotation.Resource; * * @author HUIHUI */ +@Service public class CombinationApiImpl implements CombinationApi { @Resource diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 556e47363..c82621805 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -38,6 +38,7 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; public class CombinationRecordServiceImpl implements CombinationRecordService { @Resource + @Lazy private CombinationActivityService combinationActivityService; @Resource private CombinationRecordMapper recordMapper; 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 f3d6d8685..62adb63c5 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 @@ -46,6 +46,11 @@ public interface ErrorCodeConstants { ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1007007002, "未找到对应的钱包交易"); ErrorCode WALLET_REFUND_AMOUNT_ERROR = new ErrorCode(1007007003, "钱包退款金额不对"); ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007004, "已经存在钱包退款"); + ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1007007005, "钱包充值记录不存在"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007007006, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1007007007, "钱包充值更新支付状态失败,支付单编号不匹配"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1007007008, "钱包充值更新支付状态失败,支付单状态不是【支付成功】状态"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH = new ErrorCode(1007007009, "钱包充值更新支付状态失败,支付单金额不匹配"); // ========== 示例订单 1007900000 ========== ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在"); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java new file mode 100644 index 000000000..0d8ae4913 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType; + +@Tag(name = "用户 APP - 钱包充值") +@RestController +@RequestMapping("/pay/wallet-recharge") +@Validated +@Slf4j +public class AppPayWalletRechargeController { + + @Resource + private PayWalletRechargeService payWalletRechargeService; + + @PostMapping("/create") + @Operation(summary = "创建钱包充值记录") + public CommonResult createWalletRecharge(@Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) { + PayWalletRechargeDO walletRecharge = payWalletRechargeService.createWalletRecharge(getLoginUserId(), + getLoginUserType(), reqVO); + return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge)); + } + + @PostMapping("/update-paid") + @Operation(summary = "更新钱包充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob + @PermitAll // 无需登录,安全由 内部校验实现 + @OperateLog(enable = false) // 禁用操作日志,因为没有操作人 + public CommonResult updateWalletRechargerPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { + payWalletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), + notifyReqDTO.getPayOrderId()); + return success(true); + } +} 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 index f9e908845..db0c7844d 100644 --- 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 @@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; - import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java new file mode 100644 index 000000000..1478c4ceb --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.NotNull; + +@Schema(description = "用户 APP - 创建钱包充值 Request VO") +@Data +public class AppPayWalletRechargeCreateReqVO { + + @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @NotNull(message = "支付金额不能为空") + @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") + private Integer payPrice; + + @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @NotNull(message = "钱包赠送金额不能为空") + @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零") + private Integer walletBonus; +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java new file mode 100644 index 000000000..b1a80d2b3 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 APP - 创建钱包充值 Resp VO") +@Data +public class AppPayWalletRechargeCreateRespVO { + + @Schema(description = "钱包充值编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long id; + + @Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + private Long payOrderId; +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java new file mode 100644 index 000000000..173cf75de --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.pay.convert.wallet; + +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author jason + */ +@Mapper +public interface PayWalletRechargeConvert { + + PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class); + + PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo); + + default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) { + PayWalletRechargeDO walletRecharge = convert(vo); + return walletRecharge.setWalletId(walletId) + .setPrice(walletRecharge.getPayPrice() + walletRecharge.getWalletBonus()); + } + + AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean); + +} 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 index ef695c9fe..b93c240d2 100644 --- 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 @@ -42,6 +42,19 @@ public interface PayWalletMapper extends BaseMapperX { .ge(PayWalletDO::getBalance, price); // cas 逻辑 return update(null, lambdaUpdateWrapper); } + + /** + * 当充值的时候,更新钱包 + * @param price 钱包金额 + * @param id 钱包 id + */ + default int updateWhenRecharge(Integer price, Long id){ + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" balance = balance + " + price + + ", total_recharge = total_recharge + " + price) + .eq(PayWalletDO::getId, id); + return update(null, lambdaUpdateWrapper); + } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java new file mode 100644 index 000000000..0752dbe99 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.pay.service.wallet; + +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; + +/** + * 钱包充值 Service 接口 + * + * @author jason + */ +public interface PayWalletRechargeService { + + /** + * 创建钱包充值记录 + * @param userId 用户 id + * @param userType 用户类型 + * @param vo 钱包充值请求 vo + * @return 钱包充值记录 + */ + PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, AppPayWalletRechargeCreateReqVO vo); + + + /** + * 更新钱包充值成功 + * @param walletRechargeId 钱包充值 id + * @param payOrderId 支付订单 id + */ + void updateWalletRechargerPaid(Long walletRechargeId, Long payOrderId); +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java new file mode 100644 index 000000000..a68f034bc --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java @@ -0,0 +1,135 @@ +package cn.iocoder.yudao.module.pay.service.wallet; + +import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO; +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert; +import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; +import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargeMapper; +import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; +import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; +import cn.iocoder.yudao.module.pay.service.order.PayOrderService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.time.Duration; +import java.time.LocalDateTime; + +import static cn.hutool.core.util.ObjectUtil.notEqual; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime; +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; + +/** + * 钱包充值 Service 实现类 + * + * @author jason + */ +@Service +@Slf4j +public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { + /** + * TODO 放到 配置文件中 + */ + private static final Long WALLET_PAY_APP_ID = 8L; + + private static final String WALLET_RECHARGE_ORDER_SUBJECT = "钱包余额充值"; + + @Resource + private PayWalletRechargeMapper walletRechargeMapper; + @Resource + private PayWalletService payWalletService; + @Resource + private PayOrderService payOrderService; + + + @Override + @Transactional(rollbackFor = Exception.class) + public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, AppPayWalletRechargeCreateReqVO vo) { + // 1. 获取钱包 + PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType); + // 2. 新增钱包充值记录 + PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), vo); + walletRechargeMapper.insert(walletRecharge); + // 3.创建支付单 + Long payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO() + .setAppId(WALLET_PAY_APP_ID).setUserIp(getClientIP()) + .setMerchantOrderId(walletRecharge.getId().toString()) // 业务的订单编号 + .setSubject(WALLET_RECHARGE_ORDER_SUBJECT).setBody("").setPrice(walletRecharge.getPayPrice()) + .setExpireTime(addTime(Duration.ofHours(2L)))); + // 4.更新钱包充值记录中支付订单 + walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) + .setId(walletRecharge.getId())); + return walletRechargeMapper.selectById(walletRecharge.getId()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateWalletRechargerPaid(Long walletRechargeId, Long payOrderId) { + // 1. 获取钱包充值记录 + PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(walletRechargeId); + if (walletRecharge == null) { + log.error("[updateWalletRechargerPaid],钱包充值记录不存在,钱包充值 Id:{} ", walletRechargeId); + throw exception(WALLET_RECHARGE_NOT_FOUND); + } + // 2. 校验钱包充值是否可以支付 + PayOrderDO payOrderDO = validateWalletRechargerCanPaid(walletRecharge, payOrderId); + // 3. 更新钱包充值的支付状态 + int updateCount = walletRechargeMapper.updateByIdAndPaid(walletRechargeId,false, new PayWalletRechargeDO().setId(walletRechargeId) + .setPayStatus(true).setPayTime(LocalDateTime.now()) + .setPayChannelCode(payOrderDO.getChannelCode())); + if (updateCount == 0) { + throw exception(WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID); + } + // 4. 更新钱包余额 + payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(walletRechargeId), + PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); + } + + private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { + + // 1.1 校验充值记录的支付状态 + if (walletRecharge.getPayStatus()) { + log.error("[validateWalletRechargerCanPaid][钱包({}) 不处于未支付状态! 钱包数据是:{}]", + walletRecharge.getId(), toJsonString(walletRecharge)); + throw exception(WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID); + } + // 1.2 校验支付订单匹配 + if (notEqual(walletRecharge.getPayOrderId(), payOrderId)) { // 支付单号 + log.error("[validateWalletRechargerCanPaid][钱包({}) 支付单不匹配({}),请进行处理! 钱包数据是:{}]", + walletRecharge.getId(), payOrderId, toJsonString(walletRecharge)); + throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR); + } + // 2.1 校验支付单是否存在 + PayOrderDO payOrder = payOrderService.getOrder(payOrderId); + if (payOrder == null) { + log.error("[validateWalletRechargerCanPaid][钱包({}) payOrder({}) 不存在,请进行处理!]", + walletRecharge.getId(), payOrderId); + throw exception(PAY_ORDER_NOT_FOUND); + } + // 2.2 校验支付单已支付 + if (!PayOrderStatusEnum.isSuccess(payOrder.getStatus())) { + log.error("[validateWalletRechargerCanPaid][钱包({}) payOrder({}) 未支付,请进行处理!payOrder 数据是:{}]", + walletRecharge.getId(), payOrderId, toJsonString(payOrder)); + throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS); + } + // 2.3 校验支付金额一致 + if (notEqual(payOrder.getPrice(), walletRecharge.getPayPrice())) { + log.error("[validateDemoOrderCanPaid][钱包({}) payOrder({}) 支付金额不匹配,请进行处理!钱包 数据是:{},payOrder 数据是:{}]", + walletRecharge.getId(), payOrderId, toJsonString(walletRecharge), toJsonString(payOrder)); + throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH); + } + // 2.4 校验支付订单的商户订单匹配 + if (notEqual(payOrder.getMerchantOrderId(), walletRecharge.getId().toString())) { + log.error("[validateDemoOrderCanPaid][钱包({}) 支付单不匹配({}),请进行处理!payOrder 数据是:{}]", + walletRecharge.getId(), payOrderId, toJsonString(payOrder)); + throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR); + } + return payOrder; + } +} 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 28f9849b5..ed8dcee9f 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 @@ -21,6 +21,13 @@ public interface PayWalletService { */ PayWalletDO getOrCreateWallet(Long userId, Integer userType); + /** + * 获取钱包信息 + * + * @param walletId 钱包 id + */ + PayWalletDO getWallet(Long walletId); + /** * 钱包订单支付 * @@ -56,14 +63,13 @@ public interface PayWalletService { /** * 增加钱包余额 * - * @param userId 用户 id - * @param userType 用户类型 + * @param walletId 钱包 id * @param bizId 业务关联 id * @param bizType 业务关联分类 * @param price 增加金额 * @return 钱包流水 */ - PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, - Long bizId, PayWalletBizTypeEnum bizType, Integer price); + PayWalletTransactionDO addWalletBalance(Long walletId, String bizId, + PayWalletBizTypeEnum bizType, Integer price); } 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 93c653154..8e24ed705 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 @@ -55,6 +55,11 @@ public class PayWalletServiceImpl implements PayWalletService { return wallet; } + @Override + public PayWalletDO getWallet(Long walletId) { + return walletMapper.selectById(walletId); + } + @Override @Transactional(rollbackFor = Exception.class) public PayWalletTransactionDO orderPay(Long userId, Integer userType, String outTradeNo, Integer price) { @@ -80,7 +85,7 @@ public class PayWalletServiceImpl implements PayWalletService { PayWalletDO wallet = walletMapper.selectById(walletId); Assert.notNull(wallet, "钱包 {} 不存在", walletId); // 2. 增加余额 - return addWalletBalance(wallet.getUserId(), wallet.getUserType(), payRefund.getId(), PAYMENT_REFUND, refundPrice); + return addWalletBalance(walletId, String.valueOf(payRefund.getId()), PAYMENT_REFUND, refundPrice); } /** @@ -139,25 +144,33 @@ public class PayWalletServiceImpl implements PayWalletService { } @Override - public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, - Long bizId, PayWalletBizTypeEnum bizType, Integer price) { + public PayWalletTransactionDO addWalletBalance(Long walletId, + String bizId, PayWalletBizTypeEnum bizType, Integer price) { // 1. 获取钱包 - PayWalletDO payWallet = getOrCreateWallet(userId, userType); + PayWalletDO payWallet = getWallet(walletId); + + if (payWallet == null) { + log.error("[addWalletBalance],用户钱包({})不存在.", walletId); + throw exception(WALLET_NOT_FOUND); + } + switch (bizType) { case PAYMENT_REFUND: { - // 更新退款 + // 退款更新 walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); break; } case RECHARGE: { - //TODO + // 充值更新 + walletMapper.updateWhenRecharge(price, payWallet.getId()); break; } + // TODO 其它类型 } // 2. 生成钱包流水 CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) - .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId)) + .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(bizId) .setBizType(bizType.getType()).setTitle(bizType.getDescription()); return walletTransactionService.createWalletTransaction(bo); } From 9d262e8e7fd8f7bc731683f9f905b4047ab9505f Mon Sep 17 00:00:00 2001 From: xiaqing Date: Fri, 15 Sep 2023 15:20:39 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=A4=E4=B8=AAAPP?= =?UTF-8?q?=E7=AB=AF=E6=8E=A5=E5=8F=A3=201.=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=AA=E4=BA=BA=E7=AD=BE=E5=88=B0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=202.=E7=94=A8=E6=88=B7=E7=AD=BE=E5=88=B0=E6=8E=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/enums/ErrorCodeConstants.java | 2 +- .../app/signin/AppMemberSignInController.java | 55 +++++++++ .../vo/AppMemberSignInRecordRespVO.java | 21 ++++ .../vo/AppMemberSignInSummaryRespVO.java | 21 ++++ .../signin/MemberSignInRecordConvert.java | 3 + .../signin/MemberSignInConfigMapper.java | 4 - .../signin/MemberSignInRecordMapper.java | 9 ++ .../signin/MemberSignInRecordService.java | 16 +++ .../signin/MemberSignInRecordServiceImpl.java | 116 +++++++++++++++++- .../src/main/resources/application-local.yaml | 14 +-- 10 files changed, 245 insertions(+), 16 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInRecordRespVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInSummaryRespVO.java 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 25fcdc874..74f50a20a 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 @@ -32,6 +32,6 @@ public interface ErrorCodeConstants { ErrorCode RECORD_NOT_EXISTS = new ErrorCode( 1004005005, "用户积分记录不存在"); - ErrorCode SIGN_IN_RECORD_NOT_EXISTS = new ErrorCode(1004005006, "用户签到积分不存在"); + ErrorCode SIGN_IN_RECORD_EXISTS = new ErrorCode(1004005006, "用户重复签到"); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java new file mode 100644 index 000000000..dd5acd313 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.member.controller.app.signin; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.member.convert.signin.MemberSignInRecordConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; +import cn.iocoder.yudao.module.member.service.signin.MemberSignInRecordService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 描述 :用户签到相关信息接口 + * Author :xiaqing + * Date :2023-09-15 09:02 + */ +@Tag(name = "签到APP - 签到") +@RestController +@RequestMapping("/member/signin") +public class AppMemberSignInController { + + @Resource + MemberSignInRecordService signInRecordService; + + /** + * 描述 :获取个人签到信息 + * Author :xiaqing + * Date :2023-09-15 12:56:47 + */ + + @Operation(summary = "个人签到信息") + @GetMapping("/get-summary") + public CommonResult getUserSummary(){ + return CommonResult.success(signInRecordService.getUserSummary(SecurityFrameworkUtils.getLoginUserId())); + } + + + /** + * 描述 :用户签到 + * Author :xiaqing + * Date :2023-09-15 09:20:58 + */ + @Operation(summary = "会员签到") + @PostMapping("/create") + public CommonResult create(){ + MemberSignInRecordDO recordDO = signInRecordService.create(SecurityFrameworkUtils.getLoginUserId()); + return CommonResult.success(MemberSignInRecordConvert.INSTANCE.coverRecordToAppRecordVo(recordDO)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInRecordRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInRecordRespVO.java new file mode 100644 index 000000000..e7ea26c2d --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInRecordRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.member.controller.app.signin.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户签到积分 Response VO") +@Data +public class AppMemberSignInRecordRespVO { + + @Schema(description = "第几天签到", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer day; + + @Schema(description = "签到的分数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer point; + + @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/app/signin/vo/AppMemberSignInSummaryRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInSummaryRespVO.java new file mode 100644 index 000000000..55eaddbdd --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/vo/AppMemberSignInSummaryRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.member.controller.app.signin.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户签到统计信息 Response VO") +@Data +public class AppMemberSignInSummaryRespVO { + + @Schema(description = "持续签到天数", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer continuousDay; + + @Schema(description = "总签到天数", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + private Integer totalDay; + + @Schema(description = "当天是否签到", requiredMode = Schema.RequiredMode.REQUIRED,example = "true") + private Boolean todaySignIn ; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java index 532591fa8..924bf6f1a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordRespVO; +import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInRecordRespVO; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -33,4 +34,6 @@ public interface MemberSignInRecordConvert { } PageResult convertPage(PageResult pageResult); + AppMemberSignInRecordRespVO coverRecordToAppRecordVo(MemberSignInRecordDO memberSignInRecordDO); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java index fb98d63b8..f40eef9ed 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java @@ -1,13 +1,9 @@ package cn.iocoder.yudao.module.member.dal.mysql.signin; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - /** * 积分签到规则 Mapper * diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInRecordMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInRecordMapper.java index 559b82338..05139a788 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInRecordMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInRecordMapper.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSi import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; import java.util.Set; /** @@ -25,4 +26,12 @@ public interface MemberSignInRecordMapper extends BaseMapperX selectListByUserId(Long userId){ + return selectList(new LambdaQueryWrapperX () + .eq(MemberSignInRecordDO::getUserId, userId) + .orderByDesc(MemberSignInRecordDO::getCreateTime)); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java index c3af3c1f9..7b1282b05 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.member.service.signin; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO; +import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInRecordRespVO; +import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInSummaryRespVO; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; /** @@ -19,4 +21,18 @@ public interface MemberSignInRecordService { */ PageResult getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO); + + MemberSignInRecordDO create(Long userId); + + /** + * + *功能描述: 根据用户id获取个人签到信息 + * @param userId + * @return + * @author xiaqing + * @date 2023-09-15 14:21:01 + */ + AppMemberSignInSummaryRespVO getUserSummary(Long userId); + + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java index 93975da0e..7ffa1b775 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java @@ -1,20 +1,28 @@ package cn.iocoder.yudao.module.member.service.signin; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 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.signin.vo.record.MemberSignInRecordPageReqVO; +import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInSummaryRespVO; +import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; +import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInConfigMapper; import cn.iocoder.yudao.module.member.dal.mysql.signin.MemberSignInRecordMapper; +import cn.iocoder.yudao.module.member.enums.ErrorCodeConstants; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Set; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; /** @@ -28,16 +36,62 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService @Resource private MemberSignInRecordMapper signInRecordMapper; - + @Resource + private MemberSignInConfigMapper signInConfigMapper; @Resource private MemberUserApi memberUserApi; + @Override - public PageResult getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO) { + public AppMemberSignInSummaryRespVO getUserSummary(Long userId) { + AppMemberSignInSummaryRespVO vo = new AppMemberSignInSummaryRespVO(); + vo.setTotalDay(0); + vo.setContinuousDay(0); + vo.setTodaySignIn(false); + //获取用户签到的记录,按照天数倒序获取 + List signInRecordDOList = signInRecordMapper.selectListByUserId(userId); + if(!CollectionUtils.isEmpty(signInRecordDOList)){ + //设置总签到天数 + vo.setTotalDay(signInRecordDOList.size()); + //判断当天是否有签到复用校验方法 + try { + validSignDay(signInRecordDOList.get(0)); + vo.setTodaySignIn(false); + }catch (Exception e){ + vo.setTodaySignIn(true); + } + //如果当天签到了则说明连续签到天数有意义,否则直接用默认值0 + if(vo.getTodaySignIn()){ + //下方计算连续签到从2天开始,此处直接设置一天连续签到 + vo.setContinuousDay(1); + //判断连续签到天数 + for (int i = 1; i < signInRecordDOList.size(); i++) { + //前一天减1等于当前天数则说明连续,继续循环 + LocalDate cur = signInRecordDOList.get(i).getCreateTime().toLocalDate(); + LocalDate pre = signInRecordDOList.get(i-1).getCreateTime().toLocalDate(); + if(1==daysBetween(cur,pre)){ + vo.setContinuousDay(i+1); + }else{ + break; + } + } + } + + + } + return vo; + } + + private long daysBetween(LocalDate date1,LocalDate date2){ + return ChronoUnit.DAYS.between(date1, date2); + } + + @Override + public PageResult getSignInRecordPage(MemberSignInRecordPageReqVO pageReqVO) { // 根据用户昵称查询出用户ids - Set userIds = null; + Set userIds = null; if (StringUtils.isNotBlank(pageReqVO.getNickname())) { - List users = memberUserApi.getUserListByNickname(pageReqVO.getNickname()); + List users = memberUserApi.getUserListByNickname(pageReqVO.getNickname()); // 如果查询用户结果为空直接返回无需继续查询 if (CollectionUtils.isEmpty(users)) { return PageResult.empty(); @@ -47,4 +101,58 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService return signInRecordMapper.selectPage(pageReqVO, userIds); } + @Override + public MemberSignInRecordDO create(Long userId) { + //获取当前用户签到的最大天数 + MemberSignInRecordDO maxSignDay = signInRecordMapper.selectOne(new LambdaQueryWrapperX () + .eq(MemberSignInRecordDO::getUserId, userId) + .orderByDesc(MemberSignInRecordDO::getDay) + .last("limit 1")); + //判断是否重复签到 + validSignDay(maxSignDay); + + /**1.查询出当前签到的天数**/ + MemberSignInRecordDO sign = new MemberSignInRecordDO(); + sign.setUserId(userId); + //设置签到初始化天数 + sign.setDay(1); + //设置签到分数默认为0 + sign.setPoint(0); + //如果不为空则修改当前签到对应的天数 + if (maxSignDay != null) { + sign.setDay(maxSignDay.getDay() + 1); + } + /**2.获取签到对应的分数**/ + //获取所有的签到规则,按照天数排序,只获取启用的 + List configDOList = signInConfigMapper.selectList(new LambdaQueryWrapperX () + .eq(MemberSignInConfigDO::getEnable, 1) + .orderByAsc(MemberSignInConfigDO::getDay)); + //如果签到的天数大于最大启用的规则天数,直接给最大签到的分数 + MemberSignInConfigDO lastConfig = configDOList.get(configDOList.size() - 1); + if (sign.getDay() > lastConfig.getDay()) { + sign.setPoint(lastConfig.getPoint()); + } else { + configDOList.forEach(el -> { + //循环匹配对应天数,设置对应分数 + if (el.getDay() == sign.getDay()) { + sign.setPoint(el.getPoint()); + } + + }); + } + + //3.插入当前签到获取的分数 + signInRecordMapper.insert(sign); + //4.返回给用户 + return sign; + } + + void validSignDay(MemberSignInRecordDO signInRecordDO) { + if (signInRecordDO == null) + return; + LocalDate today = LocalDate.now(); + if (today.equals(signInRecordDO.getCreateTime().toLocalDate())) { + throw exception(ErrorCodeConstants.SIGN_IN_RECORD_EXISTS); + } + } } diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 5964261ce..1e1293812 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -44,31 +44,31 @@ spring: primary: master datasource: master: - name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 + name: mall + url: jdbc:mysql://10.211.55.5:3308/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 username: root - password: 123456 + password: 1qaz!QAZ # username: sa # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W slave: # 模拟从库,可根据自己需要修改 - name: ruoyi-vue-pro - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 + name: mall + url: jdbc:mysql://10.211.55.5:3308/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 username: root - password: 123456 + password: 1qaz!QAZ # username: sa # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: - host: 127.0.0.1 # 地址 + host: 10.211.55.5 # 地址 port: 6379 # 端口 database: 0 # 数据库索引 # password: dev # 密码,建议生产环境开启 From bbc16bb9374375922c65ffe13ef1d7bb08366d6a Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Fri, 15 Sep 2023 16:14:04 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=85=85=E5=80=BC=20Ma?= =?UTF-8?q?pper=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wallet/PayWalletRechargeDO.java | 89 +++++++++++++++++++ .../mysql/wallet/PayWalletRechargeMapper.java | 20 +++++ 2 files changed, 109 insertions(+) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java new file mode 100644 index 000000000..af3670e96 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java @@ -0,0 +1,89 @@ +package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; + +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; + +import java.time.LocalDateTime; + +/** + * 会员钱包充值 + */ +@TableName(value ="pay_wallet_recharge") +@KeySequence("pay_wallet_recharge_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +public class PayWalletRechargeDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + + /** + * 会员钱包 id + */ + private Long walletId; + + /** + * 用户实际到账余额,例如充 100 送 20,则该值是 120 + */ + private Integer price; + + /** + * 实际支付金额 + */ + private Integer payPrice; + + /** + * 钱包赠送金额 + */ + private Integer walletBonus; + + /** + * 是否已支付:[0:未支付 1:已经支付过] + */ + private Boolean payStatus; + + /** + * 支付订单编号 + */ + private Long payOrderId; + + /** + * 支付成功的支付渠道 + */ + private String payChannelCode; + + /** + * 订单支付时间 + */ + private LocalDateTime payTime; + + /** + * 支付退款单编号 + */ + private Long payRefundId; + + /** + * 退款金额,包含赠送金额 + */ + private Integer refundPrice; + + /** + * 退款支付金额 + */ + private Integer refundPayPrice; + + /** + * 退款钱包赠送金额 + */ + private Integer refundWalletBonus; + + /** + * 退款时间 + */ + private LocalDateTime refundTime; +} \ No newline at end of file diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java new file mode 100644 index 000000000..cabc9c86f --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.pay.dal.mysql.wallet; + +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.demo.PayDemoOrderDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface PayWalletRechargeMapper extends BaseMapperX { + + default int updateByIdAndPaid(Long id, boolean wherePayed, PayWalletRechargeDO updateObj){ + return update(updateObj, new LambdaQueryWrapperX() + .eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayed)); + } +} + + + + From d4a891e6c496d67ca828f4dd849e0c0d6027af41 Mon Sep 17 00:00:00 2001 From: xiaqing Date: Fri, 15 Sep 2023 23:21:11 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=A4=E4=B8=AAAPP?= =?UTF-8?q?=E7=AB=AF=E6=8E=A5=E5=8F=A3=201.=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=AA=E4=BA=BA=E7=AD=BE=E5=88=B0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=202.=E7=94=A8=E6=88=B7=E7=AD=BE=E5=88=B0=E6=8E=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/member/enums/ErrorCodeConstants.java | 1 + .../member/convert/signin/MemberSignInRecordConvert.java | 1 - .../member/dal/mysql/signin/MemberSignInConfigMapper.java | 4 +++- .../member/service/signin/MemberSignInRecordServiceImpl.java | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) 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 cf375f4e4..f3b6369a6 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 @@ -39,6 +39,7 @@ public interface ErrorCodeConstants { ErrorCode SIGN_IN_CONFIG_EXISTS = new ErrorCode(1004009001, "签到天数规则已存在"); //========== 签到配置 1004010000 ========== + ErrorCode SIGN_IN_RECORD_EXISTS = new ErrorCode(1004010000,"用户重复签到"); //========== 用户等级 1004011000 ========== diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java index a11cfc8a5..edac5edae 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/signin/MemberSignInRecordConvert.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordRespVO; import cn.iocoder.yudao.module.member.controller.app.signin.vo.record.AppMemberSignInRecordRespVO; -import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInRecordRespVO; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java index e3a9aa964..211ead33d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/signin/MemberSignInConfigMapper.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInConfigDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 签到规则 Mapper * @@ -16,7 +18,7 @@ public interface MemberSignInConfigMapper extends BaseMapperX selectListByStatus(Integer status) { + default List selectListByStatus(Integer status) { return selectList(MemberSignInConfigDO::getStatus, status); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java index 76468cb21..02759db19 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.service.signin; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -37,7 +38,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService @Resource private MemberSignInRecordMapper memberSignInRecordMapper; - + @Resource private MemberSignInRecordMapper signInRecordMapper; @Resource private MemberSignInConfigMapper signInConfigMapper; @@ -134,7 +135,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService /**2.获取签到对应的分数**/ //获取所有的签到规则,按照天数排序,只获取启用的 List configDOList = signInConfigMapper.selectList(new LambdaQueryWrapperX () - .eq(MemberSignInConfigDO::getEnable, 1) + .eq(MemberSignInConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) .orderByAsc(MemberSignInConfigDO::getDay)); //如果签到的天数大于最大启用的规则天数,直接给最大签到的分数 MemberSignInConfigDO lastConfig = configDOList.get(configDOList.size() - 1); From 080c32b9f3e9f159750355af13827cfe505387e0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 18 Sep 2023 13:07:54 +0800 Subject: [PATCH 11/12] =?UTF-8?q?code=20review=EF=BC=9A=E9=92=B1=E5=8C=85?= =?UTF-8?q?=E5=85=85=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/pay/enums/ErrorCodeConstants.java | 3 ++ .../AppPayWalletRechargeController.java | 18 ++++---- .../AppPayWalletRechargeCreateReqVO.java | 3 ++ .../AppPayWalletRechargeCreateRespVO.java | 1 + .../wallet/PayWalletRechargeConvert.java | 1 + .../wallet/PayWalletTransactionConvert.java | 4 +- .../wallet/PayWalletRechargeDO.java | 36 ++++++++++------ .../pay/dal/mysql/wallet/PayWalletMapper.java | 3 ++ .../mysql/wallet/PayWalletRechargeMapper.java | 6 +-- .../wallet/PayWalletRechargeService.java | 15 ++++--- .../wallet/PayWalletRechargeServiceImpl.java | 42 +++++++++++-------- .../service/wallet/PayWalletServiceImpl.java | 30 +++++++------ .../wallet/PayWalletTransactionService.java | 6 +-- .../PayWalletTransactionServiceImpl.java | 4 +- ...java => WalletTransactionCreateReqBO.java} | 2 +- 15 files changed, 104 insertions(+), 70 deletions(-) rename yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/{CreateWalletTransactionBO.java => WalletTransactionCreateReqBO.java} (94%) 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 62adb63c5..87b046a63 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 @@ -46,6 +46,9 @@ public interface ErrorCodeConstants { ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1007007002, "未找到对应的钱包交易"); ErrorCode WALLET_REFUND_AMOUNT_ERROR = new ErrorCode(1007007003, "钱包退款金额不对"); ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007004, "已经存在钱包退款"); + + // TODO @jason:把钱包充值,单独搞个错误码段哈; + ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1007007005, "钱包充值记录不存在"); ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007007006, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态"); ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1007007007, "钱包充值更新支付状态失败,支付单编号不匹配"); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java index 0d8ae4913..6ce0cff3f 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java @@ -33,13 +33,14 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi public class AppPayWalletRechargeController { @Resource - private PayWalletRechargeService payWalletRechargeService; + private PayWalletRechargeService walletRechargeService; @PostMapping("/create") - @Operation(summary = "创建钱包充值记录") - public CommonResult createWalletRecharge(@Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) { - PayWalletRechargeDO walletRecharge = payWalletRechargeService.createWalletRecharge(getLoginUserId(), - getLoginUserType(), reqVO); + @Operation(summary = "创建钱包充值记录(发起充值)") + public CommonResult createWalletRecharge( + @Valid @RequestBody AppPayWalletRechargeCreateReqVO reqVO) { + PayWalletRechargeDO walletRecharge = walletRechargeService.createWalletRecharge( + getLoginUserId(), getLoginUserType(), reqVO); return success(PayWalletRechargeConvert.INSTANCE.convert(walletRecharge)); } @@ -47,9 +48,12 @@ public class AppPayWalletRechargeController { @Operation(summary = "更新钱包充值为已充值") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob @PermitAll // 无需登录,安全由 内部校验实现 @OperateLog(enable = false) // 禁用操作日志,因为没有操作人 - public CommonResult updateWalletRechargerPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { - payWalletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), + public CommonResult updateWalletRechargerPaid(@Valid @RequestBody PayOrderNotifyReqDTO notifyReqDTO) { + walletRechargeService.updateWalletRechargerPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), notifyReqDTO.getPayOrderId()); return success(true); } + + // TODO @jason:管理后台,是不是可以搞个发起退款; + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java index 1478c4ceb..45125e8c0 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java @@ -12,11 +12,14 @@ public class AppPayWalletRechargeCreateReqVO { @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") @NotNull(message = "支付金额不能为空") + // TODO @jason999:是不是 @Min 哈? @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") private Integer payPrice; + // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") @NotNull(message = "钱包赠送金额不能为空") @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零") private Integer walletBonus; + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java index b1a80d2b3..2c4a96f62 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateRespVO.java @@ -12,4 +12,5 @@ public class AppPayWalletRechargeCreateRespVO { @Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Long payOrderId; + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java index 173cf75de..584144734 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java @@ -16,6 +16,7 @@ public interface PayWalletRechargeConvert { PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo); + // TODO @jason:好像 price 相加,可以写个表达式的,通过 @Mapping default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) { PayWalletRechargeDO walletRecharge = convert(vo); return walletRecharge.setWalletId(walletId) 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 index f806168c8..4b3a150f8 100644 --- 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 @@ -3,7 +3,7 @@ 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.transaction.AppPayWalletTransactionRespVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -14,6 +14,6 @@ public interface PayWalletTransactionConvert { PageResult convertPage(PageResult page); - PayWalletTransactionDO convert(CreateWalletTransactionBO bean); + PayWalletTransactionDO convert(WalletTransactionCreateReqBO bean); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java index af3670e96..939b9b4a1 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -23,40 +25,49 @@ public class PayWalletRechargeDO extends BaseDO { private Long id; /** - * 会员钱包 id + * 钱包编号 + * + * 关联 {@link PayWalletDO#getId()} */ private Long walletId; + // TODO @jason:要不改成 totalPrice? /** - * 用户实际到账余额,例如充 100 送 20,则该值是 120 + * 用户实际到账余额 + * + * 例如充 100 送 20,则该值是 120 */ private Integer price; - /** * 实际支付金额 */ private Integer payPrice; - + // TODO @jason:bonusPrice 哈,更统一一点; /** * 钱包赠送金额 */ private Integer walletBonus; /** - * 是否已支付:[0:未支付 1:已经支付过] + * 是否已支付 + * + * true - 已支付 + * false - 未支付 */ private Boolean payStatus; /** * 支付订单编号 + * + * 关联 {@link PayOrderDO#getId()} */ private Long payOrderId; - /** * 支付成功的支付渠道 + * + * 冗余 {@link PayOrderDO#getChannelCode()} */ private String payChannelCode; - /** * 订单支付时间 */ @@ -64,26 +75,27 @@ public class PayWalletRechargeDO extends BaseDO { /** * 支付退款单编号 + * + * 关联 {@link PayRefundDO#getId()} */ private Long payRefundId; - + // TODO @jason:要不改成 refundTotalPrice? /** * 退款金额,包含赠送金额 */ private Integer refundPrice; - /** * 退款支付金额 */ private Integer refundPayPrice; - + // TODO @jason:要不改成 refundBonusPrice? /** * 退款钱包赠送金额 */ private Integer refundWalletBonus; - /** * 退款时间 */ private LocalDateTime refundTime; -} \ No newline at end of file + +} 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 index b93c240d2..57f9250d6 100644 --- 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 @@ -14,6 +14,8 @@ public interface PayWalletMapper extends BaseMapperX { PayWalletDO::getUserType, userType); } + // TODO @jason:下面几个更新方法,把 id 放前面哈。一般来说,重要参数放前面; + /** * 当消费退款时候, 更新钱包 * @@ -55,6 +57,7 @@ public interface PayWalletMapper extends BaseMapperX { .eq(PayWalletDO::getId, id); return update(null, lambdaUpdateWrapper); } + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java index cabc9c86f..506d978dc 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java @@ -2,17 +2,17 @@ package cn.iocoder.yudao.module.pay.dal.mysql.wallet; 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.demo.PayDemoOrderDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; import org.apache.ibatis.annotations.Mapper; @Mapper public interface PayWalletRechargeMapper extends BaseMapperX { - default int updateByIdAndPaid(Long id, boolean wherePayed, PayWalletRechargeDO updateObj){ + default int updateByIdAndPaid(Long id, boolean wherePayStatus, PayWalletRechargeDO updateObj){ return update(updateObj, new LambdaQueryWrapperX() - .eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayed)); + .eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayStatus)); } + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java index 0752dbe99..1a167474b 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java @@ -11,19 +11,22 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; public interface PayWalletRechargeService { /** - * 创建钱包充值记录 + * 创建钱包充值记录(发起充值) + * * @param userId 用户 id * @param userType 用户类型 - * @param vo 钱包充值请求 vo + * @param createReqVO 钱包充值请求 VO * @return 钱包充值记录 */ - PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, AppPayWalletRechargeCreateReqVO vo); - + PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, + AppPayWalletRechargeCreateReqVO createReqVO); /** * 更新钱包充值成功 - * @param walletRechargeId 钱包充值 id + * + * @param id 钱包充值记录 id * @param payOrderId 支付订单 id */ - void updateWalletRechargerPaid(Long walletRechargeId, Long payOrderId); + void updateWalletRechargerPaid(Long id, Long payOrderId); + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index a68f034bc..771dfd383 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java @@ -42,57 +42,61 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { @Resource private PayWalletRechargeMapper walletRechargeMapper; + @Resource private PayWalletService payWalletService; @Resource private PayOrderService payOrderService; - @Override @Transactional(rollbackFor = Exception.class) - public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, AppPayWalletRechargeCreateReqVO vo) { - // 1. 获取钱包 + public PayWalletRechargeDO createWalletRecharge(Long userId, Integer userType, + AppPayWalletRechargeCreateReqVO createReqVO) { + // 1. 新增钱包充值记录 PayWalletDO wallet = payWalletService.getOrCreateWallet(userId, userType); - // 2. 新增钱包充值记录 - PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), vo); + PayWalletRechargeDO walletRecharge = PayWalletRechargeConvert.INSTANCE.convert(wallet.getId(), createReqVO); walletRechargeMapper.insert(walletRecharge); - // 3.创建支付单 + + // 2.1 创建支付单 Long payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO() .setAppId(WALLET_PAY_APP_ID).setUserIp(getClientIP()) .setMerchantOrderId(walletRecharge.getId().toString()) // 业务的订单编号 .setSubject(WALLET_RECHARGE_ORDER_SUBJECT).setBody("").setPrice(walletRecharge.getPayPrice()) .setExpireTime(addTime(Duration.ofHours(2L)))); - // 4.更新钱包充值记录中支付订单 + // 2.2 更新钱包充值记录中支付订单 walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) .setId(walletRecharge.getId())); + // TODO @jason:是不是你直接返回就好啦;然后 payOrderId 设置下; return walletRechargeMapper.selectById(walletRecharge.getId()); } @Override @Transactional(rollbackFor = Exception.class) - public void updateWalletRechargerPaid(Long walletRechargeId, Long payOrderId) { - // 1. 获取钱包充值记录 - PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(walletRechargeId); + public void updateWalletRechargerPaid(Long id, Long payOrderId) { + // 1.1 获取钱包充值记录 + PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id); if (walletRecharge == null) { - log.error("[updateWalletRechargerPaid],钱包充值记录不存在,钱包充值 Id:{} ", walletRechargeId); + log.error("[updateWalletRechargerPaid][钱包充值记录不存在,钱包充值记录 id({})]", id); throw exception(WALLET_RECHARGE_NOT_FOUND); } - // 2. 校验钱包充值是否可以支付 + // 1.2 校验钱包充值是否可以支付 PayOrderDO payOrderDO = validateWalletRechargerCanPaid(walletRecharge, payOrderId); - // 3. 更新钱包充值的支付状态 - int updateCount = walletRechargeMapper.updateByIdAndPaid(walletRechargeId,false, new PayWalletRechargeDO().setId(walletRechargeId) - .setPayStatus(true).setPayTime(LocalDateTime.now()) + + // 2. 更新钱包充值的支付状态 + int updateCount = walletRechargeMapper.updateByIdAndPaid(id,false, + new PayWalletRechargeDO().setId(id).setPayStatus(true).setPayTime(LocalDateTime.now()) .setPayChannelCode(payOrderDO.getChannelCode())); if (updateCount == 0) { throw exception(WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID); } - // 4. 更新钱包余额 - payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(walletRechargeId), + + // 3. 更新钱包余额 + // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; + payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); } private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { - // 1.1 校验充值记录的支付状态 if (walletRecharge.getPayStatus()) { log.error("[validateWalletRechargerCanPaid][钱包({}) 不处于未支付状态! 钱包数据是:{}]", @@ -105,6 +109,7 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { walletRecharge.getId(), payOrderId, toJsonString(walletRecharge)); throw exception(WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR); } + // 2.1 校验支付单是否存在 PayOrderDO payOrder = payOrderService.getOrder(payOrderId); if (payOrder == null) { @@ -132,4 +137,5 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { } return payOrder; } + } 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 8e24ed705..346e8523e 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 @@ -9,7 +9,7 @@ import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -84,6 +84,7 @@ public class PayWalletServiceImpl implements PayWalletService { Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), refundPrice); PayWalletDO wallet = walletMapper.selectById(walletId); Assert.notNull(wallet, "钱包 {} 不存在", walletId); + // 2. 增加余额 return addWalletBalance(walletId, String.valueOf(payRefund.getId()), PAYMENT_REFUND, refundPrice); } @@ -137,42 +138,39 @@ public class PayWalletServiceImpl implements PayWalletService { } // 2.2 生成钱包流水 Integer afterBalance = payWallet.getBalance() - price; - CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) + WalletTransactionCreateReqBO bo = new WalletTransactionCreateReqBO().setWalletId(payWallet.getId()) .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) .setBizType(bizType.getType()).setTitle(bizType.getDescription()); return walletTransactionService.createWalletTransaction(bo); } @Override - public PayWalletTransactionDO addWalletBalance(Long walletId, - String bizId, PayWalletBizTypeEnum bizType, Integer price) { - // 1. 获取钱包 + public PayWalletTransactionDO addWalletBalance(Long walletId, String bizId, + PayWalletBizTypeEnum bizType, Integer price) { + // 1.1 获取钱包 PayWalletDO payWallet = getWallet(walletId); - if (payWallet == null) { log.error("[addWalletBalance],用户钱包({})不存在.", walletId); throw exception(WALLET_NOT_FOUND); } - + // 1.2 更新钱包金额 switch (bizType) { - case PAYMENT_REFUND: { - // 退款更新 + case PAYMENT_REFUND: { // 退款更新 walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); break; } - case RECHARGE: { - // 充值更新 + case RECHARGE: { // 充值更新 walletMapper.updateWhenRecharge(price, payWallet.getId()); break; } - // TODO 其它类型 + // TODO 其它类型;这里可以先跑异常;避免有业务搞错; } // 2. 生成钱包流水 - CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) - .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(bizId) - .setBizType(bizType.getType()).setTitle(bizType.getDescription()); - return walletTransactionService.createWalletTransaction(bo); + WalletTransactionCreateReqBO transactionCreateReqBO = new WalletTransactionCreateReqBO() + .setWalletId(payWallet.getId()).setPrice(price).setBalance(payWallet.getBalance() + price) + .setBizId(bizId).setBizType(bizType.getType()).setTitle(bizType.getDescription()); + return walletTransactionService.createWalletTransaction(transactionCreateReqBO); } } 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 index 52c84e159..d47c149b1 100644 --- 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 @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; import javax.validation.Valid; @@ -31,7 +31,7 @@ public interface PayWalletTransactionService { * @param bo 创建钱包流水 bo * @return 新建的钱包 do */ - PayWalletTransactionDO createWalletTransaction(@Valid CreateWalletTransactionBO bo); + PayWalletTransactionDO createWalletTransaction(@Valid WalletTransactionCreateReqBO bo); /** * 根据 no,获取钱包余流水 @@ -48,5 +48,5 @@ public interface PayWalletTransactionService { * @return 钱包流水 */ PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); - + } 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 index 6ef32a557..ad802be41 100644 --- 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 @@ -8,7 +8,7 @@ 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.dal.redis.no.PayNoRedisDAO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; -import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; +import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -43,7 +43,7 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ } @Override - public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) { + public PayWalletTransactionDO createWalletTransaction(WalletTransactionCreateReqBO bo) { PayWalletTransactionDO transaction = PayWalletTransactionConvert.INSTANCE.convert(bo) .setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); payWalletTransactionMapper.insert(transaction); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/WalletTransactionCreateReqBO.java similarity index 94% rename from yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java rename to yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/WalletTransactionCreateReqBO.java index a1b7af8be..736415154 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/WalletTransactionCreateReqBO.java @@ -9,7 +9,7 @@ import lombok.Data; * @author jason */ @Data -public class CreateWalletTransactionBO { +public class WalletTransactionCreateReqBO { // TODO @jason:bo 的话,最好加个参数校验哈; From be1ecf96d424bef5ffece08a60c5e11afa24540c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 18 Sep 2023 22:18:42 +0800 Subject: [PATCH 12/12] =?UTF-8?q?code=20review=EF=BC=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/enums/ErrorCodeConstants.java | 3 +- .../app/signin/AppMemberSignInController.java | 34 ++++-------- .../signin/MemberSignInRecordService.java | 20 ++++--- .../signin/MemberSignInRecordServiceImpl.java | 55 +++++++++++-------- 4 files changed, 55 insertions(+), 57 deletions(-) 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 f3b6369a6..933f17168 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 @@ -39,8 +39,7 @@ public interface ErrorCodeConstants { ErrorCode SIGN_IN_CONFIG_EXISTS = new ErrorCode(1004009001, "签到天数规则已存在"); //========== 签到配置 1004010000 ========== - ErrorCode SIGN_IN_RECORD_EXISTS = new ErrorCode(1004010000,"用户重复签到"); - + ErrorCode SIGN_IN_RECORD_TODAY_EXISTS = new ErrorCode(1004010000,"今日已签到,请勿重复签到"); //========== 用户等级 1004011000 ========== ErrorCode LEVEL_NOT_EXISTS = new ErrorCode(1004011000, "用户等级不存在"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java index dd5acd313..b3dcfa5f5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/signin/AppMemberSignInController.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.member.controller.app.signin; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.member.convert.signin.MemberSignInRecordConvert; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; import cn.iocoder.yudao.module.member.service.signin.MemberSignInRecordService; @@ -14,42 +13,33 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -/** - * 描述 :用户签到相关信息接口 - * Author :xiaqing - * Date :2023-09-15 09:02 - */ +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; + +// TODO @xiaqing:sign-in @Tag(name = "签到APP - 签到") @RestController @RequestMapping("/member/signin") public class AppMemberSignInController { @Resource - MemberSignInRecordService signInRecordService; - - /** - * 描述 :获取个人签到信息 - * Author :xiaqing - * Date :2023-09-15 12:56:47 - */ + private MemberSignInRecordService signInRecordService; + // TODO @xiaqing:泛型: + // TODO @xiaqing:合并到 AppMemberSignInRecordController 的 getSignInRecordSummary 里哈。 @Operation(summary = "个人签到信息") @GetMapping("/get-summary") public CommonResult getUserSummary(){ - return CommonResult.success(signInRecordService.getUserSummary(SecurityFrameworkUtils.getLoginUserId())); + return success(signInRecordService.getSignInRecordSummary(getLoginUserId())); } - - /** - * 描述 :用户签到 - * Author :xiaqing - * Date :2023-09-15 09:20:58 - */ + // TODO @xiaqing:泛型: + // TODO @xiaqing:合并到 AppMemberSignInRecordController 的 createSignInRecord 里哈。 @Operation(summary = "会员签到") @PostMapping("/create") public CommonResult create(){ - MemberSignInRecordDO recordDO = signInRecordService.create(SecurityFrameworkUtils.getLoginUserId()); - return CommonResult.success(MemberSignInRecordConvert.INSTANCE.coverRecordToAppRecordVo(recordDO)); + MemberSignInRecordDO recordDO = signInRecordService.createSignRecord(getLoginUserId()); + return success(MemberSignInRecordConvert.INSTANCE.coverRecordToAppRecordVo(recordDO)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java index 6e8096d1b..4f1c365e0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordService.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.member.service.signin; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.signin.vo.record.MemberSignInRecordPageReqVO; -import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInRecordRespVO; import cn.iocoder.yudao.module.member.controller.app.signin.vo.AppMemberSignInSummaryRespVO; import cn.iocoder.yudao.module.member.dal.dataobject.signin.MemberSignInRecordDO; @@ -31,18 +30,21 @@ public interface MemberSignInRecordService { */ PageResult getSignRecordPage(Long userId, PageParam pageParam); - - MemberSignInRecordDO create(Long userId); + /** + * 创建签到记录 + * + * @param userId 用户编号 + * @return 签到记录 + */ + MemberSignInRecordDO createSignRecord(Long userId); /** + * 根据用户编号,获得个人签到统计信息 * - *功能描述: 根据用户id获取个人签到信息 - * @param userId - * @return - * @author xiaqing - * @date 2023-09-15 14:21:01 + * @param userId 用户编号 + * @return 个人签到统计信息 */ - AppMemberSignInSummaryRespVO getUserSummary(Long userId); + AppMemberSignInSummaryRespVO getSignInRecordSummary(Long userId); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java index 02759db19..dc1646447 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/signin/MemberSignInRecordServiceImpl.java @@ -36,28 +36,28 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @Validated public class MemberSignInRecordServiceImpl implements MemberSignInRecordService { - @Resource - private MemberSignInRecordMapper memberSignInRecordMapper; @Resource private MemberSignInRecordMapper signInRecordMapper; @Resource private MemberSignInConfigMapper signInConfigMapper; + @Resource private MemberUserApi memberUserApi; - @Override - public AppMemberSignInSummaryRespVO getUserSummary(Long userId) { + public AppMemberSignInSummaryRespVO getSignInRecordSummary(Long userId) { AppMemberSignInSummaryRespVO vo = new AppMemberSignInSummaryRespVO(); vo.setTotalDay(0); vo.setContinuousDay(0); vo.setTodaySignIn(false); //获取用户签到的记录,按照天数倒序获取 List signInRecordDOList = signInRecordMapper.selectListByUserId(userId); + // TODO @xiaqing:if 空的时候,直接 return;这样括号少,逻辑更简洁; if(!CollectionUtils.isEmpty(signInRecordDOList)){ //设置总签到天数 - vo.setTotalDay(signInRecordDOList.size()); + vo.setTotalDay(signInRecordDOList.size()); // TODO @xiaqing:是不是不用读取 signInRecordDOList 所有的,而是 count下,然后另外再读取一条最后一条; //判断当天是否有签到复用校验方法 + // TODO @xiaqing:不要用异常实现逻辑;还是判断哈; try { validSignDay(signInRecordDOList.get(0)); vo.setTodaySignIn(false); @@ -69,6 +69,7 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService //下方计算连续签到从2天开始,此处直接设置一天连续签到 vo.setContinuousDay(1); //判断连续签到天数 + // TODO @xiaqing:这里逻辑,想想怎么在简化下,可读性可以在提升下哈; for (int i = 1; i < signInRecordDOList.size(); i++) { //前一天减1等于当前天数则说明连续,继续循环 LocalDate cur = signInRecordDOList.get(i).getCreateTime().toLocalDate(); @@ -103,47 +104,50 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService userIds = convertSet(users, MemberUserRespDTO::getId); } // 分页查询 - return memberSignInRecordMapper.selectPage(pageReqVO, userIds); + return signInRecordMapper.selectPage(pageReqVO, userIds); } @Override public PageResult getSignRecordPage(Long userId, PageParam pageParam) { - return memberSignInRecordMapper.selectPage(userId, pageParam); + return signInRecordMapper.selectPage(userId, pageParam); } @Override - public MemberSignInRecordDO create(Long userId) { - //获取当前用户签到的最大天数 + public MemberSignInRecordDO createSignRecord(Long userId) { + // 获取当前用户签到的最大天数 + // TODO @xiaqing:db 操作,dou封装到 mapper 中; + // TODO @xiaqing:maxSignDay,是不是变量叫 lastRecord 会更容易理解哈; MemberSignInRecordDO maxSignDay = signInRecordMapper.selectOne(new LambdaQueryWrapperX () .eq(MemberSignInRecordDO::getUserId, userId) .orderByDesc(MemberSignInRecordDO::getDay) .last("limit 1")); - //判断是否重复签到 + // 判断是否重复签到 validSignDay(maxSignDay); + // TODO @xiaqing:可以使用 // 进行注释 /**1.查询出当前签到的天数**/ - MemberSignInRecordDO sign = new MemberSignInRecordDO(); - sign.setUserId(userId); - //设置签到初始化天数 - sign.setDay(1); - //设置签到分数默认为0 - sign.setPoint(0); - //如果不为空则修改当前签到对应的天数 + MemberSignInRecordDO sign = new MemberSignInRecordDO().setUserId(userId); // TODO @xiaqing:应该使用 record 变量,会更合适 + sign.setDay(1); // 设置签到初始化天数 + sign.setPoint(0); // 设置签到分数默认为 0 + // 如果不为空则修改当前签到对应的天数 + // TODO @xiaqing:应该是要判断连续哈,就是昨天; if (maxSignDay != null) { sign.setDay(maxSignDay.getDay() + 1); } /**2.获取签到对应的分数**/ - //获取所有的签到规则,按照天数排序,只获取启用的 + // 获取所有的签到规则,按照天数排序,只获取启用的 TODO @xiaqing:不要使用 signInConfigMapper 直接查询,而是要通过 SigninConfigService; List configDOList = signInConfigMapper.selectList(new LambdaQueryWrapperX () .eq(MemberSignInConfigDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) .orderByAsc(MemberSignInConfigDO::getDay)); - //如果签到的天数大于最大启用的规则天数,直接给最大签到的分数 + // 如果签到的天数大于最大启用的规则天数,直接给最大签到的分数 + // TODO @xiaqing:超过最大配置的天数,应该直接重置到第一天哈; MemberSignInConfigDO lastConfig = configDOList.get(configDOList.size() - 1); if (sign.getDay() > lastConfig.getDay()) { sign.setPoint(lastConfig.getPoint()); } else { configDOList.forEach(el -> { - //循环匹配对应天数,设置对应分数 + // 循环匹配对应天数,设置对应分数 + // TODO @xiaqing:使用 equals;另外,这种不应该去遍历比较,从可读性来说,应该 CollUtil.findOne() if (el.getDay() == sign.getDay()) { sign.setPoint(el.getPoint()); } @@ -151,18 +155,21 @@ public class MemberSignInRecordServiceImpl implements MemberSignInRecordService }); } - //3.插入当前签到获取的分数 + // 3. 插入当前签到获取的分数 signInRecordMapper.insert(sign); - //4.返回给用户 return sign; } - void validSignDay(MemberSignInRecordDO signInRecordDO) { + // TODO @xiaqing:校验使用 validate 动词哈;可以改成 validateSigned + private void validSignDay(MemberSignInRecordDO signInRecordDO) { + // TODO @xiaqing:代码格式:if () {} 要有括号哈 if (signInRecordDO == null) return; + // TODO @xiaqing:可以直接使用 DateUtils.isToday() LocalDate today = LocalDate.now(); if (today.equals(signInRecordDO.getCreateTime().toLocalDate())) { - throw exception(ErrorCodeConstants.SIGN_IN_RECORD_EXISTS); + throw exception(ErrorCodeConstants.SIGN_IN_RECORD_TODAY_EXISTS); } } + }