规范代码,注解、类名命名规范

server_2024_3_26_jiangcan
JangCan 2024-03-28 22:15:36 +08:00
parent 5b00ec421a
commit 43a410eb35
16 changed files with 378 additions and 36 deletions

View File

@ -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));
}
}

View File

@ -1,5 +1,6 @@
package com.zhilian.common.resolver.domain; package com.zhilian.common.resolver.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zhilian.common.core.web.domain.BaseEntity; import com.zhilian.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -9,7 +10,7 @@ import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
/** /**
* @ClassName Report * @ClassName ResolverReportInfo
* @Description * @Description
* @Author Can.J * @Author Can.J
* @Date 2024/3/26 21:47 * @Date 2024/3/26 21:47
@ -17,7 +18,8 @@ import java.util.Date;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class Report extends BaseEntity { @TableName("resolver_report_info")
public class ResolverReportInfo extends BaseEntity {
/** /**
* id * id
*/ */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,6 +1,4 @@
package com.zhilian.resolver; package com.zhilian.resolver;
import com.zhilian.common.security.annotation.EnableCustomConfig;
import com.zhilian.common.security.annotation.EnableMyFeignClients; import com.zhilian.common.security.annotation.EnableMyFeignClients;
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2; import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;

View File

@ -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;
}
}

View File

@ -5,8 +5,8 @@ import com.zhilian.common.core.web.controller.BaseController;
import com.zhilian.common.core.web.page.TableDataInfo; import com.zhilian.common.core.web.page.TableDataInfo;
import com.zhilian.common.log.annotation.Log; import com.zhilian.common.log.annotation.Log;
import com.zhilian.common.log.enums.BusinessType; import com.zhilian.common.log.enums.BusinessType;
import com.zhilian.common.resolver.domain.Report; import com.zhilian.common.resolver.domain.ResolverReportInfo;
import com.zhilian.resolver.service.ReportService; import com.zhilian.resolver.service.ResolverReportInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -22,13 +22,14 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/report") @RequestMapping("/report")
public class ReportController extends BaseController { public class ResolverReportInfoController extends BaseController {
/** /**
* @Description
* @Autowired reportService * @Autowired reportService
*/ */
@Autowired @Autowired
private ReportService reportService; private ResolverReportInfoService reportService;
/** /**
* @Description * @Description
@ -38,9 +39,9 @@ public class ReportController extends BaseController {
@Log(title = "报文信息", businessType = BusinessType.OTHER) @Log(title = "报文信息", businessType = BusinessType.OTHER)
//// @RequiresPermissions("resolver:report:list") //// @RequiresPermissions("resolver:report:list")
@GetMapping("/queryReports") @GetMapping("/queryReports")
public Result<TableDataInfo<Report>> list (Report report) { public Result<TableDataInfo<ResolverReportInfo>> list (ResolverReportInfo report) {
startPage(); startPage();
List<Report> list = reportService.pageQuery(report); List<ResolverReportInfo> list = reportService.pageQuery(report);
return getDataTable(list); return getDataTable(list);
} }

View File

@ -0,0 +1,7 @@
package com.zhilian.resolver.mapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ReportByEsMapper {
}

View File

@ -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> {
}

View File

@ -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> {
}

View File

@ -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);
}

View File

@ -1,7 +1,6 @@
package com.zhilian.resolver.service; package com.zhilian.resolver.service;
import com.baomidou.mybatisplus.extension.service.IService; 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; import java.util.List;
@ -11,7 +10,7 @@ import java.util.List;
* @Author Can.J * @Author Can.J
* @Date 2024/3/26 22:30 * @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);
} }

View File

@ -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);
}
}

View File

@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.common.core.utils.StringUtils; import com.zhilian.common.core.utils.StringUtils;
import com.zhilian.common.resolver.domain.Report; import com.zhilian.common.resolver.domain.ResolverReportInfo;
import com.zhilian.resolver.mapper.ReportMapper; import com.zhilian.resolver.mapper.ResolverReportInfoMapper;
import com.zhilian.resolver.service.ReportService; import com.zhilian.resolver.service.ResolverReportInfoService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequest;
@ -33,7 +33,7 @@ import java.util.Objects;
*/ */
@Slf4j @Slf4j
@Service @Service
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService { public class ResolverReportInfoServiceImpl extends ServiceImpl<ResolverReportInfoMapper, ResolverReportInfo> implements ResolverReportInfoService {
@Resource @Resource
private RedisTemplate<String,Object> redisTemplate; private RedisTemplate<String,Object> redisTemplate;
@ -41,7 +41,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
private RestHighLevelClient restHighLevelClient; private RestHighLevelClient restHighLevelClient;
@Autowired @Autowired
private ReportMapper reportMapper; private ResolverReportInfoMapper reportMapper;
/** /**
* *
@ -49,24 +49,24 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
* @return * @return
*/ */
@Override @Override
public List<Report> pageQuery(Report report) { public List<ResolverReportInfo> pageQuery(ResolverReportInfo report) {
List<Report> resultList; List<ResolverReportInfo> resultList;
//redis中查询 //redis中查询
log.info("从redis查询数据"); log.info("从redis查询数据");
String cacheKey=generateCacheKey(report); String cacheKey=generateCacheKey(report);
resultList =(List<Report>) redisTemplate.opsForValue().get(cacheKey); resultList =(List<ResolverReportInfo>) redisTemplate.opsForValue().get(cacheKey);
if(resultList==null){ if(resultList==null){
//如果redis中不存在则从数据库中查询 //如果redis中不存在则从数据库中查询
log.info("从数据库查询数据"); log.info("从数据库查询数据");
LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ResolverReportInfo> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(report.getVin())){ if (StringUtils.isNotEmpty(report.getVin())){
queryWrapper.like(Report::getVin,report.getVin()); queryWrapper.like(ResolverReportInfo::getVin,report.getVin());
} }
//status int类型 精确查询 //status int类型 精确查询
if(Objects.nonNull(report.getStatus())){ 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); resultList =this.list(queryWrapper);
// 将从数据库中获取的数据存入 Redis设置过期时间10分钟 // 将从数据库中获取的数据存入 Redis设置过期时间10分钟
@ -88,11 +88,11 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
* @param report * @param report
* @return * @return
*/ */
private String generateCacheKey(Report report) { private String generateCacheKey(ResolverReportInfo report) {
return "report_"+report.getVin(); return "report_"+report.getVin();
} }
public void bulkInsert(List<Report> reports) throws IOException { public void bulkInsert(List<ResolverReportInfo> reports) throws IOException {
BulkRequest bulkRequest = new BulkRequest(); BulkRequest bulkRequest = new BulkRequest();
reports.forEach(report -> { reports.forEach(report -> {
// 创建一个索引请求指定索引名称和文档ID // 创建一个索引请求指定索引名称和文档ID

View File

@ -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>

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "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">--> <!-- <resultMap type="com.zhilian.resolver.domain.Report" id="resolverResult">-->
<!-- <id property="reportId" column="report_id"/>--> <!-- <id property="reportId" column="report_id"/>-->
<!-- <result property="vin" column="vin"/>--> <!-- <result property="vin" column="vin"/>-->