提交 318026c5 authored 作者: 马晨俊's avatar 马晨俊

mcj:更新

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