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

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

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