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

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

...@@ -37,7 +37,10 @@ ...@@ -37,7 +37,10 @@
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version> <version>${swagger.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jgit</groupId> <groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId> <artifactId>org.eclipse.jgit</artifactId>
......
package com.zjty.inspect.controller; package com.zjty.inspect.controller;
import com.zjty.inspect.entity.PageResult;
import com.zjty.inspect.entity.Rule;
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 io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Map;
/** /**
* 规则库设置 * 规则库设置
* @author Mcj * @author Mcj
...@@ -60,8 +67,7 @@ public class RuleController { ...@@ -60,8 +67,7 @@ public class RuleController {
@ApiOperation("根据name查询规则") @ApiOperation("根据name查询规则")
@GetMapping(value = "/{name}") @GetMapping(value = "/{name}")
public ResponseEntity getName(@PathVariable String name) { public ResponseEntity getName(@PathVariable String name) {
ruleService.findByName(name); return ResponseEntity.ok(ruleService.findByName(name));
return ResponseEntity.ok(200);
} }
/** /**
* 查询所有规则 * 查询所有规则
...@@ -72,4 +78,23 @@ public class RuleController { ...@@ -72,4 +78,23 @@ public class RuleController {
public ResponseEntity getRules(){ public ResponseEntity getRules(){
return ResponseEntity.ok(ruleService.findAll()); return ResponseEntity.ok(ruleService.findAll());
} }
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
* @param page 页码
* @param size 页大小
* @return 分页结果
*/
@ApiOperation("分页查询页面列表")
@ApiImplicitParams({
@ApiImplicitParam(name="page",value = "页码",required=true,paramType="path",dataType="int"),
@ApiImplicitParam(name="size",value = "每页记录数",required=true,paramType="path",dataType="int")
})
@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()) );
}
} }
package com.zjty.inspect.controller; package com.zjty.inspect.controller;
import com.zjty.inspect.entity.PageResult;
import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.Technology; import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.entity.TechnologyQo; import com.zjty.inspect.entity.TechnologyQo;
import com.zjty.inspect.service.TechnologyService; import com.zjty.inspect.service.TechnologyService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Map;
/** /**
* 适配技术 * 适配技术
* @author Mcj * @author Mcj
...@@ -71,4 +78,21 @@ public class TechnologyController { ...@@ -71,4 +78,21 @@ public class TechnologyController {
technologyService.update(technology); technologyService.update(technology);
return ResponseEntity.ok(200); return ResponseEntity.ok(200);
} }
/**
* 分页+多条件查询
* @param searchMap 查询条件封装
* @param page 页码
* @param size 页大小
* @return 分页结果
*/
@ApiOperation("分页查询页面列表")
@ApiImplicitParams({
@ApiImplicitParam(name="page",value = "页码",required=true,paramType="path",dataType="int"),
@ApiImplicitParam(name="size",value = "每页记录数",required=true,paramType="path",dataType="int")
})
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public ResponseEntity findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Technology> pageList = technologyService.findSearch(searchMap, page, size);
return ResponseEntity.ok(new PageResult<Technology>(pageList.getTotalElements(), pageList.getContent()) );
}
} }
...@@ -3,10 +3,11 @@ package com.zjty.inspect.dao; ...@@ -3,10 +3,11 @@ package com.zjty.inspect.dao;
import com.zjty.inspect.entity.Rule; import com.zjty.inspect.entity.Rule;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List; import java.util.List;
public interface RuleDao extends JpaRepository<Rule,String> { public interface RuleDao extends JpaRepository<Rule,String>,JpaSpecificationExecutor<Rule> {
/** /**
* 根据目标关键字查询规则 * 根据目标关键字查询规则
* @param target 目标关键字 * @param target 目标关键字
......
...@@ -2,11 +2,12 @@ package com.zjty.inspect.dao; ...@@ -2,11 +2,12 @@ package com.zjty.inspect.dao;
import com.zjty.inspect.entity.Technology; import com.zjty.inspect.entity.Technology;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
public interface TechnologyDao extends JpaRepository<Technology,String> { public interface TechnologyDao extends JpaRepository<Technology,String>, JpaSpecificationExecutor<Technology> {
/** /**
* 根据名称查询适配技术 * 根据名称查询适配技术
......
package com.zjty.inspect.entity;
import java.util.List;
public class PageResult<T> {
private Long total;
private List<T> rows;
public PageResult(Long total, List<T> rows) {
super();
this.total = total;
this.rows = rows;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
...@@ -47,8 +47,10 @@ public class Technology { ...@@ -47,8 +47,10 @@ public class Technology {
/** /**
* 技术类型 * 技术类型
* 1:前端技术
* 2:后端技术
*/ */
private String backOrFront; private Integer backOrFront=2;
/** /**
* 数据创建时间 * 数据创建时间
*/ */
......
...@@ -3,8 +3,10 @@ package com.zjty.inspect.service; ...@@ -3,8 +3,10 @@ package com.zjty.inspect.service;
import com.zjty.inspect.entity.Rule; import com.zjty.inspect.entity.Rule;
import com.zjty.inspect.entity.RuleQo; import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.entity.RuleVo; import com.zjty.inspect.entity.RuleVo;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 规则接口 * 规则接口
...@@ -40,4 +42,6 @@ public interface RuleService { ...@@ -40,4 +42,6 @@ public interface RuleService {
List<Rule> findAll(); List<Rule> findAll();
List<Rule> findByName(String name); List<Rule> findByName(String name);
Page<Rule> findSearch(Map searchMap, int page, int size);
} }
...@@ -2,8 +2,10 @@ package com.zjty.inspect.service; ...@@ -2,8 +2,10 @@ package com.zjty.inspect.service;
import com.zjty.inspect.entity.Technology; import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.entity.TechnologyQo; import com.zjty.inspect.entity.TechnologyQo;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 关键技术 * 关键技术
...@@ -26,4 +28,6 @@ public interface TechnologyService { ...@@ -26,4 +28,6 @@ public interface TechnologyService {
public List<Technology> findAllTechnology(String name); public List<Technology> findAllTechnology(String name);
void update(Technology technology); void update(Technology technology);
Page<Technology> findSearch(Map searchMap, int page, int size);
} }
...@@ -4,9 +4,15 @@ import com.zjty.inspect.dao.TechnologyDao; ...@@ -4,9 +4,15 @@ import com.zjty.inspect.dao.TechnologyDao;
import com.zjty.inspect.entity.*; import com.zjty.inspect.entity.*;
import com.zjty.inspect.service.ReportService; import com.zjty.inspect.service.ReportService;
import com.zjty.inspect.utils.RedisUtil; import com.zjty.inspect.utils.RedisUtil;
import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import java.util.Map;
/** /**
* @author Mcj * @author Mcj
...@@ -26,4 +32,26 @@ public class ReportServiceImpl implements ReportService { ...@@ -26,4 +32,26 @@ public class ReportServiceImpl implements ReportService {
return new ReportVo(); return new ReportVo();
} }
//执行静态化
private String generateHtml(String templateContent, Map model ){
//创建配置对象
Configuration configuration = new Configuration(Configuration.getVersion());
//创建模板加载器
StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
stringTemplateLoader.putTemplate("template",templateContent);
//向configuration配置模板加载器
configuration.setTemplateLoader(stringTemplateLoader);
//获取模板
try {
Template template = configuration.getTemplate("template");
//调用api进行静态化
String content = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
return content;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
} }
...@@ -8,11 +8,20 @@ import com.zjty.inspect.entity.RuleQo; ...@@ -8,11 +8,20 @@ import com.zjty.inspect.entity.RuleQo;
import com.zjty.inspect.service.RuleService; import com.zjty.inspect.service.RuleService;
import com.zjty.inspect.utils.UUIDUtil; import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 规则库 * 规则库
...@@ -44,6 +53,39 @@ public class RuleServiceImpl implements RuleService { ...@@ -44,6 +53,39 @@ public class RuleServiceImpl implements RuleService {
rule.setId(UUIDUtil.getUUID()); rule.setId(UUIDUtil.getUUID());
ruleDao.save(rule); ruleDao.save(rule);
} }
/**
* 条件查询+分页
* @param whereMap
* @param page
* @param size
* @return
*/
public Page<Rule> findSearch(Map whereMap, int page, int size) {
Specification<Rule> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page-1, size);
return ruleDao.findAll(specification, pageRequest);
}
/**
* 动态条件构建
* @param searchMap
* @return
*/
private Specification<Rule> createSpecification(Map searchMap) {
return new Specification<Rule>() {
@Override
public Predicate toPredicate(Root<Rule> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
if(searchMap.get("target")!=null && !"".equals(searchMap.get("target"))){
predicateList.add(cb.like(root.get("target").as(String.class),"%"+(String)searchMap.get("target")+"%"));
}
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
@Override @Override
public void upRule(RuleQo ruleQo) { public void upRule(RuleQo ruleQo) {
......
...@@ -6,11 +6,19 @@ import com.zjty.inspect.entity.Technology; ...@@ -6,11 +6,19 @@ import com.zjty.inspect.entity.Technology;
import com.zjty.inspect.service.TechnologyService; import com.zjty.inspect.service.TechnologyService;
import com.zjty.inspect.utils.UUIDUtil; import com.zjty.inspect.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 适配技术 * 适配技术
...@@ -85,4 +93,32 @@ public class TechnologyServiceImpl implements TechnologyService { ...@@ -85,4 +93,32 @@ public class TechnologyServiceImpl implements TechnologyService {
public void update(Technology technology) { public void update(Technology technology) {
technologyDao.save(technology); technologyDao.save(technology);
} }
@Override
public Page<Technology> findSearch(Map whereMap, int page, int size) {
Specification<Technology> specification = createSpecification(whereMap);
PageRequest pageRequest = PageRequest.of(page-1, size);
return technologyDao.findAll(specification, pageRequest);
}
/**
* 动态条件构建
* @param searchMap
* @return
*/
private Specification<Technology> createSpecification(Map searchMap) {
return new Specification<Technology>() {
@Override
public Predicate toPredicate(Root<Technology> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicateList = new ArrayList<Predicate>();
if(searchMap.get("technologyName")!=null && !"".equals(searchMap.get("technologyName"))){
predicateList.add(cb.like(root.get("technologyName").as(String.class),"%"+(String)searchMap.get("technologyName")+"%"));
}
return cb.and( predicateList.toArray(new Predicate[predicateList.size()]));
}
};
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论