将一期项目中相关代码合并到二期项目中去
This commit is contained in:
@@ -22,6 +22,13 @@
|
||||
<groupId>com.ltgk.smartFishingPort</groupId>
|
||||
<artifactId>smartFishingPort-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- solr 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-solr</artifactId>
|
||||
<version>2.2.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.ltgk.smartFishingPort.common;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.solr.core.SolrTemplate;
|
||||
import org.springframework.data.solr.core.query.Query;
|
||||
import org.springframework.data.solr.core.query.SimpleQuery;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import static javafx.scene.input.KeyCode.T;
|
||||
|
||||
/**
|
||||
* @Author: wan kun
|
||||
* @Description: solr 操作类
|
||||
* @Date: 2024/9/23 9:22
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SolrCommon {
|
||||
@Autowired
|
||||
private SolrTemplate solrTemplate;
|
||||
|
||||
private static SolrCommon solrCommon;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
solrCommon = this;
|
||||
solrCommon.solrTemplate = this.solrTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础查询
|
||||
*
|
||||
* @param solrController 文档名
|
||||
* @param solrQuery 查询条件
|
||||
* @param object 返回内容实体类
|
||||
* @return
|
||||
*/
|
||||
public static Page solrSearchAll(String solrController, String solrQuery, Class object) {
|
||||
Query queryObject = new SimpleQuery(solrQuery);
|
||||
Page query = solrCommon.solrTemplate.query(solrController, queryObject, object);
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础查询
|
||||
*
|
||||
* @param solrController
|
||||
* @param solrQuery
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static Page solrSearchByQuery(String solrController, Query solrQuery, Class object) {
|
||||
Page query = solrCommon.solrTemplate.query(solrController, solrQuery, object);
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
*
|
||||
* @param solrController 文档名
|
||||
* @param T 创建内容
|
||||
* @return
|
||||
*/
|
||||
public static Boolean solrCreate(String solrController, Object T) {
|
||||
try {
|
||||
solrCommon.solrTemplate.saveBean(solrController, T);
|
||||
solrCommon.solrTemplate.commit(solrController);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error("SolrCommon:solrCreate -- solr插入数据失败,请求参数{},失败原因{}", JSONObject.toJSONString(T), ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param solrController 文档名
|
||||
* @param solrQuery 请求参数
|
||||
* @return
|
||||
*/
|
||||
public static Boolean solrDelete(String solrController, String solrQuery) {
|
||||
Query queryObject = new SimpleQuery(solrQuery);
|
||||
try {
|
||||
solrCommon.solrTemplate.delete(solrController, queryObject);
|
||||
solrCommon.solrTemplate.commit(solrController);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error("SolrCommon:solrDelete -- solr删除数据失败,请求参数{},失败原因{}", solrQuery, ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean solrCreateByList(String solrController, List<?> object) {
|
||||
try {
|
||||
solrCommon.solrTemplate.saveBeans(solrController, object);
|
||||
solrCommon.solrTemplate.commit(solrController);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error("SolrCommon:solrCreateByList -- solr插入数据失败,请求参数{},失败原因{}", JSONObject.toJSONString(T), ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean solrCreateByList(String solrController, ConcurrentLinkedQueue<?> object) {
|
||||
try {
|
||||
solrCommon.solrTemplate.saveBeans(solrController, object);
|
||||
solrCommon.solrTemplate.commit(solrController);
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
log.error("SolrCommon:solrCreateByList -- solr插入数据失败,请求参数{},失败原因{}", JSONObject.toJSONString(T), ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSolrQuerySql(HashMap<String, Object> map) {
|
||||
if (ObjectUtils.isEmpty(map))
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ltgk.smartFishingPort.config;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.solr.core.SolrTemplate;
|
||||
|
||||
/**
|
||||
* @Author: wan kun
|
||||
* @Description: solr配置类
|
||||
* @Date: 2024/9/20 17:40
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class SolrConfig {
|
||||
|
||||
@Bean
|
||||
public SolrTemplate solrTemplate(SolrClient solrClient) {
|
||||
return new SolrTemplate(solrClient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ltgk.smartFishingPort.constant;
|
||||
|
||||
|
||||
/**
|
||||
* 常量集合
|
||||
*
|
||||
* @author Qi ChengBin
|
||||
* @date 2025/12/22
|
||||
*/
|
||||
public class DataKeyConstant {
|
||||
|
||||
// solr 集合
|
||||
public static final String SOLR_AIS_POINT = "ais_point";
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.ltgk.smartFishingPort.controller;
|
||||
|
||||
|
||||
import com.ltgk.smartFishingPort.common.core.controller.BaseController;
|
||||
import com.ltgk.smartFishingPort.common.core.domain.AjaxResult;
|
||||
import com.ltgk.smartFishingPort.service.ISolrService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Ais solr 查询数据
|
||||
*
|
||||
* @author Qi ChengBin
|
||||
* @date 2025/12/25
|
||||
*/
|
||||
@Api(tags = {"solr 中AIS数据查询模块"})
|
||||
@RestController
|
||||
@RequestMapping("/aisSolr")
|
||||
public class AisSolrController extends BaseController {
|
||||
|
||||
@Resource
|
||||
ISolrService solrService;
|
||||
|
||||
@ApiOperation(value = "根据mmsi获取 24H 轨迹信息")
|
||||
@PostMapping("/findAISPointPositionByMmsi")
|
||||
public AjaxResult findAISPointPositionByMmsi(@ApiParam("mmsi") @RequestParam("mmsi") String mmsi) {
|
||||
return AjaxResult.success(solrService.findAISPointPositionByMmsi(mmsi));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.ltgk.smartFishingPort.domain.entity;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ltgk.smartFishingPort.constant.DataKeyConstant;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.solr.core.mapping.Indexed;
|
||||
import org.springframework.data.solr.core.mapping.SolrDocument;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 船舶实时动态实体类
|
||||
*/
|
||||
@Data
|
||||
@SolrDocument(collection = DataKeyConstant.SOLR_AIS_POINT)
|
||||
@Accessors(chain = true)
|
||||
public class AisSolrEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Indexed(name = "id", type = "String")
|
||||
@ApiModelProperty("主键")
|
||||
private String id;
|
||||
|
||||
@Indexed(name = "storeLocation", type = "location")
|
||||
@ApiModelProperty(value = "点位数据存储 latitude,longitude 28.201514412386377,121.12529333335621")
|
||||
private String storeLocation;
|
||||
|
||||
@Indexed(name = "storeLocation_rpt", type = "location_rpt")
|
||||
@ApiModelProperty(value = "点位数据存储 latitude,longitude 28.201514412386377,121.12529333335621;用来进行范围查询")
|
||||
private String storeLocationRpt;
|
||||
|
||||
@ApiModelProperty("当前系统时间,格式:yyyy-MM-dd hh:mm:ss.ms")
|
||||
@Indexed(name = "time", type = "string")
|
||||
public String time;
|
||||
|
||||
@ApiModelProperty("uuid")
|
||||
@Indexed(name = "uuid", type = "string")
|
||||
private String uuid;
|
||||
|
||||
@ApiModelProperty("设备类型")
|
||||
@Indexed(name = "deviceType", type = "string")
|
||||
private String deviceType;
|
||||
|
||||
@ApiModelProperty("终端号码")
|
||||
@Indexed(name = "terminalCode", type = "string")
|
||||
private String terminalCode;
|
||||
|
||||
@ApiModelProperty("船名")
|
||||
@Indexed(name = "boatName", type = "string")
|
||||
private String boatName;
|
||||
|
||||
@ApiModelProperty("船名英文")
|
||||
@Indexed(name = "boatNameEn", type = "string")
|
||||
private String boatNameEn;
|
||||
|
||||
@ApiModelProperty("经度")
|
||||
@Indexed(name = "longitude", type = "double")
|
||||
private Double longitude;
|
||||
|
||||
@ApiModelProperty("纬度")
|
||||
@Indexed(name = "latitude", type = "double")
|
||||
private Double latitude;
|
||||
|
||||
@ApiModelProperty("船速")
|
||||
@Indexed(name = "sog", type = "string")
|
||||
private String sog;
|
||||
|
||||
@ApiModelProperty("航向")
|
||||
@Indexed(name = "cog", type = "string")
|
||||
private String cog;
|
||||
|
||||
@ApiModelProperty("船艏向")
|
||||
@Indexed(name = "heading", type = "string")
|
||||
private String heading;
|
||||
|
||||
@ApiModelProperty("来源")
|
||||
@Indexed(name = "dataSource", type = "string")
|
||||
private String dataSource;
|
||||
|
||||
@ApiModelProperty("报文内容")
|
||||
@Indexed(name = "msgContent", type = "string")
|
||||
private String msgContent;
|
||||
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty("定位时间")
|
||||
@Indexed(name = "gpsTime", type = "date")
|
||||
private Date gpsTime;
|
||||
|
||||
@ApiModelProperty("船长")
|
||||
@Indexed(name = "boatLength", type = "double")
|
||||
private Double boatLength;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ltgk.smartFishingPort.service;
|
||||
|
||||
import com.ltgk.smartFishingPort.domain.entity.AisSolrEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Solr对应服务
|
||||
*
|
||||
* @author Qi ChengBin
|
||||
* @date 2025/12/23
|
||||
*/
|
||||
public interface ISolrService {
|
||||
|
||||
/**
|
||||
* 根据 mmsi 获取AIS 船舶轨迹信息
|
||||
*
|
||||
* @param mmsi:
|
||||
* @return ltgk.pm.video.base.Response
|
||||
* @author Qi ChengBin
|
||||
* @date 2025/12/23
|
||||
*/
|
||||
Map<String, List<AisSolrEntity>> findAISPointPositionByMmsi(String mmsi);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.ltgk.smartFishingPort.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ltgk.smartFishingPort.common.SolrCommon;
|
||||
import com.ltgk.smartFishingPort.common.utils.DateUtils;
|
||||
import com.ltgk.smartFishingPort.constant.DataKeyConstant;
|
||||
import com.ltgk.smartFishingPort.domain.entity.AisSolrEntity;
|
||||
import com.ltgk.smartFishingPort.service.ISolrService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.solr.core.query.Criteria;
|
||||
import org.springframework.data.solr.core.query.SimpleQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Solr 服务实现
|
||||
*
|
||||
* @author Qi ChengBin
|
||||
* @date 2025/12/23
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SolrServiceImpl implements ISolrService {
|
||||
|
||||
/**
|
||||
* 根据 mmsi 获取AIS 船舶轨迹信息
|
||||
*
|
||||
* @param mmsi:
|
||||
* @return ltgk.pm.video.base.Response
|
||||
* @author Qi ChengBin
|
||||
* @date 2025/12/23
|
||||
*/
|
||||
@Override
|
||||
public Map<String, List<AisSolrEntity>> findAISPointPositionByMmsi(String mmsi) {
|
||||
Date nowDate = new Date();
|
||||
// 查询 24H 内的 mmsi 的数据
|
||||
String now = DateUtil.formatDateTime(nowDate);
|
||||
// 24小时之前的时间 before24HStr
|
||||
String before24HStr = DateUtil.offsetHour(nowDate, -24).toString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// 查询 solr 获取相关的轨迹
|
||||
Criteria criteria = new Criteria("terminalCode")
|
||||
.is(mmsi)
|
||||
.and("gpsTime")
|
||||
.between(DateUtils.toDate(before24HStr), DateUtils.toDate(now));
|
||||
SimpleQuery query = new SimpleQuery(criteria);
|
||||
query.addSort(Sort.by(Sort.Direction.DESC, "gpsTime"));
|
||||
query.setRows(100000);
|
||||
Page page = SolrCommon.solrSearchByQuery(DataKeyConstant.SOLR_AIS_POINT, query, AisSolrEntity.class);
|
||||
|
||||
// key 为 目标id value 为 尾迹的数据 resAisSolrList
|
||||
List<AisSolrEntity> resAisSolrList = new ArrayList<>();
|
||||
for (Object item : page.getContent()) {
|
||||
resAisSolrList.add((AisSolrEntity) item);
|
||||
}
|
||||
|
||||
return resAisSolrList.stream()
|
||||
.collect(Collectors.groupingBy(AisSolrEntity::getTerminalCode));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user