提交 31d113b6 authored 作者: 马晨俊's avatar 马晨俊

mcj:新增增加多个规则逻辑,删除入参保存逻辑

上级 de0279e0
...@@ -27,12 +27,13 @@ import java.util.Map; ...@@ -27,12 +27,13 @@ import java.util.Map;
/** /**
* 评估接口 * 评估接口
*
* @author mcj * @author mcj
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/inspect") @RequestMapping("/inspect")
@Api(value = "评估接口管理接口",description = "评估管理接口,提供页面的增、删、改、查") @Api(value = "评估接口管理接口", description = "评估管理接口,提供页面的增、删、改、查")
public class InspectController { public class InspectController {
@Autowired @Autowired
private InspectService inspectService; private InspectService inspectService;
...@@ -45,53 +46,49 @@ public class InspectController { ...@@ -45,53 +46,49 @@ public class InspectController {
@Autowired @Autowired
private ReportService reportService; private ReportService reportService;
/** /**
* 上传代码进行评估 * 上传代码进行评估
*
* @param years 系统开发时间 * @param years 系统开发时间
* @param systemFund 系统开发费用 * @param systemFund 系统开发费用
* @param modules 模块数 * @param modules 模块数
* @param valid 预算数据是否可用 * @param valid 预算数据是否可用
* @param framework 架构 * @param framework 架构
* @param safety 安全能力 * @param safety 安全能力
* @param disaster 容灾能力 * @param disaster 容灾能力
* @param data 数据量 * @param data 数据量
* @param admin 是否管理员 * @param admin 是否管理员
* @param multfile 文件 * @param multfile 文件
* @return * @return
* @throws IOException * @throws IOException
*/ */
@PostMapping("/path") @PostMapping("/path")
@ApiOperation("上传代码进行评估") @ApiOperation("上传代码进行评估")
public ResponseEntity inspect(Integer years,Integer systemFund,Integer modules public ResponseEntity inspect(Integer years, Integer systemFund, Integer modules
,String valid,Integer framework,Integer safety,Integer disaster,Integer data , String valid, Integer framework, Integer safety, Integer disaster, Integer data
,Integer admin,String projectName,Integer tables,String databaseType,Integer method,String username, MultipartFile multfile) throws IOException { , Integer admin, String projectName, Integer tables, String databaseType, Integer method, String username, MultipartFile multfile) throws IOException {
File file = FileUtil.saveToLocal(multfile); File file = FileUtil.saveToLocal(multfile);
log.info("inspect:代码解压完成,地址为{}",file.getCanonicalPath()); log.info("inspect:代码解压完成,地址为{}", file.getCanonicalPath());
InspectParameter inspectParameter = parameterService.getParameterByUsername(username); InspectParameter inspectParameter = new InspectParameter();
if(inspectParameter==null){ inspectParameter.setUsername(username);
inspectParameter = new InspectParameter(); inspectParameter.setSystemFund(systemFund);
inspectParameter.setUsername(username); inspectParameter.setModules(modules);
inspectParameter.setSystemFund(systemFund); inspectParameter.setSafety(safety);
inspectParameter.setModules(modules); inspectParameter.setTables(tables);
inspectParameter.setSafety(safety); inspectParameter.setValid(valid);
inspectParameter.setTables(tables); inspectParameter.setYears(years);
inspectParameter.setValid(valid); inspectParameter.setDisaster(disaster);
inspectParameter.setYears(years); inspectParameter.setData(data);
inspectParameter.setDisaster(disaster); inspectParameter.setFramework(framework);
inspectParameter.setData(data); inspectParameter.setId(UUIDUtil.getUUID());
inspectParameter.setFramework(framework); inspectParameter.setAdmin(admin);
inspectParameter.setId(UUIDUtil.getUUID()); inspectParameter.setSystemFund(systemFund);
inspectParameter.setAdmin(admin);
}
inspectParameter.setRecastMethod(method); inspectParameter.setRecastMethod(method);
inspectParameter.setSourceAddress(file.getCanonicalPath()); inspectParameter.setSourceAddress(file.getCanonicalPath());
ReportVo reportVo = new ReportVo(); ReportVo reportVo = new ReportVo();
int count = technologyService.findAllTechnologyCount();
reportVo.setTechnologiesNum(count);
int support = technologyService.findAllTechnologyNotSupport();
reportVo.setTechnologiesRepair(support);
reportVo.setId(RandomUtil.getRandom()); reportVo.setId(RandomUtil.getRandom());
reportVo.setUploadType("文件上传"); reportVo.setUploadType("文件上传");
...@@ -99,21 +96,25 @@ public class InspectController { ...@@ -99,21 +96,25 @@ public class InspectController {
reportVo.setProjectName(projectName); reportVo.setProjectName(projectName);
reportVo.setSourceAddress(file.getCanonicalPath()); reportVo.setSourceAddress(file.getCanonicalPath());
reportVo.setDatabaseType(databaseType); reportVo.setDatabaseType(databaseType);
//查找当前用户的参数是否存在 ReportVo inspect = inspectService.inspect(reportVo, inspectParameter);
ReportVo inspect = inspectService.inspect(reportVo,inspectParameter);
int count = technologyService.findAllTechnologyCount();
reportVo.setTechnologiesNum(count);
int support = technologyService.findAllTechnologyNotSupport();
reportVo.setTechnologiesRepair(support);
log.info("inspect:代码评估完成"); log.info("inspect:代码评估完成");
Map map=new HashMap(); Map map = new HashMap();
map.put("inspect",inspect); map.put("inspect", inspect);
map.put("time",TimeUtil.getTime()); map.put("time", TimeUtil.getTime());
HashMap<String, List<Warn>> warnMap = inspect.getWarnDetails(); HashMap<String, List<Warn>> warnMap = inspect.getWarnDetails();
List<Technology> technologies = inspect.getTechnologies(); List<Technology> technologies = inspect.getTechnologies();
Map techMap=new HashMap(); Map techMap = new HashMap();
for (Technology technology : technologies) { for (Technology technology : technologies) {
techMap.put(technology.getTechnologyName(),technology.getSupport()); techMap.put(technology.getTechnologyName(), technology.getSupport());
} }
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);
...@@ -137,13 +138,14 @@ public class InspectController { ...@@ -137,13 +138,14 @@ public class InspectController {
/** /**
* git下载代码进行评估 * git下载代码进行评估
*
* @param inspectParameter 封装 * @param inspectParameter 封装
* @return * @return
*/ */
@PostMapping("/git") @PostMapping("/git")
@ApiOperation("git下载代码进行评估") @ApiOperation("git下载代码进行评估")
public ResponseEntity inspect1(@RequestBody InspectParameter inspectParameter){ public ResponseEntity inspect1(@RequestBody InspectParameter inspectParameter) {
String path = GitLabUtil.downLoadProject(inspectParameter.getGitAddress(),inspectParameter.getGitName()); String path = GitLabUtil.downLoadProject(inspectParameter.getGitAddress(), inspectParameter.getGitName());
inspectParameter.setId(UUIDUtil.getUUID()); inspectParameter.setId(UUIDUtil.getUUID());
inspectParameter.setSourceAddress(path); inspectParameter.setSourceAddress(path);
ReportVo reportVo = new ReportVo(); ReportVo reportVo = new ReportVo();
......
...@@ -34,4 +34,14 @@ public class Budget { ...@@ -34,4 +34,14 @@ public class Budget {
*/ */
private String fundDetail; private String fundDetail;
/**
* 占比
*/
private double proportion;
/**
* 系统开发费用
*/
private Integer sysFund;
} }
...@@ -16,5 +16,9 @@ public class BudgetVo { ...@@ -16,5 +16,9 @@ public class BudgetVo {
private List<Budget> budget = new ArrayList<>(); private List<Budget> budget = new ArrayList<>();
/**
* 修正系数
*/
private List<CoefficientModelVo> coefficientModelVos = new ArrayList<>(); private List<CoefficientModelVo> coefficientModelVos = new ArrayList<>();
} }
...@@ -13,8 +13,8 @@ import java.util.List; ...@@ -13,8 +13,8 @@ import java.util.List;
*/ */
@Data @Data
public class DependencyVo implements Serializable { public class DependencyVo implements Serializable {
private List<ProjectPom> depTreeList = new ArrayList<>(); private List<ProjectPom> depTreeList = new ArrayList<>(64);
private List<ProjectPom> frontend = new ArrayList<>(); private List<ProjectPom> frontend = new ArrayList<>(64);
public void add(ProjectPom projectPom){ public void add(ProjectPom projectPom){
depTreeList.add(projectPom); depTreeList.add(projectPom);
......
...@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,7 +15,6 @@ 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;
...@@ -50,8 +49,8 @@ public class Inspector { ...@@ -50,8 +49,8 @@ public class Inspector {
private ParameterDao parameterDao; private ParameterDao parameterDao;
private DependencyVo dependencyVo = new DependencyVo(); private DependencyVo dependencyVo = new DependencyVo();
private ArrayList<Rule> rules = new ArrayList<Rule>(); private ArrayList<Rule> rules = new ArrayList<>(512);
private ArrayList<Warn> warns = new ArrayList<>(); private ArrayList<Warn> warns = new ArrayList<>(64);
/** /**
* 添加规则时去重使用 * 添加规则时去重使用
...@@ -61,7 +60,7 @@ public class Inspector { ...@@ -61,7 +60,7 @@ public class Inspector {
* <p> * <p>
* value:随意 * value:随意
*/ */
private HashMap<String, Rule> ruleMap = new HashMap<>(); private HashMap<String, Rule> ruleMap = new HashMap<>(512);
/** /**
* 支持的国产化技术 * 支持的国产化技术
...@@ -92,14 +91,14 @@ public class Inspector { ...@@ -92,14 +91,14 @@ public class Inspector {
* key:java * key:java
* value:10 * value:10
*/ */
private Map<String, Counter> languageMatchMap = new HashMap<>(); private Map<String, Counter> languageMatchMap = new HashMap<>(16);
/** /**
* 后缀语言 * 后缀语言
* key:properties * key:properties
* value:[{/Users/path},{/Users/path}] * value:[{/Users/path},{/Users/path}]
*/ */
private Map<String, Language> suffixLanguageMapping = new HashMap<>(); private Map<String, Language> suffixLanguageMapping = new HashMap<>(16);
/** /**
* 规则列表 * 规则列表
...@@ -111,9 +110,9 @@ public class Inspector { ...@@ -111,9 +110,9 @@ public class Inspector {
* xml:list【路径】 * xml:list【路径】
*/ */
private Map<String, List<Path>> configFileTypePathsMapping = new HashMap<>(); private Map<String, List<Path>> configFileTypePathsMapping = new HashMap<>(512);
private Map<String, List<Path>> ruleSuffixFileMap; private Map<String, List<Path>> ruleSuffixFilePathMap;
private Map<String, List<Rule>> ruleSuffixMap; private Map<String, List<Rule>> ruleSuffixMap;
/** /**
...@@ -121,7 +120,7 @@ public class Inspector { ...@@ -121,7 +120,7 @@ public class Inspector {
* key:技术id * key:技术id
* value:Technology * value:Technology
*/ */
private Map<String, Technology> technologyHashMap = new HashMap<>(); private Map<String, Technology> technologyHashMap = new HashMap<>(64);
/** /**
* 统计各后缀文件路径与出现次数,顺便解析jar与js文件 * 统计各后缀文件路径与出现次数,顺便解析jar与js文件
...@@ -136,21 +135,19 @@ public class Inspector { ...@@ -136,21 +135,19 @@ public class Inspector {
* @return * @return
*/ */
public ReportVo inspect() { public ReportVo inspect() {
ruleSuffixFileMap = new HashMap<>(); ruleSuffixFilePathMap = new HashMap<>();
ruleSuffixMap = new HashMap<>(); ruleSuffixMap = new HashMap<>();
warns.clear(); warns.clear();
rules.clear(); rules.clear();
//查询技术,构造支持与非支持技术对象 //查询技术,构造支持与非支持技术对象
findExistTechnology(); findExistTechnology();
statisticsLanguage(); statisticsLanguage();
this.ruleList = ruleDao.findAll();
//统计项目组成文件构成
//统计配置文件地址
statisticsConfigFile(); statisticsConfigFile();
this.ruleList = ruleDao.findAll();
//根据后缀名,收集文件进行操作 //根据后缀名,收集文件进行操作
for (Rule rule : ruleList) { for (Rule rule : ruleList) {
if (!ruleSuffixFileMap.containsKey(rule.getSuffix())) { if (!ruleSuffixFilePathMap.containsKey(rule.getSuffix())) {
ruleSuffixFileMap.put(rule.getSuffix(), new ArrayList<>()); ruleSuffixFilePathMap.put(rule.getSuffix(), new ArrayList<>());
} }
} }
try { try {
...@@ -167,9 +164,9 @@ public class Inspector { ...@@ -167,9 +164,9 @@ public class Inspector {
configFileMatcherSuffixMapping.put(aDefault.getPathMatcher("glob:**/*." + s), s); configFileMatcherSuffixMapping.put(aDefault.getPathMatcher("glob:**/*." + s), s);
} }
//构造规则后缀的正则表达式 //构造规则后缀的正则表达式
Map<PathMatcher, String> ruleSuffix = new HashMap<>(16); Map<PathMatcher, String> ruleSuffixMap = new HashMap<>(16);
for (String s : ruleSuffixFileMap.keySet()) { for (String s : ruleSuffixFilePathMap.keySet()) {
ruleSuffix.put(aDefault.getPathMatcher("glob:**/*." + s), s); ruleSuffixMap.put(aDefault.getPathMatcher("glob:**/*." + s), s);
} }
//文件读取 //文件读取
Files.walkFileTree(Paths.get(inspectParameter.getSourceAddress()), new FileVisitor<Path>() { Files.walkFileTree(Paths.get(inspectParameter.getSourceAddress()), new FileVisitor<Path>() {
...@@ -197,10 +194,10 @@ public class Inspector { ...@@ -197,10 +194,10 @@ public class Inspector {
configFileTypePathsMapping.get(entry.getValue()).add(file); configFileTypePathsMapping.get(entry.getValue()).add(file);
} }
} }
for (Map.Entry<PathMatcher, String> entry : ruleSuffix.entrySet()) { for (Map.Entry<PathMatcher, String> entry : ruleSuffixMap.entrySet()) {
//通过规则匹配后缀正则表达式匹配,记录匹配上的文件地址 //通过规则匹配后缀正则表达式匹配,记录匹配上的文件地址
if (entry.getKey().matches(file)) { if (entry.getKey().matches(file)) {
ruleSuffixFileMap.get(entry.getValue()).add(file); ruleSuffixFilePathMap.get(entry.getValue()).add(file);
} }
} }
//检查到普通jar包 //检查到普通jar包
...@@ -272,10 +269,8 @@ public class Inspector { ...@@ -272,10 +269,8 @@ public class Inspector {
public ReportVo analysis() { public ReportVo analysis() {
DependencyVo dependencyVo = new DependencyVo(); DependencyVo dependencyVo = new DependencyVo();
setReportLanguageAndFrame(); setReportLanguageAndFrame();
//查询所有规则 //查询所有规则
ruleTransform(report.getRecastMethod()); ruleTransform(report.getRecastMethod());
//解析配置文件集合 //解析配置文件集合
for (Map.Entry<String, List<Path>> entry : configFileTypePathsMapping.entrySet()) { for (Map.Entry<String, List<Path>> entry : configFileTypePathsMapping.entrySet()) {
switch (entry.getKey()) { switch (entry.getKey()) {
...@@ -317,7 +312,7 @@ public class Inspector { ...@@ -317,7 +312,7 @@ public class Inspector {
} }
} }
//指定后缀到文件匹配关键字 //指定后缀到文件匹配关键字
for (Map.Entry<String, List<Path>> entry : ruleSuffixFileMap.entrySet()) { for (Map.Entry<String, List<Path>> entry : ruleSuffixFilePathMap.entrySet()) {
//entry,key为后缀,value为文件列表 //entry,key为后缀,value为文件列表
String key = entry.getKey(); String key = entry.getKey();
//从ruleSuffixList获取指定后缀的规则列表 //从ruleSuffixList获取指定后缀的规则列表
...@@ -360,7 +355,7 @@ public class Inspector { ...@@ -360,7 +355,7 @@ public class Inspector {
//填充依赖 //填充依赖
report.setDependencyVo(dependencyVo); report.setDependencyVo(dependencyVo);
//数据转换 //数据转换
HashMap<String, Technology> map = new HashMap<>(); HashMap<String, Technology> map = new HashMap<>(64);
for (Technology technology1 : allById) { for (Technology technology1 : allById) {
map.put(technology1.getId(), technology1); map.put(technology1.getId(), technology1);
} }
...@@ -391,9 +386,10 @@ public class Inspector { ...@@ -391,9 +386,10 @@ public class Inspector {
//设置是否需要重构 //设置是否需要重构
if (languageMatchMap.get("jsp").i == 0 & languageMatchMap.get("java").i == 0) { if (languageMatchMap.get("jsp").i == 0 & languageMatchMap.get("java").i == 0) {
report.setRecastMethod(RecastMethod.适配重构.getStatus()); report.setRecastMethod(RecastMethod.适配重构.getStatus());
log.info("inspect:代码解析完成,建议进行"); log.info("inspect:代码解析完成,建议进行适配重构");
} else { } else {
report.setRecastMethod(RecastMethod.代码修改.getStatus()); report.setRecastMethod(RecastMethod.代码修改.getStatus());
log.info("inspect:代码解析完成,建议进行代码修改");
} }
} }
...@@ -419,12 +415,6 @@ public class Inspector { ...@@ -419,12 +415,6 @@ public class Inspector {
for (Technology technology : technologies) { for (Technology technology : technologies) {
technologyHashMap.put(technology.getId(), technology); technologyHashMap.put(technology.getId(), technology);
} }
//根据后缀名,收集文件进行操作
for (Rule rule : ruleList) {
if (!ruleSuffixFileMap.containsKey(rule.getSuffix())) {
ruleSuffixFileMap.put(rule.getSuffix(), new ArrayList<>());
}
}
//根据后缀名进行规则收集 //根据后缀名进行规则收集
for (Rule rule : ruleList) { for (Rule rule : ruleList) {
if (!ruleSuffixMap.containsKey(rule.getSuffix())) { if (!ruleSuffixMap.containsKey(rule.getSuffix())) {
...@@ -434,6 +424,15 @@ public class Inspector { ...@@ -434,6 +424,15 @@ public class Inspector {
ruleSuffixMap.get(rule.getSuffix()).add(rule); ruleSuffixMap.get(rule.getSuffix()).add(rule);
} }
} }
ArrayList<String> keys = new ArrayList<>();
for (String s : ruleSuffixFilePathMap.keySet()) {
if(!ruleSuffixMap.containsKey(s)){
keys.add(s);
}
}
for (String key : keys) {
ruleSuffixFilePathMap.remove(key);
}
} }
private void statisticsConfigFile() { private void statisticsConfigFile() {
......
...@@ -126,6 +126,8 @@ public class BudgetUitl { ...@@ -126,6 +126,8 @@ public class BudgetUitl {
inspectParameter.setProportion(refactorProportion); inspectParameter.setProportion(refactorProportion);
Budget codeRefactor = new Budget(); Budget codeRefactor = new Budget();
codeRefactor.setBudgetName("代码修改预算"); codeRefactor.setBudgetName("代码修改预算");
codeRefactor.setProportion(refactorProportion);
codeRefactor.setSysFund(systemFund);
double fundNotRepair = inspectParameter.getProportion() * pow * systemFund + fund; double fundNotRepair = inspectParameter.getProportion() * pow * systemFund + fund;
double fundRepair=fundNotRepair*coefficient; double fundRepair=fundNotRepair*coefficient;
if(fundNotRepair<fundRepair){ if(fundNotRepair<fundRepair){
...@@ -143,7 +145,9 @@ public class BudgetUitl { ...@@ -143,7 +145,9 @@ public class BudgetUitl {
double refactorProportion1 = Double.valueOf(doubleHashMap.get(2)); double refactorProportion1 = Double.valueOf(doubleHashMap.get(2));
inspectParameter.setProportion(refactorProportion1); inspectParameter.setProportion(refactorProportion1);
Budget codeRefactor1 = new Budget(); Budget codeRefactor1 = new Budget();
codeRefactor1.setProportion(refactorProportion1);
codeRefactor1.setBudgetName("代码重构预算"); codeRefactor1.setBudgetName("代码重构预算");
codeRefactor1.setSysFund(systemFund);
double fundNotRepair1 = inspectParameter.getProportion() * pow * systemFund + fund; double fundNotRepair1 = inspectParameter.getProportion() * pow * systemFund + fund;
double fundRepair1=fundNotRepair1*coefficient; double fundRepair1=fundNotRepair1*coefficient;
if(fundNotRepair1<fundRepair1){ if(fundNotRepair1<fundRepair1){
...@@ -162,7 +166,9 @@ public class BudgetUitl { ...@@ -162,7 +166,9 @@ public class BudgetUitl {
double refactorProportion = Double.valueOf(doubleHashMap.get(3)); double refactorProportion = Double.valueOf(doubleHashMap.get(3));
inspectParameter.setProportion(refactorProportion); inspectParameter.setProportion(refactorProportion);
Budget codeRefactor1 = new Budget(); Budget codeRefactor1 = new Budget();
codeRefactor1.setProportion(refactorProportion);
codeRefactor1.setBudgetName("代码修改预算"); codeRefactor1.setBudgetName("代码修改预算");
codeRefactor1.setSysFund(systemFund);
double fundNotRepair1 = inspectParameter.getProportion() * pow * systemFund + fund; double fundNotRepair1 = inspectParameter.getProportion() * pow * systemFund + fund;
double fundRepair1=fundNotRepair1*coefficient; double fundRepair1=fundNotRepair1*coefficient;
if(fundNotRepair1<fundRepair1){ if(fundNotRepair1<fundRepair1){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论