0605 ljc 报告模块修改
This commit is contained in:
parent
430086cfa8
commit
0e38244fbc
@ -9,15 +9,13 @@ 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.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
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 +37,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 +71,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);
|
||||||
@ -101,12 +99,11 @@ public class ReportServiceImpl implements ReportService {
|
|||||||
@Override
|
@Override
|
||||||
public String downLoadReport(BaseIdReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
public String 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);
|
JSONObject response = restTemplate.postForObject(reportDeleteUrl, requestEntity, JSONObject.class);
|
||||||
@ -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