From 73d0e9d08aa241e5b314c57b45bdec60a7179baf Mon Sep 17 00:00:00 2001 From: xiaqing Date: Sat, 10 Jun 2023 20:44:31 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=A7=AF?= =?UTF-8?q?=E5=88=86=E6=A8=A1=E5=9D=97=201.=E7=A7=AF=E5=88=86=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=AE=A1=E7=90=86=202.=E7=A7=AF=E5=88=86=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E8=A7=84=E5=88=99=E7=AE=A1=E7=90=86=203.=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=A7=AF=E5=88=86=E8=AE=B0=E5=BD=95=E7=AE=A1=E7=90=86?= =?UTF-8?q?=204.=E7=94=A8=E6=88=B7=E7=AD=BE=E5=88=B0=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-module-point/pom.xml | 19 ++ .../yudao-module-point-api/pom.xml | 28 +++ .../point/enums/ErrorCodeConstants.java | 27 +++ .../yudao-module-point-biz/pom.xml | 57 ++++++ .../pointconfig/PointConfigController.java | 102 ++++++++++ .../pointconfig/vo/PointConfigBaseVO.java | 30 +++ .../vo/PointConfigCreateReqVO.java | 14 ++ .../pointconfig/vo/PointConfigExcelVO.java | 45 +++++ .../vo/PointConfigExportReqVO.java | 15 ++ .../pointconfig/vo/PointConfigPageReqVO.java | 17 ++ .../pointconfig/vo/PointConfigRespVO.java | 22 +++ .../vo/PointConfigUpdateReqVO.java | 18 ++ .../pointrecord/PointRecordController.java | 102 ++++++++++ .../pointrecord/vo/PointRecordBaseVO.java | 67 +++++++ .../vo/PointRecordCreateReqVO.java | 14 ++ .../pointrecord/vo/PointRecordExcelVO.java | 65 +++++++ .../vo/PointRecordExportReqVO.java | 27 +++ .../pointrecord/vo/PointRecordPageReqVO.java | 29 +++ .../pointrecord/vo/PointRecordRespVO.java | 19 ++ .../vo/PointRecordUpdateReqVO.java | 18 ++ .../signinconfig/SignInConfigController.java | 102 ++++++++++ .../signinconfig/vo/SignInConfigBaseVO.java | 23 +++ .../vo/SignInConfigCreateReqVO.java | 14 ++ .../signinconfig/vo/SignInConfigExcelVO.java | 28 +++ .../vo/SignInConfigExportReqVO.java | 15 ++ .../vo/SignInConfigPageReqVO.java | 17 ++ .../signinconfig/vo/SignInConfigRespVO.java | 19 ++ .../vo/SignInConfigUpdateReqVO.java | 18 ++ .../signinrecord/SignInRecordController.java | 102 ++++++++++ .../signinrecord/vo/SignInRecordBaseVO.java | 26 +++ .../vo/SignInRecordCreateReqVO.java | 14 ++ .../signinrecord/vo/SignInRecordExcelVO.java | 34 ++++ .../vo/SignInRecordExportReqVO.java | 26 +++ .../vo/SignInRecordPageReqVO.java | 28 +++ .../signinrecord/vo/SignInRecordRespVO.java | 19 ++ .../vo/SignInRecordUpdateReqVO.java | 18 ++ .../pointconfig/PointConfigConvert.java | 34 ++++ .../pointrecord/PointRecordConvert.java | 34 ++++ .../signinconfig/SignInConfigConvert.java | 34 ++++ .../signinrecord/SignInRecordConvert.java | 34 ++++ .../dataobject/pointconfig/PointConfigDO.java | 51 +++++ .../dataobject/pointrecord/PointRecordDO.java | 82 ++++++++ .../signinconfig/SignInConfigDO.java | 39 ++++ .../signinrecord/SignInRecordDO.java | 43 ++++ .../mysql/pointconfig/PointConfigMapper.java | 32 +++ .../mysql/pointrecord/PointRecordMapper.java | 40 ++++ .../signinconfig/SignInConfigMapper.java | 41 ++++ .../signinrecord/SignInRecordMapper.java | 36 ++++ .../pointconfig/PointConfigService.java | 70 +++++++ .../pointconfig/PointConfigServiceImpl.java | 92 +++++++++ .../pointrecord/PointRecordService.java | 70 +++++++ .../pointrecord/PointRecordServiceImpl.java | 82 ++++++++ .../signinconfig/SignInConfigService.java | 70 +++++++ .../signinconfig/SignInConfigServiceImpl.java | 102 ++++++++++ .../signinrecord/SignInRecordService.java | 70 +++++++ .../signinrecord/SignInRecordServiceImpl.java | 82 ++++++++ .../mapper/pointconfig/PointConfigMapper.xml | 12 ++ .../mapper/pointrecord/PointRecordMapper.xml | 12 ++ .../signinconfig/SignInConfigMapper.xml | 12 ++ .../signinrecord/SignInRecordMapper.xml | 12 ++ .../PointConfigServiceImplTest.java | 152 +++++++++++++++ .../PointRecordServiceImplTest.java | 183 ++++++++++++++++++ .../SignInConfigServiceImplTest.java | 152 +++++++++++++++ .../SignInRecordServiceImplTest.java | 167 ++++++++++++++++ yudao-server/pom.xml | 40 ++-- 65 files changed, 3101 insertions(+), 17 deletions(-) create mode 100644 yudao-module-point/pom.xml create mode 100644 yudao-module-point/yudao-module-point-api/pom.xml create mode 100644 yudao-module-point/yudao-module-point-api/src/main/java/cn/iocoder/yudao/module/point/enums/ErrorCodeConstants.java create mode 100644 yudao-module-point/yudao-module-point-biz/pom.xml create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/PointRecordController.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordBaseVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordCreateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExcelVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExportReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordPageReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordRespVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordUpdateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/SignInConfigController.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigBaseVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigCreateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExcelVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExportReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigPageReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigRespVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigUpdateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/SignInRecordController.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordBaseVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordCreateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExcelVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExportReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordPageReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordRespVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordUpdateReqVO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointrecord/PointRecordConvert.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinconfig/SignInConfigConvert.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinrecord/SignInRecordConvert.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointrecord/PointRecordDO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinconfig/SignInConfigDO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinrecord/SignInRecordDO.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointrecord/PointRecordMapper.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinconfig/SignInConfigMapper.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinrecord/SignInRecordMapper.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordService.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImpl.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigService.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImpl.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordService.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImpl.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml create mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml create mode 100644 yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImplTest.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImplTest.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImplTest.java create mode 100644 yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImplTest.java diff --git a/yudao-module-point/pom.xml b/yudao-module-point/pom.xml new file mode 100644 index 000000000..f0361dd60 --- /dev/null +++ b/yudao-module-point/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao + ${revision} + + + yudao-module-point + pom + + yudao-module-point-api + + + + \ No newline at end of file diff --git a/yudao-module-point/yudao-module-point-api/pom.xml b/yudao-module-point/yudao-module-point-api/pom.xml new file mode 100644 index 000000000..83898557f --- /dev/null +++ b/yudao-module-point/yudao-module-point-api/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao-module-point + ${revision} + + + yudao-module-point-api + jar + + + + cn.iocoder.boot + yudao-common + + + + + org.springframework.boot + spring-boot-starter-validation + true + + + \ No newline at end of file diff --git a/yudao-module-point/yudao-module-point-api/src/main/java/cn/iocoder/yudao/module/point/enums/ErrorCodeConstants.java b/yudao-module-point/yudao-module-point-api/src/main/java/cn/iocoder/yudao/module/point/enums/ErrorCodeConstants.java new file mode 100644 index 000000000..8d4daf0fc --- /dev/null +++ b/yudao-module-point/yudao-module-point-api/src/main/java/cn/iocoder/yudao/module/point/enums/ErrorCodeConstants.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.point.enums; + + +import cn.iocoder.yudao.framework.common.exception.ErrorCode; + +/** + * Pay 错误码 Core 枚举类 + * + * pay 系统,使用 1-007-000-000 段 + */ +public interface ErrorCodeConstants { + + ErrorCode CONFIG_NOT_EXISTS = new ErrorCode(499, "积分设置不存在"); + + ErrorCode CONFIG_EXISTS = new ErrorCode(499, "积分设置已存在,只允配置一条记录"); + + + ErrorCode SIGN_IN_CONFIG_NOT_EXISTS = new ErrorCode(499, "签到天数规则不存在"); + ErrorCode SIGN_IN_CONFIG_EXISTS = new ErrorCode(499, "签到天数规则已存在"); + + ErrorCode RECORD_NOT_EXISTS = new ErrorCode( 499, "用户积分记录不存在"); + + ErrorCode SIGN_IN_RECORD_NOT_EXISTS = new ErrorCode(499, "用户签到积分不存在"); + + + +} diff --git a/yudao-module-point/yudao-module-point-biz/pom.xml b/yudao-module-point/yudao-module-point-biz/pom.xml new file mode 100644 index 000000000..fc4561441 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + cn.iocoder.boot + yudao-module-point + ${revision} + + + yudao-module-point-biz + jar + + + + cn.iocoder.boot + yudao-module-point-api + ${revision} + + + + + cn.iocoder.boot + yudao-spring-boot-starter-biz-operatelog + + + + + cn.iocoder.boot + yudao-spring-boot-starter-web + + + + cn.iocoder.boot + yudao-spring-boot-starter-security + + + + + cn.iocoder.boot + yudao-spring-boot-starter-mybatis + + + + + cn.iocoder.boot + yudao-spring-boot-starter-test + + + + + cn.iocoder.boot + yudao-spring-boot-starter-excel + + + \ No newline at end of file diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java new file mode 100644 index 000000000..137d03050 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; +import cn.iocoder.yudao.module.point.convert.pointconfig.PointConfigConvert; +import cn.iocoder.yudao.module.point.service.pointconfig.PointConfigService; + +@Tag(name = "管理后台 - 积分设置") +@RestController +@RequestMapping("/point/config") +@Validated +public class PointConfigController { + + @Resource + private PointConfigService configService; + + @PostMapping("/create") + @Operation(summary = "创建积分设置") + @PreAuthorize("@ss.hasPermission('point:config:create')") + public CommonResult createConfig(@Valid @RequestBody PointConfigCreateReqVO createReqVO) { + return success(configService.createConfig(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新积分设置") + @PreAuthorize("@ss.hasPermission('point:config:update')") + public CommonResult updateConfig(@Valid @RequestBody PointConfigUpdateReqVO updateReqVO) { + configService.updateConfig(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除积分设置") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('point:config:delete')") + public CommonResult deleteConfig(@RequestParam("id") Integer id) { + configService.deleteConfig(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得积分设置") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('point:config:query')") + public CommonResult getConfig(@RequestParam("id") Integer id) { + PointConfigDO config = configService.getConfig(id); + return success(PointConfigConvert.INSTANCE.convert(config)); + } + + @GetMapping("/list") + @Operation(summary = "获得积分设置列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('point:config:query')") + public CommonResult> getConfigList(@RequestParam("ids") Collection ids) { + List list = configService.getConfigList(ids); + return success(PointConfigConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得积分设置分页") + @PreAuthorize("@ss.hasPermission('point:config:query')") + public CommonResult> getConfigPage(@Valid PointConfigPageReqVO pageVO) { + PageResult pageResult = configService.getConfigPage(pageVO); + return success(PointConfigConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出积分设置 Excel") + @PreAuthorize("@ss.hasPermission('point:config:export')") + @OperateLog(type = EXPORT) + public void exportConfigExcel(@Valid PointConfigExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = configService.getConfigList(exportReqVO); + // 导出 Excel + List datas = PointConfigConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "积分设置.xls", "数据", PointConfigExcelVO.class, datas); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java new file mode 100644 index 000000000..d1e900cc2 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import javax.validation.constraints.*; + +/** + * 积分设置 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class PointConfigBaseVO { + + @Schema(description = "1 开启积分抵扣 0 关闭积分抵扣", example = "1") + private Integer tradeDeductEnable; + + @Schema(description = "积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元)", example = "13506") + private BigDecimal tradeDeductUnitPrice; + + @Schema(description = "积分抵扣最大值", example = "32428") + private Long tradeDeductMaxPrice; + + @Schema(description = "1元赠送多少分") + private Long tradeGivePoint; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java new file mode 100644 index 000000000..4284f5e34 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 积分设置创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointConfigCreateReqVO extends PointConfigBaseVO { + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java new file mode 100644 index 000000000..0d01c7a5c --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; + + +/** + * 积分设置 Excel VO + * + * @author QingX + */ +@Data +public class PointConfigExcelVO { + + @ExcelProperty("自增主键") + private Integer id; + + @ExcelProperty(value = "1 开启积分抵扣 0 关闭积分抵扣", converter = DictConvert.class) + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private Integer tradeDeductEnable; + + @ExcelProperty("积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元)") + private BigDecimal tradeDeductUnitPrice; + + @ExcelProperty("积分抵扣最大值") + private Long tradeDeductMaxPrice; + + @ExcelProperty("1元赠送多少分") + private Long tradeGivePoint; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @ExcelProperty("变更时间") + private LocalDateTime updateTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java new file mode 100644 index 000000000..bcc712d29 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +@Schema(description = "管理后台 - 积分设置 Excel 导出 Request VO,参数和 PointConfigPageReqVO 是一致的") +@Data +public class PointConfigExportReqVO { + + @Schema(description = "1 开启积分抵扣 0 关闭积分抵扣", example = "1") + private Integer tradeDeductEnable; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java new file mode 100644 index 000000000..cc994837c --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +@Schema(description = "管理后台 - 积分设置分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointConfigPageReqVO extends PageParam { + + @Schema(description = "1 开启积分抵扣 0 关闭积分抵扣", example = "1") + private Integer tradeDeductEnable; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java new file mode 100644 index 000000000..a8efe57b4 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 积分设置 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointConfigRespVO extends PointConfigBaseVO { + + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20937") + private Integer id; + + @Schema(description = "创建时间") + private LocalDateTime createTime; + + @Schema(description = "变更时间") + private LocalDateTime updateTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java new file mode 100644 index 000000000..9b50f259d --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 积分设置更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointConfigUpdateReqVO extends PointConfigBaseVO { + + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20937") + @NotNull(message = "自增主键不能为空") + private Integer id; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/PointRecordController.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/PointRecordController.java new file mode 100644 index 000000000..14c115a35 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/PointRecordController.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointrecord.PointRecordDO; +import cn.iocoder.yudao.module.point.convert.pointrecord.PointRecordConvert; +import cn.iocoder.yudao.module.point.service.pointrecord.PointRecordService; + +@Tag(name = "管理后台 - 用户积分记录") +@RestController +@RequestMapping("/point/record") +@Validated +public class PointRecordController { + + @Resource + private PointRecordService recordService; + + @PostMapping("/create") + @Operation(summary = "创建用户积分记录") + @PreAuthorize("@ss.hasPermission('point:record:create')") + public CommonResult createRecord(@Valid @RequestBody PointRecordCreateReqVO createReqVO) { + return success(recordService.createRecord(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新用户积分记录") + @PreAuthorize("@ss.hasPermission('point:record:update')") + public CommonResult updateRecord(@Valid @RequestBody PointRecordUpdateReqVO updateReqVO) { + recordService.updateRecord(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除用户积分记录") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('point:record:delete')") + public CommonResult deleteRecord(@RequestParam("id") Long id) { + recordService.deleteRecord(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得用户积分记录") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('point:record:query')") + public CommonResult getRecord(@RequestParam("id") Long id) { + PointRecordDO record = recordService.getRecord(id); + return success(PointRecordConvert.INSTANCE.convert(record)); + } + + @GetMapping("/list") + @Operation(summary = "获得用户积分记录列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('point:record:query')") + public CommonResult> getRecordList(@RequestParam("ids") Collection ids) { + List list = recordService.getRecordList(ids); + return success(PointRecordConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得用户积分记录分页") + @PreAuthorize("@ss.hasPermission('point:record:query')") + public CommonResult> getRecordPage(@Valid PointRecordPageReqVO pageVO) { + PageResult pageResult = recordService.getRecordPage(pageVO); + return success(PointRecordConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出用户积分记录 Excel") + @PreAuthorize("@ss.hasPermission('point:record:export')") + @OperateLog(type = EXPORT) + public void exportRecordExcel(@Valid PointRecordExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = recordService.getRecordList(exportReqVO); + // 导出 Excel + List datas = PointRecordConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "用户积分记录.xls", "数据", PointRecordExcelVO.class, datas); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordBaseVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordBaseVO.java new file mode 100644 index 000000000..0337aac8e --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordBaseVO.java @@ -0,0 +1,67 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import javax.validation.constraints.*; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 用户积分记录 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class PointRecordBaseVO { + + @Schema(description = "业务编码", example = "22706") + @NotNull(message = "业务编码不能为空") + private String bizId; + + @Schema(description = "业务类型", example = "1") + @NotNull(message = "业务类型不能为空") + private String bizType; + + @Schema(description = "1增加 0扣减", example = "1") + @NotNull(message = "操作类型不能为空") + private String type; + + @Schema(description = "积分标题") + @NotNull(message = "积分标题不能为空") + private String title; + + @Schema(description = "积分描述", example = "你猜") + private String description; + + @Schema(description = "积分") + @NotNull(message = "操作积分不能为空") + private Integer point; + + @Schema(description = "变动后的积分", requiredMode = Schema.RequiredMode.REQUIRED) +// @NotNull(message = "变动后的积分不能为空") + private Integer totalPoint; + + @Schema(description = "状态:1-订单创建,2-冻结期,3-完成,4-失效(订单退款) ", example = "1") + @NotNull(message = "积分状态不能为空") + private Integer status; + + @Schema(description = "用户id", example = "31169") + @NotNull(message = "用户ID不能为空") + private Integer userId; + + @Schema(description = "冻结时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @NotNull(message = "冻结时间不能为空") + private LocalDateTime freezingTime; + + @Schema(description = "解冻时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @NotNull(message = "解冻时间不能为空") + private LocalDateTime thawingTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordCreateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordCreateReqVO.java new file mode 100644 index 000000000..7062109d2 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户积分记录创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointRecordCreateReqVO extends PointRecordBaseVO { + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExcelVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExcelVO.java new file mode 100644 index 000000000..3db1573fc --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExcelVO.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; + + +/** + * 用户积分记录 Excel VO + * + * @author QingX + */ +@Data +public class PointRecordExcelVO { + + @ExcelProperty("自增主键") + private Long id; + + @ExcelProperty("业务编码") + private String bizId; + + @ExcelProperty(value = "业务类型", converter = DictConvert.class) + @DictFormat("biz_type") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String bizType; + + @ExcelProperty("1增加 0扣减") + private String type; + + @ExcelProperty("积分标题") + private String title; + + @ExcelProperty("积分描述") + private String description; + + @ExcelProperty("积分") + private Integer point; + + @ExcelProperty("变动后的积分") + private Integer totalPoint; + + @ExcelProperty(value = "状态:1-订单创建,2-冻结期,3-完成,4-失效(订单退款) ", converter = DictConvert.class) + @DictFormat("point_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private Integer status; + + @ExcelProperty("用户id") + private Integer userId; + + @ExcelProperty("冻结时间") + private LocalDateTime freezingTime; + + @ExcelProperty("解冻时间") + private LocalDateTime thawingTime; + + @ExcelProperty("发生时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExportReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExportReqVO.java new file mode 100644 index 000000000..d57ade55a --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordExportReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +@Schema(description = "管理后台 - 用户积分记录 Excel 导出 Request VO,参数和 PointRecordPageReqVO 是一致的") +@Data +public class PointRecordExportReqVO { + + @Schema(description = "业务编码", example = "22706") + private String bizId; + + @Schema(description = "业务类型", example = "1") + private String bizType; + + @Schema(description = "1增加 0扣减", example = "1") + private String type; + + @Schema(description = "积分标题") + private String title; + + @Schema(description = "状态:1-订单创建,2-冻结期,3-完成,4-失效(订单退款) ", example = "1") + private Integer status; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordPageReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordPageReqVO.java new file mode 100644 index 000000000..b4570c618 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordPageReqVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +@Schema(description = "管理后台 - 用户积分记录分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointRecordPageReqVO extends PageParam { + + @Schema(description = "业务编码", example = "22706") + private String bizId; + + @Schema(description = "业务类型", example = "1") + private String bizType; + + @Schema(description = "1增加 0扣减", example = "1") + private String type; + + @Schema(description = "积分标题") + private String title; + + @Schema(description = "状态:1-订单创建,2-冻结期,3-完成,4-失效(订单退款) ", example = "1") + private Integer status; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordRespVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordRespVO.java new file mode 100644 index 000000000..d40dee6ee --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 用户积分记录 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointRecordRespVO extends PointRecordBaseVO { + + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "31457") + private Long id; + + @Schema(description = "发生时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordUpdateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordUpdateReqVO.java new file mode 100644 index 000000000..d053e0a0e --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointrecord/vo/PointRecordUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户积分记录更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PointRecordUpdateReqVO extends PointRecordBaseVO { + + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "31457") + @NotNull(message = "自增主键不能为空") + private Long id; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/SignInConfigController.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/SignInConfigController.java new file mode 100644 index 000000000..2ca25dd5a --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/SignInConfigController.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinconfig.SignInConfigDO; +import cn.iocoder.yudao.module.point.convert.signinconfig.SignInConfigConvert; +import cn.iocoder.yudao.module.point.service.signinconfig.SignInConfigService; + +@Tag(name = "管理后台 - 积分签到规则") +@RestController +@RequestMapping("/point/sign-in-config") +@Validated +public class SignInConfigController { + + @Resource + private SignInConfigService signInConfigService; + + @PostMapping("/create") + @Operation(summary = "创建积分签到规则") + @PreAuthorize("@ss.hasPermission('point:sign-in-config:create')") + public CommonResult createSignInConfig(@Valid @RequestBody SignInConfigCreateReqVO createReqVO) { + return success(signInConfigService.createSignInConfig(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新积分签到规则") + @PreAuthorize("@ss.hasPermission('point:sign-in-config:update')") + public CommonResult updateSignInConfig(@Valid @RequestBody SignInConfigUpdateReqVO updateReqVO) { + signInConfigService.updateSignInConfig(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除积分签到规则") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('point:sign-in-config:delete')") + public CommonResult deleteSignInConfig(@RequestParam("id") Integer id) { + signInConfigService.deleteSignInConfig(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得积分签到规则") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('point:sign-in-config:query')") + public CommonResult getSignInConfig(@RequestParam("id") Integer id) { + SignInConfigDO signInConfig = signInConfigService.getSignInConfig(id); + return success(SignInConfigConvert.INSTANCE.convert(signInConfig)); + } + + @GetMapping("/list") + @Operation(summary = "获得积分签到规则列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('point:sign-in-config:query')") + public CommonResult> getSignInConfigList(@RequestParam("ids") Collection ids) { + List list = signInConfigService.getSignInConfigList(ids); + return success(SignInConfigConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得积分签到规则分页") + @PreAuthorize("@ss.hasPermission('point:sign-in-config:query')") + public CommonResult> getSignInConfigPage(@Valid SignInConfigPageReqVO pageVO) { + PageResult pageResult = signInConfigService.getSignInConfigPage(pageVO); + return success(SignInConfigConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出积分签到规则 Excel") + @PreAuthorize("@ss.hasPermission('point:sign-in-config:export')") + @OperateLog(type = EXPORT) + public void exportSignInConfigExcel(@Valid SignInConfigExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = signInConfigService.getSignInConfigList(exportReqVO); + // 导出 Excel + List datas = SignInConfigConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "积分签到规则.xls", "数据", SignInConfigExcelVO.class, datas); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigBaseVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigBaseVO.java new file mode 100644 index 000000000..4c2160dde --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigBaseVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import javax.validation.constraints.*; + +/** + * 积分签到规则 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class SignInConfigBaseVO { + + @Schema(description = "签到第x天", example = "7") + private Integer day; + + @Schema(description = "签到天数对应分数", example = "10") + private Integer point; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigCreateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigCreateReqVO.java new file mode 100644 index 000000000..39098c192 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 积分签到规则创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInConfigCreateReqVO extends SignInConfigBaseVO { + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExcelVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExcelVO.java new file mode 100644 index 000000000..8d066f2ae --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExcelVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 积分签到规则 Excel VO + * + * @author QingX + */ +@Data +public class SignInConfigExcelVO { + + @ExcelProperty("签到第x天") + private Integer day; + + @ExcelProperty("签到天数对应分数") + private Integer point; + + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExportReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExportReqVO.java new file mode 100644 index 000000000..473fe1153 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigExportReqVO.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +@Schema(description = "管理后台 - 积分签到规则 Excel 导出 Request VO,参数和 SignInConfigPageReqVO 是一致的") +@Data +public class SignInConfigExportReqVO { + + @Schema(description = "签到第x天", example = "7") + private Integer day; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigPageReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigPageReqVO.java new file mode 100644 index 000000000..892d1f2e8 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigPageReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +@Schema(description = "管理后台 - 积分签到规则分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInConfigPageReqVO extends PageParam { + + @Schema(description = "签到第x天", example = "7") + private Integer day; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigRespVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigRespVO.java new file mode 100644 index 000000000..a78816c3f --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 积分签到规则 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInConfigRespVO extends SignInConfigBaseVO { + + @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20937") + private Integer id; + + @Schema(description = "创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigUpdateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigUpdateReqVO.java new file mode 100644 index 000000000..cf6c788e1 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinconfig/vo/SignInConfigUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 积分签到规则更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInConfigUpdateReqVO extends SignInConfigBaseVO { + + @Schema(description = "规则自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "13653") + @NotNull(message = "规则自增主键不能为空") + private Integer id; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/SignInRecordController.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/SignInRecordController.java new file mode 100644 index 000000000..a2a639c5d --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/SignInRecordController.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinrecord.SignInRecordDO; +import cn.iocoder.yudao.module.point.convert.signinrecord.SignInRecordConvert; +import cn.iocoder.yudao.module.point.service.signinrecord.SignInRecordService; + +@Tag(name = "管理后台 - 用户签到积分") +@RestController +@RequestMapping("/point/sign-in-record") +@Validated +public class SignInRecordController { + + @Resource + private SignInRecordService signInRecordService; + + @PostMapping("/create") + @Operation(summary = "创建用户签到积分") + @PreAuthorize("@ss.hasPermission('point:sign-in-record:create')") + public CommonResult createSignInRecord(@Valid @RequestBody SignInRecordCreateReqVO createReqVO) { + return success(signInRecordService.createSignInRecord(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新用户签到积分") + @PreAuthorize("@ss.hasPermission('point:sign-in-record:update')") + public CommonResult updateSignInRecord(@Valid @RequestBody SignInRecordUpdateReqVO updateReqVO) { + signInRecordService.updateSignInRecord(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除用户签到积分") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('point:sign-in-record:delete')") + public CommonResult deleteSignInRecord(@RequestParam("id") Long id) { + signInRecordService.deleteSignInRecord(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得用户签到积分") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('point:sign-in-record:query')") + public CommonResult getSignInRecord(@RequestParam("id") Long id) { + SignInRecordDO signInRecord = signInRecordService.getSignInRecord(id); + return success(SignInRecordConvert.INSTANCE.convert(signInRecord)); + } + + @GetMapping("/list") + @Operation(summary = "获得用户签到积分列表") + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") + @PreAuthorize("@ss.hasPermission('point:sign-in-record:query')") + public CommonResult> getSignInRecordList(@RequestParam("ids") Collection ids) { + List list = signInRecordService.getSignInRecordList(ids); + return success(SignInRecordConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得用户签到积分分页") + @PreAuthorize("@ss.hasPermission('point:sign-in-record:query')") + public CommonResult> getSignInRecordPage(@Valid SignInRecordPageReqVO pageVO) { + PageResult pageResult = signInRecordService.getSignInRecordPage(pageVO); + return success(SignInRecordConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出用户签到积分 Excel") + @PreAuthorize("@ss.hasPermission('point:sign-in-record:export')") + @OperateLog(type = EXPORT) + public void exportSignInRecordExcel(@Valid SignInRecordExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = signInRecordService.getSignInRecordList(exportReqVO); + // 导出 Excel + List datas = SignInRecordConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "用户签到积分.xls", "数据", SignInRecordExcelVO.class, datas); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordBaseVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordBaseVO.java new file mode 100644 index 000000000..9cefa4a18 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordBaseVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import javax.validation.constraints.*; + +/** + * 用户签到积分 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class SignInRecordBaseVO { + + @Schema(description = "签到用户", example = "6507") + private Integer userId; + + @Schema(description = "第几天签到") + private Integer day; + + @Schema(description = "签到的分数") + private Integer point; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordCreateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordCreateReqVO.java new file mode 100644 index 000000000..9635b3076 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户签到积分创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInRecordCreateReqVO extends SignInRecordBaseVO { + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExcelVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExcelVO.java new file mode 100644 index 000000000..de9ebf605 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExcelVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 用户签到积分 Excel VO + * + * @author 芋道源码 + */ +@Data +public class SignInRecordExcelVO { + + @ExcelProperty("签到自增id") + private Long id; + + @ExcelProperty("签到用户") + private Integer userId; + + @ExcelProperty("第几天签到") + private Integer day; + + @ExcelProperty("签到的分数") + private Integer point; + + @ExcelProperty("签到时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExportReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExportReqVO.java new file mode 100644 index 000000000..673042306 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordExportReqVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import java.time.LocalDateTime; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户签到积分 Excel 导出 Request VO,参数和 SignInRecordPageReqVO 是一致的") +@Data +public class SignInRecordExportReqVO { + + @Schema(description = "签到用户", example = "6507") + private Integer userId; + + @Schema(description = "第几天签到") + private Integer day; + + @Schema(description = "签到时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordPageReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordPageReqVO.java new file mode 100644 index 000000000..49218aafa --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordPageReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 用户签到积分分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInRecordPageReqVO extends PageParam { + + @Schema(description = "签到用户", example = "6507") + private Integer userId; + + @Schema(description = "第几天签到") + private Integer day; + + @Schema(description = "签到时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordRespVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordRespVO.java new file mode 100644 index 000000000..d4180d1b1 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 用户签到积分 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInRecordRespVO extends SignInRecordBaseVO { + + @Schema(description = "签到自增id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11903") + private Long id; + + @Schema(description = "签到时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordUpdateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordUpdateReqVO.java new file mode 100644 index 000000000..81392d088 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/signinrecord/vo/SignInRecordUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 用户签到积分更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SignInRecordUpdateReqVO extends SignInRecordBaseVO { + + @Schema(description = "签到自增id", requiredMode = Schema.RequiredMode.REQUIRED, example = "11903") + @NotNull(message = "签到自增id不能为空") + private Long id; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java new file mode 100644 index 000000000..56b96cf75 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.point.convert.pointconfig; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; + +/** + * 积分设置 Convert + * + * @author QingX + */ +@Mapper +public interface PointConfigConvert { + + PointConfigConvert INSTANCE = Mappers.getMapper(PointConfigConvert.class); + + PointConfigDO convert(PointConfigCreateReqVO bean); + + PointConfigDO convert(PointConfigUpdateReqVO bean); + + PointConfigRespVO convert(PointConfigDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointrecord/PointRecordConvert.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointrecord/PointRecordConvert.java new file mode 100644 index 000000000..556c154f8 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointrecord/PointRecordConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.point.convert.pointrecord; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointrecord.PointRecordDO; + +/** + * 用户积分记录 Convert + * + * @author QingX + */ +@Mapper +public interface PointRecordConvert { + + PointRecordConvert INSTANCE = Mappers.getMapper(PointRecordConvert.class); + + PointRecordDO convert(PointRecordCreateReqVO bean); + + PointRecordDO convert(PointRecordUpdateReqVO bean); + + PointRecordRespVO convert(PointRecordDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinconfig/SignInConfigConvert.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinconfig/SignInConfigConvert.java new file mode 100644 index 000000000..a602fd399 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinconfig/SignInConfigConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.point.convert.signinconfig; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinconfig.SignInConfigDO; + +/** + * 积分签到规则 Convert + * + * @author QingX + */ +@Mapper +public interface SignInConfigConvert { + + SignInConfigConvert INSTANCE = Mappers.getMapper(SignInConfigConvert.class); + + SignInConfigDO convert(SignInConfigCreateReqVO bean); + + SignInConfigDO convert(SignInConfigUpdateReqVO bean); + + SignInConfigRespVO convert(SignInConfigDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinrecord/SignInRecordConvert.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinrecord/SignInRecordConvert.java new file mode 100644 index 000000000..6c3b434cb --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/signinrecord/SignInRecordConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.point.convert.signinrecord; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinrecord.SignInRecordDO; + +/** + * 用户签到积分 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface SignInRecordConvert { + + SignInRecordConvert INSTANCE = Mappers.getMapper(SignInRecordConvert.class); + + SignInRecordDO convert(SignInRecordCreateReqVO bean); + + SignInRecordDO convert(SignInRecordUpdateReqVO bean); + + SignInRecordRespVO convert(SignInRecordDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java new file mode 100644 index 000000000..ee30a27d1 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.point.dal.dataobject.pointconfig; + +import lombok.*; +import java.util.*; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 积分设置 DO + * + * @author QingX + */ +@TableName("member_point_config") +@KeySequence("member_point_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PointConfigDO extends BaseDO { + + /** + * 自增主键 + */ + @TableId + private Integer id; + /** + * 1 开启积分抵扣 +0 关闭积分抵扣 + * + * 枚举 {@link TODO infra_boolean_string 对应的类} + */ + private Integer tradeDeductEnable; + /** + * 积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元) + */ + private BigDecimal tradeDeductUnitPrice; + /** + * 积分抵扣最大值 + */ + private Long tradeDeductMaxPrice; + /** + * 1元赠送多少分 + */ + private Long tradeGivePoint; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointrecord/PointRecordDO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointrecord/PointRecordDO.java new file mode 100644 index 000000000..74197e70d --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointrecord/PointRecordDO.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.point.dal.dataobject.pointrecord; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 用户积分记录 DO + * + * @author QingX + */ +@TableName("member_point_record") +@KeySequence("member_point_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PointRecordDO extends BaseDO { + + /** + * 自增主键 + */ + @TableId + private Long id; + /** + * 业务编码 + */ + private String bizId; + /** + * 业务类型 + * + * 枚举 {@link TODO biz_type 对应的类} + */ + private String bizType; + /** + * 1增加 0扣减 + */ + private String type; + /** + * 积分标题 + */ + private String title; + /** + * 积分描述 + */ + private String description; + /** + * 积分 + */ + private Integer point; + /** + * 变动后的积分 + */ + private Integer totalPoint; + /** + * 状态:1-订单创建,2-冻结期,3-完成,4-失效(订单退款) + + * + * 枚举 {@link TODO point_status 对应的类} + */ + private Integer status; + /** + * 用户id + */ + private Integer userId; + /** + * 冻结时间 + */ + private LocalDateTime freezingTime; + /** + * 解冻时间 + */ + private LocalDateTime thawingTime; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinconfig/SignInConfigDO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinconfig/SignInConfigDO.java new file mode 100644 index 000000000..9eb07c929 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinconfig/SignInConfigDO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.point.dal.dataobject.signinconfig; + +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 QingX + */ +@TableName("member_sign_in_config") +@KeySequence("member_sign_in_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SignInConfigDO extends BaseDO { + + /** + * 规则自增主键 + */ + @TableId + private Integer id; + /** + * 签到第x天 + */ + private Integer day; + /** + * 签到天数对应分数 + */ + private Integer point; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinrecord/SignInRecordDO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinrecord/SignInRecordDO.java new file mode 100644 index 000000000..d75a852d3 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/signinrecord/SignInRecordDO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.point.dal.dataobject.signinrecord; + +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("member_sign_in_record") +@KeySequence("member_sign_in_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SignInRecordDO extends BaseDO { + + /** + * 签到自增id + */ + @TableId + private Long id; + /** + * 签到用户 + */ + private Integer userId; + /** + * 第几天签到 + */ + private Integer day; + /** + * 签到的分数 + */ + private Integer point; + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java new file mode 100644 index 000000000..5d11f9b5b --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.point.dal.mysql.pointconfig; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; + +/** + * 积分设置 Mapper + * + * @author QingX + */ +@Mapper +public interface PointConfigMapper extends BaseMapperX { + + default PageResult selectPage(PointConfigPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(PointConfigDO::getTradeDeductEnable, reqVO.getTradeDeductEnable()) + .orderByDesc(PointConfigDO::getId)); + } + + default List selectList(PointConfigExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(PointConfigDO::getTradeDeductEnable, reqVO.getTradeDeductEnable()) + .orderByDesc(PointConfigDO::getId)); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointrecord/PointRecordMapper.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointrecord/PointRecordMapper.java new file mode 100644 index 000000000..005056a30 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointrecord/PointRecordMapper.java @@ -0,0 +1,40 @@ +package cn.iocoder.yudao.module.point.dal.mysql.pointrecord; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.point.dal.dataobject.pointrecord.PointRecordDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo.*; + +/** + * 用户积分记录 Mapper + * + * @author QingX + */ +@Mapper +public interface PointRecordMapper extends BaseMapperX { + + default PageResult selectPage(PointRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(PointRecordDO::getBizId, reqVO.getBizId()) + .eqIfPresent(PointRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(PointRecordDO::getType, reqVO.getType()) + .eqIfPresent(PointRecordDO::getTitle, reqVO.getTitle()) + .eqIfPresent(PointRecordDO::getStatus, reqVO.getStatus()) + .orderByDesc(PointRecordDO::getId)); + } + + default List selectList(PointRecordExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(PointRecordDO::getBizId, reqVO.getBizId()) + .eqIfPresent(PointRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(PointRecordDO::getType, reqVO.getType()) + .eqIfPresent(PointRecordDO::getTitle, reqVO.getTitle()) + .eqIfPresent(PointRecordDO::getStatus, reqVO.getStatus()) + .orderByDesc(PointRecordDO::getId)); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinconfig/SignInConfigMapper.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinconfig/SignInConfigMapper.java new file mode 100644 index 000000000..6188d3fef --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinconfig/SignInConfigMapper.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.point.dal.mysql.signinconfig; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.module.point.dal.dataobject.signinconfig.SignInConfigDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo.*; + +/** + * 积分签到规则 Mapper + * + * @author QingX + */ +@Mapper +public interface SignInConfigMapper extends BaseMapperX { + + default PageResult selectPage(SignInConfigPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(SignInConfigDO::getDay, reqVO.getDay()) + .orderByAsc(SignInConfigDO::getDay)); + } + + default List selectList(SignInConfigExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(SignInConfigDO::getDay, reqVO.getDay()) + .orderByDesc(SignInConfigDO::getId)); + } + + // + default long selectSameDayNotSelf(SignInConfigUpdateReqVO reqVO){ + return selectCount(new LambdaQueryWrapperX () + .ne(SignInConfigDO::getId, reqVO.getId()) + .eq(SignInConfigDO::getDay,reqVO.getDay()) + ); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinrecord/SignInRecordMapper.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinrecord/SignInRecordMapper.java new file mode 100644 index 000000000..9d0c1c6eb --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/signinrecord/SignInRecordMapper.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.point.dal.mysql.signinrecord; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.point.dal.dataobject.signinrecord.SignInRecordDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo.*; + +/** + * 用户签到积分 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface SignInRecordMapper extends BaseMapperX { + + default PageResult selectPage(SignInRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(SignInRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(SignInRecordDO::getDay, reqVO.getDay()) + .betweenIfPresent(SignInRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SignInRecordDO::getId)); + } + + default List selectList(SignInRecordExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(SignInRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(SignInRecordDO::getDay, reqVO.getDay()) + .betweenIfPresent(SignInRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(SignInRecordDO::getId)); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java new file mode 100644 index 000000000..d579b7b9d --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.point.service.pointconfig; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 积分设置 Service 接口 + * + * @author QingX + */ +public interface PointConfigService { + + /** + * 创建积分设置 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createConfig(@Valid PointConfigCreateReqVO createReqVO); + + /** + * 更新积分设置 + * + * @param updateReqVO 更新信息 + */ + void updateConfig(@Valid PointConfigUpdateReqVO updateReqVO); + + /** + * 删除积分设置 + * + * @param id 编号 + */ + void deleteConfig(Integer id); + + /** + * 获得积分设置 + * + * @param id 编号 + * @return 积分设置 + */ + PointConfigDO getConfig(Integer id); + + /** + * 获得积分设置列表 + * + * @param ids 编号 + * @return 积分设置列表 + */ + List getConfigList(Collection ids); + + /** + * 获得积分设置分页 + * + * @param pageReqVO 分页查询 + * @return 积分设置分页 + */ + PageResult getConfigPage(PointConfigPageReqVO pageReqVO); + + /** + * 获得积分设置列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 积分设置列表 + */ + List getConfigList(PointConfigExportReqVO exportReqVO); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java new file mode 100644 index 000000000..5cc8185d8 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java @@ -0,0 +1,92 @@ +package cn.iocoder.yudao.module.point.service.pointconfig; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.point.convert.pointconfig.PointConfigConvert; +import cn.iocoder.yudao.module.point.dal.mysql.pointconfig.PointConfigMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; + +/** + * 积分设置 Service 实现类 + * + * @author QingX + */ +@Service +@Validated +public class PointConfigServiceImpl implements PointConfigService { + + @Autowired + private PointConfigMapper configMapper; + + @Override + public Integer createConfig(PointConfigCreateReqVO createReqVO) { + // 插入 + PointConfigDO config = PointConfigConvert.INSTANCE.convert(createReqVO); + //每个租户只允许存在一条记录 + validateConfigExistsOne(); + + configMapper.insert(config); + // 返回 + return config.getId(); + } + + @Override + public void updateConfig(PointConfigUpdateReqVO updateReqVO) { + // 校验存在 + validateConfigExists(updateReqVO.getId()); + // 更新 + PointConfigDO updateObj = PointConfigConvert.INSTANCE.convert(updateReqVO); + configMapper.updateById(updateObj); + } + + @Override + public void deleteConfig(Integer id) { + // 校验存在 + validateConfigExists(id); + // 删除 + configMapper.deleteById(id); + } + + private void validateConfigExists(Integer id) { + if (configMapper.selectById(id) == null) { + throw exception(CONFIG_NOT_EXISTS); + } + } + + private void validateConfigExistsOne() { + if (configMapper.selectCount() > 0) { + throw exception(CONFIG_EXISTS); + } + } + + @Override + public PointConfigDO getConfig(Integer id) { + return configMapper.selectById(id); + } + + @Override + public List getConfigList(Collection ids) { + return configMapper.selectBatchIds(ids); + } + + @Override + public PageResult getConfigPage(PointConfigPageReqVO pageReqVO) { + return configMapper.selectPage(pageReqVO); + } + + @Override + public List getConfigList(PointConfigExportReqVO exportReqVO) { + return configMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordService.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordService.java new file mode 100644 index 000000000..99833ff8d --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.point.service.pointrecord; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointrecord.PointRecordDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 用户积分记录 Service 接口 + * + * @author QingX + */ +public interface PointRecordService { + + /** + * 创建用户积分记录 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createRecord(@Valid PointRecordCreateReqVO createReqVO); + + /** + * 更新用户积分记录 + * + * @param updateReqVO 更新信息 + */ + void updateRecord(@Valid PointRecordUpdateReqVO updateReqVO); + + /** + * 删除用户积分记录 + * + * @param id 编号 + */ + void deleteRecord(Long id); + + /** + * 获得用户积分记录 + * + * @param id 编号 + * @return 用户积分记录 + */ + PointRecordDO getRecord(Long id); + + /** + * 获得用户积分记录列表 + * + * @param ids 编号 + * @return 用户积分记录列表 + */ + List getRecordList(Collection ids); + + /** + * 获得用户积分记录分页 + * + * @param pageReqVO 分页查询 + * @return 用户积分记录分页 + */ + PageResult getRecordPage(PointRecordPageReqVO pageReqVO); + + /** + * 获得用户积分记录列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 用户积分记录列表 + */ + List getRecordList(PointRecordExportReqVO exportReqVO); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImpl.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImpl.java new file mode 100644 index 000000000..a2c0d1ab9 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.point.service.pointrecord; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointrecord.PointRecordDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.point.convert.pointrecord.PointRecordConvert; +import cn.iocoder.yudao.module.point.dal.mysql.pointrecord.PointRecordMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; + +/** + * 用户积分记录 Service 实现类 + * + * @author QingX + */ +@Service +@Validated +public class PointRecordServiceImpl implements PointRecordService { + + @Resource + private PointRecordMapper recordMapper; + + @Override + public Long createRecord(PointRecordCreateReqVO createReqVO) { + // 插入 + PointRecordDO record = PointRecordConvert.INSTANCE.convert(createReqVO); + recordMapper.insert(record); + // 返回 + return record.getId(); + } + + @Override + public void updateRecord(PointRecordUpdateReqVO updateReqVO) { + // 校验存在 + validateRecordExists(updateReqVO.getId()); + // 更新 + PointRecordDO updateObj = PointRecordConvert.INSTANCE.convert(updateReqVO); + recordMapper.updateById(updateObj); + } + + @Override + public void deleteRecord(Long id) { + // 校验存在 + validateRecordExists(id); + // 删除 + recordMapper.deleteById(id); + } + + private void validateRecordExists(Long id) { + if (recordMapper.selectById(id) == null) { + throw exception(RECORD_NOT_EXISTS); + } + } + + @Override + public PointRecordDO getRecord(Long id) { + return recordMapper.selectById(id); + } + + @Override + public List getRecordList(Collection ids) { + return recordMapper.selectBatchIds(ids); + } + + @Override + public PageResult getRecordPage(PointRecordPageReqVO pageReqVO) { + return recordMapper.selectPage(pageReqVO); + } + + @Override + public List getRecordList(PointRecordExportReqVO exportReqVO) { + return recordMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigService.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigService.java new file mode 100644 index 000000000..486f08f49 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.point.service.signinconfig; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinconfig.SignInConfigDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 积分签到规则 Service 接口 + * + * @author QingX + */ +public interface SignInConfigService { + + /** + * 创建积分签到规则 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createSignInConfig(@Valid SignInConfigCreateReqVO createReqVO); + + /** + * 更新积分签到规则 + * + * @param updateReqVO 更新信息 + */ + void updateSignInConfig(@Valid SignInConfigUpdateReqVO updateReqVO); + + /** + * 删除积分签到规则 + * + * @param id 编号 + */ + void deleteSignInConfig(Integer id); + + /** + * 获得积分签到规则 + * + * @param id 编号 + * @return 积分签到规则 + */ + SignInConfigDO getSignInConfig(Integer id); + + /** + * 获得积分签到规则列表 + * + * @param ids 编号 + * @return 积分签到规则列表 + */ + List getSignInConfigList(Collection ids); + + /** + * 获得积分签到规则分页 + * + * @param pageReqVO 分页查询 + * @return 积分签到规则分页 + */ + PageResult getSignInConfigPage(SignInConfigPageReqVO pageReqVO); + + /** + * 获得积分签到规则列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 积分签到规则列表 + */ + List getSignInConfigList(SignInConfigExportReqVO exportReqVO); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImpl.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImpl.java new file mode 100644 index 000000000..ac4947ddc --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImpl.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.point.service.signinconfig; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinconfig.SignInConfigDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.point.convert.signinconfig.SignInConfigConvert; +import cn.iocoder.yudao.module.point.dal.mysql.signinconfig.SignInConfigMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; + +/** + * 积分签到规则 Service 实现类 + * + * @author QingX + */ +@Service +@Validated +public class SignInConfigServiceImpl implements SignInConfigService { + + @Resource + private SignInConfigMapper signInConfigMapper; + + @Override + public Integer createSignInConfig(SignInConfigCreateReqVO createReqVO) { + // 插入 + SignInConfigDO signInConfig = SignInConfigConvert.INSTANCE.convert(createReqVO); + //判断是否重复插入签到天数 + validateSignInConfigExistsDay(signInConfig.getDay()); + signInConfigMapper.insert(signInConfig); + // 返回 + return signInConfig.getId(); + } + + @Override + public void updateSignInConfig(SignInConfigUpdateReqVO updateReqVO) { + // 校验存在 + validateSignInConfigExists(updateReqVO.getId()); + //判断是否重复插入签到天数 + validateSignInConfigSameDayNotSelf(updateReqVO); + // 判断更新的 + SignInConfigDO updateObj = SignInConfigConvert.INSTANCE.convert(updateReqVO); + + + signInConfigMapper.updateById(updateObj); + } + + @Override + public void deleteSignInConfig(Integer id) { + // 校验存在 + validateSignInConfigExists(id); + // 删除 + signInConfigMapper.deleteById(id); + } + + private void validateSignInConfigExists(Integer id) { + if (signInConfigMapper.selectById(id) == null) { + throw exception(SIGN_IN_CONFIG_NOT_EXISTS); + } + } + //根据签到天数判断是否存在一个相同的天数 + private void validateSignInConfigExistsDay(Integer day) { + if (signInConfigMapper.selectCount(SignInConfigDO::getDay,day)>0) { + throw exception(SIGN_IN_CONFIG_EXISTS); + } + } + + //更新天数时判断是否有重复的天数,需要去除自己 + private void validateSignInConfigSameDayNotSelf(SignInConfigUpdateReqVO reqVO) { + if (signInConfigMapper.selectSameDayNotSelf(reqVO)>0) { + throw exception(SIGN_IN_CONFIG_EXISTS); + } + } + + + @Override + public SignInConfigDO getSignInConfig(Integer id) { + return signInConfigMapper.selectById(id); + } + + @Override + public List getSignInConfigList(Collection ids) { + return signInConfigMapper.selectBatchIds(ids); + } + + @Override + public PageResult getSignInConfigPage(SignInConfigPageReqVO pageReqVO) { + return signInConfigMapper.selectPage(pageReqVO); + } + + @Override + public List getSignInConfigList(SignInConfigExportReqVO exportReqVO) { + return signInConfigMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordService.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordService.java new file mode 100644 index 000000000..8910eec7f --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.point.service.signinrecord; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinrecord.SignInRecordDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 用户签到积分 Service 接口 + * + * @author 芋道源码 + */ +public interface SignInRecordService { + + /** + * 创建用户签到积分 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createSignInRecord(@Valid SignInRecordCreateReqVO createReqVO); + + /** + * 更新用户签到积分 + * + * @param updateReqVO 更新信息 + */ + void updateSignInRecord(@Valid SignInRecordUpdateReqVO updateReqVO); + + /** + * 删除用户签到积分 + * + * @param id 编号 + */ + void deleteSignInRecord(Long id); + + /** + * 获得用户签到积分 + * + * @param id 编号 + * @return 用户签到积分 + */ + SignInRecordDO getSignInRecord(Long id); + + /** + * 获得用户签到积分列表 + * + * @param ids 编号 + * @return 用户签到积分列表 + */ + List getSignInRecordList(Collection ids); + + /** + * 获得用户签到积分分页 + * + * @param pageReqVO 分页查询 + * @return 用户签到积分分页 + */ + PageResult getSignInRecordPage(SignInRecordPageReqVO pageReqVO); + + /** + * 获得用户签到积分列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 用户签到积分列表 + */ + List getSignInRecordList(SignInRecordExportReqVO exportReqVO); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImpl.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImpl.java new file mode 100644 index 000000000..00ff4967e --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.point.service.signinrecord; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinrecord.SignInRecordDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.point.convert.signinrecord.SignInRecordConvert; +import cn.iocoder.yudao.module.point.dal.mysql.signinrecord.SignInRecordMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; + +/** + * 用户签到积分 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class SignInRecordServiceImpl implements SignInRecordService { + + @Resource + private SignInRecordMapper signInRecordMapper; + + @Override + public Long createSignInRecord(SignInRecordCreateReqVO createReqVO) { + // 插入 + SignInRecordDO signInRecord = SignInRecordConvert.INSTANCE.convert(createReqVO); + signInRecordMapper.insert(signInRecord); + // 返回 + return signInRecord.getId(); + } + + @Override + public void updateSignInRecord(SignInRecordUpdateReqVO updateReqVO) { + // 校验存在 + validateSignInRecordExists(updateReqVO.getId()); + // 更新 + SignInRecordDO updateObj = SignInRecordConvert.INSTANCE.convert(updateReqVO); + signInRecordMapper.updateById(updateObj); + } + + @Override + public void deleteSignInRecord(Long id) { + // 校验存在 + validateSignInRecordExists(id); + // 删除 + signInRecordMapper.deleteById(id); + } + + private void validateSignInRecordExists(Long id) { + if (signInRecordMapper.selectById(id) == null) { + throw exception(SIGN_IN_RECORD_NOT_EXISTS); + } + } + + @Override + public SignInRecordDO getSignInRecord(Long id) { + return signInRecordMapper.selectById(id); + } + + @Override + public List getSignInRecordList(Collection ids) { + return signInRecordMapper.selectBatchIds(ids); + } + + @Override + public PageResult getSignInRecordPage(SignInRecordPageReqVO pageReqVO) { + return signInRecordMapper.selectPage(pageReqVO); + } + + @Override + public List getSignInRecordList(SignInRecordExportReqVO exportReqVO) { + return signInRecordMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml new file mode 100644 index 000000000..963afd6c8 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml new file mode 100644 index 000000000..cc09cce4b --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml new file mode 100644 index 000000000..2e665c01a --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml new file mode 100644 index 000000000..bd9d58976 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImplTest.java b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImplTest.java new file mode 100644 index 000000000..d012d03fe --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImplTest.java @@ -0,0 +1,152 @@ +package cn.iocoder.yudao.module.point.service.pointconfig; + +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; +import cn.iocoder.yudao.module.point.dal.mysql.pointconfig.PointConfigMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; +import java.time.LocalDateTime; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * {@link PointConfigServiceImpl} 的单元测试类 + * + * @author QingX + */ +@Import(PointConfigServiceImpl.class) +public class PointConfigServiceImplTest extends BaseDbUnitTest { + + @Resource + private PointConfigServiceImpl configService; + + @Resource + private PointConfigMapper configMapper; + + @Test + public void testCreateConfig_success() { + // 准备参数 + PointConfigCreateReqVO reqVO = randomPojo(PointConfigCreateReqVO.class); + + // 调用 + Integer configId = configService.createConfig(reqVO); + // 断言 + assertNotNull(configId); + // 校验记录的属性是否正确 + PointConfigDO config = configMapper.selectById(configId); + assertPojoEquals(reqVO, config); + } + + @Test + public void testUpdateConfig_success() { + // mock 数据 + PointConfigDO dbConfig = randomPojo(PointConfigDO.class); + configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 + // 准备参数 + PointConfigUpdateReqVO reqVO = randomPojo(PointConfigUpdateReqVO.class, o -> { + o.setId(dbConfig.getId()); // 设置更新的 ID + }); + + // 调用 + configService.updateConfig(reqVO); + // 校验是否更新正确 + PointConfigDO config = configMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, config); + } + + @Test + public void testUpdateConfig_notExists() { + // 准备参数 + PointConfigUpdateReqVO reqVO = randomPojo(PointConfigUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> configService.updateConfig(reqVO), CONFIG_NOT_EXISTS); + } + + @Test + public void testDeleteConfig_success() { + // mock 数据 + PointConfigDO dbConfig = randomPojo(PointConfigDO.class); + configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Integer id = dbConfig.getId(); + + // 调用 + configService.deleteConfig(id); + // 校验数据不存在了 + assertNull(configMapper.selectById(id)); + } + + @Test + public void testDeleteConfig_notExists() { + // 准备参数 + Integer id = RandomUtils.randomInteger(); + + // 调用, 并断言异常 + assertServiceException(() -> configService.deleteConfig(id), CONFIG_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetConfigPage() { + // mock 数据 + PointConfigDO dbConfig = randomPojo(PointConfigDO.class, o -> { // 等会查询到 + o.setTradeDeductEnable(null); + }); + configMapper.insert(dbConfig); + // 测试 tradeDeductEnable 不匹配 + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setTradeDeductEnable(null))); + // 准备参数 + PointConfigPageReqVO reqVO = new PointConfigPageReqVO(); + reqVO.setTradeDeductEnable(null); + + // 调用 + PageResult pageResult = configService.getConfigPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbConfig, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetConfigList() { + // mock 数据 + PointConfigDO dbConfig = randomPojo(PointConfigDO.class, o -> { // 等会查询到 + o.setTradeDeductEnable(null); + }); + configMapper.insert(dbConfig); + // 测试 tradeDeductEnable 不匹配 + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setTradeDeductEnable(null))); + // 准备参数 + PointConfigExportReqVO reqVO = new PointConfigExportReqVO(); + reqVO.setTradeDeductEnable(null); + + // 调用 + List list = configService.getConfigList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbConfig, list.get(0)); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImplTest.java b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImplTest.java new file mode 100644 index 000000000..32a7740f0 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/pointrecord/PointRecordServiceImplTest.java @@ -0,0 +1,183 @@ +package cn.iocoder.yudao.module.point.service.pointrecord; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.point.controller.admin.pointrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.pointrecord.PointRecordDO; +import cn.iocoder.yudao.module.point.dal.mysql.pointrecord.PointRecordMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; +import java.time.LocalDateTime; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * {@link PointRecordServiceImpl} 的单元测试类 + * + * @author QingX + */ +@Import(PointRecordServiceImpl.class) +public class PointRecordServiceImplTest extends BaseDbUnitTest { + + @Resource + private PointRecordServiceImpl recordService; + + @Resource + private PointRecordMapper recordMapper; + + @Test + public void testCreateRecord_success() { + // 准备参数 + PointRecordCreateReqVO reqVO = randomPojo(PointRecordCreateReqVO.class); + + // 调用 + Long recordId = recordService.createRecord(reqVO); + // 断言 + assertNotNull(recordId); + // 校验记录的属性是否正确 + PointRecordDO record = recordMapper.selectById(recordId); + assertPojoEquals(reqVO, record); + } + + @Test + public void testUpdateRecord_success() { + // mock 数据 + PointRecordDO dbRecord = randomPojo(PointRecordDO.class); + recordMapper.insert(dbRecord);// @Sql: 先插入出一条存在的数据 + // 准备参数 + PointRecordUpdateReqVO reqVO = randomPojo(PointRecordUpdateReqVO.class, o -> { + o.setId(dbRecord.getId()); // 设置更新的 ID + }); + + // 调用 + recordService.updateRecord(reqVO); + // 校验是否更新正确 + PointRecordDO record = recordMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, record); + } + + @Test + public void testUpdateRecord_notExists() { + // 准备参数 + PointRecordUpdateReqVO reqVO = randomPojo(PointRecordUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> recordService.updateRecord(reqVO), RECORD_NOT_EXISTS); + } + + @Test + public void testDeleteRecord_success() { + // mock 数据 + PointRecordDO dbRecord = randomPojo(PointRecordDO.class); + recordMapper.insert(dbRecord);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbRecord.getId(); + + // 调用 + recordService.deleteRecord(id); + // 校验数据不存在了 + assertNull(recordMapper.selectById(id)); + } + + @Test + public void testDeleteRecord_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> recordService.deleteRecord(id), RECORD_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetRecordPage() { + // mock 数据 + PointRecordDO dbRecord = randomPojo(PointRecordDO.class, o -> { // 等会查询到 + o.setBizId(null); + o.setBizType(null); + o.setType(null); + o.setTitle(null); + o.setStatus(null); + }); + recordMapper.insert(dbRecord); + // 测试 bizId 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setBizId(null))); + // 测试 bizType 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setBizType(null))); + // 测试 type 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setType(null))); + // 测试 title 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setTitle(null))); + // 测试 status 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setStatus(null))); + // 准备参数 + PointRecordPageReqVO reqVO = new PointRecordPageReqVO(); + reqVO.setBizId(null); + reqVO.setBizType(null); + reqVO.setType(null); + reqVO.setTitle(null); + reqVO.setStatus(null); + + // 调用 + PageResult pageResult = recordService.getRecordPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbRecord, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetRecordList() { + // mock 数据 + PointRecordDO dbRecord = randomPojo(PointRecordDO.class, o -> { // 等会查询到 + o.setBizId(null); + o.setBizType(null); + o.setType(null); + o.setTitle(null); + o.setStatus(null); + }); + recordMapper.insert(dbRecord); + // 测试 bizId 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setBizId(null))); + // 测试 bizType 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setBizType(null))); + // 测试 type 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setType(null))); + // 测试 title 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setTitle(null))); + // 测试 status 不匹配 + recordMapper.insert(cloneIgnoreId(dbRecord, o -> o.setStatus(null))); + // 准备参数 + PointRecordExportReqVO reqVO = new PointRecordExportReqVO(); + reqVO.setBizId(null); + reqVO.setBizType(null); + reqVO.setType(null); + reqVO.setTitle(null); + reqVO.setStatus(null); + + // 调用 + List list = recordService.getRecordList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbRecord, list.get(0)); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImplTest.java b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImplTest.java new file mode 100644 index 000000000..e0bd5a2b2 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinconfig/SignInConfigServiceImplTest.java @@ -0,0 +1,152 @@ +package cn.iocoder.yudao.module.point.service.signinconfig; + +import cn.iocoder.yudao.framework.test.core.util.RandomUtils; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.point.controller.admin.signinconfig.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinconfig.SignInConfigDO; +import cn.iocoder.yudao.module.point.dal.mysql.signinconfig.SignInConfigMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; +import java.time.LocalDateTime; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * {@link SignInConfigServiceImpl} 的单元测试类 + * + * @author QingX + */ +@Import(SignInConfigServiceImpl.class) +public class SignInConfigServiceImplTest extends BaseDbUnitTest { + + @Resource + private SignInConfigServiceImpl signInConfigService; + + @Resource + private SignInConfigMapper signInConfigMapper; + + @Test + public void testCreateSignInConfig_success() { + // 准备参数 + SignInConfigCreateReqVO reqVO = randomPojo(SignInConfigCreateReqVO.class); + + // 调用 + Integer signInConfigId = signInConfigService.createSignInConfig(reqVO); + // 断言 + assertNotNull(signInConfigId); + // 校验记录的属性是否正确 + SignInConfigDO signInConfig = signInConfigMapper.selectById(signInConfigId); + assertPojoEquals(reqVO, signInConfig); + } + + @Test + public void testUpdateSignInConfig_success() { + // mock 数据 + SignInConfigDO dbSignInConfig = randomPojo(SignInConfigDO.class); + signInConfigMapper.insert(dbSignInConfig);// @Sql: 先插入出一条存在的数据 + // 准备参数 + SignInConfigUpdateReqVO reqVO = randomPojo(SignInConfigUpdateReqVO.class, o -> { + o.setId(dbSignInConfig.getId()); // 设置更新的 ID + }); + + // 调用 + signInConfigService.updateSignInConfig(reqVO); + // 校验是否更新正确 + SignInConfigDO signInConfig = signInConfigMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, signInConfig); + } + + @Test + public void testUpdateSignInConfig_notExists() { + // 准备参数 + SignInConfigUpdateReqVO reqVO = randomPojo(SignInConfigUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> signInConfigService.updateSignInConfig(reqVO), SIGN_IN_CONFIG_NOT_EXISTS); + } + + @Test + public void testDeleteSignInConfig_success() { + // mock 数据 + SignInConfigDO dbSignInConfig = randomPojo(SignInConfigDO.class); + signInConfigMapper.insert(dbSignInConfig);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Integer id = dbSignInConfig.getId(); + + // 调用 + signInConfigService.deleteSignInConfig(id); + // 校验数据不存在了 + assertNull(signInConfigMapper.selectById(id)); + } + + @Test + public void testDeleteSignInConfig_notExists() { + // 准备参数 + Integer id = RandomUtils.randomInteger(); + + // 调用, 并断言异常 + assertServiceException(() -> signInConfigService.deleteSignInConfig(id), SIGN_IN_CONFIG_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSignInConfigPage() { + // mock 数据 + SignInConfigDO dbSignInConfig = randomPojo(SignInConfigDO.class, o -> { // 等会查询到 + o.setDay(null); + }); + signInConfigMapper.insert(dbSignInConfig); + // 测试 day 不匹配 + signInConfigMapper.insert(cloneIgnoreId(dbSignInConfig, o -> o.setDay(null))); + // 准备参数 + SignInConfigPageReqVO reqVO = new SignInConfigPageReqVO(); + reqVO.setDay(null); + + // 调用 + PageResult pageResult = signInConfigService.getSignInConfigPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbSignInConfig, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSignInConfigList() { + // mock 数据 + SignInConfigDO dbSignInConfig = randomPojo(SignInConfigDO.class, o -> { // 等会查询到 + o.setDay(null); + }); + signInConfigMapper.insert(dbSignInConfig); + // 测试 day 不匹配 + signInConfigMapper.insert(cloneIgnoreId(dbSignInConfig, o -> o.setDay(null))); + // 准备参数 + SignInConfigExportReqVO reqVO = new SignInConfigExportReqVO(); + reqVO.setDay(null); + + // 调用 + List list = signInConfigService.getSignInConfigList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbSignInConfig, list.get(0)); + } + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImplTest.java b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImplTest.java new file mode 100644 index 000000000..267bfcd40 --- /dev/null +++ b/yudao-module-point/yudao-module-point-biz/src/test/java/cn/iocoder/yudao/module/point/service/signinrecord/SignInRecordServiceImplTest.java @@ -0,0 +1,167 @@ +package cn.iocoder.yudao.module.point.service.signinrecord; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.point.controller.admin.signinrecord.vo.*; +import cn.iocoder.yudao.module.point.dal.dataobject.signinrecord.SignInRecordDO; +import cn.iocoder.yudao.module.point.dal.mysql.signinrecord.SignInRecordMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; +import java.time.LocalDateTime; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * {@link SignInRecordServiceImpl} 的单元测试类 + * + * @author 芋道源码 + */ +@Import(SignInRecordServiceImpl.class) +public class SignInRecordServiceImplTest extends BaseDbUnitTest { + + @Resource + private SignInRecordServiceImpl signInRecordService; + + @Resource + private SignInRecordMapper signInRecordMapper; + + @Test + public void testCreateSignInRecord_success() { + // 准备参数 + SignInRecordCreateReqVO reqVO = randomPojo(SignInRecordCreateReqVO.class); + + // 调用 + Long signInRecordId = signInRecordService.createSignInRecord(reqVO); + // 断言 + assertNotNull(signInRecordId); + // 校验记录的属性是否正确 + SignInRecordDO signInRecord = signInRecordMapper.selectById(signInRecordId); + assertPojoEquals(reqVO, signInRecord); + } + + @Test + public void testUpdateSignInRecord_success() { + // mock 数据 + SignInRecordDO dbSignInRecord = randomPojo(SignInRecordDO.class); + signInRecordMapper.insert(dbSignInRecord);// @Sql: 先插入出一条存在的数据 + // 准备参数 + SignInRecordUpdateReqVO reqVO = randomPojo(SignInRecordUpdateReqVO.class, o -> { + o.setId(dbSignInRecord.getId()); // 设置更新的 ID + }); + + // 调用 + signInRecordService.updateSignInRecord(reqVO); + // 校验是否更新正确 + SignInRecordDO signInRecord = signInRecordMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, signInRecord); + } + + @Test + public void testUpdateSignInRecord_notExists() { + // 准备参数 + SignInRecordUpdateReqVO reqVO = randomPojo(SignInRecordUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> signInRecordService.updateSignInRecord(reqVO), SIGN_IN_RECORD_NOT_EXISTS); + } + + @Test + public void testDeleteSignInRecord_success() { + // mock 数据 + SignInRecordDO dbSignInRecord = randomPojo(SignInRecordDO.class); + signInRecordMapper.insert(dbSignInRecord);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbSignInRecord.getId(); + + // 调用 + signInRecordService.deleteSignInRecord(id); + // 校验数据不存在了 + assertNull(signInRecordMapper.selectById(id)); + } + + @Test + public void testDeleteSignInRecord_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> signInRecordService.deleteSignInRecord(id), SIGN_IN_RECORD_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSignInRecordPage() { + // mock 数据 + SignInRecordDO dbSignInRecord = randomPojo(SignInRecordDO.class, o -> { // 等会查询到 + o.setUserId(null); + o.setDay(null); + o.setCreateTime(null); + }); + signInRecordMapper.insert(dbSignInRecord); + // 测试 userId 不匹配 + signInRecordMapper.insert(cloneIgnoreId(dbSignInRecord, o -> o.setUserId(null))); + // 测试 day 不匹配 + signInRecordMapper.insert(cloneIgnoreId(dbSignInRecord, o -> o.setDay(null))); + // 测试 createTime 不匹配 + signInRecordMapper.insert(cloneIgnoreId(dbSignInRecord, o -> o.setCreateTime(null))); + // 准备参数 + SignInRecordPageReqVO reqVO = new SignInRecordPageReqVO(); + reqVO.setUserId(null); + reqVO.setDay(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + PageResult pageResult = signInRecordService.getSignInRecordPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbSignInRecord, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetSignInRecordList() { + // mock 数据 + SignInRecordDO dbSignInRecord = randomPojo(SignInRecordDO.class, o -> { // 等会查询到 + o.setUserId(null); + o.setDay(null); + o.setCreateTime(null); + }); + signInRecordMapper.insert(dbSignInRecord); + // 测试 userId 不匹配 + signInRecordMapper.insert(cloneIgnoreId(dbSignInRecord, o -> o.setUserId(null))); + // 测试 day 不匹配 + signInRecordMapper.insert(cloneIgnoreId(dbSignInRecord, o -> o.setDay(null))); + // 测试 createTime 不匹配 + signInRecordMapper.insert(cloneIgnoreId(dbSignInRecord, o -> o.setCreateTime(null))); + // 准备参数 + SignInRecordExportReqVO reqVO = new SignInRecordExportReqVO(); + reqVO.setUserId(null); + reqVO.setDay(null); + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); + + // 调用 + List list = signInRecordService.getSignInRecordList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbSignInRecord, list.get(0)); + } + +} diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index f32144fb5..f38a73ce9 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -54,11 +54,11 @@ - - cn.iocoder.boot - yudao-module-pay-biz - ${revision} - + + + + + @@ -68,19 +68,25 @@ + + + + + + + + + + + + + + + + cn.iocoder.boot - yudao-module-promotion-biz - ${revision} - - - cn.iocoder.boot - yudao-module-product-biz - ${revision} - - - cn.iocoder.boot - yudao-module-trade-biz + yudao-module-point-biz ${revision} @@ -111,7 +117,7 @@ org.springframework.boot spring-boot-maven-plugin - 2.7.10 + 2.7.11 true From 5f64fe052b873393896517769858779cc49e778c Mon Sep 17 00:00:00 2001 From: xiaqing Date: Sat, 10 Jun 2023 20:45:31 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/menu.sql | 230 ++++++++++++++++++++++++++++++++++++++++++++ sql/mysql/point.sql | 152 +++++++++++++++++++++++++++++ 2 files changed, 382 insertions(+) create mode 100644 sql/mysql/menu.sql create mode 100644 sql/mysql/point.sql diff --git a/sql/mysql/menu.sql b/sql/mysql/menu.sql new file mode 100644 index 000000000..704979b78 --- /dev/null +++ b/sql/mysql/menu.sql @@ -0,0 +1,230 @@ +-- 菜单 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status, component_name +) +VALUES ( + '积分设置管理', '', 2, 0, 2162, + 'config', '', 'point/config/index', 0, 'PointConfig' +); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分设置查询', 'point:config:query', 3, 1, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分设置创建', 'point:config:create', 3, 2, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分设置更新', 'point:config:update', 3, 3, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分设置删除', 'point:config:delete', 3, 4, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分设置导出', 'point:config:export', 3, 5, @parentId, + '', '', '', 0 +); + + + +-- 菜单 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status, component_name +) +VALUES ( + '积分签到规则管理', '', 2, 0, 2162, + 'sign-in-config', '', 'point/signInConfig/index', 0, 'SignInConfig' +); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分签到规则查询', 'point:sign-in-config:query', 3, 1, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分签到规则创建', 'point:sign-in-config:create', 3, 2, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分签到规则更新', 'point:sign-in-config:update', 3, 3, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分签到规则删除', 'point:sign-in-config:delete', 3, 4, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '积分签到规则导出', 'point:sign-in-config:export', 3, 5, @parentId, + '', '', '', 0 +); + + +-- 菜单 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status, component_name +) +VALUES ( + '用户积分记录管理', '', 2, 0, 2162, + 'record', '', 'point/record/index', 0, 'PointRecord' +); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户积分记录查询', 'point:record:query', 3, 1, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户积分记录创建', 'point:record:create', 3, 2, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户积分记录更新', 'point:record:update', 3, 3, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户积分记录删除', 'point:record:delete', 3, 4, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户积分记录导出', 'point:record:export', 3, 5, @parentId, + '', '', '', 0 +); + + + +-- 菜单 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status, component_name +) +VALUES ( + '用户签到积分管理', '', 2, 0, 2162, + 'sign-in-record', '', 'point/signInRecord/index', 0, 'SignInRecord' +); + +-- 按钮父菜单ID +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 +SELECT @parentId := LAST_INSERT_ID(); + +-- 按钮 SQL +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户签到积分查询', 'point:sign-in-record:query', 3, 1, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户签到积分创建', 'point:sign-in-record:create', 3, 2, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户签到积分更新', 'point:sign-in-record:update', 3, 3, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户签到积分删除', 'point:sign-in-record:delete', 3, 4, @parentId, + '', '', '', 0 +); +INSERT INTO system_menu( + name, permission, type, sort, parent_id, + path, icon, component, status +) +VALUES ( + '用户签到积分导出', 'point:sign-in-record:export', 3, 5, @parentId, + '', '', '', 0 +); + + diff --git a/sql/mysql/point.sql b/sql/mysql/point.sql new file mode 100644 index 000000000..dfa625940 --- /dev/null +++ b/sql/mysql/point.sql @@ -0,0 +1,152 @@ +/* + Navicat Premium Data Transfer + + Source Server : docer-master-root(3308) + Source Server Type : MySQL + Source Server Version : 80030 + Source Host : 10.211.55.5:3308 + Source Schema : mall + + Target Server Type : MySQL + Target Server Version : 80030 + File Encoding : 65001 + + Date: 10/06/2023 20:13:57 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for member_point_config +-- ---------------------------- +DROP TABLE IF EXISTS `member_point_config`; +CREATE TABLE `member_point_config` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `trade_deduct_enable` int DEFAULT NULL COMMENT '1 开启积分抵扣\n0 关闭积分抵扣', + `trade_deduct_unit_price` decimal(10,2) DEFAULT NULL COMMENT '积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元)', + `trade_deduct_max_price` bigint DEFAULT NULL COMMENT '积分抵扣最大值', + `trade_give_point` bigint DEFAULT NULL COMMENT '1元赠送多少分', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '变更时间', + `tenant_id` varchar(255) DEFAULT NULL COMMENT '租户id', + `deleted` int DEFAULT '0' COMMENT '是否被删除 0 未删除 1已删除', + `creator` varchar(255) DEFAULT NULL COMMENT '创建人', + `updater` varchar(255) DEFAULT NULL COMMENT '更新人', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='积分设置'; + +-- ---------------------------- +-- Records of member_point_config +-- ---------------------------- +BEGIN; +INSERT INTO `member_point_config` (`id`, `trade_deduct_enable`, `trade_deduct_unit_price`, `trade_deduct_max_price`, `trade_give_point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (1, 1, 0.01, 10000, 1, '2023-06-10 10:57:22', '2023-06-10 03:06:58', '1', 1, '1', '1'); +INSERT INTO `member_point_config` (`id`, `trade_deduct_enable`, `trade_deduct_unit_price`, `trade_deduct_max_price`, `trade_give_point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (2, 1, 0.01, 10000, 10, '2023-06-10 11:07:12', '2023-06-10 11:07:12', '1', 0, '1', '1'); +INSERT INTO `member_point_config` (`id`, `trade_deduct_enable`, `trade_deduct_unit_price`, `trade_deduct_max_price`, `trade_give_point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (3, 1, 12.00, 12, 12, '2023-06-10 16:09:26', '2023-06-10 08:10:53', '1', 1, '1', '1'); +COMMIT; + +-- ---------------------------- +-- Table structure for member_point_record +-- ---------------------------- +DROP TABLE IF EXISTS `member_point_record`; +CREATE TABLE `member_point_record` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `biz_id` varchar(255) DEFAULT NULL COMMENT '业务编码', + `biz_type` varchar(255) DEFAULT NULL COMMENT '业务类型', + `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '1增加 0扣减', + `title` varchar(255) DEFAULT NULL COMMENT '积分标题', + `description` varchar(5000) DEFAULT NULL COMMENT '积分描述', + `point` int DEFAULT NULL COMMENT '积分', + `total_point` int NOT NULL COMMENT '变动后的积分', + `status` int DEFAULT NULL COMMENT '状态:1-订单创建,2-冻结期,3-完成,4-失效(订单退款)\n', + `user_id` int DEFAULT NULL COMMENT '用户id', + `freezing_time` datetime DEFAULT NULL COMMENT '冻结时间', + `thawing_time` datetime DEFAULT NULL COMMENT '解冻时间', + `create_time` datetime DEFAULT NULL COMMENT '发生时间', + `tenant_id` varchar(255) DEFAULT NULL COMMENT '租户', + `deleted` int DEFAULT '0' COMMENT '是否删除', + `creator` varchar(255) DEFAULT NULL COMMENT '创建用户', + `updater` varchar(255) DEFAULT NULL COMMENT '更新用户', + `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`), + KEY `index_userId` (`user_id`), + KEY `index_title` (`title`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户积分记录'; + +-- ---------------------------- +-- Records of member_point_record +-- ---------------------------- +BEGIN; +INSERT INTO `member_point_record` (`id`, `biz_id`, `biz_type`, `type`, `title`, `description`, `point`, `total_point`, `status`, `user_id`, `freezing_time`, `thawing_time`, `create_time`, `tenant_id`, `deleted`, `creator`, `updater`, `update_time`) VALUES (1, '1', '1', '1', '12', NULL, 212, 12, 1, 12, '2023-06-13 00:00:00', '2023-06-20 00:00:00', '2023-06-10 12:38:48', '1', 1, '1', '1', '2023-06-10 04:42:24'); +INSERT INTO `member_point_record` (`id`, `biz_id`, `biz_type`, `type`, `title`, `description`, `point`, `total_point`, `status`, `user_id`, `freezing_time`, `thawing_time`, `create_time`, `tenant_id`, `deleted`, `creator`, `updater`, `update_time`) VALUES (2, '12', '1', '0', NULL, NULL, 1212, 12, 2, 12, '2023-06-28 00:00:00', NULL, '2023-06-10 12:42:48', '1', 0, '1', '1', '2023-06-10 12:43:04'); +INSERT INTO `member_point_record` (`id`, `biz_id`, `biz_type`, `type`, `title`, `description`, `point`, `total_point`, `status`, `user_id`, `freezing_time`, `thawing_time`, `create_time`, `tenant_id`, `deleted`, `creator`, `updater`, `update_time`) VALUES (3, '12', '1', '1', '12', NULL, 12, 12, 1, 12, '2023-06-27 00:00:00', '2023-06-23 00:00:00', '2023-06-10 20:06:48', '1', 0, '1', '1', '2023-06-10 20:06:48'); +COMMIT; + +-- ---------------------------- +-- Table structure for member_sign_in_config +-- ---------------------------- +DROP TABLE IF EXISTS `member_sign_in_config`; +CREATE TABLE `member_sign_in_config` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '规则自增主键', + `day` int DEFAULT NULL COMMENT '签到第x天', + `point` int DEFAULT NULL COMMENT '签到天数对应分数', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '变更时间', + `tenant_id` varchar(255) DEFAULT NULL COMMENT '租户id', + `deleted` int DEFAULT '0' COMMENT '是否删除', + `creator` varchar(255) DEFAULT NULL COMMENT '创建人', + `updater` varchar(255) DEFAULT NULL COMMENT '变更人', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='积分签到规则'; + +-- ---------------------------- +-- Records of member_sign_in_config +-- ---------------------------- +BEGIN; +INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (1, 1, 10, '2023-06-10 11:34:43', '2023-06-10 11:34:43', '1', 0, '1', '1'); +INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (2, 2, 20, '2023-06-10 11:34:59', '2023-06-10 03:55:35', '1', 1, '1', '1'); +INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (3, 7, 1001, '2023-06-10 17:47:45', '2023-06-10 19:54:37', '1', 0, '1', '1'); +INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (4, 6, 12121, '2023-06-10 17:47:55', '2023-06-10 19:48:37', '1', 0, '1', '1'); +INSERT INTO `member_sign_in_config` (`id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (5, 2, 12, '2023-06-10 19:54:52', '2023-06-10 19:54:52', '1', 0, '1', '1'); +COMMIT; + +-- ---------------------------- +-- Table structure for member_sign_in_record +-- ---------------------------- +DROP TABLE IF EXISTS `member_sign_in_record`; +CREATE TABLE `member_sign_in_record` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '签到自增id', + `user_id` int DEFAULT NULL COMMENT '签到用户', + `day` int DEFAULT NULL COMMENT '第几天签到', + `point` int DEFAULT NULL COMMENT '签到的分数', + `create_time` datetime DEFAULT NULL COMMENT '签到时间', + `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '变更时间', + `tenant_id` varchar(255) DEFAULT NULL COMMENT '租户id', + `deleted` int DEFAULT '0' COMMENT '是否删除', + `creator` varchar(255) DEFAULT NULL COMMENT '创建人', + `updater` varchar(255) DEFAULT NULL COMMENT '更新人', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户签到积分'; + +-- ---------------------------- +-- Records of member_sign_in_record +-- ---------------------------- +BEGIN; +INSERT INTO `member_sign_in_record` (`id`, `user_id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (1, 121, 1, 123, '2023-06-10 12:58:18', '2023-06-10 04:59:00', '1', 1, '1', '1'); +INSERT INTO `member_sign_in_record` (`id`, `user_id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (2, 12, 12, 12, '2023-06-10 19:56:39', '2023-06-10 11:56:45', '1', 1, '1', '1'); +INSERT INTO `member_sign_in_record` (`id`, `user_id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (3, 12, 12, 1212, '2023-06-10 20:01:17', '2023-06-10 12:01:23', '1', 1, '1', '1'); +INSERT INTO `member_sign_in_record` (`id`, `user_id`, `day`, `point`, `create_time`, `update_time`, `tenant_id`, `deleted`, `creator`, `updater`) VALUES (4, 12, 12, 1212, '2023-06-10 20:01:27', '2023-06-10 20:01:27', '1', 0, '1', '1'); +COMMIT; + +SET FOREIGN_KEY_CHECKS = 1; + + +INSERT INTO `mall`.`system_dict_type` ( `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `deleted_time`) VALUES ( '积分业务类型', 'point_biz_type', 0, '', '1', '2023-06-10 12:15:00', '1', '2023-06-10 04:25:07', b'0', '1970-01-01 00:00:00'); +INSERT INTO `mall`.`system_dict_type` ( `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `deleted_time`) VALUES ( '积分订单状态', 'point_status', 0, '', '1', '2023-06-10 12:16:27', '1', '2023-06-10 12:16:27', b'0', '1970-01-01 00:00:00'); + +INSERT INTO `mall`.`system_dict_data` ( `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ( 1, '购物', '1', 'point_biz_type', 0, '', '', '', '1', '2023-06-10 12:15:27', '1', '2023-06-10 04:25:15', b'0'); +INSERT INTO `mall`.`system_dict_data` ( `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ( 2, '签到', '2', 'point_biz_type', 0, '', '', '', '1', '2023-06-10 12:15:48', '1', '2023-06-10 04:25:18', b'0'); +INSERT INTO `mall`.`system_dict_data` ( `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ( 1, '订单创建', '1', 'point_status', 0, '', '', '', '1', '2023-06-10 12:16:42', '1', '2023-06-10 12:16:42', b'0'); +INSERT INTO `mall`.`system_dict_data` ( `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ( 2, '冻结期', '2', 'point_status', 0, '', '', '', '1', '2023-06-10 12:16:58', '1', '2023-06-10 12:16:58', b'0'); +INSERT INTO `mall`.`system_dict_data` ( `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ( 3, '完成', '3', 'point_status', 0, '', '', '', '1', '2023-06-10 12:17:07', '1', '2023-06-10 12:17:07', b'0'); +INSERT INTO `mall`.`system_dict_data` ( `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ( 4, '失效(订单退款)', '4', 'point_status', 0, '', '', '', '1', '2023-06-10 12:17:21', '1', '2023-06-10 12:17:21', b'0'); From e69e6d880b08e02b0d9c9ca9b8c166cc1ef0954b Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Thu, 15 Jun 2023 10:49:24 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E5=BF=AB=E9=80=92=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=20review=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 5 +- .../DeliveryExpressTemplateConvert.java | 7 +- .../DeliveryExpressTemplateChargeMapper.java | 8 +- .../DeliveryExpressTemplateFreeMapper.java | 9 ++- .../DeliveryExpressTemplateService.java | 12 ++- .../DeliveryExpressTemplateServiceImpl.java | 55 ++++++------- .../bo/DeliveryExpressTemplateChargeBO.java | 29 ------- .../bo/DeliveryExpressTemplateFreeBO.java | 26 ------ .../bo/DeliveryExpressTemplateRespBO.java | 79 +++++++++++++++++++ .../bo/SpuDeliveryExpressTemplateRespBO.java | 33 -------- .../price/bo/TradePriceCalculateRespBO.java | 5 ++ .../TradeDeliveryPriceCalculator.java | 46 ++++++----- .../TradePriceCalculatorHelper.java | 3 +- .../TradeDeliveryPriceCalculatorTest.java | 38 +++++---- 14 files changed, 172 insertions(+), 183 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateChargeBO.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateFreeBO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 46ee636a5..800b5f239 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -51,13 +51,12 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011003001, "已经存在该编码的快递公司"); ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011003002, "运费模板不存在"); ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); - ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); // TODO @jaosn:这个错误码,放到 Price 这块 - ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板"); // TODO @jaosn:这个错误码,放到 Price 这块 ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003006, "快递查询接口异常"); ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003007, "快递查询返回失败, 原因:{}"); ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003008, "自提门店不存在"); // ========== Price 相关 1011004000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011004000, "支付价格计算异常,原因:价格小于等于 0"); - + ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY = new ErrorCode(1011004001, "计算快递运费异常,收件人地址编号为空"); + ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011004002, "计算快递运费异常,找不到对应的运费模板"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java index 6ac562658..bbd57c62e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java @@ -6,8 +6,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplat import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateChargeDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateFreeDO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateChargeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateFreeBO; +import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -49,7 +48,7 @@ public interface DeliveryExpressTemplateConvert { DeliveryExpressTemplateChargeDO convertTemplateCharge(DeliveryExpressTemplateUpdateReqVO.ExpressTemplateChargeUpdateVO vo); - DeliveryExpressTemplateChargeBO convertTemplateCharge(DeliveryExpressTemplateChargeDO bean); + DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO convertTemplateCharge(DeliveryExpressTemplateChargeDO bean); default List convertTemplateChargeList(Long templateId, Integer chargeMode, List list) { return CollectionUtils.convertList(list, vo -> convertTemplateCharge(templateId, chargeMode, vo)); @@ -61,7 +60,7 @@ public interface DeliveryExpressTemplateConvert { DeliveryExpressTemplateFreeDO convertTemplateFree(DeliveryExpressTemplateUpdateReqVO.ExpressTemplateFreeUpdateVO vo); - DeliveryExpressTemplateFreeBO convertTemplateFree(DeliveryExpressTemplateFreeDO bean); + DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO convertTemplateFree(DeliveryExpressTemplateFreeDO bean); List convertTemplateChargeList(List list); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java index dc96b24f2..985b418ac 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java @@ -5,10 +5,9 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateChargeDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; @Mapper @@ -23,6 +22,11 @@ public interface DeliveryExpressTemplateChargeMapper extends BaseMapperX() .eq(DeliveryExpressTemplateChargeDO::getTemplateId, templateId)); } + + default List selectByTemplateIds(Collection templateIds) { + return selectList(new LambdaQueryWrapperX() + .inIfPresent(DeliveryExpressTemplateChargeDO::getTemplateId, templateIds)); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java index 58caaf9af..5cc407354 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java @@ -2,13 +2,11 @@ package cn.iocoder.yudao.module.trade.dal.mysql.delivery; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateChargeDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateFreeDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; @Mapper @@ -23,6 +21,11 @@ public interface DeliveryExpressTemplateFreeMapper extends BaseMapperX() .eq(DeliveryExpressTemplateFreeDO::getTemplateId, templateId)); } + + default List selectListByTemplateIds(Collection ids) { + return selectList(new LambdaQueryWrapperX() + .inIfPresent(DeliveryExpressTemplateFreeDO::getTemplateId, ids)); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java index 3c438df12..39edd823e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplat import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplate.DeliveryExpressTemplatePageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplate.DeliveryExpressTemplateUpdateReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateDO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.SpuDeliveryExpressTemplateRespBO; +import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import javax.validation.Valid; import java.util.Collection; @@ -83,14 +83,12 @@ public interface DeliveryExpressTemplateService { */ DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); - // TODO @jason:可以把 spuIds 改成传递 ids 么?价格计算那,在 TradePriceCalculateRespBO 冗余好 templateId 字段。目的是,减少重复的查询 /** - * 基于指定的 SPU 编号数组和收件人地址区域编号. 获取匹配运费模板 + * 基于运费模板编号数组和收件人地址区域编号. 获取匹配运费模板 * - * @param spuIds SPU 编号列表 + * @param ids 编号列表 * @param areaId 区域编号 - * @return Map (spuId -> 运费模板设置) + * @return Map (templateId -> 运费模板设置) */ - Map getExpressTemplateMapBySpuIdsAndArea(Collection spuIds, Integer areaId); - + Map getExpressTemplateMapByIdsAndArea(Collection ids, Integer areaId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java index c7ddc9da6..c4aa22b8f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.trade.service.delivery; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; -import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplate.DeliveryExpressTemplateCreateReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplate.DeliveryExpressTemplateDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.expresstemplate.DeliveryExpressTemplatePageReqVO; @@ -15,9 +13,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemp import cn.iocoder.yudao.module.trade.dal.mysql.delivery.DeliveryExpressTemplateChargeMapper; import cn.iocoder.yudao.module.trade.dal.mysql.delivery.DeliveryExpressTemplateFreeMapper; import cn.iocoder.yudao.module.trade.dal.mysql.delivery.DeliveryExpressTemplateMapper; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateChargeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateFreeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.SpuDeliveryExpressTemplateRespBO; +import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -46,8 +42,6 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla private DeliveryExpressTemplateChargeMapper expressTemplateChargeMapper; @Resource private DeliveryExpressTemplateFreeMapper expressTemplateFreeMapper; - @Resource - private ProductSpuApi productSpuApi; @Override @Transactional(rollbackFor = Exception.class) @@ -228,41 +222,40 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla } @Override - public Map getExpressTemplateMapBySpuIdsAndArea(Collection spuIds, Integer areaId) { + public Map getExpressTemplateMapByIdsAndArea(Collection ids, Integer areaId) { Assert.notNull(areaId, "区域编号 {} 不能为空", areaId); - List spuList = productSpuApi.getSpuList(spuIds); - if (CollUtil.isEmpty(spuList)) { + if (CollUtil.isEmpty(ids)) { return Collections.emptyMap(); } - Map spuMap = convertMap(spuList, ProductSpuRespDTO::getDeliveryTemplateId); - List templateList = expressTemplateMapper.selectBatchIds(spuMap.keySet()); - Map result = new HashMap<>(templateList.size()); + List templateList = expressTemplateMapper.selectBatchIds(ids); + // 查询 templateCharge + List templeChargeList = expressTemplateChargeMapper.selectByTemplateIds(ids); + Map> templateChargeMap = convertMultiMap(templeChargeList, + DeliveryExpressTemplateChargeDO::getTemplateId); + // 查询 templateFree + List templateFreeList = expressTemplateFreeMapper.selectListByTemplateIds(ids); + Map> templateFreeMap = convertMultiMap(templateFreeList, + DeliveryExpressTemplateFreeDO::getTemplateId); + // 组合运费模板配置 RespBO + Map result = new HashMap<>(templateList.size()); templateList.forEach(item -> { - ProductSpuRespDTO spu = spuMap.get(item.getId()); - if (spu == null) { - return; - } - // TODO @jason:避免循环查询;最好类似 expressTemplateMapper.selectBatchIds(spuMap.keySet()); 批量查询,内存组合; - SpuDeliveryExpressTemplateRespBO bo = new SpuDeliveryExpressTemplateRespBO() + DeliveryExpressTemplateRespBO bo = new DeliveryExpressTemplateRespBO() .setChargeMode(item.getChargeMode()) - .setTemplateCharge(findMatchExpressTemplateCharge(item.getId(), areaId)) - .setTemplateFree(findMatchExpressTemplateFree(item.getId(), areaId)); - result.put(spu.getId(), bo); + .setTemplateCharge(findMatchExpressTemplateCharge(templateChargeMap.get(item.getId()), areaId)) + .setTemplateFree(findMatchExpressTemplateFree(templateFreeMap.get(item.getId()), areaId)); + result.put(item.getId(), bo); }); return result; } - private DeliveryExpressTemplateChargeBO findMatchExpressTemplateCharge(Long templateId, Integer areaId) { - return INSTANCE.convertTemplateCharge(findFirst( - expressTemplateChargeMapper.selectListByTemplateId(templateId), item -> item.getAreaIds().contains(areaId) - ) - ); + private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO findMatchExpressTemplateCharge( + List templateChargeList, Integer areaId) { + return INSTANCE.convertTemplateCharge(findFirst(templateChargeList, item -> item.getAreaIds().contains(areaId))); } - private DeliveryExpressTemplateFreeBO findMatchExpressTemplateFree(Long templateId, Integer areaId) { - return INSTANCE.convertTemplateFree(findFirst( - expressTemplateFreeMapper.selectListByTemplateId(templateId), item -> item.getAreaIds().contains(areaId) - )); + private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO findMatchExpressTemplateFree( + List templateFreeList, Integer areaId) { + return INSTANCE.convertTemplateFree(findFirst(templateFreeList, item -> item.getAreaIds().contains(areaId))); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateChargeBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateChargeBO.java deleted file mode 100644 index 9dd908c41..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateChargeBO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.module.trade.service.delivery.bo; - -import lombok.Data; - -/** - * 快递运费模板费用配置 BO - * - * @author jason - */ -@Data -public class DeliveryExpressTemplateChargeBO { - - /** - * 首件数量(件数,重量,或体积) - */ - private Double startCount; - /** - * 起步价,单位:分 - */ - private Integer startPrice; - /** - * 续件数量(件, 重量,或体积) - */ - private Double extraCount; - /** - * 额外价,单位:分 - */ - private Integer extraPrice; -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateFreeBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateFreeBO.java deleted file mode 100644 index 6bccb038e..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateFreeBO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.trade.service.delivery.bo; - -import lombok.Data; - -/** - * 快递运费模板包邮配置 BO - * - * @author jason - */ -@Data -public class DeliveryExpressTemplateFreeBO { - - /** - * 包邮金额,单位:分 - * - * 订单总金额 > 包邮金额时,才免运费 - */ - private Integer freePrice; - - /** - * 包邮件数 - * - * 订单总件数 > 包邮件数时,才免运费 - */ - private Integer freeCount; -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java new file mode 100644 index 000000000..6c8764a5c --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.module.trade.service.delivery.bo; + +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; +import lombok.Data; + +/** + * 运费模板配置 Resp BO + * + * @author jason + */ +@Data +public class DeliveryExpressTemplateRespBO { + + /** + * 配送计费方式 + * + * 枚举 {@link DeliveryExpressChargeModeEnum} + */ + private Integer chargeMode; + + /** + * 运费模板快递运费设置 + */ + private DeliveryExpressTemplateChargeBO templateCharge; + + /** + * 运费模板包邮设置 + */ + private DeliveryExpressTemplateFreeBO templateFree; + + /** + * 快递运费模板费用配置 BO + * + * @author jason + */ + @Data + public static class DeliveryExpressTemplateChargeBO { + + /** + * 首件数量(件数,重量,或体积) + */ + private Double startCount; + /** + * 起步价,单位:分 + */ + private Integer startPrice; + /** + * 续件数量(件, 重量,或体积) + */ + private Double extraCount; + /** + * 额外价,单位:分 + */ + private Integer extraPrice; + } + + /** + * 快递运费模板包邮配置 BO + * + * @author jason + */ + @Data + public static class DeliveryExpressTemplateFreeBO { + + /** + * 包邮金额,单位:分 + * + * 订单总金额 > 包邮金额时,才免运费 + */ + private Integer freePrice; + + /** + * 包邮件数 + * + * 订单总件数 > 包邮件数时,才免运费 + */ + private Integer freeCount; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java deleted file mode 100644 index 82a0274de..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.trade.service.delivery.bo; - -import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; -import lombok.Data; - -/** - * SPU 运费模板配置 Resp BO - * - * @author jason - */ -@Data -public class SpuDeliveryExpressTemplateRespBO { - - /** - * 配送计费方式 - * - * 枚举 {@link DeliveryExpressChargeModeEnum} - */ - private Integer chargeMode; - - // TODO @jaosn:可以把 DeliveryExpressTemplateChargeBO 和 DeliveryExpressTemplateFreeBO 搞成内嵌的类。这样简洁一点 - - /** - * 运费模板快递运费设置 - */ - private DeliveryExpressTemplateChargeBO templateCharge; - - /** - * 运费模板包邮设置 - */ - private DeliveryExpressTemplateFreeBO templateFree; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java index 8231621bb..76fb68c1f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java @@ -180,6 +180,11 @@ public class TradePriceCalculateRespBO { */ private Long categoryId; + /** + * 运费模板 Id + */ + private Long deliveryTemplateId; + // ========== 商品 SKU 信息 ========== /** * 商品重量,单位:kg 千克 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 9f8e6afa7..1a0598c63 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -7,9 +7,7 @@ import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressTemplateService; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateChargeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateFreeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.SpuDeliveryExpressTemplateRespBO; +import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO.OrderItem; @@ -24,8 +22,8 @@ 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.*; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND; /** * 运费的 {@link TradePriceCalculator} 实现类 @@ -49,7 +47,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { return; } if (param.getAddressId() == null) { - throw exception(DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY); + throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY); } // 1.2 得到收件地址区域 AddressRespDTO address = addressApi.getAddress(param.getAddressId(), param.getUserId()); @@ -57,29 +55,29 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { // 2. 过滤出已选中的商品SKU List selectedItem = filterList(result.getItems(), OrderItem::getSelected); - Set spuIds = convertSet(selectedItem, OrderItem::getSpuId); - Map spuExpressTemplateMap = - deliveryExpressTemplateService.getExpressTemplateMapBySpuIdsAndArea(spuIds, address.getAreaId()); + Set deliveryTemplateIds = convertSet(selectedItem, OrderItem::getDeliveryTemplateId); + Map expressTemplateMap = + deliveryExpressTemplateService.getExpressTemplateMapByIdsAndArea(deliveryTemplateIds, address.getAreaId()); // 3. 计算配送费用 - if (CollUtil.isEmpty(spuExpressTemplateMap)) { - log.error("[calculate][找不到商品 spuId{} areaId{} 对应的运费模板]", spuIds, address.getAreaId()); - throw exception(PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND); + if (CollUtil.isEmpty(expressTemplateMap)) { + log.error("[calculate][找不到商品 templateIds {} areaId{} 对应的运费模板]", deliveryTemplateIds, address.getAreaId()); + throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND); } - calculateDeliveryPrice(selectedItem, spuExpressTemplateMap, result); + calculateDeliveryPrice(selectedItem, expressTemplateMap, result); } private void calculateDeliveryPrice(List selectedSkus, - Map spuExpressTemplateMap, + Map expressTemplateMap, TradePriceCalculateRespBO result) { - // 按 SPU 来计算商品的运费:一个 spuId 可能对应多条订单商品 SKU - Map> spuIdItemMap = convertMultiMap(selectedSkus, OrderItem::getSpuId); - // 依次计算每个 SPU 的快递运费 - for (Map.Entry> entry : spuIdItemMap.entrySet()) { - Long spuId = entry.getKey(); + // 按商品运费模板来计算商品的运费:相同的运费模板可能对应多条订单商品 SKU + Map> tplIdItemMap = convertMultiMap(selectedSkus, OrderItem::getDeliveryTemplateId); + // 依次计算快递运费 + for (Map.Entry> entry : tplIdItemMap.entrySet()) { + Long templateId = entry.getKey(); List orderItems = entry.getValue(); - SpuDeliveryExpressTemplateRespBO templateBO = spuExpressTemplateMap.get(spuId); + DeliveryExpressTemplateRespBO templateBO = expressTemplateMap.get(templateId); if (templateBO == null) { - log.error("不能计算快递运费。不能找到 spuId : {}. 对应的运费模板配置 Resp BO", spuId); + log.error("不能计算快递运费。不能找到 templateId : {}. 对应的运费模板配置 Resp BO", templateId); continue; } // 总件数, 总金额, 总重量, 总体积 @@ -117,7 +115,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * @param orderItems SKU 商品项目 */ private void calculateExpressFeeByChargeMode(double totalCount, double totalWeight, double totalVolume, - int chargeMode, DeliveryExpressTemplateChargeBO templateCharge, + int chargeMode, DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO templateCharge, List orderItems) { if (templateCharge == null) { log.error("计算快递运费时,不能找到对应的快递运费模板费用配置。无法计算以下商品 SKU 项目运费: {}", orderItems); @@ -147,7 +145,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * @param templateCharge 快递运费配置 * @param orderItems SKU 商品项目 */ - private void calculateExpressFee(double total, DeliveryExpressTemplateChargeBO templateCharge, List orderItems) { + private void calculateExpressFee(double total, DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO templateCharge, List orderItems) { int deliveryPrice; if (total <= templateCharge.getStartCount()) { deliveryPrice = templateCharge.getStartPrice(); @@ -192,7 +190,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * @param templateFree 包邮配置 */ private boolean isExpressFree(Integer chargeMode, int totalCount, double totalWeight, - double totalVolume, int totalPrice, DeliveryExpressTemplateFreeBO templateFree) { + double totalVolume, int totalPrice, DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO templateFree) { if (templateFree == null) { return false; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index 7945c72eb..bd3d3b5be 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -56,7 +56,8 @@ public class TradePriceCalculatorHelper { orderItem.setPicUrl(sku.getPicUrl()).setProperties(sku.getProperties()) .setWeight(sku.getWeight()).setVolume(sku.getVolume()); // spu 信息 - orderItem.setSpuName(spu.getName()).setCategoryId(spu.getCategoryId()); + orderItem.setSpuName(spu.getName()).setCategoryId(spu.getCategoryId()) + .setDeliveryTemplateId(spu.getDeliveryTemplateId()); if (orderItem.getPicUrl() == null) { orderItem.setPicUrl(spu.getPicUrl()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java index e6af92430..99fdac64e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java @@ -4,9 +4,7 @@ import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressTemplateService; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateChargeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateFreeBO; -import cn.iocoder.yudao.module.trade.service.delivery.bo.SpuDeliveryExpressTemplateRespBO; +import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.BeforeEach; @@ -44,9 +42,9 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { private TradePriceCalculateReqBO reqBO; private TradePriceCalculateRespBO resultBO; private AddressRespDTO addressResp; - private DeliveryExpressTemplateChargeBO chargeBO; - private DeliveryExpressTemplateFreeBO freeBO; - private SpuDeliveryExpressTemplateRespBO spuTemplateRespBO; + private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO chargeBO; + private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO freeBO; + private DeliveryExpressTemplateRespBO templateRespBO; @BeforeEach public void init(){ @@ -64,11 +62,11 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( - new TradePriceCalculateRespBO.OrderItem().setSpuId(1L).setSkuId(10L).setCount(2).setSelected(true) + new TradePriceCalculateRespBO.OrderItem().setDeliveryTemplateId(1L).setSkuId(10L).setCount(2).setSelected(true) .setWeight(10d).setVolume(10d).setPrice(100), - new TradePriceCalculateRespBO.OrderItem().setSpuId(1L).setSkuId(20L).setCount(10).setSelected(true) + new TradePriceCalculateRespBO.OrderItem().setDeliveryTemplateId(1L).setSkuId(20L).setCount(10).setSelected(true) .setWeight(10d).setVolume(10d).setPrice(200), - new TradePriceCalculateRespBO.OrderItem().setSpuId(1L).setSkuId(30L).setCount(1).setSelected(false) + new TradePriceCalculateRespBO.OrderItem().setDeliveryTemplateId(1L).setSkuId(30L).setCount(1).setSelected(false) .setWeight(10d).setVolume(10d).setPrice(300) )); // 保证价格被初始化上 @@ -77,13 +75,13 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // 准备收件地址数据 addressResp = randomPojo(AddressRespDTO.class, item -> item.setAreaId(10)); // 准备运费模板费用配置数据 - chargeBO = randomPojo(DeliveryExpressTemplateChargeBO.class, + chargeBO = randomPojo(DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO.class, item -> item.setStartCount(10D).setStartPrice(1000).setExtraCount(10D).setExtraPrice(2000)); // 准备运费模板包邮配置数据 订单总件数 < 包邮件数时 12 < 20 - freeBO = randomPojo(DeliveryExpressTemplateFreeBO.class, + freeBO = randomPojo(DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO.class, item -> item.setFreeCount(20).setFreePrice(100)); // 准备 SP 运费模板 数据 - spuTemplateRespBO = randomPojo(SpuDeliveryExpressTemplateRespBO.class, + templateRespBO = randomPojo(DeliveryExpressTemplateRespBO.class, item -> item.setChargeMode(PIECE.getType()) .setTemplateCharge(chargeBO).setTemplateFree(freeBO)); } @@ -94,12 +92,12 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // SKU 1 : 100 * 2 = 200 // SKU 2 :200 * 10 = 2000 // 运费 首件 1000 + 续件 2000 = 3000 - Map respMap = new HashMap<>(); - respMap.put(1L, spuTemplateRespBO); + Map respMap = new HashMap<>(); + respMap.put(1L, templateRespBO); // mock 方法 when(addressApi.getAddress(eq(10L), eq(1L))).thenReturn(addressResp); - when(deliveryExpressTemplateService.getExpressTemplateMapBySpuIdsAndArea(eq(asSet(1L)), eq(10))) + when(deliveryExpressTemplateService.getExpressTemplateMapByIdsAndArea(eq(asSet(1L)), eq(10))) .thenReturn(respMap); calculator.calculate(reqBO, resultBO); @@ -131,15 +129,15 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // SKU 1 : 100 * 2 = 200 // SKU 2 :200 * 10 = 2000 // 运费 0 - Map respMap = new HashMap<>(); - respMap.put(1L, spuTemplateRespBO); + Map respMap = new HashMap<>(); + respMap.put(1L, templateRespBO); // 准备运费模板包邮配置数据 包邮 订单总件数 > 包邮件数时 12 > 10 - freeBO = randomPojo(DeliveryExpressTemplateFreeBO.class, + freeBO = randomPojo(DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO.class, item -> item.setFreeCount(10).setFreePrice(1000)); - spuTemplateRespBO.setTemplateFree(freeBO); + templateRespBO.setTemplateFree(freeBO); // mock 方法 when(addressApi.getAddress(eq(10L), eq(1L))).thenReturn(addressResp); - when(deliveryExpressTemplateService.getExpressTemplateMapBySpuIdsAndArea(eq(asSet(1L)), eq(10))) + when(deliveryExpressTemplateService.getExpressTemplateMapByIdsAndArea(eq(asSet(1L)), eq(10))) .thenReturn(respMap); calculator.calculate(reqBO, resultBO); From 1662d17fc97c824e5373c28809e5f6b075538ec5 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Thu, 15 Jun 2023 14:59:31 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=BF=AB=E9=80=92=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=20review=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 7 +- .../delivery/config/ExpressClientConfig.java | 31 ++++++++ ...rties.java => TradeExpressProperties.java} | 17 ++--- .../delivery/core/ExpressQueryClient.java | 24 ------- .../delivery/core/ExpressQueryProvider.java | 22 ------ .../core/ExpressQueryProviderFactory.java | 19 ----- .../delivery/core/client/ExpressClient.java | 23 ++++++ .../ExpressClientEnum.java} | 13 ++-- .../core/client/ExpressClientFactory.java | 23 ++++++ .../client/convert/ExpressQueryConvert.java | 27 +++++++ .../{ => client}/dto/ExpressQueryReqDTO.java | 5 +- .../{ => client}/dto/ExpressQueryRespDTO.java | 2 +- .../dto}/kd100/Kd100ExpressQueryReqDTO.java | 5 +- .../dto}/kd100/Kd100ExpressQueryRespDTO.java | 2 +- .../dto}/kdniao/KdNiaoExpressQueryReqDTO.java | 5 +- .../kdniao/KdNiaoExpressQueryRespDTO.java | 2 +- .../client/impl/ExpressClientFactoryImpl.java | 56 +++++++++++++++ .../impl/Kd100ExpressClient.java} | 70 ++++++++----------- .../impl/KdNiaoExpressClient.java} | 67 ++++++++---------- .../client/impl/NoProvideExpressClient.java | 22 ++++++ .../core/convert/ExpressQueryConvert.java | 27 ------- .../core/impl/ExpressQueryClientImpl.java | 65 ----------------- .../impl/ExpressQueryProviderFactoryImpl.java | 48 ------------- .../impl/Kd100ExpressClientTest.java} | 26 +++---- .../impl/KdNiaoExpressClientTest.java} | 24 +++---- .../impl/NoProvideExpressClientTest.java | 52 ++++++++++++++ .../application-trade-delivery-query.yaml | 18 ----- .../test/resources/application-unit-test.yaml | 8 +++ 28 files changed, 351 insertions(+), 359 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/{TradeExpressQueryProperties.java => TradeExpressProperties.java} (70%) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{ExpressQueryProviderEnum.java => client/ExpressClientEnum.java} (58%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{ => client}/dto/ExpressQueryReqDTO.java (71%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{ => client}/dto/ExpressQueryRespDTO.java (81%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{dto/provider => client/dto}/kd100/Kd100ExpressQueryReqDTO.java (80%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{dto/provider => client/dto}/kd100/Kd100ExpressQueryRespDTO.java (93%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{dto/provider => client/dto}/kdniao/KdNiaoExpressQueryReqDTO.java (74%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{dto/provider => client/dto}/kdniao/KdNiaoExpressQueryRespDTO.java (94%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{impl/Kd100ExpressQueryProvider.java => client/impl/Kd100ExpressClient.java} (58%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{impl/KdNiaoExpressQueryProvider.java => client/impl/KdNiaoExpressClient.java} (62%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{impl/Kd100ExpressQueryProviderTest.java => client/impl/Kd100ExpressClientTest.java} (62%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{impl/KdNiaoExpressQueryProviderTest.java => client/impl/KdNiaoExpressClientTest.java} (61%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 800b5f239..12d921a88 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -51,9 +51,10 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011003001, "已经存在该编码的快递公司"); ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011003002, "运费模板不存在"); ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); - ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003006, "快递查询接口异常"); - ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003007, "快递查询返回失败, 原因:{}"); - ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003008, "自提门店不存在"); + ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003004, "快递查询接口异常"); + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003005, "快递查询返回失败, 原因:{}"); + ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011003006, "需要接入快递服务商,比如【快递100】"); + ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003007, "自提门店不存在"); // ========== Price 相关 1011004000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011004000, "支付价格计算异常,原因:价格小于等于 0"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java new file mode 100644 index 000000000..e93c0a70b --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.config; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.ExpressClientFactoryImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +/** + * 快递客户端端配置类, 提供快递客户端工厂,默认的快递客户端实现 + * + * @author jason + */ +@Configuration( + proxyBeanMethods = false +) +public class ExpressClientConfig { + + @Bean + public ExpressClientFactory expressClientFactory(TradeExpressProperties tradeExpressProperties, + RestTemplate restTemplate) { + return new ExpressClientFactoryImpl(tradeExpressProperties, restTemplate); + } + + @Bean + public ExpressClient defaultExpressClient(ExpressClientFactory expressClientFactory) { + return expressClientFactory.getDefaultExpressClient(); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java similarity index 70% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java index be0f93414..5f593df8b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.trade.framework.delivery.config; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @@ -9,27 +9,24 @@ import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; -// TODO @jason:TradeExpressProperties;更通用哈 // TODO @芋艿:未来要不要放数据库中?考虑 saas 多租户时,不同租户使用不同的配置? /** - * 交易快递查询的配置项 + * 交易运费快递的配置项 * * @author jason */ @Component -@ConfigurationProperties(prefix = "yudao.trade.express.query") +@ConfigurationProperties(prefix = "yudao.trade.express") @Data @Validated -public class TradeExpressQueryProperties { +public class TradeExpressProperties { /** - * 快递查询服务商 + * 快递客户端 * - * 如果未配置,默认使用快递鸟 + * 默认不提供,需要提醒用户配置一个快递服务商。 */ - // TODO @jason:可以把 expressQueryProvider 改成 client 变量,更简洁一点; - private ExpressQueryProviderEnum expressQueryProvider; // TODO @jaosn:默认值可以通过属性直接赋值哈; - // TODO @jason:需要考虑下,用户只配置了其中一个; + private ExpressClientEnum client = ExpressClientEnum.NOT_PROVIDE; /** * 快递鸟配置 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java deleted file mode 100644 index 1494bb2e5..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core; - -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; - -import java.util.List; - -// TODO @jason:可以改成 ExpressClient,未来可能还对接别的接口噢 -/** - * 快递查询客户端 - * - * @author jason - */ -public interface ExpressQueryClient { - - /** - * 快递实时查询 - * - * @param reqDTO 查询请求参数 - */ - // TODO @jason:可以改成 getExpressTrackList。返回字段可以参考 https://doc.youzanyun.com/detail/API/0/5 响应的 data - List realTimeQuery(ExpressQueryReqDTO reqDTO); - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java deleted file mode 100644 index e741e1426..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core; - -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; - -import java.util.List; - -/** - * 快递查询服务商 - * - * @author jason - */ -public interface ExpressQueryProvider { - - /** - * 快递实时查询 - * - * @param reqDTO 查询请求参数 - */ - List realTimeQueryExpress(ExpressQueryReqDTO reqDTO); - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java deleted file mode 100644 index bad2c6a5d..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core; - -/** - * 快递服务商工厂,用于创建和缓存快递服务商服务 - * - * @author jason - */ -public interface ExpressQueryProviderFactory { - - /** - * 通过枚举获取快递查询服务商 - * - * 如果不存在,就创建一个对应的快递查询服务商 - * - * @param queryProviderEnum 快递服务商枚举 - */ - ExpressQueryProvider getOrCreateExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum); - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java new file mode 100644 index 000000000..b670313c5 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.client; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; + +import java.util.List; + +/** + * 快递客户端接口 + * + * @author jason + */ +public interface ExpressClient { + + /** + * 快递实时查询 + * + * @param reqDTO 查询请求参数 + */ + // TODO @jason:返回字段可以参考 https://doc.youzanyun.com/detail/API/0/5 响应的 data + List getExpressTrackList(ExpressQueryReqDTO reqDTO); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java similarity index 58% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java index 48dab7eec..756252e61 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java @@ -1,16 +1,15 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client; import lombok.Getter; /** - * 快递查询服务商枚举 + * 快递客户端枚举 * * @author jason */ @Getter - -public enum ExpressQueryProviderEnum { - +public enum ExpressClientEnum { + NOT_PROVIDE("not-provide","未提供"), KD_NIAO("kd-niao", "快递鸟"), KD_100("kd-100", "快递100"); @@ -24,10 +23,8 @@ public enum ExpressQueryProviderEnum { */ private final String name; - // TODO @jaosn:@AllArgsConstructor 可以替代哈 - ExpressQueryProviderEnum(String code, String name) { + ExpressClientEnum(String code, String name) { this.code = code; this.name = name; } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java new file mode 100644 index 000000000..f6a54dd8f --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.client; + +/** + * 快递客户端工厂接口,快递客户端工厂:用于创建和缓存快递客户端 + * + * @author jason + */ +public interface ExpressClientFactory { + + /** + * 获取默认的快递客户端 + */ + ExpressClient getDefaultExpressClient(); + + /** + * 通过枚举获取快递客户端,如果不存在,就创建一个对应快递客户端 + * + * @param clientEnum 快递客户端枚举 + */ + ExpressClient getOrCreateExpressClient(ExpressClientEnum clientEnum); + + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java new file mode 100644 index 000000000..14a2c1c98 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.convert; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryRespDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ExpressQueryConvert { + + ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class); + + List convertList(List expressTrackList); + + List convertList2(List expressTrackList); + + KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); + + Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java similarity index 71% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java index ffa72c532..ea579a170 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.dto; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import lombok.Data; @@ -16,8 +16,7 @@ public class ExpressQueryReqDTO { * * 对应 {@link DeliveryExpressDO#getCode()} */ - // TODO @jaosn:要不改成 expressCode;项目里使用这个哈 - private String expressCompanyCode; + private String expressCode; /** * 发货快递单号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java similarity index 81% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java index 0bdb386c4..a2aad9025 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.dto; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryReqDTO.java similarity index 80% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryReqDTO.java index d1b72426f..78bdada31 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryReqDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -13,12 +13,11 @@ import lombok.Data; @JsonInclude(JsonInclude.Include.NON_NULL) public class Kd100ExpressQueryReqDTO { - // TODO @jaosn:要不改成 expressCode;项目里使用这个哈 /** * 快递公司编码 */ @JsonProperty("com") - private String expressCompanyCode; + private String expressCode; /** * 快递单号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java similarity index 93% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java index f7e5bdf04..6a301f4e4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryReqDTO.java similarity index 74% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryReqDTO.java index 21b1abc58..bcb6e3353 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryReqDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -13,12 +13,11 @@ import lombok.Data; @JsonInclude(JsonInclude.Include.NON_NULL) public class KdNiaoExpressQueryReqDTO { - // TODO @jaosn:要不改成 expressCode;项目里使用这个哈 /** * 快递公司编码 */ @JsonProperty("ShipperCode") - private String expressCompanyCode; + private String expressCode; /** * 快递单号 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryRespDTO.java similarity index 94% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryRespDTO.java index 3e8883bbd..877b1206d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryRespDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java new file mode 100644 index 000000000..96666bfef --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; + +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 快递客户端工厂实现类 + * + * @author jason + */ +public class ExpressClientFactoryImpl implements ExpressClientFactory { + + private final Map clientMap = new ConcurrentHashMap<>(8); + + private final TradeExpressProperties tradeExpressProperties; + private final RestTemplate restTemplate; + + public ExpressClientFactoryImpl(TradeExpressProperties tradeExpressProperties, + RestTemplate restTemplate) { + this.tradeExpressProperties = tradeExpressProperties; + this.restTemplate = restTemplate; + } + + @Override + public ExpressClient getDefaultExpressClient() { + ExpressClient defaultClient = getOrCreateExpressClient(tradeExpressProperties.getClient()); + Assert.notNull("默认的快递客户端不能为空"); + return defaultClient; + } + + @Override + public ExpressClient getOrCreateExpressClient(ExpressClientEnum clientEnum) { + return clientMap.computeIfAbsent(clientEnum, + client -> createExpressClient(client, tradeExpressProperties)); + } + + private ExpressClient createExpressClient(ExpressClientEnum queryProviderEnum, + TradeExpressProperties tradeExpressProperties) { + switch (queryProviderEnum) { + case NOT_PROVIDE: + return new NoProvideExpressClient(); + case KD_NIAO: + return new KdNiaoExpressClient(restTemplate, tradeExpressProperties.getKdNiao()); + case KD_100: + return new Kd100ExpressClient(restTemplate, tradeExpressProperties.getKd100()); + } + return null; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java similarity index 58% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java index 4227cebc8..930d5d8d9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java @@ -1,15 +1,16 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.HexUtil; import cn.hutool.crypto.digest.DigestUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.*; import org.springframework.util.LinkedMultiValueMap; @@ -23,48 +24,41 @@ import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_ERROR; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; -import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE; +import static cn.iocoder.yudao.module.trade.framework.delivery.core.client.convert.ExpressQueryConvert.INSTANCE; -// TODO @jason:可以参考 KdNiaoExpressQueryProvider 建议改改哈 /** - * 快递 100 服务商 + * 快递 100 客户端 * * @author jason */ @Slf4j -public class Kd100ExpressQueryProvider implements ExpressQueryProvider { +@AllArgsConstructor +public class Kd100ExpressClient implements ExpressClient { private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do"; - private final RestTemplate restTemplate; - private final TradeExpressQueryProperties.Kd100Config config; - - public Kd100ExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.Kd100Config config) { - this.restTemplate = restTemplate; - this.config = config; - } + private final TradeExpressProperties.Kd100Config config; @Override - public List realTimeQueryExpress(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { // 发起查询 Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO); - kd100ReqParam.setExpressCompanyCode(kd100ReqParam.getExpressCompanyCode().toLowerCase()); // 快递公司编码需要转成小写 - Kd100ExpressQueryRespDTO respDTO = sendExpressQueryReq(REAL_TIME_QUERY_URL, kd100ReqParam, + kd100ReqParam.setExpressCode(kd100ReqParam.getExpressCode().toLowerCase()); // 快递公司编码需要转成小写 + Kd100ExpressQueryRespDTO respDTO = requestExpressQuery(REAL_TIME_QUERY_URL, kd100ReqParam, Kd100ExpressQueryRespDTO.class); - log.debug("[realTimeQueryExpress][快递 100 接口 查询接口返回 {}]", respDTO); + log.debug("[getExpressTrackList][快递 100 接口 查询接口返回 {}]", respDTO); // 处理结果 if (Objects.equals("false", respDTO.getResult())) { - log.error("[realTimeQueryExpress][快递 100 接口 返回失败 {}]", respDTO.getMessage()); + log.error("[getExpressTrackList][快递 100 接口 返回失败 {}]", respDTO.getMessage()); throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage()); - // TODO @json:else 可以不用写哈; - } else { - // TODO @jason:convertList2 如果空,应该返回 list 了; - if (CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList2(respDTO.getTracks()); - } else { - return Collections.emptyList(); - } } + // TODO @jason:convertList2 如果空,应该返回 list 了; @芋艿 为了避免返回 null + if (CollUtil.isNotEmpty(respDTO.getTracks())) { + return INSTANCE.convertList2(respDTO.getTracks()); + } else { + return Collections.emptyList(); + } + } /** @@ -76,8 +70,7 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { * @param 每个请求的请求结构 Req DTO * @param 每个请求的响应结构 Resp DTO */ - // TODO @jason:可以改成 request,发起请求哈; - private Resp sendExpressQueryReq(String url, Req req, Class respClass) { + private Resp requestExpressQuery(String url, Req req, Class respClass) { // 请求头 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); @@ -92,23 +85,20 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { log.debug("[sendExpressQueryReq][快递 100 接口的请求参数: {}]", requestBody); // 发送请求 HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - // TODO @jason:可以使用 restTemplate 的 post 方法哇? + // TODO @jason:可以使用 restTemplate 的 post 方法哇 @芋艿 为了获取接口的原始返回。用exchange 便于查问题。 ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); log.debug("[sendExpressQueryReq][快递 100 接口响应结果 {}]", responseEntity); // 处理响应 - // TODO @jason:if return 原则;if (!responseEntity.getStatusCode().is2xxSuccessful()) 抛出异常;接着处理成功的 - if (responseEntity.getStatusCode().is2xxSuccessful()) { - String response = responseEntity.getBody(); - return JsonUtils.parseObject(response, respClass); - } else { + if (!responseEntity.getStatusCode().is2xxSuccessful()) { throw exception(EXPRESS_API_QUERY_ERROR); } + return JsonUtils.parseObject(responseEntity.getBody(), respClass); } private String generateReqSign(String param, String key, String customer) { String plainText = String.format("%s%s%s", param, key, customer); - // TODO @jason:DigestUtil.md5Hex(plainText); + // TODO @芋艿。 这里需要转换成大写, 没有对应方法 return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java similarity index 62% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java index 4ca5f6142..1e5e5f535 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java @@ -1,16 +1,17 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.net.URLEncodeUtil; import cn.hutool.crypto.digest.DigestUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryRespDTO; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.*; import org.springframework.util.LinkedMultiValueMap; @@ -23,15 +24,16 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_ERROR; -import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE; +import static cn.iocoder.yudao.module.trade.framework.delivery.core.client.convert.ExpressQueryConvert.INSTANCE; /** - * 快递鸟服务商 + * 快递鸟客户端 * * @author jason */ @Slf4j -public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { +@AllArgsConstructor +public class KdNiaoExpressClient implements ExpressClient { private static final String REAL_TIME_QUERY_URL = "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx"; @@ -39,15 +41,8 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { * 快递鸟即时查询免费版 RequestType */ private static final String REAL_TIME_FREE_REQ_TYPE = "1002"; - private final RestTemplate restTemplate; - private final TradeExpressQueryProperties.KdNiaoConfig config; - - // TODO @jason:可以改成 lombok 哈 - public KdNiaoExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.KdNiaoConfig config) { - this.restTemplate = restTemplate; - this.config = config; - } + private final TradeExpressProperties.KdNiaoConfig config; /** * 快递鸟即时查询免费版本 @@ -56,21 +51,20 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { * @param reqDTO 查询请求参数 */ @Override - public List realTimeQueryExpress(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { KdNiaoExpressQueryReqDTO kdNiaoReqData = INSTANCE.convert(reqDTO); // 快递公司编码需要转成大写 - kdNiaoReqData.setExpressCompanyCode(reqDTO.getExpressCompanyCode().toUpperCase()); - KdNiaoExpressQueryRespDTO respDTO = sendKdNiaoApiRequest(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, + kdNiaoReqData.setExpressCode(reqDTO.getExpressCode().toUpperCase()); + KdNiaoExpressQueryRespDTO respDTO = requestKdNiaoApi(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, kdNiaoReqData, KdNiaoExpressQueryRespDTO.class); - log.debug("[realTimeQueryExpress][快递鸟即时查询接口返回 {}]", respDTO); - if(!respDTO.getSuccess()){ - throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getReason()); - }else{ - if (CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList(respDTO.getTracks()); - }else{ - return Collections.emptyList(); - } + log.debug("[getExpressTrackList][快递鸟即时查询接口返回 {}]", respDTO); + if (respDTO == null || !respDTO.getSuccess()) { + throw exception(EXPRESS_API_QUERY_FAILED, respDTO == null ? "" : respDTO.getReason()); + } + if (CollUtil.isNotEmpty(respDTO.getTracks())) { + return INSTANCE.convertList(respDTO.getTracks()); + } else { + return Collections.emptyList(); } } @@ -83,8 +77,8 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { * @param 每个请求的请求结构 Req DTO * @param 每个请求的响应结构 Resp DTO */ - private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, - Class respClass){ + private Resp requestKdNiaoApi(String url, String requestType, Req req, + Class respClass){ // 请求头 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); @@ -97,19 +91,16 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { requestBody.add("EBusinessID", config.getBusinessId()); requestBody.add("DataSign", dataSign); requestBody.add("RequestType", requestType); - log.debug("[sendKdNiaoApiRequest][快递鸟接口 RequestType : {}, 的请求参数 {}]", requestType, requestBody); - + log.debug("[requestKdNiaoApi][快递鸟接口 RequestType : {}, 的请求参数 {}]", requestType, requestBody); // 发送请求 HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); log.debug("快递鸟接口 RequestType : {}, 的响应结果 {}", requestType, responseEntity); // 处理响应 - if (responseEntity.getStatusCode().is2xxSuccessful()) { - String response = responseEntity.getBody(); - return JsonUtils.parseObject(response, respClass); - } else { + if (!responseEntity.getStatusCode().is2xxSuccessful()) { throw exception(EXPRESS_API_QUERY_ERROR); } + return JsonUtils.parseObject(responseEntity.getBody(), respClass); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java new file mode 100644 index 000000000..b4b9403a7 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_CLIENT_NOT_PROVIDE; + +/** + * 未实现的快递客户端,用来提醒用户需要接入快递服务商, + * + * @author jason + */ +public class NoProvideExpressClient implements ExpressClient { + @Override + public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + throw exception(EXPRESS_CLIENT_NOT_PROVIDE); + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java deleted file mode 100644 index 615f84b4e..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.convert; - -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryRespDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface ExpressQueryConvert { - - ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class); - - List convertList(List expressTrackList); - - List convertList2(List expressTrackList); - - KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); - - Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto); - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java deleted file mode 100644 index 59dfc77c1..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; - -import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderFactory; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import java.util.List; - -import static cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum.KD_NIAO; - -// TODO @jason:可以把整体包结构调整下;参考 sms client 的方式; -// + config -// + core -// client -// + dto -// + impl:里面可以放 kdniaoclient、kd100client -// ExpressClient -// ExpressClientFactory: 通过它直接获取默认和创建默认的 Client -// enums -/** - * 快递查询客户端实现 - * - * @author jason - */ -@Component -@Slf4j -public class ExpressQueryClientImpl implements ExpressQueryClient { - - @Resource - private ExpressQueryProviderFactory expressQueryProviderFactory; - @Resource - private TradeExpressQueryProperties tradeExpressQueryProperties; - - private ExpressQueryProvider expressQueryProvider; - - @PostConstruct - private void init() { - // 如果未设置,默认使用快递鸟 - ExpressQueryProviderEnum queryProvider = tradeExpressQueryProperties.getExpressQueryProvider(); - if (queryProvider == null) { - queryProvider = KD_NIAO; - } - // 创建客户端 - expressQueryProvider = expressQueryProviderFactory.getOrCreateExpressQueryProvider(queryProvider); - if (expressQueryProvider == null) { - log.error("获取创建快递查询服务商{}失败,请检查相关配置", queryProvider); - } - Assert.notNull(expressQueryProvider, "快递查询服务商不能为空"); - } - - @Override - public List realTimeQuery(ExpressQueryReqDTO reqDTO) { - return expressQueryProvider.realTimeQueryExpress(reqDTO); - } - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java deleted file mode 100644 index b6ce8d68a..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; - -import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum; -import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderFactory; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - -import javax.annotation.Resource; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * // TODO @jason:注释不全 - * @author jason - */ -@Component -public class ExpressQueryProviderFactoryImpl implements ExpressQueryProviderFactory { - - private final Map providerMap = new ConcurrentHashMap<>(8); - - @Resource - private TradeExpressQueryProperties tradeExpressQueryProperties; - @Resource - private RestTemplate restTemplate; - - @Override - public ExpressQueryProvider getOrCreateExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum) { - return providerMap.computeIfAbsent(queryProviderEnum, - provider -> createExpressQueryProvider(provider, tradeExpressQueryProperties)); - } - - private ExpressQueryProvider createExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum, - TradeExpressQueryProperties tradeExpressQueryProperties) { - // TODO @jason:是不是直接 return 就好啦,更简洁一点 - ExpressQueryProvider result = null; - switch (queryProviderEnum) { - case KD_NIAO: - result = new KdNiaoExpressQueryProvider(restTemplate, tradeExpressQueryProperties.getKdNiao()); - break; - case KD_100: - result = new Kd100ExpressQueryProvider(restTemplate, tradeExpressQueryProperties.getKd100()); - break; - } - return result; - } -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java similarity index 62% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java index 0d82f745b..6fa41e314 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.framework.common.exception.ServiceException; -import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -21,36 +21,36 @@ import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author jason */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = Kd100ExpressQueryProviderTest.Application.class) -@ActiveProfiles("trade-delivery-query") // 设置使用 trade-delivery-query 配置文件 -public class Kd100ExpressQueryProviderTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = Kd100ExpressClientTest.Application.class) +@ActiveProfiles("unit-test") // 设置使用 trade-delivery-query 配置文件 +public class Kd100ExpressClientTest { @Resource private RestTemplateBuilder builder; @Resource - private TradeExpressQueryProperties expressQueryProperties; + private TradeExpressProperties expressQueryProperties; - private Kd100ExpressQueryProvider kd100ExpressQueryProvider; + private Kd100ExpressClient kd100ExpressClient; @BeforeEach public void init(){ - kd100ExpressQueryProvider = new Kd100ExpressQueryProvider(builder.build(),expressQueryProperties.getKd100()); + kd100ExpressClient = new Kd100ExpressClient(builder.build(),expressQueryProperties.getKd100()); } @Test @Disabled("需要 授权 key. 暂时忽略") void testRealTimeQueryExpressFailed() { ServiceException t = assertThrows(ServiceException.class, () -> { ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); - reqDTO.setExpressCompanyCode("yto"); + reqDTO.setExpressCode("yto"); reqDTO.setLogisticsNo("YT9383342193097"); - kd100ExpressQueryProvider.realTimeQueryExpress(reqDTO); + kd100ExpressClient.getExpressTrackList(reqDTO); }); - assertEquals(1011003007, t.getCode()); + assertEquals(1011003005, t.getCode()); } @Import({ RestTemplateAutoConfiguration.class }) - @EnableConfigurationProperties(TradeExpressQueryProperties.class) + @EnableConfigurationProperties(TradeExpressProperties.class) public static class Application { } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java similarity index 61% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java index 8f6615678..ebf38d0b7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.framework.common.exception.ServiceException; -import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -21,35 +21,35 @@ import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author jason */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressQueryProviderTest.Application.class) -@ActiveProfiles("trade-delivery-query") // 设置使用 trade-delivery-query 配置文件 TODO @jason:可以直接写到 application-unit-test.yaml 配置文件里 -public class KdNiaoExpressQueryProviderTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressClientTest.Application.class) +@ActiveProfiles("unit-test") +public class KdNiaoExpressClientTest { @Resource private RestTemplateBuilder builder; @Resource - private TradeExpressQueryProperties expressQueryProperties; + private TradeExpressProperties expressQueryProperties; - private KdNiaoExpressQueryProvider kdNiaoExpressQueryProvider; + private KdNiaoExpressClient kdNiaoExpressClient; @BeforeEach public void init(){ - kdNiaoExpressQueryProvider = new KdNiaoExpressQueryProvider(builder.build(),expressQueryProperties.getKdNiao()); + kdNiaoExpressClient = new KdNiaoExpressClient(builder.build(),expressQueryProperties.getKdNiao()); } @Test @Disabled("需要 授权 key. 暂时忽略") void testRealTimeQueryExpressFailed() { assertThrows(ServiceException.class,() ->{ ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); - reqDTO.setExpressCompanyCode("yy"); + reqDTO.setExpressCode("yy"); reqDTO.setLogisticsNo("YT9383342193097"); - kdNiaoExpressQueryProvider.realTimeQueryExpress(reqDTO); + kdNiaoExpressClient.getExpressTrackList(reqDTO); }); } @Import({ RestTemplateAutoConfiguration.class }) - @EnableConfigurationProperties(TradeExpressQueryProperties.class) + @EnableConfigurationProperties(TradeExpressProperties.class) public static class Application { } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java new file mode 100644 index 000000000..76b8cd6b4 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; + +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.module.trade.framework.delivery.config.ExpressClientConfig; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author jason + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = NoProvideExpressClientTest.Application.class) +@ActiveProfiles("unit-test") // 设置使用 trade-delivery-query 配置文件 +@Import({ExpressClientConfig.class}) +public class NoProvideExpressClientTest { + + @Resource + private ExpressClient expressClient; + + @Test + void getExpressTrackList() { + ServiceException t = assertThrows(ServiceException.class, () -> { + expressClient.getExpressTrackList(null); + }); + assertEquals(1011003006, t.getCode()); + } + + @Import({ + RestTemplateAutoConfiguration.class, + }) + @EnableConfigurationProperties(TradeExpressProperties.class) + public static class Application { + + @Bean + private RestTemplate restTemplate(RestTemplateBuilder builder) { + return builder.build(); + } + } +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml deleted file mode 100644 index e01cb1652..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml +++ /dev/null @@ -1,18 +0,0 @@ -spring: - main: - lazy-initialization: true # 开启懒加载,加快速度 - banner-mode: off # 单元测试,禁用 Banner - ---- #################### 交易快递查询相关配置 #################### - -yudao: - trade: - express: - query: - express-query-provider: kd_niao - kd-niao: - api-key: xxx - business-id: xxxxxxxx - kd100: - customer: xxxx - key: xxxxx diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml index 19dd0e97b..b548da6a3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-unit-test.yaml @@ -51,3 +51,11 @@ yudao: order: app-id: 1 merchant-order-id: 1 + express: + kd-niao: + api-key: xxxx + business-id: xxxxx + kd100: + customer: xxxxx + key: xxxxx + client: not_provide \ No newline at end of file From af9334c9b23567a79e091fede55cd977358227ac Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 16 Jun 2023 00:12:49 +0800 Subject: [PATCH 05/11] =?UTF-8?q?mall=20+=20trade=EF=BC=9Amock=20=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E8=AE=B0=E5=BD=95=E8=AF=A6=E6=83=85=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... => AppCombinationActivityController.java} | 8 +- .../AppCombinationRecordController.java | 78 +++++++++++++++++++ .../AppCombinationActivityDetailRespVO.java | 21 ++--- .../AppCombinationRecordDetailRespVO.java | 21 +++++ .../AppCombinationRecordSimpleRespVO.java | 30 +++++++ .../vo/AppSeckillActivitiDetailRespVO.java | 3 - 6 files changed, 140 insertions(+), 21 deletions(-) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/{AppCombinationController.java => AppCombinationActivityController.java} (92%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java similarity index 92% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationController.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index cd6d142a2..ba4c01e9a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -21,7 +21,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/promotion/combination-activity") @Validated -public class AppCombinationController { +public class AppCombinationActivityController { @GetMapping("/get-detail") @Operation(summary = "获得拼团活动明细") @@ -33,8 +33,10 @@ public class AppCombinationController { obj.setId(id); obj.setName("晚九点限时秒杀"); obj.setStatus(1); - obj.setStartTime(LocalDateTime.of(2023, 6, 11, 0, 0, 0)); - obj.setEndTime(LocalDateTime.of(2023, 6, 11, 23, 59, 0)); + obj.setStartTime(LocalDateTime.of(2023, 6, 15, 0, 0, 0)); + obj.setEndTime(LocalDateTime.of(2023, 6, 15, 23, 59, 0)); + obj.setUserSize(2); + obj.setSuccessCount(100); obj.setSpuId(633L); // 创建一个Product对象的列表 List productList = new ArrayList<>(); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java new file mode 100644 index 000000000..1e32111f1 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -0,0 +1,78 @@ +package cn.iocoder.yudao.module.promotion.controller.app.combination; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSimpleRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.constraints.Max; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 APP - 拼团活动") +@RestController +@RequestMapping("/promotion/combination-record") +@Validated +public class AppCombinationRecordController { + + @GetMapping("/get-head-list") + @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") + public CommonResult> getHeadCombinationRecordList( + @RequestParam("status") Integer status, + @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { + List list = new ArrayList<>(); + for (int i = 1; i <= count; i++) { + AppCombinationRecordSimpleRespVO record = new AppCombinationRecordSimpleRespVO(); + record.setId((long) i); + record.setNickname("用户" + i); + record.setAvatar("头像" + i); + record.setExpireTime(new Date()); + record.setUserSize(10); + record.setUserCount(i); + list.add(record); + } + return success(list); + } + + @GetMapping("/get-detail") + @Operation(summary = "获得拼团记录明细") + @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") + public CommonResult getCombinationRecordDetail(@RequestParam("id") Long id) { + AppCombinationRecordDetailRespVO detail = new AppCombinationRecordDetailRespVO(); + // 团长 + AppCombinationRecordSimpleRespVO headRecord = new AppCombinationRecordSimpleRespVO(); + headRecord.setId(1L); + headRecord.setNickname("用户" + 1); + headRecord.setAvatar("头像" + 1); + headRecord.setExpireTime(new Date()); + headRecord.setUserSize(10); + headRecord.setUserCount(3); + // 团员 + List list = new ArrayList<>(); + for (int i = 1; i <= 2; i++) { + AppCombinationRecordSimpleRespVO record = new AppCombinationRecordSimpleRespVO(); + record.setId((long) i); + record.setNickname("用户" + i); + record.setAvatar("头像" + i); + record.setExpireTime(new Date()); + record.setUserSize(10); + record.setUserCount(i); + list.add(record); + } + detail.setMemberRecords(list); + // 订单编号 + detail.setOrderId(100L); + return success(detail); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java index 553a31fd8..79e54d610 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java @@ -25,18 +25,18 @@ public class AppCombinationActivityDetailRespVO { @Schema(description = "活动结束时间", required = true) private LocalDateTime endTime; + @Schema(description = "拼团人数", required = true, example = "3") + private Integer userSize; + + @Schema(description = "成功的拼团数量", required = true, example = "100") + private Integer successCount; + @Schema(description = "商品 SPU 编号", required = true, example = "2048") private Long spuId; @Schema(description = "商品信息数组", required = true) private List products; - @Schema(description = "成功的拼团记录", required = true) - private List successRecords; - - @Schema(description = "进行中的拼团记录", required = true) - private List runningRecords; - @Schema(description = "商品信息") @Data public static class Product { @@ -55,13 +55,4 @@ public class AppCombinationActivityDetailRespVO { } - @Schema(description = "拼团记录") - @Data - public static class Record { - - @Schema(description = "拼团记录编号", required = true, example = "1024") - private Long id; - - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java new file mode 100644 index 000000000..120926ad6 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Schema(description = "用户 App - 拼团记录详细 Response VO") +@Data +public class AppCombinationRecordDetailRespVO { + + @Schema(description = "团长的拼团记录", required = true) + private AppCombinationRecordSimpleRespVO headRecord; + + @Schema(description = "成员的拼团记录", required = true) + private List memberRecords; + + @Schema(description = "当前用户参团记录对应的订单编号", required = true, example = "1024") // 如果没参团,返回 null + private Long orderId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java new file mode 100644 index 000000000..54177aeb8 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Date; + +@Schema(description = "用户 App - 拼团记录精简 Response VO") +@Data +public class AppCombinationRecordSimpleRespVO { + + @Schema(description = "拼团记录编号", required = true, example = "1024") + private Long id; + + @Schema(description = "用户昵称", required = true, example = "1024") + private String nickname; + + @Schema(description = "用户头像", required = true, example = "1024") + private String avatar; + + @Schema(description = "过期时间", required = true) + private Date expireTime; + + @Schema(description = "可参团人数", required = true, example = "10") + private Integer userSize; + + @Schema(description = "已参团人数", required = true, example = "5") + private Integer userCount; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java index a643fc1b3..0feeac6ff 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java @@ -27,9 +27,6 @@ public class AppSeckillActivitiDetailRespVO { @Schema(description = "活动结束时间", required = true) private LocalDateTime endTime; - - private Long successGruopCount; - @Schema(description = "商品 SPU 编号", required = true, example = "2048") private Long spuId; From 8ec373388250cf26b16094de895e5a414490ed3b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 16 Jun 2023 20:32:03 +0800 Subject: [PATCH 06/11] =?UTF-8?q?mall=20+=20trade=EF=BC=9Amock=20=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E8=AE=B0=E5=BD=95=E5=88=97=E8=A1=A8=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/date/DateUtils.java | 1 - .../AppCombinationRecordController.java | 29 ++++++++++++++----- .../AppCombinationRecordDetailRespVO.java | 4 +-- ...O.java => AppCombinationRecordRespVO.java} | 21 ++++++++++++-- .../vo/AppTradeOrderSettlementReqVO.java | 12 ++++++++ 5 files changed, 54 insertions(+), 13 deletions(-) rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/{AppCombinationRecordSimpleRespVO.java => AppCombinationRecordRespVO.java} (50%) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java index a329fb177..c2d069a59 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java @@ -55,7 +55,6 @@ public class DateUtils { return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); } - @Deprecated public static Date addTime(Duration duration) { return new Date(System.currentTimeMillis() + duration.toMillis()); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 1e32111f1..b9086f362 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; -import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSimpleRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.validation.constraints.Max; +import java.time.Duration; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -27,18 +29,23 @@ public class AppCombinationRecordController { @GetMapping("/get-head-list") @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") - public CommonResult> getHeadCombinationRecordList( + // TODO @芋艿:注解要补全 + public CommonResult> getHeadCombinationRecordList( + @RequestParam(value = "activityId", required = false) Long activityId, @RequestParam("status") Integer status, @RequestParam(value = "count", defaultValue = "20") @Max(20) Integer count) { - List list = new ArrayList<>(); + List list = new ArrayList<>(); for (int i = 1; i <= count; i++) { - AppCombinationRecordSimpleRespVO record = new AppCombinationRecordSimpleRespVO(); + AppCombinationRecordRespVO record = new AppCombinationRecordRespVO(); record.setId((long) i); record.setNickname("用户" + i); record.setAvatar("头像" + i); record.setExpireTime(new Date()); record.setUserSize(10); record.setUserCount(i); + record.setPicUrl("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); + record.setActivityId(1L); + record.setActivityName("活动:" + i); list.add(record); } return success(list); @@ -50,23 +57,29 @@ public class AppCombinationRecordController { public CommonResult getCombinationRecordDetail(@RequestParam("id") Long id) { AppCombinationRecordDetailRespVO detail = new AppCombinationRecordDetailRespVO(); // 团长 - AppCombinationRecordSimpleRespVO headRecord = new AppCombinationRecordSimpleRespVO(); + AppCombinationRecordRespVO headRecord = new AppCombinationRecordRespVO(); headRecord.setId(1L); headRecord.setNickname("用户" + 1); headRecord.setAvatar("头像" + 1); - headRecord.setExpireTime(new Date()); + headRecord.setExpireTime(DateUtils.addTime(Duration.ofDays(1))); headRecord.setUserSize(10); headRecord.setUserCount(3); + headRecord.setStatus(1); + headRecord.setActivityId(10L); + headRecord.setPicUrl("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); + headRecord.setCombinationPrice(100); + detail.setHeadRecord(headRecord); // 团员 - List list = new ArrayList<>(); + List list = new ArrayList<>(); for (int i = 1; i <= 2; i++) { - AppCombinationRecordSimpleRespVO record = new AppCombinationRecordSimpleRespVO(); + AppCombinationRecordRespVO record = new AppCombinationRecordRespVO(); record.setId((long) i); record.setNickname("用户" + i); record.setAvatar("头像" + i); record.setExpireTime(new Date()); record.setUserSize(10); record.setUserCount(i); + record.setStatus(1); list.add(record); } detail.setMemberRecords(list); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java index 120926ad6..dae83ea9c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordDetailRespVO.java @@ -10,10 +10,10 @@ import java.util.List; public class AppCombinationRecordDetailRespVO { @Schema(description = "团长的拼团记录", required = true) - private AppCombinationRecordSimpleRespVO headRecord; + private AppCombinationRecordRespVO headRecord; @Schema(description = "成员的拼团记录", required = true) - private List memberRecords; + private List memberRecords; @Schema(description = "当前用户参团记录对应的订单编号", required = true, example = "1024") // 如果没参团,返回 null private Long orderId; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java similarity index 50% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java index 54177aeb8..0f591bcff 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSimpleRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java @@ -5,13 +5,16 @@ import lombok.Data; import java.util.Date; -@Schema(description = "用户 App - 拼团记录精简 Response VO") +@Schema(description = "用户 App - 拼团记录 Response VO") @Data -public class AppCombinationRecordSimpleRespVO { +public class AppCombinationRecordRespVO { @Schema(description = "拼团记录编号", required = true, example = "1024") private Long id; + @Schema(description = "拼团活动编号", required = true, example = "1024") + private Long activityId; + @Schema(description = "用户昵称", required = true, example = "1024") private String nickname; @@ -27,4 +30,18 @@ public class AppCombinationRecordSimpleRespVO { @Schema(description = "已参团人数", required = true, example = "5") private Integer userCount; + @Schema(description = "拼团状态", required = true, example = "1") + private Integer status; + + @Schema(description = "商品图片", required = true, example = "https://www.iocoder.cn/1.png") + private String picUrl; + + @Schema(description = "拼团金额,单位:分", required = true, example = "100") + private Integer combinationPrice; + + // ========== 获得最近 n 条拼团记录(团长发起的)返回的字段 ========== + + @Schema(description = "拼团活动名字", required = true, example = "1024") + private String activityName; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java index 0324b492b..4a21bbc63 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java @@ -18,6 +18,7 @@ public class AppTradeOrderSettlementReqVO { @NotNull(message = "交易类型不能为空") @InEnum(value = TradeOrderTypeEnum.class, message = "交易类型必须是 {value}") + @Deprecated // TODO 芋艿:后续干掉这个字段,对于前端不需要关注这个 private Integer type; @Schema(description = "商品项数组", required = true) @@ -30,6 +31,17 @@ public class AppTradeOrderSettlementReqVO { @Schema(description = "优惠劵编号", example = "1024") private Long couponId; + // ========== 秒杀活动相关字段 ========== + @Schema(description = "秒杀活动编号", example = "1024") + private Long seckillActivityId; + + // ========== 拼团活动相关字段 ========== + @Schema(description = "拼团活动编号", example = "1024") + private Long combinationActivityId; + + @Schema(description = "拼团团长编号", example = "2048") + private Long combinationHeadId; + @Data @Schema(description = "用户 App - 商品项") @Valid From 5b324f90a4d5a1d544eae275b0666aa327c2e272 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 16 Jun 2023 23:27:27 +0800 Subject: [PATCH 07/11] =?UTF-8?q?mall=20+=20promotion=EF=BC=9Amock=20?= =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppCombinationActivityController.java | 32 ++++++++++++++++++- .../AppCombinationRecordController.java | 2 +- .../AppCombinationActivityPageItemRespVO.java | 31 ++++++++++++++++++ .../vo/record/AppCombinationRecordRespVO.java | 8 ++--- 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index ba4c01e9a..43680baa0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityPageItemRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -23,10 +26,37 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppCombinationActivityController { + @GetMapping("/page") + @Operation(summary = "获得拼团活动分页") + public CommonResult> getCombinationActivityPage(PageParam pageParam) { + List activityList = new ArrayList<>(); + AppCombinationActivityPageItemRespVO activity1 = new AppCombinationActivityPageItemRespVO(); + activity1.setId(1L); + activity1.setName("618 大拼团"); + activity1.setUserSize(3); + activity1.setSpuId(2048L); + activity1.setPicUrl("商品图片地址"); + activity1.setMarketPrice(50); + activity1.setCombinationPrice(100); + activityList.add(activity1); + + AppCombinationActivityPageItemRespVO activity2 = new AppCombinationActivityPageItemRespVO(); + activity2.setId(2L); + activity2.setName("双十一拼团"); + activity2.setUserSize(5); + activity2.setSpuId(4096L); + activity2.setPicUrl("商品图片地址"); + activity2.setMarketPrice(100); + activity2.setCombinationPrice(200); + activityList.add(activity2); + + return success(new PageResult<>(activityList, 2L)); + } + @GetMapping("/get-detail") @Operation(summary = "获得拼团活动明细") @Parameter(name = "id", description = "活动编号", required = true, example = "1024") - public CommonResult getCombinationActivity(@RequestParam("id") Long id) { + public CommonResult getCombinationActivityDetail(@RequestParam("id") Long id) { // TODO 芋艿:如果禁用的时候,需要抛出异常; AppCombinationActivityDetailRespVO obj = new AppCombinationActivityDetailRespVO(); // 设置其属性的值 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index b9086f362..657fe8b9c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -45,7 +45,7 @@ public class AppCombinationRecordController { record.setUserCount(i); record.setPicUrl("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); record.setActivityId(1L); - record.setActivityName("活动:" + i); + record.setSpuName("活动:" + i); list.add(record); } return success(list); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java new file mode 100644 index 000000000..090a5f190 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 App - 拼团活动分页项 Response VO") +@Data +public class AppCombinationActivityPageItemRespVO { + + @Schema(description = "拼团活动编号", required = true, example = "1024") + private Long id; + + @Schema(description = "拼团活动名称", required = true, example = "618 大拼团") + private String name; + + @Schema(description = "拼团人数", required = true, example = "3") + private Integer userSize; + + @Schema(description = "商品 SPU 编号", required = true, example = "2048") + private Long spuId; + + @Schema(description = "商品图片", required = true, example = "4096") // 从 SPU 的 picUrl 读取 + private String picUrl; + + @Schema(description = "商品市场价,单位:分", required = true, example = "50") // 从 SPU 的 marketPrice 读取 + private Integer marketPrice; + + @Schema(description = "拼团金额,单位:分", required = true, example = "100") // 从拼团商品里取最低价 + private Integer combinationPrice; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java index 0f591bcff..143271b3b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordRespVO.java @@ -33,15 +33,13 @@ public class AppCombinationRecordRespVO { @Schema(description = "拼团状态", required = true, example = "1") private Integer status; + @Schema(description = "商品名字", required = true, example = "我是大黄豆") + private String spuName; + @Schema(description = "商品图片", required = true, example = "https://www.iocoder.cn/1.png") private String picUrl; @Schema(description = "拼团金额,单位:分", required = true, example = "100") private Integer combinationPrice; - // ========== 获得最近 n 条拼团记录(团长发起的)返回的字段 ========== - - @Schema(description = "拼团活动名字", required = true, example = "1024") - private String activityName; - } From 07fe52939d1cb24654e1cfabe8c289a84a414611 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 17 Jun 2023 00:47:47 +0800 Subject: [PATCH 08/11] =?UTF-8?q?mall=20+=20promotion=EF=BC=9Amock=20banne?= =?UTF-8?q?r=20mock=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/banner/vo/BannerRespVO.java | 12 +---- .../app/banner/AppBannerController.java | 40 ++++++++--------- .../app/banner/vo/AppBannerRespVO.java | 20 +++++++++ .../AppCombinationActivityController.java | 44 ++++++++++++++++--- .../AppCombinationRecordController.java | 18 ++++++++ ...java => AppCombinationActivityRespVO.java} | 4 +- .../AppCombinationRecordSummaryRespVO.java | 18 ++++++++ 7 files changed, 116 insertions(+), 40 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/vo/AppBannerRespVO.java rename yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/{AppCombinationActivityPageItemRespVO.java => AppCombinationActivityRespVO.java} (89%) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/banner/vo/BannerRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/banner/vo/BannerRespVO.java index f07644e8a..b1ea6c207 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/banner/vo/BannerRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/banner/vo/BannerRespVO.java @@ -4,22 +4,12 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.ToString; -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -/** - * @author xia - */ @Schema(description = "管理后台 - Banner Response VO") @Data @ToString(callSuper = true) public class BannerRespVO extends BannerBaseVO { - @Schema(description = "banner编号", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "banner编号不能为空") + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED) private Long id; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/AppBannerController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/AppBannerController.java index 4bc094598..3a4ff8a78 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/AppBannerController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/AppBannerController.java @@ -1,42 +1,42 @@ package cn.iocoder.yudao.module.promotion.controller.app.banner; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.promotion.controller.admin.banner.vo.BannerRespVO; -import cn.iocoder.yudao.module.promotion.convert.banner.BannerConvert; -import cn.iocoder.yudao.module.promotion.dal.dataobject.banner.BannerDO; -import cn.iocoder.yudao.module.promotion.service.banner.BannerService; +import cn.iocoder.yudao.module.promotion.controller.app.banner.vo.AppBannerRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -/** - * @author: XIA - */ @RestController -@RequestMapping("/market/banner") -@Tag(name = "用户APP- 首页Banner") +@RequestMapping("/promotion/banner") +@Tag(name = "用户 APP - 首页 Banner") @Validated public class AppBannerController { - @Resource - private BannerService bannerService; - - // TODO @xia:新建一个 AppBannerRespVO,只返回必要的字段。status 要过滤下。然后 sort 下结果 @GetMapping("/list") - @Operation(summary = "获得banner列表") - @PreAuthorize("@ss.hasPermission('market:banner:query')") - public CommonResult> getBannerList() { - List list = bannerService.getBannerList(); - return success(BannerConvert.INSTANCE.convertList(list)); + @Operation(summary = "获得 banner 列表") + // todo @芋艿:swagger 注解,待补全 + // TODO @芋艿:可以增加缓存,提升性能 + // TODO @芋艿:position = 1 时,首页;position = 10 时,拼团活动页 + public CommonResult> getBannerList(@RequestParam("position") Integer position) { + List bannerList = new ArrayList<>(); + AppBannerRespVO banner1 = new AppBannerRespVO(); + banner1.setUrl("https://www.example.com/link1"); + banner1.setPicUrl("https://api.java.crmeb.net/crmebimage/public/content/2022/08/04/0f78716213f64bfa83f191d51a832cbf73f6axavoy.jpg"); + bannerList.add(banner1); + AppBannerRespVO banner2 = new AppBannerRespVO(); + banner2.setUrl("https://www.example.com/link2"); + banner2.setPicUrl("https://api.java.crmeb.net/crmebimage/public/content/2023/01/11/be09e755268b43ee90b0db3a3e1b7132r7a6t2wvsm.jpg"); + bannerList.add(banner2); + return success(bannerList); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/vo/AppBannerRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/vo/AppBannerRespVO.java new file mode 100644 index 000000000..7656a431d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/banner/vo/AppBannerRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.controller.app.banner.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Schema(description = "用户 App - Banner Response VO") +@Data +public class AppBannerRespVO { + + @Schema(description = "跳转链接", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "跳转链接不能为空") + private String url; + + @Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "图片地址不能为空") + private String picUrl; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 43680baa0..2f9d23278 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO; -import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityPageItemRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -26,11 +26,14 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppCombinationActivityController { - @GetMapping("/page") - @Operation(summary = "获得拼团活动分页") - public CommonResult> getCombinationActivityPage(PageParam pageParam) { - List activityList = new ArrayList<>(); - AppCombinationActivityPageItemRespVO activity1 = new AppCombinationActivityPageItemRespVO(); + @GetMapping("/list") + @Operation(summary = "获得拼团活动列表", description = "用于小程序首页") + // TODO 芋艿:增加 Spring Cache + // TODO 芋艿:缺少 swagger 注解 + public CommonResult> getCombinationActivityList( + @RequestParam(name = "count", defaultValue = "6") Integer count) { + List activityList = new ArrayList<>(); + AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO(); activity1.setId(1L); activity1.setName("618 大拼团"); activity1.setUserSize(3); @@ -40,7 +43,34 @@ public class AppCombinationActivityController { activity1.setCombinationPrice(100); activityList.add(activity1); - AppCombinationActivityPageItemRespVO activity2 = new AppCombinationActivityPageItemRespVO(); + AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO(); + activity2.setId(2L); + activity2.setName("双十一拼团"); + activity2.setUserSize(5); + activity2.setSpuId(4096L); + activity2.setPicUrl("商品图片地址"); + activity2.setMarketPrice(100); + activity2.setCombinationPrice(200); + activityList.add(activity2); + + return success(activityList); + } + + @GetMapping("/page") + @Operation(summary = "获得拼团活动分页") + public CommonResult> getCombinationActivityPage(PageParam pageParam) { + List activityList = new ArrayList<>(); + AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO(); + activity1.setId(1L); + activity1.setName("618 大拼团"); + activity1.setUserSize(3); + activity1.setSpuId(2048L); + activity1.setPicUrl("商品图片地址"); + activity1.setMarketPrice(50); + activity1.setCombinationPrice(100); + activityList.add(activity1); + + AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO(); activity2.setId(2L); activity2.setName("双十一拼团"); activity2.setUserSize(5); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 657fe8b9c..0c1c8510d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordDetailRespVO; import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordRespVO; +import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -27,6 +28,23 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppCombinationRecordController { + @GetMapping("/get-summary") + @Operation(summary = "获得拼团活动的概要信息", description = "用于小程序首页") + // TODO 芋艿:增加 @Cache 缓存,1 分钟过期 + public CommonResult getCombinationSummary() { + AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); + summary.setUserCount(1024); + summary.setAvatars(new ArrayList<>()); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLjFK35Wvia9lJKHoXfQuHhk0qZbvpPNxrAiaEKF7aL2k4I8kuqrdTWwliamdPHeyAA7DjAg725X2GIQ/132"); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTK1pXgdj5DvBMwrbe8v3tFibSWeQATEsAibt3fllD8XwJ460P2r6KS3WCQvDefuv1bVpDhNCle6CTCA/132"); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTL7KRGHBE62N0awFyBesmmxiaCicf1fJ7E7UCh6zA8GWlT1QC1zT01gG4OxI7BWDESkdPZ5o7tno4hA/132"); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/ouwtwJycbic2JrCoZjETict0klxd1uRuicRneKk00ewMcCClxVcVHQT91Sh9MJGtwibf1fOicD1WpwSP4icJM6eQq1AA/132"); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/RpUrhwens58qc99OcGs993xL4M5QPOe05ekqF9Eia440kRicAlicicIdQWicHBmy2bzLgHzHguWEzHHxnIgeictL7bLA/132"); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/S4tfqmxc8GZGsKc1K4mnhpvtG16gtMrLnTQfDibhr7jJich9LRI5RQKZDoqEjZM3azMib5nic7F4ZXKMEgYyLO08KA/132"); + summary.getAvatars().add("https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKXMYJOomfp7cebz3cIeb8sHk3GGSIJtWEgREe3j7J1WoAbTvIOicpcNdFkWAziatBSMod8b5RyS4CQ/132"); + return success(summary); + } + @GetMapping("/get-head-list") @Operation(summary = "获得最近 n 条拼团记录(团长发起的)") // TODO @芋艿:注解要补全 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java similarity index 89% rename from yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java rename to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java index 090a5f190..1c3139a1e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityPageItemRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityRespVO.java @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -@Schema(description = "用户 App - 拼团活动分页项 Response VO") +@Schema(description = "用户 App - 拼团活动 Response VO") @Data -public class AppCombinationActivityPageItemRespVO { +public class AppCombinationActivityRespVO { @Schema(description = "拼团活动编号", required = true, example = "1024") private Long id; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java new file mode 100644 index 000000000..a071620a4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/record/AppCombinationRecordSummaryRespVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Schema(description = "用户 App - 拼团记录的简要概括 Response VO") +@Data +public class AppCombinationRecordSummaryRespVO { + + @Schema(description = "拼团用户数量", required = true, example = "1024") + private Integer userCount; + + @Schema(description = "拼团用户头像列表", required = true) // 只返回最近的 7 个 + private List avatars; + +} From 59d5fef59277919dd5929045f0f7d9d09d12d20c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 17 Jun 2023 11:35:31 +0800 Subject: [PATCH 09/11] =?UTF-8?q?mall=20+=20trade=EF=BC=9A=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=BF=90=E8=B4=B9=E6=A8=A1=E7=89=88=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 34 ++++---- .../DeliveryExpressTemplateConvert.java | 27 +++++- .../DeliveryExpressTemplateChargeMapper.java | 5 +- .../DeliveryExpressTemplateFreeMapper.java | 6 +- .../delivery/DeliveryExpressServiceImpl.java | 2 +- .../DeliveryExpressTemplateService.java | 3 +- .../DeliveryExpressTemplateServiceImpl.java | 28 ++----- .../bo/DeliveryExpressTemplateRespBO.java | 9 +- .../service/order/TradeOrderServiceImpl.java | 2 +- .../TradeDeliveryPriceCalculator.java | 15 ++-- .../TradeDeliveryPriceCalculatorTest.java | 83 +++++++++---------- 11 files changed, 112 insertions(+), 102 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 12d921a88..ae7a0a501 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -45,19 +45,25 @@ public interface ErrorCodeConstants { // ========== Cart 模块 1011002000 ========== ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1011002000, "购物车项不存在"); - // ========== 物流配送模块 1011003000 ========== - ErrorCode DELIVERY_EXPRESS_NOT_EXISTS = new ErrorCode(1011003000, "快递公司不存在"); - // TODO @jason:最好每个模块一段哈。express 一个;exmpresstemplate 一个;pickup 一个 - ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011003001, "已经存在该编码的快递公司"); - ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011003002, "运费模板不存在"); - ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); - ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003004, "快递查询接口异常"); - ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003005, "快递查询返回失败, 原因:{}"); - ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011003006, "需要接入快递服务商,比如【快递100】"); - ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003007, "自提门店不存在"); + // ========== Price 相关 1011003000 ============ + ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011003000, "支付价格计算异常,原因:价格小于等于 0"); + ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); + ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); + + // ========== 物流 Express 模块 1011004000 ========== + ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); + ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011004001, "已经存在该编码的快递公司"); + ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004002, "快递查询接口异常"); + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004003, "快递查询返回失败,原因:{}"); + ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004004, "需要接入快递服务商,比如【快递100】"); + + // ========== 物流 Template 模块 1011005000 ========== + ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011005000, "已经存在该运费模板名"); + ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011005001, "运费模板不存在"); + + // ========== 物流 PICK_UP 模块 1011006000 ========== + + ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011006000, "自提门店不存在"); + - // ========== Price 相关 1011004000 ============ - ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011004000, "支付价格计算异常,原因:价格小于等于 0"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY = new ErrorCode(1011004001, "计算快递运费异常,收件人地址编号为空"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011004002, "计算快递运费异常,找不到对应的运费模板"); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java index bbd57c62e..665dc787d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/delivery/DeliveryExpressTemplateConvert.java @@ -7,10 +7,15 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemp import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateFreeDO; import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; +import com.google.common.collect.Maps; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; @Mapper public interface DeliveryExpressTemplateConvert { @@ -48,7 +53,7 @@ public interface DeliveryExpressTemplateConvert { DeliveryExpressTemplateChargeDO convertTemplateCharge(DeliveryExpressTemplateUpdateReqVO.ExpressTemplateChargeUpdateVO vo); - DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO convertTemplateCharge(DeliveryExpressTemplateChargeDO bean); + DeliveryExpressTemplateRespBO.Charge convertTemplateCharge(DeliveryExpressTemplateChargeDO bean); default List convertTemplateChargeList(Long templateId, Integer chargeMode, List list) { return CollectionUtils.convertList(list, vo -> convertTemplateCharge(templateId, chargeMode, vo)); @@ -60,7 +65,7 @@ public interface DeliveryExpressTemplateConvert { DeliveryExpressTemplateFreeDO convertTemplateFree(DeliveryExpressTemplateUpdateReqVO.ExpressTemplateFreeUpdateVO vo); - DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO convertTemplateFree(DeliveryExpressTemplateFreeDO bean); + DeliveryExpressTemplateRespBO.Free convertTemplateFree(DeliveryExpressTemplateFreeDO bean); List convertTemplateChargeList(List list); @@ -70,4 +75,22 @@ public interface DeliveryExpressTemplateConvert { return CollectionUtils.convertList(list, vo -> convertTemplateFree(templateId, vo)); } + default Map convertMap(Integer areaId, List templateList, + List chargeList, + List freeList) { + Map> templateIdChargeMap = convertMultiMap(chargeList, + DeliveryExpressTemplateChargeDO::getTemplateId); + Map> templateIdFreeMap = convertMultiMap(freeList, + DeliveryExpressTemplateFreeDO::getTemplateId); + // 组合运费模板配置 RespBO + Map result = Maps.newHashMapWithExpectedSize(templateList.size()); + templateList.forEach(template -> { + DeliveryExpressTemplateRespBO bo = new DeliveryExpressTemplateRespBO() + .setChargeMode(template.getChargeMode()) + .setCharge(convertTemplateCharge(findFirst(templateIdChargeMap.get(template.getId()), charge -> charge.getAreaIds().contains(areaId)))) + .setFree(convertTemplateFree(findFirst(templateIdFreeMap.get(template.getId()), free -> free.getAreaIds().contains(areaId)))); + result.put(template.getId(), bo); + }); + return result; + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java index 985b418ac..a2403f019 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateChargeMapper.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.dal.mysql.delivery; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateChargeDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -24,9 +23,9 @@ public interface DeliveryExpressTemplateChargeMapper extends BaseMapperX selectByTemplateIds(Collection templateIds) { - return selectList(new LambdaQueryWrapperX() - .inIfPresent(DeliveryExpressTemplateChargeDO::getTemplateId, templateIds)); + return selectList(DeliveryExpressTemplateChargeDO::getTemplateId, templateIds); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java index 5cc407354..b64a3c979 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/delivery/DeliveryExpressTemplateFreeMapper.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.dal.mysql.delivery; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressTemplateFreeDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -22,9 +21,8 @@ public interface DeliveryExpressTemplateFreeMapper extends BaseMapperX selectListByTemplateIds(Collection ids) { - return selectList(new LambdaQueryWrapperX() - .inIfPresent(DeliveryExpressTemplateFreeDO::getTemplateId, ids)); + default List selectListByTemplateIds(Collection templateIds) { + return selectList(DeliveryExpressTemplateFreeDO::getTemplateId, templateIds); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java index a396a389a..2f08b0b3f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressServiceImpl.java @@ -75,7 +75,7 @@ public class DeliveryExpressServiceImpl implements DeliveryExpressService { } private void validateDeliveryExpressExists(Long id) { if (deliveryExpressMapper.selectById(id) == null) { - throw exception(DELIVERY_EXPRESS_NOT_EXISTS); + throw exception(EXPRESS_NOT_EXISTS); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java index 39edd823e..c455701b2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java @@ -84,11 +84,12 @@ public interface DeliveryExpressTemplateService { DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); /** - * 基于运费模板编号数组和收件人地址区域编号. 获取匹配运费模板 + * 基于运费模板编号数组和收件人地址区域编号,获取匹配运费模板 * * @param ids 编号列表 * @param areaId 区域编号 * @return Map (templateId -> 运费模板设置) */ Map getExpressTemplateMapByIdsAndArea(Collection ids, Integer areaId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java index c4aa22b8f..0cfe5e815 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java @@ -224,36 +224,26 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla @Override public Map getExpressTemplateMapByIdsAndArea(Collection ids, Integer areaId) { Assert.notNull(areaId, "区域编号 {} 不能为空", areaId); + // 查询 template 数组 if (CollUtil.isEmpty(ids)) { return Collections.emptyMap(); } List templateList = expressTemplateMapper.selectBatchIds(ids); - // 查询 templateCharge - List templeChargeList = expressTemplateChargeMapper.selectByTemplateIds(ids); - Map> templateChargeMap = convertMultiMap(templeChargeList, - DeliveryExpressTemplateChargeDO::getTemplateId); - // 查询 templateFree - List templateFreeList = expressTemplateFreeMapper.selectListByTemplateIds(ids); - Map> templateFreeMap = convertMultiMap(templateFreeList, - DeliveryExpressTemplateFreeDO::getTemplateId); + // 查询 templateCharge 数组 + List chargeList = expressTemplateChargeMapper.selectByTemplateIds(ids); + // 查询 templateFree 数组 + List freeList = expressTemplateFreeMapper.selectListByTemplateIds(ids); + // 组合运费模板配置 RespBO - Map result = new HashMap<>(templateList.size()); - templateList.forEach(item -> { - DeliveryExpressTemplateRespBO bo = new DeliveryExpressTemplateRespBO() - .setChargeMode(item.getChargeMode()) - .setTemplateCharge(findMatchExpressTemplateCharge(templateChargeMap.get(item.getId()), areaId)) - .setTemplateFree(findMatchExpressTemplateFree(templateFreeMap.get(item.getId()), areaId)); - result.put(item.getId(), bo); - }); - return result; + return INSTANCE.convertMap(areaId, templateList, chargeList, freeList); } - private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO findMatchExpressTemplateCharge( + private DeliveryExpressTemplateRespBO.Charge findMatchExpressTemplateCharge( List templateChargeList, Integer areaId) { return INSTANCE.convertTemplateCharge(findFirst(templateChargeList, item -> item.getAreaIds().contains(areaId))); } - private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO findMatchExpressTemplateFree( + private DeliveryExpressTemplateRespBO.Free findMatchExpressTemplateFree( List templateFreeList, Integer areaId) { return INSTANCE.convertTemplateFree(findFirst(templateFreeList, item -> item.getAreaIds().contains(areaId))); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java index 6c8764a5c..db0af04eb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/DeliveryExpressTemplateRespBO.java @@ -21,12 +21,12 @@ public class DeliveryExpressTemplateRespBO { /** * 运费模板快递运费设置 */ - private DeliveryExpressTemplateChargeBO templateCharge; + private Charge charge; /** * 运费模板包邮设置 */ - private DeliveryExpressTemplateFreeBO templateFree; + private Free free; /** * 快递运费模板费用配置 BO @@ -34,7 +34,7 @@ public class DeliveryExpressTemplateRespBO { * @author jason */ @Data - public static class DeliveryExpressTemplateChargeBO { + public static class Charge { /** * 首件数量(件数,重量,或体积) @@ -60,7 +60,7 @@ public class DeliveryExpressTemplateRespBO { * @author jason */ @Data - public static class DeliveryExpressTemplateFreeBO { + public static class Free { /** * 包邮金额,单位:分 @@ -76,4 +76,5 @@ public class DeliveryExpressTemplateRespBO { */ private Integer freeCount; } + } 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 7cd6fe87b..d90be3031 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 @@ -342,7 +342,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // TODO 芋艿:logisticsId 校验存在 发货物流公司 fix DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId()); if (deliveryExpress == null) { - throw exception(DELIVERY_EXPRESS_NOT_EXISTS); + throw exception(EXPRESS_NOT_EXISTS); } // 更新 TradeOrderDO 状态为已发货,等待收货 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 1a0598c63..35a3cb92a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -77,7 +77,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { List orderItems = entry.getValue(); DeliveryExpressTemplateRespBO templateBO = expressTemplateMap.get(templateId); if (templateBO == null) { - log.error("不能计算快递运费。不能找到 templateId : {}. 对应的运费模板配置 Resp BO", templateId); + log.error("[calculateDeliveryPrice][不能计算快递运费,找不到 templateId({}) 对应的运费模板配置]", templateId); continue; } // 总件数, 总金额, 总重量, 总体积 @@ -93,12 +93,12 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { } // 优先判断是否包邮. 如果包邮不计算快递运费 if (isExpressFree(templateBO.getChargeMode(), totalCount, totalWeight, - totalVolume, totalPrice, templateBO.getTemplateFree())) { + totalVolume, totalPrice, templateBO.getFree())) { continue; } // 计算快递运费 calculateExpressFeeByChargeMode(totalCount, totalWeight, totalVolume, - templateBO.getChargeMode(), templateBO.getTemplateCharge(), orderItems); + templateBO.getChargeMode(), templateBO.getCharge(), orderItems); } TradePriceCalculatorHelper.recountAllPrice(result); @@ -115,10 +115,10 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * @param orderItems SKU 商品项目 */ private void calculateExpressFeeByChargeMode(double totalCount, double totalWeight, double totalVolume, - int chargeMode, DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO templateCharge, + int chargeMode, DeliveryExpressTemplateRespBO.Charge templateCharge, List orderItems) { if (templateCharge == null) { - log.error("计算快递运费时,不能找到对应的快递运费模板费用配置。无法计算以下商品 SKU 项目运费: {}", orderItems); + log.error("[calculateExpressFeeByChargeMode][计算快递运费时,找不到 SKU({}) 对应的运费模版]", orderItems); return; } DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode); @@ -145,7 +145,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * @param templateCharge 快递运费配置 * @param orderItems SKU 商品项目 */ - private void calculateExpressFee(double total, DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO templateCharge, List orderItems) { + private void calculateExpressFee(double total, DeliveryExpressTemplateRespBO.Charge templateCharge, List orderItems) { int deliveryPrice; if (total <= templateCharge.getStartCount()) { deliveryPrice = templateCharge.getStartPrice(); @@ -174,7 +174,6 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { for (OrderItem item : orderItems) { // 更新快递运费 item.setDeliveryPrice(dividePrice); - TradePriceCalculatorHelper.recountPayPrice(item); } } @@ -190,7 +189,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * @param templateFree 包邮配置 */ private boolean isExpressFree(Integer chargeMode, int totalCount, double totalWeight, - double totalVolume, int totalPrice, DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO templateFree) { + double totalVolume, int totalPrice, DeliveryExpressTemplateRespBO.Free templateFree) { if (templateFree == null) { return false; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java index 99fdac64e..1f408cf47 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; +import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressTemplateService; import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; @@ -14,20 +17,17 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; -import static cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum.PIECE; -import static cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum.EXPRESS; import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static org.assertj.core.api.Assertions.assertThat; - /** + * {@link TradeDeliveryPriceCalculator} 的单元测试 + * * @author jason */ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { @@ -41,22 +41,22 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { private TradePriceCalculateReqBO reqBO; private TradePriceCalculateRespBO resultBO; - private AddressRespDTO addressResp; - private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO chargeBO; - private DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO freeBO; + private DeliveryExpressTemplateRespBO templateRespBO; + private DeliveryExpressTemplateRespBO.Charge chargeBO; + private DeliveryExpressTemplateRespBO.Free freeBO; @BeforeEach public void init(){ // 准备参数 reqBO = new TradePriceCalculateReqBO() - .setDeliveryType(EXPRESS.getMode()) + .setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode()) .setAddressId(10L) .setUserId(1L) .setItems(asList( new TradePriceCalculateReqBO.Item().setSkuId(10L).setCount(2).setSelected(true), new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(10).setSelected(true), - new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(false) + new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(false) // 未选中 )); resultBO = new TradePriceCalculateRespBO() .setPrice(new TradePriceCalculateRespBO.Price()) @@ -72,18 +72,21 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // 保证价格被初始化上 TradePriceCalculatorHelper.recountPayPrice(resultBO.getItems()); TradePriceCalculatorHelper.recountAllPrice(resultBO); + // 准备收件地址数据 - addressResp = randomPojo(AddressRespDTO.class, item -> item.setAreaId(10)); + AddressRespDTO addressResp = randomPojo(AddressRespDTO.class, item -> item.setAreaId(10)); + when(addressApi.getAddress(eq(10L), eq(1L))).thenReturn(addressResp); + // 准备运费模板费用配置数据 - chargeBO = randomPojo(DeliveryExpressTemplateRespBO.DeliveryExpressTemplateChargeBO.class, + chargeBO = randomPojo(DeliveryExpressTemplateRespBO.Charge.class, item -> item.setStartCount(10D).setStartPrice(1000).setExtraCount(10D).setExtraPrice(2000)); - // 准备运费模板包邮配置数据 订单总件数 < 包邮件数时 12 < 20 - freeBO = randomPojo(DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO.class, + // 准备运费模板包邮配置数据:订单总件数 < 包邮件数时 12 < 20 + freeBO = randomPojo(DeliveryExpressTemplateRespBO.Free.class, item -> item.setFreeCount(20).setFreePrice(100)); - // 准备 SP 运费模板 数据 + // 准备 SP 运费模板数据 templateRespBO = randomPojo(DeliveryExpressTemplateRespBO.class, - item -> item.setChargeMode(PIECE.getType()) - .setTemplateCharge(chargeBO).setTemplateFree(freeBO)); + item -> item.setChargeMode(DeliveryExpressChargeModeEnum.PIECE.getType()) + .setCharge(chargeBO).setFree(freeBO)); } @Test @@ -92,32 +95,27 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // SKU 1 : 100 * 2 = 200 // SKU 2 :200 * 10 = 2000 // 运费 首件 1000 + 续件 2000 = 3000 - Map respMap = new HashMap<>(); - respMap.put(1L, templateRespBO); - // mock 方法 - when(addressApi.getAddress(eq(10L), eq(1L))).thenReturn(addressResp); when(deliveryExpressTemplateService.getExpressTemplateMapByIdsAndArea(eq(asSet(1L)), eq(10))) - .thenReturn(respMap); + .thenReturn(MapUtil.of(1L, templateRespBO)); + // 调用 calculator.calculate(reqBO, resultBO); - + // 断言 TradePriceCalculateRespBO.Price price = resultBO.getPrice(); - assertThat(price) .extracting("totalPrice","discountPrice","couponPrice","pointPrice","deliveryPrice","payPrice") .containsExactly(2200, 0, 0, 0, 3000, 5200); - // 断言:SKU assertThat(resultBO.getItems()).hasSize(3); - // SKU1 + // 断言:SKU1 assertThat(resultBO.getItems().get(0)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") .containsExactly(100, 2, 0, 0, 0, 1500, 1700); - // SKU2 + // 断言:SKU2 assertThat(resultBO.getItems().get(1)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") .containsExactly(200, 10, 0, 0, 0, 1500, 3500); - // SKU3 未选中 + // 断言:SKU3 未选中 assertThat(resultBO.getItems().get(2)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") .containsExactly(300, 1, 0, 0, 0, 0, 300); @@ -129,38 +127,33 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // SKU 1 : 100 * 2 = 200 // SKU 2 :200 * 10 = 2000 // 运费 0 - Map respMap = new HashMap<>(); - respMap.put(1L, templateRespBO); - // 准备运费模板包邮配置数据 包邮 订单总件数 > 包邮件数时 12 > 10 - freeBO = randomPojo(DeliveryExpressTemplateRespBO.DeliveryExpressTemplateFreeBO.class, - item -> item.setFreeCount(10).setFreePrice(1000)); - templateRespBO.setTemplateFree(freeBO); // mock 方法 - when(addressApi.getAddress(eq(10L), eq(1L))).thenReturn(addressResp); + // 准备运费模板包邮配置数据 包邮 订单总件数 > 包邮件数时 12 > 10 + templateRespBO.setFree(randomPojo(DeliveryExpressTemplateRespBO.Free.class, + item -> item.setFreeCount(10).setFreePrice(1000))); when(deliveryExpressTemplateService.getExpressTemplateMapByIdsAndArea(eq(asSet(1L)), eq(10))) - .thenReturn(respMap); + .thenReturn(MapUtil.of(1L, templateRespBO)); + // 调用 calculator.calculate(reqBO, resultBO); - + // 断言 TradePriceCalculateRespBO.Price price = resultBO.getPrice(); - - // 断言price assertThat(price) .extracting("totalPrice","discountPrice","couponPrice","pointPrice","deliveryPrice","payPrice") .containsExactly(2200, 0, 0, 0, 0, 2200); - // 断言:SKU assertThat(resultBO.getItems()).hasSize(3); - // SKU1 + // 断言:SKU1 assertThat(resultBO.getItems().get(0)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") .containsExactly(100, 2, 0, 0, 0, 0, 200); - // SKU2 + // 断言:SKU2 assertThat(resultBO.getItems().get(1)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") .containsExactly(200, 10, 0, 0, 0, 0, 2000); - // SKU3 未选中 + // 断言:SKU3 未选中 assertThat(resultBO.getItems().get(2)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") .containsExactly(300, 1, 0, 0, 0, 0, 300); } -} \ No newline at end of file + +} From 0d47d6cead6ad1c56c4bbfdaaab5f54e71c965d3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 17 Jun 2023 11:59:38 +0800 Subject: [PATCH 10/11] =?UTF-8?q?mall=20+=20trade=EF=BC=9Acode=20review=20?= =?UTF-8?q?=E5=BF=AB=E9=80=92=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=8C=E6=B2=A1=E5=95=A5=E9=97=AE=E9=A2=98=E5=92=A7?= =?UTF-8?q?=EF=BC=8C=E6=90=9E=E4=B8=8B=E5=8D=95=E6=B5=8B=E5=B0=B1=20ok=20?= =?UTF-8?q?=E6=8B=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 7 ++++--- .../delivery/config/ExpressClientConfig.java | 9 +++++---- .../config/TradeExpressProperties.java | 3 ++- .../delivery/core/client/ExpressClient.java | 6 +++--- .../core/client/ExpressClientFactory.java | 5 +++-- .../client/convert/ExpressQueryConvert.java | 12 +++++------ ...qDTO.java => ExpressTrackQueryReqDTO.java} | 4 ++-- ...yRespDTO.java => ExpressTrackRespDTO.java} | 2 +- .../client/impl/ExpressClientFactoryImpl.java | 12 +++++------ .../client/impl/NoProvideExpressClient.java | 8 +++++--- .../impl/{ => kd100}/Kd100ExpressClient.java | 19 ++++++++---------- .../{ => kdniao}/KdNiaoExpressClient.java | 20 ++++++++++--------- .../{client => enums}/ExpressClientEnum.java | 10 ++++------ .../client/impl/Kd100ExpressClientTest.java | 9 ++++++--- .../client/impl/KdNiaoExpressClientTest.java | 10 +++++++--- .../impl/NoProvideExpressClientTest.java | 3 ++- 16 files changed, 74 insertions(+), 65 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/{ExpressQueryReqDTO.java => ExpressTrackQueryReqDTO.java} (87%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/{ExpressQueryRespDTO.java => ExpressTrackRespDTO.java} (91%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/{ => kd100}/Kd100ExpressClient.java (88%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/{ => kdniao}/KdNiaoExpressClient.java (90%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{client => enums}/ExpressClientEnum.java (68%) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ae7a0a501..1b3c73c30 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -53,9 +53,10 @@ public interface ErrorCodeConstants { // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011004001, "已经存在该编码的快递公司"); - ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004002, "快递查询接口异常"); - ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004003, "快递查询返回失败,原因:{}"); - ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004004, "需要接入快递服务商,比如【快递100】"); + ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004002, "需要接入快递服务商,比如【快递100】"); + + ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004101, "快递查询接口异常"); + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004102, "快递查询返回失败,原因:{}"); // ========== 物流 Template 模块 1011005000 ========== ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011005000, "已经存在该运费模板名"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java index e93c0a70b..2799c3f1c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java @@ -8,13 +8,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; /** - * 快递客户端端配置类, 提供快递客户端工厂,默认的快递客户端实现 + * 快递客户端端配置类: + * + * 1. 快递客户端工厂 {@link ExpressClientFactory} + * 2. 默认的快递客户端实现 {@link ExpressClient} * * @author jason */ -@Configuration( - proxyBeanMethods = false -) +@Configuration(proxyBeanMethods = false) public class ExpressClientConfig { @Bean diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java index 5f593df8b..795af0dee 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.trade.framework.delivery.config; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum; +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @@ -27,6 +27,7 @@ public class TradeExpressProperties { * 默认不提供,需要提醒用户配置一个快递服务商。 */ private ExpressClientEnum client = ExpressClientEnum.NOT_PROVIDE; + /** * 快递鸟配置 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java index b670313c5..76b361c3f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import java.util.List; @@ -18,6 +18,6 @@ public interface ExpressClient { * @param reqDTO 查询请求参数 */ // TODO @jason:返回字段可以参考 https://doc.youzanyun.com/detail/API/0/5 响应的 data - List getExpressTrackList(ExpressQueryReqDTO reqDTO); + List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java index f6a54dd8f..5e457092f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client; +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum; + /** - * 快递客户端工厂接口,快递客户端工厂:用于创建和缓存快递客户端 + * 快递客户端工厂接口:用于创建和缓存快递客户端 * * @author jason */ @@ -19,5 +21,4 @@ public interface ExpressClientFactory { */ ExpressClient getOrCreateExpressClient(ExpressClientEnum clientEnum); - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java index 14a2c1c98..1c8f76d73 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.convert; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO; @@ -16,12 +16,12 @@ public interface ExpressQueryConvert { ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class); - List convertList(List expressTrackList); + List convertList(List expressTrackList); - List convertList2(List expressTrackList); + List convertList2(List expressTrackList); - KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); + KdNiaoExpressQueryReqDTO convert(ExpressTrackQueryReqDTO dto); - Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto); + Kd100ExpressQueryReqDTO convert2(ExpressTrackQueryReqDTO dto); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java similarity index 87% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java index ea579a170..34ad0128d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java @@ -4,12 +4,12 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import lombok.Data; /** - * 快递查询 Req DTO + * 快递轨迹的查询 Req DTO * * @author jason */ @Data -public class ExpressQueryReqDTO { +public class ExpressTrackQueryReqDTO { /** * 快递公司编码 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java index a2aad9025..b6463ef1d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java @@ -8,7 +8,7 @@ import lombok.Data; * @author jason */ @Data -public class ExpressQueryRespDTO { +public class ExpressTrackRespDTO { // TODO @jason:LocalDateTime /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java index 96666bfef..d4432b264 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java @@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; +import lombok.AllArgsConstructor; import org.springframework.web.client.RestTemplate; import java.util.Map; @@ -15,6 +18,7 @@ import java.util.concurrent.ConcurrentHashMap; * * @author jason */ +@AllArgsConstructor public class ExpressClientFactoryImpl implements ExpressClientFactory { private final Map clientMap = new ConcurrentHashMap<>(8); @@ -22,12 +26,6 @@ public class ExpressClientFactoryImpl implements ExpressClientFactory { private final TradeExpressProperties tradeExpressProperties; private final RestTemplate restTemplate; - public ExpressClientFactoryImpl(TradeExpressProperties tradeExpressProperties, - RestTemplate restTemplate) { - this.tradeExpressProperties = tradeExpressProperties; - this.restTemplate = restTemplate; - } - @Override public ExpressClient getDefaultExpressClient() { ExpressClient defaultClient = getOrCreateExpressClient(tradeExpressProperties.getClient()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java index b4b9403a7..7289710f6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import java.util.List; @@ -15,8 +15,10 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_CLI * @author jason */ public class NoProvideExpressClient implements ExpressClient { + @Override - public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) { throw exception(EXPRESS_CLIENT_NOT_PROVIDE); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java similarity index 88% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java index 930d5d8d9..0b7e1dcbd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.HexUtil; @@ -6,8 +6,8 @@ import cn.hutool.crypto.digest.DigestUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO; import lombok.AllArgsConstructor; @@ -36,29 +36,28 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.client.conve public class Kd100ExpressClient implements ExpressClient { private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do"; + private final RestTemplate restTemplate; private final TradeExpressProperties.Kd100Config config; @Override - public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) { // 发起查询 Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO); kd100ReqParam.setExpressCode(kd100ReqParam.getExpressCode().toLowerCase()); // 快递公司编码需要转成小写 Kd100ExpressQueryRespDTO respDTO = requestExpressQuery(REAL_TIME_QUERY_URL, kd100ReqParam, Kd100ExpressQueryRespDTO.class); log.debug("[getExpressTrackList][快递 100 接口 查询接口返回 {}]", respDTO); + // 处理结果 if (Objects.equals("false", respDTO.getResult())) { log.error("[getExpressTrackList][快递 100 接口 返回失败 {}]", respDTO.getMessage()); throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage()); } - // TODO @jason:convertList2 如果空,应该返回 list 了; @芋艿 为了避免返回 null - if (CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList2(respDTO.getTracks()); - } else { + if (CollUtil.isEmpty(respDTO.getTracks())) { return Collections.emptyList(); } - + return INSTANCE.convertList2(respDTO.getTracks()); } /** @@ -85,7 +84,6 @@ public class Kd100ExpressClient implements ExpressClient { log.debug("[sendExpressQueryReq][快递 100 接口的请求参数: {}]", requestBody); // 发送请求 HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - // TODO @jason:可以使用 restTemplate 的 post 方法哇 @芋艿 为了获取接口的原始返回。用exchange 便于查问题。 ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); log.debug("[sendExpressQueryReq][快递 100 接口响应结果 {}]", responseEntity); @@ -98,7 +96,6 @@ public class Kd100ExpressClient implements ExpressClient { private String generateReqSign(String param, String key, String customer) { String plainText = String.format("%s%s%s", param, key, customer); - // TODO @芋艿。 这里需要转换成大写, 没有对应方法 return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java similarity index 90% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java index 1e5e5f535..52ebf72da 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; @@ -7,8 +7,8 @@ import cn.hutool.crypto.digest.DigestUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryRespDTO; import lombok.AllArgsConstructor; @@ -51,25 +51,27 @@ public class KdNiaoExpressClient implements ExpressClient { * @param reqDTO 查询请求参数 */ @Override - public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) { KdNiaoExpressQueryReqDTO kdNiaoReqData = INSTANCE.convert(reqDTO); // 快递公司编码需要转成大写 kdNiaoReqData.setExpressCode(reqDTO.getExpressCode().toUpperCase()); KdNiaoExpressQueryRespDTO respDTO = requestKdNiaoApi(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, kdNiaoReqData, KdNiaoExpressQueryRespDTO.class); log.debug("[getExpressTrackList][快递鸟即时查询接口返回 {}]", respDTO); + + // 处理结果 if (respDTO == null || !respDTO.getSuccess()) { throw exception(EXPRESS_API_QUERY_FAILED, respDTO == null ? "" : respDTO.getReason()); } if (CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList(respDTO.getTracks()); - } else { return Collections.emptyList(); } + return INSTANCE.convertList(respDTO.getTracks()); } /** - * 快递鸟 通用的 API 请求, 暂时没有其他应用场景, 暂时放这里 + * 快递鸟 通用的 API 请求,暂时没有其他应用场景, 暂时放这里 + * * @param url 请求 url * @param requestType 对应的请求指令 (快递鸟的RequestType) * @param req 对应请求的请求参数 @@ -77,8 +79,8 @@ public class KdNiaoExpressClient implements ExpressClient { * @param 每个请求的请求结构 Req DTO * @param 每个请求的响应结构 Resp DTO */ - private Resp requestKdNiaoApi(String url, String requestType, Req req, - Class respClass){ + private Resp requestKdNiaoApi(String url, String requestType, Req req, + Class respClass){ // 请求头 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java similarity index 68% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java index 756252e61..81b96184c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java @@ -1,5 +1,6 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.client; +package cn.iocoder.yudao.module.trade.framework.delivery.core.enums; +import lombok.AllArgsConstructor; import lombok.Getter; /** @@ -8,7 +9,9 @@ import lombok.Getter; * @author jason */ @Getter +@AllArgsConstructor public enum ExpressClientEnum { + NOT_PROVIDE("not-provide","未提供"), KD_NIAO("kd-niao", "快递鸟"), KD_100("kd-100", "快递100"); @@ -17,14 +20,9 @@ public enum ExpressClientEnum { * 快递服务商唯一编码 */ private final String code; - /** * 快递服务商名称 */ private final String name; - ExpressClientEnum(String code, String name) { - this.code = code; - this.name = name; - } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java index 6fa41e314..21b615dd0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -18,12 +19,14 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器 /** * @author jason */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = Kd100ExpressClientTest.Application.class) @ActiveProfiles("unit-test") // 设置使用 trade-delivery-query 配置文件 public class Kd100ExpressClientTest { + @Resource private RestTemplateBuilder builder; @Resource @@ -39,7 +42,7 @@ public class Kd100ExpressClientTest { @Disabled("需要 授权 key. 暂时忽略") void testRealTimeQueryExpressFailed() { ServiceException t = assertThrows(ServiceException.class, () -> { - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO(); reqDTO.setExpressCode("yto"); reqDTO.setLogisticsNo("YT9383342193097"); kd100ExpressClient.getExpressTrackList(reqDTO); @@ -53,4 +56,4 @@ public class Kd100ExpressClientTest { @EnableConfigurationProperties(TradeExpressProperties.class) public static class Application { } -} \ No newline at end of file +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java index ebf38d0b7..fc7c6a953 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -17,13 +18,16 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertThrows; -// TODO @芋艿:单测最后 review +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器 /** + * {@link KdNiaoExpressClient} 的单元测试 + * * @author jason */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressClientTest.Application.class) @ActiveProfiles("unit-test") public class KdNiaoExpressClientTest { + @Resource private RestTemplateBuilder builder; @Resource @@ -39,7 +43,7 @@ public class KdNiaoExpressClientTest { @Disabled("需要 授权 key. 暂时忽略") void testRealTimeQueryExpressFailed() { assertThrows(ServiceException.class,() ->{ - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO(); reqDTO.setExpressCode("yy"); reqDTO.setLogisticsNo("YT9383342193097"); kdNiaoExpressClient.getExpressTrackList(reqDTO); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java index 76b8cd6b4..3b60f3645 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器 /** * @author jason */ @@ -49,4 +50,4 @@ public class NoProvideExpressClientTest { return builder.build(); } } -} \ No newline at end of file +} From fd072b7d6ee0001826033fdaa367814c5313f2d7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 17 Jun 2023 18:33:17 +0800 Subject: [PATCH 11/11] =?UTF-8?q?code=20review=EF=BC=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/MemberPointConfigController.java | 45 ++++++++ .../vo/config/MemberPointConfigBaseVO.java | 27 +++++ .../vo/config/MemberPointConfigRespVO.java | 13 +++ .../vo/config/MemberPointConfigSaveReqVO.java | 13 +++ .../admin/point/vo/recrod/package-info.java | 1 + .../point/MemberPointConfigConvert.java | 20 ++++ .../dataobject/point/MemberPointConfigDO.java | 35 +++--- .../mysql/point/MemberPointConfigMapper.java | 14 +++ .../point/MemberPointConfigService.java | 29 +++++ .../point/MemberPointConfigServiceImpl.java | 33 ++++++ .../pointconfig/PointConfigController.java | 102 ------------------ .../pointconfig/vo/PointConfigBaseVO.java | 30 ------ .../vo/PointConfigCreateReqVO.java | 14 --- .../pointconfig/vo/PointConfigExcelVO.java | 45 -------- .../vo/PointConfigExportReqVO.java | 15 --- .../pointconfig/vo/PointConfigPageReqVO.java | 17 --- .../pointconfig/vo/PointConfigRespVO.java | 22 ---- .../vo/PointConfigUpdateReqVO.java | 18 ---- .../pointconfig/PointConfigConvert.java | 34 ------ .../mysql/pointconfig/PointConfigMapper.java | 32 ------ .../pointconfig/PointConfigService.java | 70 ------------ .../pointconfig/PointConfigServiceImpl.java | 92 ---------------- .../mapper/pointconfig/PointConfigMapper.xml | 12 --- .../mapper/pointrecord/PointRecordMapper.xml | 12 --- .../signinconfig/SignInConfigMapper.xml | 12 --- .../signinrecord/SignInRecordMapper.xml | 12 --- 26 files changed, 212 insertions(+), 557 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/MemberPointConfigController.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigRespVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigSaveReqVO.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/recrod/package-info.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java rename yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java => yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java (53%) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/point/MemberPointConfigMapper.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigService.java create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigServiceImpl.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml delete mode 100644 yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/MemberPointConfigController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/MemberPointConfigController.java new file mode 100644 index 000000000..f0e6d0ee2 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/MemberPointConfigController.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.module.member.controller.admin.point; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigRespVO; +import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigSaveReqVO; +import cn.iocoder.yudao.module.member.convert.point.MemberPointConfigConvert; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; +import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 会员积分设置") +@RestController +@RequestMapping("/point/config") +@Validated +public class MemberPointConfigController { + + @Resource + private MemberPointConfigService memberPointConfigService; + + @PutMapping("/update") + @Operation(summary = "保存会员积分配置") + @PreAuthorize("@ss.hasPermission('member:point-config:save')") + public CommonResult updateConfig(@Valid @RequestBody MemberPointConfigSaveReqVO saveReqVO) { + memberPointConfigService.saveConfig(saveReqVO); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得会员积分配置") + @PreAuthorize("@ss.hasPermission('member:point-config:query')") + public CommonResult getConfig() { + MemberPointConfigDO config = memberPointConfigService.getConfig(); + return success(MemberPointConfigConvert.INSTANCE.convert(config)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java new file mode 100644 index 000000000..46ad58321 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigBaseVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.member.controller.admin.point.vo.config; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 会员积分配置 Base VO,提供给添加、修改、详细的子 VO 使用 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 + */ +@Data +public class MemberPointConfigBaseVO { + + @Schema(description = "积分抵扣开关", required = true, example = "true") + private Boolean tradeDeductEnable; + + @Schema(description = "积分抵扣,单位:分", example = "13506") + private BigDecimal tradeDeductUnitPrice; + + @Schema(description = "积分抵扣最大值", example = "32428") + private Long tradeDeductMaxPrice; + + @Schema(description = "1 元赠送多少分") + private Long tradeGivePoint; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigRespVO.java new file mode 100644 index 000000000..36ace83e7 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigRespVO.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.module.member.controller.admin.point.vo.config; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 会员积分配置 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MemberPointConfigRespVO extends MemberPointConfigBaseVO { +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigSaveReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigSaveReqVO.java new file mode 100644 index 000000000..729ab74b6 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/config/MemberPointConfigSaveReqVO.java @@ -0,0 +1,13 @@ +package cn.iocoder.yudao.module.member.controller.admin.point.vo.config; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 会员积分配置保存 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MemberPointConfigSaveReqVO extends MemberPointConfigBaseVO { +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/recrod/package-info.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/recrod/package-info.java new file mode 100644 index 000000000..284e2178b --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/point/vo/recrod/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java new file mode 100644 index 000000000..cf49d2951 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.member.convert.point; + +import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigRespVO; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * 会员积分配置 Convert + * + * @author QingX + */ +@Mapper +public interface MemberPointConfigConvert { + + MemberPointConfigConvert INSTANCE = Mappers.getMapper(MemberPointConfigConvert.class); + + MemberPointConfigRespVO convert(MemberPointConfigDO bean); + +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java similarity index 53% rename from yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java rename to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java index ee30a27d1..a7d54219f 100644 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/dataobject/pointconfig/PointConfigDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/point/MemberPointConfigDO.java @@ -1,15 +1,15 @@ -package cn.iocoder.yudao.module.point.dal.dataobject.pointconfig; +package cn.iocoder.yudao.module.member.dal.dataobject.point; -import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.*; 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.*; + +import java.math.BigDecimal; /** - * 积分设置 DO + * 会员积分配置 DO * * @author QingX */ @@ -21,7 +21,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; @Builder @NoArgsConstructor @AllArgsConstructor -public class PointConfigDO extends BaseDO { +public class MemberPointConfigDO extends BaseDO { /** * 自增主键 @@ -29,23 +29,22 @@ public class PointConfigDO extends BaseDO { @TableId private Integer id; /** - * 1 开启积分抵扣 -0 关闭积分抵扣 - * - * 枚举 {@link TODO infra_boolean_string 对应的类} + * 积分抵扣开关 */ - private Integer tradeDeductEnable; + private Boolean tradeDeductEnable; /** - * 积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元) + * 积分抵扣,单位:分 + * + * 1 积分抵扣多少分 */ private BigDecimal tradeDeductUnitPrice; /** * 积分抵扣最大值 */ - private Long tradeDeductMaxPrice; + private Integer tradeDeductMaxPrice; /** - * 1元赠送多少分 + * 1 元赠送多少分 */ - private Long tradeGivePoint; + private Integer tradeGivePoint; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/point/MemberPointConfigMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/point/MemberPointConfigMapper.java new file mode 100644 index 000000000..e099c1714 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/point/MemberPointConfigMapper.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.member.dal.mysql.point; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 积分设置 Mapper + * + * @author QingX + */ +@Mapper +public interface MemberPointConfigMapper extends BaseMapperX { +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigService.java new file mode 100644 index 000000000..4becacd36 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigService.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.member.service.point; + +import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigSaveReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; + +import javax.validation.Valid; + +/** + * 会员积分配置 Service 接口 + * + * @author QingX + */ +public interface MemberPointConfigService { + + /** + * 保存会员积分配置 + * + * @param saveReqVO 更新信息 + */ + void saveConfig(@Valid MemberPointConfigSaveReqVO saveReqVO); + + /** + * 获得会员积分配置 + * + * @return 积分配置 + */ + MemberPointConfigDO getConfig(); + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigServiceImpl.java new file mode 100644 index 000000000..181537d55 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointConfigServiceImpl.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.member.service.point; + +import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigSaveReqVO; +import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; +import cn.iocoder.yudao.module.member.dal.mysql.point.MemberPointConfigMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; + +/** + * 会员积分配置 Service 实现类 + * + * @author QingX + */ +@Service +@Validated +public class MemberPointConfigServiceImpl implements MemberPointConfigService { + + @Resource + private MemberPointConfigMapper memberPointConfigMapper; + + @Override + public void saveConfig(MemberPointConfigSaveReqVO saveReqVO) { + // TODO qingx:配置存在,则 update;不存在则 insert + } + + @Override + public MemberPointConfigDO getConfig() { + // TODO qingx:直接查询到一条; + return null; + } +} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java deleted file mode 100644 index 137d03050..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/PointConfigController.java +++ /dev/null @@ -1,102 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig; - -import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.security.access.prepost.PreAuthorize; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; - -import javax.validation.constraints.*; -import javax.validation.*; -import javax.servlet.http.*; -import java.util.*; -import java.io.IOException; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; - -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; - -import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; -import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; -import cn.iocoder.yudao.module.point.convert.pointconfig.PointConfigConvert; -import cn.iocoder.yudao.module.point.service.pointconfig.PointConfigService; - -@Tag(name = "管理后台 - 积分设置") -@RestController -@RequestMapping("/point/config") -@Validated -public class PointConfigController { - - @Resource - private PointConfigService configService; - - @PostMapping("/create") - @Operation(summary = "创建积分设置") - @PreAuthorize("@ss.hasPermission('point:config:create')") - public CommonResult createConfig(@Valid @RequestBody PointConfigCreateReqVO createReqVO) { - return success(configService.createConfig(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新积分设置") - @PreAuthorize("@ss.hasPermission('point:config:update')") - public CommonResult updateConfig(@Valid @RequestBody PointConfigUpdateReqVO updateReqVO) { - configService.updateConfig(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除积分设置") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('point:config:delete')") - public CommonResult deleteConfig(@RequestParam("id") Integer id) { - configService.deleteConfig(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得积分设置") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('point:config:query')") - public CommonResult getConfig(@RequestParam("id") Integer id) { - PointConfigDO config = configService.getConfig(id); - return success(PointConfigConvert.INSTANCE.convert(config)); - } - - @GetMapping("/list") - @Operation(summary = "获得积分设置列表") - @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") - @PreAuthorize("@ss.hasPermission('point:config:query')") - public CommonResult> getConfigList(@RequestParam("ids") Collection ids) { - List list = configService.getConfigList(ids); - return success(PointConfigConvert.INSTANCE.convertList(list)); - } - - @GetMapping("/page") - @Operation(summary = "获得积分设置分页") - @PreAuthorize("@ss.hasPermission('point:config:query')") - public CommonResult> getConfigPage(@Valid PointConfigPageReqVO pageVO) { - PageResult pageResult = configService.getConfigPage(pageVO); - return success(PointConfigConvert.INSTANCE.convertPage(pageResult)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出积分设置 Excel") - @PreAuthorize("@ss.hasPermission('point:config:export')") - @OperateLog(type = EXPORT) - public void exportConfigExcel(@Valid PointConfigExportReqVO exportReqVO, - HttpServletResponse response) throws IOException { - List list = configService.getConfigList(exportReqVO); - // 导出 Excel - List datas = PointConfigConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "积分设置.xls", "数据", PointConfigExcelVO.class, datas); - } - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java deleted file mode 100644 index d1e900cc2..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigBaseVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import javax.validation.constraints.*; - -/** - * 积分设置 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ -@Data -public class PointConfigBaseVO { - - @Schema(description = "1 开启积分抵扣 0 关闭积分抵扣", example = "1") - private Integer tradeDeductEnable; - - @Schema(description = "积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元)", example = "13506") - private BigDecimal tradeDeductUnitPrice; - - @Schema(description = "积分抵扣最大值", example = "32428") - private Long tradeDeductMaxPrice; - - @Schema(description = "1元赠送多少分") - private Long tradeGivePoint; - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java deleted file mode 100644 index 4284f5e34..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 积分设置创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class PointConfigCreateReqVO extends PointConfigBaseVO { - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java deleted file mode 100644 index 0d01c7a5c..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExcelVO.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.time.LocalDateTime; - -import com.alibaba.excel.annotation.ExcelProperty; -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; - - -/** - * 积分设置 Excel VO - * - * @author QingX - */ -@Data -public class PointConfigExcelVO { - - @ExcelProperty("自增主键") - private Integer id; - - @ExcelProperty(value = "1 开启积分抵扣 0 关闭积分抵扣", converter = DictConvert.class) - @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 - private Integer tradeDeductEnable; - - @ExcelProperty("积分抵扣,抵扣最低为分 以0.01表示 1积分抵扣0.01元(单位:元)") - private BigDecimal tradeDeductUnitPrice; - - @ExcelProperty("积分抵扣最大值") - private Long tradeDeductMaxPrice; - - @ExcelProperty("1元赠送多少分") - private Long tradeGivePoint; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - - @ExcelProperty("变更时间") - private LocalDateTime updateTime; - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java deleted file mode 100644 index bcc712d29..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigExportReqVO.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import cn.iocoder.yudao.framework.common.pojo.PageParam; - -@Schema(description = "管理后台 - 积分设置 Excel 导出 Request VO,参数和 PointConfigPageReqVO 是一致的") -@Data -public class PointConfigExportReqVO { - - @Schema(description = "1 开启积分抵扣 0 关闭积分抵扣", example = "1") - private Integer tradeDeductEnable; - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java deleted file mode 100644 index cc994837c..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigPageReqVO.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import cn.iocoder.yudao.framework.common.pojo.PageParam; - -@Schema(description = "管理后台 - 积分设置分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class PointConfigPageReqVO extends PageParam { - - @Schema(description = "1 开启积分抵扣 0 关闭积分抵扣", example = "1") - private Integer tradeDeductEnable; - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java deleted file mode 100644 index a8efe57b4..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigRespVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 积分设置 Response VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class PointConfigRespVO extends PointConfigBaseVO { - - @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20937") - private Integer id; - - @Schema(description = "创建时间") - private LocalDateTime createTime; - - @Schema(description = "变更时间") - private LocalDateTime updateTime; - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java deleted file mode 100644 index 9b50f259d..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/controller/admin/pointconfig/vo/PointConfigUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; -import java.util.*; -import javax.validation.constraints.*; - -@Schema(description = "管理后台 - 积分设置更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class PointConfigUpdateReqVO extends PointConfigBaseVO { - - @Schema(description = "自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20937") - @NotNull(message = "自增主键不能为空") - private Integer id; - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java deleted file mode 100644 index 56b96cf75..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/convert/pointconfig/PointConfigConvert.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.point.convert.pointconfig; - -import java.util.*; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; -import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; -import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; - -/** - * 积分设置 Convert - * - * @author QingX - */ -@Mapper -public interface PointConfigConvert { - - PointConfigConvert INSTANCE = Mappers.getMapper(PointConfigConvert.class); - - PointConfigDO convert(PointConfigCreateReqVO bean); - - PointConfigDO convert(PointConfigUpdateReqVO bean); - - PointConfigRespVO convert(PointConfigDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java deleted file mode 100644 index 5d11f9b5b..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/dal/mysql/pointconfig/PointConfigMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.point.dal.mysql.pointconfig; - -import java.util.*; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; -import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; - -/** - * 积分设置 Mapper - * - * @author QingX - */ -@Mapper -public interface PointConfigMapper extends BaseMapperX { - - default PageResult selectPage(PointConfigPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(PointConfigDO::getTradeDeductEnable, reqVO.getTradeDeductEnable()) - .orderByDesc(PointConfigDO::getId)); - } - - default List selectList(PointConfigExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(PointConfigDO::getTradeDeductEnable, reqVO.getTradeDeductEnable()) - .orderByDesc(PointConfigDO::getId)); - } - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java deleted file mode 100644 index d579b7b9d..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigService.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.point.service.pointconfig; - -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; -import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -/** - * 积分设置 Service 接口 - * - * @author QingX - */ -public interface PointConfigService { - - /** - * 创建积分设置 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Integer createConfig(@Valid PointConfigCreateReqVO createReqVO); - - /** - * 更新积分设置 - * - * @param updateReqVO 更新信息 - */ - void updateConfig(@Valid PointConfigUpdateReqVO updateReqVO); - - /** - * 删除积分设置 - * - * @param id 编号 - */ - void deleteConfig(Integer id); - - /** - * 获得积分设置 - * - * @param id 编号 - * @return 积分设置 - */ - PointConfigDO getConfig(Integer id); - - /** - * 获得积分设置列表 - * - * @param ids 编号 - * @return 积分设置列表 - */ - List getConfigList(Collection ids); - - /** - * 获得积分设置分页 - * - * @param pageReqVO 分页查询 - * @return 积分设置分页 - */ - PageResult getConfigPage(PointConfigPageReqVO pageReqVO); - - /** - * 获得积分设置列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 积分设置列表 - */ - List getConfigList(PointConfigExportReqVO exportReqVO); - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java b/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java deleted file mode 100644 index 5cc8185d8..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/java/cn/iocoder/yudao/module/point/service/pointconfig/PointConfigServiceImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -package cn.iocoder.yudao.module.point.service.pointconfig; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; - -import java.util.*; -import cn.iocoder.yudao.module.point.controller.admin.pointconfig.vo.*; -import cn.iocoder.yudao.module.point.dal.dataobject.pointconfig.PointConfigDO; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - -import cn.iocoder.yudao.module.point.convert.pointconfig.PointConfigConvert; -import cn.iocoder.yudao.module.point.dal.mysql.pointconfig.PointConfigMapper; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.point.enums.ErrorCodeConstants.*; - -/** - * 积分设置 Service 实现类 - * - * @author QingX - */ -@Service -@Validated -public class PointConfigServiceImpl implements PointConfigService { - - @Autowired - private PointConfigMapper configMapper; - - @Override - public Integer createConfig(PointConfigCreateReqVO createReqVO) { - // 插入 - PointConfigDO config = PointConfigConvert.INSTANCE.convert(createReqVO); - //每个租户只允许存在一条记录 - validateConfigExistsOne(); - - configMapper.insert(config); - // 返回 - return config.getId(); - } - - @Override - public void updateConfig(PointConfigUpdateReqVO updateReqVO) { - // 校验存在 - validateConfigExists(updateReqVO.getId()); - // 更新 - PointConfigDO updateObj = PointConfigConvert.INSTANCE.convert(updateReqVO); - configMapper.updateById(updateObj); - } - - @Override - public void deleteConfig(Integer id) { - // 校验存在 - validateConfigExists(id); - // 删除 - configMapper.deleteById(id); - } - - private void validateConfigExists(Integer id) { - if (configMapper.selectById(id) == null) { - throw exception(CONFIG_NOT_EXISTS); - } - } - - private void validateConfigExistsOne() { - if (configMapper.selectCount() > 0) { - throw exception(CONFIG_EXISTS); - } - } - - @Override - public PointConfigDO getConfig(Integer id) { - return configMapper.selectById(id); - } - - @Override - public List getConfigList(Collection ids) { - return configMapper.selectBatchIds(ids); - } - - @Override - public PageResult getConfigPage(PointConfigPageReqVO pageReqVO) { - return configMapper.selectPage(pageReqVO); - } - - @Override - public List getConfigList(PointConfigExportReqVO exportReqVO) { - return configMapper.selectList(exportReqVO); - } - -} diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml deleted file mode 100644 index 963afd6c8..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointconfig/PointConfigMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml deleted file mode 100644 index cc09cce4b..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/pointrecord/PointRecordMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml deleted file mode 100644 index 2e665c01a..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinconfig/SignInConfigMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml b/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml deleted file mode 100644 index bd9d58976..000000000 --- a/yudao-module-point/yudao-module-point-biz/src/main/resources/mapper/signinrecord/SignInRecordMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -