Commit 7e43ba41 authored by 李腾威's avatar 李腾威

公众号开发,地图接口开发

parent 9a36750d
package com.yeejoin.amos.boot.module.tzs.api.dto;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import java.util.List;
/**
* 警情接警填报记录
......@@ -147,10 +149,13 @@ public class AlertCalledDto extends BaseDto {
@ApiModelProperty(value = "投诉描述/故障报修描述")
private String describe;
@ApiModelProperty(value = "图片")
private String images;
//
// @ApiModelProperty(value = "图片")
// private String images;
@ApiModelProperty(value = "设备id")
private Long equipmentId;
@ApiModelProperty(value = "现场照片")
private List<AttachmentDto> images;
}
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author litw
* @date 2021-09-27.
*/
@Data
public class AlertHandlerDto {
@ApiModelProperty(value = "处置时间")
Map<String, Date> handlerTime;
@ApiModelProperty(value = "处置信息")
List<AlertHandlerInfoDto> alertHandlerInfoDto;
}
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author litw
* @date 2021-09-27.
*/
@Data
public class AlertHandlerInfoDto {
@ApiModelProperty(value = "处置流程")
String process;
@ApiModelProperty(value = "接警")
String answerThePolice;
@ApiModelProperty(value = "上报")
String report;
@ApiModelProperty(value = "派遣/通知")
String notice;
@ApiModelProperty(value = "到达")
String arrive;
@ApiModelProperty(value = "完成")
String complete;
@ApiModelProperty(value = "回访")
String returnVisit;
}
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author litw
* @date 2021-09-26.
*/
@Data
@ApiModel(value="EsElevatorDto", description="ES电梯信息")
public class EsElevatorDto {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* 注册编码
*/
@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 Integer rescueCode;
/**
* 电梯经度
*/
@ApiModelProperty(value = "电梯经度")
private String longitude;
/**
* 电梯纬度
*/
@ApiModelProperty(value = "电梯纬度")
private String latitude;
/**
* 地址
*/
@ApiModelProperty(value = "地址")
private String address;
/**
* 警情类型code
*/
@ApiModelProperty(value = "警情类型")
private String alarmTypeCode;
/**
* 警情id
*/
@ApiModelProperty(value = "警情id")
private String alertId;
}
......@@ -3,12 +3,14 @@ package com.yeejoin.amos.boot.module.tzs.api.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
import java.util.List;
/**
* 警情接警填报记录
......@@ -225,8 +227,9 @@ public class AlertCalled extends BaseEntity {
@ApiModelProperty(value = "设备id")
private Long equipmentId;
@TableField("images")
@ApiModelProperty(value = "图片")
private String images;
@TableField(exist=false)
@ApiModelProperty(value = "现场照片")
private List<AttachmentDto> images;
}
package com.yeejoin.amos.boot.module.tzs.api.entity;
import lombok.Data;
import lombok.experimental.Accessors;
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;
/**
* @author litw
* @date 2021-09-26.
*/
@Data
@Accessors(chain = true)
@Document(indexName = "elev", type = "tzsElevator", shards = 1, replicas = 0)
public class EsElevator {
/** 主键 */
@Id
private Long sequenceNbr;
/**
* 注册编码
*/
@Field(type = FieldType.Text)
private String registerCode;
/**
* 所属省
*/
@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)
private String regionCode;
/**
* 电梯识别码
*/
@Field(type = FieldType.Text)
private Integer rescueCode;
/**
* 电梯经度
*/
@Field(type = FieldType.Text)
private String longitude;
/**
* 电梯纬度
*/
@Field(type = FieldType.Text)
private String latitude;
/**
* 地址
*/
@Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
private String address;
}
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledFormDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledQueryDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertHandlerDto;
import com.yeejoin.amos.boot.module.tzs.api.enums.DispatchPaperEnums;
import org.typroject.tyboot.core.rdbms.annotation.Condition;
import org.typroject.tyboot.core.rdbms.annotation.Operator;
......@@ -58,4 +59,8 @@ public interface IAlertCalledService {
* @return
*/
Boolean updateAlertStage(AlertCalledDto alertCalledVo, DispatchPaperEnums stage);
AlertHandlerDto getHandlerInfo(String alertId);
}
......@@ -22,6 +22,7 @@ import com.yeejoin.amos.boot.module.tzs.api.dto.ESAlertCalledRequestDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator;
import com.yeejoin.amos.boot.module.tzs.api.entity.WechatRelation;
import com.yeejoin.amos.boot.module.tzs.api.enums.AlertStageEnums;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.AlertCalledServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.AlertFormValueServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.DispatchPaperServiceImpl;
......@@ -117,15 +118,19 @@ public class AlertCalledController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/saveMobile")
@ApiOperation(httpMethod = "POST", value = "新增警情接警填报记录", notes = "新增警情接警填报记录")
public ResponseModel<AlertCalledDto> saveMobile(@RequestBody AlertCalledDto alertCalledDto,
@RequestParam String phone) {
public ResponseModel<AlertCalledDto> saveMobile(@RequestBody AlertCalledDto alertCalledDto
) {
if (ValidationUtil.isEmpty(alertCalledDto)) {
throw new BadRequest("参数校验失败.");
}
if (ValidationUtil.isEmpty(alertCalledDto.getEmergencyCall())) {
throw new BadRequest("参数校验失败.");
}
// 校验手机号 是否存在
LambdaQueryWrapper<WechatRelation> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(WechatRelation::getPhone, phone);
queryWrapper.eq(WechatRelation::getPhone, alertCalledDto.getEmergencyCall());
WechatRelation wechatRelation = wechatRelationService.getOne(queryWrapper);
if (null == wechatRelation) {
throw new BadRequest("手机号未注册");
......@@ -144,6 +149,7 @@ public class AlertCalledController extends BaseController {
alertCalledDto.setDeviceId(String.valueOf(elevator.getRescueCode()));
alertCalledDto.setUseStatus(elevator.getUseStatus());
alertCalledDto.setUseSiteCategory(elevator.getUseSiteCategory());
alertCalledDto.setAlarmType(AlertStageEnums.getEnumById(alertCalledDto.getAlarmTypeCode()).getValue());
AlertCalledDto alertCalledDtoReturn = iAlertCalledService.createAlertCalled(alertCalledDto);
return ResponseHelper.buildResponse(alertCalledDtoReturn);
......@@ -478,4 +484,15 @@ public class AlertCalledController extends BaseController {
return ResponseHelper.buildResponse(iAlertCalledService.getImportantEventOrTodayEmergencyCount(type));
}
/**
* 警情处置流程信息
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getHandlerInfo")
@ApiOperation(httpMethod = "GET", value = "警情处置流程信息", notes = "警情处置流程信息")
public ResponseModel<Object> getHandlerInfo(@RequestParam String alertId) {
return ResponseHelper.buildResponse(iAlertCalledService.getHandlerInfo(alertId));
}
}
......@@ -12,10 +12,12 @@ import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorInfoDto;
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.EsElevatorDto;
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.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;
......@@ -72,6 +74,9 @@ public class ElevatorController extends BaseController {
@Autowired
private TestInfoServiceImpl testInfoService;
@Autowired
ESElevatorServiceImpl esElevatorService;
/**
* 新增电梯
*
......@@ -339,5 +344,45 @@ public class ElevatorController extends BaseController {
return ResponseHelper.buildResponse(elevatorInfoDto);
}
/**
*
* @return
*/
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/init", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "电梯信息放入es", notes = "电梯信息放入es")
public void init() {
IPage<Elevator> elevatorPage = new Page<>();
Integer count = elevatorService.count();
for(int i = 0; i <= count % 500 ; i ++ ) {
elevatorPage.setCurrent(i);
elevatorPage.setSize(500);
elevatorPage = elevatorService.page(elevatorPage);
for (Elevator el:elevatorPage.getRecords()
) {
esElevatorService.saveEsElevatorToES(el);
}
}
}
/**
* ES分页查询电梯信息
*
* @param current 当前页
* @param size 每页大小
* @param elevatorDto 查询参数
* @return 查询结果
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/query_elevator_list_es", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "ES分页查询电梯信息", notes = "ES分页查询电梯信息")
public ResponseModel<IPage<EsElevatorDto>> queryElevatorListEs(@RequestParam(value = "current") int current, @RequestParam(value = "size") int size,
@RequestBody EsElevatorDto elevatorDto){
Page<EsElevatorDto> page = esElevatorService.queryByKeys(elevatorDto,current,size);
return ResponseHelper.buildResponse(page);
}
}
......@@ -738,15 +738,19 @@ public class WechatController extends BaseController {
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/uploadImage")
@ApiOperation(httpMethod = "POST", value = "微信公众号上传图片", notes = "微信公众号上传图片")
public ResponseModel<String> uploadImage(@ApiParam(value = "图片", required = true)@RequestParam MultipartFile file
) {
public ResponseModel<String> uploadImage(@ApiParam(value = "图片", required = true)@RequestParam MultipartFile file,
String appKey, String product, String token ) {
if (ValidationUtil.isEmpty(file)){
throw new BadRequest("参数校验失败.");
}
// RequestContext.setProduct(product);
// RequestContext.setAppKey(appKey);
// RequestContext.setToken(token);
FeignClientResult<Map<String, String>> date = Systemctl.fileStorageClient.updateCommonFile(file);
String urlString="";
if (date != null) {
......
package com.yeejoin.amos.boot.module.tzs.biz.dao;
import com.yeejoin.amos.boot.module.tzs.api.entity.EsElevator;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
/**
* @author fengwang
* @date 2021-09-26.
*/
@Repository
public interface ESElavtorRepository extends PagingAndSortingRepository<EsElevator, Long> {
}
......@@ -7,17 +7,22 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.itextpdf.text.pdf.PdfStructTreeController.returnType;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import com.yeejoin.amos.boot.module.common.api.service.ISourceFileService;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledFormDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledObjsDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledQueryDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertHandlerDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertHandlerInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.FormValue;
import com.yeejoin.amos.boot.module.tzs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.tzs.api.entity.AlertFormValue;
import com.yeejoin.amos.boot.module.tzs.api.entity.DispatchPaper;
import com.yeejoin.amos.boot.module.tzs.api.entity.DispatchTask;
import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator;
import com.yeejoin.amos.boot.module.tzs.api.enums.AlertStageEnums;
import com.yeejoin.amos.boot.module.tzs.api.enums.DispatchPaperEnums;
......@@ -35,12 +40,15 @@ import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.rdbms.annotation.Condition;
import org.typroject.tyboot.core.rdbms.annotation.Operator;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 警情接警填报记录服务实现类
......@@ -78,6 +86,15 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
@Autowired
RepairConsultServiceImpl repairConsultServiceImpl;
@Autowired
DispatchPaperServiceImpl dispatchPaperService;
@Autowired
DispatchTaskServiceImpl dispatchTaskService;
@Autowired
ISourceFileService ISourceFileService;
private final Logger logger = LogManager.getLogger(AlertCalledServiceImpl.class);
......@@ -218,6 +235,84 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
return this.update(updateWrapper);
}
/**
* 警情处置流程信息
*/
@Override
public AlertHandlerDto getHandlerInfo(String alertId) {
AlertHandlerDto alertHandlerDto = new AlertHandlerDto();
Map<String,Date> map = new HashMap<>();
List<AlertHandlerInfoDto> list = new ArrayList<>();
AlertHandlerInfoDto alertHandlerInfoDtoHead = new AlertHandlerInfoDto();
alertHandlerInfoDtoHead.setProcess("处置流程");
alertHandlerInfoDtoHead.setAnswerThePolice("接警");
alertHandlerInfoDtoHead.setReport("上报");
alertHandlerInfoDtoHead.setNotice("派遣/通知");
alertHandlerInfoDtoHead.setArrive("到达");
alertHandlerInfoDtoHead.setComplete("完成");
alertHandlerInfoDtoHead.setReturnVisit("回访");
list.add(alertHandlerInfoDtoHead);
AlertCalled called = this.getById(Long.valueOf(alertId));
if(null == called) {
throw new BadRequest("警情不存在");
}
map.put("接警",called.getCallTime());
map.put("上报",called.getRecDate());
LambdaQueryWrapper<DispatchPaper> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(DispatchPaper::getAlertId,Long.valueOf(alertId));
DispatchPaper dispatchPaper = dispatchPaperService.getOne(queryWrapper);
LambdaQueryWrapper<DispatchTask> queryWrapper1 = new LambdaQueryWrapper();
queryWrapper1.eq(DispatchTask::getPaperId,Long.valueOf(dispatchPaper.getSequenceNbr()));
List<DispatchTask> dispatchTask = dispatchTaskService.list(queryWrapper1);
String [] str = new String[]{"使用单位","一级响应","二级响应","三级响应","市级监督"};
if(null != dispatchPaper) {
for(String s:str) {
AlertHandlerInfoDto alertHandlerInfoDto = new AlertHandlerInfoDto();
if(null != dispatchTask &&dispatchTask.size() > 0 ) {
List<DispatchTask> taskList = dispatchTask.stream().filter(e->e.getOrgType().equals(s)).collect(Collectors.toList());
if(taskList.size() > 0) {
map.put("派遣/通知",called.getRecDate());
map.put("到达",dispatchTask.get(0).getArriveTime());
map.put("完成",dispatchTask.get(0).getSaveTime());
dataInit(alertHandlerInfoDto,s,"", "","已派遣",
dispatchTask.get(0).getArriveTime() == null ? "" : "已到达" ,dispatchTask.get(0).getSaveTime() == null ? "" : "已完成",
dispatchPaper.getFeedbackTime() != null || dispatchPaper.getFeedbackFinishTime() != null ? "已回访" : "");
} else {
dataInit(alertHandlerInfoDto,s,"","","","","","");
}
}
list.add(alertHandlerInfoDto);
}
map.put("回访",dispatchPaper.getFeedbackTime());
} else {
for(String s:str) {
AlertHandlerInfoDto alertHandlerInfoDto = new AlertHandlerInfoDto();
dataInit(alertHandlerInfoDto,s,"","","","","","");
list.add(alertHandlerInfoDto);
}
}
alertHandlerDto.setAlertHandlerInfoDto(list);
alertHandlerDto.setHandlerTime(map);
return alertHandlerDto;
}
private void dataInit(AlertHandlerInfoDto alertHandlerInfoDto, String process,String answerThePolice, String report, String notice, String arrive, String complete,String returnVisit) {
alertHandlerInfoDto.setProcess(process);
alertHandlerInfoDto.setAnswerThePolice(answerThePolice);
alertHandlerInfoDto.setReport(report);
alertHandlerInfoDto.setNotice(notice);
alertHandlerInfoDto.setArrive(arrive);
alertHandlerInfoDto.setComplete(complete);
alertHandlerInfoDto.setReturnVisit(returnVisit);
}
/**
*
......@@ -330,6 +425,11 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
alertCalled.setTypeCode(AlertStageEnums.JQCB.getId());
this.save(alertCalled);
// 保存照片
Map<String, List<AttachmentDto>> attachmentMap = new HashMap<>();
attachmentMap.put("imgs",alertCalledDto.getImages());
ISourceFileService.saveAttachments(alertCalled.getSequenceNbr(),attachmentMap);
// 动态表单
AlertFormValue alertFormValue = new AlertFormValue();
// 填充警情主键
......
package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.EsElevatorDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator;
import com.yeejoin.amos.boot.module.tzs.api.entity.EsElevator;
import com.yeejoin.amos.boot.module.tzs.biz.dao.ESElavtorRepository;
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.NativeSearchQueryBuilder;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
/**
*
* <pre>
* 电梯信息ES检索服务
* </pre>
*
* @authorlitw
* @version 2021年9月26日
*/
@Service
public class ESElevatorServiceImpl {
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
private ESElavtorRepository esElavtorRepository;
@Autowired
AlertCalledServiceImpl iAlertCalledService;
@Value("${alertcall.es.synchrony.time}")
private Long time;
/**
*
* <pre>
* 电梯信息
* </pre>
*
* @param elevator 电梯信息
*/
public EsElevator saveEsElevatorToES(Elevator elevator)
{
EsElevator esElevator = new EsElevator();
esElevator.setSequenceNbr(elevator.getSequenceNbr());
esElevator.setProvince(elevator.getProvince());
esElevator.setAddress(elevator.getAddress());
esElevator.setCity(elevator.getCity());
esElevator.setDistrict(elevator.getDistrict());
esElevator.setLatitude(elevator.getLatitude());
esElevator.setRegisterCode(elevator.getRegisterCode());
esElevator.setRegionCode(elevator.getRegionCode());
esElavtorRepository.save(esElevator);
return esElevator;
}
/**
* 根据关键字查询文档,关键字不为空时按相关性从大到小排序
*
* @param elevatorDto 关键字
* @param current 当前页码
* @param size 页面大小
* @return
*/
@SuppressWarnings({ "rawtypes" })
public Page<EsElevatorDto> queryByKeys(EsElevatorDto elevatorDto, int current, int size) {
Page<EsElevatorDto> result = new Page<>(current, size);
String alarmTypeCode = elevatorDto.getAlarmTypeCode();
String address = elevatorDto.getAddress();
String regionCode = elevatorDto.getRegionCode();
/**
* 通用匹配规则,条件构建
*/
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
if(!ValidationUtil.isEmpty(alarmTypeCode)) {
BoolQueryBuilder qb0 = QueryBuilders.boolQuery();
LambdaQueryWrapper<AlertCalled> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(AlertCalled::getAlarmTypeCode,alarmTypeCode);
queryWrapper.ge(AlertCalled::getCallTime, DateUtils.stampToDate(System.currentTimeMillis(),DateUtils.DATE_PATTERN));
queryWrapper.le(AlertCalled::getCallTime, DateUtils.stampToDate(DateUtils.dateAddDays(new Date(),1).getTime(),DateUtils.DATE_PATTERN));
List<AlertCalled> alertCalleds = iAlertCalledService.list(queryWrapper);
List<Long> stringList = new ArrayList<>();
for (AlertCalled al: alertCalleds
) {
stringList.add(al.getEquipmentId());
}
qb0.must(QueryBuilders.termsQuery("sequenceNbr", stringList.toArray()));
boolMust.must(qb0);
}
if(!ValidationUtil.isEmpty(address)) {
BoolQueryBuilder boolMustAddress = QueryBuilders.boolQuery();
BoolQueryBuilder qb1 = QueryBuilders.boolQuery()
.should(QueryBuilders.matchPhraseQuery("address", address));
boolMustAddress.should(qb1);
boolMust.must(boolMustAddress);
}
if(!ValidationUtil.isEmpty(regionCode)) {
BoolQueryBuilder qb2= QueryBuilders.boolQuery().
filter(QueryBuilders. termQuery("regionCode", regionCode));
boolMust.must(qb2);
}
// 创建查询构造器
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
// 分页
.withPageable(PageRequest.of(current, size))
// 排序
// .withSort(SortBuilders.fieldSort("callTimeLong").order(SortOrder.DESC))
//过滤条件
.withQuery(boolMust);
List<EsElevatorDto> list = new LinkedList<>();
long totle = 0;
try
{
SearchHits<EsElevator> searchHits =elasticsearchTemplate.search(queryBuilder.build(), EsElevator.class);
for (SearchHit searchHit : searchHits.getSearchHits())
{
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
EsElevatorDto esElevatorDto =JSONObject.toJavaObject(jsonObject, EsElevatorDto.class);
list.add(esElevatorDto);
}
totle =searchHits.getTotalHits();
}
catch (Exception e)
{
// TODO: handle exception
}
result.setRecords(list);
result.setTotal(totle);
return 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