From 18785550dae11320f53dbe476b6dc05e443f6776 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 21:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20=E5=A2=9E=E5=8A=A0=20dept=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E5=8D=95=E6=B5=8B=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/dept/PostService.java | 12 ++++-------- .../system/service/dept/PostServiceImpl.java | 9 +++++++++ .../service/dept/PostServiceImplTest.java | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java index 73068e234..25604ceb3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.dept; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; @@ -10,8 +9,6 @@ import org.springframework.lang.Nullable; import java.util.Collection; import java.util.List; -import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; - /** * 岗位 Service 接口 * @@ -44,12 +41,10 @@ public interface PostService { /** * 获得岗位列表 * - * @param ids 岗位编号数组。如果为空,不进行筛选 + * @param ids 岗位编号数组 * @return 部门列表 */ - default List getPostList(@Nullable Collection ids) { - return getPostList(ids, asSet(CommonStatusEnum.ENABLE.getStatus(), CommonStatusEnum.DISABLE.getStatus())); - } + List getPostList(@Nullable Collection ids); /** * 获得符合条件的岗位列表 @@ -58,7 +53,8 @@ public interface PostService { * @param statuses 状态数组。如果为空,不进行筛选 * @return 部门列表 */ - List getPostList(@Nullable Collection ids, @Nullable Collection statuses); + List getPostList(@Nullable Collection ids, + @Nullable Collection statuses); /** * 获得岗位分页列表 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java index 560a8bc8f..168386e50 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -107,6 +108,14 @@ public class PostServiceImpl implements PostService { } } + @Override + public List getPostList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return postMapper.selectBatchIds(ids); + } + @Override public List getPostList(Collection ids, Collection statuses) { return postMapper.selectList(ids, statuses); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java index ecc17452c..a6412277c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java @@ -155,6 +155,24 @@ public class PostServiceImplTest extends BaseDbUnitTest { @Test public void testGetPostList() { + // mock 数据 + PostDO postDO01 = randomPojo(PostDO.class); + postMapper.insert(postDO01); + // 测试 id 不匹配 + PostDO postDO02 = randomPojo(PostDO.class); + postMapper.insert(postDO02); + // 准备参数 + List ids = singletonList(postDO01.getId()); + + // 调用 + List list = postService.getPostList(ids); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(postDO01, list.get(0)); + } + + @Test + public void testGetPostList_idsAndStatus() { // mock 数据 PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); postMapper.insert(postDO01);