From 940cde9e791da02a1ad1bde55d4cfa5e78918fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Tue, 9 Jan 2024 09:37:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=9F=A5=E8=AF=A2=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=8C=89=E7=85=A7=E7=A7=8D?= =?UTF-8?q?=E7=B1=BBid=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/ComponentController.java | 18 ++++++++++++++++++ .../ruoyi/platform/mapper/ComponentDao.java | 4 ++++ .../platform/service/ComponentService.java | 5 +++++ .../service/impl/ComponentServiceImpl.java | 14 ++++++++++++++ .../managementPlatform/ComponentDaoMapper.xml | 6 ++++++ 5 files changed, 47 insertions(+) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/component/ComponentController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/component/ComponentController.java index 8e9cc051..abbd3a12 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/component/ComponentController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/component/ComponentController.java @@ -11,6 +11,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; +import java.util.Map; /** * (Component)表控制层 @@ -41,6 +43,22 @@ public class ComponentController { return ResponseEntity.ok(this.componentService.queryByPage(component, pageRequest)); } + + /** + * 查询全部 + * + * + * + * @return 查询结果 + */ + @GetMapping("/components/all") + @ApiOperation("查询全部") + public ResponseEntity>> queryAll(){ + return ResponseEntity.ok(this.componentService.queryAllGroupedByCategory()); + } + + + /** * 通过主键查询单条数据 * diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComponentDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComponentDao.java index 3b7f3685..ce42dca6 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComponentDao.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ComponentDao.java @@ -29,6 +29,9 @@ public interface ComponentDao { */ Component queryById(Integer id); + + List queryAll(); + /** * 查询指定行数据 * @@ -90,5 +93,6 @@ public interface ComponentDao { // 检查相同category_id下的component_name是否存在 Integer countByNameAndCategoryId(@Param("componentName") String componentName, @Param("categoryId") Integer categoryId); + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ComponentService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ComponentService.java index a1a60951..df8b5500 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ComponentService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ComponentService.java @@ -5,6 +5,9 @@ import com.ruoyi.platform.vo.ComponentVo; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import java.util.List; +import java.util.Map; + /** * (Component)表服务接口 * @@ -56,4 +59,6 @@ public interface ComponentService { String removeById(Integer id); + Map> queryAllGroupedByCategory(); + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ComponentServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ComponentServiceImpl.java index 9b5bd44d..a1a2638c 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ComponentServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ComponentServiceImpl.java @@ -16,6 +16,9 @@ import org.springframework.data.domain.PageRequest; import javax.annotation.Resource; import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * (Component)表服务实现类 @@ -30,6 +33,8 @@ public class ComponentServiceImpl implements ComponentService { @Value("${pipeline.control_strategy}") private String controlStrategy; + + /** * 通过ID查询单条数据 * @@ -46,6 +51,13 @@ public class ComponentServiceImpl implements ComponentService { return this.componentDao.queryById(id); } + @Override + public Map> queryAllGroupedByCategory() { + List componentList = this.componentDao.queryAll(); + Map> groupedComponent = componentList.stream().collect(Collectors.groupingBy(Component::getCategoryId)); + return groupedComponent; + } + /** * 分页查询 * @@ -150,4 +162,6 @@ public class ComponentServiceImpl implements ComponentService { component.setState(0); return this.componentDao.update(component)>0?"删除成功":"删除失败"; } + + } diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComponentDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComponentDaoMapper.xml index 832cdee7..c51a1767 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComponentDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ComponentDaoMapper.xml @@ -31,6 +31,12 @@ where id = #{id} and state = 1 + + + +