Browse Source

Merge branch 'lingshan_master' into dev

master
wxz 2 years ago
parent
commit
d999ffbe2e
  1. 83
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/CategoryDictController.java
  2. 2
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/CategoryDictService.java
  3. 13
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/CategoryDictServiceImpl.java

83
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/CategoryDictController.java

@ -10,12 +10,20 @@ import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.dto.CategoryDictDTO; import com.epmet.dto.CategoryDictDTO;
import com.epmet.service.CategoryDictService; import com.epmet.service.CategoryDictService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/** /**
@ -31,12 +39,87 @@ public class CategoryDictController {
@Autowired @Autowired
private CategoryDictService categoryDictService; private CategoryDictService categoryDictService;
@Data
@NoArgsConstructor
public static class TreeNode {
private String pid;
private String id;
private String categoryName;
private List<TreeNode> children = new ArrayList<>();
public TreeNode(String pid, String id, String categoryName) {
this.pid = pid;
this.id = id;
this.categoryName = categoryName;
}
}
@GetMapping("tree")
public Result<List<TreeNode>> tree() {
List<TreeNode> treeNodes = buildTree(categoryDictService.list(1, 100));
return new Result().ok(treeNodes);
}
/**
* 树形结构输出
*/
@RequestMapping("list") @RequestMapping("list")
public Result<List<CategoryDictDTO>> list(@RequestParam Integer pageNo, @RequestParam Integer pageSize){ public Result<List<CategoryDictDTO>> list(@RequestParam Integer pageNo, @RequestParam Integer pageSize){
List<CategoryDictDTO> list = categoryDictService.list(pageNo, pageSize); List<CategoryDictDTO> list = categoryDictService.list(pageNo, pageSize);
return new Result<List<CategoryDictDTO>>().ok(list); return new Result<List<CategoryDictDTO>>().ok(list);
} }
/**
* @description: 根据父级栏目id查询子栏目列表
* @param parentCategoryId: 父级栏目id
* @return
* @author: WangXianZhang
* @date: 2023/4/25 3:33 PM
*/
@GetMapping("subCategories")
public Result<List<CategoryDictDTO>> listSubCategories(@RequestParam("parentCategoryId") String parentCategoryId) {
List<CategoryDictDTO> list = categoryDictService.listSubCategories(parentCategoryId);
return new Result<List<CategoryDictDTO>>().ok(list);
}
/**
* @description: 构建树状结构
* @param list:
* @return
* @author: WangXianZhang
* @date: 2023/4/25 3:38 PM
*/
private List<TreeNode> buildTree(List<CategoryDictDTO> list) {
//总共2级,直接构建就行了。
List<TreeNode> pNodes = new ArrayList<>();
List<TreeNode> sNodes = new ArrayList<>();
// 过滤出一级和二级节点
for (CategoryDictDTO ele : list) {
if (StringUtils.isBlank(ele.getPid()) || "0".equals(ele.getPid())) {
// 是一级节点
pNodes.add(new TreeNode(ele.getPid(), ele.getId(), ele.getCategoryName()));
} else {
// 二级节点
sNodes.add(new TreeNode(ele.getPid(), ele.getId(), ele.getCategoryName()));
}
}
// 追加二级节点
for (TreeNode sNode : sNodes) {
for (TreeNode pNode : pNodes) {
if (pNode.getId().equals(sNode.getPid())) {
pNode.getChildren().add(sNode);
}
}
}
return pNodes;
}
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) @RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET})
public Result<CategoryDictDTO> get(@PathVariable("id") String id){ public Result<CategoryDictDTO> get(@PathVariable("id") String id){
CategoryDictDTO data = categoryDictService.get(id); CategoryDictDTO data = categoryDictService.get(id);

2
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/CategoryDictService.java

@ -85,4 +85,6 @@ public interface CategoryDictService extends BaseService<CategoryDictEntity> {
* @date: 2023/4/11 7:06 PM * @date: 2023/4/11 7:06 PM
*/ */
List<CategoryDictDTO> list(Integer pageNo, Integer pageSize); List<CategoryDictDTO> list(Integer pageNo, Integer pageSize);
List<CategoryDictDTO> listSubCategories(String parentCategoryId);
} }

13
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/CategoryDictServiceImpl.java

@ -143,7 +143,18 @@ public class CategoryDictServiceImpl extends BaseServiceImpl<CategoryDictDao, Ca
@Override @Override
public List<CategoryDictDTO> list(Integer pageNo, Integer pageSize) { public List<CategoryDictDTO> list(Integer pageNo, Integer pageSize) {
List<CategoryDictEntity> list = baseDao.selectList(null); LambdaQueryWrapper<CategoryDictEntity> query = new LambdaQueryWrapper<>();
query.eq(CategoryDictEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId());
List<CategoryDictEntity> list = baseDao.selectList(query);
return ConvertUtils.sourceToTarget(list, CategoryDictDTO.class);
}
@Override
public List<CategoryDictDTO> listSubCategories(String parentCategoryId) {
LambdaQueryWrapper<CategoryDictEntity> query = new LambdaQueryWrapper<>();
query.eq(CategoryDictEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId());
query.eq(CategoryDictEntity::getPid, parentCategoryId);
List<CategoryDictEntity> list = baseDao.selectList(query);
return ConvertUtils.sourceToTarget(list, CategoryDictDTO.class); return ConvertUtils.sourceToTarget(list, CategoryDictDTO.class);
} }
} }
Loading…
Cancel
Save