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

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

package com.zjty.inspect.controller;
import com.zjty.inspect.entity.Page;
import com.zjty.inspect.entity.PageResult;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo;
......@@ -9,7 +10,6 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -43,13 +43,11 @@ public class RuleController {
/**
* 修改规则
* @param ruleQo 规则封装
* @param id id
* @return
*/
@PostMapping(value = "/{id}")
@PostMapping(value = "/update")
@ApiOperation("修改规则")
public ResponseEntity update(@RequestBody RuleQo ruleQo,@PathVariable String id){
ruleQo.setId(id);
public ResponseEntity update(@RequestBody RuleQo ruleQo){
ruleService.upRule(ruleQo);
return ResponseEntity.ok(200);
}
......@@ -103,7 +101,7 @@ public class RuleController {
})
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public ResponseEntity findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Rule> pageList = ruleService.findSearch(searchMap, page, size);
return ResponseEntity.ok(new PageResult<Rule>(pageList.getTotalElements(), pageList.getContent()) );
Page<RuleQo> search = ruleService.findSearch(searchMap, page, size);
return ResponseEntity.ok(search);
}
}
......@@ -36,4 +36,6 @@ public interface RuleDao extends JpaRepository<Rule,String>,JpaSpecificationExec
* @return
*/
List<Rule> findAllByTechnologyIdIn(List<String> ids);
List<Rule> findAllByTechnologyIdEqualsAndTargetEquals(String techId,String target);
}
......@@ -38,4 +38,8 @@ public class Page<T> {
public List<T> getObjects() {
return objects;
}
public void setObjects(List<T> objects) {
this.objects=objects;
}
}
......@@ -199,9 +199,7 @@ public class Inspector {
Files.walkFileTree(Paths.get(inspectParameter.getSourceAddress()), new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
//这里是对于路径(文件夹)的过滤,在这里读不到文件如果能判断,可以返回FileVisitResult.SKIP_SUBTREE 不访问子目录
//if(dir.getFileName().startsWith("."))return FileVisitResult.SKIP_SUBTREE;
//if (dir.endsWith(".git"))return FileVisitResult.SKIP_SUBTREE;
return FileVisitResult.CONTINUE;
}
......@@ -274,7 +272,6 @@ public class Inspector {
ruleSuffixFilePathMap.get(entry.getValue()).add(file);
}
}
//检查到普通jar包
return FileVisitResult.CONTINUE;
}
......@@ -316,7 +313,6 @@ public class Inspector {
public ReportVo analysis() {
DependencyVo dependencyVo = new DependencyVo();
setReportLanguageAndFrame();
//查询所有规则
ruleTransform(report.getRecastMethod());
//解析配置文件集合
......@@ -375,9 +371,6 @@ public class Inspector {
if (path1.toAbsolutePath().toString().endsWith("jar") || path1.toAbsolutePath().toString().endsWith("class")) {
continue;
}
if(path1.getFileName().toString().equals("js")){
System.out.println("d");
}
valiWarn(rules, path1, path1.getFileName().toString(), 0);
//将文件的每一行都与规则匹配
List<String> strings = Files.readAllLines(path1);
......
package com.zjty.inspect.service;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.Page;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.entity.RuleVo;
import org.springframework.data.domain.Page;
import java.util.List;
import java.util.Map;
......@@ -39,10 +37,10 @@ public interface RuleService {
* 查询所有规则
* @return 规则
*/
List<Rule> findAll();
List<RuleQo> findAll();
List<Rule> findByName(String name);
List<RuleQo> findByName(String name);
Page<Rule> findSearch(Map searchMap, int page, int size);
Page<RuleQo> findSearch(Map searchMap, int page, int size);
void test();
}
package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.ExcelDataVo;
import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService;
......@@ -99,10 +97,17 @@ public class RuleServiceImpl implements RuleService {
* @return
*/
@Override
public Page<Rule> findSearch(Map whereMap, int page, int size) {
public com.zjty.inspect.entity.Page<RuleQo> findSearch(Map whereMap, int page, int size) {
Specification<Rule> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page - 1, size);
return ruleDao.findAll(specification, pageRequest);
Page<Rule> all = ruleDao.findAll(specification, pageRequest);
List<RuleQo> ruleQos = data2RuleQo(all.getContent());
com.zjty.inspect.entity.Page<RuleQo> myPage = new com.zjty.inspect.entity.Page<>();
myPage.setTotalPage(all.getTotalPages());
myPage.setTotalElement((int)all.getTotalElements());
myPage.setObjects(ruleQos);
return myPage;
}
/**
......@@ -133,18 +138,11 @@ public class RuleServiceImpl implements RuleService {
@Override
public void upRule(RuleQo ruleQo) {
List<String> suffixes = ruleQo.getSuffix();
for (String suffix : suffixes) {
Rule rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix,ruleQo.getTechnologyId());
if (rule1 != null) {
return;
}
rule1.setTarget(ruleQo.getTarget());
rule1.setSuffix(suffix);
rule1.setTechnologyId(ruleQo.getTechnologyId());
rule1.setTechnologyName(ruleQo.getTechnologyName());
ruleDao.save(rule1);
List<Rule> rules = ruleDao.findAllByTechnologyIdEqualsAndTargetEquals(ruleQo.getTechnologyId(), ruleQo.getTarget());
for (Rule rule : rules) {
ruleDao.deleteById(rule.getId());
}
addRule(ruleQo);
}
@Override
......@@ -160,20 +158,53 @@ public class RuleServiceImpl implements RuleService {
/**
* 查询所有规则
* 规则唯一 关键字+后缀+技术id
* target:xx,suffix:js:tech:gjfgj
* target:xx,suffix:html:tech:gjfgj
* target:xx,suffix:css:tech:gjfgj
*
* target:xx,suffix:html,css,js:tech:gjfgj
* @return RuleVoList
*/
@Override
public List<Rule> findAll() {
return ruleDao.findAll();
public List<RuleQo> findAll() {
List<Rule> rules = ruleDao.findAll();
List<RuleQo> ruleQos = data2RuleQo(rules);
return ruleQos;
}
@Override
public List<Rule> findByName(String name) {
public List<RuleQo> findByName(String name) {
List<Rule> rules = ruleDao.findAllByTargetLike("%" + name + "%");
if (rules != null && rules.size() > 0) {
return rules;
return data2RuleQo(rules);
}
return null;
}
private List<RuleQo> data2RuleQo(List<Rule> rules){
HashMap<String, RuleQo> hashMap = new HashMap<>();
for (Rule rule : rules) {
if(!hashMap.containsKey(rule.getTarget()+rule.getTechnologyId())){
RuleQo ruleQo = new RuleQo();
ruleQo.setId(rule.getId());
ruleQo.setTarget(rule.getTarget());
ruleQo.setTechnologyId(rule.getTechnologyId());
ruleQo.setTechnologyName(rule.getTechnologyName());
ArrayList<String> suffix = new ArrayList<>();
suffix.add(rule.getSuffix());
ruleQo.setSuffix(suffix);
hashMap.put(rule.getTarget()+rule.getTechnologyId(),ruleQo);
}else{
RuleQo ruleQo = hashMap.get(rule.getTarget() + rule.getTechnologyId());
ruleQo.getSuffix().add(rule.getSuffix());
if(ruleQo.getSuffix().size()>1){
System.out.println(rule.getTarget()+rule.getTechnologyId());
System.out.println(ruleQo.getSuffix());
}
}
}
return new ArrayList<>(hashMap.values());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论