目录树查询

This commit is contained in:
s2042968 2024-11-19 09:18:16 +08:00
parent 0a4e98f446
commit 239b94ec33
12 changed files with 353 additions and 2 deletions

View File

@ -0,0 +1,28 @@
package com.electromagnetic.industry.software.data.manage.controller.category;
import com.electromagnetic.industry.software.data.manage.facade.Category.CategoryFacade;
import electromagnetic.data.framework.share.model.ElectromagneticResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RequestMapping("/data/ed/category")
@RestController
public class CategoryController {
@Resource
CategoryFacade categoryFacade;
/**
* 目录树查询
*/
@ApiOperation(value = "目录树查询", notes = "")
@RequestMapping(value = "/tree", method = RequestMethod.GET)
public ElectromagneticResult<?> categoryTree() {
return categoryFacade.categoryTree();
}
}

View File

@ -45,7 +45,6 @@ public class UserController {
@ApiOperation(value = "获取单条用户信息", notes = "")
@RequestMapping(value = "/getInfo", method = RequestMethod.GET)
public ElectromagneticResult<?> getSingleUser(GetSingleUserRequest getSingleUserRequest) {
System.out.println(getSingleUserRequest.getUserId());
return userFacade.getSingleUser(getSingleUserRequest);
}

View File

@ -0,0 +1,82 @@
package com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
public class Category implements Serializable {
/**
* 主键ID
*/
private Long id;
/**
* 目录类型ID
*/
private String categoryTypeId;
/**
* 上级编码为空则为一级
*/
private String parentId;
/**
* 目录编码
*/
private String categoryId;
/**
* 目录名称
*/
private String categoryName;
/**
* 目录状态
*/
private String categoryStatus;
/**
* 创建人
*/
private String creator;
/**
* 创建人姓名
*/
private String creatorName;
/**
* 创建时间
*/
private Date gmtCreate;
/**
* 编辑人
*/
private String modifier;
/**
* 编辑人姓名
*/
private String modifierName;
/**
* 编辑时间
*/
private Date gmtModified;
/**
* 是否有效0-无效 1-有效
*/
private int effectFlag;
/**
* 子目录
*/
private List<Category> children = new ArrayList<>();
}

View File

@ -0,0 +1,18 @@
package com.electromagnetic.industry.software.data.manage.domain.boardservice.user.repository;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import java.util.List;
public interface CategoryRepository {
/**
* 获取顶级节点
*/
List<Category> getTopCategories();
/**
* 获取所有节点
*/
List<Category> getAllCategories();
}

View File

@ -0,0 +1,14 @@
package com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import java.util.List;
public interface CategoryService {
/**
* 构建树结构
*/
public List<Category> buildCategoryTree();
}

View File

@ -1,6 +1,5 @@
package com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.model.Token;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.model.User;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.model.UserLoginInfo;

View File

@ -0,0 +1,83 @@
package com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.impl;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.repository.CategoryRepository;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.CategoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CategoryServiceImpl implements CategoryService {
@Resource
CategoryRepository categoryRepository;
/**
* 构建树结构
*/
@Override
public List<Category> buildCategoryTree(){
List<Category> categories = categoryRepository.getAllCategories();
List<Category> returnList = new ArrayList<>();
List<String> tempList = categories.stream().map(Category::getCategoryId).collect(Collectors.toList());
for (Category category : categories) {
if (!tempList.contains(category.getParentId())) {
recursionFn(categories, category);
returnList.add(category);
}
}
if (returnList.isEmpty()) {
returnList = categories;
}
return returnList;
}
/**
* 递归列表
* @param list
* @param category
*/
private void recursionFn (List<Category> list, Category category) {
List<Category> childList = getChildList(list, category);
category.setChildren(childList);
for (Category child : childList) {
if (hasChild(list, child)) {
recursionFn(list, child);
}
}
}
/**
* 得到子节点列表
* @param list
* @param category
* @return
*/
private List<Category> getChildList(List<Category> list, Category category) {
List<Category> childList = new ArrayList<>();
Iterator<Category> it = list.iterator();
while (it.hasNext()) {
Category child = it.next();
if (!StringUtils.isEmpty(child.getParentId()) && child.getParentId().equals(category.getCategoryId())) {
childList.add(child);
}
}
return childList;
}
/**
* 判断是否有子节点
* @param list
* @param category
* @return
*/
private boolean hasChild(List<Category> list, Category category) {
return !getChildList(list, category).isEmpty();
}
}

View File

@ -0,0 +1,12 @@
package com.electromagnetic.industry.software.data.manage.facade.Category;
import java.util.List;
import electromagnetic.data.framework.share.model.ElectromagneticResult;
public interface CategoryFacade {
/**
* 构建树结构
*/
ElectromagneticResult<?> categoryTree();
}

View File

@ -0,0 +1,22 @@
package com.electromagnetic.industry.software.data.manage.repository.dao;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface CategoryMapper {
/**
* 获取顶级节点
* @return
*/
List<Category> selectTopCategories();
/**
* 获取所有节点
* @return
*/
List<Category> selectAllCategories();
}

View File

@ -0,0 +1,33 @@
package com.electromagnetic.industry.software.data.manage.repository.impl;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.repository.CategoryRepository;
import com.electromagnetic.industry.software.data.manage.repository.dao.CategoryMapper;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
@Repository
public class CategoryRepositoryImpl implements CategoryRepository {
@Resource
CategoryMapper categoryMapper;
/**
* 获取顶级节点
*/
@Override
public List<Category> getTopCategories(){
return categoryMapper.selectTopCategories();
}
/**
* 获取所有节点
*/
@Override
public List<Category> getAllCategories(){
return categoryMapper.selectAllCategories();
}
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.electromagnetic.industry.software.data.manage.repository.dao.CategoryMapper">
<resultMap id="CategoryResultMap" type="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="category_type_id" jdbcType="VARCHAR" property="categoryTypeId" />
<result column="parent_id" jdbcType="VARCHAR" property="parentId" />
<result column="category_id" jdbcType="VARCHAR" property="categoryId" />
<result column="category_name" jdbcType="VARCHAR" property="categoryName" />
<result column="category_status" jdbcType="VARCHAR" property="categoryStatus" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="creator_name" jdbcType="VARCHAR" property="creatorName" />
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
<result column="modifier" jdbcType="VARCHAR" property="modifier" />
<result column="modifier_name" jdbcType="VARCHAR" property="modifierName" />
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified" />
<result column="effect_flag" jdbcType="TINYINT" property="effectFlag" />
</resultMap>
<sql id="selectUserVo">
select category_type_id, parent_id, category_id, category_name, category_status,
creator, creator_name, gmt_create, modifier, modifier_name, gmt_modified, effect_flag
from ed_category
</sql>
<select id="selectTopCategories" resultMap="CategoryResultMap">
<include refid="selectUserVo" />
where parent_id = 0 and category_status="available"
</select>
<select id="selectAllCategories" resultMap="CategoryResultMap">
<include refid="selectUserVo" />
where category_status="available"
</select>
</mapper>

View File

@ -0,0 +1,26 @@
package com.electromagnetic.industry.software.data.manage.service.facade.user;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.CategoryService;
import com.electromagnetic.industry.software.data.manage.facade.Category.CategoryFacade;
import electromagnetic.data.framework.share.model.ElectromagneticResult;
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class CategoryFacadeImpl implements CategoryFacade {
@Resource
CategoryService categoryService;
/**
* 构建树结构
*/
public ElectromagneticResult<?> categoryTree(){
List<Category> list =categoryService.buildCategoryTree();
return ElectromagneticResultUtil.success(list);
}
}