提交 e61b1478 authored 作者: 孙洁清's avatar 孙洁清

Merge branch 'master' of git.yfzx.zjtys.com.cn:912-system/monitor/inspect

...@@ -68,14 +68,12 @@ public class InspectController { ...@@ -68,14 +68,12 @@ public class InspectController {
File file = FileUtil.saveToLocal(multfile); File file = FileUtil.saveToLocal(multfile);
log.info("inspect:代码解压完成,地址为{}",file.getCanonicalPath()); log.info("inspect:代码解压完成,地址为{}",file.getCanonicalPath());
InspectParameter inspectParameter; InspectParameter inspectParameter = parameterService.getParameterByUsername(username);
InspectParameter parameterByUsername = parameterService.getParameterByUsername(username);
if(parameterByUsername==null){ if(inspectParameter==null){
inspectParameter = new InspectParameter(); inspectParameter = new InspectParameter();
inspectParameter.setUsername(username); inspectParameter.setUsername(username);
inspectParameter.setSourceAddress(file.getCanonicalPath());
inspectParameter.setSystemFund(systemFund); inspectParameter.setSystemFund(systemFund);
inspectParameter.setAdmin(admin);
inspectParameter.setModules(modules); inspectParameter.setModules(modules);
inspectParameter.setSafety(safety); inspectParameter.setSafety(safety);
inspectParameter.setTables(tables); inspectParameter.setTables(tables);
...@@ -84,12 +82,11 @@ public class InspectController { ...@@ -84,12 +82,11 @@ public class InspectController {
inspectParameter.setDisaster(disaster); inspectParameter.setDisaster(disaster);
inspectParameter.setData(data); inspectParameter.setData(data);
inspectParameter.setFramework(framework); inspectParameter.setFramework(framework);
inspectParameter.setPath(file.getCanonicalPath());
inspectParameter.setRecastMethod(method);
inspectParameter.setId(UUIDUtil.getUUID()); inspectParameter.setId(UUIDUtil.getUUID());
}else{ inspectParameter.setAdmin(admin);
inspectParameter=parameterByUsername;
} }
inspectParameter.setRecastMethod(method);
inspectParameter.setSourceAddress(file.getCanonicalPath());
ReportVo reportVo = new ReportVo(); ReportVo reportVo = new ReportVo();
int count = technologyService.findAllTechnologyCount(); int count = technologyService.findAllTechnologyCount();
reportVo.setTechnologiesNum(count); reportVo.setTechnologiesNum(count);
...@@ -117,17 +114,17 @@ public class InspectController { ...@@ -117,17 +114,17 @@ public class InspectController {
map.put("techMap",techMap); map.put("techMap",techMap);
map.put("warnMap",warnMap); map.put("warnMap",warnMap);
map.put("technologies",technologies); map.put("technologies",technologies);
try { // try {
String template = FreemarkerUtils.getTemplate("pg.ftl", map); // String template = FreemarkerUtils.getTemplate("pg.ftl", map);
String s = inspectService.generateHtml(template, map); // String s = inspectService.generateHtml(template, map);
String filePath = FileUtil.createFilePath(); // String filePath = FileUtil.createFilePath();
File file1 = new File("./pgbg/" + filePath + "/" + file.getName() + ".html"); // File file1 = new File("./pgbg/" + filePath + "/" + file.getName() + ".html");
FileUtil.write(s,"./pgbg/"+filePath+"/"+file.getName()+".html"); // FileUtil.write(s,"./pgbg/"+filePath+"/"+file.getName()+".html");
reportVo.setHtmlAddress(file1.getCanonicalPath()); // reportVo.setHtmlAddress(file1.getCanonicalPath());
System.out.println("内容"+s); // System.out.println("内容"+s);
} catch (TemplateException e) { // } catch (TemplateException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
Report report = new Report(); Report report = new Report();
String random = RandomUtil.getRandom(); String random = RandomUtil.getRandom();
report.setId(RandomUtil.getRandom()); report.setId(RandomUtil.getRandom());
...@@ -156,12 +153,4 @@ public class InspectController { ...@@ -156,12 +153,4 @@ public class InspectController {
ReportVo inspect = inspectService.inspect(reportVo, inspectParameter); ReportVo inspect = inspectService.inspect(reportVo, inspectParameter);
return ResponseEntity.ok(inspect); return ResponseEntity.ok(inspect);
} }
@PostMapping("/frontend")
@ApiOperation("git下载代码进行评估")
public ResponseEntity inspect(MultipartFile file) throws IOException {
return ResponseEntity.ok(200);
}
} }
...@@ -47,5 +47,5 @@ public interface TechnologyDao extends JpaRepository<Technology,String>, JpaSpec ...@@ -47,5 +47,5 @@ public interface TechnologyDao extends JpaRepository<Technology,String>, JpaSpec
* @param backOrFront * @param backOrFront
* @return * @return
*/ */
List<Technology> findAllByBackorfrontEquals(String backOrFront); List<Technology> findAllByBackorfrontEquals(Integer backOrFront);
} }
...@@ -91,11 +91,6 @@ public class InspectParameter { ...@@ -91,11 +91,6 @@ public class InspectParameter {
*/ */
private Integer disaster; private Integer disaster;
/**
* git地址
*/
private String path;
/** /**
* null:无效 * null:无效
*/ */
......
...@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
...@@ -128,8 +129,11 @@ public class Inspector { ...@@ -128,8 +129,11 @@ public class Inspector {
* FileVisitResult.TERMINATE 中止访问 * FileVisitResult.TERMINATE 中止访问
* FileVisitResult.SKIP_SIBLINGS 不访问同级的文件或目录 * FileVisitResult.SKIP_SIBLINGS 不访问同级的文件或目录
* FileVisitResult.SKIP_SUBTREE 不访问子目录 * FileVisitResult.SKIP_SUBTREE 不访问子目录
* * 准备工作
* @return 报告 * 1.解析文件
* 2/记录文件地址
* 3/统计各个规则文件后缀
* @return
*/ */
public ReportVo inspect() { public ReportVo inspect() {
ruleSuffixFileMap = new HashMap<>(); ruleSuffixFileMap = new HashMap<>();
...@@ -143,6 +147,12 @@ public class Inspector { ...@@ -143,6 +147,12 @@ public class Inspector {
//统计项目组成文件构成 //统计项目组成文件构成
//统计配置文件地址 //统计配置文件地址
statisticsConfigFile(); statisticsConfigFile();
//根据后缀名,收集文件进行操作
for (Rule rule : ruleList) {
if (!ruleSuffixFileMap.containsKey(rule.getSuffix())) {
ruleSuffixFileMap.put(rule.getSuffix(), new ArrayList<>());
}
}
try { try {
//以下为计算文件名称匹配正则表达式 //以下为计算文件名称匹配正则表达式
FileSystem aDefault = FileSystems.getDefault(); FileSystem aDefault = FileSystems.getDefault();
...@@ -162,7 +172,7 @@ public class Inspector { ...@@ -162,7 +172,7 @@ public class Inspector {
ruleSuffix.put(aDefault.getPathMatcher("glob:**/*." + s), s); ruleSuffix.put(aDefault.getPathMatcher("glob:**/*." + s), s);
} }
//文件读取 //文件读取
Files.walkFileTree(Paths.get(inspectParameter.getPath()), new FileVisitor<Path>() { Files.walkFileTree(Paths.get(inspectParameter.getSourceAddress()), new FileVisitor<Path>() {
@Override @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
//这里是对于路径(文件夹)的过滤,在这里读不到文件如果能判断,可以返回FileVisitResult.SKIP_SUBTREE 不访问子目录 //这里是对于路径(文件夹)的过滤,在这里读不到文件如果能判断,可以返回FileVisitResult.SKIP_SUBTREE 不访问子目录
...@@ -173,7 +183,6 @@ public class Inspector { ...@@ -173,7 +183,6 @@ public class Inspector {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
for (Map.Entry<String, PathMatcher> entry : languageSuffixMatcherMapping.entrySet()) { for (Map.Entry<String, PathMatcher> entry : languageSuffixMatcherMapping.entrySet()) {
//通过正则表达式匹配.java类型后缀文件,并+1 //通过正则表达式匹配.java类型后缀文件,并+1
if (entry.getValue().matches(file)) { if (entry.getValue().matches(file)) {
...@@ -342,9 +351,8 @@ public class Inspector { ...@@ -342,9 +351,8 @@ public class Inspector {
if (inspectParameter.getValid() != null) { if (inspectParameter.getValid() != null) {
BudgetVo budget = budgetUitl.getBudget(fund, report, inspectParameter); BudgetVo budget = budgetUitl.getBudget(fund, report, inspectParameter);
report.setBudgets(budget); report.setBudgets(budget);
inspectParameter.setId(UUIDUtil.getUUID());
parameterDao.save(inspectParameter);
} }
parameterDao.save(inspectParameter);
//填充地址(如果有) //填充地址(如果有)
report.setGitAddress(inspectParameter.getGitAddress()); report.setGitAddress(inspectParameter.getGitAddress());
//填充适配技术 //填充适配技术
...@@ -392,16 +400,16 @@ public class Inspector { ...@@ -392,16 +400,16 @@ public class Inspector {
/** /**
* rule所需要数据装配 * rule所需要数据装配
*/ */
private void ruleTransform(int i) { private void ruleTransform(Integer i) {
if (i == 1) { if (i == 1) {
List<Technology> front = technologyDao.findAllByBackorfrontEquals("1"); List<Technology> front = technologyDao.findAllByBackorfrontEquals(1);
List<String> ids = front.stream().map(Technology::getId).collect(Collectors.toList()); List<String> ids = front.stream().map(Technology::getId).collect(Collectors.toList());
this.ruleList = ruleDao.findAllByTechnologyIdIn(ids); this.ruleList = ruleDao.findAllByTechnologyIdIn(ids);
} else { } else {
if (inspectParameter.getRecastMethod() == 1) { if (inspectParameter.getRecastMethod() == 1) {
this.ruleList = ruleDao.findAll(); this.ruleList = ruleDao.findAll();
} else { } else {
List<Technology> front = technologyDao.findAllByBackorfrontEquals("1"); List<Technology> front = technologyDao.findAllByBackorfrontEquals(1);
List<String> ids = front.stream().map(Technology::getId).collect(Collectors.toList()); List<String> ids = front.stream().map(Technology::getId).collect(Collectors.toList());
this.ruleList = ruleDao.findAllByTechnologyIdIn(ids); this.ruleList = ruleDao.findAllByTechnologyIdIn(ids);
} }
......
...@@ -43,15 +43,14 @@ public class FileUtil { ...@@ -43,15 +43,14 @@ public class FileUtil {
// MultipartFile to File // MultipartFile to File
multipartFile.transferTo(excelFile); multipartFile.transferTo(excelFile);
if(prefix.equals(".zip")){ if(prefix.equals(".zip")){
FileUtil.unPackZip(excelFile,"", ".././"+name+"/"+split1[0]); FileUtil.unPackZip(excelFile,"", "./"+name+"/"+split1[0]);
}else{ }else{
FileUtil.unPackRar(excelFile, ".././"+name+"/"+split1[0]); FileUtil.unPackRar(excelFile, "./"+name+"/"+split1[0]);
} }
String[] split = fileName.split("\\."); String[] split = fileName.split("\\.");
File file3 = new File(".././"+name+"/"+split1[0]+"/"+split[0]); File file3 = new File("./"+name+"/"+split1[0]+"/"+split[0]);
excelFile.delete(); excelFile.delete();
log.info("end unpack file"); log.info("end unpack file");
System.out.println(file3.getCanonicalPath());
return file3; return file3;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论