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

mcj:新增评估报告管理

上级 6a1af196
package com.zjty.inspect.controller; package com.zjty.inspect.controller;
import com.zjty.inspect.dao.TechnologyDao; import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.InspectParameter; import com.zjty.inspect.entity.*;
import com.zjty.inspect.entity.ReportVo;
import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.entity.Warn;
import com.zjty.inspect.service.InspectService; import com.zjty.inspect.service.InspectService;
import com.zjty.inspect.service.ParameterService;
import com.zjty.inspect.service.ReportService;
import com.zjty.inspect.service.TechnologyService; import com.zjty.inspect.service.TechnologyService;
import com.zjty.inspect.utils.*; import com.zjty.inspect.utils.*;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
...@@ -39,6 +38,11 @@ public class InspectController { ...@@ -39,6 +38,11 @@ public class InspectController {
@Autowired @Autowired
private TechnologyService technologyService; private TechnologyService technologyService;
@Autowired
private ParameterService parameterService;
@Autowired
private ReportService reportService;
/** /**
* 上传代码进行评估 * 上传代码进行评估
* @param years 系统开发时间 * @param years 系统开发时间
...@@ -82,13 +86,15 @@ public class InspectController { ...@@ -82,13 +86,15 @@ public class InspectController {
int support = technologyService.findAllTechnologyNotSupport(); int support = technologyService.findAllTechnologyNotSupport();
reportVo.setTechnologiesRepair(support); reportVo.setTechnologiesRepair(support);
reportVo.setId(TimeUtil.getNowDate()); reportVo.setId(RandomUtil.getRandom());
reportVo.setUploadType("文件上传"); reportVo.setUploadType("文件上传");
reportVo.setFileName(file.getName()); reportVo.setFileName(file.getName());
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);
Map map=new HashMap(); Map map=new HashMap();
...@@ -113,7 +119,13 @@ public class InspectController { ...@@ -113,7 +119,13 @@ public class InspectController {
} catch (TemplateException e) { } catch (TemplateException e) {
e.printStackTrace(); e.printStackTrace();
} }
Report report = new Report();
String random = RandomUtil.getRandom();
report.setId(RandomUtil.getRandom());
report.setHtmlAddress(reportVo.getHtmlAddress());
reportService.saveReport(report);
inspectParameter.setReportId(random);
parameterService.saveParameter(inspectParameter);
return ResponseEntity.ok(inspect); return ResponseEntity.ok(inspect);
} }
......
package com.zjty.inspect.controller;
import com.zjty.inspect.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Mcj
* @date 2020-03-05 19:22
*/
@RestController
@RequestMapping("/report")
@Api(value = "报告管理页面接口",description = "报告管理页面接口,提供页面的增、删、改、查")
public class ReportController {
@Autowired
private ReportService reportService;
@GetMapping("/page/{page}")
@ApiOperation("根据页码获取数据")
public ResponseEntity getReportByPage(@PathVariable int page){
return ResponseEntity.ok(reportService.findReportByPage(page));
}
@GetMapping("/id/{id}")
@ApiOperation("根据id获取数据")
public ResponseEntity getReportById(@PathVariable String id){
return ResponseEntity.ok(reportService.findReportById(id));
}
}
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> {
}
...@@ -46,7 +46,7 @@ public class CoefficientModel { ...@@ -46,7 +46,7 @@ public class CoefficientModel {
private Integer scale; private Integer scale;
public Double countCoefficient(Integer data) { public Double countCoefficient(Integer data) {
if(data==null || data==0){ if(data==null){
return 1D; return 1D;
} }
if(data<min){ if(data<min){
......
...@@ -56,6 +56,11 @@ public class InspectParameter { ...@@ -56,6 +56,11 @@ public class InspectParameter {
* 代码量 * 代码量
*/ */
private Integer codeSize; private Integer codeSize;
/**
* 内容
*/
private Integer content;
/** /**
* 架构 * 架构
*/ */
...@@ -97,11 +102,6 @@ public class InspectParameter { ...@@ -97,11 +102,6 @@ public class InspectParameter {
*/ */
private String reportAddress; private String reportAddress;
/**
* 预算报告地址
*/
private String budgetAddress;
/** /**
* git上传地址 * git上传地址
*/ */
...@@ -128,4 +128,9 @@ public class InspectParameter { ...@@ -128,4 +128,9 @@ public class InspectParameter {
* 方式 * 方式
*/ */
private Integer recastMethod; private Integer recastMethod;
/**
* 报告id
*/
private String reportId;
} }
package com.zjty.inspect.entity;
import java.util.ArrayList;
import java.util.List;
/**
* @author Mcj
* @date 2020-03-05 19:24
*/
public class Page<T> {
private int totalPage;
private int totalElement;
private List<T> objects = new ArrayList<T>();
public void add(T t){
objects.add(t);
}
public void addAll(List<T> t){
objects.addAll(t);
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public void setTotalElement(int totalElement) {
this.totalElement = totalElement;
}
public int getTotalPage() {
return totalPage;
}
public int getTotalElement() {
return totalElement;
}
}
...@@ -13,45 +13,19 @@ import java.sql.Timestamp; ...@@ -13,45 +13,19 @@ import java.sql.Timestamp;
* 报告 * 报告
* @author mcj * @author mcj
*/ */
@Entity
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class Report { public class Report {
/** @Id
* git源代码地址 private String id;
*/
private String gitAddress;
/**
* 架构,整合型还是分离型,根据jsp数量决定
*/
private String framework;
/**
* 代码管理方式,
*/
private String manager;
/**
* 语言
*/
private String language;
/** /**
* 生成报告存储地址 * 生成报告存储地址
*/ */
private String htmlAddress; private String htmlAddress;
/**
* 适配方式
* 1:适配
* 2:重构
*/
@Column(length = 5)
private Integer recastMethod;
//前端适配预算 //前端适配预算
//代码重构预算 //代码重构预算
//代码修改预算 //代码修改预算
...@@ -69,11 +43,4 @@ public class Report { ...@@ -69,11 +43,4 @@ public class Report {
@Column(name="update_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false) @Column(name="update_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false)
@Generated(GenerationTime.ALWAYS) @Generated(GenerationTime.ALWAYS)
private Timestamp updateDate; private Timestamp updateDate;
public enum DependenceManagement{
MAVEN,GRADLE,ANT
}
public enum Language{
JAVA,PYTHON,CPP,JSP,ASP,ONLYVIEW,UNKNOW,JAVASCRIPT,GO,VUE,HTML
}
} }
package com.zjty.inspect.entity;
import lombok.Data;
/**
* @author Mcj
* @date 2020-03-05 19:49
*/
@Data
public class ReportManage {
Report report;
InspectParameter inspectParameter;
}
...@@ -16,7 +16,7 @@ public interface ParameterService { ...@@ -16,7 +16,7 @@ public interface ParameterService {
public void saveParameter(InspectParameter inspectParameter); public void saveParameter(InspectParameter inspectParameter);
/** /**
* 保存参数 * 根据id获取参数
* @param id id * @param id id
*/ */
public InspectParameter getParameterById(String id); public InspectParameter getParameterById(String id);
......
package com.zjty.inspect.service; package com.zjty.inspect.service;
import com.zjty.inspect.entity.ReportVo; import com.zjty.inspect.entity.Page;
import org.springframework.data.domain.Page; import com.zjty.inspect.entity.Report;
import com.zjty.inspect.entity.ReportManage;
import java.util.List;
public interface ReportService { public interface ReportService {
public Page findReportByPage(int page);
public ReportManage findReportById(String id);
void saveReport(Report report);
} }
package com.zjty.inspect.service.impl; package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.ReportDao;
import com.zjty.inspect.entity.InspectParameter; import com.zjty.inspect.entity.InspectParameter;
import com.zjty.inspect.entity.Report; import com.zjty.inspect.entity.Report;
import com.zjty.inspect.entity.ReportVo; import com.zjty.inspect.entity.ReportVo;
import com.zjty.inspect.enums.Language; import com.zjty.inspect.enums.Language;
import com.zjty.inspect.service.InspectService; import com.zjty.inspect.service.InspectService;
import com.zjty.inspect.inspect.Inspector; import com.zjty.inspect.inspect.Inspector;
import com.zjty.inspect.service.ParameterService;
import com.zjty.inspect.utils.RandomUtil;
import freemarker.cache.StringTemplateLoader; import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
...@@ -27,6 +30,12 @@ public class InspectServiceImpl implements InspectService { ...@@ -27,6 +30,12 @@ public class InspectServiceImpl implements InspectService {
@Autowired @Autowired
Inspector inspector; Inspector inspector;
@Autowired
private ReportDao reportDao;
@Autowired
private ParameterService parameterService;
@Transactional @Transactional
@Override @Override
public ReportVo inspect(ReportVo reportVo,InspectParameter inspectParameter) { public ReportVo inspect(ReportVo reportVo,InspectParameter inspectParameter) {
...@@ -46,11 +55,10 @@ public class InspectServiceImpl implements InspectService { ...@@ -46,11 +55,10 @@ public class InspectServiceImpl implements InspectService {
inspector.setReport(reportVo); inspector.setReport(reportVo);
//需要重构 //需要重构
inspector.setSuffixLanguageMapping(suffixLanguageMapping); inspector.setSuffixLanguageMapping(suffixLanguageMapping);
ReportVo report = inspector.inspect(); ReportVo reportVoReturn = inspector.inspect();
return report; return reportVoReturn;
} }
//执行静态化 //执行静态化
......
package com.zjty.inspect.service.impl; package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.ReportDao;
import com.zjty.inspect.dao.TechnologyDao; import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.*; import com.zjty.inspect.entity.*;
import com.zjty.inspect.service.ParameterService;
import com.zjty.inspect.service.ReportService; import com.zjty.inspect.service.ReportService;
import com.zjty.inspect.utils.RedisUtil;
import freemarker.cache.StringTemplateLoader; import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import java.util.Map; import java.util.Map;
import java.util.Optional;
/** /**
* @author Mcj * @author Mcj
...@@ -24,14 +27,12 @@ public class ReportServiceImpl implements ReportService { ...@@ -24,14 +27,12 @@ public class ReportServiceImpl implements ReportService {
@Autowired @Autowired
private TechnologyDao technologyDao; private TechnologyDao technologyDao;
@Autowired
private RedisUtil redisUtil;
public ReportVo set(Report report){ @Autowired
private ParameterService parameterService;
return new ReportVo(); @Autowired
} private ReportDao reportDao;
//执行静态化 //执行静态化
private String generateHtml(String templateContent, Map model ){ private String generateHtml(String templateContent, Map model ){
...@@ -56,4 +57,31 @@ public class ReportServiceImpl implements ReportService { ...@@ -56,4 +57,31 @@ public class ReportServiceImpl implements ReportService {
} }
@Override
public Page findReportByPage(int page) {
PageRequest of = PageRequest.of(page - 1, 10);
org.springframework.data.domain.Page<Report> all = reportDao.findAll(of);
Page<Report> reportPage = new Page<>();
reportPage.setTotalElement((int) all.getTotalElements());
reportPage.setTotalPage(all.getTotalPages());
reportPage.addAll(all.getContent());
return reportPage;
}
@Override
public ReportManage findReportById(String id) {
Optional<Report> report = reportDao.findById(id);
ReportManage reportManage = new ReportManage();
if(report.isPresent()){
reportManage.setReport(report.get());
InspectParameter inspectParameter = parameterService.getParameterById(report.get().getId());
reportManage.setInspectParameter(inspectParameter);
}
return reportManage;
}
@Override
public void saveReport(Report report) {
reportDao.save(report);
}
} }
...@@ -32,7 +32,7 @@ public class BudgetUitl { ...@@ -32,7 +32,7 @@ public class BudgetUitl {
public BudgetVo getBudget(Integer fund, ReportVo report, InspectParameter inspectParameter){ public BudgetVo getBudget(Integer fund, ReportVo report, InspectParameter inspectParameter){
BudgetVo budgetVo = new BudgetVo(); BudgetVo budgetVo = new BudgetVo();
// TODO: 2020-03-05 查询年复利率 // TODO: 2020-03-05 查询年复利率,查询修改,适配和重构占比
inspectParameter.setMoneyRate(1.04); inspectParameter.setMoneyRate(1.04);
//代码重构比 //代码重构比
...@@ -42,7 +42,6 @@ public class BudgetUitl { ...@@ -42,7 +42,6 @@ public class BudgetUitl {
if(report.getRecastMethod()==1){ if(report.getRecastMethod()==1){
inspectParameter.setProportion(0.6); inspectParameter.setProportion(0.6);
}else{ }else{
// TODO: 2020-03-05 查询config表0.3或者0.15
inspectParameter.setProportion(0.3); inspectParameter.setProportion(0.3);
} }
int scale; int scale;
...@@ -72,6 +71,7 @@ public class BudgetUitl { ...@@ -72,6 +71,7 @@ public class BudgetUitl {
strings.add("模块数"); strings.add("模块数");
strings.add("数据库表"); strings.add("数据库表");
strings.add("代码量"); strings.add("代码量");
strings.add("内容");
double coefficient = 1; double coefficient = 1;
List<CoefficientModel> nameIn = coefficientModelDao.findAllByNameIn(strings); List<CoefficientModel> nameIn = coefficientModelDao.findAllByNameIn(strings);
List<CoefficientModel> collect = nameIn.stream().filter(a -> a.getScale() == scale).collect(Collectors.toList()); List<CoefficientModel> collect = nameIn.stream().filter(a -> a.getScale() == scale).collect(Collectors.toList());
...@@ -111,6 +111,10 @@ public class BudgetUitl { ...@@ -111,6 +111,10 @@ public class BudgetUitl {
Double value = model.countCoefficient(inspectParameter.getCodeSize()); Double value = model.countCoefficient(inspectParameter.getCodeSize());
coefficientModelVo.setValue(value); coefficientModelVo.setValue(value);
coefficient*=value; coefficient*=value;
}else if("内容".equals(model.getName())){
Double value = model.countCoefficient(inspectParameter.getContent());
coefficientModelVo.setValue(value);
coefficient*=value;
} }
budgetVo.getCoefficientModelVos().add(coefficientModelVo); budgetVo.getCoefficientModelVos().add(coefficientModelVo);
} }
......
package com.zjty.inspect.utils;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Stack;
/**
* @author Mcj
* @date 2020-03-05 19:20
*/
public class RandomUtil {
public synchronized static String getRandom()
{
String digths = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int base = digths.length();
long now = System.currentTimeMillis();
try {Thread.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
StringBuffer str = new StringBuffer("");
Stack<Character> s = new Stack<Character>();
while(now != 0){
s.push(digths.charAt((int)(now%base)));
now/=base;
}
while(!s.isEmpty()){
str.append(s.pop());
}
StringBuilder stringBuilder = new StringBuilder();
LocalDateTime date = LocalDateTime.now();
String[] split = UUIDUtil.getUUID().split("-");
stringBuilder.append(date.getYear())
.append(date.getMonth())
.append(date.getDayOfMonth())
.append(date.getHour() )
.append(date.getMinute())
.append(date.getSecond())
.append(split[0]);
return stringBuilder.toString();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论