feat: 零部件接口懒加载

This commit is contained in:
2024-08-06 19:01:39 +08:00
parent ac47184197
commit 3ee3d1905b
6 changed files with 89 additions and 18 deletions
@@ -31,7 +31,7 @@ public class LawsDictTreeController {
@ApiOperation(value = "树形结构-获取一级树", notes = "树形结构-获取一级树")
@GetMapping("/page")
public Result<List<SysDictItem>> queryTreeList(
@RequestParam(name = "nodeName", required = false, defaultValue = "") @ApiParam("一级节点名称") String nodeName,
@RequestParam(name = "nodeName", required = false, defaultValue = "") @ApiParam("节点名称") String nodeName,
@RequestParam("dictId") @ApiParam("字典编码") String dictId) {
List<SysDictItem> list = dictTreeService.queryTreeList(nodeName, dictId);
return Result.OK(list);
@@ -49,8 +49,9 @@ public class LawsDictTreeController {
@ApiOperation(value = "树形结构-获取子集", notes = "树形结构-获取子集")
@GetMapping("/getChild")
public Result<List<SysDictItem>> getChild(@RequestParam("dictItemId") String dictItemId,
@RequestParam("dictId") @ApiParam("字典编码") String dictId) {
return Result.OK(dictTreeService.getChild(dictItemId, dictId));
@RequestParam("dictId") @ApiParam("字典编码") String dictId,
@RequestParam("nodeName") String nodeName) {
return Result.OK(dictTreeService.getChild(dictItemId, dictId, nodeName));
}
@@ -3,7 +3,6 @@ package com.jero.modules.laws.standard.controller;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.laws.standard.entity.PartName;
import com.jero.modules.laws.standard.entity.TreePage;
import com.jero.modules.laws.standard.service.ILawsPartNameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -31,17 +30,9 @@ public class LawsPartNameController {
@AutoLog(value = "企业标准-零部件树")
@ApiOperation(value = "企业标准-零部件树", notes = "企业标准-零部件树")
@GetMapping("/")
public Result<TreePage<PartName>> queryENTreeList(
@RequestParam(name = "nodeName", required = false, defaultValue = "") @ApiParam("一级节点名称") String nodeName,
@RequestParam(name = "pageNo", defaultValue = "1") @ApiParam("页码") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") @ApiParam("页面大小") Integer pageSize) {
if (pageNo == null) {
pageNo = 1;
}
if (pageSize == null) {
pageSize = 5;
}
TreePage<PartName> list = IPartNameService.queryTreeList(nodeName, pageNo, pageSize);
public Result<List<PartName>> queryENTreeList(
@RequestParam(name = "nodeName", required = false, defaultValue = "") @ApiParam("节点名称") String nodeName) {
List<PartName> list = IPartNameService.queryList(nodeName);
return Result.OK(list);
}
@@ -53,6 +44,14 @@ public class LawsPartNameController {
return Result.OK(list);
}
@AutoLog(value = "企业标准-获取子集")
@ApiOperation(value = "企业标准-获取子集", notes = "企业标准-获取子集")
@GetMapping("/getChild")
public Result<List<PartName>> getChild(@RequestParam("dictItemId") String parentCode,
@RequestParam("nodeName") String nodeName) {
return Result.OK(IPartNameService.getChild(parentCode, nodeName));
}
@AutoLog(value = "企业标准-零部件树历史数据处理")
@ApiOperation(value = "企业标准-零部件树历史数据处理", notes = "企业标准-零部件树历史数据处理")
@PostMapping("/hisDataFix")
@@ -98,6 +98,13 @@ public class PartName implements Serializable, TreeNode {
@ApiModelProperty(value = "父级分类内部码(根节点0")
private String parentCode;
/**
* 父级分类内部码(根节点0)
*/
@ApiModelProperty(value = "父级分类内部码(根节点0")
@TableField(exist = false)
private boolean hasChild;
/**
* 子零部件
*/
@@ -34,6 +34,9 @@ public class DictTreeService {
queryWrapper.clear();
queryWrapper.eq(SysDictItem::getDictId, dictId);
queryWrapper.in(SysDictItem::getParentId, dictItemIds);
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(SysDictItem::getItemText, nodeName);
}
List<SysDictItem> childList = dictItemService.list(queryWrapper);
list.forEach(item -> {
if (childList.stream().anyMatch(child -> child.getParentId().equals(item.getId()))) {
@@ -50,10 +53,13 @@ public class DictTreeService {
return dictItemService.list(queryWrapper);
}
public List<SysDictItem> getChild(String dictItemId, String dictId) {
public List<SysDictItem> getChild(String dictItemId, String dictId, String nodeName) {
LambdaQueryWrapper<SysDictItem> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDictItem::getDictId, dictId);
queryWrapper.eq(SysDictItem::getParentId, dictItemId);
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(SysDictItem::getItemText, nodeName);
}
List<SysDictItem> list = dictItemService.list(queryWrapper);
List<String> dictItemIds = list.stream().map(SysDictItem::getId).collect(Collectors.toList());
@@ -61,6 +67,9 @@ public class DictTreeService {
queryWrapper.clear();
queryWrapper.eq(SysDictItem::getDictId, dictId);
queryWrapper.in(SysDictItem::getParentId, dictItemIds);
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(SysDictItem::getItemText, nodeName);
}
List<SysDictItem> childList = dictItemService.list(queryWrapper);
list.forEach(item -> {
if (childList.stream().anyMatch(child -> child.getParentId().equals(item.getId()))) {
@@ -1,7 +1,7 @@
package com.jero.modules.laws.standard.service;
import com.jero.modules.laws.standard.entity.PartName;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.laws.standard.entity.PartName;
import com.jero.modules.laws.standard.entity.TreePage;
import java.util.List;
@@ -21,6 +21,7 @@ public interface ILawsPartNameService extends IService<PartName> {
* @param pageSize 页面大小
* @return 零部件树
*/
@Deprecated
TreePage<PartName> queryTreeList(String nodeName, Integer pageNo, Integer pageSize);
/**
@@ -35,4 +36,8 @@ public interface ILawsPartNameService extends IService<PartName> {
* 零部件树历史数据处理
*/
void fixFirstNodeCode();
List<PartName> queryList(String nodeName);
List<PartName> getChild(String parentCode, String nodeName);
}
@@ -7,8 +7,8 @@ import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.laws.standard.entity.PartName;
import com.jero.modules.laws.standard.entity.TreePage;
import com.jero.modules.laws.standard.service.ILawsPartNameService;
import com.jero.modules.laws.standard.mapper.PartNameMapper;
import com.jero.modules.laws.standard.service.ILawsPartNameService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -177,6 +177,56 @@ public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
}
}
@Override
public List<PartName> queryList(String nodeName) {
LambdaQueryWrapper<PartName> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PartName::getParentCode, "Part");
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(PartName::getName, nodeName);
}
List<PartName> list = list(queryWrapper);
List<String> codes = list.stream().map(PartName::getCode).collect(Collectors.toList());
// 判断有没有子级
queryWrapper.clear();
queryWrapper.in(PartName::getParentCode, codes);
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(PartName::getName, nodeName);
}
List<PartName> childList = list(queryWrapper);
list.forEach(item -> {
if (childList.stream().anyMatch(child -> child.getParentCode().equals(item.getCode()))) {
item.setHasChild(true);
}
});
return list;
}
@Override
public List<PartName> getChild(String parentCode, String nodeName) {
LambdaQueryWrapper<PartName> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PartName::getParentCode, "Part");
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(PartName::getName, nodeName);
}
List<PartName> list = list(queryWrapper);
List<String> codes = list.stream().map(PartName::getCode).collect(Collectors.toList());
// 判断有没有子级
queryWrapper.clear();
queryWrapper.in(PartName::getParentCode, codes);
if (nodeName != null && !nodeName.isEmpty()) {
queryWrapper.like(PartName::getName, nodeName);
}
List<PartName> childList = list(queryWrapper);
list.forEach(item -> {
if (childList.stream().anyMatch(child -> child.getParentCode().equals(item.getCode()))) {
item.setHasChild(true);
}
});
return list;
}
private PartName getFirstLevelNode(PartName node, Map<String, PartName> nodeMap) {
if (node.getParentCode().equals("Part")) {
return node;