Commit 0e28ab169c31cc79572832d6366cb5ea414e9197
1 parent
00d22bf6
1. 优化 config 模板
Showing
6 changed files
with
150 additions
and
176 deletions
ruoyi-ui/src/views/infra/config/index.vue
| @@ -2,24 +2,12 @@ | @@ -2,24 +2,12 @@ | ||
| 2 | <div class="app-container"> | 2 | <div class="app-container"> |
| 3 | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> | 3 | <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> |
| 4 | <el-form-item label="参数名称" prop="name"> | 4 | <el-form-item label="参数名称" prop="name"> |
| 5 | - <el-input | ||
| 6 | - v-model="queryParams.name" | ||
| 7 | - placeholder="请输入参数名称" | ||
| 8 | - clearable | ||
| 9 | - size="small" | ||
| 10 | - style="width: 240px" | ||
| 11 | - @keyup.enter.native="handleQuery" | ||
| 12 | - /> | 5 | + <el-input v-model="queryParams.name" placeholder="请输入参数名称" clearable size="small" style="width: 240px" |
| 6 | + @keyup.enter.native="handleQuery"/> | ||
| 13 | </el-form-item> | 7 | </el-form-item> |
| 14 | <el-form-item label="参数键名" prop="key"> | 8 | <el-form-item label="参数键名" prop="key"> |
| 15 | - <el-input | ||
| 16 | - v-model="queryParams.key" | ||
| 17 | - placeholder="请输入参数键名" | ||
| 18 | - clearable | ||
| 19 | - size="small" | ||
| 20 | - style="width: 240px" | ||
| 21 | - @keyup.enter.native="handleQuery" | ||
| 22 | - /> | 9 | + <el-input v-model="queryParams.key" placeholder="请输入参数键名" clearable size="small" style="width: 240px" |
| 10 | + @keyup.enter.native="handleQuery"/> | ||
| 23 | </el-form-item> | 11 | </el-form-item> |
| 24 | <el-form-item label="系统内置" prop="type"> | 12 | <el-form-item label="系统内置" prop="type"> |
| 25 | <el-select v-model="queryParams.type" placeholder="系统内置" clearable size="small"> | 13 | <el-select v-model="queryParams.type" placeholder="系统内置" clearable size="small"> |
| @@ -56,7 +44,7 @@ | @@ -56,7 +44,7 @@ | ||
| 56 | icon="el-icon-plus" | 44 | icon="el-icon-plus" |
| 57 | size="mini" | 45 | size="mini" |
| 58 | @click="handleAdd" | 46 | @click="handleAdd" |
| 59 | - v-hasPermi="['infra:config:add']" | 47 | + v-hasPermi="['infra:config:create']" |
| 60 | >新增</el-button> | 48 | >新增</el-button> |
| 61 | </el-col> | 49 | </el-col> |
| 62 | <el-col :span="1.5"> | 50 | <el-col :span="1.5"> |
| @@ -95,31 +83,15 @@ | @@ -95,31 +83,15 @@ | ||
| 95 | </el-table-column> | 83 | </el-table-column> |
| 96 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | 84 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 97 | <template slot-scope="scope"> | 85 | <template slot-scope="scope"> |
| 98 | - <el-button | ||
| 99 | - size="mini" | ||
| 100 | - type="text" | ||
| 101 | - icon="el-icon-edit" | ||
| 102 | - @click="handleUpdate(scope.row)" | ||
| 103 | - v-hasPermi="['infra:config:edit']" | ||
| 104 | - >修改</el-button> | ||
| 105 | - <el-button | ||
| 106 | - size="mini" | ||
| 107 | - type="text" | ||
| 108 | - icon="el-icon-delete" | ||
| 109 | - @click="handleDelete(scope.row)" | ||
| 110 | - v-hasPermi="['infra:config:remove']" | ||
| 111 | - >删除</el-button> | 86 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" |
| 87 | + v-hasPermi="['infra:config:update']">修改</el-button> | ||
| 88 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | ||
| 89 | + v-hasPermi="['infra:config:delete']">删除</el-button> | ||
| 112 | </template> | 90 | </template> |
| 113 | </el-table-column> | 91 | </el-table-column> |
| 114 | </el-table> | 92 | </el-table> |
| 115 | 93 | ||
| 116 | - <pagination | ||
| 117 | - v-show="total>0" | ||
| 118 | - :total="total" | ||
| 119 | - :page.sync="queryParams.pageNo" | ||
| 120 | - :limit.sync="queryParams.pageSize" | ||
| 121 | - @pagination="getList" | ||
| 122 | - /> | 94 | + <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList"/> |
| 123 | 95 | ||
| 124 | <!-- 添加或修改参数配置对话框 --> | 96 | <!-- 添加或修改参数配置对话框 --> |
| 125 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | 97 | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
src/main/java/cn/iocoder/dashboard/modules/infra/controller/config/InfConfigController.java
| @@ -3,7 +3,6 @@ package cn.iocoder.dashboard.modules.infra.controller.config; | @@ -3,7 +3,6 @@ package cn.iocoder.dashboard.modules.infra.controller.config; | ||
| 3 | import cn.iocoder.dashboard.common.pojo.CommonResult; | 3 | import cn.iocoder.dashboard.common.pojo.CommonResult; |
| 4 | import cn.iocoder.dashboard.common.pojo.PageResult; | 4 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 5 | import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; | 5 | import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils; |
| 6 | -import cn.iocoder.dashboard.framework.idempotent.core.annotation.Idempotent; | ||
| 7 | import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; | 6 | import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; |
| 8 | import cn.iocoder.dashboard.modules.infra.controller.config.vo.*; | 7 | import cn.iocoder.dashboard.modules.infra.controller.config.vo.*; |
| 9 | import cn.iocoder.dashboard.modules.infra.convert.config.InfConfigConvert; | 8 | import cn.iocoder.dashboard.modules.infra.convert.config.InfConfigConvert; |
| @@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.*; | @@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.*; | ||
| 19 | import javax.annotation.Resource; | 18 | import javax.annotation.Resource; |
| 20 | import javax.servlet.http.HttpServletResponse; | 19 | import javax.servlet.http.HttpServletResponse; |
| 21 | import javax.validation.Valid; | 20 | import javax.validation.Valid; |
| 22 | - | ||
| 23 | import java.io.IOException; | 21 | import java.io.IOException; |
| 24 | import java.util.List; | 22 | import java.util.List; |
| 25 | 23 | ||
| @@ -44,18 +42,17 @@ public class InfConfigController { | @@ -44,18 +42,17 @@ public class InfConfigController { | ||
| 44 | return success(configService.createConfig(reqVO)); | 42 | return success(configService.createConfig(reqVO)); |
| 45 | } | 43 | } |
| 46 | 44 | ||
| 47 | - @ApiOperation("修改参数配置") | ||
| 48 | @PutMapping("/update") | 45 | @PutMapping("/update") |
| 46 | + @ApiOperation("修改参数配置") | ||
| 49 | @PreAuthorize("@ss.hasPermission('infra:config:update')") | 47 | @PreAuthorize("@ss.hasPermission('infra:config:update')") |
| 50 | - @Idempotent(timeout = 60) | ||
| 51 | public CommonResult<Boolean> updateConfig(@Valid @RequestBody InfConfigUpdateReqVO reqVO) { | 48 | public CommonResult<Boolean> updateConfig(@Valid @RequestBody InfConfigUpdateReqVO reqVO) { |
| 52 | configService.updateConfig(reqVO); | 49 | configService.updateConfig(reqVO); |
| 53 | return success(true); | 50 | return success(true); |
| 54 | } | 51 | } |
| 55 | 52 | ||
| 53 | + @DeleteMapping("/delete") | ||
| 56 | @ApiOperation("删除参数配置") | 54 | @ApiOperation("删除参数配置") |
| 57 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | 55 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 58 | - @DeleteMapping("/delete") | ||
| 59 | @PreAuthorize("@ss.hasPermission('infra:config:delete')") | 56 | @PreAuthorize("@ss.hasPermission('infra:config:delete')") |
| 60 | public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) { | 57 | public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) { |
| 61 | configService.deleteConfig(id); | 58 | configService.deleteConfig(id); |
| @@ -70,9 +67,9 @@ public class InfConfigController { | @@ -70,9 +67,9 @@ public class InfConfigController { | ||
| 70 | return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id))); | 67 | return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id))); |
| 71 | } | 68 | } |
| 72 | 69 | ||
| 70 | + @GetMapping(value = "/get-value-by-key") | ||
| 73 | @ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端") | 71 | @ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端") |
| 74 | @ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class) | 72 | @ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class) |
| 75 | - @GetMapping(value = "/get-value-by-key") | ||
| 76 | public CommonResult<String> getConfigKey(@RequestParam("key") String key) { | 73 | public CommonResult<String> getConfigKey(@RequestParam("key") String key) { |
| 77 | InfConfigDO config = configService.getConfigByKey(key); | 74 | InfConfigDO config = configService.getConfigByKey(key); |
| 78 | if (config == null) { | 75 | if (config == null) { |
src/main/java/cn/iocoder/dashboard/modules/infra/dal/mysql/config/InfConfigMapper.java
| @@ -14,20 +14,21 @@ import java.util.List; | @@ -14,20 +14,21 @@ import java.util.List; | ||
| 14 | @Mapper | 14 | @Mapper |
| 15 | public interface InfConfigMapper extends BaseMapperX<InfConfigDO> { | 15 | public interface InfConfigMapper extends BaseMapperX<InfConfigDO> { |
| 16 | 16 | ||
| 17 | - default PageResult<InfConfigDO> selectPage(InfConfigPageReqVO reqVO) { | ||
| 18 | - return selectPage(reqVO, | ||
| 19 | - new QueryWrapperX<InfConfigDO>().likeIfPresent("name", reqVO.getName()) | ||
| 20 | - .likeIfPresent("`key`", reqVO.getKey()) | ||
| 21 | - .eqIfPresent("`type`", reqVO.getType()) | ||
| 22 | - .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | default InfConfigDO selectByKey(String key) { | 17 | default InfConfigDO selectByKey(String key) { |
| 26 | return selectOne(new QueryWrapper<InfConfigDO>().eq("`key`", key)); | 18 | return selectOne(new QueryWrapper<InfConfigDO>().eq("`key`", key)); |
| 27 | } | 19 | } |
| 28 | 20 | ||
| 21 | + default PageResult<InfConfigDO> selectPage(InfConfigPageReqVO reqVO) { | ||
| 22 | + return selectPage(reqVO, new QueryWrapperX<InfConfigDO>() | ||
| 23 | + .likeIfPresent("name", reqVO.getName()) | ||
| 24 | + .likeIfPresent("`key`", reqVO.getKey()) | ||
| 25 | + .eqIfPresent("`type`", reqVO.getType()) | ||
| 26 | + .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | default List<InfConfigDO> selectList(InfConfigExportReqVO reqVO) { | 29 | default List<InfConfigDO> selectList(InfConfigExportReqVO reqVO) { |
| 30 | - return selectList(new QueryWrapperX<InfConfigDO>().likeIfPresent("name", reqVO.getName()) | 30 | + return selectList(new QueryWrapperX<InfConfigDO>() |
| 31 | + .likeIfPresent("name", reqVO.getName()) | ||
| 31 | .likeIfPresent("`key`", reqVO.getKey()) | 32 | .likeIfPresent("`key`", reqVO.getKey()) |
| 32 | .eqIfPresent("`type`", reqVO.getType()) | 33 | .eqIfPresent("`type`", reqVO.getType()) |
| 33 | .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())); | 34 | .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())); |
src/main/java/cn/iocoder/dashboard/modules/infra/service/config/InfConfigService.java
| @@ -7,6 +7,7 @@ import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigPageReqV | @@ -7,6 +7,7 @@ import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigPageReqV | ||
| 7 | import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigUpdateReqVO; | 7 | import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigUpdateReqVO; |
| 8 | import cn.iocoder.dashboard.modules.infra.dal.dataobject.config.InfConfigDO; | 8 | import cn.iocoder.dashboard.modules.infra.dal.dataobject.config.InfConfigDO; |
| 9 | 9 | ||
| 10 | +import javax.validation.Valid; | ||
| 10 | import java.util.List; | 11 | import java.util.List; |
| 11 | 12 | ||
| 12 | /** | 13 | /** |
| @@ -17,20 +18,26 @@ import java.util.List; | @@ -17,20 +18,26 @@ import java.util.List; | ||
| 17 | public interface InfConfigService { | 18 | public interface InfConfigService { |
| 18 | 19 | ||
| 19 | /** | 20 | /** |
| 20 | - * 获得参数配置分页列表 | 21 | + * 创建参数配置 |
| 21 | * | 22 | * |
| 22 | - * @param reqVO 分页条件 | ||
| 23 | - * @return 分页列表 | 23 | + * @param reqVO 创建信息 |
| 24 | + * @return 配置编号 | ||
| 24 | */ | 25 | */ |
| 25 | - PageResult<InfConfigDO> getConfigPage(InfConfigPageReqVO reqVO); | 26 | + Long createConfig(@Valid InfConfigCreateReqVO reqVO); |
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | - * 获得参数配置列表 | 29 | + * 更新参数配置 |
| 29 | * | 30 | * |
| 30 | - * @param reqVO 列表 | ||
| 31 | - * @return 列表 | 31 | + * @param reqVO 更新信息 |
| 32 | */ | 32 | */ |
| 33 | - List<InfConfigDO> getConfigList(InfConfigExportReqVO reqVO); | 33 | + void updateConfig(@Valid InfConfigUpdateReqVO reqVO); |
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 删除参数配置 | ||
| 37 | + * | ||
| 38 | + * @param id 配置编号 | ||
| 39 | + */ | ||
| 40 | + void deleteConfig(Long id); | ||
| 34 | 41 | ||
| 35 | /** | 42 | /** |
| 36 | * 获得参数配置 | 43 | * 获得参数配置 |
| @@ -49,25 +56,20 @@ public interface InfConfigService { | @@ -49,25 +56,20 @@ public interface InfConfigService { | ||
| 49 | InfConfigDO getConfigByKey(String key); | 56 | InfConfigDO getConfigByKey(String key); |
| 50 | 57 | ||
| 51 | /** | 58 | /** |
| 52 | - * 创建参数配置 | 59 | + * 获得参数配置分页列表 |
| 53 | * | 60 | * |
| 54 | - * @param reqVO 创建信息 | ||
| 55 | - * @return 配置编号 | 61 | + * @param reqVO 分页条件 |
| 62 | + * @return 分页列表 | ||
| 56 | */ | 63 | */ |
| 57 | - Long createConfig(InfConfigCreateReqVO reqVO); | 64 | + PageResult<InfConfigDO> getConfigPage(@Valid InfConfigPageReqVO reqVO); |
| 58 | 65 | ||
| 59 | /** | 66 | /** |
| 60 | - * 更新参数配置 | 67 | + * 获得参数配置列表 |
| 61 | * | 68 | * |
| 62 | - * @param reqVO 更新信息 | 69 | + * @param reqVO 列表 |
| 70 | + * @return 列表 | ||
| 63 | */ | 71 | */ |
| 64 | - void updateConfig(InfConfigUpdateReqVO reqVO); | 72 | + List<InfConfigDO> getConfigList(@Valid InfConfigExportReqVO reqVO); |
| 65 | 73 | ||
| 66 | - /** | ||
| 67 | - * 删除参数配置 | ||
| 68 | - * | ||
| 69 | - * @param id 配置编号 | ||
| 70 | - */ | ||
| 71 | - void deleteConfig(Long id); | ||
| 72 | 74 | ||
| 73 | } | 75 | } |
src/main/java/cn/iocoder/dashboard/modules/infra/service/config/impl/InfConfigServiceImpl.java
| @@ -15,6 +15,7 @@ import cn.iocoder.dashboard.modules.infra.service.config.InfConfigService; | @@ -15,6 +15,7 @@ import cn.iocoder.dashboard.modules.infra.service.config.InfConfigService; | ||
| 15 | import com.google.common.annotations.VisibleForTesting; | 15 | import com.google.common.annotations.VisibleForTesting; |
| 16 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 18 | +import org.springframework.validation.annotation.Validated; | ||
| 18 | 19 | ||
| 19 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 20 | 21 | ||
| @@ -27,6 +28,7 @@ import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*; | @@ -27,6 +28,7 @@ import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*; | ||
| 27 | */ | 28 | */ |
| 28 | @Service | 29 | @Service |
| 29 | @Slf4j | 30 | @Slf4j |
| 31 | +@Validated | ||
| 30 | public class InfConfigServiceImpl implements InfConfigService { | 32 | public class InfConfigServiceImpl implements InfConfigService { |
| 31 | 33 | ||
| 32 | @Resource | 34 | @Resource |
| @@ -36,26 +38,6 @@ public class InfConfigServiceImpl implements InfConfigService { | @@ -36,26 +38,6 @@ public class InfConfigServiceImpl implements InfConfigService { | ||
| 36 | private InfConfigProducer configProducer; | 38 | private InfConfigProducer configProducer; |
| 37 | 39 | ||
| 38 | @Override | 40 | @Override |
| 39 | - public PageResult<InfConfigDO> getConfigPage(InfConfigPageReqVO reqVO) { | ||
| 40 | - return configMapper.selectPage(reqVO); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - @Override | ||
| 44 | - public List<InfConfigDO> getConfigList(InfConfigExportReqVO reqVO) { | ||
| 45 | - return configMapper.selectList(reqVO); | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - @Override | ||
| 49 | - public InfConfigDO getConfig(Long id) { | ||
| 50 | - return configMapper.selectById(id); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - @Override | ||
| 54 | - public InfConfigDO getConfigByKey(String key) { | ||
| 55 | - return configMapper.selectByKey(key); | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | public Long createConfig(InfConfigCreateReqVO reqVO) { | 41 | public Long createConfig(InfConfigCreateReqVO reqVO) { |
| 60 | // 校验正确性 | 42 | // 校验正确性 |
| 61 | checkCreateOrUpdate(null, reqVO.getKey()); | 43 | checkCreateOrUpdate(null, reqVO.getKey()); |
| @@ -93,6 +75,26 @@ public class InfConfigServiceImpl implements InfConfigService { | @@ -93,6 +75,26 @@ public class InfConfigServiceImpl implements InfConfigService { | ||
| 93 | configProducer.sendConfigRefreshMessage(); | 75 | configProducer.sendConfigRefreshMessage(); |
| 94 | } | 76 | } |
| 95 | 77 | ||
| 78 | + @Override | ||
| 79 | + public InfConfigDO getConfig(Long id) { | ||
| 80 | + return configMapper.selectById(id); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public InfConfigDO getConfigByKey(String key) { | ||
| 85 | + return configMapper.selectByKey(key); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public PageResult<InfConfigDO> getConfigPage(InfConfigPageReqVO reqVO) { | ||
| 90 | + return configMapper.selectPage(reqVO); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public List<InfConfigDO> getConfigList(InfConfigExportReqVO reqVO) { | ||
| 95 | + return configMapper.selectList(reqVO); | ||
| 96 | + } | ||
| 97 | + | ||
| 96 | private void checkCreateOrUpdate(Long id, String key) { | 98 | private void checkCreateOrUpdate(Long id, String key) { |
| 97 | // 校验自己存在 | 99 | // 校验自己存在 |
| 98 | checkConfigExists(id); | 100 | checkConfigExists(id); |
src/test/java/cn/iocoder/dashboard/modules/infra/service/config/InfConfigServiceTest.java
| @@ -48,88 +48,6 @@ public class InfConfigServiceTest extends BaseDbUnitTest { | @@ -48,88 +48,6 @@ public class InfConfigServiceTest extends BaseDbUnitTest { | ||
| 48 | private InfConfigProducer configProducer; | 48 | private InfConfigProducer configProducer; |
| 49 | 49 | ||
| 50 | @Test | 50 | @Test |
| 51 | - public void testGetConfigPage() { | ||
| 52 | - // mock 数据 | ||
| 53 | - InfConfigDO dbConfig = randomInfConfigDO(o -> { // 等会查询到 | ||
| 54 | - o.setName("芋艿"); | ||
| 55 | - o.setKey("yunai"); | ||
| 56 | - o.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 57 | - o.setCreateTime(buildTime(2021, 2, 1)); | ||
| 58 | - }); | ||
| 59 | - configMapper.insert(dbConfig); | ||
| 60 | - // 测试 name 不匹配 | ||
| 61 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setName("土豆"))); | ||
| 62 | - // 测试 key 不匹配 | ||
| 63 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setKey("tudou"))); | ||
| 64 | - // 测试 type 不匹配 | ||
| 65 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setType(InfConfigTypeEnum.CUSTOM.getType()))); | ||
| 66 | - // 测试 createTime 不匹配 | ||
| 67 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | ||
| 68 | - // 准备参数 | ||
| 69 | - InfConfigPageReqVO reqVO = new InfConfigPageReqVO(); | ||
| 70 | - reqVO.setName("艿"); | ||
| 71 | - reqVO.setKey("nai"); | ||
| 72 | - reqVO.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 73 | - reqVO.setBeginTime(buildTime(2021, 1, 15)); | ||
| 74 | - reqVO.setEndTime(buildTime(2021, 2, 15)); | ||
| 75 | - | ||
| 76 | - // 调用 | ||
| 77 | - PageResult<InfConfigDO> pageResult = configService.getConfigPage(reqVO); | ||
| 78 | - // 断言 | ||
| 79 | - assertEquals(1, pageResult.getTotal()); | ||
| 80 | - assertEquals(1, pageResult.getList().size()); | ||
| 81 | - assertPojoEquals(dbConfig, pageResult.getList().get(0)); | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - @Test | ||
| 85 | - public void testGetConfigList() { | ||
| 86 | - // mock 数据 | ||
| 87 | - InfConfigDO dbConfig = randomInfConfigDO(o -> { // 等会查询到 | ||
| 88 | - o.setName("芋艿"); | ||
| 89 | - o.setKey("yunai"); | ||
| 90 | - o.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 91 | - o.setCreateTime(buildTime(2021, 2, 1)); | ||
| 92 | - }); | ||
| 93 | - configMapper.insert(dbConfig); | ||
| 94 | - // 测试 name 不匹配 | ||
| 95 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setName("土豆"))); | ||
| 96 | - // 测试 key 不匹配 | ||
| 97 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setKey("tudou"))); | ||
| 98 | - // 测试 type 不匹配 | ||
| 99 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setType(InfConfigTypeEnum.CUSTOM.getType()))); | ||
| 100 | - // 测试 createTime 不匹配 | ||
| 101 | - configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | ||
| 102 | - // 准备参数 | ||
| 103 | - InfConfigExportReqVO reqVO = new InfConfigExportReqVO(); | ||
| 104 | - reqVO.setName("艿"); | ||
| 105 | - reqVO.setKey("nai"); | ||
| 106 | - reqVO.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 107 | - reqVO.setBeginTime(buildTime(2021, 1, 15)); | ||
| 108 | - reqVO.setEndTime(buildTime(2021, 2, 15)); | ||
| 109 | - | ||
| 110 | - // 调用 | ||
| 111 | - List<InfConfigDO> list = configService.getConfigList(reqVO); | ||
| 112 | - // 断言 | ||
| 113 | - assertEquals(1, list.size()); | ||
| 114 | - assertPojoEquals(dbConfig, list.get(0)); | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - @Test | ||
| 118 | - public void testGetConfigByKey() { | ||
| 119 | - // mock 数据 | ||
| 120 | - InfConfigDO dbConfig = randomInfConfigDO(); | ||
| 121 | - configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 | ||
| 122 | - // 准备参数 | ||
| 123 | - String key = dbConfig.getKey(); | ||
| 124 | - | ||
| 125 | - // 调用 | ||
| 126 | - InfConfigDO config = configService.getConfigByKey(key); | ||
| 127 | - // 断言 | ||
| 128 | - assertNotNull(config); | ||
| 129 | - assertPojoEquals(dbConfig, config); | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - @Test | ||
| 133 | public void testCreateConfig_success() { | 51 | public void testCreateConfig_success() { |
| 134 | // 准备参数 | 52 | // 准备参数 |
| 135 | InfConfigCreateReqVO reqVO = randomPojo(InfConfigCreateReqVO.class); | 53 | InfConfigCreateReqVO reqVO = randomPojo(InfConfigCreateReqVO.class); |
| @@ -243,6 +161,88 @@ public class InfConfigServiceTest extends BaseDbUnitTest { | @@ -243,6 +161,88 @@ public class InfConfigServiceTest extends BaseDbUnitTest { | ||
| 243 | CONFIG_KEY_DUPLICATE); | 161 | CONFIG_KEY_DUPLICATE); |
| 244 | } | 162 | } |
| 245 | 163 | ||
| 164 | + @Test | ||
| 165 | + public void testGetConfigPage() { | ||
| 166 | + // mock 数据 | ||
| 167 | + InfConfigDO dbConfig = randomInfConfigDO(o -> { // 等会查询到 | ||
| 168 | + o.setName("芋艿"); | ||
| 169 | + o.setKey("yunai"); | ||
| 170 | + o.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 171 | + o.setCreateTime(buildTime(2021, 2, 1)); | ||
| 172 | + }); | ||
| 173 | + configMapper.insert(dbConfig); | ||
| 174 | + // 测试 name 不匹配 | ||
| 175 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setName("土豆"))); | ||
| 176 | + // 测试 key 不匹配 | ||
| 177 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setKey("tudou"))); | ||
| 178 | + // 测试 type 不匹配 | ||
| 179 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setType(InfConfigTypeEnum.CUSTOM.getType()))); | ||
| 180 | + // 测试 createTime 不匹配 | ||
| 181 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | ||
| 182 | + // 准备参数 | ||
| 183 | + InfConfigPageReqVO reqVO = new InfConfigPageReqVO(); | ||
| 184 | + reqVO.setName("艿"); | ||
| 185 | + reqVO.setKey("nai"); | ||
| 186 | + reqVO.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 187 | + reqVO.setBeginTime(buildTime(2021, 1, 15)); | ||
| 188 | + reqVO.setEndTime(buildTime(2021, 2, 15)); | ||
| 189 | + | ||
| 190 | + // 调用 | ||
| 191 | + PageResult<InfConfigDO> pageResult = configService.getConfigPage(reqVO); | ||
| 192 | + // 断言 | ||
| 193 | + assertEquals(1, pageResult.getTotal()); | ||
| 194 | + assertEquals(1, pageResult.getList().size()); | ||
| 195 | + assertPojoEquals(dbConfig, pageResult.getList().get(0)); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + @Test | ||
| 199 | + public void testGetConfigList() { | ||
| 200 | + // mock 数据 | ||
| 201 | + InfConfigDO dbConfig = randomInfConfigDO(o -> { // 等会查询到 | ||
| 202 | + o.setName("芋艿"); | ||
| 203 | + o.setKey("yunai"); | ||
| 204 | + o.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 205 | + o.setCreateTime(buildTime(2021, 2, 1)); | ||
| 206 | + }); | ||
| 207 | + configMapper.insert(dbConfig); | ||
| 208 | + // 测试 name 不匹配 | ||
| 209 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setName("土豆"))); | ||
| 210 | + // 测试 key 不匹配 | ||
| 211 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setKey("tudou"))); | ||
| 212 | + // 测试 type 不匹配 | ||
| 213 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setType(InfConfigTypeEnum.CUSTOM.getType()))); | ||
| 214 | + // 测试 createTime 不匹配 | ||
| 215 | + configMapper.insert(ObjectUtils.clone(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | ||
| 216 | + // 准备参数 | ||
| 217 | + InfConfigExportReqVO reqVO = new InfConfigExportReqVO(); | ||
| 218 | + reqVO.setName("艿"); | ||
| 219 | + reqVO.setKey("nai"); | ||
| 220 | + reqVO.setType(InfConfigTypeEnum.SYSTEM.getType()); | ||
| 221 | + reqVO.setBeginTime(buildTime(2021, 1, 15)); | ||
| 222 | + reqVO.setEndTime(buildTime(2021, 2, 15)); | ||
| 223 | + | ||
| 224 | + // 调用 | ||
| 225 | + List<InfConfigDO> list = configService.getConfigList(reqVO); | ||
| 226 | + // 断言 | ||
| 227 | + assertEquals(1, list.size()); | ||
| 228 | + assertPojoEquals(dbConfig, list.get(0)); | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + @Test | ||
| 232 | + public void testGetConfigByKey() { | ||
| 233 | + // mock 数据 | ||
| 234 | + InfConfigDO dbConfig = randomInfConfigDO(); | ||
| 235 | + configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 | ||
| 236 | + // 准备参数 | ||
| 237 | + String key = dbConfig.getKey(); | ||
| 238 | + | ||
| 239 | + // 调用 | ||
| 240 | + InfConfigDO config = configService.getConfigByKey(key); | ||
| 241 | + // 断言 | ||
| 242 | + assertNotNull(config); | ||
| 243 | + assertPojoEquals(dbConfig, config); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | // ========== 随机对象 ========== | 246 | // ========== 随机对象 ========== |
| 247 | 247 | ||
| 248 | @SafeVarargs | 248 | @SafeVarargs |