省厅位置汇聚ES查询返回时间大8小时问题处理并添加查询设备列表功能

stwzhj
luyya 2025-08-26 11:01:50 +08:00
parent 87882579c7
commit a01837bf6d
5 changed files with 80 additions and 21 deletions

View File

@ -29,10 +29,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -131,7 +128,7 @@ public class SearchServiceImpl implements ISearchService {
for (int i = 0; i < len; i++) {
hash = dateTimes.get(i).toString();
hash = hash.substring(0, 10).replaceAll("-","");
list.add("gpsinfo" + hash);
list.add("rs_gpsinfo" + hash);
}
return list;
}
@ -194,23 +191,13 @@ public class SearchServiceImpl implements ISearchService {
gpsInfoVO2.setDeviceCode(deviceCode);
gpsInfoVO2.setDeviceType(source.get("deviceType").toString());
long timestamp = Instant.parse(source.get("gpsTime").toString()).toEpochMilli();
String isoString =source.get("gpsTime").toString();
String isoString = source.get("gpsTime").toString();
Instant instant = Instant.parse(isoString);
Date utcDate = Date.from(instant);
// 方法2使用 Hutool + 时区转换
Date date = DateUtil.parse(isoString);
// 将时间调整为 UTC 时区
ZonedDateTime utcZdt = date.toInstant().atZone(ZoneId.of("UTC"));
Date utcDate2 = Date.from(utcZdt.toInstant());
Instant correctedInstant = instant.minus(Duration.ofHours(8));
// 验证结果
log.error("原始 UTC 时间: " + isoString);
log.error("方法1转换结果: " + utcDate);
log.error("方法2转换结果: " + utcDate2);
log.error("时间戳: " + utcDate.getTime());
gpsInfoVO2.setGpsTime(new Date(timestamp));
long correctedTimestamp = correctedInstant.toEpochMilli();
gpsInfoVO2.setGpsTime(new Date(correctedTimestamp));
gpsInfoVO2.setLat(lat+"");
gpsInfoVO2.setLng(lon+"");
log.info("gpsInfoVO2={}",gpsInfoVO2.toString());

View File

@ -10,8 +10,8 @@ spring:
profiles:
# 环境配置
active: @profiles.active@
autoconfigure:
exclude: org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration
autoconfigure:
exclude: org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration
--- # nacos 配置
spring:

View File

@ -1,11 +1,13 @@
package org.dromara.system.controller;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.exception.MyBusinessException;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
@ -46,6 +48,18 @@ public class TDeviceController extends BaseController {
return tDeviceService.queryPageList(bo, pageQuery);
}
@PostMapping("/getDeviceList")
public TableDataInfo<TDeviceVo> getDeviceList(@RequestBody TDeviceBo bo){
PageQuery pageQuery = new PageQuery();
if (Objects.isNull(bo)) {
throw new MyBusinessException("请求参数不能为空");
}
pageQuery.setPageNum(bo.getPageNum());
pageQuery.setPageSize(bo.getPageSize());
return tDeviceService.queryPageList(bo, pageQuery);
}
/**
* device
*/

View File

@ -109,5 +109,9 @@ public class TDeviceBo extends BaseEntity {
private String xgrsfzh;
private int pageNum;
private int pageSize;
}

View File

@ -0,0 +1,54 @@
package org.dromara.system.exception;
/**
* <p>description: </p>
*
* @author chenle
* @date 2021-06-07 10:56
*/
public class MyBusinessException extends RuntimeException {
private static final long serialVersionUID = 1L;
private String msg;
private int code = 500;
public MyBusinessException(String msg) {
super(msg);
this.msg = msg;
}
public MyBusinessException(String msg, Throwable e) {
super(msg, e);
this.msg = msg;
}
public MyBusinessException(String msg, int code) {
super(msg);
this.msg = msg;
this.code = code;
}
public MyBusinessException(String msg, int code, Throwable e) {
super(msg, e);
this.msg = msg;
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}