113 lines
4.7 KiB
Java
113 lines
4.7 KiB
Java
package net.educoder.quality;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.github.pagehelper.PageInfo;
|
|
import net.educoder.quality.common.util.WordUtil;
|
|
import net.educoder.quality.dto.ProjectSastBugCenterDTO;
|
|
import net.educoder.quality.dto.ReportDetailDTO;
|
|
import net.educoder.quality.entity.mysql.Projects;
|
|
import net.educoder.quality.entity.mysql.ReportCenter;
|
|
import net.educoder.quality.entity.mysql.SastAnalysisDetail;
|
|
import net.educoder.quality.entity.postgres.PgIssues;
|
|
import net.educoder.quality.entity.postgres.PgProjects;
|
|
import net.educoder.quality.mapper.mysql.SastAnalysisDetailMapper;
|
|
import net.educoder.quality.mapper.mysql.TestMapper;
|
|
import net.educoder.quality.mapper.postgres.PgProjectMapper;
|
|
import net.educoder.quality.service.ProjectService;
|
|
import net.educoder.quality.service.ReportCenterService;
|
|
import net.educoder.quality.service.postgres.PgProjectsService;
|
|
import net.educoder.quality.vo.DetectResultCompareDetailVO;
|
|
import net.educoder.quality.vo.ProjectBugCenterVO;
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.annotation.Rollback;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Author: youys
|
|
* @Date: 2022/9/13
|
|
* @Description:
|
|
*/
|
|
@SpringBootTest
|
|
@Rollback(false)
|
|
public class MapperTest {
|
|
|
|
@Autowired
|
|
public TestMapper testMapper;
|
|
|
|
|
|
@Autowired
|
|
private ReportCenterService reportCenterService;
|
|
|
|
@Autowired
|
|
private ProjectService projectService;
|
|
|
|
@Autowired
|
|
private PgProjectsService pgProjectsService;
|
|
|
|
@Autowired
|
|
private SastAnalysisDetailMapper sastMapper;
|
|
|
|
@Test
|
|
@Transactional
|
|
public void testInsert(){
|
|
ProjectBugCenterVO projectBugCenterVO = new ProjectBugCenterVO();
|
|
projectBugCenterVO.setPageSize(5);
|
|
projectBugCenterVO.setPageNum(2);
|
|
PageInfo<ProjectSastBugCenterDTO> res = projectService.projectSastBugCenter(86L, projectBugCenterVO);
|
|
System.out.println(res);
|
|
// System.out.println(pgProjectsService.getSastBug("475336319468306432"));
|
|
}
|
|
|
|
@Test
|
|
public void testFix(){
|
|
DetectResultCompareDetailVO detectResultCompareDetailVO = new DetectResultCompareDetailVO();
|
|
detectResultCompareDetailVO.setProjectId(89L);
|
|
detectResultCompareDetailVO.setFiledName("all");
|
|
detectResultCompareDetailVO.setType(1);
|
|
System.out.println(projectService.detectResultCompareDetail(detectResultCompareDetailVO));
|
|
}
|
|
|
|
@Test
|
|
public void testS() throws Exception {
|
|
Long reportId = 11L;
|
|
ReportCenter reportCenter = reportCenterService.reportCenterDetail(reportId);
|
|
Projects projects = projectService.getProjectById(reportCenter.getProjectId());
|
|
// 获取模板,填充数据
|
|
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx");
|
|
|
|
ReportDetailDTO reportDetail = reportCenterService.getReportDetail(projects.getId());
|
|
|
|
Map<String, String> param = new HashMap<>(13);
|
|
param.put("projectName", projects.getProjectName());
|
|
param.put("createTime", DateUtil.formatDateTime(new Date()));
|
|
param.put("issueCount",String.valueOf(reportDetail.getBugCount().getTotal()));
|
|
param.put("seriousIssueCount",String.valueOf(reportDetail.getBugCount().getCritical()));
|
|
param.put("highRiskIssueCount",String.valueOf(reportDetail.getBugCount().getHigh()));
|
|
param.put("midRiskIssueCount",String.valueOf(reportDetail.getBugCount().getMiddle()));
|
|
param.put("lowRiskIssueCount",String.valueOf(reportDetail.getBugCount().getLow()));
|
|
param.put("componentCount",String.valueOf(reportDetail.getComponents()));
|
|
param.put("componentBugCount",String.valueOf(reportDetail.getVulnerabilityCount().getTotal()));
|
|
param.put("seriousBugCount",String.valueOf(reportDetail.getVulnerabilityCount().getCritical()));
|
|
param.put("highRiskBugCount",String.valueOf(reportDetail.getVulnerabilityCount().getHigh()));
|
|
param.put("midRiskBugCount",String.valueOf(reportDetail.getVulnerabilityCount().getMiddle()));
|
|
param.put("lowRiskBugCount",String.valueOf(reportDetail.getVulnerabilityCount().getLow()));
|
|
|
|
XWPFDocument doc = new XWPFDocument(resourceAsStream);
|
|
|
|
WordUtil.changeText(doc, param);
|
|
pgProjectsService.fillReportTable(doc,reportDetail);
|
|
WordUtil.save(doc,"C:\\Users\\14666\\Desktop\\report.docx");
|
|
}
|
|
}
|