Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface HeraAppService {

List<AppBaseInfo> queryAppInfoWithLog(String appName, Integer type);

List<AppBaseInfo> queryAppInfoWithLogLatest(String appName, Integer type, Integer count);

List<AppBaseInfo> queryAllExistsApp();

AppBaseInfo queryById(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public List<AppBaseInfo> queryAppInfoWithLog(String appName, Integer type) {
return heraAppService.queryAppInfoWithLog(appName, type);
}

@GetMapping("query/app/log/latest")
public List<AppBaseInfo> queryAppInfoWithLog(String appName, Integer type, Integer limit) {
return heraAppService.queryAppInfoWithLogLatest(appName, type, limit);
}

@PostMapping("/hera/app/add")
public Result heraAppAdd(@RequestBody HeraAppBaseInfo heraAppBaseInfo) {
if (StringUtils.isBlank(heraAppBaseInfo.getBindId()) || StringUtils.isBlank(heraAppBaseInfo.getAppName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ public List<AppBaseInfo> queryAppInfoWithLog(String appName, Integer type) {
return appBaseInfos;
}

@Override
public List<AppBaseInfo> queryAppInfoWithLogLatest(String appName, Integer type, Integer count){
Integer platformType = null;
Integer appType = null;
if (Objects.nonNull(type)) {
appType = appTypeServiceExtension.getAppTypeLog(type);
platformType = appTypeServiceExtension.getAppPlatForm(type);
}
List<AppBaseInfo> appBaseInfos;
if(appName != null && appName.isBlank()){
appBaseInfos = heraAppBaseInfoMapper.queryAppInfo(appName, platformType, appType);
}else{
appBaseInfos = heraAppBaseInfoMapper.queryLatestAppInfo(count, platformType, appType);
}

if (CollectionUtils.isNotEmpty(appBaseInfos)) {
appBaseInfos = appBaseInfos.parallelStream().map(appBaseInfo -> {
appBaseInfo.setPlatformName(appTypeServiceExtension.getPlatformName(appBaseInfo.getPlatformType()));
appBaseInfo.setAppTypeName(appTypeServiceExtension.getAppTypeName(appBaseInfo.getAppType()));
return appBaseInfo;
}).collect(Collectors.toList());
}
return appBaseInfos;
}

@Override
public List<AppBaseInfo> querySpecifiedAppInfoWithLog(String appName, Integer limit, Integer type) {
List<AppBaseInfo> appBaseInfos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,19 +354,19 @@ public void downLogFileV2(Workbook excel, String fileName) throws IOException {
Down.down(fileName);
} catch (Exception e) {
log.error("downLogFile error,fileName:{}", fileName, e);
throw e;
} finally {
if (excel != null) {
excel.close();
if (excel instanceof SXSSFWorkbook sxssf) {
sxssf.dispose();
}
}
if (fos != null) {
fos.close();
try {
fos.close();
} catch (Exception e) {
log.error("Error closing FileOutputStream", e);
}
}
if (file != null) {
file.delete();
}
// Note: Workbook cleanup (close/dispose) is handled by the caller
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface HeraAppService {

List<AppBaseInfo> queryAppInfoWithLog(String appName, Integer type);

List<AppBaseInfo> queryAppInfoWithLogLatest(String appName, Integer type, Integer limit);

List<AppBaseInfo> queryAllExistsApp();

AppBaseInfo queryById(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,87 +750,100 @@ public void logExport(LogQuery logQuery) throws Exception {
final int rowsPerSheet = 5000; //each sheet is fixed at 5000 rows
final int maxPage = 100; //max pages, the upper limit of the number of rows: 5000*100
int page = 1;
Workbook workbook = new SXSSFWorkbook();
String title = generateTitle(logQuery);
List<String> headers = null;
Object[] lastSortValues = null;
logQuery.setIsDownload(true);
while(page <= maxPage) {
logQuery.setPageSize(rowsPerSheet);
logQuery.setPage(page);
//Prevent errors when performing deep paging in the ES database
logQuery.setSearchAfter(lastSortValues);

Result<LogDTO> logDTOResult = this.logQuery(logQuery);
if (logDTOResult.getCode() != CommonError.Success.getCode() || logDTOResult.getData() == null || logDTOResult.getData().getLogDataDTOList() == null || logDTOResult.getData().getLogDataDTOList().isEmpty()) {
break;
}
List<Map<String, Object>> list = logDTOResult.getData().getLogDataDTOList().stream().map(logDataDto -> ExportUtils.SplitTooLongContent(logDataDto)).collect(Collectors.toList());

if (list == null || list.isEmpty()) {
break;
}
SXSSFWorkbook workbook = new SXSSFWorkbook();
try {
String title = generateTitle(logQuery);
List<String> headers = null;
Object[] lastSortValues = null;
logQuery.setIsDownload(true);
while (page <= maxPage) {
logQuery.setPageSize(rowsPerSheet);
logQuery.setPage(page);
//Prevent errors when performing deep paging in the ES database
logQuery.setSearchAfter(lastSortValues);

Result<LogDTO> logDTOResult = this.logQuery(logQuery);
if (logDTOResult.getCode() != CommonError.Success.getCode() || logDTOResult.getData() == null || logDTOResult.getData().getLogDataDTOList() == null || logDTOResult.getData().getLogDataDTOList().isEmpty()) {
break;
}
List<Map<String, Object>> list = logDTOResult.getData().getLogDataDTOList().stream().map(logDataDto -> ExportUtils.SplitTooLongContent(logDataDto)).collect(Collectors.toList());

if (page == 1){
headers = new ArrayList<>(list.getFirst().keySet());
}
if (list == null || list.isEmpty()) {
break;
}

//If the table header is empty, then obtain the header from the current page.
if (headers == null || headers.isEmpty()) {
headers = new ArrayList<>(list.getFirst().keySet());
}
if (page == 1) {
headers = new ArrayList<>(list.getFirst().keySet());
}

Sheet sheet = workbook.createSheet("Sheet" + page);
int dataBeginRow;

if (title != null && !title.isEmpty() && page == 1) { //only the first sheet has a title
Row titleRow = sheet.createRow(0);
Cell cell = titleRow.createCell(0);
cell.setCellValue(title);
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment((short)2);
titleStyle.setVerticalAlignment((short)1);
Font titleFont = workbook.createFont();
titleFont.setBoldweight((short)700);
titleStyle.setFont(titleFont);
cell.setCellStyle(titleStyle);
titleRow.setHeight((short)450);
dataBeginRow = list != null && !list.isEmpty() ? ((Map)list.get(0)).size() - 1 : 5;
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, dataBeginRow));
}
//If the table header is empty, then obtain the header from the current page.
if (headers == null || headers.isEmpty()) {
headers = new ArrayList<>(list.getFirst().keySet());
}

if (list != null && !list.isEmpty()) {
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.setAlignment((short)2);
headerStyle.setBorderBottom((short)2);
headerStyle.setBorderTop((short)2);
int headRowIndex = title != null && !title.isEmpty() && page == 1 ? 1 : 0;
Row headRow = sheet.createRow(headRowIndex);
int i = 0;
for (String h : headers){
Cell cell = headRow.createCell(i++);
cell.setCellValue(h);
cell.setCellStyle(headerStyle);
Sheet sheet = workbook.createSheet("Sheet" + page);
int dataBeginRow;

if (title != null && !title.isEmpty() && page == 1) { //only the first sheet has a title
Row titleRow = sheet.createRow(0);
Cell cell = titleRow.createCell(0);
cell.setCellValue(title);
CellStyle titleStyle = workbook.createCellStyle();
titleStyle.setAlignment((short) 2);
titleStyle.setVerticalAlignment((short) 1);
Font titleFont = workbook.createFont();
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
cell.setCellStyle(titleStyle);
titleRow.setHeight((short) 450);
dataBeginRow = list != null && !list.isEmpty() ? ((Map) list.get(0)).size() - 1 : 5;
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, dataBeginRow));
}

dataBeginRow = title != null && !title.isEmpty() && page == 1 ? 2 : 1;
if (list != null && !list.isEmpty()) {
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.setAlignment((short) 2);
headerStyle.setBorderBottom((short) 2);
headerStyle.setBorderTop((short) 2);
int headRowIndex = title != null && !title.isEmpty() && page == 1 ? 1 : 0;
Row headRow = sheet.createRow(headRowIndex);
int i = 0;
for (String h : headers) {
Cell cell = headRow.createCell(i++);
cell.setCellValue(h);
cell.setCellStyle(headerStyle);
}

for(int j = 0; j < list.size(); ++j) {
Row row = sheet.createRow(dataBeginRow++);
Map<String, Object> rowMap = list.get(j);
for (int k = 0; k < headers.size(); k++){
Cell cell = row.createCell(k);
Object val = rowMap.get(headers.get(k));
cell.setCellValue(val == null ? "" : val.toString());
dataBeginRow = title != null && !title.isEmpty() && page == 1 ? 2 : 1;

for (int j = 0; j < list.size(); ++j) {
Row row = sheet.createRow(dataBeginRow++);
Map<String, Object> rowMap = list.get(j);
for (int k = 0; k < headers.size(); k++) {
Cell cell = row.createCell(k);
Object val = rowMap.get(headers.get(k));
cell.setCellValue(val == null ? "" : val.toString());
}
}
}
lastSortValues = logDTOResult.getData().getThisSortValue();
page++;
}
// Download
String fileName = String.format("%s_log.xlsx", logQuery.getLogstore());
searchLog.downLogFileV2(workbook, fileName);
} finally {
// Ensure temporary files are cleaned up even if an exception occurs
if (workbook != null) {
try {
workbook.close();
} catch (Exception e) {
log.error("Error closing workbook", e);
} finally {
workbook.dispose();
}
}
lastSortValues = logDTOResult.getData().getThisSortValue();
page++;
}
// Download
String fileName = String.format("%s_log.xlsx", logQuery.getLogstore());
searchLog.downLogFileV2(workbook, fileName);
}

private String generateTitle(LogQuery logQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public List<AppBaseInfo> queryAppInfoWithLog(String appName, Integer type) {
return heraAppService.queryAppInfoWithLog(appName, type);
}

@Override
public List<AppBaseInfo> queryAppInfoWithLogLatest(String appName, Integer type, Integer limit){
return heraAppService.queryAppInfoWithLogLatest(appName, type, limit);
}

@Override
public List<AppBaseInfo> querySpecifiedAppInfoWithLog(String appName, Integer limit, Integer type) {
return heraAppService.querySpecifiedAppInfoWithLog(appName, limit, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.List;

@Slf4j
@Service(interfaceClass = LogAgentApiService.class, group = "$dubbo.group", timeout = 10000)
@Service(interfaceClass = LogAgentApiService.class, group = "$dubbo.api.group", timeout = 10000)
public class LogAgentApiServiceImpl implements LogAgentApiService {

@Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ miline_rocketmq_consumer_group=${miline_rocketmq_consumer_group}
#dubbo
dubbo_app_name=${dubbo_app_name}
dubbo.group=${dubbo.group}
dubbo.api.group=${dubbo.api.group}
dubbo.env.group=${dubbo.env.group}
dubbo_reg_check=${dubbo_reg_check}
dubbo_reg_address=${dubbo_reg_address}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ app.env=test
#dubbo
dubbo_app_name=milog
dubbo.group=
dubbo.api.group=open
dubbo.env.group=open
dubbo_reg_check=false
dubbo_reg_address=nacos://nacos:80
Expand Down
Loading