提交 f61abf2e authored 作者: 孙洁清's avatar 孙洁清

评估报告管理页面修改v1.0.4

上级 24a80904
......@@ -17,6 +17,7 @@ public interface TechnologyService {
*/
public void addAdvice(TechnologyQo technologyQo);
public void add(Technology technology);
public void addTech(Technology technology);
/**
* 查询所有技术
......
package com.zjty.inspect.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zjty.inspect.dao.RuleCollectionDao;
import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.*;
......@@ -17,6 +18,7 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.persistence.criteria.Predicate;
......@@ -73,7 +75,14 @@ public class RuleServiceImpl implements RuleService {
ruleCollectionDao.save(ruleCollection);
}
public void saveRule(Rule rule) {
String suffix = rule.getSuffix();
Rule rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(rule.getTarget(), suffix,rule.getTechnologyId());
if (rule1 != null) {
return;
}
ruleDao.save(rule);
}
@Override
public void addRule(List<Rule> rules) {
ruleDao.saveAll(rules);
......@@ -257,7 +266,7 @@ public class RuleServiceImpl implements RuleService {
}
syncData.setTechnologies(technologySyns);
String s = JSON.toJSONString(syncData);
String path=System.getProperty("user.dir")+ File.separator+"inspect"+File.separator+"评测微服务数据.txt";
String path=System.getProperty("user.dir")+ File.separator+"inspect"+File.separator+"inspect.txt";
//2.生成json文件
FileUtil.write(s,path);
return path;
......@@ -278,12 +287,31 @@ public class RuleServiceImpl implements RuleService {
} catch (IOException e) {
e.printStackTrace();
}
//1.导入json文件
String s = readTxt(dest.getAbsolutePath());
System.out.println(s);
//1.导入json文件
if(!StringUtils.isEmpty(s)){
//2.清洗规则数据
//3.将数据添加到数据库中
//4.生成json文件
SyncData syncData = JSON.parseObject(s, SyncData.class);
List<TechnologySyn> technologies = syncData.getTechnologies();
if(technologies!=null&&technologies.size()>0) {
for (TechnologySyn technology : technologies) {
List<Rule> rules = technology.getRules();
if(rules!=null&&rules.size()>0){
for (Rule rule : rules) {
saveRule(rule);
}
}
}
ruleCollectionDao.deleteAll();
List<Rule> all = ruleDao.findAll();
List<RuleCollection> ruleCollections = dataList2RuleCollection(all);
ruleCollectionDao.saveAll(ruleCollections);
}
}
}
public String readTxt(String filePath){
......
......@@ -13,6 +13,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
......@@ -75,6 +76,18 @@ public class TechnologyServiceImpl implements TechnologyService {
technologyDao.save(technology);
}
@Override
public void addTech(Technology technology) {
Optional<Technology> optional = technologyDao.findById(technology.getId());
if(optional.isPresent()){
Technology te = optional.get();
if(te.getTechnologyName().equals(technology.getTechnologyName())){
return;
}
}
}
@Override
public List<Technology> findAllTechnology() {
return technologyDao.findAll();
......
......@@ -152,13 +152,20 @@ public class FileUtil {
}
}
File file = new File(path);
if (!file.exists()) {
if(file.exists()){
file.delete();
}
if (!file.getParentFile().exists()) {
boolean mkdir = file.getParentFile().mkdirs();
if (!mkdir) {
throw new RuntimeException("创建目标文件所在目录失败!");
}
}
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论