Commit 143a56a0 by 黄明步

完成应用能力调用记录导出,修复导出数据缺失bug

parent b1c592cb
...@@ -8,12 +8,14 @@ import com.alibaba.excel.util.MapUtils; ...@@ -8,12 +8,14 @@ import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxmailu.ocrCloudPlatform.dto.RecordDto; import com.gxmailu.ocrCloudPlatform.dto.RecordDto;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll; import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.excel.handler.ExcelFillCellMergeStrategy; import com.gxmailu.ocrCloudPlatform.excel.handler.ExcelFillCellMergeStrategy;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel; import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils; import com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils;
import com.gxmailu.ocrCloudPlatform.service.AppAbilityRecordAllService; import com.gxmailu.ocrCloudPlatform.service.AppAbilityRecordAllService;
import com.gxmailu.ocrCloudPlatform.vo.AppAbilityRecordVo;
import com.gxmailu.ocrCloudPlatform.vo.Result; import com.gxmailu.ocrCloudPlatform.vo.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -22,7 +24,9 @@ import org.springframework.util.Assert; ...@@ -22,7 +24,9 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -45,14 +49,14 @@ public class AppAbilityRecordAllController { ...@@ -45,14 +49,14 @@ public class AppAbilityRecordAllController {
/** /**
* 导出应用调用记录 * 导出应用调用记录
* *
* @param yearMonthDay 年月日calendar * @param yearMonthDay 年月日
*/ */
@RequestMapping("/deriveCallRecord") @RequestMapping("/deriveCallRecord")
@ResponseBody @ResponseBody
public void deriveCallRecord(String yearMonthDay, String endYearMonthDay, HttpServletResponse response) { public void deriveCallRecord(String yearMonthDay, String endYearMonthDay, HttpServletResponse response) {
//设置到新的对象上,用以下面的文件名称处理 // 设置到新的对象上,用以下面的文件名称处理
String newYearMonthDay = yearMonthDay; String newYearMonthDay = yearMonthDay;
if(StrUtil.isNotBlank(yearMonthDay)){ if (StrUtil.isNotBlank(yearMonthDay)) {
int count = yearMonthDay.split("-").length; int count = yearMonthDay.split("-").length;
switch (count) { switch (count) {
case 1: case 1:
...@@ -73,23 +77,24 @@ public class AppAbilityRecordAllController { ...@@ -73,23 +77,24 @@ public class AppAbilityRecordAllController {
break; break;
} }
System.out.println("yearMonthDay==========" + yearMonthDay + ";endYearMonthDay==========" + endYearMonthDay);
} else { } else {
yearMonthDay = DateUtil.parse("2014-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toString(); yearMonthDay = DateUtil.parse("2014-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toString();
endYearMonthDay = DateUtil.parse(DateUtil.date().toString(), "yyyy-MM-dd HH:mm:ss").toString(); endYearMonthDay = DateUtil.parse(DateUtil.date().toString(), "yyyy-MM-dd HH:mm:ss").toString();
} }
try{ System.out.println("yearMonthDay==========" + yearMonthDay + ";endYearMonthDay==========" + endYearMonthDay);
try {
List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay); List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay);
Assert.notNull(callRecordList, "未找到相关数据"); Assert.notNull(callRecordList, "未找到相关数据");
String fileName = StringUtils.isEmpty(newYearMonthDay) ? "各法院调用统计.xlsx" : "各法院" + newYearMonthDay + "调用统计.xlsx"; String fileName = StringUtils.isEmpty(newYearMonthDay) ? "各法院调用统计.xlsx" : "各法院" + newYearMonthDay + "调用统计.xlsx";
fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
// 设置单元格样式策略 // 设置单元格样式策略
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(ExcelStyleUtils.getHeadStyle(), ExcelStyleUtils.getContentStyle()); HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(ExcelStyleUtils.getHeadStyle(), ExcelStyleUtils.getContentStyle());
EasyExcel.write(response.getOutputStream(), CallRecordModel.class) EasyExcel.write(response.getOutputStream(), CallRecordModel.class)
.sheet("导出数据") .sheet(StrUtil.isBlank(newYearMonthDay) ? "ALL" : newYearMonthDay)
.head(CallRecordModel.class) .head(CallRecordModel.class)
// 自动行宽策略 // 自动行宽策略
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
...@@ -98,7 +103,7 @@ public class AppAbilityRecordAllController { ...@@ -98,7 +103,7 @@ public class AppAbilityRecordAllController {
// 设置单元格样式 // 设置单元格样式
.registerWriteHandler(horizontalCellStyleStrategy) .registerWriteHandler(horizontalCellStyleStrategy)
.doWrite(callRecordList); .doWrite(callRecordList);
} catch (Exception e){ } catch (Exception e) {
log.error("导出异常", e); log.error("导出异常", e);
// 重置response // 重置response
response.reset(); response.reset();
...@@ -106,7 +111,7 @@ public class AppAbilityRecordAllController { ...@@ -106,7 +111,7 @@ public class AppAbilityRecordAllController {
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
Map<String, String> map = MapUtils.newHashMap(); Map<String, String> map = MapUtils.newHashMap();
map.put("status", "500"); map.put("status", "500");
map.put("message", "数据过大,导出文件失败"); map.put("message", "由于导出数据量过大,导致无法导出。请移步详见后台管理-应用能力调用记录");
try { try {
response.getWriter().println(JSON.toJSONString(map)); response.getWriter().println(JSON.toJSONString(map));
} catch (IOException ex) { } catch (IOException ex) {
...@@ -128,20 +133,62 @@ public class AppAbilityRecordAllController { ...@@ -128,20 +133,62 @@ public class AppAbilityRecordAllController {
return recordAllService.getList(recordDto); return recordAllService.getList(recordDto);
} }
@PostMapping("/exportRecord")
public Object exportRecord(RecordDto recordDto, HttpServletResponse response) {
Assert.notNull(recordDto, "参数不能为空");
try {
if (StrUtil.isNotBlank(recordDto.getIpScope())) {
recordDto.setIpScopeList(StrUtil.splitTrim(recordDto.getIpScope(), ";"));
}
Page<AppAbilityRecordVo> recordListByPage = recordAllService.getRecordListByPage(recordDto);
String fileName = URLEncoder.encode("fileName", "UTF-8").replaceAll("\\+", "%20");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
// 设置单元格样式策略
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(ExcelStyleUtils.getHeadStyle(), ExcelStyleUtils.getContentStyle());
EasyExcel.write(response.getOutputStream(), AppAbilityRecordVo.class)
.sheet("调用记录")
.head(AppAbilityRecordVo.class)
// 自动行宽策略
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 自定义合并策略
.registerWriteHandler(new ExcelFillCellMergeStrategy(0, 0, new int[]{0, 1}))
// 设置单元格样式
.registerWriteHandler(horizontalCellStyleStrategy)
.doWrite(recordListByPage.getRecords());
} catch (IOException e) {
log.error("调用记录导出异常", e);
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
Map<String, String> map = MapUtils.newHashMap();
map.put("status", "500");
map.put("message", "由于导出数据量过大,处理失败。");
try {
response.getWriter().println(JSON.toJSONString(map));
} catch (IOException ex) {
log.error("", ex);
}
}
return null;
}
@PostMapping("/getListByPage") @PostMapping("/getListByPage")
public Result getListByPage(@RequestBody RecordDto recordDto) { public Result getListByPage(@RequestBody RecordDto recordDto) {
Assert.notNull(recordDto, "参数不能为空"); Assert.notNull(recordDto, "参数不能为空");
try { try {
return Result.success("", recordAllService.getRecordList(recordDto)); return Result.success("", recordAllService.getRecordListByPage(recordDto));
} catch (IOException e) { } catch (IOException e) {
log.error("调用记录查询异常", e); log.error("调用记录查询异常", e);
return Result.error("查询异常,请联系管理员"); return Result.error("查询异常,请联系管理员");
} }
} }
@PostMapping("/getById") @PostMapping("/getById")
public Object getById(Long id) { public Object getById(Long id) {
Assert.notNull(id, "参数不能为空"); Assert.notNull(id, "参数不能为空");
return Result.success("",recordAllService.getById(id)); return Result.success("", recordAllService.getById(id));
} }
...@@ -151,27 +198,27 @@ public class AppAbilityRecordAllController { ...@@ -151,27 +198,27 @@ public class AppAbilityRecordAllController {
} }
@GetMapping("/getCourtUseInYear") @GetMapping("/getCourtUseInYear")
public Object getCourtUseInYear(@RequestParam Integer year,@RequestParam String courtName) { public Object getCourtUseInYear(@RequestParam Integer year, @RequestParam String courtName) {
return recordAllService.getCourtUseInYear(year,courtName); return recordAllService.getCourtUseInYear(year, courtName);
} }
@GetMapping("/getCourtUseInMonth") @GetMapping("/getCourtUseInMonth")
public Object getCourtUseInMonth(Integer year, Integer month,String courtName) { public Object getCourtUseInMonth(Integer year, Integer month, String courtName) {
return recordAllService.getCourtUseInMonth(year, month,courtName); return recordAllService.getCourtUseInMonth(year, month, courtName);
} }
@GetMapping("/getCourtUseInDay") @GetMapping("/getCourtUseInDay")
public Object getCourtUseInDay(Integer year, Integer month, Integer day,String courtName) { public Object getCourtUseInDay(Integer year, Integer month, Integer day, String courtName) {
return recordAllService.getCourtUseInDay(year, month, day,courtName); return recordAllService.getCourtUseInDay(year, month, day, courtName);
} }
@GetMapping("getCorrelationData") @GetMapping("getCorrelationData")
public Result getCorrelationDate(String day1,String day2){ public Result getCorrelationDate(String day1, String day2) {
return recordAllService.getCorrelationData(day1,day2); return recordAllService.getCorrelationData(day1, day2);
} }
@GetMapping("getBrokenLineData") @GetMapping("getBrokenLineData")
public Result getBrokenLineData(String date){ public Result getBrokenLineData(String date) {
return recordAllService.getBrokenLineData(date); return recordAllService.getBrokenLineData(date);
} }
......
...@@ -15,7 +15,7 @@ public class RecordDto implements Serializable { ...@@ -15,7 +15,7 @@ public class RecordDto implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Integer courtId; private Integer courtCode;
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date startTime; private Date startTime;
...@@ -25,6 +25,7 @@ public class RecordDto implements Serializable { ...@@ -25,6 +25,7 @@ public class RecordDto implements Serializable {
private Date endTime; private Date endTime;
private String applicationId; private String applicationId;
private String abilityId; private String abilityId;
private String ipScope;
private List<String> ipScopeList; private List<String> ipScopeList;
private Integer page; private Integer page;
private Integer limit; private Integer limit;
......
...@@ -2,6 +2,7 @@ package com.gxmailu.ocrCloudPlatform.excel.model; ...@@ -2,6 +2,7 @@ package com.gxmailu.ocrCloudPlatform.excel.model;
import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -29,7 +30,7 @@ public class CallRecordModel implements Serializable { ...@@ -29,7 +30,7 @@ public class CallRecordModel implements Serializable {
@ExcelIgnore @ExcelIgnore
@ExcelProperty(value = "总调用次数") @ExcelProperty(value = "总调用次数")
private Integer callCount; private Long callCount;
@ExcelIgnore @ExcelIgnore
@ExcelProperty(value = "用户调用次数") @ExcelProperty(value = "用户调用次数")
...@@ -42,7 +43,7 @@ public class CallRecordModel implements Serializable { ...@@ -42,7 +43,7 @@ public class CallRecordModel implements Serializable {
@ExcelProperty(value = "识别能力", index = 2) @ExcelProperty(value = "识别能力", index = 2)
private String abilityName; private String abilityName;
@ExcelProperty(value = "调用次数", index = 3) @ExcelProperty(value = "调用次数", index = 3)
private long abilityDocCount; private Long abilityDocCount;
@ExcelProperty(value = "总识别页数", index = 4) @ExcelProperty(value = "总识别页数", index = 4)
private Integer fileCount; private Long fileCount;
} }
package com.gxmailu.ocrCloudPlatform.service; package com.gxmailu.ocrCloudPlatform.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.gxmailu.ocrCloudPlatform.dto.RecordDto; import com.gxmailu.ocrCloudPlatform.dto.RecordDto;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll; import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.entity.DeriveCallRecord; import com.gxmailu.ocrCloudPlatform.entity.DeriveCallRecord;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel; import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.vo.AppAbilityRecordVo;
import com.gxmailu.ocrCloudPlatform.vo.Result; import com.gxmailu.ocrCloudPlatform.vo.Result;
import java.io.IOException; import java.io.IOException;
...@@ -39,5 +41,5 @@ public interface AppAbilityRecordAllService extends IService<AppAbilityRecordAll ...@@ -39,5 +41,5 @@ public interface AppAbilityRecordAllService extends IService<AppAbilityRecordAll
Result getBrokenLineData(String date); Result getBrokenLineData(String date);
Object getRecordList(RecordDto recordDto) throws IOException; Page<AppAbilityRecordVo> getRecordListByPage(RecordDto recordDto) throws IOException;
} }
...@@ -102,10 +102,10 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord ...@@ -102,10 +102,10 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
@Override @Override
public Object getList(RecordDto recordDto) { public Object getList(RecordDto recordDto) {
List<String> serverIpList = new ArrayList<>(); List<String> serverIpList = new ArrayList<>();
Integer courtId = recordDto.getCourtId(); Integer courtCode = recordDto.getCourtCode();
Integer network = recordDto.getNetwork(); Integer network = recordDto.getNetwork();
List<ServerInfo> list = serverInfoMapper.selectList(Wrappers.lambdaQuery(ServerInfo.class) List<ServerInfo> list = serverInfoMapper.selectList(Wrappers.lambdaQuery(ServerInfo.class)
.eq(courtId != null, ServerInfo::getCourtCode, courtId) .eq(courtCode != null, ServerInfo::getCourtCode, courtCode)
.eq(network != null && network != -1, ServerInfo::getNetwork, network)); .eq(network != null && network != -1, ServerInfo::getNetwork, network));
for (ServerInfo serverInfo : list) { for (ServerInfo serverInfo : list) {
serverIpList.add(serverInfo.getIp()); serverIpList.add(serverInfo.getIp());
...@@ -129,7 +129,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord ...@@ -129,7 +129,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
} }
@Override @Override
public Page<AppAbilityRecordVo> getRecordList(RecordDto recordDto) throws IOException { public Page<AppAbilityRecordVo> getRecordListByPage(RecordDto recordDto) throws IOException {
// 获取应用用户配置 // 获取应用用户配置
List<ConfigAbility> configAbilityList = configAbilityService.selectAll(); List<ConfigAbility> configAbilityList = configAbilityService.selectAll();
Map<String, ConfigAbility> abilityMap = configAbilityList.stream().collect(Collectors.toMap(ConfigAbility::getId, obj -> obj)); Map<String, ConfigAbility> abilityMap = configAbilityList.stream().collect(Collectors.toMap(ConfigAbility::getId, obj -> obj));
...@@ -146,7 +146,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord ...@@ -146,7 +146,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
redisService.set(RedisConstant.COURT_LIST, courtList, 1L, TimeUnit.DAYS); redisService.set(RedisConstant.COURT_LIST, courtList, 1L, TimeUnit.DAYS);
} }
Page<AppAbilityRecord> recordByPage = elasticSearchService.getRecordList(recordDto); Page<AppAbilityRecord> recordByPage = elasticSearchService.getRecordListByPage(recordDto);
ArrayList<AppAbilityRecordVo> recordVoList = new ArrayList<>(); ArrayList<AppAbilityRecordVo> recordVoList = new ArrayList<>();
recordByPage.getRecords().forEach(abilityRecord -> { recordByPage.getRecords().forEach(abilityRecord -> {
...@@ -155,7 +155,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord ...@@ -155,7 +155,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
recordVo.setIp(abilityRecord.getIp().split(",")[0]); recordVo.setIp(abilityRecord.getIp().split(",")[0]);
Optional<Court> first = courtList.stream().filter(court -> { Optional<Court> first = courtList.stream().filter(court -> {
String ipScope = court.getIpScope(); String ipScope = court.getIpScope();
String[] ipScopes = ipScope.split(";"); List<String> ipScopes = StrUtil.splitTrim(ipScope, ";");
for (String scope : ipScopes) { for (String scope : ipScopes) {
if (recordVo.getIp().startsWith(scope)) { if (recordVo.getIp().startsWith(scope)) {
return true; return true;
......
package com.gxmailu.ocrCloudPlatform.service.impl; package com.gxmailu.ocrCloudPlatform.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
...@@ -152,7 +153,7 @@ public class ElasticSearchService { ...@@ -152,7 +153,7 @@ public class ElasticSearchService {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(start.toString())) .gte(JsonData.of(start.toString()))
.lt(JsonData.of(end.toString())))); .lte(JsonData.of(end.toString()))));
// 法院ip前缀查询 // 法院ip前缀查询
if (ObjUtil.isNotNull(court) && StrUtil.isNotBlank(court.getIpScope())) { if (ObjUtil.isNotNull(court) && StrUtil.isNotBlank(court.getIpScope())) {
boolQuery.must(mustQuery -> mustQuery.prefix(pq -> pq.field("ip").value(court.getIpScope()))); boolQuery.must(mustQuery -> mustQuery.prefix(pq -> pq.field("ip").value(court.getIpScope())));
...@@ -240,7 +241,7 @@ public class ElasticSearchService { ...@@ -240,7 +241,7 @@ public class ElasticSearchService {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(startTime)) .gte(JsonData.of(startTime))
.lt(JsonData.of(endTime)) .lte(JsonData.of(endTime))
)); ));
return boolQuery; return boolQuery;
// 聚合查询,按每一分钟为间隔查询每分钟的调用量 // 聚合查询,按每一分钟为间隔查询每分钟的调用量
...@@ -294,17 +295,24 @@ public class ElasticSearchService { ...@@ -294,17 +295,24 @@ public class ElasticSearchService {
log.info("app_ability_record索引最后更新时间:{}", lastIndexTime); log.info("app_ability_record索引最后更新时间:{}", lastIndexTime);
} }
public Page<AppAbilityRecord> getRecordList(RecordDto recordDto) throws IOException { public Page<AppAbilityRecord> getRecordListByPage(RecordDto recordDto) throws IOException {
Integer network = recordDto.getNetwork(); // 内网或内网,-1:全部,0:内网,1:外网 Integer network = recordDto.getNetwork(); // 内网或内网,-1:全部,0:内网,1:外网
// 查询内外网机器的ip // 查询内外网机器的ip
List<ServerInfo> list = serverInfoMapper.selectList(Wrappers.lambdaQuery(ServerInfo.class) List<ServerInfo> list = serverInfoMapper.selectList(Wrappers.lambdaQuery(ServerInfo.class)
.eq(network != null && network != -1, ServerInfo::getNetwork, network)); .eq(network != null && network != -1, ServerInfo::getNetwork, network));
List<String> serverIpList = list.stream().map(ServerInfo::getIp).collect(Collectors.toList()); List<String> serverIpList = list.stream().map(ServerInfo::getIp).collect(Collectors.toList());
// 若未传入分页参数,则查询全部
if (ObjUtil.isNull(recordDto.getPage()) && ObjUtil.isNull(recordDto.getLimit())) {
recordDto.setPage(1);
recordDto.setLimit(10000);
}
// 限制查询数不超过10000,若超过随机查询一页 // 限制查询数不超过10000,若超过随机查询一页
recordDto.setLimit(ObjUtil.isNull(recordDto.getLimit()) ? 10 : recordDto.getLimit()); recordDto.setLimit(ObjUtil.isNull(recordDto.getLimit()) ? 10 : recordDto.getLimit());
int offset = (recordDto.getPage() - 1) * recordDto.getLimit() + recordDto.getLimit() > 10000 ? RandomUtil.randomInt(8000, 9000) : (recordDto.getPage() - 1) * recordDto.getLimit(); int offset = (recordDto.getPage() - 1) * recordDto.getLimit() + recordDto.getLimit() > 10000 ? RandomUtil.randomInt(100, 200) : (recordDto.getPage() - 1) * recordDto.getLimit();
int size = recordDto.getLimit(); int size = recordDto.getLimit();
System.out.println(recordDto);
SearchResponse<AppAbilityRecord> searchResponse = client.search(srBuilder -> srBuilder SearchResponse<AppAbilityRecord> searchResponse = client.search(srBuilder -> srBuilder
.index(APP_ABILITY_RECORD_INDEX) .index(APP_ABILITY_RECORD_INDEX)
.query(queryBuilder -> queryBuilder.bool(boolQuery -> { .query(queryBuilder -> queryBuilder.bool(boolQuery -> {
...@@ -315,7 +323,7 @@ public class ElasticSearchService { ...@@ -315,7 +323,7 @@ public class ElasticSearchService {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(startTime)) .gte(JsonData.of(startTime))
.lt(JsonData.of(endTime)))); .lte(JsonData.of(endTime))));
} }
if (CollUtil.isNotEmpty(serverIpList)) { if (CollUtil.isNotEmpty(serverIpList)) {
...@@ -343,10 +351,10 @@ public class ElasticSearchService { ...@@ -343,10 +351,10 @@ public class ElasticSearchService {
return bq; return bq;
})); }));
if (ObjUtil.isNotNull(recordDto.getApplicationId())) { if (StrUtil.isNotBlank(recordDto.getApplicationId())) {
boolQuery.must(mustQuery -> mustQuery.match(mq -> mq.field("applicationId").query(recordDto.getApplicationId()))); boolQuery.must(mustQuery -> mustQuery.match(mq -> mq.field("applicationId").query(recordDto.getApplicationId())));
} }
if (ObjUtil.isNotNull(recordDto.getAbilityId())) { if (StrUtil.isNotBlank(recordDto.getAbilityId())) {
boolQuery.must(mustQuery -> mustQuery.match(mq -> mq.field("abilityId").query(recordDto.getAbilityId()))); boolQuery.must(mustQuery -> mustQuery.match(mq -> mq.field("abilityId").query(recordDto.getAbilityId())));
} }
return boolQuery; return boolQuery;
...@@ -358,6 +366,60 @@ public class ElasticSearchService { ...@@ -358,6 +366,60 @@ public class ElasticSearchService {
return handlePageResultWithHighlight(searchResponse, AppAbilityRecord.class, recordDto); return handlePageResultWithHighlight(searchResponse, AppAbilityRecord.class, recordDto);
} }
public List<AppAbilityRecord> getRecords(RecordDto recordDto) throws IOException {
Integer network = recordDto.getNetwork(); // 内网或内网,-1:全部,0:内网,1:外网
// 查询内外网机器的ip
List<ServerInfo> list = serverInfoMapper.selectList(Wrappers.lambdaQuery(ServerInfo.class)
.eq(network != null && network != -1, ServerInfo::getNetwork, network));
List<String> serverIpList = list.stream().map(ServerInfo::getIp).collect(Collectors.toList());
SearchResponse<AppAbilityRecord> searchResponse = client.search(srBuilder -> srBuilder
.index(APP_ABILITY_RECORD_INDEX)
.query(queryBuilder -> queryBuilder.bool(boolQuery -> {
// 时间范围查询
if (ObjUtil.isNotNull(recordDto.getStartTime()) && ObjUtil.isNotNull(recordDto.getEndTime())) {
String startTime = DateUtil.beginOfDay(recordDto.getStartTime()).toString("yyyy-MM-dd HH:mm:ss");
String endTime = DateUtil.endOfDay(recordDto.getEndTime()).toString("yyyy-MM-dd HH:mm:ss");
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime")
.gte(JsonData.of(startTime))
.lte(JsonData.of(endTime))));
}
if (CollUtil.isNotEmpty(serverIpList)) {
List<FieldValue> collect = serverIpList.stream().map(FieldValue::of).collect(Collectors.toList());
boolQuery.filter(mustQuery -> mustQuery.terms(tq -> tq.field("serverIp").terms(tqf -> tqf.value(collect))));
}
boolQuery.must(mustQuery -> mustQuery.bool(bq -> {
// 多个ip前缀过滤
if (CollUtil.isNotEmpty(recordDto.getIpScopeList())) {
for (String ipScope : recordDto.getIpScopeList()) {
if (StrUtil.isNotBlank(ipScope)) {
bq.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ipScope)));
}
}
}
return bq;
}));
if (ObjUtil.isNotNull(recordDto.getApplicationId())) {
boolQuery.must(mustQuery -> mustQuery.match(mq -> mq.field("applicationId").query(recordDto.getApplicationId())));
}
if (ObjUtil.isNotNull(recordDto.getAbilityId())) {
boolQuery.must(mustQuery -> mustQuery.match(mq -> mq.field("abilityId").query(recordDto.getAbilityId())));
}
return boolQuery;
}))
.sort(s -> s.field(fs -> fs.field("callTime.keyword").order(SortOrder.Desc)))
.trackTotalHits(tb -> tb.enabled(true)), AppAbilityRecord.class);
List<AppAbilityRecord> records = new ArrayList<>();
searchResponse.hits().hits().forEach(hit -> {
AppAbilityRecord source = hit.source();
records.add(source);
});
return records;
}
public List<CallRecordModel> selectCallRecord(String yearMonthDay, String endYearMonthDay) throws IOException { public List<CallRecordModel> selectCallRecord(String yearMonthDay, String endYearMonthDay) throws IOException {
SearchResponse<Void> searchResponse = client.search(srBuilder -> srBuilder SearchResponse<Void> searchResponse = client.search(srBuilder -> srBuilder
.index(APP_ABILITY_RECORD_INDEX) .index(APP_ABILITY_RECORD_INDEX)
...@@ -365,18 +427,18 @@ public class ElasticSearchService { ...@@ -365,18 +427,18 @@ public class ElasticSearchService {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(yearMonthDay)) .gte(JsonData.of(yearMonthDay))
.lt(JsonData.of(endYearMonthDay)))); .lte(JsonData.of(endYearMonthDay))));
return boolQuery; return boolQuery;
})) }))
.size(0) .size(0)
// 添加聚合查询 // 添加聚合查询
.aggregations("ip_agg", ipAgg -> ipAgg.terms(ipTerm -> ipTerm.field("ip.keyword")) .aggregations("ip_agg", ipAgg -> ipAgg.terms(ipTerm -> ipTerm.field("ip.keyword").size(9999999))
.aggregations("applicationId_agg", applicationAgg -> applicationAgg.terms(applicationTerm -> applicationTerm.field("applicationId")) .aggregations("applicationId_agg", applicationAgg -> applicationAgg.terms(applicationTerm -> applicationTerm.field("applicationId").size(9999999))
.aggregations("ablilityId_agg", abilityAgg -> abilityAgg.terms(abilityTerm -> abilityTerm.field("abilityId")) .aggregations("ablilityId_agg", abilityAgg -> abilityAgg.terms(abilityTerm -> abilityTerm.field("abilityId").size(9999999))
.aggregations("fileCount", fileCountAgg -> fileCountAgg.sum(fileCountSum -> fileCountSum.field("fileCount")))))) .aggregations("fileCount", fileCountAgg -> fileCountAgg.sum(fileCountSum -> fileCountSum.field("fileCount"))))))
.trackTotalHits(tb -> tb.enabled(true)), Void.class); .trackTotalHits(tb -> tb.enabled(true)), Void.class);
ArrayList<CallRecordModel> recordModels = new ArrayList<>(); List<CallRecordModel> recordModels = new ArrayList<>();
List<Court> courtList = courtService.getCourtList(); List<Court> courtList = courtService.getCourtList();
List<ConfigAbility> abilityList = configAbilityService.selectAll(); List<ConfigAbility> abilityList = configAbilityService.selectAll();
...@@ -385,7 +447,7 @@ public class ElasticSearchService { ...@@ -385,7 +447,7 @@ public class ElasticSearchService {
searchResponse.aggregations().get("ip_agg").sterms().buckets().array().forEach(ipBucket -> { searchResponse.aggregations().get("ip_agg").sterms().buckets().array().forEach(ipBucket -> {
ipBucket.aggregations().get("applicationId_agg").lterms().buckets().array().forEach(applicationIdBucket -> { ipBucket.aggregations().get("applicationId_agg").lterms().buckets().array().forEach(applicationIdBucket -> {
applicationIdBucket.aggregations().get("ablilityId_agg").lterms().buckets().array().forEach(abilityIdBucket -> { applicationIdBucket.aggregations().get("ablilityId_agg").lterms().buckets().array().forEach(abilityIdBucket -> {
int fileCount = (int) abilityIdBucket.aggregations().get("fileCount").sum().value(); long fileCount = (long) abilityIdBucket.aggregations().get("fileCount").sum().value();
CallRecordModel recordModel = new CallRecordModel(); CallRecordModel recordModel = new CallRecordModel();
recordModel.setIp(ipBucket.key().stringValue()); recordModel.setIp(ipBucket.key().stringValue());
...@@ -415,10 +477,16 @@ public class ElasticSearchService { ...@@ -415,10 +477,16 @@ public class ElasticSearchService {
}); });
}); });
}); });
recordModels.sort(Comparator.comparing(CallRecordModel::getCourtName) List<CallRecordModel> mergeCallRecordList = mergeCallRecord(recordModels);
mergeCallRecordList.sort(Comparator.comparing(CallRecordModel::getCourtName)
.thenComparing(CallRecordModel::getBusinessVendorName) .thenComparing(CallRecordModel::getBusinessVendorName)
.thenComparing(CallRecordModel::getAbilityName).reversed()); .thenComparing(CallRecordModel::getAbilityName).reversed());
return recordModels; CallRecordModel callRecordModel = new CallRecordModel();
callRecordModel.setCourtName("总计");
callRecordModel.setAbilityDocCount(mergeCallRecordList.stream().mapToLong(CallRecordModel::getAbilityDocCount).sum());
callRecordModel.setFileCount(mergeCallRecordList.stream().mapToLong(CallRecordModel::getFileCount).sum());
mergeCallRecordList.add(callRecordModel);
return mergeCallRecordList;
} }
...@@ -433,8 +501,6 @@ public class ElasticSearchService { ...@@ -433,8 +501,6 @@ public class ElasticSearchService {
TotalHits totalHits = response.hits().total(); TotalHits totalHits = response.hits().total();
long total = ObjUtil.isNull(totalHits) ? 0 : totalHits.value(); long total = ObjUtil.isNull(totalHits) ? 0 : totalHits.value();
// 这是索引库中的总数
// total = total != 10000 ? total : client.count(req -> req.index(indexName)).count();
List<T> list = response.hits().hits().stream().map(hit -> { List<T> list = response.hits().hits().stream().map(hit -> {
// 对象转换 // 对象转换
T obj = objectMapper.convertValue(hit.source(), targetType); T obj = objectMapper.convertValue(hit.source(), targetType);
...@@ -468,6 +534,29 @@ public class ElasticSearchService { ...@@ -468,6 +534,29 @@ public class ElasticSearchService {
page.setSize(dto.getLimit()); page.setSize(dto.getLimit());
page.setCurrent(dto.getPage()); page.setCurrent(dto.getPage());
return page; return page;
// return PageVo.ofReqVo(vo, list, (int) total); }
public List<CallRecordModel> mergeCallRecord(List<CallRecordModel> callRecordModels) {
// 使用 Map 存储合并后的结果
Map<String, CallRecordModel> mergedMap = new HashMap<>();
// 遍历原始列表
for (CallRecordModel record : callRecordModels) {
// 生成合并的键,这里使用 courtName、businessVendorName、abilityName 拼接
StringBuilder key = new StringBuilder();
key.append(record.getCourtName()).append(record.getBusinessVendorName()).append(record.getAbilityName());
// 如果 Map 中已存在相同键的对象,则将属性累加
if (mergedMap.containsKey(key.toString())) {
CallRecordModel existingRecord = mergedMap.get(key.toString());
existingRecord.setAbilityDocCount(existingRecord.getAbilityDocCount() + record.getAbilityDocCount());
existingRecord.setFileCount(existingRecord.getFileCount() + record.getFileCount());
} else {
// 如果 Map 中不存在相同键的对象,则将当前对象添加到 Map
mergedMap.put(key.toString(), BeanUtil.copyProperties(record, CallRecordModel.class));
}
}
// 将 Map 中的值转回列表
return new ArrayList<>(mergedMap.values());
} }
} }
package com.gxmailu.ocrCloudPlatform.vo; package com.gxmailu.ocrCloudPlatform.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
...@@ -12,37 +13,50 @@ import java.util.Date; ...@@ -12,37 +13,50 @@ import java.util.Date;
@Data @Data
public class AppAbilityRecordVo { public class AppAbilityRecordVo {
@ExcelProperty(value = "编号", index = 0)
private String id; private String id;
/** /**
* 法院名称 * 法院名称
*/ */
@ExcelProperty(value = "法院名称", index = 1)
private String courtName; private String courtName;
/** /**
* 业务厂家 * 业务厂家
*/ */
@ExcelProperty(value = "业务厂家", index = 2)
private String businessVendors; private String businessVendors;
private String appAbilityName;
private String ip;
/** /**
* 文件页数 * 识别能力
*/ */
private Integer fileCount; @ExcelProperty(value = "识别能力", index = 3)
private String appAbilityName;
@ExcelProperty(value = "调用方IP", index = 4)
private String ip;
/** /**
* 调用次数 * 调用次数
*/ */
@ExcelProperty(value = "调用次数", index = 5)
private String callCount; private String callCount;
/** /**
* 文件页数
*/
@ExcelProperty(value = "文件页数", index = 6)
private Integer fileCount;
/**
* 调用时间 * 调用时间
*/ */
@ExcelProperty(value = "调用时间", index = 7)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date callTime; private Date callTime;
/** /**
* 调用服务器ip * 调用服务器ip
*/ */
@ExcelProperty(value = "服务器ip", index = 8)
private String serverIp; private String serverIp;
} }
...@@ -97,7 +97,7 @@ public class ESTest { ...@@ -97,7 +97,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(start.toString())) .gte(JsonData.of(start.toString()))
.lt(JsonData.of(end.toString())))); .lte(JsonData.of(end.toString()))));
if (ObjUtil.isNotNull(court) && StrUtil.isNotBlank(court.getIpScope())) { if (ObjUtil.isNotNull(court) && StrUtil.isNotBlank(court.getIpScope())) {
boolQuery.must(mustQuery -> mustQuery.prefix(pq -> pq.field("ip").value(court.getIpScope()))); boolQuery.must(mustQuery -> mustQuery.prefix(pq -> pq.field("ip").value(court.getIpScope())));
} }
...@@ -210,7 +210,7 @@ public class ESTest { ...@@ -210,7 +210,7 @@ public class ESTest {
// recordDto.setApplicationId(5L); // recordDto.setApplicationId(5L);
// recordDto.setStartTime(DateUtil.parseDate("2023-05-11")); // recordDto.setStartTime(DateUtil.parseDate("2023-05-11"));
// recordDto.setEndTime(DateUtil.parseDate("2023-05-11")); // recordDto.setEndTime(DateUtil.parseDate("2023-05-11"));
Page<AppAbilityRecord> recordList = elasticSearchService.getRecordList(recordDto); Page<AppAbilityRecord> recordList = elasticSearchService.getRecordListByPage(recordDto);
recordList.getRecords().forEach(System.out::println); recordList.getRecords().forEach(System.out::println);
// Object recordList1 = appAbilityRecordAllService.getRecordList(recordDto); // Object recordList1 = appAbilityRecordAllService.getRecordList(recordDto);
...@@ -284,7 +284,6 @@ public class ESTest { ...@@ -284,7 +284,6 @@ public class ESTest {
List<BrokenLineData> brokenLineData = null; List<BrokenLineData> brokenLineData = null;
// 创建一个公共方法获取数据
String finalDate = date; String finalDate = date;
Supplier<List<BrokenLineData>> fetchData = () -> { Supplier<List<BrokenLineData>> fetchData = () -> {
List<BrokenLineData> data = recordAllMapper.selectBrokenLineData(finalDate); List<BrokenLineData> data = recordAllMapper.selectBrokenLineData(finalDate);
...@@ -293,7 +292,7 @@ public class ESTest { ...@@ -293,7 +292,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(DateUtil.beginOfDay(nowDateTime).toString())) .gte(JsonData.of(DateUtil.beginOfDay(nowDateTime).toString()))
.lt(JsonData.of(DateUtil.endOfDay(nowDateTime).toString())))); .lte(JsonData.of(DateUtil.endOfDay(nowDateTime).toString()))));
return boolQuery; return boolQuery;
})).aggregations("count", agg -> agg.dateHistogram(DateHistogramAggregation.of(s -> s.field("callTime") })).aggregations("count", agg -> agg.dateHistogram(DateHistogramAggregation.of(s -> s.field("callTime")
.calendarInterval(CalendarInterval.Minute)))).trackTotalHits(tb -> tb.enabled(true)), Void.class); .calendarInterval(CalendarInterval.Minute)))).trackTotalHits(tb -> tb.enabled(true)), Void.class);
...@@ -333,7 +332,7 @@ public class ESTest { ...@@ -333,7 +332,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(DateUtil.beginOfDay(nowDateTime).toString())) .gte(JsonData.of(DateUtil.beginOfDay(nowDateTime).toString()))
.lt(JsonData.of(DateUtil.endOfDay(nowDateTime).toString())))); .lte(JsonData.of(DateUtil.endOfDay(nowDateTime).toString()))));
return boolQuery; return boolQuery;
})).aggregations("record", agg -> agg.dateHistogram(DateHistogramAggregation.of(s -> s.field("callTime") })).aggregations("record", agg -> agg.dateHistogram(DateHistogramAggregation.of(s -> s.field("callTime")
.calendarInterval(CalendarInterval.Minute)))).trackTotalHits(tb -> tb.enabled(true)), Void.class); .calendarInterval(CalendarInterval.Minute)))).trackTotalHits(tb -> tb.enabled(true)), Void.class);
...@@ -369,7 +368,7 @@ public class ESTest { ...@@ -369,7 +368,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
.gte(JsonData.of(start)) .gte(JsonData.of(start))
.lt(JsonData.of(end)))); .lte(JsonData.of(end))));
return boolQuery; return boolQuery;
})) }))
.size(0) .size(0)
...@@ -389,7 +388,7 @@ public class ESTest { ...@@ -389,7 +388,7 @@ public class ESTest {
searchResponse.aggregations().get("ip_agg").sterms().buckets().array().forEach(ipBucket -> { searchResponse.aggregations().get("ip_agg").sterms().buckets().array().forEach(ipBucket -> {
ipBucket.aggregations().get("applicationId_agg").lterms().buckets().array().forEach(applicationIdBucket -> { ipBucket.aggregations().get("applicationId_agg").lterms().buckets().array().forEach(applicationIdBucket -> {
applicationIdBucket.aggregations().get("ablilityId_agg").lterms().buckets().array().forEach(abilityIdBucket -> { applicationIdBucket.aggregations().get("ablilityId_agg").lterms().buckets().array().forEach(abilityIdBucket -> {
int fileCount = (int) abilityIdBucket.aggregations().get("fileCount").sum().value(); long fileCount = (long) abilityIdBucket.aggregations().get("fileCount").sum().value();
CallRecordModel recordModel = new CallRecordModel(); CallRecordModel recordModel = new CallRecordModel();
recordModel.setIp(ipBucket.key().stringValue()); recordModel.setIp(ipBucket.key().stringValue());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment