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