Commit 5aa497e3 by 赵剑炜

添加了装备类别的模糊查询

parent ef262676
...@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; ...@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Data @Data
...@@ -22,4 +23,9 @@ public class EquipmentTypeDto { ...@@ -22,4 +23,9 @@ public class EquipmentTypeDto {
private Boolean isLeaf; private Boolean isLeaf;
private List<String> supplierList; private List<String> supplierList;
private String photo; private String photo;
private List<EquipmentTypeDto> children = new ArrayList<>();
public void addChild(EquipmentTypeDto child) {
children.add(child);
}
} }
...@@ -12,6 +12,7 @@ public class OrgDto { ...@@ -12,6 +12,7 @@ public class OrgDto {
private String orgCode; private String orgCode;
private Integer isDepartment; private Integer isDepartment;
private Long orgParentId; private Long orgParentId;
private String orgParentIds;
private String areaName; private String areaName;
private String levelFlag; private String levelFlag;
private String dName; private String dName;
......
...@@ -15,6 +15,7 @@ import org.springframework.validation.annotation.Validated; ...@@ -15,6 +15,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.List; import java.util.List;
@RestController @RestController
...@@ -49,7 +50,11 @@ public class EquipmentTypeController { ...@@ -49,7 +50,11 @@ public class EquipmentTypeController {
public ApiRes<List<EquipmentTypeDto>> ShowEquipmentList(@RequestBody QueryEquipmentTypeReq req) { public ApiRes<List<EquipmentTypeDto>> ShowEquipmentList(@RequestBody QueryEquipmentTypeReq req) {
return ApiRes.success(equipmentTypeService.getEquipmentList(req)); return ApiRes.success(equipmentTypeService.getEquipmentList(req));
} }
@PostMapping("/ShowEquipmentESList")
@ApiOperation("通过ES模糊检索类别列表")
public ApiRes<List<EquipmentTypeDto>> ShowEquipmentESList(@RequestBody QueryEquipmentTypeReq req) throws IOException {
return ApiRes.success(equipmentTypeService.getTypeTreeByEs(req));
}
@PostMapping("/GetEquipmentDetail") @PostMapping("/GetEquipmentDetail")
@ApiOperation("查询单个物资信息") @ApiOperation("查询单个物资信息")
......
package com.junmp.jyzb.entity; package com.junmp.jyzb.entity;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable; import java.io.Serializable;
...@@ -17,6 +18,7 @@ import org.springframework.data.elasticsearch.annotations.Document; ...@@ -17,6 +18,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
@NoArgsConstructor @NoArgsConstructor
@TableName("base_equipment_type") @TableName("base_equipment_type")
@Document(indexName = "type_pinyin") @Document(indexName = "type_pinyin")
@JsonIgnoreProperties(ignoreUnknown = true)
public class EquipmentType implements Serializable { public class EquipmentType implements Serializable {
/** /**
* 装备类型ID * 装备类型ID
......
...@@ -25,7 +25,7 @@ public interface EquipmentTypeService extends IService<EquipmentType> { ...@@ -25,7 +25,7 @@ public interface EquipmentTypeService extends IService<EquipmentType> {
List<EquipmentTypeDto> getLowType(QueryEquipmentTypeReq orgId); List<EquipmentTypeDto> getLowType(QueryEquipmentTypeReq orgId);
ResponseResult setTypeParentIds(); ResponseResult setTypeParentIds();
List<EquipmentTypeDto> getTypeTreeByEs(QueryOrgReq req) throws IOException; List<EquipmentTypeDto> getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException;
List<EquipmentTreeDto> GetTypeTree(); List<EquipmentTreeDto> GetTypeTree();
} }
...@@ -271,36 +271,71 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E ...@@ -271,36 +271,71 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E
return new ResponseResult(HttpStatus.SUCCESS, ReturnMsg.PASS); return new ResponseResult(HttpStatus.SUCCESS, ReturnMsg.PASS);
} }
@Override
public List<EquipmentTypeDto> getTypeTreeByEs(QueryOrgReq req) throws IOException {
return null;
}
public List<EquipmentTypeDto> getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException { public List<EquipmentTypeDto> getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException {
// LambdaQueryWrapper<EquipmentType> wp = this.createWrapper(req);
// ElasticsearchUtil esUtil=new ElasticsearchUtil<>(client); ElasticsearchUtil es=new ElasticsearchUtil<>(client);
// // 1. 从 Elasticsearch 中搜索组织机构数据 // 先从ES中拿到检索数据
// List<EquipmentType> searchResults = esUtil.searchEntities("name","type_pinyin",0, 20, req.getTypeName(),EquipmentType.class); List<EquipmentType> searchResults = es.searchEntities("type_pinyin","name",0, 10, req.getTypeName(),EquipmentType.class);
// // 2. 从数据库中获取完整的组织机构数据 LambdaQueryWrapper<EquipmentType> wp = this.createWrapper(req);
// List<EquipmentType> fullOrgData = this.list(wp); // 获取所有组织机构数据
// List<EquipmentType> allTypes = this.list(wp);
// // 3. 构建树状结构 List<EquipmentTypeDto> treeResult= buildTypeTree(searchResults,allTypes);
// List<OrgDto> tree = new ArrayList<>(); return treeResult;
// for (PubOrg searchResult : searchResults) {
// // 在完整数据中查找匹配的组织机构
// PubOrg fullOrg = findOrgById(fullOrgData, searchResult.getOrgId());
//
// // 将完整数据转换为前端需要的 DTO
// OrgDto orgDto = convertToDto(fullOrg, fullOrgData);
//
// // TODO: 根据需求决定是否加入树状结构
// tree.add(orgDto);
// }
// return tree;
return null;
} }
public List<EquipmentTypeDto> buildTypeTree(List<EquipmentType> searchResults, List<EquipmentType> allTypes) {
Map<String, EquipmentTypeDto> typeDtoMap = new HashMap<>();
// 将所有组织机构转换为OrgDto并放入map中
for (EquipmentType type : allTypes) {
EquipmentTypeDto typeDto = new EquipmentTypeDto();
BeanPlusUtil.copyProperties(type, typeDto);
// 其他字段的映射...
// 将OrgDto放入map中,以orgId为键
typeDtoMap.put(typeDto.getId(), typeDto);
}
List<EquipmentTypeDto> tree = new ArrayList<>();
// 遍历所有搜索到的组织机构数据,构建树
for (EquipmentType searchResult : searchResults) {
EquipmentTypeDto typeDto = typeDtoMap.get(searchResult.getId());
// 如果找到对应的OrgDto
if (typeDto != null && !tree.contains(typeDto)) {
// 从当前节点开始,依次向上查找上级节点,直到最顶层
String parentId = typeDto.getParentId();
// 将当前节点及其相关节点加入树中
while (parentId != null) {
EquipmentTypeDto parentDto = typeDtoMap.get(parentId);
if (parentDto != null) {
// 将当前节点添加到上级节点的children中,确保不重复添加
if (!parentDto.getChildren().contains(typeDto)) {
parentDto.getChildren().add(typeDto);
}
// 如果上级节点是最顶层,将上级节点添加到树中,确保不重复添加
if (parentDto.getParentId().equals("00000000-0000-0000-0000-000000000000")
&&parentDto.getId()!="00000000-0000-0000-0000-000000000000" && !tree.contains(parentDto)) {
tree.add(parentDto);
}
// 将上级节点设为当前节点,继续向上查找
typeDto = parentDto;
parentId = typeDto.getParentId();
} else {
parentId = null; // 上级节点不存在,跳出循环
}
}
}
}
return tree;
}
//获取整棵type树 //获取整棵type树
public List<EquipmentTreeDto> GetTypeTree() { public List<EquipmentTreeDto> GetTypeTree() {
List<EquipmentType> list = list(new LambdaQueryWrapper<EquipmentType>() List<EquipmentType> list = list(new LambdaQueryWrapper<EquipmentType>()
......
...@@ -394,11 +394,11 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -394,11 +394,11 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
// 添加 MatchQueryBuilder 作为 must 条件 // 添加 MatchQueryBuilder 作为 must 条件
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("orgName", keyword).operator(Operator.AND); MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("orgName", keyword).operator(Operator.AND);
// MatchQueryBuilder matchQueryBuilder2 = QueryBuilders.matchQuery("orgName.pinyin", keyword).operator(Operator.AND); MatchQueryBuilder matchQueryBuilder2 = QueryBuilders.matchQuery("orgName.pinyin", keyword).operator(Operator.AND);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.should(matchQueryBuilder); boolQueryBuilder.should(matchQueryBuilder);
// boolQueryBuilder.should(matchQueryBuilder2); boolQueryBuilder.should(matchQueryBuilder2);
// 添加过滤条件,只获取 delFlag 为 1 的数据 // 添加过滤条件,只获取 delFlag 为 1 的数据
builder.postFilter(QueryBuilders.termQuery("delFlag", 1)); builder.postFilter(QueryBuilders.termQuery("delFlag", 1));
...@@ -447,6 +447,7 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -447,6 +447,7 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
orgDto.setLevelFlag(String.valueOf(org.getLevelFlag())); orgDto.setLevelFlag(String.valueOf(org.getLevelFlag()));
orgDto.setStatusFlag(org.getStatusFlag()); orgDto.setStatusFlag(org.getStatusFlag());
orgDto.setDName(org.getDName()); orgDto.setDName(org.getDName());
orgDto.setOrgParentIds(org.getOrgParentIds());
// 其他字段的映射... // 其他字段的映射...
// 将OrgDto放入map中,以orgId为键 // 将OrgDto放入map中,以orgId为键
......
...@@ -28,14 +28,14 @@ public class ElasticsearchUtil<T> { ...@@ -28,14 +28,14 @@ public class ElasticsearchUtil<T> {
public List<T> searchEntities(String typeName,String index, Integer pageNum, Integer pageSize, String keyword, Class<T> entityClass) throws IOException { public List<T> searchEntities(String typeName,String index, Integer pageNum, Integer pageSize, String keyword, Class<T> entityClass) throws IOException {
if (pageNum < 0) pageNum = 0; if (pageNum < 0) pageNum = 0;
SearchRequest request = new SearchRequest(index); SearchRequest request = new SearchRequest(typeName);
SearchSourceBuilder builder = new SearchSourceBuilder(); SearchSourceBuilder builder = new SearchSourceBuilder();
builder.from(pageNum); builder.from(pageNum);
builder.size(pageSize); builder.size(pageSize);
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(typeName, keyword).operator(Operator.AND); MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(index, keyword).operator(Operator.AND);
MatchQueryBuilder matchQueryBuilder2 = QueryBuilders.matchQuery(typeName+".pinyin", keyword).operator(Operator.AND); MatchQueryBuilder matchQueryBuilder2 = QueryBuilders.matchQuery(index+".pinyin", keyword).operator(Operator.AND);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.should(matchQueryBuilder); boolQueryBuilder.should(matchQueryBuilder);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论