Commit f4278632 authored by tangwei's avatar tangwei

Merge branch 'developer' of http://172.16.10.76/moa/amos-boot-biz into developer

parents 8c53150e d5d2b723
package com.yeejoin.amos.boot.module.jcs.api.dto;
import java.util.Date;
import org.springframework.data.annotation.Id;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
*
* <pre>
* 警情信息ES dto对象
* </pre>
*
* @author gwb
* @version $Id: ESAlertCalledDto.java, v 0.1 2021年6月23日 下午1:52:07 gwb Exp $
*/
@Data
public class ESAlertCalledDto {
/** 主键 */
@Id
private Long sequenceNbr;
/**
* 警情状态
*/
@ApiModelProperty(value = "警情状态")
private Boolean alertStatus;
/**
* 响应级别字典code 为了过滤用(只有航空器故障有)
*/
@ApiModelProperty(value = "响应级别")
private String responseLevelCode;
/**
* 警情阶段
*/
@ApiModelProperty(value = "警情阶段")
private String alertStage;
/**
* 联系人姓名
*/
@ApiModelProperty(value = "联系人姓名")
private String contactUser;
/**
* 联系人电话
*/
@ApiModelProperty(value = "联系人电话")
private String contactPhone;
/**
* 接警时间
*/
@ApiModelProperty(value = "接警时间")
private Date callTime;
/**
* 接警时间
*/
@ApiModelProperty(value = "接警时间戳")
private Long callTimeLong;
/**
* 警情类型
*/
@ApiModelProperty(value = "警情类型")
private String alertType;
/**
* 事发单位
*/
@ApiModelProperty(value = "事发单位")
private String unitInvolved;
/**
* 地址
*/
@ApiModelProperty(value = "地址")
private String address;
/**
* 坐标x
*/
@ApiModelProperty(value = "坐标x")
private String coordinateX;
/**
* 坐标y
*/
@ApiModelProperty(value = "坐标y")
private String coordinateY;
}
package com.yeejoin.amos.boot.module.jcs.api.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.util.Date;
import lombok.Data;
import lombok.experimental.Accessors;
/**
*
......@@ -31,141 +31,60 @@ public class ESAlertCalled {
/**
* 警情状态
*/
@ApiModelProperty(value = " 警情状态")
@Field(type = FieldType.Text, searchAnalyzer = "ik_smart", analyzer = "ik_smart")
@Field(type = FieldType.Text)
private Boolean alertStatus;
// /**
// * 系统/人工
// */
// @Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
// private String type;
// @Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
// private String alertStage;
// /**
// * 报警类型
// */
// @Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
// private String alarmType;
/**
* 响应级别字典code 为了过滤用(只有航空器故障有)
*/
@ApiModelProperty(value = "响应级别")
@Field(type = FieldType.Text)
@Field(type = FieldType.Text, index = false)
private String responseLevelCode;
/**
* 警情阶段
*/
@ApiModelProperty(value = "警情阶段")
@Field(type = FieldType.Text)
@Field(type = FieldType.Text, index = false)
private String alertStage;
// /**
// * 报警类型code
// */
// @Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
// private String alarmTypeCode;
// /**
// * 通话记录信息id
// */
// @Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
// private Integer callRecordId;
// /**
// * 父警情id
// */
// private Long fatherAlert;
/**
* 联系人姓名
*/
@ApiModelProperty(value = "联系人姓名")
@Field(type = FieldType.Text)
private String contactUser;
/**
* 联系人电话
*/
@ApiModelProperty(value = "联系人电话")
@Field(type = FieldType.Text)
private String contactPhone;
/**
* 接警时间
*/
@ApiModelProperty(value = "接警时间")
@Field(type = FieldType.Date, format = DateFormat.basic_date_time)
@Field(type = FieldType.Date, format = DateFormat.basic_date_time, index = false)
private Date callTime;
// /**
// * 接警时长
// */
// private Double callTimeNum;
// /**
// * 警情来源
// */
// private String alertSource;
// /**
// * 警情来源code
// */
// private String alertSourceCode;
/**
* 接警时间
*/
@Field(type = FieldType.Long)
private Long callTimeLong;
/**
* 警情类型
*/
@ApiModelProperty(value = "警情类型")
@Field(type = FieldType.Text, searchAnalyzer = "ik_smart", analyzer = "ik_smart")
@Field(type = FieldType.Text)
private String alertType;
// /**
// * 警情类型code
// */
// private String alertTypeCode;
/**
* 事发单位
*/
@ApiModelProperty(value = "事发单位")
@Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
private String unitInvolved;
// /**
// * 被困人数
// */
// private Integer trappedNum;
// /**
// * 伤亡人数
// */
// private Integer casualtiesNum;
/**
* 地址
*/
@ApiModelProperty(value = "地址")
@Field(type = FieldType.Text, searchAnalyzer = "ik_max_word", analyzer = "ik_max_word")
private String address;
// /**
// * 救援方格
// */
// private String rescueGrid;
/**
* 坐标x
*/
@ApiModelProperty(value = "坐标x")
private String coordinateX;
/**
* 坐标y
*/
@ApiModelProperty(value = "坐标y")
private String coordinateY;
// /**
// * 更新时间
// */
// private Date updateTime;
// /**
// * 发送人名称
// */
// private String recUserName;
// /**
// * 接警时间开始---用于列表过滤
// */
// private Date callTimeStart ;
// /**
// * 接警时间结束---用于列表过滤
// */
// private Date callTimeEnd ;
// /**
// * 是否处警
// */
// private Boolean isFatherAlert;
}
package com.yeejoin.amos.boot.module.jcs.biz.controller;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
......@@ -8,35 +34,18 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jcs.api.dto.ESAlertCalledDto;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertFormValue;
import com.yeejoin.amos.boot.module.jcs.api.entity.ESAlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.service.IAlertCalledService;
import com.yeejoin.amos.boot.module.jcs.api.service.IAlertFormValueService;
import com.yeejoin.amos.boot.module.jcs.api.vo.AlertCalledFormVo;
import com.yeejoin.amos.boot.module.jcs.api.vo.AlertCalledVo;
import com.yeejoin.amos.boot.module.jcs.api.vo.FormValue;
import com.yeejoin.amos.boot.module.jcs.biz.service.impl.ESAlertCalledService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 警情接警记录
......@@ -196,8 +205,8 @@ public class AlertCalledController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "相似警情分页查询")
@RequestMapping(value = "/page/similar", method = RequestMethod.POST)
public ResponseModel<Page<ESAlertCalled>> pageBySimilar(
@RequestBody ESAlertCalled alertCalled,
public ResponseModel<Page<ESAlertCalledDto>> pageBySimilar(
@RequestBody ESAlertCalledDto alertCalled,
@RequestParam(value = "current") int current,
@RequestParam(value = "size") int size) throws Exception {
return ResponseHelper.buildResponse(eSAlertCalledService.queryByKeys(alertCalled, current, size));
......
package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.entity.ESAlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.service.IAlertCalledService;
import com.yeejoin.amos.boot.module.jcs.biz.dao.ESAlertCalledRepository;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -18,10 +18,14 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jcs.api.dto.ESAlertCalledDto;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.entity.ESAlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.service.IAlertCalledService;
import com.yeejoin.amos.boot.module.jcs.biz.dao.ESAlertCalledRepository;
/**
*
......@@ -96,24 +100,38 @@ public class ESAlertCalledService {
* @return
*/
@SuppressWarnings({ "rawtypes" })
public Page<ESAlertCalled> queryByKeys(ESAlertCalled alertCalled, int current, int size)
public Page<ESAlertCalledDto> queryByKeys(ESAlertCalledDto alertCalled, int current, int size)
{
// 条件构造,多条件循环匹配
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
/**
* 通用匹配规则,条件构建
*/
//接警时间,距离当前时间不超过半小时的
long currentTime = System.currentTimeMillis() ;
currentTime = currentTime - 30*60*1000;
Date date=new Date(currentTime);
BoolQueryBuilder qb1 = QueryBuilders.boolQuery()
.must(QueryBuilders.rangeQuery("callTimeLong").gte(currentTime));
//报警人及报警电话一致
BoolQueryBuilder qb2 = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("contactUser.keyword", alertCalled.getContactUser()))
.must(QueryBuilders.termQuery("contactPhone.keyword", alertCalled.getContactPhone()));
//事发地点一致,或相距不超过200米的
BoolQueryBuilder qb3 = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("address", alertCalled.getAddress()));
//警情类型一致
BoolQueryBuilder qb4 = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("alertType.keyword", alertCalled.getAlertType()));
//事发单位名称一致
BoolQueryBuilder qb5 = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("unitInvolved", alertCalled.getUnitInvolved()));
BoolQueryBuilder boolMust = QueryBuilders.boolQuery();
boolMust.should(qb1).should(qb2).should(qb3).should(qb4).should(qb5);
/**
* 一般火灾,条件构造
*/
boolMust.must(
QueryBuilders.boolQuery().minimumShouldMatch(1)
.should(QueryBuilders.termQuery("contactUser", alertCalled.getContactUser()))//联系人姓名
.should(QueryBuilders.termQuery("contactPhone", alertCalled.getContactPhone()))//联系人电话
.should(QueryBuilders.rangeQuery("callTime").gte(date))//接警时间,距离当前时间不超过半小时的
.should(QueryBuilders.termQuery("alertType", alertCalled.getAlertType()))//警情类型
.should(QueryBuilders.matchQuery("address", alertCalled.getAddress()))//事发地址
.should(QueryBuilders.matchQuery("unitInvolved", alertCalled.getUnitInvolved())) //事发单位
);
// 创建查询构造器
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
// 分页
......@@ -123,61 +141,20 @@ public class ESAlertCalledService {
//过滤条件
.withQuery(boolMust);
// List<ESAlertCalled> articleEntities = elasticsearchTemplate.queryForObject(queryBuilder, ESAlertCalled.class);
// 对高亮词条进行操作
SearchHits<ESAlertCalled> searchHits =elasticsearchTemplate.search(queryBuilder.build(), ESAlertCalled.class);
Page<ESAlertCalled> result = new Page<ESAlertCalled>(current, size);
List<ESAlertCalled> list = new ArrayList<>();
Page<ESAlertCalledDto> result = new Page<ESAlertCalledDto>(current, size);
List<ESAlertCalledDto> list = new LinkedList<>();
for (SearchHit searchHit : searchHits.getSearchHits())
{
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
ESAlertCalled eSAlertCalled =JSONObject.toJavaObject(jsonObject, ESAlertCalled.class);
ESAlertCalledDto eSAlertCalled =JSONObject.toJavaObject(jsonObject, ESAlertCalledDto.class);
list.add(eSAlertCalled);
}
result.setRecords(list);
result.setTotal(searchHits.getTotalHits());
// Page<ESAlertCalled> result = new PageImpl(searchHits.getSearchHits(),
// PageRequest.of(current, size), searchHits.getTotalHits());
// SearchHits<ESAlertCalled> result = elasticsearchTemplate.search(queryBuilder, ESAlertCalled.class, new SearchHitMapping() {
//// public <T> SearchHits<T> mapResults(SearchResponse response, Class<T> aClass, Pageable pageable) {
//// List<ESAlertCalled> list = new ArrayList<>();
////// for (SearchHit searchHit : response.getHits()) {
////// ESAlertCalled docEntity = JSON.parseObject(searchHit.getSourceAsString(), ESAlertCalled.class);
////// // 文档标题
////// HighlightField docTitle = searchHit.getHighlightFields().get("docTitle");
////// if (docTitle != null) {
////// docEntity.setDocTitle(docTitle.fragments()[0].toString());
////// }
////// // 文档内容
////// HighlightField textContent = searchHit.getHighlightFields().get("textContent");
////// if (textContent != null) {
////// docEntity.setSummary(textContent.fragments()[0].toString());
////// }
////// Set<String> tagInfoSet = new HashSet<>();
////// // 文档标签
////// HighlightField docTagsInfo = searchHit.getHighlightFields().get("docTags.tagInfo");
////// if (docTagsInfo != null) {
////// for (Text name : docTagsInfo.getFragments()) {
////// tagInfoSet.add(name.toString());
////// }
////// }
////// HighlightField contentTagsInfo = searchHit.getHighlightFields().get("contentTags.tagInfo");
////// if (contentTagsInfo != null) {
////// for (Text name : contentTagsInfo.getFragments()) {
////// tagInfoSet.add(name.toString());
////// }
////// }
////// // 删除不匹配的和重复的标签
////// deleteRepeatedTags(docEntity.getDocTags(), tagInfoSet);
////// deleteRepeatedTags(docEntity.getContentTags(), tagInfoSet);
//////
////// list.add(docEntity);
////// }
//// return new SearchHitsImpl<T>((List<T>) list, PageRequest.of(current, size), response.getHits().getTotalHits());
//// }
// });
return result;
}
......@@ -240,8 +217,13 @@ public class ESAlertCalledService {
esAlertCalled.setSequenceNbr(alertCalled.getSequenceNbr());
esAlertCalled.setAlertType(alertCalled.getAlarmType());
esAlertCalled.setCallTime(alertCalled.getCallTime());
esAlertCalled.setCallTimeLong(alertCalled.getCallTime().getTime());
esAlertCalled.setContactUser(alertCalled.getContactUser());
esAlertCalled.setContactPhone(alertCalled.getContactPhone());
esAlertCalled.setAddress(alertCalled.getAddress());
esAlertCalled.setAlertStage(alertCalled.getAlertStage());
esAlertCalled.setAlertStatus(alertCalled.getAlertStatus());
esAlertCalled.setResponseLevelCode(alertCalled.getResponseLevelCode());
esAlertCalled.setUnitInvolved(alertCalled.getUnitInvolved());
esAlertCalled.setCoordinateX(alertCalled.getCoordinateX());
esAlertCalled.setCoordinateY(alertCalled.getCoordinateY());
......
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