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

mcj:问题包导入删除

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