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 + + + +