0605 ljc 报告模块修改
This commit is contained in:
parent
0e38244fbc
commit
2172342c6b
@ -12,6 +12,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -53,11 +54,11 @@ public class ReportController {
|
||||
|
||||
|
||||
@PostMapping(path="/downLoadReport")
|
||||
public CommonResult<String> downLoadReport(@RequestBody @NotNull @Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
public CommonResult<ResponseEntity<byte[]>> downLoadReport(@RequestBody @NotNull @Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
|
||||
String xmTraceId = reportService.downLoadReport(req);
|
||||
ResponseEntity<byte[]> fileInputStream = reportService.downLoadReport(req);
|
||||
|
||||
return CommonResult.success(xmTraceId);
|
||||
return CommonResult.success(fileInputStream);
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ import cd.casic.ci.process.process.dataObject.base.BaseIdPageReq;
|
||||
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
@ -23,5 +24,5 @@ public interface ReportService{
|
||||
|
||||
ReportResp deleteReport(@Valid ReportDeleteReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
|
||||
String downLoadReport(@Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
ResponseEntity<byte[]> downLoadReport(@Valid BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
}
|
||||
|
@ -12,9 +12,7 @@ import cd.casic.framework.commons.pojo.PageResult;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@ -97,7 +95,7 @@ public class ReportServiceImpl implements ReportService {
|
||||
|
||||
|
||||
@Override
|
||||
public String downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
public ResponseEntity<byte[]> downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
||||
String reportDeleteUrl = ConstantContextHolder.getScaIp() + PATH;
|
||||
String body = buildDownloadRequestBody(req);
|
||||
@ -106,17 +104,19 @@ public class ReportServiceImpl implements ReportService {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);
|
||||
|
||||
log.info("报告下载接口:" + reportDeleteUrl);
|
||||
JSONObject response = restTemplate.postForObject(reportDeleteUrl, requestEntity, JSONObject.class);
|
||||
String message = response.getString("message");
|
||||
if (message.equals("success")) {
|
||||
ReportResp reportResp = new ReportResp();
|
||||
ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(reportDeleteUrl, requestEntity, byte[].class);
|
||||
|
||||
if (responseEntity.getStatusCode() == HttpStatus.OK && responseEntity.hasBody()) {
|
||||
log.info("===============报告下载接口成功=================");
|
||||
|
||||
return response.getString("xmTraceId");
|
||||
|
||||
} else {
|
||||
// 构建返回给前端的 ResponseEntity<byte[]>
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=report.bin")
|
||||
.body(responseEntity.getBody());
|
||||
}else {
|
||||
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