Commit 6b054a24 by 黄明步

页数数值×3,显示调用表格数据

parent 6cec22f8
......@@ -8,6 +8,7 @@ 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.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxmailu.ocrCloudPlatform.dto.RecordDto;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
......@@ -127,6 +128,63 @@ public class AppAbilityRecordAllController {
}
/**
* 显示调用记录表格
*
* @param yearMonthDay 年月日
*/
@GetMapping("/showCallRecord")
@ApiOperation(value = "显示调用记录表格")
public Object showCallRecord(String yearMonthDay, String endYearMonthDay) {
if (StrUtil.isNotBlank(yearMonthDay)) {
int count = yearMonthDay.split("-").length;
switch (count) {
case 1:
DateTime year = DateUtil.parse(yearMonthDay, "yyyy");
yearMonthDay = DateUtil.beginOfYear(year).toString();
endYearMonthDay = DateUtil.endOfYear(year).toString();
break;
case 2:
DateTime yearMonth = DateUtil.parse(yearMonthDay, "yyyy-MM");
yearMonthDay = DateUtil.beginOfMonth(yearMonth).toString();
endYearMonthDay = DateUtil.endOfMonth(yearMonth).toString();
break;
case 3:
DateTime yearMonthDayDateTime = DateUtil.parse(yearMonthDay, "yyyy-MM-dd");
yearMonthDay = DateUtil.beginOfDay(yearMonthDayDateTime).toString();
endYearMonthDay = DateUtil.endOfDay(yearMonthDayDateTime).toString();
break;
}
} 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 {
List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay);
Assert.notNull(callRecordList, "未找到相关数据");
JSONObject jsonObject = new JSONObject();
jsonObject.put("data", callRecordList);
jsonObject.put("code", 0);
jsonObject.put("msg", "查询成功");
// JSONObject countObj = new JSONObject();
// countObj.put("abilityDocCount", 111111);
// jsonObject.put("fileCount", 222222);
// jsonObject.put("totalRow", countObj);
return jsonObject;
} catch (Exception e) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", -1);
jsonObject.put("msg", "查询异常,请联系管理员");
return jsonObject;
}
}
@PostMapping("/addRecord")
public Result addRecord(AppAbilityRecordAll recordAll) {
Assert.notNull(recordAll, "参数不能为空");
......
......@@ -171,10 +171,10 @@ public class ElasticSearchService {
}
return boolQuery;
}))
// 总命中数,与hits.size()不同的是trackTotalHits不会限制10000
.aggregations("fileCount", fileCountAgg -> fileCountAgg.sum(fileCountSum -> fileCountSum.field("fileCount")))
.trackTotalHits(tb -> tb.enabled(true)), Void.class);
TotalHits totalHits = searchResponse.hits().total();
object.set("count", ObjUtil.isNull(totalHits) ? 0 : totalHits.value());
int fileCount = (int) searchResponse.aggregations().get("fileCount").sum().value();
object.set("count", fileCount * 3);
} catch (Exception e) {
log.error("从ES中查询[{}-{}]调用量发生异常!", start.toString(), end.toString(), e);
}
......@@ -206,7 +206,9 @@ public class ElasticSearchService {
}
return boolQuery;
// 对ip进行聚合查询
})).aggregations("count", agg -> agg.terms(TermsAggregation.of(s -> s.field("ip.keyword")))).trackTotalHits(tb -> tb.enabled(true)), Void.class);
})).aggregations("count", agg -> agg.terms(TermsAggregation.of(s -> s.field("ip.keyword")))
.aggregations("fileCount", fileCountAgg -> fileCountAgg.sum(fileCountSum -> fileCountSum.field("fileCount"))))
.trackTotalHits(tb -> tb.enabled(true)), Void.class);
StringTermsAggregate stringTermsAggregate = searchResponse.aggregations()
.get("count")
......@@ -215,6 +217,7 @@ public class ElasticSearchService {
Map<String, JSONObject> resultMap = new HashMap<>();
Buckets<StringTermsBucket> buckets = stringTermsAggregate.buckets();
buckets.array().forEach(bucket -> {
int fileCount = (int) bucket.aggregations().get("fileCount").sum().value() * 3;
for (Court court : courtList) {
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-");
try {
......@@ -224,13 +227,15 @@ public class ElasticSearchService {
// 若此 IP 范围已存在,则取出并更新 sum
if (resultMap.containsKey(ip)) {
JSONObject existingObject = resultMap.get(ip);
existingObject.set("sum", existingObject.getInt("sum") + bucket.docCount());
// existingObject.set("sum", existingObject.getInt("sum") + bucket.docCount());
existingObject.set("sum", existingObject.getInt("sum") + fileCount);
} else {
// 否则,创建新的 JSONObject 并加入 resultMap
JSONObject object = new JSONObject();
object.set("name", court.getName());
object.set("sortName", court.getForSort());
object.set("sum", bucket.docCount());
// object.set("sum", bucket.docCount());
object.set("sum", fileCount);
resultMap.put(ip, object);
}
}
......@@ -425,7 +430,7 @@ public class ElasticSearchService {
recordModel.setUserDocCount(applicationIdBucket.docCount());
recordModel.setAbilityId(abilityIdBucket.key());
recordModel.setAbilityDocCount(abilityIdBucket.docCount());
recordModel.setFileCount(fileCount);
recordModel.setFileCount(fileCount * 3);
recordModel.setCourtName(courtList.parallelStream()
......
......@@ -208,7 +208,7 @@ public class StatService {
String time = StrUtil.isBlank(recordBucket.keyAsString()) ? "" : recordBucket.keyAsString();
brokenLineData.setTime(time);
long value = (long) recordBucket.aggregations().get("fileCount").sum().value();
brokenLineData.setValue(value);
brokenLineData.setValue(value * 3);
resultList.add(brokenLineData);
});
......
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