提交 3d710f2f authored 作者: 孙洁清's avatar 孙洁清

评估报告管理页面修改v1.0.4

上级 adb7f3ac
......@@ -8,6 +8,7 @@ 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.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -32,60 +33,42 @@ public class RuleController {
/**
* test
* 新增规则
* @param ruleQo 规则封装
* @param
* @return
*/
@PostMapping
@ApiOperation("新增规则")
public ResponseEntity rule(@RequestBody RuleQo ruleQo){
ruleService.addRule(ruleQo);
return ResponseEntity.ok(200);
public ResponseEntity rule(@RequestBody Rule rule){
Rule rule1 = ruleService.addRulePlugs(rule);
if(rule1!=null){
return ResponseEntity.ok(rule1);
}
return ResponseEntity.status(500).build();
}
/**
* 修改规则
* @param ruleQo 规则封装
* @param rule 规则封装
* @return
*/
@PostMapping(value = "/update")
@ApiOperation("修改规则")
public ResponseEntity update(@RequestBody RuleQo ruleQo){
ruleService.upRule(ruleQo);
public ResponseEntity update(@RequestBody Rule rule){
ruleService.upRulePlugs(rule);
return ResponseEntity.ok(200);
}
/**
* 根据id删除规则
* @param ruleQo 数据封装
* @param id
* @return
*/
@ApiOperation("根据数据封装删除规则")
@DeleteMapping
public ResponseEntity deleteByQo(@RequestBody RuleQo ruleQo){
ruleService.deleteRule(ruleQo);
return ResponseEntity.ok(200);
}
@ApiOperation("根据name查询规则")
@GetMapping(value = "/{name}")
public ResponseEntity getName(@PathVariable String name) {
List<RuleCollection> byName = ruleService.findByName(name);
return ResponseEntity.ok(byName);
}
/**
* 查询所有规则
* @return 规则
*/
@ApiOperation("查询所有规则")
@GetMapping
public ResponseEntity getRules(){
List<RuleCollection> all = ruleService.findAll();
return ResponseEntity.ok(all);
}
@ApiOperation("测试所有规则")
@GetMapping("/test")
public ResponseEntity testRules(){
ruleService.testgb();
public ResponseEntity deleteByQo(@RequestBody String id){
ruleService.deleteRulePlugs(id);
return ResponseEntity.ok(200);
}
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
......@@ -100,7 +83,7 @@ public class RuleController {
})
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public ResponseEntity findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
CustomPage<RuleCollection> search = ruleService.findSearch(searchMap, page, size);
Page<Rule> search = ruleService.findSearch(searchMap, page, size);
return ResponseEntity.ok(search);
}
......
......@@ -27,6 +27,7 @@ public interface RuleDao extends JpaRepository<Rule,String>,JpaSpecificationExec
List<Rule> findAllByTarget(String target);
Rule findByTarget(String target);
Rule findByTargetaAndIdNot(String target,String id);
List<Rule> findByTargetAndSuffixEqualsAndTechnologyIdEquals(String target,String suffix,String technologyId);
......
package com.zjty.inspect.service;
import com.zjty.inspect.entity.CustomPage;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleCollection;
import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.entity.*;
import org.springframework.data.domain.Page;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
......@@ -19,20 +17,22 @@ public interface RuleService {
* @param ruleQo 规则封装类
*/
public void addRule(RuleQo ruleQo);
public Rule addRulePlugs(Rule rule);
public void addRule(List<Rule> rules);
public void testgb();
/**
* 修改规则
* @param ruleQo 规则封装类
*/
public void upRule(RuleQo ruleQo);
public void upRulePlugs(Rule rule);
public String exportData();
/**
* 删除规则
* @param ruleQo 规则封装类
*/
public void deleteRule(RuleQo ruleQo);
public void deleteRulePlugs(String id);
/**
* 查询所有规则
......@@ -47,8 +47,7 @@ public interface RuleService {
List<Rule> findRules();
List<RuleCollection> findByName(String name);
CustomPage<RuleCollection> findSearch(Map searchMap, int page, int size);
Page<Rule> findSearch(Map searchMap, int page, int size);
List<Rule> findAllByTechnologyIdIn(List<String> technologyIds);
......
......@@ -53,34 +53,6 @@ public class RuleServiceImpl implements RuleService {
private RuleCollectionDao ruleCollectionDao;
public void testgb(){
/*List<Rule> rules = ruleDao.findAll();
Map<String, List<Rule>> ruleMap = rules.stream().collect(groupingBy(Rule::getTarget));
Set<String> strings = ruleMap.keySet();
List<Rule> ruleList=new ArrayList<>();
for (String string : strings) {
List<Rule> rules1 = ruleMap.get(string);
System.out.println(rules1.toArray());
Rule rule=new Rule();
StringBuilder sb=new StringBuilder();
for (int i = 0; i < rules1.size(); i++) {
if(i==0){
rule.setTechnologyName(rules1.get(i).getTechnologyName());
rule.setId(rules1.get(i).getId());
rule.setTarget(rules1.get(i).getTarget());
rule.setTechnologyId(rules1.get(i).getTechnologyId());
sb.append(rules1.get(i).getSuffix());
continue;
}
sb.append(","+rules1.get(i).getSuffix());
}
rule.setSuffix(sb.toString());
ruleList.add(rule);
}
ruleDao.deleteAll();
ruleList.forEach(System.out::println);
ruleDao.saveAll(ruleList);*/
}
public List<Rule> mcjAllRule(){
List<Rule> rules = ruleDao.findAll();
List<Rule> ruleList=new ArrayList<>();
......@@ -98,6 +70,18 @@ public class RuleServiceImpl implements RuleService {
}
return ruleList;
}
public Rule addRulePlugs(Rule rule){
if(StringUtils.isEmpty(rule.getTarget())){
return null;
}
Rule rule1 = ruleDao.findByTarget(rule.getTarget());
if(rule1==null){
rule.setId(UUIDUtil.getUUID());
Rule save = ruleDao.save(rule);
return save;
}
return null;
}
/**
* 新增规则
*
......@@ -152,17 +136,12 @@ public class RuleServiceImpl implements RuleService {
* @return
*/
@Override
public CustomPage<RuleCollection> findSearch(Map whereMap, int page, int size) {
Specification<RuleCollection> specification = createSpecification(whereMap);
public Page<Rule> findSearch(Map whereMap, int page, int size) {
Specification<Rule> specification = createSpecification(whereMap);
Sort sort = new Sort(Sort.Direction.DESC, "updateDate");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Page<RuleCollection> ruleCollections = ruleCollectionDao.findAll(specification, pageRequest);
return ruleDao.findAll(specification, pageRequest);
CustomPage<RuleCollection> myCustomPage = new CustomPage<>();
myCustomPage.setTotalPage(ruleCollections.getTotalPages());
myCustomPage.setTotalElement((int)ruleCollections.getTotalElements());
myCustomPage.setObjects(ruleCollections.getContent());
return myCustomPage;
}
@Override
......@@ -178,7 +157,7 @@ public class RuleServiceImpl implements RuleService {
* @param searchMap
* @return
*/
private Specification<RuleCollection> createSpecification(Map searchMap) {
private Specification<Rule> createSpecification(Map searchMap) {
return (root, query, cb) -> {
List<Predicate> predicateList = new ArrayList<>();
......@@ -188,6 +167,9 @@ public class RuleServiceImpl implements RuleService {
if (searchMap.get("target") != null && !"".equals(searchMap.get("target"))) {
predicateList.add(cb.like(root.get("target").as(String.class), "%" + searchMap.get("target") + "%"));
}
if (searchMap.get("suffix") != null && !"".equals(searchMap.get("suffix"))) {
predicateList.add(cb.like(root.get("suffix").as(String.class), "%" + searchMap.get("suffix") + "%"));
}
return cb.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
......@@ -208,6 +190,20 @@ public class RuleServiceImpl implements RuleService {
addRule(ruleQo);
}
@Override
public void upRulePlugs(Rule rule) {
Rule rule1 = ruleDao.findByTargetaAndIdNot(rule.getTarget(), rule.getId());
if(rule1==null){
ruleDao.save(rule);
}else{
ruleDao.deleteById(rule.getId());
}
}
public void deleteRulePlugs(String id){
ruleDao.deleteById(id);
}
@Override
@Modifying
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论