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

git update 规则增删改查

上级 fa64da32
com.zjty:inspect:jar:0.0.1-SNAPSHOT
+- org.eclipse.jgit:org.eclipse.jgit:jar:5.2.1.201812262042-r:compile
+- org.springframework.boot:spring-boot-starter-data-redis:jar:2.1.6.RELEASE:compile
| +- org.springframework.data:spring-data-redis:jar:2.1.9.RELEASE:compile
| | +- org.springframework.data:spring-data-keyvalue:jar:2.1.9.RELEASE:compile
| | +- org.springframework:spring-tx:jar:5.1.8.RELEASE:compile
| | +- org.springframework:spring-oxm:jar:5.1.8.RELEASE:compile
| | +- org.springframework:spring-aop:jar:5.1.8.RELEASE:compile
| | +- org.springframework:spring-context-support:jar:5.1.8.RELEASE:compile
| | \- org.slf4j:slf4j-api:jar:1.7.26:compile
| \- io.lettuce:lettuce-core:jar:5.1.7.RELEASE:compile
| +- io.netty:netty-common:jar:4.1.36.Final:compile
| +- io.netty:netty-handler:jar:4.1.36.Final:compile
| | +- io.netty:netty-buffer:jar:4.1.36.Final:compile
| | \- io.netty:netty-codec:jar:4.1.36.Final:compile
| +- io.netty:netty-transport:jar:4.1.36.Final:compile
| | \- io.netty:netty-resolver:jar:4.1.36.Final:compile
| \- io.projectreactor:reactor-core:jar:3.2.10.RELEASE:compile
| \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
+- org.springframework.boot:spring-boot-starter:jar:2.1.6.RELEASE:compile
| +- org.springframework.boot:spring-boot:jar:2.1.6.RELEASE:compile
| | \- org.springframework:spring-context:jar:5.1.8.RELEASE:compile
| +- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.6.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter-logging:jar:2.1.6.RELEASE:compile
| | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
| | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
| | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.2:compile
| | | \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
| | \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
| +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
| \- org.springframework:spring-core:jar:5.1.8.RELEASE:compile
| \- org.springframework:spring-jcl:jar:5.1.8.RELEASE:compile
+- org.apache.maven.shared:maven-invoker:jar:3.0.1:compile
| +- org.apache.maven.shared:maven-shared-utils:jar:3.2.1:compile
| | \- commons-io:commons-io:jar:2.5:compile
| \- org.codehaus.plexus:plexus-component-annotations:jar:1.7.1:compile
+- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.1.6.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter-aop:jar:2.1.6.RELEASE:compile
| | \- org.aspectj:aspectjweaver:jar:1.9.4:compile
| +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.1.6.RELEASE:compile
| | +- com.zaxxer:HikariCP:jar:3.2.0:compile
| | \- org.springframework:spring-jdbc:jar:5.1.8.RELEASE:compile
| +- javax.transaction:javax.transaction-api:jar:1.3:compile
| +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
| | \- javax.activation:javax.activation-api:jar:1.2.0:compile
| +- org.hibernate:hibernate-core:jar:5.3.10.Final:compile
| | +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
| | +- javax.persistence:javax.persistence-api:jar:2.2:compile
| | +- org.javassist:javassist:jar:3.23.2-GA:compile
| | +- net.bytebuddy:byte-buddy:jar:1.9.13:compile
| | +- antlr:antlr:jar:2.7.7:compile
| | +- org.jboss:jandex:jar:2.0.5.Final:compile
| | +- com.fasterxml:classmate:jar:1.4.0:compile
| | +- org.dom4j:dom4j:jar:2.1.1:compile
| | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
| +- org.springframework.data:spring-data-jpa:jar:2.1.9.RELEASE:compile
| | +- org.springframework.data:spring-data-commons:jar:2.1.9.RELEASE:compile
| | +- org.springframework:spring-orm:jar:5.1.8.RELEASE:compile
| | \- org.springframework:spring-beans:jar:5.1.8.RELEASE:compile
| \- org.springframework:spring-aspects:jar:5.1.8.RELEASE:compile
+- org.springframework.boot:spring-boot-starter-web:jar:2.1.6.RELEASE:compile
| +- org.springframework.boot:spring-boot-starter-json:jar:2.1.6.RELEASE:compile
| | +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile
| | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
| | | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.9:compile
| | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.9:compile
| | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.9:compile
| | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.9:compile
| +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.6.RELEASE:compile
| | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.21:compile
| | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.21:compile
| | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.21:compile
| +- org.hibernate.validator:hibernate-validator:jar:6.0.17.Final:compile
| | \- javax.validation:validation-api:jar:2.0.1.Final:compile
| +- org.springframework:spring-web:jar:5.1.8.RELEASE:compile
| \- org.springframework:spring-webmvc:jar:5.1.8.RELEASE:compile
| \- org.springframework:spring-expression:jar:5.1.8.RELEASE:compile
+- com.alibaba:fastjson:jar:1.2.61:compile
+- mysql:mysql-connector-java:jar:8.0.16:compile
+- org.projectlombok:lombok:jar:1.18.8:compile
+- org.springframework.boot:spring-boot-starter-test:jar:2.1.6.RELEASE:test
| +- org.springframework.boot:spring-boot-test:jar:2.1.6.RELEASE:test
| +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.6.RELEASE:test
| +- com.jayway.jsonpath:json-path:jar:2.4.0:test
| | \- net.minidev:json-smart:jar:2.3:test
| | \- net.minidev:accessors-smart:jar:1.2:test
| | \- org.ow2.asm:asm:jar:5.0.4:test
| +- junit:junit:jar:4.12:test
| +- org.assertj:assertj-core:jar:3.11.1:test
| +- org.mockito:mockito-core:jar:2.23.4:test
| | +- net.bytebuddy:byte-buddy-agent:jar:1.9.13:test
| | \- org.objenesis:objenesis:jar:2.6:test
| +- org.hamcrest:hamcrest-core:jar:1.3:test
| +- org.hamcrest:hamcrest-library:jar:1.3:test
| +- org.skyscreamer:jsonassert:jar:1.5.0:test
| | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
| +- org.springframework:spring-test:jar:5.1.8.RELEASE:test
| \- org.xmlunit:xmlunit-core:jar:2.6.2:test
\- org.yaml:snakeyaml:jar:1.25:compile
......@@ -27,12 +27,20 @@
<version>5.2.1.201812262042-r</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
......
package com.zjty.inspect.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @author Mcj
* @date 2020-03-02 11:27
*/
@Configuration
public class RedisConfig {
// @Bean(name = "defaultRedisTpl")
// public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
// RedisTemplate<String, Object> template = new RedisTemplate<>();
// template.setConnectionFactory(factory);
//
// Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
// ObjectMapper om = new ObjectMapper();
// om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
// jackson2JsonRedisSerializer.setObjectMapper(om);
// // value序列化方式采用jackson
// template.setValueSerializer(jackson2JsonRedisSerializer);
//
// template.setKeySerializer(new StringRedisSerializer());
// template.setValueSerializer(jackson2JsonRedisSerializer);
// return template;
// }
//
//
//
// @Bean
// public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
// //获得redis缓存管理类
// RedisCacheManager redisCacheManager = RedisCacheManager.create(connectionFactory);
// // 开启使用缓存名称做为key前缀(这样所有同名缓存会整理在一起比较容易查找)
//
// return redisCacheManager;
// }
}
......@@ -2,11 +2,16 @@ package com.zjty.inspect.controller;
import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.service.InspectService;
import com.zjty.inspect.utils.FileUtil;
import com.zjty.inspect.utils.MavenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
/**
* 评估接口
* @author mcj
......@@ -20,14 +25,17 @@ public class InspectController {
/**
* 上传代码进行评估
* @param path
* @param inspectParameter
* @return
*/
@GetMapping("/path")
public ResponseEntity inspect(@RequestBody InspectParameter path, MultipartFile file){
@PostMapping("/path")
public ResponseEntity inspect(@RequestBody InspectParameter inspectParameter, MultipartFile file) {
//得到压缩包,进行解压
//inspectService.inspect(inspectParameter),解析
//File file1 = file.getResource().getFile();
//String path = FileUtil.unZip(file1, "/Users/mcj/IdeaProjects/t5");
File file2 = new File("/Users/mcj/IdeaProjects/inspect");
String path1 = file2.getPath();
inspectService.inspect(inspectParameter,path1);
return ResponseEntity.ok(200);
}
......@@ -36,9 +44,13 @@ public class InspectController {
* @param path
* @return
*/
@PostMapping
public ResponseEntity inspect1(String path){
@PostMapping("/git")
public ResponseEntity inspect1(@RequestBody InspectParameter inspectParameter,String path){
inspectService.inspect(inspectParameter,path);
System.out.println(path);
return ResponseEntity.ok(200);
}
}
package com.zjty.inspect.controller;
import com.zjty.inspect.entity.ReportVo;
import com.zjty.inspect.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 报告
* @author Mcj
* @date 2020-02-27 09:58
*/
@RequestMapping("/report")
@RestController
public class ReportController {
@Autowired
private ReportService reportService;
/**
* 历史报告查看
* @return 历史报告
*/
@GetMapping
public ResponseEntity history(){
List<ReportVo> history = reportService.getHistory();
return ResponseEntity.ok(history);
}
}
package com.zjty.inspect.controller;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* 规则库设置
* @author Mcj
* @date 2020-02-26 14:42
*/
@RestController
@RequestMapping("/rule")
public class RuleController {
@Autowired
private RuleService ruleService;
/**
* 新增规则
* @param ruleQo 规则封装
* @return
*/
@PostMapping
public ResponseEntity rule(@RequestBody RuleQo ruleQo){
ruleService.addRule(ruleQo);
return ResponseEntity.ok(200);
}
/**
* 查询所有规则
* @return 规则
*/
@GetMapping
public ResponseEntity getRules(){
return ResponseEntity.ok(ruleService.findAll());
}
}
package com.zjty.inspect.controller;
import com.zjty.inspect.entity.TechnologyQo;
import com.zjty.inspect.service.TechnologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* 适配技术
* @author Mcj
* @date 2020-02-29 16:10
*/
@RequestMapping("/technology")
@RestController
public class TechnologyController {
@Autowired
private TechnologyService technologyService;
/**
* 获取所有关键技术
* @return List
*/
@GetMapping
public ResponseEntity getTechnologies(){
return ResponseEntity.ok(technologyService.findAllTechnology());
}
/**
* 添加关键技术
* @return List
*/
@PostMapping
public ResponseEntity addTechnologies(@RequestBody TechnologyQo technologyQo){
technologyService.addAdvice(technologyQo);
return ResponseEntity.ok(200);
}
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.Budget;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
*
* 预算
* @author mcj
*/
public interface BudgetDao extends JpaRepository<Budget,String> {
/**
* 根据报告id查询预算
* @param id 报告id
* @return
*/
List<Budget> findAllByReportIdEquals(String id);
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.CoefficientModel;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CoefficientModelDao extends JpaRepository<CoefficientModel,String> {
/**
* 根据范围查询系数
* @param name 内容名称
* @param scale 规模
* @return
*/
List<CoefficientModel> findAllByNameInAndScaleEquals(List<String> name,Integer scale);
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.InspectParameter;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ParameterDao extends JpaRepository<InspectParameter,String> {
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.Report;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ReportDao extends JpaRepository<Report,String> {
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.Rule;
import org.springframework.data.jpa.repository.JpaRepository;
public interface RuleDao extends JpaRepository<Rule,String> {
/**
* 根据目标关键字查询规则
* @param target 目标关键字
* @return
*/
Rule findAllByTargetEquals(String target);
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.TechnologyAndReport;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* 报告与适配技术中间表
* @author mcj
*/
public interface TechnologyAndReportDao extends JpaRepository<TechnologyAndReport,String> {
/**
* 根据报告id查询规则
* @param id 报告id
* @return list
*/
List<TechnologyAndReport> findAllByReportIdEquals(String id);
}
package com.zjty.inspect.dao;
import com.zjty.inspect.entity.Technology;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TechnologyDao extends JpaRepository<Technology,String> {
/**
* 根据名称查询适配技术
* @param name 适配技术名称
* @return Technology
*/
Technology findAllByTechnologyNameEquals(String name);
}
package com.zjty.inspect.entity;
import lombok.Data;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.sql.Timestamp;
/**
* 预算
* @author Mcj
* @date 2020-02-27 19:05
*/
@Data
@Entity
public class Budget {
@Id
private String id;
/**
* 代码重构预算、代码修改预算、
*/
private String budgetName;
/**
* 资金
*/
private String fund;
/**
* 资金详情
*/
private String fundDetail;
/**
* 关键报告id
*/
private String reportId;
/**
* 数据创建时间
*/
@Column(name="create_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false,updatable = false)
@Generated(GenerationTime.INSERT)
private Timestamp createDate;
/**
* 数据更新时间
*/
@Column(name="update_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false)
@Generated(GenerationTime.ALWAYS)
private Timestamp updateDate;
}
package com.zjty.inspect.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* 系数计算
*
* @author Mcj
*/
@Entity
@Data
public class CoefficientModel {
@Id
private String id;
/**
* 评定名称
*/
private String name;
/**
* 大规模系数 0.1
*/
private Double topCoefficient;
/**
* 中等规模系数 0
*/
private Double mediumCoefficient;
/**
* 小规模系数 -0.1
*/
private Double belowCoefficient;
/**
* 最小值4
*/
private Integer min;
private Integer max;
private Integer scale;
public Double countCoefficient(Double data) {
if(data<min){
return 1+belowCoefficient;
}else if(data>max){
return 1+topCoefficient;
}else {
return 1+mediumCoefficient;
}
}
}
package com.zjty.inspect.entity;
import lombok.Data;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Mcj
* @date 2020-03-01 21:18
*/
@Data
public class DepTreePom {
Set<String> technologies = new HashSet<>();
private String id;
private DepTree depTree;
public void add(String id){
technologies.add(id);
}
}
......@@ -2,13 +2,17 @@ package com.zjty.inspect.entity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 依赖树封装
* @author Mcj
* @date 2020-02-21 20:26
*/
@Data
public class DepTreeAndReport {
public class DepTreeVo {
private String id;
private DepTree depTree;
private List<DepTree> depTreeList = new ArrayList<>();
private List<DepTree> frontend = new ArrayList<>();
}
......@@ -27,12 +27,17 @@ public class InspectParameter {
/**
* 重构占比
*/
private String proportion;
private Double proportion;
/**
* 年利率
*/
private String moneyRate;
private Double moneyRate;
/**
* 软件开发时间
*/
private Integer years;
/**
* 原系统费用
......@@ -49,5 +54,30 @@ public class InspectParameter {
*/
private Integer pageBudget;
/**
* 数据量
*/
private Integer data;
/**
* 架构
*/
private Double framework;
/**
* 安全能力
* 1:无
* 2:弱
* 3:强
*/
private Double safety;
/**
* 容灾
* 1:无0,有+0.05
* 2:有0,无-0.05
* 3:有0,无-0.1
*/
private Double disaster;
}
......@@ -21,52 +21,4 @@ public class PomDependency {
* 2:后端依赖
*/
private Integer type;
/*依赖类型,默认类型是jar。它通常表示依赖的文件的扩展名,但也有例外。一个类型可以被映射成另外一个扩展
名或分类器。类型经常和使用的打包方式对应,尽管这也有例外。一些类型的例子:jar,war,ejb-client和test-jar。
如果设置extensions为 true,就可以在plugin里定义新的类型。所以前面的类型的例子不完整
*/
//private String type;
/*依赖的分类器。分类器可以区分属于同一个POM,但不同构建方式的构件。分类器名被附加到文件名的版本号后面。例如,
如果你想要构建两个单独的构件成JAR,一个使用Java 1.4编译器,另一个使用Java 6编译器,你就可以使用分类器来生
成两个单独的JAR构件
*/
//private String classifier;
/*
依赖范围。在项目发布过程中,帮助决定哪些构件被包括进来。欲知详情请参考依赖机制。
- compile :默认范围,用于编译
- provided:类似于编译,但支持你期待jdk或者容器提供,类似于classpath
- runtime: 在执行时需要使用
- test: 用于test任务时使用
- system: 需要外在提供相应的元素。通过systemPath来取得
- systemPath: 仅用于范围为system。提供相应的路径
- optional: 当项目自身被依赖时,标注依赖是否传递。用于连续依赖时使用
*/
//private String scope;
/*
仅供system范围使用。注意,不鼓励使用这个元素,并且在新的版本中该元素可能被覆盖掉。该元素为依赖规定了文件
系统上的路径。需要绝对路径而不是相对路径。推荐使用属性匹配绝对路径,例如${java.home}
*/
//private String systemPath;
/*
当计算传递依赖时, 从依赖构件列表里,列出被排除的依赖构件集。即告诉maven你只依赖指定的项目,不依赖项目的
依赖。此元素主要用于解决版本冲突问题
*/
//private List<Exclusion> exclusions;
/*
可选依赖,如果你在项目B中把C依赖声明为可选,你就需要在依赖于B的项目(例如项目A)中显式的引用对C的依赖。
可选依赖阻断依赖的传递性
*/
//private String optional;
// private class Exclusion{
// private String artifactId;
// private String groupId;
// }
//private List<PomDependency> parentDependencies;//
//private int reportId;
}
......@@ -63,11 +63,9 @@ public class Report {
@Column(length = 5)
private Integer recastMethod;
/**
* 总资金(万元)
*/
@Column(length = 10)
private Integer fund;
//前端适配预算
//代码重构预算
//代码修改预算
/**
* 数据创建时间
......
package com.zjty.inspect.entity;
import lombok.Data;
import javax.persistence.Column;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* @author Mcj
*/
@Data
public class ReportVo {
/**
* 主键id uuid
*/
private String id;
/**
* git源代码地址
*/
private String gitAddress;
/**
* 架构,整合型还是分离型,根据jsp数量决定
*/
private String framework;
/**
* 代码管理方式,
*/
private String manager;
/**
* 语言
*/
private String language;
/**
* 生成报告存储地址
*/
private String htmlAddress;
/**
* 适配方式
* 1:适配
* 2:重构
*/
@Column(length = 5)
private Integer recastMethod;
/**
* 预算详情
*/
private List<Budget> budgets;
/**
* 依赖
*/
private DepTreeVo depTreeVo;
/**
* 匹配技术列表
*/
private List<TechnologyVo> technologyVos;
/**
* 告警点
*/
private HashMap<String, ArrayList<RuleAndReportVo>> warnDetails;
/**
* 关键技术数量
*/
private Integer warnNum;
}
......@@ -38,6 +38,10 @@ public class Rule {
*/
private String suffix;
/**
* 适配技术id
*/
private String technologyId;
/**
* 数据创建时间
*/
......
package com.zjty.inspect.entity;
import lombok.Data;
/**
* @author Mcj
* @date 2020-02-27 14:42
*/
@Data
public class RuleAndReportVo {
/**
* 发现问题的文件地址
*/
private String filePath;
/**
* 匹配行数
*/
private Integer lineNum;
}
package com.zjty.inspect.entity;
import lombok.Data;
/**
* 规则
* @author Mcj
* @date 2020-02-26 15:08
*/
@Data
public class RuleQo {
/**
* 规则id
*/
private String id;
/**
* 目标关键字
*/
private String target;
/**
* 匹配的文件后缀
*/
private String suffix;
/**
* 适配技术id
*/
private String technologyId;
}
package com.zjty.inspect.entity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @author Mcj
* @date 2020-02-26 23:18
*/
@Data
public class RuleVo {
private String id;
/**
* 目标关键字
*/
private String target;
/**
* 匹配的文件后缀
*/
private String suffix;
/**
* 建议
*/
private String technologyId;
}
package com.zjty.inspect.entity;
import lombok.Data;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.sql.Timestamp;
/**
* 建议
* @author Mcj
* @date 2020-02-26 14:18
*/
@Entity
@Data
public class Technology {
@Id
@Column( length = 48)
private String id;
/**
* 技术名称
*/
private String technologyName;
/**
* 技术建议
*/
private String advice;
/**
* 金额(万元)
*/
private Integer fund;
/**
* 数据创建时间
*/
@Column(name="create_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false,updatable = false)
@Generated(GenerationTime.INSERT)
private Timestamp createDate;
/**
* 数据更新时间
*/
@Column(name="update_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false)
@Generated(GenerationTime.ALWAYS)
private Timestamp updateDate;
}
package com.zjty.inspect.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* 规则与报告中间表
* @author Mcj
* @date 2020-02-26 14:57
*/
@Data
@Entity
public class TechnologyAndReport {
/**
* 主键id
*/
@Id
private String id;
/**
* 报告id
*/
private String reportId;
/**
* 发现问题的文件地址
*/
private String filePath;
/**
* 匹配行数
*/
private Integer lineNum;
/**
* 适配技术id
*/
private String technologyId;
/**
* 关键字id
*/
private String ruleId;
}
package com.zjty.inspect.entity;
import lombok.Data;
/**
* 关键技术qo
* @author Mcj
* @date 2020-02-27 12:01
*/
@Data
public class TechnologyQo {
/**
* 技术名称
*/
private String technologyQoName;
/**
* 适配建议
*/
private String advice;
/**
* 金额
*/
private Integer fund;
}
package com.zjty.inspect.entity;
import lombok.Data;
import java.util.List;
/**
* 建议
* @author Mcj
* @date 2020-02-27 10:31
*/
@Data
public class TechnologyVo {
/**
* 技术名称
*/
private String technologyName;
/**
* 建议
*/
private String advice;
/**
* 资金
*/
private Integer fund;
}
package com.zjty.inspect.entity;
import lombok.Data;
import java.util.List;
/**
* @author Mcj
* @date 2020-02-27 14:56
*/
@Data
public class TechnologyVoNoFund {
/**
* 建议
*/
private String advice;
/**
* 绑定的规则
*/
private List<RuleVo> ruleVos;
}
......@@ -23,6 +23,6 @@ public class VueDep {
Map<String,String> dependencies = new HashMap<>();
Map<String,String> scripts = new HashMap<>();
Map<String,String> eslintConfig = new HashMap<>();
VueBrowserslist browserslist;
VueBrowserslist browserslist = new VueBrowserslist();
}
......@@ -4,7 +4,6 @@ import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.entity.Report;
public interface InspectService {
Report inspect(InspectParameter inspectParameter);
Report inspect(InspectParameter inspectParameter,String path);
}
package com.zjty.inspect.service;
import com.zjty.inspect.entity.InspectParameter;
/**
*
* 评估参数
* @author mcj
*/
public interface ParameterService {
/**
* 保存参数
* @param inspectParameter 评估封装参数。
*/
public void saveParameter(InspectParameter inspectParameter);
}
package com.zjty.inspect.service;
import com.zjty.inspect.entity.ReportVo;
import java.util.List;
public interface ReportService {
/**
* 获取所有历史报告
* @return 历史报告
*/
public List<ReportVo> getHistory();
}
package com.zjty.inspect.service;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.entity.RuleVo;
import java.util.List;
/**
* 规则接口
*/
public interface RuleService {
/**
* 新增规则
* @param ruleQo 规则封装类
*/
public void addRule(RuleQo ruleQo);
/**
* 删除规则
* @param ruleQo 规则封装类
*/
public void deleteRule(RuleQo ruleQo);
/**
* 查询所有规则
* @return 规则
*/
List<Rule> findAll();
}
package com.zjty.inspect.service;
import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.entity.TechnologyQo;
import java.util.List;
/**
* 关键技术
* @author mcj
*/
public interface TechnologyService {
/**
* 新增关键技术点
*/
public void addAdvice(TechnologyQo technologyQo);
/**
* 查询所有技术
* @return List
*/
public List<Technology> findAllTechnology();
}
package com.zjty.inspect.service.impl;
import com.alibaba.fastjson.JSON;
import com.zjty.inspect.dao.ReportDao;
import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.entity.PomDependency;
import com.zjty.inspect.entity.Report;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.service.InspectService;
import com.zjty.inspect.service.ParameterService;
import com.zjty.inspect.utils.Inspector;
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.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 解析
......@@ -26,10 +29,21 @@ import java.util.*;
@Service
public class InspectServiceImpl implements InspectService {
@Autowired
Inspector inspector;
@Autowired
private ParameterService parameterService;
@Autowired
private RuleDao ruleDao;
@Autowired
private ReportDao reportDao;
@Transactional
@Override
public Report inspect(InspectParameter inspectParameter) {
public Report inspect(InspectParameter inspectParameter,String path) {
Map<String, Report.Language> suffixLanguageMapping = new HashMap<>();
suffixLanguageMapping.put("java", Report.Language.JAVA);
suffixLanguageMapping.put("vue", Report.Language.VUE);
......@@ -39,45 +53,16 @@ public class InspectServiceImpl implements InspectService {
suffixLanguageMapping.put("html", Report.Language.ONLYVIEW);
suffixLanguageMapping.put("js", Report.Language.JAVASCRIPT);
suffixLanguageMapping.put("go", Report.Language.GO);
List<Rule> ruleList = inspectParameter.getRuleList();
//com.mysql.cj.jdbc.Driver//com.mysql.jdbc.Driver
// ruleList.add(new Rule("com.mysql.cj.jdbc.Driver", "建议修改为postgresql数据库驱动"));
// ruleList.add(new Rule("com.mysql.jdbc.Driver", "建议修改为postgresql数据库驱动"));
// //net.sourceforge.jtds.jdbc.Driver//sqlserver
// ruleList.add(new Rule("net.sourceforge.jtds.jdbc.Driver", "建议修改为postgresql数据库驱动"));
// //COM.ibm.db2.jdbc.app.DB2Driver//com.ibm.db2.jcc.DB2Driver//COM.ibm.db2.jdbc.net.DB2Driver//com.ibm.db2.jcc.DB2Driver
// ruleList.add(new Rule("DB2Driver", "建议修改为postgresql数据库驱动"));
// //oracle.jdbc.OracleDriver//oracle.jdbc.driver.OracleDriver
// ruleList.add(new Rule("OracleDriver", "建议修改为postgresql数据库驱动"));
//
// ruleList.add(new Rule("mysql-connector-java", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("com.microsoft.sqlserver", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("com.oracle", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("org.mariadb.jdbc", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("com.sap.cloud.db.jdbc", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("com.ibm.informix", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("org.firebirdsql.jdbc", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("org.hsqldb", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("com.h2database", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("org.apache.derby", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("org.mongodb", "建议修改为postgresql依赖声明"));
// ruleList.add(new Rule("package.json", "需要nodejs环境"));
// ruleList.add(new Rule("public native", "这里用到了JNI"));
// ruleList.add(new Rule("<packaging>jar</packaging>", "建议修改打包方式为war包并排除掉springboot内置的tomcat,以部署到国产化中间件上"));
// ruleList.add(new Rule("WebOffice", "这里用到了weboffice文档展示编辑插件"));
// ruleList.add(new Rule("webOffice", "这里用到了weboffice文档展示编辑插件"));
// ruleList.add(new Rule("weboffice", "这里用到了weboffice文档展示编辑插件"));
// ruleList.add(new Rule("Weboffice", "这里用到了weboffice文档展示编辑插件"));
// ruleList.add(new Rule("pdfobject.min.js", "这里用到了pdf文档展示插件"));
// ruleList.add(new Rule("pdfobject.js", "这里用到了pdf文档展示插件"));
// ruleList.add(new Rule(".swf", "这里用到了flash流媒体播放插件"));
String path = inspectParameter.getPath();
//调用下载服务下载源代码
Report report = notList(path, suffixLanguageMapping, ruleList);
return report;
Path path1 = Paths.get(path);
File file = path1.toFile();
Report report1 = new Report();
report1.setGitAddress(path);
inspector.setReport(report1);
inspector.setSuffixLanguageMapping(suffixLanguageMapping);
inspector.setPath(path);
Report report = inspector.inspect();
reportDao.save(report);
return null;
}
public void listfile(String path,Map<String, Report.Language> suffixLanguageMapping,List<Rule> ruleList){
Path path1 = Paths.get(path);
......@@ -85,38 +70,22 @@ public class InspectServiceImpl implements InspectService {
File[] files = file.listFiles();
System.out.println(file.isDirectory());
for (File file1 : files) {
Report report = new Inspector(file1.getPath(), suffixLanguageMapping, ruleList).inspect();
File file2 = new File(file1.getPath() + "/评估报告" + file1.getName() + ".txt");
// Report report = new Inspector(file1.getPath(), suffixLanguageMapping, ruleList).inspect();
try {
FileWriter writer = new FileWriter(file2);
writer.write("系统名称:" + file1.getName() + "\n");
writer.write("评估时间:" + new Date() + "\n\n");
writer.close();
} catch (IOException e) {
}
}
}
public Report notList(String path,Map<String, Report.Language> suffixLanguageMapping,List<Rule> ruleList){
Path path1 = Paths.get(path);
File file = path1.toFile();
File file2 = new File(file.getPath() + "/评估报告" + file.getName() + ".txt");
if (file2.exists()){
file2.delete();
//File file2 = new File(file.getPath() + "/评估报告" + file.getName() + ".txt");
// if (file2.exists()){
// file2.delete();
//
// }
// Report report = new Inspector(file.getPath(), suffixLanguageMapping, ruleList).inspect();
}
Report report = new Inspector(file.getPath(), suffixLanguageMapping, ruleList).inspect();
try {
FileWriter writer = new FileWriter(file2);
writer.write("系统名称:" + file.getName() + "\n");
writer.write("评估时间:" + new Date() + "\n\n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
return report;
return new Report();
}
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.service.ParameterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author Mcj
* @date 2020-02-27 21:36
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ParameterServiceImpl implements ParameterService {
@Override
public void saveParameter(InspectParameter inspectParameter) {
}
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.BudgetDao;
import com.zjty.inspect.dao.ReportDao;
import com.zjty.inspect.dao.TechnologyAndReportDao;
import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.*;
import com.zjty.inspect.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* @author Mcj
* @date 2020-02-27 10:35
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ReportServiceImpl implements ReportService {
@Autowired
private ReportDao reportDao;
@Autowired
private TechnologyDao technologyDao;
@Autowired
private TechnologyAndReportDao technologyAndReportDao;
@Autowired
private BudgetDao budgetDao;
@Override
public List<ReportVo> getHistory() {
ArrayList<ReportVo> reportVos = new ArrayList<>();
List<Report> all = reportDao.findAll();
for (Report report : all) {
ReportVo reportVo = new ReportVo();
reportVo.setId(report.getId());
reportVo.setManager(report.getManager());
reportVo.setLanguage(report.getLanguage());
reportVo.setFramework(report.getFramework());
reportVo.setRecastMethod(report.getRecastMethod());
reportVo.setHtmlAddress(report.getHtmlAddress());
// TODO: 2020-02-27 从redis中查询依赖树
HashSet<String> num = new HashSet<>();
List<TechnologyAndReport> rar = technologyAndReportDao.findAllByReportIdEquals(report.getId());
ArrayList<TechnologyVo> technologyVos = new ArrayList<>();
HashMap<String, ArrayList<RuleAndReportVo>> map = new HashMap<>();
for (TechnologyAndReport technologyAndReport : rar) {
num.add(technologyAndReport.getTechnologyId());
if (map.containsKey(technologyAndReport.getTechnologyId())) {
RuleAndReportVo ruleAndReportVo = new RuleAndReportVo();
ruleAndReportVo.setFilePath(technologyAndReport.getFilePath());
ruleAndReportVo.setLineNum(technologyAndReport.getLineNum());
map.get(technologyAndReport.getTechnologyId()).add(ruleAndReportVo);
} else {
RuleAndReportVo ruleAndReportVo = new RuleAndReportVo();
ruleAndReportVo.setFilePath(technologyAndReport.getFilePath());
ruleAndReportVo.setLineNum(technologyAndReport.getLineNum());
map.put(technologyAndReport.getTechnologyId(), new ArrayList<>());
map.get(technologyAndReport.getTechnologyId()).add(ruleAndReportVo);
}
}
Set<String> strings = map.keySet();
ArrayList<String> strings1 = new ArrayList<>(strings);
for (String id : strings) {
Optional<Technology> byId = technologyDao.findById(id);
if (byId.isPresent()) {
Technology technology = byId.get();
String technologyName = technology.getTechnologyName();
map.put(technologyName, map.get(id));
TechnologyVo technologyVo = new TechnologyVo();
technologyVo.setAdvice(technology.getAdvice());
technologyVo.setTechnologyName(technology.getTechnologyName());
technologyVo.setFund(technology.getFund());
technologyVos.add(technologyVo);
}
}
List<Budget> budgetList = budgetDao.findAllByReportIdEquals(report.getId());
for (String s : strings1) {
map.remove(s);
}
reportVo.setBudgets(budgetList);
reportVo.setWarnDetails(map);
reportVo.setTechnologyVos(technologyVos);
reportVo.setWarnNum(num.size());
reportVos.add(reportVo);
}
return reportVos;
}
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService;
import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 规则库
* @author Mcj
* @date 2020-02-26 15:05
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class RuleServiceImpl implements RuleService {
/**
* 规则库dao
*/
@Autowired
private RuleDao ruleDao;
/**
* 新增规则
* @param ruleQo 规则封装类
*/
@Override
public void addRule(RuleQo ruleQo) {
// TODO: 2020-02-27 适配技术与扫描关键字关联
Rule rule = new Rule();
rule.setTarget(ruleQo.getTarget());
rule.setSuffix(ruleQo.getSuffix());
rule.setTechnologyId(ruleQo.getTechnologyId());
rule.setId(UUIDUtil.getUUID());
ruleDao.save(rule);
}
@Override
@Modifying
public void deleteRule(RuleQo ruleQo) {
ruleDao.deleteById(ruleQo.getId());
}
/**
* 查询所有规则
* @return RuleVoList
*/
@Override
public List<Rule> findAll() {
return ruleDao.findAll();
}
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.TechnologyQo;
import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.service.TechnologyService;
import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 适配技术
* @author Mcj
* @date 2020-02-27 12:00
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class TechnologyServiceImpl implements TechnologyService {
@Autowired
private TechnologyDao technologyDao;
/**
* 新增适配技术
* @param technologyQo 前端数据封装类
*/
@Override
public void addAdvice(TechnologyQo technologyQo) {
if(technologyDao.findAllByTechnologyNameEquals(technologyQo.getTechnologyQoName())==null){
Technology technology = new Technology();
technology.setFund(technologyQo.getFund());
technology.setAdvice(technologyQo.getAdvice());
technology.setTechnologyName(technologyQo.getTechnologyQoName());
technology.setId(UUIDUtil.getUUID());
technologyDao.save(technology);
}
}
@Override
public List<Technology> findAllTechnology() {
return technologyDao.findAll();
}
}
package com.zjty.inspect.task;
import com.zjty.inspect.dao.CoefficientModelDao;
import com.zjty.inspect.dao.RuleDao;
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.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
/**
* @author Mcj
* @date 2020-03-02 14:35
*/
@Component
public class task implements CommandLineRunner {
@Autowired
private CoefficientModelDao coefficientModelDao;
@Autowired
private RuleDao ruleDao;
@Autowired
private TechnologyDao technologyDao;
@Override
public void run(String... args) {
ArrayList<CoefficientModel> coefficientModels = new ArrayList<>();
//无,弱,强
CoefficientModel coefficientModel = new CoefficientModel();
coefficientModel.setScale(1);
coefficientModel.setId(UUIDUtil.getUUID());
coefficientModel.setName("安全能力");
coefficientModel.setMin(0);
coefficientModel.setMax(2);
coefficientModel.setBelowCoefficient(0D);
coefficientModel.setMediumCoefficient(0.1);
coefficientModel.setTopCoefficient(0.2);
CoefficientModel coefficientMode2 = new CoefficientModel();
coefficientMode2.setScale(2);
coefficientMode2.setId(UUIDUtil.getUUID());
coefficientMode2.setName("安全能力");
coefficientMode2.setMin(0);
coefficientMode2.setMax(2);
coefficientMode2.setBelowCoefficient(-0.1);
coefficientMode2.setMediumCoefficient(0D);
coefficientMode2.setTopCoefficient(0.1);
CoefficientModel coefficientMode3 = new CoefficientModel();
coefficientMode3.setScale(3);
coefficientMode3.setId(UUIDUtil.getUUID());
coefficientMode3.setName("安全能力");
coefficientMode3.setMin(0);
coefficientMode3.setMax(2);
coefficientMode3.setBelowCoefficient(-0.2);
coefficientMode3.setMediumCoefficient(-0.1);
coefficientMode3.setTopCoefficient(0D);
CoefficientModel coefficientMode4 = new CoefficientModel();
coefficientMode4.setScale(1);
coefficientMode4.setId(UUIDUtil.getUUID());
coefficientMode4.setName("模块");
coefficientMode4.setMin(4);
coefficientMode4.setMax(10);
coefficientMode4.setBelowCoefficient(-0.3);
coefficientMode4.setMediumCoefficient(0D);
coefficientMode4.setTopCoefficient(0.3);
CoefficientModel coefficientMode5 = new CoefficientModel();
coefficientMode5.setScale(1);
coefficientMode5.setId(UUIDUtil.getUUID());
coefficientMode5.setName("数据量");
coefficientMode5.setMin(1);
coefficientMode5.setMax(100);
coefficientMode5.setBelowCoefficient(-0.05);
coefficientMode5.setMediumCoefficient(0D);
coefficientMode5.setTopCoefficient(0.05);
CoefficientModel coefficientMode6 = new CoefficientModel();
coefficientMode6.setScale(1);
coefficientMode6.setId(UUIDUtil.getUUID());
coefficientMode6.setName("页面数");
coefficientMode6.setMin(10);
coefficientMode6.setMax(100);
coefficientMode6.setBelowCoefficient(-0.05);
coefficientMode6.setMediumCoefficient(0D);
coefficientMode6.setTopCoefficient(0.05);
coefficientModels.add(coefficientMode6);
coefficientModels.add(coefficientMode5);
coefficientModels.add(coefficientMode4);
coefficientModels.add(coefficientMode3);
coefficientModels.add(coefficientMode2);
coefficientModels.add(coefficientModel);
coefficientModelDao.saveAll(coefficientModels);
Technology technology = new Technology();
technology.setTechnologyName("spring技术");
technology.setAdvice("建议替换成国产化技术");
technology.setFund(200);
technology.setId(UUIDUtil.getUUID());
Rule rule = new Rule();
rule.setId(UUIDUtil.getUUID());
rule.setSuffix("java");
rule.setTarget("ruleService");
rule.setTechnologyId(technology.getId());
technologyDao.save(technology);
ruleDao.save(rule);
}
}
package com.zjty.inspect.utils;
import com.alibaba.fastjson.JSONObject;
import com.zjty.inspect.dao.TechnologyAndReportDao;
import com.zjty.inspect.entity.*;
import com.zjty.inspect.entity.Properties;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@Component
public class AnalysisFile {
public static ProjectPom analysisPom(Path pomPath){
ProjectPom projectPom = new ProjectPom();
List<PomDependency> dependencies = new ArrayList<>();
Document document = null;
try {
document = DocumentHelper.parseText(new String(Files.readAllBytes(pomPath)));
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Element rootElement = document.getRootElement();
if(rootElement.element("properties")!=null){
Element dependencies1 = rootElement.element("properties");
for(Element element:dependencies1.elements()){
Properties properties = new Properties();
String name = element.getName();
String stringValue = element.getStringValue();
properties.setValue(stringValue);
properties.setName(name);
projectPom.getProperties().add(properties);
}
}
projectPom.setModelVersion(rootElement.elementText("modelVersion"));
projectPom.setGroupId(rootElement.elementText("groupId"));
projectPom.setArtifactId(rootElement.elementText("artifactId"));
projectPom.setPackaging(rootElement.elementText("packing"));
projectPom.setVersion(rootElement.elementText("version"));
if(rootElement.elementText("version")!=null){
projectPom.setVersion(rootElement.elementText("version"));
}
projectPom.setName(rootElement.elementText("name"));
projectPom.setDescription(rootElement.elementText("description"));
if(rootElement.element("dependencies")!=null){
Element dependencies1 = rootElement.element("dependencies");
List<Element> dependency = dependencies1.elements("dependency");
for(Element element:dependency){
PomDependency pomDependency = new PomDependency();
pomDependency.setGroupId(element.elementText("groupId"));
pomDependency.setArtifactId(element.elementText("artifactId"));
if(element.elementText("version")!=null){
pomDependency.setVersion(element.elementText("version"));
}
dependencies.add(pomDependency);
}
}
if(rootElement.elements("parent")!=null){
List<Element> parent = rootElement.elements("parent");
for(Element p:parent){
PomDependency pomDependency = new PomDependency();
pomDependency.setGroupId(p.elementText("groupId"));
pomDependency.setArtifactId(p.elementText("artifactId"));
if(p.elementText("version")!=null){
pomDependency.setVersion(p.elementText("version"));
}
dependencies.add(pomDependency);
}
}
if(rootElement.element("dependencyManagement")!=null){
Element dependencies1 = rootElement.element("dependencyManagement");
Element dependencies2 = dependencies1.element("dependencies");
List<Element> dependency = dependencies2.elements("dependency");
for(Element element:dependency){
PomDependency pomDependency = new PomDependency();
pomDependency.setGroupId(element.elementText("groupId"));
pomDependency.setArtifactId(element.elementText("artifactId"));
if(element.elementText("version")!=null){
pomDependency.setVersion(element.elementText("version"));
}
dependencies.add(pomDependency);
}
}
projectPom.setDependencies(dependencies);
return projectPom;
}
@Autowired
private TechnologyAndReportDao technologyAndReportDao;
public static List<PomDependency> analysisGradle(Path pomPath) {
List<String> strings = null;
try {
......@@ -113,25 +44,40 @@ public class AnalysisFile {
return dependencies;
}
public static void main(String[] args) {
Path path = Paths.get("/Users/mcj/IdeaProjects/inspect/tree.txt");
int is=0;
boolean b1 = path.toString().endsWith("");
public DepTreePom parseTreeFile(String reportId,String filePath, List<Rule> ruleList) {
ArrayList<TechnologyAndReport> technologyAndReports = new ArrayList<>();
Path path = Paths.get(filePath);
DepTreePom depTreePom = new DepTreePom();
HashMap<Integer, DepTree> map = new HashMap<>();
int one = 1;
DepTree depTree = new DepTree();
depTreePom.setDepTree(depTree);
try {
List<String> strings = Files.readAllLines(path);
String s1 = strings.get(7);
String s2 = s1.replaceAll("\\[INFO] ", "");
depTree.setDepName(s2);
map.put(1,depTree);
String s1 = strings.get(0);
depTree.setDepName(s1);
map.put(0,depTree);
System.out.println(strings.size());
int now = 0;
for (int i = 8; i <= strings.size()-7; i++) {
for (int i = 1; i <= strings.size()-1; i++) {
DepTree depTree1 = new DepTree();
String s = strings.get(i).replaceAll("\\[INFO] ", "");
System.out.println(i);
String s = strings.get(i);
for (Rule rule : ruleList) {
if(KmpUtil.kmpMatch(s,rule.getTarget())>0){
depTree1.setViolation(1);
depTreePom.add(rule.getTechnologyId());
//rule匹配上了
TechnologyAndReport technologyAndReport = new TechnologyAndReport();
technologyAndReport.setFilePath(filePath);
technologyAndReport.setLineNum(i);
technologyAndReport.setTechnologyId(rule.getTechnologyId());
technologyAndReport.setReportId(reportId);
technologyAndReport.setRuleId(rule.getId());
technologyAndReport.setId(UUIDUtil.getUUID());
technologyAndReports.add(technologyAndReport);
}
}
int i1 = s.indexOf("-");
if(i1==one){
depTree1.setDepName(s);
......@@ -148,54 +94,11 @@ public class AnalysisFile {
map.put(i1+3,depTree1);
now = i1;
}
DepTreeAndReport depTreeAndReport = new DepTreeAndReport();
depTreeAndReport.setId("报告id");
depTreeAndReport.setDepTree(depTree);
Object o = JSONObject.toJSON(depTreeAndReport);
System.out.println(o);
} catch (IOException e) {
e.printStackTrace();
}
String a = "AAbaaa";
String b = "cccccaaB";
boolean aaB = a.equalsIgnoreCase("aaB");
int aaB1 = b.indexOf("aaB");
int i = AnalysisFile.EditDistance(a, b);
System.out.println(i);
}
public static int EditDistance(String source, String target) {
char[] sources = source.toCharArray();
char[] targets = target.toCharArray();
int sourceLen = sources.length;
int targetLen = targets.length;
int[][] d = new int[sourceLen + 1][targetLen + 1];
for (int i = 0; i <= sourceLen; i++) {
d[i][0] = i;
}
for (int i = 0; i <= targetLen; i++) {
d[0][i] = i;
}
for (int i = 1; i <= sourceLen; i++) {
for (int j = 1; j <= targetLen; j++) {
if (sources[i - 1] == targets[j - 1]) {
d[i][j] = d[i - 1][j - 1];
} else {
//插入
int insert = d[i][j - 1] + 1;
//删除
int delete = d[i - 1][j] + 1;
//替换
int replace = d[i - 1][j - 1] + 1;
d[i][j] = Math.min(insert, delete) > Math.min(delete, replace) ? Math.min(delete, replace) :
Math.min(insert, delete);
}
}
}
return d[sourceLen][targetLen];
technologyAndReportDao.saveAll(technologyAndReports);
return depTreePom;
}
......
package com.zjty.inspect.utils;
import com.zjty.inspect.dao.BudgetDao;
import com.zjty.inspect.dao.CoefficientModelDao;
import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.Budget;
import com.zjty.inspect.entity.CoefficientModel;
import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.entity.TechnologyAndReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* 获取预算
* @author Mcj
* @date 2020-02-26 15:14
*/
@Component
public class BudgetUitl {
@Autowired
private CoefficientModelDao coefficientModelDao;
@Autowired
private BudgetDao budgetDao;
/**
* 获取预算数据
* @param reportId 报告id
* @param fund 技术费用
* @param inspectParameter2 计算所需数据
* @return
*/
public List<Budget> getBudget(String reportId,Integer fund, InspectParameter inspectParameter2){
InspectParameter inspectParameter = new InspectParameter();
inspectParameter.setMoneyRate(1.42);
inspectParameter.setYears(2015);
inspectParameter.setModules(5);
inspectParameter.setProportion(1.1);
inspectParameter.setFramework(0.5);
inspectParameter.setDisaster(0.5);
inspectParameter.setSafety(2.5);
inspectParameter.setSystemFund(200);
Integer scale;
Integer systemFund = inspectParameter.getSystemFund();
if(systemFund==0){
double v = inspectParameter.getModules() * 7.5;
systemFund= (int) v;
}
if(systemFund<30){
scale=1;
}else if(systemFund<200){
scale=2;
}else{
scale=3;
}
Budget budget = new Budget();
budget.setId(UUIDUtil.getUUID());
budget.setBudgetName("代码重构预算");
budget.setReportId(reportId);
Double moneyRate = inspectParameter.getMoneyRate();
int i = 2020 - inspectParameter.getYears();
double pow = Math.pow(moneyRate, i);
//不带修正系数资金
double v = inspectParameter.getProportion() * pow * systemFund + fund;
//带修正系数资金
ArrayList<String> strings = new ArrayList<>();
Double v1 = v;
strings.add("安全能力");
strings.add("容灾能力");
strings.add("架构");
List<CoefficientModel> nameIn = coefficientModelDao.findAllByNameInAndScaleEquals(strings,scale);
for (CoefficientModel model : nameIn) {
if("架构".equals(model.getName())){
Double aDouble = model.countCoefficient(inspectParameter.getFramework());
v1*=aDouble;
}else if("容灾能力".equals(model.getName())){
Double aDouble = model.countCoefficient(inspectParameter.getDisaster());
v1*=aDouble;
}
else if("安全能力".equals(model.getName())){
Double aDouble = model.countCoefficient(inspectParameter.getSafety());
v1*=aDouble;
}
}
if(v<v1){
budget.setFund(v +"--"+v1);
}else if(v>v1){
budget.setFund(v1 +"--"+v);
}else{
budget.setFund(v1 +"--"+v);
}
budget.setFundDetail("普通业务开发费用:"+v);
budget.setFundDetail("普通业务开发费用(修正):"+v1);
budget.setFundDetail("关键适配技术成本:"+fund);
Budget budget1 = new Budget();
//budget.setBudgetName("代码修改预算");
ArrayList<Budget> budgets = new ArrayList<>();
budgets.add(budget);
budgetDao.saveAll(budgets);
return budgets;
}
}
......@@ -28,7 +28,7 @@ public class FileUtil {
* @param destDirPath 解压后的目标文件夹
* @throws RuntimeException 解压失败会抛出运行时异常
*/
public static void unZip(File srcFile, String destDirPath) throws RuntimeException {
public static String unZip(File srcFile, String destDirPath) throws RuntimeException {
long start = System.currentTimeMillis();
// 判断源文件是否存在
if (!srcFile.exists()) {
......@@ -66,6 +66,7 @@ public class FileUtil {
// 关流顺序,先打开的后关闭
fos.close();
is.close();
return targetFile.getPath();
}
}
long end = System.currentTimeMillis();
......@@ -81,6 +82,7 @@ public class FileUtil {
}
}
}
return "";
}
private static void recursiveFiles(String path) {
......@@ -118,7 +120,7 @@ public class FileUtil {
vueDep = new ObjectMapper().readValue(file,VueDep.class);
return vueDep;
} catch (Exception e) {
return null;
return new VueDep();
}
}
......
......@@ -11,7 +11,7 @@ public class KmpUtil {
* @param t 字符数组
* @return next数组
*/
public static int[] getNextArray(char[] t) {
private static int[] getNextArray(char[] t) {
int[] next = new int[t.length];
next[0] = -1;
next[1] = 0;
......
package com.zjty.inspect.utils;
import org.apache.maven.shared.invoker.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.Collections;
/**
* @author Mcj
* @date 2020-03-01 17:11
*/
@Component
public class MavenUtil {
@Value("${maven.command}")
private String mavenCommand;
@Value("${maven.home}")
private String mavenHome;
@Value("${maven.treefile}")
private String treeFile;
public File genTreeFile(String path){
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(path));
request.setGoals(Collections.singletonList(mavenCommand+treeFile));
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(mavenHome));
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
e.printStackTrace();
}
return new File(treeFile);
}
}
package com.zjty.inspect.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import java.io.Serializable;
/**
* @author Mcj
* @date 2020-03-02 11:30
*/
@Service
public class RedisUtil {
@Autowired
private RedisTemplate redisTemplate;
/**
* 写入缓存
* @param key
* @param value
* @return
*/
public boolean set(final String key, Object value) {
boolean result = false;
try {
ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
operations.set(key, value);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 批量删除对应的value
* @param keys
*/
public void remove(final String... keys) {
for (String key : keys) {
remove(key);
}
}
/**
* 删除对应的value
* @param key
*/
public void remove(final String key) {
if (exists(key)) {
redisTemplate.delete(key);
}
}
/**
* 判断缓存中是否有对应的value
* @param key
* @return
*/
public boolean exists(final String key) {
return redisTemplate.hasKey(key);
}
}
package com.zjty.inspect.utils;
import java.util.UUID;
/**
* @author Mcj
* @date 2019-09-20 10:57
*/
public class UUIDUtil {
public static String getUUID(){
//转化为String对象
return UUID.randomUUID().toString();
}
}
......@@ -54,3 +54,12 @@ spring.datasource.url=jdbc:mysql://localhost:3306/adaptation?useSSL=false&server
spring.datasource.username=root
spring.datasource.password=root
maven.home=/Users/mcj/apache-maven-3.6.1
maven.command=dependency:tree -DoutputType=txt -DoutputFile=
maven.treefile=/Users/mcj/IdeaProjects/inspect/hello
spring.redis.host=127.0.0.1
#Redis服务器连接端口
spring.redis.port=6379
#Redis服务器连接密码(默认为空)
spring.redis.password=
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论