Merge branch 'master' of http://1.14.125.6:3000/mianbin/ops-pro
This commit is contained in:
commit
90cb7a430f
@ -12,6 +12,7 @@ import jakarta.annotation.Resource;
|
|||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -53,11 +54,11 @@ public class ReportController {
|
|||||||
|
|
||||||
|
|
||||||
@PostMapping(path="/downLoadReport")
|
@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.ci.process.process.dataObject.base.BaseIdReq;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
@ -23,5 +24,5 @@ public interface ReportService{
|
|||||||
|
|
||||||
ReportResp deleteReport(@Valid ReportDeleteReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,11 @@ import cd.casic.ci.process.process.service.report.ReportService;
|
|||||||
import cd.casic.framework.commons.exception.ServiceException;
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.*;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
|
||||||
import org.springframework.util.MultiValueMap;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
@ -39,15 +35,16 @@ import static cd.casic.ci.process.engine.worker.base.HttpWorker.getRestTemplateW
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ReportServiceImpl implements ReportService {
|
public class ReportServiceImpl implements ReportService {
|
||||||
|
|
||||||
|
public static final String PATH = "/openapi/v1/asset/report/downLoadReport/batch";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<ReportResp> findReportList(BaseIdPageReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
public PageResult<ReportResp> findReportList(BaseIdPageReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||||
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
||||||
String reportFindUrl = ConstantContextHolder.getScaIp() + "/openapi/v1/asset/report/list";
|
String reportFindUrl = ConstantContextHolder.getScaIp() + "/openapi/v1/asset/report/list";
|
||||||
MultiValueMap<String, Object> body = buildFindRequestBody(req);
|
String body = buildFindRequestBody(req);
|
||||||
HttpHeaders headers = createHeaders();
|
HttpHeaders headers = createHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.add("OpenApiUserToken", ConstantContextHolder.getScaToken());
|
HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);
|
||||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
|
||||||
|
|
||||||
log.info("报告分页查询接口:" + reportFindUrl);
|
log.info("报告分页查询接口:" + reportFindUrl);
|
||||||
JSONObject response = restTemplate.postForObject(reportFindUrl, requestEntity, JSONObject.class);
|
JSONObject response = restTemplate.postForObject(reportFindUrl, requestEntity, JSONObject.class);
|
||||||
@ -72,12 +69,11 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
@Override
|
@Override
|
||||||
public ReportResp deleteReport(ReportDeleteReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
public ReportResp deleteReport(ReportDeleteReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||||
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
||||||
String reportDeleteUrl = ConstantContextHolder.getScaIp() + "/openapi/v1/asset/report/delet";
|
String reportDeleteUrl = ConstantContextHolder.getScaIp() + "/openapi/v1/asset/report/delete";
|
||||||
MultiValueMap<String, Object> body = buildDeleteRequestBody(req);
|
String body = buildDeleteRequestBody(req);
|
||||||
HttpHeaders headers = createHeaders();
|
HttpHeaders headers = createHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.add("OpenApiUserToken", ConstantContextHolder.getScaToken());
|
HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);
|
||||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
|
||||||
|
|
||||||
log.info("报告删除接口:" + reportDeleteUrl);
|
log.info("报告删除接口:" + reportDeleteUrl);
|
||||||
JSONObject response = restTemplate.postForObject(reportDeleteUrl, requestEntity, JSONObject.class);
|
JSONObject response = restTemplate.postForObject(reportDeleteUrl, requestEntity, JSONObject.class);
|
||||||
@ -99,24 +95,25 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
public ResponseEntity<byte[]> downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||||
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
||||||
String reportDeleteUrl = ConstantContextHolder.getScaIp() + "/openapi/v1/asset/report/downLoadReport/batch";
|
String reportDeleteUrl = ConstantContextHolder.getScaIp() + PATH;
|
||||||
MultiValueMap<String, Object> body = buildDownloadRequestBody(req);
|
String body = buildDownloadRequestBody(req);
|
||||||
HttpHeaders headers = createHeaders();
|
HttpHeaders headers = createHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.add("OpenApiUserToken", ConstantContextHolder.getScaToken());
|
HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);
|
||||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
|
||||||
|
|
||||||
log.info("报告下载接口:" + reportDeleteUrl);
|
log.info("报告下载接口:" + reportDeleteUrl);
|
||||||
JSONObject response = restTemplate.postForObject(reportDeleteUrl, requestEntity, JSONObject.class);
|
ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(reportDeleteUrl, requestEntity, byte[].class);
|
||||||
String message = response.getString("message");
|
|
||||||
if (message.equals("success")) {
|
if (responseEntity.getStatusCode() == HttpStatus.OK && responseEntity.hasBody()) {
|
||||||
ReportResp reportResp = new ReportResp();
|
|
||||||
log.info("===============报告下载接口成功=================");
|
log.info("===============报告下载接口成功=================");
|
||||||
|
|
||||||
return response.getString("xmTraceId");
|
// 构建返回给前端的 ResponseEntity<byte[]>
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=report.bin")
|
||||||
|
.body(responseEntity.getBody());
|
||||||
}else {
|
}else {
|
||||||
log.error("===============报告下载接口失败=================");
|
log.error("===============报告下载接口失败=================");
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), "删除报告失败");
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(), "删除报告失败");
|
||||||
@ -132,40 +129,43 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultiValueMap<String, Object> buildFindRequestBody(BaseIdPageReq req) {
|
private String buildFindRequestBody(BaseIdPageReq req) {
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
JSONObject json = new JSONObject();
|
||||||
if (!ObjectUtils.isEmpty(req.getProjectId())){
|
if (req.getProjectId() != null) {
|
||||||
body.add("projectId", req.getProjectId());
|
json.put("projectId", req.getProjectId());
|
||||||
}
|
}
|
||||||
body.add("pageNum", req.getPageNo());
|
json.put("pageNum", req.getPageNo());
|
||||||
body.add("pageSize", req.getPageSize());
|
json.put("pageSize", req.getPageSize());
|
||||||
return body;
|
return json.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultiValueMap<String, Object> buildDeleteRequestBody(ReportDeleteReq req) {
|
private String buildDeleteRequestBody(ReportDeleteReq req) {
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
JSONObject json = new JSONObject();
|
||||||
body.add("endDate", req.getEndDate());
|
|
||||||
body.add("name", req.getName());
|
json.put("endDate", req.getEndDate());
|
||||||
body.add("projectIdList", req.getProjectIdList());
|
json.put("name", req.getName());
|
||||||
body.add("reportId", req.getReportId());
|
json.put("projectIdList", req.getProjectIdList());
|
||||||
body.add("sourceCode", req.getSourceCode());
|
json.put("reportId", req.getReportId());
|
||||||
body.add("startDate", req.getStartDate());
|
json.put("sourceCode", req.getSourceCode());
|
||||||
body.add("status", req.getStatus());
|
json.put("startDate", req.getStartDate());
|
||||||
body.add("type", req.getType());
|
json.put("status", req.getStatus());
|
||||||
body.add("use", req.getUse());
|
json.put("type", req.getType());
|
||||||
return body;
|
json.put("use", req.getUse());
|
||||||
|
|
||||||
|
return json.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultiValueMap<String, Object> buildDownloadRequestBody(BaseIdReq req) {
|
private String buildDownloadRequestBody(BaseIdReq req) {
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
JSONObject json = new JSONObject();
|
||||||
body.add("reportIds", req.getReportIds());
|
json.put("reportIds", req.getReportIds());
|
||||||
return body;
|
return json.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setReportFindResp(JSONObject data, String xmTraceId, List<ReportResp> respList) {
|
private void setReportFindResp(JSONObject data, String xmTraceId, List<ReportResp> respList) {
|
||||||
data.getJSONArray("records").forEach(item -> {
|
JSONArray records = data.getJSONArray("records");
|
||||||
JSONObject report = (JSONObject) item;
|
for (int i = 0; i < records.size(); i++) {
|
||||||
|
JSONObject report = records.getJSONObject(i);
|
||||||
ReportResp reportResp = new ReportResp();
|
ReportResp reportResp = new ReportResp();
|
||||||
|
|
||||||
reportResp.setId(report.getInteger("id"));
|
reportResp.setId(report.getInteger("id"));
|
||||||
@ -183,13 +183,14 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
reportResp.setXmTraceId(xmTraceId);
|
reportResp.setXmTraceId(xmTraceId);
|
||||||
|
|
||||||
List<Integer> typeList = new ArrayList<>();
|
List<Integer> typeList = new ArrayList<>();
|
||||||
report.getJSONArray("type").forEach(o->{
|
JSONArray typeArray = report.getJSONArray("type");
|
||||||
typeList.add((Integer) o);
|
for (int j = 0; j < typeArray.size(); j++) {
|
||||||
});
|
typeList.add(typeArray.getInteger(j));
|
||||||
|
}
|
||||||
reportResp.setType(typeList);
|
reportResp.setType(typeList);
|
||||||
|
|
||||||
respList.add(reportResp);
|
respList.add(reportResp);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user