diff --git a/db/prod/2024-3-18-变更.sql b/db/prod/2024-3-18-变更.sql index 8736bf50..8a97224b 100644 --- a/db/prod/2024-3-18-变更.sql +++ b/db/prod/2024-3-18-变更.sql @@ -195,3 +195,10 @@ INSERT INTO `laws_tag` (`id`, `table_name`, `db_field_name`, `db_field_en_name`, INSERT INTO `laws_tag` (`id`, `table_name`, `db_field_name`, `db_field_en_name`, `db_field_txt`, `order_num`, `db_field_name_old`, `db_is_key`, `db_is_null`, `db_type`, `db_length`, `db_point_length`, `db_default_val`, `dict_field`, `dict_table`, `dict_text`, `field_show_type`, `field_href`, `field_length`, `field_valid_type`, `field_must_input`, `field_extend_json`, `field_default_value`, `is_show_form_create`, `is_query`, `is_show_form`, `is_show_list`, `is_read_only`, `query_mode`, `main_table`, `main_field`, `update_by`, `update_time`, `create_time`, `create_by`, `converter`, `query_def_val`, `query_dict_text`, `query_dict_field`, `query_dict_table`, `query_show_type`, `query_config_flag`, `query_valid_type`, `query_must_input`, `sort_flag`, `show_area`, `is_show_laws_list`, `is_show_search`, `del_flag`, `is_model`, `dict_id`, `home_search_context_order`, `home_search_file_order`, `dict_field_search`, `dict_table_search`, `dict_text_search`, `usable_range`) VALUES ('1818916543200575489', 'laws_domestic_standard', 'new_model_implementation_date_remarks', 'New model implementation date Remarks', '新车型实施日期备注', 12, 'new_model_implementation_date_remarks', 0, 1, 'String', 500, NULL, NULL, NULL, NULL, NULL, '5', NULL, NULL, NULL, '0', NULL, NULL, 1, 0, 1, 0, 0, NULL, NULL, NULL, NULL, NULL, '2024-08-01 15:47:52', 'ldq1', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '1499657602378825729', NULL, 0, 0, '1', NULL, NULL, NULL, NULL, NULL, NULL, NULL); INSERT INTO `laws_tag` (`id`, `table_name`, `db_field_name`, `db_field_en_name`, `db_field_txt`, `order_num`, `db_field_name_old`, `db_is_key`, `db_is_null`, `db_type`, `db_length`, `db_point_length`, `db_default_val`, `dict_field`, `dict_table`, `dict_text`, `field_show_type`, `field_href`, `field_length`, `field_valid_type`, `field_must_input`, `field_extend_json`, `field_default_value`, `is_show_form_create`, `is_query`, `is_show_form`, `is_show_list`, `is_read_only`, `query_mode`, `main_table`, `main_field`, `update_by`, `update_time`, `create_time`, `create_by`, `converter`, `query_def_val`, `query_dict_text`, `query_dict_field`, `query_dict_table`, `query_show_type`, `query_config_flag`, `query_valid_type`, `query_must_input`, `sort_flag`, `show_area`, `is_show_laws_list`, `is_show_search`, `del_flag`, `is_model`, `dict_id`, `home_search_context_order`, `home_search_file_order`, `dict_field_search`, `dict_table_search`, `dict_text_search`, `usable_range`) VALUES ('1818916929537916923', 'laws_overseas_standard', 'on_the_production_date_remarks', 'Remarks on date of implementation in production ve', '在产车实施日期备注', 13, 'on_the_production_date_remarks', 0, 1, 'String', 500, NULL, NULL, NULL, NULL, NULL, '5', NULL, NULL, NULL, '0', NULL, NULL, 1, 0, 1, 0, 0, NULL, NULL, NULL, NULL, NULL, '2024-08-01 15:49:25', 'ldq1', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '1694630597254553601', NULL, 0, 0, '1', NULL, NULL, NULL, NULL, NULL, NULL, NULL); INSERT INTO `laws_tag` (`id`, `table_name`, `db_field_name`, `db_field_en_name`, `db_field_txt`, `order_num`, `db_field_name_old`, `db_is_key`, `db_is_null`, `db_type`, `db_length`, `db_point_length`, `db_default_val`, `dict_field`, `dict_table`, `dict_text`, `field_show_type`, `field_href`, `field_length`, `field_valid_type`, `field_must_input`, `field_extend_json`, `field_default_value`, `is_show_form_create`, `is_query`, `is_show_form`, `is_show_list`, `is_read_only`, `query_mode`, `main_table`, `main_field`, `update_by`, `update_time`, `create_time`, `create_by`, `converter`, `query_def_val`, `query_dict_text`, `query_dict_field`, `query_dict_table`, `query_show_type`, `query_config_flag`, `query_valid_type`, `query_must_input`, `sort_flag`, `show_area`, `is_show_laws_list`, `is_show_search`, `del_flag`, `is_model`, `dict_id`, `home_search_context_order`, `home_search_file_order`, `dict_field_search`, `dict_table_search`, `dict_text_search`, `usable_range`) VALUES ('1818916929537916929', 'laws_domestic_standard', 'on_the_production_date_remarks', 'Remarks on date of implementation in production ve', '在产车实施日期备注', 12, 'on_the_production_date_remarks', 0, 1, 'String', 500, NULL, NULL, NULL, NULL, NULL, '5', NULL, NULL, NULL, '0', NULL, NULL, 1, 0, 1, 0, 0, NULL, NULL, NULL, NULL, NULL, '2024-08-01 15:49:25', 'ldq1', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', '1499657602378825729', NULL, 0, 0, '1', NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +-- 2024-08-12 零部件性能优化 +ALTER TABLE `laws_tag` + ADD COLUMN `tree_first_href` varchar(255) NULL DEFAULT NULL COMMENT '懒加载树形结构一级接口' AFTER `usable_range`; +UPDATE `laws_tag` SET `field_show_type` = '17', `tree_first_href` = '/laws/standard/partName/queryFirstList' WHERE `id` = '1696038850540003301'; +UPDATE `laws_tag` SET `field_show_type` = '17', `tree_first_href` = '/laws/standard/partName/queryFirstList' WHERE `id` = '1696038850540003330'; +UPDATE `laws_tag` SET `field_show_type` = '17', `tree_first_href` = '/laws/standard/partName/queryFirstList' WHERE `id` = '1703608885251108865'; diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsPartNameController.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsPartNameController.java index 9b39f7eb..84092b0b 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsPartNameController.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsPartNameController.java @@ -1,10 +1,7 @@ package com.jero.modules.laws.standard.controller; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.jero.common.api.vo.Result; import com.jero.common.aspect.annotation.AutoLog; -import com.jero.modules.laws.enterprise.entity.vo.LawsTreeNodeModel; -import com.jero.modules.laws.standard.entity.LawsTreeNode; import com.jero.modules.laws.standard.entity.PartName; import com.jero.modules.laws.standard.entity.TreePage; import com.jero.modules.laws.standard.service.PartNameService; @@ -64,5 +61,22 @@ public class LawsPartNameController { return Result.OK(); } + @AutoLog(value = "企业标准-零部件树") + @ApiOperation(value = "企业标准-零部件树", notes = "企业标准-零部件树") + @GetMapping("/queryFirstList") + public Result> queryFirstList( + @RequestParam(name = "nodeName", required = false, defaultValue = "") @ApiParam("节点名称") String nodeName) { + List list = partNameService.queryList(nodeName); + return Result.OK(list); + } + + + @AutoLog(value = "企业标准-获取子集") + @ApiOperation(value = "企业标准-获取子集", notes = "企业标准-获取子集") + @GetMapping("/getChild") + public Result> getChild(@RequestParam("parentCode") String parentCode, + @RequestParam("nodeName") String nodeName) { + return Result.OK(partNameService.getChild(parentCode, nodeName)); + } } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/PartName.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/PartName.java index 3a6a3ac9..64e640ba 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/PartName.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/entity/PartName.java @@ -4,17 +4,17 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + /** * @TableName laws_part_name */ @@ -107,6 +107,14 @@ public class PartName implements Serializable { @ApiModelProperty(value = "备用字段3") private String remark3; + /** + * 是否是叶子节点 + */ + @ApiModelProperty(value = "是否是叶子节点") + @TableField(exist = false) + @JsonProperty("isLeaf") + private boolean leafFlag; + /** * 子零部件 */ diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/PartNameService.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/PartNameService.java index 3e1abf66..55cdddca 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/PartNameService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/PartNameService.java @@ -35,4 +35,8 @@ public interface PartNameService extends IService { * 零部件树历史数据处理 */ void fixFirstNodeCode(); + + List queryList(String nodeName); + + List getChild(String parentCode, String nodeName); } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/PartNameServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/PartNameServiceImpl.java index d82670f9..9354f0c1 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/PartNameServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/PartNameServiceImpl.java @@ -193,6 +193,118 @@ public class PartNameServiceImpl extends ServiceImpl } + @Override + public List queryList(String nodeName) { + // 查询所有节点 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + List allNodes = list(queryWrapper); + + // 通过 nodeName 过滤符合条件的节点 + List matchedNodes = allNodes.stream() + .filter(node -> node.getName() != null && node.getName().contains(nodeName)) + .collect(Collectors.toList()); + + if (matchedNodes.isEmpty()) { + return Collections.emptyList(); + } + + // 用于存储一级节点 + Set rootNodes = new HashSet<>(); + + // 查找每个匹配节点的一级父节点 + for (PartName matchedNode : matchedNodes) { + PartName currentNode = matchedNode; + while (currentNode != null && !currentNode.getParentCode().equals("Part")) { + // 查找当前节点的父节点 + String parentCode = currentNode.getParentCode(); + currentNode = allNodes.stream() + .filter(node -> node.getCode().equals(parentCode)) + .findFirst() + .orElse(null); + } + // 添加一级节点到结果集 + if (currentNode != null) { + rootNodes.add(currentNode); + } + } + + // 设置叶子标志的逻辑调整 + for (PartName node : rootNodes) { + Set descendantCodes = getAllDescendantCodes(node.getCode(), allNodes); // 获取所有子孙节点的ID + boolean isLeaf = true; // 默认设置为叶子节点 + + for (PartName matchedNode : matchedNodes) { + if (descendantCodes.contains(matchedNode.getCode())) { + isLeaf = false; + break; // 如果在子孙节点中找到匹配节点,当前根节点不是叶子节点 + } + } + node.setLeafFlag(isLeaf); // 设置叶子标志 + } + + return new ArrayList<>(rootNodes); + } + + // 方法:获取给定节点ID的所有子孙节点ID + private Set getAllDescendantCodes(String parentCode, List allNodes) { + Set descendantCodes = new HashSet<>(); + List directChildren = allNodes.stream() + .filter(node -> node.getParentCode().equals(parentCode)) + .collect(Collectors.toList()); + + for (PartName child : directChildren) { + descendantCodes.add(child.getCode()); + descendantCodes.addAll(getAllDescendantCodes(child.getCode(), allNodes)); // 递归获取子孙节点 + } + + return descendantCodes; + } + + @Override + public List getChild(String parentCode, String nodeName) { + // 查询所有节点 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + List allNodes = list(queryWrapper); + + // 通过 nodeName 过滤符合条件的节点 + List matchedNodes = allNodes.stream() + .filter(node -> node.getName() != null && node.getName().contains(nodeName)) + .collect(Collectors.toList()); + + if (matchedNodes.isEmpty()) { + return Collections.emptyList(); + } + + // 用于存储一级节点 + Set rootNodes = new HashSet<>(); + + // 查找每个匹配节点的一级父节点 + for (PartName matchedNode : matchedNodes) { + PartName currentNode = matchedNode; + while (currentNode != null && !currentNode.getParentCode().equals(parentCode)) { + // 查找当前节点的父节点 + String pCode = currentNode.getParentCode(); + currentNode = allNodes.stream() + .filter(node -> node.getCode().equals(pCode)) + .findFirst() + .orElse(null); + } + // 添加一级节点到结果集 + if (currentNode != null) { + rootNodes.add(currentNode); + } + } + + // 设置叶子标志 + Set rootNodeCodes = rootNodes.stream().map(PartName::getCode).collect(Collectors.toSet()); + rootNodes.forEach(node -> { + node.setLeafFlag(matchedNodes.stream() + .noneMatch(n -> rootNodeCodes.contains(n.getParentCode()))); + }); + + return new ArrayList<>(rootNodes); + } + }