提交 2c8edc5c authored 作者: 马晨俊's avatar 马晨俊

mcj:问题包导入删除

上级 9826d759
......@@ -30,17 +30,17 @@ public class InspectController {
*/
@PostMapping("/path")
public ResponseEntity inspect(@RequestBody InspectParameter inspectParameter, MultipartFile file) throws IOException {
File file1 = file.getResource().getFile();
if(file1.getName().endsWith("zip")){
FileUtil.unPackZip(file1,"", "./");
}else{
FileUtil.unPackRar(file1, "./");
}
String[] split = file1.getName().split("\\.");
File file2 = new File("./"+split[0]);
String path1 = file2.getPath();
//File file1 = new File("/Users/mcj/IdeaProjects/inspect");
//String path1 = file1.getPath();
// File file1 = file.getResource().getFile();
// if(file1.getName().endsWith("zip")){
// FileUtil.unPackZip(file1,"", "./");
// }else{
// FileUtil.unPackRar(file1, "./");
// }
// String[] split = file1.getName().split("\\.");
// File file2 = new File("./"+split[0]);
// String path1 = file2.getPath();
File file1 = new File("/Users/mcj/IdeaProjects/inspect");
String path1 = file1.getPath();
inspectService.inspect(inspectParameter,path1);
return ResponseEntity.ok(200);
}
......@@ -53,7 +53,7 @@ public class InspectController {
@PostMapping("/git")
public ResponseEntity inspect1(@RequestBody InspectParameter inspectParameter,String path){
inspectService.inspect(inspectParameter,path);
//inspectService.inspect(inspectParameter,path);
System.out.println(path);
return ResponseEntity.ok(200);
}
......
......@@ -11,4 +11,12 @@ public interface RuleDao extends JpaRepository<Rule,String> {
* @return
*/
Rule findAllByTargetEquals(String target);
/**
* 根据目标关键字查询规则
* @param target 目标关键字
* @param techId 关键技术id
* @return
*/
Rule findAllByTargetEqualsAndTechnologyIdEquals(String target,String techId);
}
......@@ -80,4 +80,8 @@ public class InspectParameter {
*/
private Double disaster;
/**
* git地址
*/
private String path;
}
......@@ -38,6 +38,17 @@ public class Technology {
*/
private Integer fund;
/**
* 1:支持
* 2:不支持
*/
private Integer support = 1;
/**
* 1:前端技术
* 2:后端技术
*/
private Integer backOrFront = 2;
/**
* 数据创建时间
*/
......
......@@ -6,4 +6,5 @@ import com.zjty.inspect.entity.Report;
public interface InspectService {
Report inspect(InspectParameter inspectParameter,String path);
void setTechId(String id);
}
......@@ -32,11 +32,7 @@ public class InspectServiceImpl implements InspectService {
@Autowired
Inspector inspector;
@Autowired
private ParameterService parameterService;
@Autowired
private RuleDao ruleDao;
private String techId;
@Autowired
private ReportDao reportDao;
......@@ -57,6 +53,7 @@ public class InspectServiceImpl implements InspectService {
File file = path1.toFile();
Report report1 = new Report();
report1.setGitAddress(path);
inspector.setTechId(techId);
inspector.setInspectParameter(inspectParameter);
inspector.setReport(report1);
inspector.setSuffixLanguageMapping(suffixLanguageMapping);
......@@ -65,6 +62,12 @@ public class InspectServiceImpl implements InspectService {
reportDao.save(report);
return null;
}
@Override
public void setTechId(String id) {
techId=id;
}
public void listfile(String path,Map<String, Report.Language> suffixLanguageMapping,List<Rule> ruleList){
Path path1 = Paths.get(path);
File file = path1.toFile();
......
......@@ -6,12 +6,16 @@ import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.CoefficientModel;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.service.InspectService;
import com.zjty.inspect.utils.AnalysisFile;
import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* @author Mcj
......@@ -30,7 +34,11 @@ public class task implements CommandLineRunner {
@Autowired
private TechnologyDao technologyDao;
@Autowired
private InspectService inspectService;
@Autowired
private AnalysisFile analysisFile;
@Override
public void run(String... args) {
......@@ -104,18 +112,34 @@ public class task implements CommandLineRunner {
coefficientModelDao.saveAll(coefficientModels);
Technology technology = new Technology();
technology.setTechnologyName("spring技术");
technology.setAdvice("建议替换成国产化技术");
technology.setFund(200);
technology.setTechnologyName("Java依赖");
technology.setAdvice("spring技术");
technology.setFund(5);
technology.setId(UUIDUtil.getUUID());
inspectService.setTechId(technology.getId());
Technology technology1 = new Technology();
technology1.setTechnologyName("非国产化依赖");
technology1.setAdvice("建议替换成国产化技术");
technology1.setFund(5);
technology1.setId(UUIDUtil.getUUID());
Rule rule = new Rule();
rule.setId(UUIDUtil.getUUID());
rule.setSuffix("java");
rule.setSuffix("*");
rule.setTarget("ruleService");
rule.setTechnologyId(technology.getId());
technologyDao.save(technology);
ruleDao.save(rule);
List<Rule> all = ruleDao.findAll();
HashMap<String, Rule> stringRuleHashMap = new HashMap<>();
for (Rule rule1 : all) {
stringRuleHashMap.put(rule1+":"+rule1.getTechnologyId(),rule1);
}
analysisFile.setMap(stringRuleHashMap);
}
}
package com.zjty.inspect.utils;
import com.alibaba.fastjson.JSONObject;
import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.dao.TechnologyAndReportDao;
import com.zjty.inspect.entity.*;
import com.zjty.inspect.entity.Properties;
......@@ -20,9 +21,14 @@ import java.util.*;
@Component
public class AnalysisFile {
private HashMap<String,Rule> ruleMap = new HashMap<String,Rule>();
@Autowired
private TechnologyAndReportDao technologyAndReportDao;
@Autowired
private RuleDao ruleDao;
public static List<PomDependency> analysisGradle(Path pomPath) {
List<String> strings = null;
try {
......@@ -44,7 +50,9 @@ public class AnalysisFile {
return dependencies;
}
public DepTreePom parseTreeFile(String reportId,String filePath, List<Rule> ruleList) {
public DepTreePom parseTreeFile(String reportId,String filePath, List<Rule> ruleList,String techId) {
ArrayList<Rule> rules = new ArrayList<>();
HashMap<String, String> map1 = new HashMap<>();
ArrayList<TechnologyAndReport> technologyAndReports = new ArrayList<>();
Path path = Paths.get(filePath);
DepTreePom depTreePom = new DepTreePom();
......@@ -57,11 +65,9 @@ public class AnalysisFile {
String s1 = strings.get(0);
depTree.setDepName(s1);
map.put(0,depTree);
System.out.println(strings.size());
int now = 0;
for (int i = 1; i <= strings.size()-1; i++) {
DepTree depTree1 = new DepTree();
System.out.println(i);
String s = strings.get(i);
for (Rule rule : ruleList) {
if(KmpUtil.kmpMatch(s,rule.getTarget())>0){
......@@ -93,13 +99,61 @@ public class AnalysisFile {
}
map.put(i1+3,depTree1);
now = i1;
//将依赖全部放进规则库中
String[] split = s.substring(i1+1).replaceAll("\\|","").replaceAll("\\+","")
.replaceAll(" ","")
.replaceAll("\\\\","")
.split(":");
StringBuilder stringBuffer = new StringBuilder();
for (int i2 = 0; i2 < 2; i2++) {
if(stringBuffer.length()==0){
stringBuffer.append(split[i2]).append(":");
}else{
stringBuffer.append(split[i2]);
}
}
map1.put(stringBuffer.toString(),"");
}
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder stringBuilder = new StringBuilder();
Set<String> strings = map1.keySet();
for (String string : strings) {
StringBuilder append = stringBuilder.append(string).append(":").append(techId);
if(!ruleMap.containsKey(append.toString())){
Rule rule1 = new Rule();
rule1.setId(UUIDUtil.getUUID());
rule1.setTechnologyId(techId);
rule1.setTarget(string);
rule1.setSuffix("xml");
rules.add(rule1);
Rule rule2 = new Rule();
rule2.setId(UUIDUtil.getUUID());
rule2.setTechnologyId(techId);
rule2.setTarget(string);
rule2.setSuffix("gradle");
rules.add(rule2);
ruleMap.put(append.toString(),rule1);
}
append.delete(0,append.length());
}
ruleDao.saveAll(rules);
technologyAndReportDao.saveAll(technologyAndReports);
return depTreePom;
}
public void setMap(HashMap<String,Rule> map){
this.ruleMap=map;
}
public static void main(String[] args) {
String s = "\\gfdgdfgdfgd";
System.out.println(s.replaceAll(
"\\\\",""));
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(1).append(2).append("fdf");
stringBuilder.delete(0,stringBuilder.length());
System.out.println(stringBuilder.toString());
}
}
......@@ -71,8 +71,8 @@ public class BudgetUitl {
//带修正系数资金
ArrayList<String> strings = new ArrayList<>();
Double v1 = v;
strings.add("安全能力");
strings.add("容灾能力");
//strings.add("安全能力");
//strings.add("容灾能力");
strings.add("架构");
List<CoefficientModel> nameIn = coefficientModelDao.findAllByNameInAndScaleEquals(strings,scale);
for (CoefficientModel model : nameIn) {
......
......@@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.IOException;
import java.nio.charset.MalformedInputException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
......@@ -28,7 +29,6 @@ import java.util.stream.Collectors;
@AllArgsConstructor
@NoArgsConstructor
@Service
@Scope("prototype")
public class Inspector {
@Autowired
......@@ -57,6 +57,11 @@ public class Inspector {
* 利率参数
*/
private InspectParameter inspectParameter;
/**
* 利率参数
*/
private String techId;
/**
* 报告对象
*/
......@@ -246,9 +251,8 @@ public class Inspector {
// TODO: 2020-02-28 解析maven树文件,设置依赖保存到redis
report.setManager(Report.DependenceManagement.MAVEN.name());
File file = mavenUtil.genTreeFile(path.toString());
DepTreePom depTreePom = analysisFile.parseTreeFile(report.getId(),file.getPath(),ruleList);
DepTreePom depTreePom = analysisFile.parseTreeFile(report.getId(),file.getPath(),ruleList,techId);
depTreeVo.getDepTreeList().add(depTreePom.getDepTree());
//savetoredis
redisUtil.set(report.getId(),depTreeVo);
}
......@@ -305,6 +309,8 @@ public class Inspector {
}
}
}
} catch (MalformedInputException e){
} catch (IOException e) {
e.printStackTrace();
}
......@@ -318,9 +324,12 @@ public class Inspector {
fund+=technology.getFund();
}
//计算预算,三种预算
parameterDao.save(inspectParameter);
List<Budget> budget = budgetUitl.getBudget(report.getId(),fund, inspectParameter);
budgetDao.saveAll(budget);
if(inspectParameter!=null){
List<Budget> budget = budgetUitl.getBudget(report.getId(),fund, inspectParameter);
budgetDao.saveAll(budget);
inspectParameter.setId(UUIDUtil.getUUID());
parameterDao.save(inspectParameter);
}
// TODO: 2020-02-28 生成报告,返回地址 report.setsourceaddress;
return report;
}
......
......@@ -31,7 +31,6 @@ public class MavenUtil {
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
e.printStackTrace();
}
return new File(treeFile);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论