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

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

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