0605 ljc 报告模块修改
This commit is contained in:
parent
2172342c6b
commit
b346c8f42e
@ -54,9 +54,9 @@ public class ReportController {
|
||||
|
||||
|
||||
@PostMapping(path="/downLoadReport")
|
||||
public CommonResult<ResponseEntity<byte[]>> downLoadReport(@RequestBody @NotNull @Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
public CommonResult<ResponseEntity<String>> downLoadReport(@RequestBody @NotNull @Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
|
||||
ResponseEntity<byte[]> fileInputStream = reportService.downLoadReport(req);
|
||||
ResponseEntity<String> fileInputStream = reportService.downLoadReport(req);
|
||||
|
||||
return CommonResult.success(fileInputStream);
|
||||
}
|
||||
|
@ -88,13 +88,16 @@ public class ScaBinaryWorker extends HttpWorker {
|
||||
|
||||
|
||||
File file = new File(filePath);
|
||||
if (!file.exists() || !file.canRead()) {
|
||||
log.error("目标文件不存在或不可读");
|
||||
localVariables.put("statusCode", "-1");
|
||||
append(context,"目标文件不存在或不可读");
|
||||
if (!file.exists()) {
|
||||
log.error("文件不存在: {}", file.getAbsolutePath());
|
||||
append(context, "文件不存在: " + file.getAbsolutePath());
|
||||
} else if (!file.canRead()) {
|
||||
log.error("文件存在但不可读: {}", file.getAbsolutePath());
|
||||
append(context, "文件存在但不可读: " + file.getAbsolutePath());
|
||||
} else {
|
||||
// 正常处理文件上传
|
||||
handleUpload(pipTask.getTaskProperties(), file, context);
|
||||
}
|
||||
|
||||
handleUpload(pipTask.getTaskProperties(), file,context);
|
||||
}catch (Exception e){
|
||||
append(context,"==================SCA-BINARY节点执行失败=================");
|
||||
append(context,"SCA-BINARY节点执行失败失败,请检查当前节点配置!");
|
||||
|
@ -24,5 +24,5 @@ public interface ReportService{
|
||||
|
||||
ReportResp deleteReport(@Valid ReportDeleteReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
|
||||
ResponseEntity<byte[]> downLoadReport(@Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
ResponseEntity<String> downLoadReport(@Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
}
|
||||
|
@ -19,8 +19,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static cd.casic.ci.process.engine.worker.base.HttpWorker.getRestTemplateWithoutSANCheck;
|
||||
|
||||
@ -95,7 +94,7 @@ public class ReportServiceImpl implements ReportService {
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
public ResponseEntity<String> downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
||||
String reportDeleteUrl = ConstantContextHolder.getScaIp() + PATH;
|
||||
String body = buildDownloadRequestBody(req);
|
||||
@ -109,11 +108,14 @@ public class ReportServiceImpl implements ReportService {
|
||||
if (responseEntity.getStatusCode() == HttpStatus.OK && responseEntity.hasBody()) {
|
||||
log.info("===============报告下载接口成功=================");
|
||||
|
||||
byte[] responseBody = responseEntity.getBody();
|
||||
String base64ResponseBody = Base64.getEncoder().encodeToString(responseBody);
|
||||
// 构建返回给前端的 ResponseEntity<byte[]>
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=report.bin")
|
||||
.body(responseEntity.getBody());
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=report.zip")
|
||||
.body(base64ResponseBody);
|
||||
}else {
|
||||
log.error("===============报告下载接口失败=================");
|
||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), "删除报告失败");
|
||||
|
Loading…
x
Reference in New Issue
Block a user