diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java index a2b8d6f56..8dc38a644 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.controller.admin.dict; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -66,7 +67,8 @@ public class DictDataController { @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地") // 无需添加权限认证,因为前端全局都需要 public CommonResult> getSimpleDictDataList() { - List list = dictDataService.getDictDataList(); + List list = dictDataService.getDictDataList( + CommonStatusEnum.ENABLE.getStatus(), null); return success(BeanUtils.toBean(list, DictDataSimpleRespVO.class)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 15976361e..8c4b97f6f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.controller.app.dict; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; @@ -32,7 +33,8 @@ public class AppDictDataController { @Operation(summary = "根据字典类型查询字典数据信息") @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") public CommonResult> getDictDataListByType(@RequestParam("type") String type) { - List list = dictDataService.getEnabledDictDataListByType(type); + List list = dictDataService.getDictDataList( + CommonStatusEnum.ENABLE.getStatus(), type); return success(BeanUtils.toBean(list, AppDictDataRespVO.class)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index fe00e55b4..87a05c636 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -40,10 +40,10 @@ public interface DictDataMapper extends BaseMapperX { .orderByDesc(Arrays.asList(DictDataDO::getDictType, DictDataDO::getSort))); } - default List selectListByTypeAndStatus(String dictType, Integer status) { - return selectList(new LambdaQueryWrapper() - .eq(DictDataDO::getDictType, dictType) - .eq(DictDataDO::getStatus, status)); + default List selectListByStatusAndDictType(Integer status, String dictType) { + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(DictDataDO::getStatus, status) + .eqIfPresent(DictDataDO::getDictType, dictType)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java index a0abf106c..a752476da 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; +import org.springframework.lang.Nullable; import java.util.Collection; import java.util.List; @@ -40,9 +41,11 @@ public interface DictDataService { /** * 获得字典数据列表 * + * @param status 状态 + * @param dictType 字典类型 * @return 字典数据全列表 */ - List getDictDataList(); + List getDictDataList(@Nullable Integer status, @Nullable String dictType); /** * 获得字典数据分页列表 @@ -52,14 +55,6 @@ public interface DictDataService { */ PageResult getDictDataPage(DictDataPageReqVO pageReqVO); - /** - * 获得字典数据列表 - * - * @param dictType 字典类型 - * @return 字典数据列表 - */ - List getEnabledDictDataListByType(String dictType); - /** * 获得字典数据详情 * @@ -74,7 +69,7 @@ public interface DictDataService { * @param dictType 字典类型 * @return 数据数量 */ - long countByDictType(String dictType); + long getDictDataCountByDictType(String dictType); /** * 校验字典数据们是否有效。如下情况,视为无效: @@ -103,4 +98,5 @@ public interface DictDataService { * @return 字典数据 */ DictDataDO parseDictData(String dictType, String label); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java index 1391a8f1a..b9b87f0c4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java @@ -46,8 +46,8 @@ public class DictDataServiceImpl implements DictDataService { private DictDataMapper dictDataMapper; @Override - public List getDictDataList() { - List list = dictDataMapper.selectList(DictDataDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); + public List getDictDataList(Integer status, String dictType) { + List list = dictDataMapper.selectListByStatusAndDictType(status, dictType); list.sort(COMPARATOR_TYPE_AND_SORT); return list; } @@ -57,13 +57,6 @@ public class DictDataServiceImpl implements DictDataService { return dictDataMapper.selectPage(pageReqVO); } - @Override - public List getEnabledDictDataListByType(String dictType) { - List list = dictDataMapper.selectListByTypeAndStatus(dictType, CommonStatusEnum.ENABLE.getStatus()); - list.sort(COMPARATOR_TYPE_AND_SORT); - return list; - } - @Override public DictDataDO getDictData(Long id) { return dictDataMapper.selectById(id); @@ -106,7 +99,7 @@ public class DictDataServiceImpl implements DictDataService { } @Override - public long countByDictType(String dictType) { + public long getDictDataCountByDictType(String dictType) { return dictDataMapper.selectCountByDictType(dictType); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java index 76c1de55e..5e7f27e55 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java @@ -80,7 +80,7 @@ public class DictTypeServiceImpl implements DictTypeService { // 校验是否存在 DictTypeDO dictType = validateDictTypeExists(id); // 校验是否有字典数据 - if (dictDataService.countByDictType(dictType.getType()) > 0) { + if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) { throw exception(DICT_TYPE_HAS_CHILDREN); } // 删除字典类型 diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java index 983a70c52..68edd735f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java @@ -50,10 +50,15 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { DictDataDO dictDataDO03 = randomDictDataDO().setDictType("yunai").setSort(3) .setStatus(CommonStatusEnum.DISABLE.getStatus()); dictDataMapper.insert(dictDataDO03); + DictDataDO dictDataDO04 = randomDictDataDO().setDictType("yunai2").setSort(3) + .setStatus(CommonStatusEnum.DISABLE.getStatus()); + dictDataMapper.insert(dictDataDO04); // 准备参数 + Integer status = CommonStatusEnum.ENABLE.getStatus(); + String dictType = "yunai"; // 调用 - List dictDataDOList = dictDataService.getDictDataList(); + List dictDataDOList = dictDataService.getDictDataList(status, dictType); // 断言 assertEquals(2, dictDataDOList.size()); assertPojoEquals(dictDataDO02, dictDataDOList.get(0)); @@ -236,7 +241,7 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { } @Test - public void testCountByDictType() { + public void testGetDictDataCountByDictType() { // mock 数据 dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai"))); dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("tudou"))); @@ -245,7 +250,7 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { String dictType = "yunai"; // 调用 - long count = dictDataService.countByDictType(dictType); + long count = dictDataService.getDictDataCountByDictType(dictType); // 校验 assertEquals(2L, count); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java index b9eb10a5f..82b4b2f2e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImplTest.java @@ -158,7 +158,7 @@ public class DictTypeServiceImplTest extends BaseDbUnitTest { // 准备参数 Long id = dbDictType.getId(); // mock 方法 - when(dictDataService.countByDictType(eq(dbDictType.getType()))).thenReturn(1L); + when(dictDataService.getDictDataCountByDictType(eq(dbDictType.getType()))).thenReturn(1L); // 调用, 并断言异常 assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN);