Commit 9b7f7b21 authored by kongfm's avatar kongfm

特种设备ES 搜索优化

parent 35ee00c5
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 特种设备搜索DTO
*/
@Data
@ApiModel(value="EsSpecialEquipmentDto", description="特种设备搜索DTO")
public class EsSpecialEquipmentDto {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* 左上经度
*/
@ApiModelProperty(value = "左上经度")
private Double startLongitude;
/**
* 左上纬度
*/
@ApiModelProperty(value = "左上纬度")
private Double startLatitude;
/**
* 右下经度
*/
@ApiModelProperty(value = "右下经度")
private Double endLongitude;
/**
* 右下纬度
*/
@ApiModelProperty(value = "右下纬度")
private Double endLatitude;
/**
* 搜索关键字
*/
@ApiModelProperty(value = "搜索关键字")
private String keyword;
/**
* 所属区域代码
*/
@ApiModelProperty(value = "所属区域代码")
private String regionCode;
/**
* 设备类别编码
*/
@ApiModelProperty(value = "设备类别编码")
private String categoryCode;
@ApiModelProperty(value = "聚合精确度1-12")
private Integer precision;
}
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 特种设备搜索列表DTO
*/
@Data
@ApiModel(value="EsSpecialEquipmentListDto", description="特种设备搜索列表DTO")
public class EsSpecialEquipmentListDto {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* 所属区域代码
*/
@ApiModelProperty(value = "所属区域代码")
private String regionCode;
/**
* 设备类别编码
*/
@ApiModelProperty(value = "设备类别编码")
private String categoryCode;
/**
* 搜索数量
*/
@ApiModelProperty(value = "搜索数量")
private Integer equipmentNumber;
}
package com.yeejoin.amos.boot.module.tzs.api.dto;
import com.alibaba.excel.annotation.ExcelIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 特种设备DTO
*/
@Data
@ApiModel(value="SpecialEquipmentDto", description="特种设备DTO")
public class SpecialEquipmentDto {
/**
*
*/
private static final long serialVersionUID = 1L;
@ExcelIgnore
@ApiModelProperty(value = "主键ID")
protected Long sequenceNbr;
@ApiModelProperty(value = "电梯应急救援识别码")
private Integer rescueCode;
@ApiModelProperty(value = "设备注册代码")
private String registerCode;
@ApiModelProperty(value = "所属省")
private String province;
@ApiModelProperty(value = "所属地市")
private String city;
@ApiModelProperty(value = "所属区县")
private String district;
@ApiModelProperty(value = "所属区域代码")
private String regionCode;
@ApiModelProperty(value = "安装地址")
private String address;
@ApiModelProperty(value = "经度")
private Double longitude;
@ApiModelProperty(value = "纬度")
private Double latitude;
@ApiModelProperty(value = "设备类别编码")
private String categoryCode;
}
...@@ -2,10 +2,12 @@ package com.yeejoin.amos.boot.module.tzs.api.entity; ...@@ -2,10 +2,12 @@ package com.yeejoin.amos.boot.module.tzs.api.entity;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.elasticsearch.common.geo.GeoPoint;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
/** /**
* @author litw * @author litw
...@@ -55,19 +57,25 @@ public class EsElevator { ...@@ -55,19 +57,25 @@ public class EsElevator {
* 电梯识别码 * 电梯识别码
*/ */
@Field(type = FieldType.Text) @Field(type = FieldType.Text)
private Integer rescueCode; private String rescueCode;
/** /**
* 电梯经度 * 电梯经度
*/ */
@Field(type = FieldType.Text) @Field(type = FieldType.Double)
private String longitude; private Double longitude;
/** /**
* 电梯纬度 * 电梯纬度
*/ */
@Field(type = FieldType.Text) @Field(type = FieldType.Double)
private String latitude; private Double latitude;
/**
* 经纬度字段
*/
@GeoPointField
private GeoPoint location;
/** /**
* 地址 * 地址
......
...@@ -688,17 +688,22 @@ public class AlertCalledController extends BaseController { ...@@ -688,17 +688,22 @@ public class AlertCalledController extends BaseController {
while(regionIt.hasNext()) { while(regionIt.hasNext()) {
String tempCode = regionIt.next(); String tempCode = regionIt.next();
String districtCode = tempCode.substring(4,6); String districtCode = tempCode.substring(4,6);
if("00".equals(districtCode)) { // 为市 String provinceCode = tempCode.substring(2,6);
if(!useRegionCode.contains(tempCode)) { // 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件 if("0000".equals(provinceCode)) {// 为省则默认使用用户现有权限查询数据
for(String tempUsercode : useRegionCode) { regionCodes = useRegionCode;
if(tempUsercode.indexOf(tempCode.substring(0,4)) != -1) { } else {
tempList.add(tempUsercode); if("00".equals(districtCode)) { // 为市
if(!useRegionCode.contains(tempCode)) { // 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件
for(String tempUsercode : useRegionCode) {
if(tempUsercode.indexOf(tempCode.substring(0,4)) != -1) {
tempList.add(tempUsercode);
}
} }
regionIt.remove();
} }
regionIt.remove(); } else { // 为区 不会出现越权情况
}
} else { // 为区 不会出现越权情况
}
} }
} }
for (String t : tempList) { for (String t : tempList) {
...@@ -727,17 +732,22 @@ public class AlertCalledController extends BaseController { ...@@ -727,17 +732,22 @@ public class AlertCalledController extends BaseController {
while(regionIt.hasNext()) { while(regionIt.hasNext()) {
String tempCode = regionIt.next(); String tempCode = regionIt.next();
String districtCode = tempCode.substring(4,6); String districtCode = tempCode.substring(4,6);
if("00".equals(districtCode)) { // 为市 String provinceCode = tempCode.substring(2,6);
if(!useRegionCode.contains(tempCode)) { // 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件 if("0000".equals(provinceCode)) {// 为省则默认使用用户现有权限查询数据
for(String tempUsercode : useRegionCode) { regionCodes = useRegionCode;
if(tempUsercode.indexOf(tempCode.substring(0,4)) != -1) { } else {
tempList.add(tempUsercode); if("00".equals(districtCode)) { // 为市
if(!useRegionCode.contains(tempCode)) { // 不包含该市权限 需要移除市搜索条件 添加 该市下区搜索条件
for(String tempUsercode : useRegionCode) {
if(tempUsercode.indexOf(tempCode.substring(0,4)) != -1) {
tempList.add(tempUsercode);
}
} }
regionIt.remove();
} }
regionIt.remove(); } else { // 为区 不会出现越权情况
}
} else { // 为区 不会出现越权情况
}
} }
} }
for (String t : tempList) { for (String t : tempList) {
......
package com.yeejoin.amos.boot.module.tzs.biz.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.feign.AmosFeignService;
import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.module.common.api.feign.EquipFeignClient;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorBaseInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorListDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorMaintenanceInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorNewDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorTestInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorWlInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EsElevatorDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentListDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.SpecialEquipmentDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator;
import com.yeejoin.amos.boot.module.tzs.api.entity.MaintainInfo;
import com.yeejoin.amos.boot.module.tzs.api.entity.TestInfo;
import com.yeejoin.amos.boot.module.tzs.api.service.IElevatorRelationService;
import com.yeejoin.amos.boot.module.tzs.api.service.IElevatorService;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.ESElevatorServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.ElevatorServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.MaintainInfoServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.TestInfoServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.utils.BeanDtoVoUtils;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 特种设备API
*/
@RestController
@Api(tags = "特种设备API")
@RequestMapping(value = "/special-equipment")
public class SpecialEquipmentController extends BaseController {
private final Logger logger = LoggerFactory.getLogger(SpecialEquipmentController.class);
@Autowired
IElevatorService iElevatorService;
@Autowired
ElevatorServiceImpl elevatorService;
@Autowired
private AmosFeignService amosFeignService;
@Autowired
private MaintainInfoServiceImpl maintainInfoService;
@Autowired
private EquipFeignClient equipFeignClient;
@Autowired
private TestInfoServiceImpl testInfoService;
@Autowired
ESElevatorServiceImpl esElevatorService;
@Autowired
private EmqKeeper emqKeeper;
@Value("${mqtt.topic.elevator.push}")
private String elevatorpushTopic;
@Autowired
private IElevatorRelationService elevatorRelationService;
/**
* ES查询电梯信息
*
* @return 查询结果
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/querySpecialEquipment", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "ES查询八大类信息", notes = "ES查询八大类信息")
public ResponseModel<Map<String, List<SpecialEquipmentDto>>> querySpecialEquipment(@RequestBody EsSpecialEquipmentDto esSpecialEquipmentDto){
Map<String, List<SpecialEquipmentDto>> result = new HashMap<>();
if(StringUtils.isNotBlank(esSpecialEquipmentDto.getCategoryCode())) { // 查找特定设备
if("3000".equals(esSpecialEquipmentDto.getCategoryCode())) {
List<SpecialEquipmentDto> elevatorList = esElevatorService.queryByDto(esSpecialEquipmentDto, true);
result.put("3000",elevatorList);
}
} else { // 查找所有设备
// 查找电梯数据
List<SpecialEquipmentDto> elevatorList = esElevatorService.queryByDto(esSpecialEquipmentDto, false);
result.put("3000",elevatorList);
}
return ResponseHelper.buildResponse(result);
}
/**
* ES查询电梯信息
*
* @return 查询结果
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/querySpecialEquipmentList", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "ES查询八大类列表信息", notes = "ES查询八大类列表信息")
public ResponseModel<List<SpecialEquipmentDto>> querySpecialEquipmentList(@RequestBody EsSpecialEquipmentListDto eSpecialEquipmentListDto){
List<SpecialEquipmentDto> result = new ArrayList<>();
if (ValidationUtil.isEmpty(eSpecialEquipmentListDto.getCategoryCode())) {
throw new BadRequest("参数校验失败.");
}
if("3000".equals(eSpecialEquipmentListDto.getCategoryCode())) {
result = esElevatorService.queryListByDto(eSpecialEquipmentListDto);
}
return ResponseHelper.buildResponse(result);
}
/**
* ES查询电梯信息
*
* @return 查询结果
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/queryTogetherByDto", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "ES查询聚合信息", notes = "ES查询聚合信息")
public ResponseModel<List<Map<String, String>>> queryTogetherByDto(@RequestBody EsSpecialEquipmentDto esSpecialEquipmentDto){
List<Map<String, String>> result = new ArrayList<>();
if (ValidationUtil.isEmpty(esSpecialEquipmentDto.getCategoryCode()) ||
ValidationUtil.isEmpty(esSpecialEquipmentDto.getPrecision()) ||
ValidationUtil.isEmpty(esSpecialEquipmentDto.getStartLatitude()) ||
ValidationUtil.isEmpty(esSpecialEquipmentDto.getStartLongitude()) ||
ValidationUtil.isEmpty(esSpecialEquipmentDto.getEndLatitude()) ||
ValidationUtil.isEmpty(esSpecialEquipmentDto.getEndLongitude())) {
throw new BadRequest("参数校验失败.");
}
if(StringUtils.isNotBlank(esSpecialEquipmentDto.getCategoryCode())) { // 查找特定设备
if("3000".equals(esSpecialEquipmentDto.getCategoryCode())) {
result = esElevatorService.queryTogetherByDto(esSpecialEquipmentDto);
}
}
return ResponseHelper.buildResponse(result);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment