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

mcj:新增规则查询逻辑,新增表

上级 760b10ab
package com.zjty.inspect.controller; package com.zjty.inspect.controller;
import com.zjty.inspect.entity.Page; import com.zjty.inspect.entity.*;
import com.zjty.inspect.entity.PageResult;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService; import com.zjty.inspect.service.RuleService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -92,7 +89,7 @@ public class RuleController { ...@@ -92,7 +89,7 @@ public class RuleController {
}) })
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public ResponseEntity findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public ResponseEntity findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<RuleQo> search = ruleService.findSearch(searchMap, page, size); Page<RuleCollection> search = ruleService.findSearch(searchMap, page, size);
return ResponseEntity.ok(search); return ResponseEntity.ok(search);
} }
} }
...@@ -32,7 +32,7 @@ public class Rule { ...@@ -32,7 +32,7 @@ public class Rule {
@Column(length = 48) @Column(length = 48)
private String id; private String id;
/** /**
* 建议 * 适配技术名称
*/ */
private String technologyName; private String technologyName;
/** /**
......
package com.zjty.inspect.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Mcj
* @date 2020-02-27 14:42
*/
@Data
@ApiModel(value = "规则类")
public class RuleAndReportVo {
/**
* 发现问题的文件地址
*/
private String filePath;
/**
* 匹配行数
*/
@ApiModelProperty(value = "权限",example = "1")
private Integer lineNum;
}
package com.zjty.inspect.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
/**
* @author Mcj
* @date 2020-02-27 14:42
*/
@Data
@Entity
@ApiModel(value = "规则类")
public class RuleCollection {
/**
* 主键id
*/
@Id
@Column(length = 48)
private String id;
/**
* 技术名称
*/
private String technologyName;
/**
* 目标关键字
*/
private String target;
/**
* 匹配的文件后缀
*/
private String suffix;
/**
* 适配技术id
*/
private String technologyId;
/**
* 数据创建时间
*/
@Column(name="create_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false,updatable = false)
@CreatedDate
private Date createDate;
/**
* 数据更新时间
*/
@Column(name="update_time",columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",insertable = false)
@LastModifiedDate
private Date updateDate;
}
package com.zjty.inspect.service; package com.zjty.inspect.service;
import com.zjty.inspect.entity.Page; import com.zjty.inspect.entity.Page;
import com.zjty.inspect.entity.RuleCollection;
import com.zjty.inspect.entity.RuleQo; import com.zjty.inspect.entity.RuleQo;
import java.util.List; import java.util.List;
...@@ -21,11 +22,6 @@ public interface RuleService { ...@@ -21,11 +22,6 @@ public interface RuleService {
* @param ruleQo 规则封装类 * @param ruleQo 规则封装类
*/ */
public void upRule(RuleQo ruleQo); public void upRule(RuleQo ruleQo);
/**
* 根据id删除规则
* @param id
*/
public void deleteById(String id);
/** /**
* 删除规则 * 删除规则
...@@ -37,9 +33,9 @@ public interface RuleService { ...@@ -37,9 +33,9 @@ public interface RuleService {
* 查询所有规则 * 查询所有规则
* @return 规则 * @return 规则
*/ */
List<RuleQo> findAll(); List<RuleCollection> findAll();
List<RuleQo> findByName(String name); List<RuleCollection> findByName(String name);
Page<RuleQo> findSearch(Map searchMap, int page, int size); Page<RuleCollection> findSearch(Map searchMap, int page, int size);
} }
package com.zjty.inspect.service.impl; package com.zjty.inspect.service.impl;
import com.zjty.inspect.dao.RuleCollectionDao;
import com.zjty.inspect.dao.RuleDao; import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.entity.ExcelDataVo; import com.zjty.inspect.entity.ExcelDataVo;
import com.zjty.inspect.entity.Rule; import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleCollection;
import com.zjty.inspect.entity.RuleQo; import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService; import com.zjty.inspect.service.RuleService;
import com.zjty.inspect.service.TechnologyService; import com.zjty.inspect.service.TechnologyService;
...@@ -38,9 +40,9 @@ public class RuleServiceImpl implements RuleService { ...@@ -38,9 +40,9 @@ public class RuleServiceImpl implements RuleService {
*/ */
@Autowired @Autowired
private RuleDao ruleDao; private RuleDao ruleDao;
@Autowired
private TechnologyService technologyService;
@Autowired
private RuleCollectionDao ruleCollectionDao;
/** /**
* 新增规则 * 新增规则
...@@ -53,7 +55,7 @@ public class RuleServiceImpl implements RuleService { ...@@ -53,7 +55,7 @@ public class RuleServiceImpl implements RuleService {
for (String suffix : suffixes) { for (String suffix : suffixes) {
Rule rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix,ruleQo.getTechnologyId()); Rule rule1 = ruleDao.findByTargetAndSuffixEqualsAndTechnologyIdEquals(ruleQo.getTarget(), suffix,ruleQo.getTechnologyId());
if (rule1 != null) { if (rule1 != null) {
return; continue;
} }
Rule rule = new Rule(); Rule rule = new Rule();
rule.setTarget(ruleQo.getTarget()); rule.setTarget(ruleQo.getTarget());
...@@ -63,6 +65,8 @@ public class RuleServiceImpl implements RuleService { ...@@ -63,6 +65,8 @@ public class RuleServiceImpl implements RuleService {
rule.setId(UUIDUtil.getUUID()); rule.setId(UUIDUtil.getUUID());
ruleDao.save(rule); ruleDao.save(rule);
} }
RuleCollection ruleCollection = data2RuleCollection(ruleQo);
ruleCollectionDao.save(ruleCollection);
} }
...@@ -75,17 +79,16 @@ public class RuleServiceImpl implements RuleService { ...@@ -75,17 +79,16 @@ public class RuleServiceImpl implements RuleService {
* @return * @return
*/ */
@Override @Override
public com.zjty.inspect.entity.Page<RuleQo> findSearch(Map whereMap, int page, int size) { public com.zjty.inspect.entity.Page<RuleCollection> findSearch(Map whereMap, int page, int size) {
Specification<Rule> specification = createSpecification(whereMap); Specification<RuleCollection> specification = createSpecification(whereMap);
Sort sort = new Sort(Sort.Direction.DESC, "updateDate"); Sort sort = new Sort(Sort.Direction.DESC, "updateDate");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort); PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Page<Rule> all = ruleDao.findAll(specification, pageRequest); Page<RuleCollection> ruleCollections = ruleCollectionDao.findAll(specification, pageRequest);
List<RuleQo> ruleQos = data2RuleQo(all.getContent());
com.zjty.inspect.entity.Page<RuleQo> myPage = new com.zjty.inspect.entity.Page<>(); com.zjty.inspect.entity.Page<RuleCollection> myPage = new com.zjty.inspect.entity.Page<>();
myPage.setTotalPage(all.getTotalPages()); myPage.setTotalPage(ruleCollections.getTotalPages());
myPage.setTotalElement((int)all.getTotalElements()); myPage.setTotalElement((int)ruleCollections.getTotalElements());
myPage.setObjects(ruleQos); myPage.setObjects(ruleCollections.getContent());
return myPage; return myPage;
} }
...@@ -95,22 +98,18 @@ public class RuleServiceImpl implements RuleService { ...@@ -95,22 +98,18 @@ public class RuleServiceImpl implements RuleService {
* @param searchMap * @param searchMap
* @return * @return
*/ */
private Specification<Rule> createSpecification(Map searchMap) { private Specification<RuleCollection> createSpecification(Map searchMap) {
return new Specification<Rule>() { return (root, query, cb) -> {
List<Predicate> predicateList = new ArrayList<>();
@Override
public Predicate toPredicate(Root<Rule> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
if (searchMap.get("technologyName") != null && !"".equals(searchMap.get("technologyName"))) { if (searchMap.get("technologyName") != null && !"".equals(searchMap.get("technologyName"))) {
predicateList.add(cb.like(root.get("technologyName").as(String.class), "%" + (String) searchMap.get("technologyName") + "%")); predicateList.add(cb.like(root.get("technologyName").as(String.class), "%" + searchMap.get("technologyName") + "%"));
} }
if (searchMap.get("target") != null && !"".equals(searchMap.get("target"))) { if (searchMap.get("target") != null && !"".equals(searchMap.get("target"))) {
predicateList.add(cb.like(root.get("target").as(String.class), "%" + (String) searchMap.get("target") + "%")); predicateList.add(cb.like(root.get("target").as(String.class), "%" + searchMap.get("target") + "%"));
} }
return cb.and(predicateList.toArray(new Predicate[predicateList.size()])); return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
}
}; };
} }
...@@ -119,16 +118,16 @@ public class RuleServiceImpl implements RuleService { ...@@ -119,16 +118,16 @@ public class RuleServiceImpl implements RuleService {
public void upRule(RuleQo ruleQo) { public void upRule(RuleQo ruleQo) {
RuleQo oldRule = ruleQo.getOldRule(); RuleQo oldRule = ruleQo.getOldRule();
List<Rule> rules = ruleDao.findAllByTechnologyIdEqualsAndTargetEquals(oldRule.getTechnologyId(), oldRule.getTarget()); List<Rule> rules = ruleDao.findAllByTechnologyIdEqualsAndTargetEquals(oldRule.getTechnologyId(), oldRule.getTarget());
RuleCollection ruleCollection = ruleCollectionDao.findAllByTechnologyIdEqualsAndTargetEquals(oldRule.getTechnologyId(), oldRule.getTarget());
for (Rule rule : rules) { for (Rule rule : rules) {
ruleDao.deleteById(rule.getId()); ruleDao.deleteById(rule.getId());
} }
if(ruleCollection!=null){
ruleCollectionDao.deleteById(ruleCollection.getId());
}
addRule(ruleQo); addRule(ruleQo);
} }
@Override
public void deleteById(String id) {
ruleDao.deleteById(id);
}
@Override @Override
@Modifying @Modifying
...@@ -137,6 +136,11 @@ public class RuleServiceImpl implements RuleService { ...@@ -137,6 +136,11 @@ public class RuleServiceImpl implements RuleService {
for (Rule rule : rules) { for (Rule rule : rules) {
ruleDao.deleteById(rule.getId()); ruleDao.deleteById(rule.getId());
} }
RuleCollection ruleCollection = ruleCollectionDao.findAllByTechnologyIdEqualsAndTargetEquals(ruleQo.getTechnologyId(), ruleQo.getTarget());
if(ruleCollection!=null){
ruleCollectionDao.deleteById(ruleCollection.getId());
}
} }
/** /**
...@@ -150,19 +154,15 @@ public class RuleServiceImpl implements RuleService { ...@@ -150,19 +154,15 @@ public class RuleServiceImpl implements RuleService {
* @return RuleVoList * @return RuleVoList
*/ */
@Override @Override
public List<RuleQo> findAll() { public List<RuleCollection> findAll() {
List<Rule> rules = ruleDao.findAll(); List<RuleCollection> rules = ruleCollectionDao.findAll();
List<RuleQo> ruleQos = data2RuleQo(rules); return rules;
return ruleQos;
} }
@Override @Override
public List<RuleQo> findByName(String name) { public List<RuleCollection> findByName(String name) {
List<Rule> rules = ruleDao.findAllByTargetLike("%" + name + "%"); List<RuleCollection> rules = ruleCollectionDao.findAllByTargetLike("%" + name + "%");
if (rules != null && rules.size() > 0) { return rules;
return data2RuleQo(rules);
}
return null;
} }
private List<RuleQo> data2RuleQo(List<Rule> rules){ private List<RuleQo> data2RuleQo(List<Rule> rules){
...@@ -186,4 +186,22 @@ public class RuleServiceImpl implements RuleService { ...@@ -186,4 +186,22 @@ public class RuleServiceImpl implements RuleService {
} }
return new ArrayList<>(hashMap.values()); return new ArrayList<>(hashMap.values());
} }
private RuleCollection data2RuleCollection(RuleQo ruleQo){
RuleCollection ruleCollection = new RuleCollection();
ruleCollection.setTechnologyName(ruleQo.getTechnologyName());
ruleCollection.setTechnologyId(ruleQo.getTechnologyId());
ruleCollection.setTarget(ruleQo.getTarget());
ruleCollection.setId(UUIDUtil.getUUID());
StringBuilder stringBuilder = new StringBuilder();
for (String suffix : ruleQo.getSuffix()) {
if(stringBuilder.length()==0){
stringBuilder.append(suffix);
}else{
stringBuilder.append(",").append(suffix);
}
}
ruleCollection.setSuffix(stringBuilder.toString());
return ruleCollection;
}
} }
package com.zjty.inspect.task; package com.zjty.inspect.task;
import com.zjty.inspect.dao.CoefficientModelDao; import com.zjty.inspect.dao.CoefficientModelDao;
import com.zjty.inspect.dao.RuleCollectionDao;
import com.zjty.inspect.dao.RuleDao; import com.zjty.inspect.dao.RuleDao;
import com.zjty.inspect.dao.TechnologyDao; import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.CoefficientModel; import com.zjty.inspect.entity.CoefficientModel;
import com.zjty.inspect.entity.Rule; import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleCollection;
import com.zjty.inspect.entity.Technology; import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.service.InspectService; import com.zjty.inspect.service.InspectService;
import com.zjty.inspect.utils.AnalysisFile; import com.zjty.inspect.utils.AnalysisFile;
...@@ -37,6 +39,9 @@ public class task implements CommandLineRunner { ...@@ -37,6 +39,9 @@ public class task implements CommandLineRunner {
@Autowired @Autowired
private InspectService inspectService; private InspectService inspectService;
@Autowired
private RuleCollectionDao ruleCollectionDao;
@Autowired @Autowired
private AnalysisFile analysisFile; private AnalysisFile analysisFile;
...@@ -257,5 +262,47 @@ public class task implements CommandLineRunner { ...@@ -257,5 +262,47 @@ public class task implements CommandLineRunner {
// ruleDao.save(rule); // ruleDao.save(rule);
// ruleDao.save(NotCnJavaTechnology); // ruleDao.save(NotCnJavaTechnology);
// ruleDao.save(UnknowunMysqlRule); // ruleDao.save(UnknowunMysqlRule);
//文件后缀map
if(ruleCollectionDao.count()!=0){
return;
}
HashMap<String, ArrayList<String>> map = new HashMap<>();
//
HashMap<String, Rule> map1 = new HashMap<>();
ArrayList<RuleCollection> ruleCollections = new ArrayList<>();
List<Rule> all = ruleDao.findAll();
for (Rule rule : all) {
if(!map.containsKey(rule.getTarget()+":"+rule.getTechnologyId())){
ArrayList<String> suffixes = new ArrayList<>();
suffixes.add(rule.getSuffix());
map.put(rule.getTarget()+":"+rule.getTechnologyId(),suffixes);
}else{
map.get(rule.getTarget()+":"+rule.getTechnologyId()).add(rule.getSuffix());
}
map1.put(rule.getTarget()+":"+rule.getTechnologyId(),rule);
}
StringBuilder stringBuilder = new StringBuilder();
for (String key : map.keySet()) {
RuleCollection ruleCollection = new RuleCollection();
ruleCollection.setId(UUIDUtil.getUUID());
ArrayList<String> suffixes = map.get(key);
for (String suffix : suffixes) {
if(stringBuilder.length()==0){
stringBuilder.append(suffix);
}else{
stringBuilder.append(",").append(suffix);
}
}
ruleCollection.setSuffix(stringBuilder.toString());
stringBuilder.delete(0,stringBuilder.length());
Rule rule = map1.get(key);
ruleCollection.setTarget(rule.getTarget());
ruleCollection.setTechnologyId(rule.getTechnologyId());
ruleCollection.setTechnologyName(rule.getTechnologyName());
ruleCollections.add(ruleCollection);
}
ruleCollectionDao.saveAll(ruleCollections);
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论