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

mcj:更新规则查询数据结构

上级 49f69a8f
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.*;
......@@ -101,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);
}
}
......@@ -38,4 +38,8 @@ public class Page<T> {
public List<T> getObjects() {
return objects;
}
public void setObjects(List<T> objects) {
this.objects=objects;
}
}
package com.zjty.inspect.service;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.Page;
import com.zjty.inspect.entity.RuleQo;
import org.springframework.data.domain.Page;
import java.util.List;
import java.util.Map;
......@@ -40,8 +39,8 @@ public interface RuleService {
*/
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();
}
......@@ -97,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;
}
/**
......@@ -161,9 +168,22 @@ public class RuleServiceImpl implements RuleService {
*/
@Override
public List<RuleQo> findAll() {
HashMap<String, RuleQo> hashMap = new HashMap<>();
ArrayList<Rule> list = new ArrayList<>();
List<Rule> rules = ruleDao.findAll();
List<RuleQo> ruleQos = data2RuleQo(rules);
return ruleQos;
}
@Override
public List<RuleQo> findByName(String name) {
List<Rule> rules = ruleDao.findAllByTargetLike("%" + name + "%");
if (rules != null && rules.size() > 0) {
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();
......@@ -187,13 +207,4 @@ public class RuleServiceImpl implements RuleService {
}
return new ArrayList<>(hashMap.values());
}
@Override
public List<Rule> findByName(String name) {
List<Rule> rules = ruleDao.findAllByTargetLike("%" + name + "%");
if (rules != null && rules.size() > 0) {
return rules;
}
return null;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论