规范代码,注解、类名命名规范
parent
5b00ec421a
commit
43a410eb35
|
@ -0,0 +1,35 @@
|
|||
package com.zhilian.common.core.web.page;
|
||||
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 列表返回结果集
|
||||
*/
|
||||
@Data
|
||||
public class PageResult<T> implements Serializable {
|
||||
/**
|
||||
* 总条数
|
||||
*/
|
||||
private long total;
|
||||
/**
|
||||
* 结果集合
|
||||
*/
|
||||
private List<T> list;
|
||||
public PageResult() {
|
||||
}
|
||||
public PageResult(long total, List<T> list) {
|
||||
this.total = total;
|
||||
this.list = list;
|
||||
}
|
||||
public static <T> PageResult<T> toPageResult(long total, List<T> list){
|
||||
return new PageResult(total , list);
|
||||
}
|
||||
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
|
||||
return Result.success(PageResult.toPageResult(total,list));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.zhilian.common.resolver.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zhilian.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -9,7 +10,7 @@ import java.math.BigDecimal;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName Report
|
||||
* @ClassName ResolverReportInfo
|
||||
* @Description 报文实体类
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/26 21:47
|
||||
|
@ -17,7 +18,8 @@ import java.util.Date;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Report extends BaseEntity {
|
||||
@TableName("resolver_report_info")
|
||||
public class ResolverReportInfo extends BaseEntity {
|
||||
/**
|
||||
* 报文id
|
||||
*/
|
|
@ -0,0 +1,26 @@
|
|||
package com.zhilian.common.resolver.domain.req;
|
||||
|
||||
import lombok.Data;
|
||||
/**
|
||||
* @ClassName ReportByEsReq
|
||||
* @Description es查询报文请求参数
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/27 23:47
|
||||
*/
|
||||
@Data
|
||||
public class ReportByEsReq {
|
||||
/**
|
||||
* 当前页码
|
||||
*/
|
||||
private Integer pageNum=1;
|
||||
|
||||
/**
|
||||
* 每页显示条数
|
||||
*/
|
||||
private Integer pageSize=3;
|
||||
|
||||
/**
|
||||
* 车辆编号
|
||||
*/
|
||||
private String vin;
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.zhilian.common.resolver.domain.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* @ClassName ReportByEsResp
|
||||
* @Description ES 查询返回报文
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/27 23:48
|
||||
*/
|
||||
@Data
|
||||
public class ReportByEsResp {
|
||||
/**
|
||||
* 报文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;
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
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;
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.zhilian.resolver.controller;
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
import com.zhilian.common.core.web.page.PageResult;
|
||||
import com.zhilian.common.log.annotation.Log;
|
||||
import com.zhilian.common.log.enums.BusinessType;
|
||||
import com.zhilian.common.resolver.domain.req.ReportByEsReq;
|
||||
import com.zhilian.common.resolver.domain.resp.ReportByEsResp;
|
||||
import com.zhilian.resolver.service.ReportByEsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.RestController;
|
||||
/**
|
||||
* @ClassName ReportByElasticSearchController
|
||||
* @Description es获取报文数据
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/27 23:54
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/es")
|
||||
public class ReportByElasticSearchController {
|
||||
|
||||
/**
|
||||
* @Description ReportByEsService业务层
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/28 22:08
|
||||
*/
|
||||
@Autowired
|
||||
private ReportByEsService reportByEsService;
|
||||
|
||||
/**
|
||||
* @Description es获取报文数据
|
||||
* @Param [roomRequest]
|
||||
* @return com.zhilian.common.result.Result<com.zhilian.common.result.PageResult<com.zhilian.common.result.RoomResponse>>
|
||||
**/
|
||||
@Log(title = "es获取报文数据", businessType = BusinessType.OTHER)
|
||||
@PostMapping("/queryReportByEs")
|
||||
public Result<PageResult<ReportByEsResp>> queryReportByEs(@RequestBody ReportByEsReq reportByEsReq){
|
||||
Result<PageResult<ReportByEsResp>> result=reportByEsService.queryReportByEs(reportByEsReq);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,8 +5,8 @@ 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 com.zhilian.common.resolver.domain.ResolverReportInfo;
|
||||
import com.zhilian.resolver.service.ResolverReportInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -22,13 +22,14 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/report")
|
||||
public class ReportController extends BaseController {
|
||||
public class ResolverReportInfoController extends BaseController {
|
||||
|
||||
/**
|
||||
* @Description 注入报文服务层
|
||||
* @Autowired reportService
|
||||
*/
|
||||
@Autowired
|
||||
private ReportService reportService;
|
||||
private ResolverReportInfoService reportService;
|
||||
|
||||
/**
|
||||
* @Description 查询报文列表
|
||||
|
@ -38,9 +39,9 @@ public class ReportController extends BaseController {
|
|||
@Log(title = "报文信息", businessType = BusinessType.OTHER)
|
||||
//// @RequiresPermissions("resolver:report:list")
|
||||
@GetMapping("/queryReports")
|
||||
public Result<TableDataInfo<Report>> list (Report report) {
|
||||
public Result<TableDataInfo<ResolverReportInfo>> list (ResolverReportInfo report) {
|
||||
startPage();
|
||||
List<Report> list = reportService.pageQuery(report);
|
||||
List<ResolverReportInfo> list = reportService.pageQuery(report);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.zhilian.resolver.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ReportByEsMapper {
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
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,8 @@
|
|||
package com.zhilian.resolver.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhilian.common.resolver.domain.ResolverReportInfo;
|
||||
|
||||
public interface ResolverReportInfoMapper extends BaseMapper<ResolverReportInfo> {
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.zhilian.resolver.service;
|
||||
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
import com.zhilian.common.core.web.page.PageResult;
|
||||
import com.zhilian.common.resolver.domain.req.ReportByEsReq;
|
||||
import com.zhilian.common.resolver.domain.resp.ReportByEsResp;
|
||||
/**
|
||||
* @ClassName ReportByEsService
|
||||
* @Description ES 查询报文 业务层
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/28 0:03
|
||||
*/
|
||||
public interface ReportByEsService {
|
||||
/**
|
||||
* @Description: 查询报文
|
||||
* @Param: [reportByEsReq]
|
||||
* @return: Result<PageResult<ReportByEsResp>>
|
||||
*/
|
||||
Result<PageResult<ReportByEsResp>> queryReportByEs(ReportByEsReq reportByEsReq);
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.zhilian.resolver.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zhilian.common.resolver.domain.Report;
|
||||
import com.zhilian.common.resolver.domain.ResolverReportInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -11,7 +10,7 @@ import java.util.List;
|
|||
* @Author Can.J
|
||||
* @Date 2024/3/26 22:30
|
||||
*/
|
||||
public interface ReportService extends IService<Report> {
|
||||
public interface ResolverReportInfoService extends IService<ResolverReportInfo> {
|
||||
|
||||
List<Report> pageQuery(Report report);
|
||||
List<ResolverReportInfo> pageQuery(ResolverReportInfo report);
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.zhilian.resolver.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zhilian.common.core.domain.Result;
|
||||
import com.zhilian.common.core.utils.StringUtils;
|
||||
import com.zhilian.common.core.web.page.PageResult;
|
||||
import com.zhilian.common.resolver.domain.req.ReportByEsReq;
|
||||
import com.zhilian.common.resolver.domain.resp.ReportByEsResp;
|
||||
import com.zhilian.resolver.service.ReportByEsService;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName ReportByEsServiceImpl
|
||||
* @Description ES 查询报文业务实现层
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/28 0:03
|
||||
*/
|
||||
@Service
|
||||
public class ReportByEsServiceImpl implements ReportByEsService {
|
||||
/**
|
||||
* @Description RestHighLevelClient
|
||||
* @Author Can.J
|
||||
* @Date 2024/3/28 22:10
|
||||
*/
|
||||
@Autowired
|
||||
private RestHighLevelClient restHighLevelClient;
|
||||
|
||||
public static final String INDEX_REPORT = "report";
|
||||
@Override
|
||||
public Result<PageResult<ReportByEsResp>> queryReportByEs(ReportByEsReq reportByEsReq) {
|
||||
long total = 0;
|
||||
ArrayList<ReportByEsResp> list = new ArrayList<>();
|
||||
try {
|
||||
SearchRequest searchRequest = new SearchRequest(INDEX_REPORT);
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
if (StringUtils.isNotEmpty(reportByEsReq.getVin())) {
|
||||
boolQuery.must(QueryBuilders.matchQuery("vin", reportByEsReq.getVin()));
|
||||
}
|
||||
|
||||
searchSourceBuilder.query(boolQuery);
|
||||
searchSourceBuilder.from((reportByEsReq.getPageNum() - 1) * reportByEsReq.getPageSize());
|
||||
searchSourceBuilder.size(reportByEsReq.getPageSize());
|
||||
|
||||
searchSourceBuilder.highlighter(new HighlightBuilder()
|
||||
.field("vin")
|
||||
.preTags("<font color='red'>")
|
||||
.postTags("</font>"));
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
SearchHits searchHits = searchResponse.getHits();
|
||||
total = searchHits.getTotalHits().value;
|
||||
|
||||
SearchHit[] hits = searchHits.getHits();
|
||||
for (SearchHit hit : hits) {
|
||||
String sourceAsString = hit.getSourceAsString();
|
||||
ReportByEsResp reportByEsResp = JSONObject.parseObject(sourceAsString, ReportByEsResp.class);
|
||||
reportByEsResp.setReportId(Long.parseLong(hit.getId()));
|
||||
|
||||
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
|
||||
if (highlightFields != null) {
|
||||
HighlightField highlightField = highlightFields.get("vin");
|
||||
if (highlightField != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Text fragment : highlightField.getFragments()) {
|
||||
sb.append(fragment);
|
||||
System.out.println("打印" + fragment);
|
||||
}
|
||||
reportByEsResp.setVin(sb.toString());
|
||||
}
|
||||
}
|
||||
list.add(reportByEsResp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return PageResult.toResult(total, list);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@ 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 com.zhilian.common.resolver.domain.ResolverReportInfo;
|
||||
import com.zhilian.resolver.mapper.ResolverReportInfoMapper;
|
||||
import com.zhilian.resolver.service.ResolverReportInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
|
@ -33,7 +33,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService {
|
||||
public class ResolverReportInfoServiceImpl extends ServiceImpl<ResolverReportInfoMapper, ResolverReportInfo> implements ResolverReportInfoService {
|
||||
@Resource
|
||||
private RedisTemplate<String,Object> redisTemplate;
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|||
private RestHighLevelClient restHighLevelClient;
|
||||
|
||||
@Autowired
|
||||
private ReportMapper reportMapper;
|
||||
private ResolverReportInfoMapper reportMapper;
|
||||
|
||||
/**
|
||||
* 查询报文数据
|
||||
|
@ -49,24 +49,24 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Report> pageQuery(Report report) {
|
||||
List<Report> resultList;
|
||||
public List<ResolverReportInfo> pageQuery(ResolverReportInfo report) {
|
||||
List<ResolverReportInfo> resultList;
|
||||
//redis中查询
|
||||
log.info("从redis查询数据");
|
||||
String cacheKey=generateCacheKey(report);
|
||||
resultList =(List<Report>) redisTemplate.opsForValue().get(cacheKey);
|
||||
resultList =(List<ResolverReportInfo>) redisTemplate.opsForValue().get(cacheKey);
|
||||
if(resultList==null){
|
||||
//如果redis中不存在,则从数据库中查询
|
||||
log.info("从数据库查询数据");
|
||||
LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
|
||||
LambdaQueryWrapper<ResolverReportInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(report.getVin())){
|
||||
queryWrapper.like(Report::getVin,report.getVin());
|
||||
queryWrapper.like(ResolverReportInfo::getVin,report.getVin());
|
||||
}
|
||||
//status int类型 精确查询
|
||||
if(Objects.nonNull(report.getStatus())){
|
||||
queryWrapper.eq(Report::getStatus,report.getStatus());
|
||||
queryWrapper.eq(ResolverReportInfo::getStatus,report.getStatus());
|
||||
}
|
||||
queryWrapper.eq(Report::getIsDelete, 1); // 添加 isDelete == 1 的条件
|
||||
queryWrapper.eq(ResolverReportInfo::getIsDelete, 1); // 添加 isDelete == 1 的条件
|
||||
resultList =this.list(queryWrapper);
|
||||
|
||||
// 将从数据库中获取的数据存入 Redis,设置过期时间10分钟
|
||||
|
@ -88,11 +88,11 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|||
* @param report
|
||||
* @return
|
||||
*/
|
||||
private String generateCacheKey(Report report) {
|
||||
private String generateCacheKey(ResolverReportInfo report) {
|
||||
return "report_"+report.getVin();
|
||||
}
|
||||
|
||||
public void bulkInsert(List<Report> reports) throws IOException {
|
||||
public void bulkInsert(List<ResolverReportInfo> reports) throws IOException {
|
||||
BulkRequest bulkRequest = new BulkRequest();
|
||||
reports.forEach(report -> {
|
||||
// 创建一个索引请求,指定索引名称和文档ID
|
|
@ -0,0 +1,7 @@
|
|||
<?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.ReportByEsMapper">
|
||||
|
||||
</mapper>
|
|
@ -2,7 +2,7 @@
|
|||
<!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">
|
||||
<mapper namespace="com.zhilian.resolver.mapper.ResolverReportInfoMapper">
|
||||
<!-- <resultMap type="com.zhilian.resolver.domain.Report" id="resolverResult">-->
|
||||
<!-- <id property="reportId" column="report_id"/>-->
|
||||
<!-- <result property="vin" column="vin"/>-->
|
Loading…
Reference in New Issue