Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
ae039b098c | |
|
|
34e4edd5e9 |
|
|
@ -27,7 +27,7 @@ public enum BugTypeEnum {
|
|||
|
||||
public static BugTypeEnum getBugTypeEnum(String bugType){
|
||||
for (BugTypeEnum bugTypeEnum : BugTypeEnum.values()) {
|
||||
if(bugTypeEnum.bugType.equals(bugType)){
|
||||
if(bugTypeEnum.getBugType().equals(bugType)){
|
||||
return bugTypeEnum;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public enum BugTypeEnum {
|
|||
|
||||
public static BugTypeEnum getBugTypeEnumByDbValue(String dbValue){
|
||||
for (BugTypeEnum bugTypeEnum : BugTypeEnum.values()) {
|
||||
if(bugTypeEnum.dbValue.equals(dbValue)){
|
||||
if(bugTypeEnum.getDbValue().equals(dbValue)){
|
||||
return bugTypeEnum;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class GitUtil {
|
|||
/**
|
||||
* 克隆代码到指定目录
|
||||
*/
|
||||
public static ShellResult gitClone(String gitUrl, String branch, String username, String password, String fullWorkspace) {
|
||||
public static ShellResult gitClone(String gitUrl, String branch, String username, String md5Pwd, String fullWorkspace) {
|
||||
File file = new File(fullWorkspace);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
|
|
@ -27,7 +27,7 @@ public class GitUtil {
|
|||
String command;
|
||||
if (StringUtils.isNotBlank(username)) {
|
||||
command = StringUtils.join("cd ", fullWorkspace, " && git clone -b ", branch, " ", gitUrl.substring(0, index + 2), username, ":",
|
||||
password, "@", gitUrl.substring(index + 2));
|
||||
md5Pwd, "@", gitUrl.substring(index + 2));
|
||||
} else {
|
||||
command = StringUtils.join("cd ", fullWorkspace, " && git clone -b ", branch, " ", gitUrl.substring(0, index + 2), gitUrl.substring(index + 2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class IpUtil {
|
|||
ip = request.getRemoteAddr();
|
||||
}
|
||||
if("0:0:0:0:0:0:0:1".equals(ip)){
|
||||
ip = "127.0.0.1";
|
||||
ip = System.getenv("localIp") ;
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author guange
|
||||
|
|
@ -15,6 +17,9 @@ public final class ShellUtil {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShellUtil.class);
|
||||
|
||||
private static final List<String> MALICIOUS_COMMAND = Arrays.asList("rm -rf /", "rm -rf .", "rm -rf *", "curl -fsSL",
|
||||
"wget -q -O","rcp ","scp ", "rsync ", "sftp ", "powershell -nop", "bitsadmin");
|
||||
|
||||
/**
|
||||
* 执行shell命令并获取输出
|
||||
*/
|
||||
|
|
@ -43,13 +48,21 @@ public final class ShellUtil {
|
|||
/**
|
||||
* 执行命令并获得输出以及退出码
|
||||
*/
|
||||
public static ShellResult executeAndGetExitStatus(String command) {
|
||||
public static ShellResult executeAndGetExitStatus(String userCommand) {
|
||||
|
||||
for (String s : MALICIOUS_COMMAND) {
|
||||
if (userCommand.contains(s)) {
|
||||
return new ShellResult(-1,"包含恶意命令");
|
||||
}
|
||||
}
|
||||
|
||||
ShellResult result = new ShellResult();
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
Integer exitStatus = -1;
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", command);
|
||||
List<String> commands = Arrays.asList("/bin/sh", "-c", userCommand);
|
||||
ProcessBuilder pb = new ProcessBuilder(commands);
|
||||
pb.redirectErrorStream(true);
|
||||
try {
|
||||
Process process = pb.start();
|
||||
|
|
@ -62,12 +75,11 @@ public final class ShellUtil {
|
|||
exitStatus = process.waitFor();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("执行shell出错, command:{}", command, e);
|
||||
logger.error("执行shell出错", e);
|
||||
}
|
||||
|
||||
result.setOut(out.toString().trim());
|
||||
result.setExitStatus(exitStatus);
|
||||
logger.debug("execute shell command: {}, out: {}, status: {}", command, out, exitStatus);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -100,7 +112,7 @@ public final class ShellUtil {
|
|||
exitStatus = process.waitFor();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("执行shell出错, command:{}", command, e);
|
||||
logger.error("执行shell出错", e);
|
||||
}
|
||||
|
||||
result.setOut(out.toString().trim());
|
||||
|
|
@ -139,7 +151,7 @@ public final class ShellUtil {
|
|||
}
|
||||
exitStatus = ps.waitFor();
|
||||
}catch (Exception e) {
|
||||
logger.error("执行shell出错, command:{}", cmd, e);
|
||||
logger.error("执行shell出错", e);
|
||||
}
|
||||
result.setOut(sb.toString().trim());
|
||||
result.setExitStatus(exitStatus);
|
||||
|
|
@ -167,7 +179,7 @@ public final class ShellUtil {
|
|||
}
|
||||
exitStatus = ps.waitFor();
|
||||
}catch (Exception e) {
|
||||
logger.error("执行shell出错, command:{}", cmd, e);
|
||||
logger.error("执行shell出错", e);
|
||||
}
|
||||
result.setOut(sb.toString().trim());
|
||||
result.setExitStatus(exitStatus);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import cn.hutool.core.date.DateUtil;
|
|||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import net.educoder.quality.common.enums.ErrorCodeEnum;
|
||||
import net.educoder.quality.common.exception.BusinessException;
|
||||
import net.educoder.quality.common.util.R;
|
||||
import net.educoder.quality.common.util.WordUtil;
|
||||
import net.educoder.quality.dto.ReportDetailDTO;
|
||||
|
|
@ -91,40 +93,40 @@ public class ReportCenterController {
|
|||
String fileName = new String(reportCenter.getReportName().getBytes("utf-8"), "ISO8859-1");
|
||||
|
||||
// 获取模板,填充数据
|
||||
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx");
|
||||
try(InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx")) {
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
ReportDetailDTO reportDetail = pgProjectsService.getReportDetail(projects.getProjectName());
|
||||
|
||||
ReportDetailDTO reportDetail = pgProjectsService.getReportDetail(projects.getProjectName());
|
||||
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()));
|
||||
|
||||
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);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(resourceAsStream);
|
||||
WordUtil.changeText(doc, param);
|
||||
pgProjectsService.fillReportTable(doc,reportDetail);
|
||||
|
||||
String format = reportCenter.getFormat();
|
||||
if ("pdf".equals(format)){
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".pdf");
|
||||
response.setContentType("application/pdf");
|
||||
WordUtil.docToPdf(doc,outputStream);
|
||||
}else {
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx");
|
||||
response.setContentType("application/octet-stream");
|
||||
doc.write(outputStream);
|
||||
String format = reportCenter.getFormat();
|
||||
if ("pdf".equals(format)) {
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".pdf");
|
||||
response.setContentType("application/pdf");
|
||||
WordUtil.docToPdf(doc, outputStream);
|
||||
} else {
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".docx");
|
||||
response.setContentType("application/octet-stream");
|
||||
doc.write(outputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,52 +151,68 @@ public class ReportCenterController {
|
|||
|
||||
String[] filePaths = new String[reportIds.size()];
|
||||
InputStream[] ins = new InputStream[reportIds.size()];
|
||||
try {
|
||||
int i = 0;
|
||||
for (Long reportId : reportIds) {
|
||||
ReportCenter reportCenter = reportCenterService.reportCenterDetail(reportId);
|
||||
if(reportCenter == null){
|
||||
throw new BusinessException(ErrorCodeEnum.PARAM_ERROR);
|
||||
}
|
||||
Projects projects = projectService.getProjectById(reportCenter.getProjectId());
|
||||
|
||||
int i = 0;
|
||||
for (Long reportId : reportIds) {
|
||||
ReportCenter reportCenter = reportCenterService.reportCenterDetail(reportId);
|
||||
Projects projects = projectService.getProjectById(reportCenter.getProjectId());
|
||||
if(reportCenter == null){
|
||||
throw new BusinessException(ErrorCodeEnum.PROJECT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 获取模板,填充数据
|
||||
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx");
|
||||
ReportDetailDTO reportDetail = pgProjectsService.getReportDetail(projects.getProjectName());
|
||||
|
||||
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()));
|
||||
|
||||
ReportDetailDTO reportDetail = pgProjectsService.getReportDetail(projects.getProjectName());
|
||||
// 获取模板,填充数据
|
||||
try(InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx");){
|
||||
XWPFDocument doc = new XWPFDocument(resourceAsStream);
|
||||
WordUtil.changeText(doc, param);
|
||||
pgProjectsService.fillReportTable(doc, reportDetail);
|
||||
|
||||
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()));
|
||||
String filePath = filePath(reportCenter.getReportName());
|
||||
String path = new File(filePath).getPath();
|
||||
doc.write(new FileOutputStream(path));
|
||||
doc.close();
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(resourceAsStream);
|
||||
WordUtil.changeText(doc, param);
|
||||
pgProjectsService.fillReportTable(doc,reportDetail);
|
||||
ins[i] = new FileInputStream(path);
|
||||
filePaths[i] = filePath;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
String filePath = filePath(reportCenter.getReportName());
|
||||
doc.write(new FileOutputStream(new File(filePath)));
|
||||
doc.close();
|
||||
|
||||
ins[i] = new FileInputStream(new File(filePath));
|
||||
filePaths[i] = filePath;
|
||||
i++;
|
||||
ZipUtil.zip(outputStream, filePaths, ins);
|
||||
}finally {
|
||||
if (ins.length > 0){
|
||||
for (int i = 0; i < ins.length; i++) {
|
||||
if (ins[i] != null) {
|
||||
ins[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZipUtil.zip(outputStream, filePaths, ins);
|
||||
}
|
||||
|
||||
private String filePath(String reportName){
|
||||
String path = StringUtils.join(downloadTempDir, "/", IdUtil.fastSimpleUUID(), "/");
|
||||
String name = reportName + ".docx";
|
||||
String name = reportName.replaceAll(".","").replaceAll("/", "") + ".docx";
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -333,7 +334,7 @@ public class CloneDetectionServiceImpl implements CloneDetectionService {
|
|||
// mac上为String cntResult = ShellUtil.execute("cd " + repoPath + " && du -s -k -I \"\\.git\" | awk '{print $1}'");
|
||||
String cntResult = ShellUtil.execute("cd " + repoPath + " && du -s -k --exclude=\"\\.git\" | awk '{print $1}'");
|
||||
String[] split = cntResult.trim().split("\n");
|
||||
return NumberUtils.toInt(split[split.length - 1].trim(), Integer.MAX_VALUE) * 1024L;
|
||||
return BigDecimal.valueOf(NumberUtils.toInt(split[split.length - 1].trim(), Integer.MAX_VALUE)).multiply(BigDecimal.valueOf(1024)).longValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -929,12 +929,21 @@ public class ProjectServiceImpl implements ProjectService {
|
|||
* @return
|
||||
*/
|
||||
private String processGitUrl(String gitUrl){
|
||||
if(StringUtils.isBlank(gitUrl)){
|
||||
throw new BusinessException(ErrorCodeEnum.PARAM_ERROR);
|
||||
}
|
||||
|
||||
// 必须以http or https 开头
|
||||
if( !(gitUrl.startsWith("http://") || gitUrl.startsWith("https://"))){
|
||||
throw new BusinessException(ErrorCodeEnum.PARAM_ERROR);
|
||||
}
|
||||
|
||||
String router = gitUrl.substring(gitUrl.lastIndexOf("/"));
|
||||
if ("/".equals(router) || StringUtils.isBlank(router)) {
|
||||
String newGitUrl = gitUrl.substring(0, gitUrl.length() - 1);
|
||||
router = newGitUrl.substring(newGitUrl.lastIndexOf("/"));
|
||||
return newGitUrl.replaceAll(router,"") + ".git";
|
||||
return newGitUrl.substring(0, newGitUrl.length() - router.length()) + ".git";
|
||||
}
|
||||
return gitUrl.replaceAll(router,"") + ".git";
|
||||
return gitUrl.substring(0, gitUrl.length() - router.length()) + ".git";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class PgProjectsService {
|
|||
bugTable.removeRow(tempLine);
|
||||
}
|
||||
//循环添加表格行并填充数据
|
||||
for (int kk = 1;kk <= bugIssues.size();kk++){
|
||||
for (int kk = 1;bugIssues != null && kk <= bugIssues.size();kk++){
|
||||
PgIssues pgIssues = bugIssues.get(kk-1);
|
||||
for (int i = 0;i < tempLine;i++){
|
||||
//先在模板表格下复制模板的行
|
||||
|
|
@ -150,7 +150,9 @@ public class PgProjectsService {
|
|||
while (vulnerabilityTable.getRows().size()>tempLine){
|
||||
vulnerabilityTable.removeRow(tempLine);
|
||||
}
|
||||
for (int kk = 1;kk <= parseRecordDetails.size();kk++){
|
||||
|
||||
|
||||
for (int kk = 1;parseRecordDetails!=null && kk <= parseRecordDetails.size();kk++){
|
||||
ComponentParseRecordDetailDTO recordDetailDTO = parseRecordDetails.get(kk-1);
|
||||
for (int i = 0;i < 4;i++){
|
||||
WordUtil.insertRow(vulnerabilityTable,vulnerabilityTable.getRow(i),vulnerabilityTable.getRows().size());
|
||||
|
|
@ -165,7 +167,7 @@ public class PgProjectsService {
|
|||
StringBuilder vulnerabilityDes = new StringBuilder();
|
||||
if (StringUtils.isNotEmpty(vulnerabilities)){
|
||||
JSONArray jsonArray = JSONObject.parseArray(vulnerabilities);
|
||||
for (int i = 0;i<jsonArray.size();i++){
|
||||
for (int i = 0;jsonArray != null && i<jsonArray.size();i++){
|
||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||||
String description = jsonObject.getString("description");
|
||||
vulnerabilityDes.append(i + 1).append(".漏洞").append(i + 1).append(":").append(description).append('\n');
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
<generatorConfiguration>
|
||||
|
||||
<properties resource="classpath:generator/jdbc.properties"/>
|
||||
|
||||
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
|
@ -13,10 +15,10 @@
|
|||
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
|
||||
</plugin>
|
||||
|
||||
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
|
||||
connectionURL="jdbc:mysql://rm-bp13v5020p7828r5rso.mysql.rds.aliyuncs.com:3306/quality_analysis"
|
||||
userId="testeducoder"
|
||||
password="TEST@123">
|
||||
<jdbcConnection driverClass="${jdbcDriver}"
|
||||
connectionURL="${jdbcUrl}"
|
||||
userId="${jdbcUser}"
|
||||
password="${jdbcPassword}">
|
||||
</jdbcConnection>
|
||||
|
||||
<javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"/>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
jdbcDriver=com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl=jdbc:mysql://rm-bp13v5020p7828r5rso.mysql.rds.aliyuncs.com:3306/quality_analysis
|
||||
jdbcUser=testeducoder
|
||||
jdbcPassword=${jdbcPassword}
|
||||
|
|
@ -65,29 +65,30 @@ public class MapperTest {
|
|||
ReportCenter reportCenter = reportCenterService.reportCenterDetail(reportId);
|
||||
Projects projects = projectService.getProjectById(reportCenter.getProjectId());
|
||||
// 获取模板,填充数据
|
||||
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx");
|
||||
try(InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/report-center-template.docx");){
|
||||
ReportDetailDTO reportDetail = pgProjectsService.getReportDetail(projects.getProjectName());
|
||||
|
||||
ReportDetailDTO reportDetail = pgProjectsService.getReportDetail(projects.getProjectName());
|
||||
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()));
|
||||
|
||||
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);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(resourceAsStream);
|
||||
WordUtil.changeText(doc, param);
|
||||
pgProjectsService.fillReportTable(doc,reportDetail);
|
||||
WordUtil.save(doc,"C:\\Users\\14666\\Desktop\\res004.docx");
|
||||
}
|
||||
|
||||
WordUtil.changeText(doc, param);
|
||||
pgProjectsService.fillReportTable(doc,reportDetail);
|
||||
WordUtil.save(doc,"C:\\Users\\14666\\Desktop\\res004.docx");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue