Commit 143a56a0 by 黄明步

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

parent b1c592cb
......@@ -8,12 +8,14 @@ import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxmailu.ocrCloudPlatform.dto.RecordDto;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.excel.handler.ExcelFillCellMergeStrategy;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils;
import com.gxmailu.ocrCloudPlatform.service.AppAbilityRecordAllService;
import com.gxmailu.ocrCloudPlatform.vo.AppAbilityRecordVo;
import com.gxmailu.ocrCloudPlatform.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -22,7 +24,9 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
......@@ -45,14 +49,14 @@ public class AppAbilityRecordAllController {
/**
* 导出应用调用记录
*
* @param yearMonthDay 年月日calendar
* @param yearMonthDay 年月日
*/
@RequestMapping("/deriveCallRecord")
@ResponseBody
public void deriveCallRecord(String yearMonthDay, String endYearMonthDay, HttpServletResponse response) {
//设置到新的对象上,用以下面的文件名称处理
// 设置到新的对象上,用以下面的文件名称处理
String newYearMonthDay = yearMonthDay;
if(StrUtil.isNotBlank(yearMonthDay)){
if (StrUtil.isNotBlank(yearMonthDay)) {
int count = yearMonthDay.split("-").length;
switch (count) {
case 1:
......@@ -73,23 +77,24 @@ public class AppAbilityRecordAllController {
break;
}
System.out.println("yearMonthDay==========" + yearMonthDay + ";endYearMonthDay==========" + endYearMonthDay);
} else {
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();
}
try{
System.out.println("yearMonthDay==========" + yearMonthDay + ";endYearMonthDay==========" + endYearMonthDay);
try {
List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay);
Assert.notNull(callRecordList, "未找到相关数据");
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.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
// 设置单元格样式策略
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(ExcelStyleUtils.getHeadStyle(), ExcelStyleUtils.getContentStyle());
EasyExcel.write(response.getOutputStream(), CallRecordModel.class)
.sheet("导出数据")
.sheet(StrUtil.isBlank(newYearMonthDay) ? "ALL" : newYearMonthDay)
.head(CallRecordModel.class)
// 自动行宽策略
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
......@@ -98,7 +103,7 @@ public class AppAbilityRecordAllController {
// 设置单元格样式
.registerWriteHandler(horizontalCellStyleStrategy)
.doWrite(callRecordList);
} catch (Exception e){
} catch (Exception e) {
log.error("导出异常", e);
// 重置response
response.reset();
......@@ -106,7 +111,7 @@ public class AppAbilityRecordAllController {
response.setCharacterEncoding("utf-8");
Map<String, String> map = MapUtils.newHashMap();
map.put("status", "500");
map.put("message", "数据过大,导出文件失败");
map.put("message", "由于导出数据量过大,导致无法导出。请移步详见后台管理-应用能力调用记录");
try {
response.getWriter().println(JSON.toJSONString(map));
} catch (IOException ex) {
......@@ -128,20 +133,62 @@ public class AppAbilityRecordAllController {
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")
public Result getListByPage(@RequestBody RecordDto recordDto) {
Assert.notNull(recordDto, "参数不能为空");
try {
return Result.success("", recordAllService.getRecordList(recordDto));
return Result.success("", recordAllService.getRecordListByPage(recordDto));
} catch (IOException e) {
log.error("调用记录查询异常", e);
return Result.error("查询异常,请联系管理员");
}
}
@PostMapping("/getById")
public Object getById(Long id) {
Assert.notNull(id, "参数不能为空");
return Result.success("",recordAllService.getById(id));
return Result.success("", recordAllService.getById(id));
}
......@@ -151,27 +198,27 @@ public class AppAbilityRecordAllController {
}
@GetMapping("/getCourtUseInYear")
public Object getCourtUseInYear(@RequestParam Integer year,@RequestParam String courtName) {
return recordAllService.getCourtUseInYear(year,courtName);
public Object getCourtUseInYear(@RequestParam Integer year, @RequestParam String courtName) {
return recordAllService.getCourtUseInYear(year, courtName);
}
@GetMapping("/getCourtUseInMonth")
public Object getCourtUseInMonth(Integer year, Integer month,String courtName) {
return recordAllService.getCourtUseInMonth(year, month,courtName);
public Object getCourtUseInMonth(Integer year, Integer month, String courtName) {
return recordAllService.getCourtUseInMonth(year, month, courtName);
}
@GetMapping("/getCourtUseInDay")
public Object getCourtUseInDay(Integer year, Integer month, Integer day,String courtName) {
return recordAllService.getCourtUseInDay(year, month, day,courtName);
public Object getCourtUseInDay(Integer year, Integer month, Integer day, String courtName) {
return recordAllService.getCourtUseInDay(year, month, day, courtName);
}
@GetMapping("getCorrelationData")
public Result getCorrelationDate(String day1,String day2){
return recordAllService.getCorrelationData(day1,day2);
public Result getCorrelationDate(String day1, String day2) {
return recordAllService.getCorrelationData(day1, day2);
}
@GetMapping("getBrokenLineData")
public Result getBrokenLineData(String date){
public Result getBrokenLineData(String date) {
return recordAllService.getBrokenLineData(date);
}
......
......@@ -15,7 +15,7 @@ public class RecordDto implements Serializable {
private static final long serialVersionUID = 1L;
private Integer courtId;
private Integer courtCode;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date startTime;
......@@ -25,6 +25,7 @@ public class RecordDto implements Serializable {
private Date endTime;
private String applicationId;
private String abilityId;
private String ipScope;
private List<String> ipScopeList;
private Integer page;
private Integer limit;
......
......@@ -2,6 +2,7 @@ package com.gxmailu.ocrCloudPlatform.excel.model;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
......@@ -29,7 +30,7 @@ public class CallRecordModel implements Serializable {
@ExcelIgnore
@ExcelProperty(value = "总调用次数")
private Integer callCount;
private Long callCount;
@ExcelIgnore
@ExcelProperty(value = "用户调用次数")
......@@ -42,7 +43,7 @@ public class CallRecordModel implements Serializable {
@ExcelProperty(value = "识别能力", index = 2)
private String abilityName;
@ExcelProperty(value = "调用次数", index = 3)
private long abilityDocCount;
private Long abilityDocCount;
@ExcelProperty(value = "总识别页数", index = 4)
private Integer fileCount;
private Long fileCount;
}
package com.gxmailu.ocrCloudPlatform.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxmailu.ocrCloudPlatform.dto.RecordDto;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.entity.DeriveCallRecord;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.vo.AppAbilityRecordVo;
import com.gxmailu.ocrCloudPlatform.vo.Result;
import java.io.IOException;
......@@ -39,5 +41,5 @@ public interface AppAbilityRecordAllService extends IService<AppAbilityRecordAll
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
@Override
public Object getList(RecordDto recordDto) {
List<String> serverIpList = new ArrayList<>();
Integer courtId = recordDto.getCourtId();
Integer courtCode = recordDto.getCourtCode();
Integer network = recordDto.getNetwork();
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));
for (ServerInfo serverInfo : list) {
serverIpList.add(serverInfo.getIp());
......@@ -129,7 +129,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
}
@Override
public Page<AppAbilityRecordVo> getRecordList(RecordDto recordDto) throws IOException {
public Page<AppAbilityRecordVo> getRecordListByPage(RecordDto recordDto) throws IOException {
// 获取应用用户配置
List<ConfigAbility> configAbilityList = configAbilityService.selectAll();
Map<String, ConfigAbility> abilityMap = configAbilityList.stream().collect(Collectors.toMap(ConfigAbility::getId, obj -> obj));
......@@ -146,7 +146,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
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<>();
recordByPage.getRecords().forEach(abilityRecord -> {
......@@ -155,7 +155,7 @@ public class AppAbilityRecordAllServiceImpl extends ServiceImpl<AppAbilityRecord
recordVo.setIp(abilityRecord.getIp().split(",")[0]);
Optional<Court> first = courtList.stream().filter(court -> {
String ipScope = court.getIpScope();
String[] ipScopes = ipScope.split(";");
List<String> ipScopes = StrUtil.splitTrim(ipScope, ";");
for (String scope : ipScopes) {
if (recordVo.getIp().startsWith(scope)) {
return true;
......
package com.gxmailu.ocrCloudPlatform.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
......@@ -12,37 +13,50 @@ import java.util.Date;
@Data
public class AppAbilityRecordVo {
@ExcelProperty(value = "编号", index = 0)
private String id;
/**
* 法院名称
*/
@ExcelProperty(value = "法院名称", index = 1)
private String courtName;
/**
* 业务厂家
*/
@ExcelProperty(value = "业务厂家", index = 2)
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;
/**
* 文件页数
*/
@ExcelProperty(value = "文件页数", index = 6)
private Integer fileCount;
/**
* 调用时间
*/
@ExcelProperty(value = "调用时间", index = 7)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date callTime;
/**
* 调用服务器ip
*/
@ExcelProperty(value = "服务器ip", index = 8)
private String serverIp;
}
......@@ -97,7 +97,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime")
.gte(JsonData.of(start.toString()))
.lt(JsonData.of(end.toString()))));
.lte(JsonData.of(end.toString()))));
if (ObjUtil.isNotNull(court) && StrUtil.isNotBlank(court.getIpScope())) {
boolQuery.must(mustQuery -> mustQuery.prefix(pq -> pq.field("ip").value(court.getIpScope())));
}
......@@ -210,7 +210,7 @@ public class ESTest {
// recordDto.setApplicationId(5L);
// recordDto.setStartTime(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);
// Object recordList1 = appAbilityRecordAllService.getRecordList(recordDto);
......@@ -284,7 +284,6 @@ public class ESTest {
List<BrokenLineData> brokenLineData = null;
// 创建一个公共方法获取数据
String finalDate = date;
Supplier<List<BrokenLineData>> fetchData = () -> {
List<BrokenLineData> data = recordAllMapper.selectBrokenLineData(finalDate);
......@@ -293,7 +292,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime")
.gte(JsonData.of(DateUtil.beginOfDay(nowDateTime).toString()))
.lt(JsonData.of(DateUtil.endOfDay(nowDateTime).toString()))));
.lte(JsonData.of(DateUtil.endOfDay(nowDateTime).toString()))));
return boolQuery;
})).aggregations("count", agg -> agg.dateHistogram(DateHistogramAggregation.of(s -> s.field("callTime")
.calendarInterval(CalendarInterval.Minute)))).trackTotalHits(tb -> tb.enabled(true)), Void.class);
......@@ -333,7 +332,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime")
.gte(JsonData.of(DateUtil.beginOfDay(nowDateTime).toString()))
.lt(JsonData.of(DateUtil.endOfDay(nowDateTime).toString()))));
.lte(JsonData.of(DateUtil.endOfDay(nowDateTime).toString()))));
return boolQuery;
})).aggregations("record", agg -> agg.dateHistogram(DateHistogramAggregation.of(s -> s.field("callTime")
.calendarInterval(CalendarInterval.Minute)))).trackTotalHits(tb -> tb.enabled(true)), Void.class);
......@@ -369,7 +368,7 @@ public class ESTest {
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime")
.gte(JsonData.of(start))
.lt(JsonData.of(end))));
.lte(JsonData.of(end))));
return boolQuery;
}))
.size(0)
......@@ -389,7 +388,7 @@ public class ESTest {
searchResponse.aggregations().get("ip_agg").sterms().buckets().array().forEach(ipBucket -> {
ipBucket.aggregations().get("applicationId_agg").lterms().buckets().array().forEach(applicationIdBucket -> {
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();
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