Commit f424b1ba by 赵剑炜

修改智能检索接口

parent 631b307e
package com.junmp.jyzb.api.bean.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class ESOrgDto {
private List<OrgDto> orgDto;
private ArrayList ids;
}
package com.junmp.jyzb.api.bean.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class ESTypeDto {
private List<EquipmentTypeDto> typeDto;
private ArrayList ids;
}
...@@ -2,6 +2,8 @@ package com.junmp.jyzb.controller.ES; ...@@ -2,6 +2,8 @@ package com.junmp.jyzb.controller.ES;
import com.junmp.jyzb.Repository.BlogRepository; import com.junmp.jyzb.Repository.BlogRepository;
import com.junmp.jyzb.entity.ES.Blog; import com.junmp.jyzb.entity.ES.Blog;
import com.junmp.jyzb.entity.EquipmentSize;
import com.junmp.jyzb.service.EquipmentSizeService;
import com.junmp.jyzb.service.EquipmentTypeService; import com.junmp.jyzb.service.EquipmentTypeService;
import com.junmp.jyzb.service.PubOrgService; import com.junmp.jyzb.service.PubOrgService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -33,6 +35,8 @@ public class CrudController { ...@@ -33,6 +35,8 @@ public class CrudController {
@Resource @Resource
public EquipmentTypeService equipmentTypeService; public EquipmentTypeService equipmentTypeService;
@Resource @Resource
public EquipmentSizeService equipmentSizeService;
@Resource
public PubOrgService pubOrgService; public PubOrgService pubOrgService;
@ApiOperation("测试") @ApiOperation("测试")
@PostMapping("testDocument") @PostMapping("testDocument")
...@@ -50,7 +54,7 @@ public class CrudController { ...@@ -50,7 +54,7 @@ public class CrudController {
public Object UpdateES() { public Object UpdateES() {
pubOrgService.AddToEs(); pubOrgService.AddToEs();
equipmentTypeService.addEs(); equipmentTypeService.addEs();
equipmentSizeService.addEs();
return true; return true;
} }
@ApiOperation("添加单个文档") @ApiOperation("添加单个文档")
......
package com.junmp.jyzb.controller; package com.junmp.jyzb.controller;
import com.junmp.jyzb.api.bean.dto.ESTypeDto;
import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto; import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto;
import com.junmp.jyzb.api.bean.dto.EquipmentTreeDto; import com.junmp.jyzb.api.bean.dto.EquipmentTreeDto;
import com.junmp.jyzb.api.bean.query.QueryEquipmentTypeReq; import com.junmp.jyzb.api.bean.query.QueryEquipmentTypeReq;
...@@ -52,7 +53,7 @@ public class EquipmentTypeController { ...@@ -52,7 +53,7 @@ public class EquipmentTypeController {
} }
@PostMapping("/ShowEquipmentESList") @PostMapping("/ShowEquipmentESList")
@ApiOperation("通过ES模糊检索类别列表") @ApiOperation("通过ES模糊检索类别列表")
public ApiRes<List<EquipmentTypeDto>> ShowEquipmentESList(@RequestBody QueryEquipmentTypeReq req) throws IOException { public ApiRes<ESTypeDto> ShowEquipmentESList(@RequestBody QueryEquipmentTypeReq req) throws IOException {
return ApiRes.success(equipmentTypeService.getTypeTreeByEs(req)); return ApiRes.success(equipmentTypeService.getTypeTreeByEs(req));
} }
......
package com.junmp.jyzb.controller; package com.junmp.jyzb.controller;
import com.junmp.jyzb.api.bean.dto.ESOrgDto;
import com.junmp.jyzb.api.bean.dto.OrgDto; import com.junmp.jyzb.api.bean.dto.OrgDto;
import com.junmp.jyzb.api.bean.dto.OrgTreeDto; import com.junmp.jyzb.api.bean.dto.OrgTreeDto;
import com.junmp.jyzb.api.bean.query.ProductSkuReq; import com.junmp.jyzb.api.bean.query.ProductSkuReq;
...@@ -56,7 +57,7 @@ public class PubOrgController { ...@@ -56,7 +57,7 @@ public class PubOrgController {
} }
@PostMapping("/GetCurrentESList") @PostMapping("/GetCurrentESList")
@ApiOperation("根据当前组织机构列表ES查询") @ApiOperation("根据当前组织机构列表ES查询")
public ApiRes<List<OrgDto>> GetCurrentESList(@RequestBody QueryOrgReq req) throws IOException { public ApiRes<ESOrgDto> GetCurrentESList(@RequestBody QueryOrgReq req) throws IOException {
return ApiRes.success(pubOrgService.getOrgTreeByEs(req)); return ApiRes.success(pubOrgService.getOrgTreeByEs(req));
} }
@PostMapping("/ChangeOrgState") @PostMapping("/ChangeOrgState")
......
package com.junmp.jyzb.service; package com.junmp.jyzb.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.junmp.jyzb.api.bean.dto.ESTypeDto;
import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto; import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto;
import com.junmp.jyzb.api.bean.dto.EquipmentTreeDto; import com.junmp.jyzb.api.bean.dto.EquipmentTreeDto;
import com.junmp.jyzb.api.bean.dto.OrgDto; import com.junmp.jyzb.api.bean.dto.OrgDto;
...@@ -25,7 +26,7 @@ public interface EquipmentTypeService extends IService<EquipmentType> { ...@@ -25,7 +26,7 @@ public interface EquipmentTypeService extends IService<EquipmentType> {
List<EquipmentTypeDto> getLowType(QueryEquipmentTypeReq orgId); List<EquipmentTypeDto> getLowType(QueryEquipmentTypeReq orgId);
ResponseResult setTypeParentIds(); ResponseResult setTypeParentIds();
List<EquipmentTypeDto> getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException; ESTypeDto getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException;
List<EquipmentTreeDto> GetTypeTree(); List<EquipmentTreeDto> GetTypeTree();
} }
...@@ -20,6 +20,8 @@ import java.util.List; ...@@ -20,6 +20,8 @@ import java.util.List;
public interface PolicemanService extends IService<Policeman> { public interface PolicemanService extends IService<Policeman> {
Object addEs();
//添加警员 //添加警员
String AddPoliceman(UpdatePolicemanReq req); String AddPoliceman(UpdatePolicemanReq req);
......
package com.junmp.jyzb.service; package com.junmp.jyzb.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.junmp.jyzb.api.bean.dto.ESOrgDto;
import com.junmp.jyzb.api.bean.dto.OrgDto; import com.junmp.jyzb.api.bean.dto.OrgDto;
import com.junmp.jyzb.api.bean.dto.OrgTreeDto; import com.junmp.jyzb.api.bean.dto.OrgTreeDto;
import com.junmp.jyzb.api.bean.dto.TjOrgEqsDto; import com.junmp.jyzb.api.bean.dto.TjOrgEqsDto;
...@@ -29,7 +30,7 @@ public interface PubOrgService extends IService<PubOrg> { ...@@ -29,7 +30,7 @@ public interface PubOrgService extends IService<PubOrg> {
OrgDto getOrgHierarchy(QueryOrgReq req); OrgDto getOrgHierarchy(QueryOrgReq req);
List<OrgDto> getOrgTreeByEs(QueryOrgReq req) throws IOException; ESOrgDto getOrgTreeByEs(QueryOrgReq req) throws IOException;
List<OrgDto> getLowOrg(QueryOrgReq req); List<OrgDto> getLowOrg(QueryOrgReq req);
Boolean ChangeState(UpdateOrgReq req); Boolean ChangeState(UpdateOrgReq req);
......
...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.junmp.jyzb.Repository.BlogRepository; import com.junmp.jyzb.Repository.BlogRepository;
import com.junmp.jyzb.Repository.TypeRepository; import com.junmp.jyzb.Repository.TypeRepository;
import com.junmp.jyzb.api.bean.dto.ESTypeDto;
import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto; import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto;
import com.junmp.jyzb.api.bean.dto.EquipmentTreeDto; import com.junmp.jyzb.api.bean.dto.EquipmentTreeDto;
import com.junmp.jyzb.api.bean.dto.OrgDto; import com.junmp.jyzb.api.bean.dto.OrgDto;
...@@ -46,7 +47,8 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E ...@@ -46,7 +47,8 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E
@Resource @Resource
private SupplierTypeService supplierTypeService; private SupplierTypeService supplierTypeService;
private static final String REDIS_TYPE = "Type_"; private static final String REDIS_TYPE = "Type_";
private List<EquipmentTypeDto> typeDto;
private ArrayList<String> ids;
//查询出类别表中数据的所有装备信息(入库时调用) //查询出类别表中数据的所有装备信息(入库时调用)
public List<EquipmentTypeDto> getEquipmentList(QueryEquipmentTypeReq req) { public List<EquipmentTypeDto> getEquipmentList(QueryEquipmentTypeReq req) {
...@@ -272,7 +274,7 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E ...@@ -272,7 +274,7 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E
} }
public List<EquipmentTypeDto> getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException { public ESTypeDto getTypeTreeByEs(QueryEquipmentTypeReq req) throws IOException {
ElasticsearchUtil es=new ElasticsearchUtil<>(client); ElasticsearchUtil es=new ElasticsearchUtil<>(client);
// 先从ES中拿到检索数据 // 先从ES中拿到检索数据
...@@ -281,7 +283,34 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E ...@@ -281,7 +283,34 @@ public class EquipmentTypeServiceImpl extends ServiceImpl<EquipmentTypeMapper, E
// 获取所有组织机构数据 // 获取所有组织机构数据
List<EquipmentType> allTypes = this.list(wp); List<EquipmentType> allTypes = this.list(wp);
List<EquipmentTypeDto> treeResult= buildTypeTree(searchResults,allTypes); List<EquipmentTypeDto> treeResult= buildTypeTree(searchResults,allTypes);
return treeResult; ESTypeDto resultDto=new ESTypeDto();
resultDto.setTypeDto(treeResult);
SetIds(treeResult);
resultDto.setIds(ids);
return resultDto;
}
public void SetIds(List<EquipmentTypeDto> treeResult) {
ids = new ArrayList<>();
if (treeResult != null) {
for (EquipmentTypeDto equipmentTypeDto : treeResult) {
setIdsRecursive(equipmentTypeDto);
}
}
}
private void setIdsRecursive(EquipmentTypeDto equipmentTypeDto) {
if (equipmentTypeDto != null) {
// 添加当前节点的 id
ids.add(equipmentTypeDto.getId());
// 递归处理子节点
if (equipmentTypeDto.getChildren() != null) {
for (EquipmentTypeDto child : equipmentTypeDto.getChildren()) {
setIdsRecursive(child);
}
}
}
} }
public List<EquipmentTypeDto> buildTypeTree(List<EquipmentType> searchResults, List<EquipmentType> allTypes) { public List<EquipmentTypeDto> buildTypeTree(List<EquipmentType> searchResults, List<EquipmentType> allTypes) {
......
...@@ -117,6 +117,11 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman ...@@ -117,6 +117,11 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
private static final String REDIS_ORG = "Organization_"; private static final String REDIS_ORG = "Organization_";
@Override
public Object addEs() {
return null;
}
/** /**
* 添加警员信息 * 添加警员信息
* *
......
...@@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.junmp.jyzb.Repository.PubOrgRepository; import com.junmp.jyzb.Repository.PubOrgRepository;
import com.junmp.jyzb.Repository.TypeRepository; import com.junmp.jyzb.Repository.TypeRepository;
import com.junmp.jyzb.api.bean.dto.EquipmentTypeDto; import com.junmp.jyzb.api.bean.dto.*;
import com.junmp.jyzb.api.bean.dto.OrgDto;
import com.junmp.jyzb.api.bean.dto.OrgTreeDto;
import com.junmp.jyzb.api.bean.dto.TjOrgEqsDto;
import com.junmp.jyzb.api.bean.query.QueryOrgReq; import com.junmp.jyzb.api.bean.query.QueryOrgReq;
import com.junmp.jyzb.api.bean.req.UpdateOrgReq; import com.junmp.jyzb.api.bean.req.UpdateOrgReq;
import com.junmp.jyzb.api.exception.JYZBAppException; import com.junmp.jyzb.api.exception.JYZBAppException;
...@@ -60,7 +57,8 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -60,7 +57,8 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Autowired @Autowired
private PubOrgRepository pubOrgRepository; private PubOrgRepository pubOrgRepository;
private List<OrgDto> OrgDto;
private ArrayList<String> ids;
//例:传入abc,OrderMQReceiver ==>bc 删掉开头的字符串,不是就不删除 //例:传入abc,OrderMQReceiver ==>bc 删掉开头的字符串,不是就不删除
public static String removePrefix(String name, String deleteName) { public static String removePrefix(String name, String deleteName) {
if (name.startsWith(deleteName)) { if (name.startsWith(deleteName)) {
...@@ -514,7 +512,7 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -514,7 +512,7 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
} }
///通过ES获取数据 ///通过ES获取数据
@Override @Override
public List<OrgDto> getOrgTreeByEs(QueryOrgReq req) throws IOException { public ESOrgDto getOrgTreeByEs(QueryOrgReq req) throws IOException {
// 先进行搜索,获取前20条数据 // 先进行搜索,获取前20条数据
List<PubOrg> searchResults = searchOrg(0, 10, req.getOrgName()); List<PubOrg> searchResults = searchOrg(0, 10, req.getOrgName());
...@@ -523,8 +521,34 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -523,8 +521,34 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
// 获取所有组织机构数据 // 获取所有组织机构数据
List<PubOrg> allOrgs = this.list(wp); List<PubOrg> allOrgs = this.list(wp);
List<OrgDto> treeResult= buildTree(searchResults,allOrgs); List<OrgDto> treeResult= buildTree(searchResults,allOrgs);
return treeResult; ESOrgDto resultDto =new ESOrgDto();
resultDto.setOrgDto(treeResult);
SetIds(treeResult);
resultDto.setIds(ids);
return resultDto;
}
public void SetIds(List<OrgDto> treeResult) {
ids = new ArrayList<>();
if (treeResult != null) {
for (OrgDto orgDto : treeResult) {
setIdsRecursive(orgDto);
}
}
}
private void setIdsRecursive(OrgDto orgDto) {
if (orgDto != null) {
// 添加当前节点的 id
ids.add(String.valueOf(orgDto.getOrgId()));
// 递归处理子节点
if (orgDto.getChildren() != null) {
for (OrgDto child : orgDto.getChildren()) {
setIdsRecursive(child);
}
}
}
} }
private OrgDto convertToDto(PubOrg org, List<PubOrg> allOrgs) { private OrgDto convertToDto(PubOrg org, List<PubOrg> allOrgs) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论