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

Merge branch 'master' of git.yfzx.zjtys.com.cn:912-system/monitor/inspect into mcj-dev

package com.zjty.inspect.config; package com.zjty.inspect.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration @Configuration
public class MvcConfig extends WebMvcConfigurationSupport { public class MvcConfig extends WebMvcConfigurationSupport {
@Autowired @Autowired
...@@ -26,4 +32,14 @@ public class MvcConfig extends WebMvcConfigurationSupport { ...@@ -26,4 +32,14 @@ public class MvcConfig extends WebMvcConfigurationSupport {
registry.addResourceHandler("/webjars/**") registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/"); .addResourceLocations("classpath:/META-INF/resources/webjars/");
} }
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setFastJsonConfig(fastJsonConfig);
converters.add(fastConverter);
}
} }
package com.zjty.inspect.controller; package com.zjty.inspect.controller;
import com.alibaba.fastjson.JSON;
import com.zjty.inspect.entity.AssessmentReport;
import com.zjty.inspect.entity.Evaluation; import com.zjty.inspect.entity.Evaluation;
import com.zjty.inspect.entity.PageResult; import com.zjty.inspect.entity.PageResult;
import com.zjty.inspect.entity.Reform;
import com.zjty.inspect.service.EvaluationService; import com.zjty.inspect.service.EvaluationService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -39,13 +42,15 @@ public class EvaluationController { ...@@ -39,13 +42,15 @@ public class EvaluationController {
if(StringUtils.isEmpty(id)||id.equals("null")){ if(StringUtils.isEmpty(id)||id.equals("null")){
Evaluation e = evaluationService.findByName(name); Evaluation e = evaluationService.findByName(name);
if(e!=null){ if(e!=null){
return ResponseEntity.ok(e.getOutEva()); AssessmentReport assessmentReport = JSON.parseObject(e.getOutEva(), AssessmentReport.class);
return ResponseEntity.ok(assessmentReport);
} }
return ResponseEntity.ok(null); return ResponseEntity.ok(null);
} }
Evaluation evaluation = evaluationService.findById(id); Evaluation evaluation = evaluationService.findById(id);
if(evaluation!=null){ if(evaluation!=null){
return ResponseEntity.ok(evaluation.getOutEva()); AssessmentReport assessmentReport = JSON.parseObject(evaluation.getOutEva(), AssessmentReport.class);
return ResponseEntity.ok(assessmentReport);
} }
return ResponseEntity.ok(null); return ResponseEntity.ok(null);
} }
...@@ -54,7 +59,8 @@ public class EvaluationController { ...@@ -54,7 +59,8 @@ public class EvaluationController {
public ResponseEntity getInName(@PathVariable String name) { public ResponseEntity getInName(@PathVariable String name) {
Evaluation evaluation = evaluationService.findById(name); Evaluation evaluation = evaluationService.findById(name);
if(evaluation!=null){ if(evaluation!=null){
return ResponseEntity.ok(evaluation.getInEva()); Reform reform = JSON.parseObject(evaluation.getInEva(), Reform.class);
return ResponseEntity.ok(reform);
} }
return ResponseEntity.ok(null); return ResponseEntity.ok(null);
} }
......
...@@ -28,7 +28,7 @@ public interface RuleDao extends JpaRepository<Rule,String>,JpaSpecificationExec ...@@ -28,7 +28,7 @@ public interface RuleDao extends JpaRepository<Rule,String>,JpaSpecificationExec
Rule findByTarget(String target); Rule findByTarget(String target);
Rule findByTargetAndSuffixEqualsAndTechnologyIdEquals(String target,String suffix,String technologyId); List<Rule> findByTargetAndSuffixEqualsAndTechnologyIdEquals(String target,String suffix,String technologyId);
/** /**
* 根据技术id查询规则 * 根据技术id查询规则
......
...@@ -17,6 +17,7 @@ public interface TechnologyService { ...@@ -17,6 +17,7 @@ public interface TechnologyService {
*/ */
public void addAdvice(TechnologyQo technologyQo); public void addAdvice(TechnologyQo technologyQo);
public void add(Technology technology); public void add(Technology technology);
public void addTech(Technology technology);
/** /**
* 查询所有技术 * 查询所有技术
......
package com.zjty.inspect.service.impl; package com.zjty.inspect.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zjty.inspect.dao.RuleCollectionDao; import com.zjty.inspect.dao.RuleCollectionDao;
import com.zjty.inspect.dao.RuleDao; import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.*; import com.zjty.inspect.entity.*;
...@@ -17,6 +18,7 @@ import org.springframework.data.jpa.domain.Specification; ...@@ -17,6 +18,7 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
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.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
...@@ -57,8 +59,8 @@ public class RuleServiceImpl implements RuleService { ...@@ -57,8 +59,8 @@ public class RuleServiceImpl implements RuleService {
public void addRule(RuleQo ruleQo) { public void addRule(RuleQo ruleQo) {
List<String> suffixes = ruleQo.getSuffix(); List<String> suffixes = ruleQo.getSuffix();
for (String suffix : suffixes) { for (String suffix : suffixes) {
Rule rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix,ruleQo.getTechnologyId()); List<Rule> rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix,ruleQo.getTechnologyId());
if (rule1 != null) { if (rule1 != null&& rule1.size()>0) {
continue; continue;
} }
Rule rule = new Rule(); Rule rule = new Rule();
...@@ -73,7 +75,19 @@ public class RuleServiceImpl implements RuleService { ...@@ -73,7 +75,19 @@ public class RuleServiceImpl implements RuleService {
ruleCollectionDao.save(ruleCollection); ruleCollectionDao.save(ruleCollection);
} }
public void saveRule(Rule rule) {
String suffix = rule.getSuffix();
List<Rule> rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(rule.getTarget(), suffix,rule.getTechnologyId());
if (rule1 != null&&rule1.size()>0) {
if(rule1.size()>1){
for (int i = 1; i < rule1.size(); i++) {
ruleDao.deleteById(rule1.get(i).getId());
}
}
return;
}
ruleDao.save(rule);
}
@Override @Override
public void addRule(List<Rule> rules) { public void addRule(List<Rule> rules) {
ruleDao.saveAll(rules); ruleDao.saveAll(rules);
...@@ -257,7 +271,7 @@ public class RuleServiceImpl implements RuleService { ...@@ -257,7 +271,7 @@ public class RuleServiceImpl implements RuleService {
} }
syncData.setTechnologies(technologySyns); syncData.setTechnologies(technologySyns);
String s = JSON.toJSONString(syncData); 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文件 //2.生成json文件
FileUtil.write(s,path); FileUtil.write(s,path);
return path; return path;
...@@ -278,12 +292,31 @@ public class RuleServiceImpl implements RuleService { ...@@ -278,12 +292,31 @@ public class RuleServiceImpl implements RuleService {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
//1.导入json文件
String s = readTxt(dest.getAbsolutePath()); String s = readTxt(dest.getAbsolutePath());
System.out.println(s); System.out.println(s);
//1.导入json文件 if(!StringUtils.isEmpty(s)){
//2.清洗规则数据
//3.将数据添加到数据库中 //2.清洗规则数据
//4.生成json文件 //3.将数据添加到数据库中
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){ public String readTxt(String filePath){
......
...@@ -13,6 +13,7 @@ import org.springframework.data.domain.PageRequest; ...@@ -13,6 +13,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
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.util.StringUtils;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
...@@ -75,6 +76,18 @@ public class TechnologyServiceImpl implements TechnologyService { ...@@ -75,6 +76,18 @@ public class TechnologyServiceImpl implements TechnologyService {
technologyDao.save(technology); 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 @Override
public List<Technology> findAllTechnology() { public List<Technology> findAllTechnology() {
return technologyDao.findAll(); return technologyDao.findAll();
......
...@@ -152,13 +152,20 @@ public class FileUtil { ...@@ -152,13 +152,20 @@ public class FileUtil {
} }
} }
File file = new File(path); File file = new File(path);
if (!file.exists()) { if(file.exists()){
try { file.delete();
file.createNewFile(); }
} catch (IOException e) { if (!file.getParentFile().exists()) {
e.printStackTrace(); boolean mkdir = file.getParentFile().mkdirs();
if (!mkdir) {
throw new RuntimeException("创建目标文件所在目录失败!");
} }
} }
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return file; return file;
} }
......
...@@ -50,7 +50,7 @@ spring.resources.static-locations=classpath:/uploads/ ...@@ -50,7 +50,7 @@ spring.resources.static-locations=classpath:/uploads/
# mysql\u6570\u636E\u5E93\u914D\u7F6E # mysql\u6570\u636E\u5E93\u914D\u7F6E
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.datasource.url=jdbc:mysql://192.168.1.249:3306/bservice?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8 #spring.datasource.url=jdbc:mysql://192.168.1.249:3306/bservice?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8
spring.datasource.url=jdbc:mysql://120.55.57.35:3306/adaptation?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8 spring.datasource.url=jdbc:mysql://localhost:3306/adaptation?useSSL=false&serverTimezone=UTC&autoReconnect=true&characterEncoding=utf-8
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=root spring.datasource.password=root
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论