Commit 1ced89e5 authored by tianbo's avatar tianbo

气瓶分页查询接口

parent 7e73200d
...@@ -54,4 +54,6 @@ public class SpecialEquipmentDto { ...@@ -54,4 +54,6 @@ public class SpecialEquipmentDto {
@ApiModelProperty(value = "内部编码") @ApiModelProperty(value = "内部编码")
private String innerNum; private String innerNum;
@ApiModelProperty(value = "设备唯一编码")
private String uniqueCode;
} }
package com.yeejoin.amos.boot.module.tzs.api.entity;
import lombok.Data;
import lombok.experimental.Accessors;
import org.elasticsearch.common.geo.GeoPoint;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
/**
* @author tb
* @date 2022-04-20.
*/
@Data
@Accessors(chain = true)
@Document(indexName = "cylinder", replicas = 0)
public class EsCylinder {
/**
* 主键
*/
@Id
private Long sequenceNbr;
/**
* 气瓶出厂编号
*/
@Field(type = FieldType.Text)
private String factoryNum;
// /**
// * 所属省
// */
// @Field(type = FieldType.Text)
// private String province;
//
// /**
// * 所属地市
// */
// @Field(type = FieldType.Text)
// private String city;
//
// /**
// * 所属区县
// */
// @Field(type = FieldType.Text)
// private String district;
//
// /**
// * 所属区域代码
// */
// @Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
// private String regionCode;
/**
* 产权单位名称
*/
@Field(type = FieldType.Text)
private String unitName;
/**
* 经度
*/
@Field(type = FieldType.Double)
private Double longitude;
/**
* 纬度
*/
@Field(type = FieldType.Double)
private Double latitude;
/**
* 经纬度字段
*/
@GeoPointField
private GeoPoint location;
/**
* 地址
*/
@Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
private String address;
}
package com.yeejoin.amos.boot.module.tzs.api.enums;
/**
* <pre>
* 特种设备类别枚举
* </pre>
*
* @author tb
*/
public enum SpecialEquipmentCategoryEnum {
ELEVATOR("3000", "电梯"),
PRESSURE_VESSEL("2000", "压力容器");
/**
* 编码
*/
private String code;
/**
* 名称
*/
private String name;
// 构造方法
SpecialEquipmentCategoryEnum(String code, String name) {
this.code = code;
this.name = name;
}
public static SpecialEquipmentCategoryEnum getEnum(String code) {
for (SpecialEquipmentCategoryEnum specialEquipmentCategoryEnum : SpecialEquipmentCategoryEnum.values()) {
if (specialEquipmentCategoryEnum.getCode().equals(code)) {
return specialEquipmentCategoryEnum;
}
}
return null;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
...@@ -169,4 +169,16 @@ public class CylinderInfo { ...@@ -169,4 +169,16 @@ public class CylinderInfo {
* 预警等级 计算日期 * 预警等级 计算日期
*/ */
private Date earlyWarningLevelCalDate; private Date earlyWarningLevelCalDate;
/**
* 经度
*/
@TableField("longitude")
private String longitude;
/**
* 纬度
*/
@TableField("longitude")
private String latitude;
} }
...@@ -26,9 +26,11 @@ import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator; ...@@ -26,9 +26,11 @@ import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator;
import com.yeejoin.amos.boot.module.tzs.api.entity.EquipmentRegionNum; import com.yeejoin.amos.boot.module.tzs.api.entity.EquipmentRegionNum;
import com.yeejoin.amos.boot.module.tzs.api.entity.MaintainInfo; 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.entity.TestInfo;
import com.yeejoin.amos.boot.module.tzs.api.enums.SpecialEquipmentCategoryEnum;
import com.yeejoin.amos.boot.module.tzs.api.service.IElevatorRelationService; 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.api.service.IElevatorService;
import com.yeejoin.amos.boot.module.tzs.api.service.TzsAuthService; import com.yeejoin.amos.boot.module.tzs.api.service.TzsAuthService;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.ESCylinderServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.ESElevatorServiceImpl; 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.ElevatorServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.EquipmentRegionNumServiceImpl; import com.yeejoin.amos.boot.module.tzs.biz.service.impl.EquipmentRegionNumServiceImpl;
...@@ -112,6 +114,9 @@ public class SpecialEquipmentController extends BaseController { ...@@ -112,6 +114,9 @@ public class SpecialEquipmentController extends BaseController {
@Autowired @Autowired
EquipmentRegionNumServiceImpl equipmentRegionNumServiceImpl; EquipmentRegionNumServiceImpl equipmentRegionNumServiceImpl;
@Autowired
ESCylinderServiceImpl esCylinderService;
/** /**
* ES查询特种设备信息 带分页 加经纬度过滤 keyword 搜索 * ES查询特种设备信息 带分页 加经纬度过滤 keyword 搜索
...@@ -128,9 +133,12 @@ public class SpecialEquipmentController extends BaseController { ...@@ -128,9 +133,12 @@ public class SpecialEquipmentController extends BaseController {
throw new BadRequest("参数校验失败."); throw new BadRequest("参数校验失败.");
} }
if(StringUtils.isNotBlank(esSpecialEquipmentDto.getCategoryCode())) { // 查找特定设备 if(StringUtils.isNotBlank(esSpecialEquipmentDto.getCategoryCode())) { // 查找特定设备
if("3000".equals(esSpecialEquipmentDto.getCategoryCode())) { if(SpecialEquipmentCategoryEnum.ELEVATOR.getCode().equals(esSpecialEquipmentDto.getCategoryCode())) {
result = esElevatorService.queryPageByDto(esSpecialEquipmentDto, current, size); result = esElevatorService.queryPageByDto(esSpecialEquipmentDto, current, size);
} }
if(SpecialEquipmentCategoryEnum.PRESSURE_VESSEL.getCode().equals(esSpecialEquipmentDto.getCategoryCode())) {
result = esCylinderService.queryPageByDto(esSpecialEquipmentDto, current, size);
}
} }
return ResponseHelper.buildResponse(result); return ResponseHelper.buildResponse(result);
} }
......
package com.yeejoin.amos.boot.module.tzs.biz.dao;
import com.yeejoin.amos.boot.module.tzs.api.entity.EsCylinder;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* @author fengwang
* @date 2021-09-26.
*/
@Repository
public interface ESCylinderRepository extends PagingAndSortingRepository<EsCylinder, Long> {
}
package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.tzs.api.dto.EsSpecialEquipmentDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.SpecialEquipmentDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.EsCylinder;
import com.yeejoin.amos.boot.module.tzs.api.enums.SpecialEquipmentCategoryEnum;
import com.yeejoin.amos.boot.module.tzs.biz.dao.ESCylinderRepository;
import com.yeejoin.amos.boot.module.tzs.flc.api.entity.CylinderInfo;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.LinkedList;
import java.util.List;
/**
* <pre>
* 压力容器信息ES检索服务
* </pre>
*
* @author tb
* @version 2022年4月20日
*/
@Service
public class ESCylinderServiceImpl {
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
private ESCylinderRepository esCylinderRepository;
/**
* <pre>
* 保存气瓶信息
* </pre>
*
* @param cylinderInfo 保存气瓶信息
*/
public EsCylinder saveEsCylinderToES(CylinderInfo cylinderInfo) {
EsCylinder esCylinder = new EsCylinder();
if (StringUtils.isNotEmpty(cylinderInfo.getLongitude())) {
esCylinder.setLongitude(Double.parseDouble(cylinderInfo.getLongitude()));
}
if (StringUtils.isNotEmpty(cylinderInfo.getLatitude())) {
esCylinder.setLatitude(Double.parseDouble(cylinderInfo.getLatitude()));
}
esCylinder.setSequenceNbr(cylinderInfo.getSequenceNbr());
// esCylinder.setAddress(cylinder.getAddress());
esCylinder.setFactoryNum(cylinderInfo.getFactoryNum());
esCylinder.setUnitName(cylinderInfo.getUnitName());
if (StringUtils.isNotBlank(cylinderInfo.getLatitude()) && StringUtils.isNotBlank(cylinderInfo.getLongitude())) {
Double lat = Double.parseDouble(cylinderInfo.getLatitude());
Double lon = Double.parseDouble(cylinderInfo.getLongitude());
esCylinder.setLocation(new GeoPoint(lat, lon));
}
esCylinderRepository.save(esCylinder);
return esCylinder;
}
public Page<SpecialEquipmentDto> queryPageByDto(EsSpecialEquipmentDto esSpecialEquipmentDto, int current, int size) {
Page<SpecialEquipmentDto> result = new Page<>(current, size);
Double startLongitude = esSpecialEquipmentDto.getStartLongitude();
Double startLatitude = esSpecialEquipmentDto.getStartLatitude();
Double endLongitude = esSpecialEquipmentDto.getEndLongitude();
Double endLatitude = esSpecialEquipmentDto.getEndLatitude();
String regionCode = esSpecialEquipmentDto.getRegionCode();
String keyword = esSpecialEquipmentDto.getKeyword();
/**
* 通用匹配规则,条件构建
*/
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
// 经度比start 大比end 小 纬度比start 小 比end 大
if (!ValidationUtil.isEmpty(startLongitude) && !ValidationUtil.isEmpty(startLatitude) && !ValidationUtil.isEmpty(endLongitude) && !ValidationUtil.isEmpty(endLatitude)) {
BoolQueryBuilder longLatMust = QueryBuilders.boolQuery();
BoolQueryBuilder qb1 = QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("longitude").gte(startLongitude).lte(endLongitude));
BoolQueryBuilder qb2 = QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("latitude").gte(endLatitude).lte(startLatitude));
longLatMust.must(qb1);
longLatMust.must(qb2);
boolMust.must(longLatMust);
}
if (!ValidationUtil.isEmpty(regionCode)) {
BoolQueryBuilder qb2 = QueryBuilders.boolQuery().
filter(QueryBuilders.matchPhraseQuery("regionCode", regionCode));
boolMust.must(qb2);
}
if (!ValidationUtil.isEmpty(keyword)) {
BoolQueryBuilder qb0 = QueryBuilders.boolQuery().
must(QueryBuilders.matchQuery("factoryNum", keyword));
boolMust.should(qb0);
BoolQueryBuilder qb1 = QueryBuilders.boolQuery().
must(QueryBuilders.matchQuery("address", keyword));
boolMust.should(qb1);
BoolQueryBuilder qb2 = QueryBuilders.boolQuery().
must(QueryBuilders.matchQuery("unitName", keyword));
boolMust.should(qb2);
boolMust.minimumShouldMatch(1);
}
// 创建查询构造器
NativeSearchQuery query = new NativeSearchQueryBuilder()
// 分页
.withPageable(PageRequest.of(current - 1, size))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.withQuery(boolMust).build();
query.setTrackTotalHits(true);
query.setMaxResults(size);
List<SpecialEquipmentDto> list = new LinkedList<>();
long total = 0;
try {
SearchHits<EsCylinder> searchHits = elasticsearchTemplate.search(query, EsCylinder.class);
for (SearchHit searchHit : searchHits.getSearchHits()) {
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
SpecialEquipmentDto esCylinderDto = JSONObject.toJavaObject(jsonObject, SpecialEquipmentDto.class);
esCylinderDto.setCategoryCode(SpecialEquipmentCategoryEnum.PRESSURE_VESSEL.getCode());
esCylinderDto.setUniqueCode(jsonObject.getString("factoryNum"));
list.add(esCylinderDto);
}
total = searchHits.getTotalHits();
} catch (Exception e) {
// TODO: handle exception
}
result.setRecords(list);
result.setTotal(total);
return result;
}
}
...@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.module.tzs.api.entity.MsgLog; import com.yeejoin.amos.boot.module.tzs.api.entity.MsgLog;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.ESCylinderServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.utils.BeanDtoVoUtils; import com.yeejoin.amos.boot.module.tzs.biz.utils.BeanDtoVoUtils;
import com.yeejoin.amos.boot.module.tzs.flc.api.dto.CylinderFillingRecordDto; import com.yeejoin.amos.boot.module.tzs.flc.api.dto.CylinderFillingRecordDto;
import com.yeejoin.amos.boot.module.tzs.flc.api.dto.CylinderInfoDto; import com.yeejoin.amos.boot.module.tzs.flc.api.dto.CylinderInfoDto;
...@@ -23,7 +24,16 @@ import io.swagger.annotations.ApiOperation; ...@@ -23,7 +24,16 @@ import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
...@@ -31,7 +41,12 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper; ...@@ -31,7 +41,12 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 气瓶基本信息 * 气瓶基本信息
...@@ -53,6 +68,9 @@ public class CylinderInfoController extends BaseController { ...@@ -53,6 +68,9 @@ public class CylinderInfoController extends BaseController {
@Autowired @Autowired
CylinderFillingRecordServiceImpl cylinderFillingRecordServiceImpl; CylinderFillingRecordServiceImpl cylinderFillingRecordServiceImpl;
@Autowired
ESCylinderServiceImpl esCylinderService;
private Map<Integer, String> regionMap; private Map<Integer, String> regionMap;
...@@ -881,4 +899,37 @@ public class CylinderInfoController extends BaseController { ...@@ -881,4 +899,37 @@ public class CylinderInfoController extends BaseController {
return ResponseHelper.buildResponse(cylinderInfoServiceImpl.nextInspectionDateUpdate(cylinderInfoDtos)); return ResponseHelper.buildResponse(cylinderInfoServiceImpl.nextInspectionDateUpdate(cylinderInfoDtos));
} }
/**
* 气瓶信息放入es
*
* @return
*/
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/init", method = RequestMethod.PUT)
@ApiOperation(httpMethod = "PUT", value = "气瓶信息放入es", notes = "气瓶信息放入es")
public void init(Integer num) {
IPage<CylinderInfo> cylinderInfoPage = new Page<>();
Integer count = cylinderInfoServiceImpl.count();
Integer times = 0;
if (ValidationUtil.isEmpty(num) && count != 0) {
times = count / 500;
int last = count % 500;
if (last > 0) {
times++;
}
} else if (count != 0) {
times = num;
}
for (int i = 0; i <= times; i++) {
cylinderInfoPage.setCurrent(i);
cylinderInfoPage.setSize(500);
cylinderInfoPage = cylinderInfoServiceImpl.page(cylinderInfoPage);
for (CylinderInfo el : cylinderInfoPage.getRecords()
) {
esCylinderService.saveEsCylinderToES(el);
}
}
}
} }
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