jc报文表实现预加载,同步es成功
parent
979074fc11
commit
5b00ec421a
6
pom.xml
6
pom.xml
|
@ -207,6 +207,12 @@
|
||||||
<version>${zhilian.version}</version>
|
<version>${zhilian.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-resolver</artifactId>
|
||||||
|
<version>${zhilian.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 智联业务模块 -->
|
<!-- 智联业务模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zhilian</groupId>
|
<groupId>com.zhilian</groupId>
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<module>zhilian-common-datascope</module>
|
<module>zhilian-common-datascope</module>
|
||||||
<module>zhilian-common-datasource</module>
|
<module>zhilian-common-datasource</module>
|
||||||
<module>zhilian-common-system</module>
|
<module>zhilian-common-system</module>
|
||||||
|
<module>zhilian-common-resolver</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>zhilian-common</artifactId>
|
<artifactId>zhilian-common</artifactId>
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>zhilian-common-resolver</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,113 @@
|
||||||
|
package com.zhilian.common.resolver.domain;
|
||||||
|
|
||||||
|
import com.zhilian.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName Report
|
||||||
|
* @Description 报文实体类
|
||||||
|
* @Author Can.J
|
||||||
|
* @Date 2024/3/26 21:47
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Report extends BaseEntity {
|
||||||
|
/**
|
||||||
|
* 报文id
|
||||||
|
*/
|
||||||
|
private Long reportId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆编码
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆在线时间
|
||||||
|
*/
|
||||||
|
private Date onlineTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆下线时间
|
||||||
|
*/
|
||||||
|
private Date downLineTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 经度
|
||||||
|
*/
|
||||||
|
private String longitude;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 维度
|
||||||
|
*/
|
||||||
|
private String latitude;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电池剩余电量
|
||||||
|
*/
|
||||||
|
private BigDecimal remainingBattery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电池电量
|
||||||
|
*/
|
||||||
|
private BigDecimal batteryLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总里程
|
||||||
|
*/
|
||||||
|
private BigDecimal totalMileage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前是否在线: 1在线 0:不在线
|
||||||
|
*/
|
||||||
|
private int isOnline;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆是否发生故障: 1是 0:否
|
||||||
|
*/
|
||||||
|
private int isBreakDown;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆故障是否解决: 1是 0:否
|
||||||
|
*/
|
||||||
|
private int isSolve;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆是否延迟:1是 0:否
|
||||||
|
*/
|
||||||
|
private int isDelay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆是否重复: 1是 0:否
|
||||||
|
*/
|
||||||
|
private int isRepeat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆状态: 1行驶中 0:停止
|
||||||
|
*/
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对应企业id
|
||||||
|
*/
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否展示 1展示 0:不展示
|
||||||
|
*/
|
||||||
|
private Integer isDelete;
|
||||||
|
private String createBy;
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
#com.zhilian.common.system.remote.factory.RemoteUserFallbackFactory
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
@ -34,6 +36,7 @@ spring:
|
||||||
ds1:
|
ds1:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
dataId: sentinel-zhilian-gateway
|
dataId: sentinel-zhilian-gateway
|
||||||
groupId: DEFAULT_GROUP
|
groupId: DEFAULT_GROUP
|
||||||
data-type: json
|
data-type: json
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -11,12 +11,6 @@
|
||||||
|
|
||||||
<artifactId>zhilian-resolver</artifactId>
|
<artifactId>zhilian-resolver</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
zhilian-resolver 处理模块
|
zhilian-resolver 处理模块
|
||||||
</description>
|
</description>
|
||||||
|
@ -66,6 +60,11 @@
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- zhilian Common Log -->
|
<!-- zhilian Common Log -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zhilian</groupId>
|
<groupId>com.zhilian</groupId>
|
||||||
|
@ -78,6 +77,39 @@
|
||||||
<artifactId>zhilian-common-swagger</artifactId>
|
<artifactId>zhilian-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- zhilian Common DataSource -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-datasource</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- zhilian Common DataScope -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-datascope</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- zhilian Common Log -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-log</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhilian</groupId>
|
||||||
|
<artifactId>zhilian-common-resolver</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
|
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -105,4 +137,4 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.zhilian.resolver;
|
||||||
|
|
||||||
|
import com.zhilian.common.security.annotation.EnableCustomConfig;
|
||||||
|
import com.zhilian.common.security.annotation.EnableMyFeignClients;
|
||||||
|
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@EnableCustomSwagger2
|
||||||
|
@EnableMyFeignClients
|
||||||
|
@MapperScan("com.zhilian.resolver.mapper")
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ZhiLianResolverApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ZhiLianResolverApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.zhilian.resolver.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
|
import org.elasticsearch.client.RestClient;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "es")
|
||||||
|
@Data
|
||||||
|
public class InitEsRes {
|
||||||
|
private String host;
|
||||||
|
private int port;
|
||||||
|
private String scheme;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestHighLevelClient restHighLevelClient(){
|
||||||
|
return new RestHighLevelClient(
|
||||||
|
RestClient.builder(new HttpHost(host,port,scheme))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.zhilian.resolver.controller;
|
||||||
|
|
||||||
|
import com.zhilian.common.core.domain.Result;
|
||||||
|
import com.zhilian.common.core.web.controller.BaseController;
|
||||||
|
import com.zhilian.common.core.web.page.TableDataInfo;
|
||||||
|
import com.zhilian.common.log.annotation.Log;
|
||||||
|
import com.zhilian.common.log.enums.BusinessType;
|
||||||
|
import com.zhilian.common.resolver.domain.Report;
|
||||||
|
import com.zhilian.resolver.service.ReportService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ReportController
|
||||||
|
* @Description 报文控制层
|
||||||
|
* @Author Can.J
|
||||||
|
* @Date 2024/3/26 22:13
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/report")
|
||||||
|
public class ReportController extends BaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Autowired reportService
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private ReportService reportService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 查询报文列表
|
||||||
|
* @Param [report]
|
||||||
|
* @Return com.zhilian.common.core.web.controller.Result<com.zhilian.common.core.web.page.TableDataInfo<com.zhilian.resolver.domain.Report>>
|
||||||
|
*/
|
||||||
|
@Log(title = "报文信息", businessType = BusinessType.OTHER)
|
||||||
|
//// @RequiresPermissions("resolver:report:list")
|
||||||
|
@GetMapping("/queryReports")
|
||||||
|
public Result<TableDataInfo<Report>> list (Report report) {
|
||||||
|
startPage();
|
||||||
|
List<Report> list = reportService.pageQuery(report);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.zhilian.resolver.mapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.zhilian.common.resolver.domain.Report;
|
||||||
|
|
||||||
|
public interface ReportMapper extends BaseMapper<Report> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.zhilian.resolver.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.zhilian.common.resolver.domain.Report;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ReportService
|
||||||
|
* @Description 报文业务层
|
||||||
|
* @Author Can.J
|
||||||
|
* @Date 2024/3/26 22:30
|
||||||
|
*/
|
||||||
|
public interface ReportService extends IService<Report> {
|
||||||
|
|
||||||
|
List<Report> pageQuery(Report report);
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
package com.zhilian.resolver.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.zhilian.common.core.utils.StringUtils;
|
||||||
|
import com.zhilian.common.resolver.domain.Report;
|
||||||
|
import com.zhilian.resolver.mapper.ReportMapper;
|
||||||
|
import com.zhilian.resolver.service.ReportService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||||
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
|
import org.elasticsearch.action.bulk.BulkResponse;
|
||||||
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
|
import org.elasticsearch.client.RequestOptions;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.elasticsearch.xcontent.XContentType;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ReportServiceImpl
|
||||||
|
* @Description 报文业务实现层
|
||||||
|
* @Author Can.J
|
||||||
|
* @Date 2024/3/26 22:31
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService {
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String,Object> redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestHighLevelClient restHighLevelClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ReportMapper reportMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询报文数据
|
||||||
|
* @param report
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Report> pageQuery(Report report) {
|
||||||
|
List<Report> resultList;
|
||||||
|
//redis中查询
|
||||||
|
log.info("从redis查询数据");
|
||||||
|
String cacheKey=generateCacheKey(report);
|
||||||
|
resultList =(List<Report>) redisTemplate.opsForValue().get(cacheKey);
|
||||||
|
if(resultList==null){
|
||||||
|
//如果redis中不存在,则从数据库中查询
|
||||||
|
log.info("从数据库查询数据");
|
||||||
|
LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (StringUtils.isNotEmpty(report.getVin())){
|
||||||
|
queryWrapper.like(Report::getVin,report.getVin());
|
||||||
|
}
|
||||||
|
//status int类型 精确查询
|
||||||
|
if(Objects.nonNull(report.getStatus())){
|
||||||
|
queryWrapper.eq(Report::getStatus,report.getStatus());
|
||||||
|
}
|
||||||
|
queryWrapper.eq(Report::getIsDelete, 1); // 添加 isDelete == 1 的条件
|
||||||
|
resultList =this.list(queryWrapper);
|
||||||
|
|
||||||
|
// 将从数据库中获取的数据存入 Redis,设置过期时间10分钟
|
||||||
|
redisTemplate.opsForValue().set(cacheKey,resultList, Duration.ofMinutes(10));
|
||||||
|
|
||||||
|
//查询结果从数据库获取之后,将其批量写入Elasticsearch
|
||||||
|
try {
|
||||||
|
bulkInsert(resultList);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("报文数据同步ES错误",e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成缓存的key
|
||||||
|
* @param report
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String generateCacheKey(Report report) {
|
||||||
|
return "report_"+report.getVin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bulkInsert(List<Report> reports) throws IOException {
|
||||||
|
BulkRequest bulkRequest = new BulkRequest();
|
||||||
|
reports.forEach(report -> {
|
||||||
|
// 创建一个索引请求,指定索引名称和文档ID
|
||||||
|
IndexRequest indexRequest = new IndexRequest("report");
|
||||||
|
indexRequest.id(report.getReportId().toString());
|
||||||
|
// 将对象转换为JSON字符串
|
||||||
|
String jsonString = JSON.toJSONString(report);
|
||||||
|
// 将JSON字符串设置为索引请求的文档内容
|
||||||
|
indexRequest.source(jsonString, XContentType.JSON);
|
||||||
|
// 将索引请求添加到批量请求中
|
||||||
|
bulkRequest.add(indexRequest);
|
||||||
|
});
|
||||||
|
BulkResponse bulkResponse = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
|
||||||
|
if(bulkResponse.hasFailures()){
|
||||||
|
//处理失败的情况
|
||||||
|
for (BulkItemResponse item : bulkResponse.getItems()) {
|
||||||
|
if(item.isFailed()){
|
||||||
|
log.error("报文数据同步到ES失败:{}",item.getFailureMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.info("报文同步ES成功:{}条",reports.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,10 @@ server:
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
redis:
|
||||||
|
host: 10.10.25.3
|
||||||
|
port: 6379
|
||||||
|
password: fffdev
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: zhilian-resolver
|
name: zhilian-resolver
|
||||||
|
@ -15,11 +19,17 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
es:
|
||||||
|
host: 111.229.33.194
|
||||||
|
port: 9200
|
||||||
|
scheme: http
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.zhilian.resolver.mapper.ReportMapper">
|
||||||
|
<!-- <resultMap type="com.zhilian.resolver.domain.Report" id="resolverResult">-->
|
||||||
|
<!-- <id property="reportId" column="report_id"/>-->
|
||||||
|
<!-- <result property="vin" column="vin"/>-->
|
||||||
|
<!-- <result property="onlineTime" column="online_time"/>-->
|
||||||
|
<!-- <result property="downLineTime" column="down_line_time"/>-->
|
||||||
|
<!-- <result property="longitude" column="longitude"/>-->
|
||||||
|
<!-- <result property="latitude" column="latitude"/>-->
|
||||||
|
<!-- <result property="remainingBattery" column="remaining_battery"/>-->
|
||||||
|
<!-- <result property="batteryLevel" column="battery_level"/>-->
|
||||||
|
<!-- <result property="totalMileage" column="total_mileage"/>-->
|
||||||
|
<!-- <result property="isOnline" column="is_online"/>-->
|
||||||
|
<!-- <result property="createTime" column="create_time"/>-->
|
||||||
|
<!-- <result property="isBreakDown" column="is_break_down"/>-->
|
||||||
|
<!-- <result property="isSolve" column="is_solve"/>-->
|
||||||
|
<!-- <result property="isDelay" column="is_delay"/>-->
|
||||||
|
<!-- <result property="isRepeat" column="is_repeat"/>-->
|
||||||
|
<!-- <result property="status" column="status"/>-->
|
||||||
|
<!-- <result property="companyId" column="company_id"/>-->
|
||||||
|
<!-- </resultMap>-->
|
||||||
|
<!-- <sql id="resolverList">-->
|
||||||
|
<!-- SELECT report_id,-->
|
||||||
|
<!-- vin,-->
|
||||||
|
<!-- online_time,-->
|
||||||
|
<!-- down_line_time,-->
|
||||||
|
<!-- longitude,-->
|
||||||
|
<!-- latitude,-->
|
||||||
|
<!-- remaining_battery,-->
|
||||||
|
<!-- battery_level,-->
|
||||||
|
<!-- total_mileage,-->
|
||||||
|
<!-- is_online,-->
|
||||||
|
<!-- create_time,-->
|
||||||
|
<!-- is_break_down,-->
|
||||||
|
<!-- is_solve,-->
|
||||||
|
<!-- is_delay,-->
|
||||||
|
<!-- is_repeat,-->
|
||||||
|
<!-- status,-->
|
||||||
|
<!-- company_id-->
|
||||||
|
<!-- from t_report WHERE is_delete=1-->
|
||||||
|
<!-- </sql>-->
|
||||||
|
|
||||||
|
<!-- <select id="queryReports" resultType="com.zhilian.resolver.domain.ResReport" resultMap="resolverResult">-->
|
||||||
|
<!-- <include refid="resolverList"/>-->
|
||||||
|
<!-- <where>-->
|
||||||
|
<!-- <if test="vin != null and vin != ''">-->
|
||||||
|
<!-- AND vin like concat('%',#{vin},'%')-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- <if test="status != null ">-->
|
||||||
|
<!-- AND status = #{status}-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- </where>-->
|
||||||
|
<!-- </select>-->
|
||||||
|
</mapper>
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 10.10.25.2:8848
|
server-addr: 10.10.25.2:8848
|
||||||
|
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
Loading…
Reference in New Issue