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

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

...@@ -32,7 +32,7 @@ public class AopIntercept { ...@@ -32,7 +32,7 @@ public class AopIntercept {
this.user = user; this.user = user;
} }
@Pointcut("execution(* com.zjty.inspect.inspect.Inspector.inspect(..))") @Pointcut("@annotation(com.zjty.inspect.aop.AuthAnnotation)")
public void doPointCut() { public void doPointCut() {
} }
......
...@@ -39,7 +39,7 @@ public class RuleController { ...@@ -39,7 +39,7 @@ public class RuleController {
@PostMapping @PostMapping
@ApiOperation("新增规则") @ApiOperation("新增规则")
public ResponseEntity rule(@RequestBody Rule rule){ public ResponseEntity rule(@RequestBody Rule rule){
Rule rule1 = ruleService.addRulePlugs(rule); Rule rule1 = ruleService.addRulePlus(rule);
if(rule1!=null){ if(rule1!=null){
return ResponseEntity.ok(rule1); return ResponseEntity.ok(rule1);
} }
...@@ -53,7 +53,7 @@ public class RuleController { ...@@ -53,7 +53,7 @@ public class RuleController {
@PostMapping(value = "/update") @PostMapping(value = "/update")
@ApiOperation("修改规则") @ApiOperation("修改规则")
public ResponseEntity update(@RequestBody Rule rule){ public ResponseEntity update(@RequestBody Rule rule){
ruleService.upRulePlugs(rule); ruleService.upRulePlus(rule);
return ResponseEntity.ok(200); return ResponseEntity.ok(200);
} }
/** /**
...@@ -64,7 +64,7 @@ public class RuleController { ...@@ -64,7 +64,7 @@ public class RuleController {
@ApiOperation("根据数据封装删除规则") @ApiOperation("根据数据封装删除规则")
@DeleteMapping @DeleteMapping
public ResponseEntity deleteByQo(@RequestBody String id){ public ResponseEntity deleteByQo(@RequestBody String id){
ruleService.deleteRulePlugs(id); ruleService.deleteRulePlus(id);
return ResponseEntity.ok(200); return ResponseEntity.ok(200);
} }
......
...@@ -17,8 +17,8 @@ public interface RuleService { ...@@ -17,8 +17,8 @@ public interface RuleService {
* @param ruleQo 规则封装类 * @param ruleQo 规则封装类
*/ */
public void addRule(RuleQo ruleQo); public void addRule(RuleQo ruleQo);
public Rule addRulePlugs(Rule rule); public Rule addRulePlus(Rule rule);
public void addListRulePlugs(List<Rule> rules); public void addListRulePlus(List<Rule> rules);
public void addRule(List<Rule> rules); public void addRule(List<Rule> rules);
/** /**
...@@ -26,14 +26,14 @@ public interface RuleService { ...@@ -26,14 +26,14 @@ public interface RuleService {
* @param ruleQo 规则封装类 * @param ruleQo 规则封装类
*/ */
public void upRule(RuleQo ruleQo); public void upRule(RuleQo ruleQo);
public void upRulePlugs(Rule rule); public void upRulePlus(Rule rule);
public String exportData(); public String exportData();
/** /**
* 删除规则 * 删除规则
* @param ruleQo 规则封装类 * @param ruleQo 规则封装类
*/ */
public void deleteRule(RuleQo ruleQo); public void deleteRule(RuleQo ruleQo);
public void deleteRulePlugs(String id); public void deleteRulePlus(String id);
/** /**
* 查询所有规则 * 查询所有规则
......
...@@ -56,16 +56,16 @@ public class RuleServiceImpl implements RuleService { ...@@ -56,16 +56,16 @@ public class RuleServiceImpl implements RuleService {
private RuleCollectionDao ruleCollectionDao; private RuleCollectionDao ruleCollectionDao;
public List<Rule> mcjAllRule(){ public List<Rule> mcjAllRule() {
List<Rule> rules = ruleDao.findAll(); List<Rule> rules = ruleDao.findAll();
List<Rule> ruleList=new ArrayList<>(); List<Rule> ruleList = new ArrayList<>();
if(rules!=null&&rules.size()>0){ if (rules != null && rules.size() > 0) {
for (Rule rule : rules) { for (Rule rule : rules) {
String suffix = rule.getSuffix(); String suffix = rule.getSuffix();
String[] split = suffix.split(","); String[] split = suffix.split(",");
for (String s : split) { for (String s : split) {
Rule rule1=new Rule(); Rule rule1 = new Rule();
BeanUtils.copyProperties(rule,rule1); BeanUtils.copyProperties(rule, rule1);
rule1.setSuffix(s); rule1.setSuffix(s);
ruleList.add(rule1); ruleList.add(rule1);
} }
...@@ -73,18 +73,21 @@ public class RuleServiceImpl implements RuleService { ...@@ -73,18 +73,21 @@ public class RuleServiceImpl implements RuleService {
} }
return ruleList; return ruleList;
} }
public Rule addRulePlugs(Rule rule){
if(StringUtils.isEmpty(rule.getTarget())){ @Override
public Rule addRulePlus(Rule rule) {
if (StringUtils.isEmpty(rule.getTarget())) {
return null; return null;
} }
Rule rule1 = ruleDao.findByTarget(rule.getTarget()); Rule rule1 = ruleDao.findByTarget(rule.getTarget());
if(rule1==null){ if (rule1 == null) {
rule.setId(UUIDUtil.getUUID()); rule.setId(UUIDUtil.getUUID());
Rule save = ruleDao.save(rule); Rule save = ruleDao.save(rule);
return save; return save;
} }
return null; return null;
} }
/** /**
* 新增规则 * 新增规则
* *
...@@ -94,8 +97,8 @@ public class RuleServiceImpl implements RuleService { ...@@ -94,8 +97,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) {
List<Rule> rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix,ruleQo.getTechnologyId()); List<Rule> rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix, ruleQo.getTechnologyId());
if (rule1 != null&& rule1.size()>0) { if (rule1 != null && rule1.size() > 0) {
continue; continue;
} }
Rule rule = new Rule(); Rule rule = new Rule();
...@@ -110,11 +113,12 @@ public class RuleServiceImpl implements RuleService { ...@@ -110,11 +113,12 @@ public class RuleServiceImpl implements RuleService {
ruleCollectionDao.save(ruleCollection); ruleCollectionDao.save(ruleCollection);
} }
public void saveRule(Rule rule) { public void saveRule(Rule rule) {
String suffix = rule.getSuffix(); String suffix = rule.getSuffix();
List<Rule> rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(rule.getTarget(), suffix,rule.getTechnologyId()); List<Rule> rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(rule.getTarget(), suffix, rule.getTechnologyId());
if (rule1 != null&&rule1.size()>0) { if (rule1 != null && rule1.size() > 0) {
if(rule1.size()>1){ if (rule1.size() > 1) {
for (int i = 1; i < rule1.size(); i++) { for (int i = 1; i < rule1.size(); i++) {
ruleDao.deleteById(rule1.get(i).getId()); ruleDao.deleteById(rule1.get(i).getId());
} }
...@@ -123,12 +127,15 @@ public class RuleServiceImpl implements RuleService { ...@@ -123,12 +127,15 @@ public class RuleServiceImpl implements RuleService {
} }
ruleDao.save(rule); ruleDao.save(rule);
} }
//批量添加 //批量添加
public void addListRulePlugs(List<Rule> rules){ @Override
public void addListRulePlus(List<Rule> rules) {
for (Rule rule : rules) { for (Rule rule : rules) {
addRulePlugs(rule); addRulePlus(rule);
} }
} }
@Override @Override
public void addRule(List<Rule> rules) { public void addRule(List<Rule> rules) {
ruleDao.saveAll(rules); ruleDao.saveAll(rules);
...@@ -159,7 +166,6 @@ public class RuleServiceImpl implements RuleService { ...@@ -159,7 +166,6 @@ public class RuleServiceImpl implements RuleService {
} }
/** /**
* 动态条件构建 * 动态条件构建
* *
...@@ -198,23 +204,24 @@ public class RuleServiceImpl implements RuleService { ...@@ -198,23 +204,24 @@ public class RuleServiceImpl implements RuleService {
for (Rule rule : rules) { for (Rule rule : rules) {
ruleDao.deleteById(rule.getId()); ruleDao.deleteById(rule.getId());
} }
if(ruleCollection!=null){ if (ruleCollection != null) {
ruleCollectionDao.deleteById(ruleCollection.getId()); ruleCollectionDao.deleteById(ruleCollection.getId());
} }
addRule(ruleQo); addRule(ruleQo);
} }
@Override @Override
public void upRulePlugs(Rule rule) { public void upRulePlus(Rule rule) {
Rule rule1 = ruleDao.findByTargetAndIdNot(rule.getTarget(), rule.getId()); Rule rule1 = ruleDao.findByTargetAndIdNot(rule.getTarget(), rule.getId());
if(rule1==null){ if (rule1 == null) {
ruleDao.save(rule); ruleDao.save(rule);
}else{ } else {
ruleDao.deleteById(rule.getId()); ruleDao.deleteById(rule.getId());
} }
} }
public void deleteRulePlugs(String id){ @Override
public void deleteRulePlus(String id) {
ruleDao.deleteById(id); ruleDao.deleteById(id);
} }
...@@ -227,7 +234,7 @@ public class RuleServiceImpl implements RuleService { ...@@ -227,7 +234,7 @@ public class RuleServiceImpl implements RuleService {
ruleDao.deleteById(rule.getId()); ruleDao.deleteById(rule.getId());
} }
RuleCollection ruleCollection = ruleCollectionDao.findAllByTechnologyIdEqualsAndTargetEquals(ruleQo.getTechnologyId(), ruleQo.getTarget()); RuleCollection ruleCollection = ruleCollectionDao.findAllByTechnologyIdEqualsAndTargetEquals(ruleQo.getTechnologyId(), ruleQo.getTarget());
if(ruleCollection!=null){ if (ruleCollection != null) {
ruleCollectionDao.deleteById(ruleCollection.getId()); ruleCollectionDao.deleteById(ruleCollection.getId());
} }
...@@ -239,8 +246,9 @@ public class RuleServiceImpl implements RuleService { ...@@ -239,8 +246,9 @@ public class RuleServiceImpl implements RuleService {
* target:xx,suffix:js:tech:gjfgj * target:xx,suffix:js:tech:gjfgj
* target:xx,suffix:html:tech:gjfgj * target:xx,suffix:html:tech:gjfgj
* target:xx,suffix:css:tech:gjfgj * target:xx,suffix:css:tech:gjfgj
* * <p>
* target:xx,suffix:html,css,js:tech:gjfgj * target:xx,suffix:html,css,js:tech:gjfgj
*
* @return RuleVoList * @return RuleVoList
*/ */
@Override @Override
...@@ -260,7 +268,7 @@ public class RuleServiceImpl implements RuleService { ...@@ -260,7 +268,7 @@ public class RuleServiceImpl implements RuleService {
return rules; return rules;
} }
private RuleCollection dataQo2RuleCollection(RuleQo ruleQo){ private RuleCollection dataQo2RuleCollection(RuleQo ruleQo) {
RuleCollection ruleCollection = new RuleCollection(); RuleCollection ruleCollection = new RuleCollection();
ruleCollection.setTechnologyName(ruleQo.getTechnologyName()); ruleCollection.setTechnologyName(ruleQo.getTechnologyName());
ruleCollection.setTechnologyId(ruleQo.getTechnologyId()); ruleCollection.setTechnologyId(ruleQo.getTechnologyId());
...@@ -268,9 +276,9 @@ public class RuleServiceImpl implements RuleService { ...@@ -268,9 +276,9 @@ public class RuleServiceImpl implements RuleService {
ruleCollection.setId(UUIDUtil.getUUID()); ruleCollection.setId(UUIDUtil.getUUID());
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (String suffix : ruleQo.getSuffix()) { for (String suffix : ruleQo.getSuffix()) {
if(stringBuilder.length()==0){ if (stringBuilder.length() == 0) {
stringBuilder.append(suffix); stringBuilder.append(suffix);
}else{ } else {
stringBuilder.append(",").append(suffix); stringBuilder.append(",").append(suffix);
} }
} }
...@@ -278,19 +286,19 @@ public class RuleServiceImpl implements RuleService { ...@@ -278,19 +286,19 @@ public class RuleServiceImpl implements RuleService {
return ruleCollection; return ruleCollection;
} }
private List<RuleCollection> dataList2RuleCollection(List<Rule> rules){ private List<RuleCollection> dataList2RuleCollection(List<Rule> rules) {
ArrayList<RuleCollection> ruleCollections = new ArrayList<>(); ArrayList<RuleCollection> ruleCollections = new ArrayList<>();
HashMap<String, ArrayList<String>> map = new HashMap<>(); HashMap<String, ArrayList<String>> map = new HashMap<>();
HashMap<String, Rule> ruleMap = new HashMap<>(); HashMap<String, Rule> ruleMap = new HashMap<>();
for (Rule rule : rules) { for (Rule rule : rules) {
ruleMap.put(rule.getTarget()+":"+rule.getTechnologyId(),rule); ruleMap.put(rule.getTarget() + ":" + rule.getTechnologyId(), rule);
if(map.containsKey(rule.getTarget()+":"+rule.getTechnologyId())){ if (map.containsKey(rule.getTarget() + ":" + rule.getTechnologyId())) {
ArrayList<String> suffix = map.get(rule.getTarget()+":"+rule.getTechnologyId()); ArrayList<String> suffix = map.get(rule.getTarget() + ":" + rule.getTechnologyId());
suffix.add(rule.getSuffix()); suffix.add(rule.getSuffix());
}else{ } else {
ArrayList<String> suffix = new ArrayList<>(); ArrayList<String> suffix = new ArrayList<>();
suffix.add(rule.getSuffix()); suffix.add(rule.getSuffix());
map.put(rule.getTarget()+":"+rule.getTechnologyId(),suffix); map.put(rule.getTarget() + ":" + rule.getTechnologyId(), suffix);
} }
} }
...@@ -303,9 +311,9 @@ public class RuleServiceImpl implements RuleService { ...@@ -303,9 +311,9 @@ public class RuleServiceImpl implements RuleService {
ruleCollection.setId(UUIDUtil.getUUID()); ruleCollection.setId(UUIDUtil.getUUID());
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (String suffix : map.get(target)) { for (String suffix : map.get(target)) {
if(stringBuilder.length()==0){ if (stringBuilder.length() == 0) {
stringBuilder.append(suffix); stringBuilder.append(suffix);
}else{ } else {
stringBuilder.append(",").append(suffix); stringBuilder.append(",").append(suffix);
} }
} }
...@@ -315,33 +323,35 @@ public class RuleServiceImpl implements RuleService { ...@@ -315,33 +323,35 @@ public class RuleServiceImpl implements RuleService {
return ruleCollections; return ruleCollections;
} }
public String exportData(){ @Override
SyncData syncData=new SyncData(); public String exportData() {
List<TechnologySyn> technologySyns=new ArrayList<>(); SyncData syncData = new SyncData();
List<TechnologySyn> technologySyns = new ArrayList<>();
//1.生成数据 //1.生成数据
List<Technology> technologies = technologyService.findAllTechnology(); List<Technology> technologies = technologyService.findAllTechnology();
for (Technology technology : technologies) { for (Technology technology : technologies) {
TechnologySyn technologySyn=new TechnologySyn(); TechnologySyn technologySyn = new TechnologySyn();
BeanUtils.copyProperties(technology,technologySyn); BeanUtils.copyProperties(technology, technologySyn);
List<Rule> rules = ruleDao.findAllByTechnologyId(technology.getId()); List<Rule> rules = ruleDao.findAllByTechnologyId(technology.getId());
technologySyn.setRules(rules); technologySyn.setRules(rules);
technologySyns.add(technologySyn); technologySyns.add(technologySyn);
} }
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+"inspect.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;
} }
@Override @Override
public void importRules(MultipartFile file) { public void importRules(MultipartFile file) {
if (file.isEmpty()) { if (file.isEmpty()) {
return; return;
} }
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
String fileType = fileName.substring(0,fileName.lastIndexOf(".")); String fileType = fileName.substring(0, fileName.lastIndexOf("."));
File dest = new File(System.getProperty("user.dir") +File.separator+"inspect"+File.separator+UUIDUtil.getUUID()+File.separator+fileType); File dest = new File(System.getProperty("user.dir") + File.separator + "inspect" + File.separator + UUIDUtil.getUUID() + File.separator + fileType);
if (!dest.getParentFile().exists()) { if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs(); dest.getParentFile().mkdirs();
} }
...@@ -353,16 +363,16 @@ public class RuleServiceImpl implements RuleService { ...@@ -353,16 +363,16 @@ public class RuleServiceImpl implements RuleService {
//1.导入json文件 //1.导入json文件
String s = readTxt(dest.getAbsolutePath()); String s = readTxt(dest.getAbsolutePath());
System.out.println(s); System.out.println(s);
if(!StringUtils.isEmpty(s)){ if (!StringUtils.isEmpty(s)) {
//2.清洗规则数据 //2.清洗规则数据
//3.将数据添加到数据库中 //3.将数据添加到数据库中
SyncData syncData = JSON.parseObject(s, SyncData.class); SyncData syncData = JSON.parseObject(s, SyncData.class);
List<TechnologySyn> technologies = syncData.getTechnologies(); List<TechnologySyn> technologies = syncData.getTechnologies();
if(technologies!=null&&technologies.size()>0) { if (technologies != null && technologies.size() > 0) {
for (TechnologySyn technology : technologies) { for (TechnologySyn technology : technologies) {
List<Rule> rules = technology.getRules(); List<Rule> rules = technology.getRules();
if(rules!=null&&rules.size()>0){ if (rules != null && rules.size() > 0) {
for (Rule rule : rules) { for (Rule rule : rules) {
saveRule(rule); saveRule(rule);
} }
...@@ -377,7 +387,7 @@ public class RuleServiceImpl implements RuleService { ...@@ -377,7 +387,7 @@ public class RuleServiceImpl implements RuleService {
} }
public String readTxt(String filePath){ public String readTxt(String filePath) {
try { try {
String encoding = "UTF-8"; String encoding = "UTF-8";
File file = new File(filePath); File file = new File(filePath);
...@@ -403,7 +413,8 @@ public class RuleServiceImpl implements RuleService { ...@@ -403,7 +413,8 @@ public class RuleServiceImpl implements RuleService {
} }
return null; return null;
} }
public void syncData(){
public void syncData() {
//1.导入json数据 //1.导入json数据
//2.清空数据库 //2.清空数据库
//3.导入到标准库 //3.导入到标准库
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论