彻底移除jpa依赖,菜单管理添加缓存,优化页面刷新速度
This commit is contained in:
10
pom.xml
10
pom.xml
@ -48,8 +48,9 @@
|
|||||||
|
|
||||||
<!--Spring boot start-->
|
<!--Spring boot start-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>javax.persistence</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>persistence-api</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -64,6 +65,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- spring cache -->
|
<!-- spring cache -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -7,8 +7,6 @@ package co.yixiang.enums;
|
|||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,178 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2018-2020
|
|
||||||
* All rights reserved, Designed By www.yixiang.co
|
|
||||||
|
|
||||||
*/
|
|
||||||
package co.yixiang.utils;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import co.yixiang.annotation.Query;
|
|
||||||
import javax.persistence.criteria.*;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Zheng Jie
|
|
||||||
* @date 2019-6-4 14:59:48
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@SuppressWarnings({"unchecked","all"})
|
|
||||||
public class QueryHelp {
|
|
||||||
|
|
||||||
public static <R, Q> Predicate getPredicate(Root<R> root, Q query, CriteriaBuilder cb) {
|
|
||||||
List<Predicate> list = new ArrayList<>();
|
|
||||||
|
|
||||||
if(query == null){
|
|
||||||
return cb.and(list.toArray(new Predicate[0]));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
List<Field> fields = getAllFields(query.getClass(), new ArrayList<>());
|
|
||||||
for (Field field : fields) {
|
|
||||||
boolean accessible = field.isAccessible();
|
|
||||||
field.setAccessible(true);
|
|
||||||
Query q = field.getAnnotation(Query.class);
|
|
||||||
if (q != null) {
|
|
||||||
String propName = q.propName();
|
|
||||||
String joinName = q.joinName();
|
|
||||||
String blurry = q.blurry();
|
|
||||||
String attributeName = isBlank(propName) ? field.getName() : propName;
|
|
||||||
Class<?> fieldType = field.getType();
|
|
||||||
Object val = field.get(query);
|
|
||||||
if (ObjectUtil.isNull(val) || "".equals(val)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Join join = null;
|
|
||||||
// 模糊多字段
|
|
||||||
if (ObjectUtil.isNotEmpty(blurry)) {
|
|
||||||
String[] blurrys = blurry.split(",");
|
|
||||||
List<Predicate> orPredicate = new ArrayList<>();
|
|
||||||
for (String s : blurrys) {
|
|
||||||
orPredicate.add(cb.like(root.get(s)
|
|
||||||
.as(String.class), "%" + val.toString() + "%"));
|
|
||||||
}
|
|
||||||
Predicate[] p = new Predicate[orPredicate.size()];
|
|
||||||
list.add(cb.or(orPredicate.toArray(p)));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (ObjectUtil.isNotEmpty(joinName)) {
|
|
||||||
String[] joinNames = joinName.split(">");
|
|
||||||
for (String name : joinNames) {
|
|
||||||
switch (q.join()) {
|
|
||||||
case LEFT:
|
|
||||||
if(ObjectUtil.isNotNull(join)){
|
|
||||||
join = join.join(name, JoinType.LEFT);
|
|
||||||
} else {
|
|
||||||
join = root.join(name, JoinType.LEFT);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RIGHT:
|
|
||||||
if(ObjectUtil.isNotNull(join)){
|
|
||||||
join = join.join(name, JoinType.RIGHT);
|
|
||||||
} else {
|
|
||||||
join = root.join(name, JoinType.RIGHT);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (q.type()) {
|
|
||||||
case EQUAL:
|
|
||||||
list.add(cb.equal(getExpression(attributeName,join,root)
|
|
||||||
.as((Class<? extends Comparable>) fieldType),val));
|
|
||||||
break;
|
|
||||||
case GREATER_THAN:
|
|
||||||
list.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root)
|
|
||||||
.as((Class<? extends Comparable>) fieldType), (Comparable) val));
|
|
||||||
break;
|
|
||||||
case LESS_THAN:
|
|
||||||
list.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root)
|
|
||||||
.as((Class<? extends Comparable>) fieldType), (Comparable) val));
|
|
||||||
break;
|
|
||||||
case LESS_THAN_NQ:
|
|
||||||
list.add(cb.lessThan(getExpression(attributeName,join,root)
|
|
||||||
.as((Class<? extends Comparable>) fieldType), (Comparable) val));
|
|
||||||
break;
|
|
||||||
case INNER_LIKE:
|
|
||||||
list.add(cb.like(getExpression(attributeName,join,root)
|
|
||||||
.as(String.class), "%" + val.toString() + "%"));
|
|
||||||
break;
|
|
||||||
case LEFT_LIKE:
|
|
||||||
list.add(cb.like(getExpression(attributeName,join,root)
|
|
||||||
.as(String.class), "%" + val.toString()));
|
|
||||||
break;
|
|
||||||
case RIGHT_LIKE:
|
|
||||||
list.add(cb.like(getExpression(attributeName,join,root)
|
|
||||||
.as(String.class), val.toString() + "%"));
|
|
||||||
break;
|
|
||||||
case IN:
|
|
||||||
if (CollUtil.isNotEmpty((Collection<Long>)val)) {
|
|
||||||
list.add(getExpression(attributeName,join,root).in((Collection<Long>) val));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NOT_EQUAL:
|
|
||||||
list.add(cb.notEqual(getExpression(attributeName,join,root), val));
|
|
||||||
break;
|
|
||||||
case NOT_NULL:
|
|
||||||
list.add(cb.isNotNull(getExpression(attributeName,join,root)));
|
|
||||||
break;
|
|
||||||
case BETWEEN:
|
|
||||||
List<Object> between = new ArrayList<>((List<Object>)val);
|
|
||||||
list.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()),
|
|
||||||
(Comparable) between.get(0), (Comparable) between.get(1)));
|
|
||||||
break;
|
|
||||||
case UNIX_TIMESTAMP:
|
|
||||||
List<Object> UNIX_TIMESTAMP = new ArrayList<>((List<Object>)val);
|
|
||||||
if(!UNIX_TIMESTAMP.isEmpty()){
|
|
||||||
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
long time1 = fm.parse(UNIX_TIMESTAMP.get(0).toString()).getTime()/1000;
|
|
||||||
long time2 = fm.parse(UNIX_TIMESTAMP.get(1).toString()).getTime()/1000;
|
|
||||||
list.add(cb.between(getExpression(attributeName, join, root),
|
|
||||||
time1, time2));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
field.setAccessible(accessible);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
int size = list.size();
|
|
||||||
return cb.and(list.toArray(new Predicate[size]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) {
|
|
||||||
if (ObjectUtil.isNotEmpty(join)) {
|
|
||||||
return join.get(attributeName);
|
|
||||||
} else {
|
|
||||||
return root.get(attributeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isBlank(final CharSequence cs) {
|
|
||||||
int strLen;
|
|
||||||
if (cs == null || (strLen = cs.length()) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < strLen; i++) {
|
|
||||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Field> getAllFields(Class clazz, List<Field> fields) {
|
|
||||||
if (clazz != null) {
|
|
||||||
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
|
||||||
getAllFields(clazz.getSuperclass(), fields);
|
|
||||||
}
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,8 @@
|
|||||||
package co.yixiang.utils;
|
package co.yixiang.utils;
|
||||||
|
|
||||||
import co.yixiang.exception.BadRequestException;
|
import co.yixiang.exception.BadRequestException;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.hibernate.annotations.CreationTimestamp;
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@ -11,13 +11,10 @@ import co.yixiang.common.web.vo.Paging;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import co.yixiang.annotation.Query;
|
import co.yixiang.annotation.Query;
|
||||||
|
import net.sf.jsqlparser.statement.select.Join;
|
||||||
import javax.persistence.criteria.*;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.sql.Wrapper;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
@ -149,14 +146,7 @@ public class QueryHelpPlus {
|
|||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) {
|
|
||||||
if (ObjectUtil.isNotEmpty(join)) {
|
|
||||||
return join.get(attributeName);
|
|
||||||
} else {
|
|
||||||
return root.get(attributeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isBlank(final CharSequence cs) {
|
private static boolean isBlank(final CharSequence cs) {
|
||||||
int strLen;
|
int strLen;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -32,8 +32,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -30,8 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -10,7 +10,6 @@ import co.yixiang.modules.shop.domain.YxStoreCart;
|
|||||||
import co.yixiang.modules.shop.service.dto.CountDto;
|
import co.yixiang.modules.shop.service.dto.CountDto;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -10,8 +10,6 @@ import co.yixiang.modules.shop.domain.YxUser;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
import org.springframework.data.jpa.repository.Modifying;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,23 +104,8 @@ public class MenuController {
|
|||||||
if (resources.getId() != null) {
|
if (resources.getId() != null) {
|
||||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||||
}
|
}
|
||||||
Menu menu = menuService.getOne(new QueryWrapper<Menu>().eq("name",resources.getName()));
|
|
||||||
if(menu != null){
|
return new ResponseEntity<>(menuService.create(resources),HttpStatus.CREATED);
|
||||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
|
||||||
}
|
|
||||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
|
||||||
menu = menuService.getOne(new QueryWrapper<Menu>().eq("component_name",resources.getComponentName()));
|
|
||||||
if(menu != null){
|
|
||||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(resources.getIFrame()){
|
|
||||||
String http = "http://", https = "https://";
|
|
||||||
if (!(resources.getPath().toLowerCase().startsWith(http)||resources.getPath().toLowerCase().startsWith(https))) {
|
|
||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(menuService.save(resources),HttpStatus.CREATED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log("修改菜单")
|
@Log("修改菜单")
|
||||||
|
@ -104,4 +104,6 @@ public interface MenuService extends BaseService<Menu>{
|
|||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(Menu resources);
|
void update(Menu resources);
|
||||||
|
|
||||||
|
Object create(Menu resources);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -30,8 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,8 +31,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -30,7 +30,9 @@ import co.yixiang.modules.system.service.MenuService;
|
|||||||
import co.yixiang.modules.system.service.dto.MenuDto;
|
import co.yixiang.modules.system.service.dto.MenuDto;
|
||||||
import co.yixiang.modules.system.service.dto.MenuQueryCriteria;
|
import co.yixiang.modules.system.service.dto.MenuQueryCriteria;
|
||||||
import co.yixiang.modules.system.service.mapper.MenuMapper;
|
import co.yixiang.modules.system.service.mapper.MenuMapper;
|
||||||
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -58,7 +60,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
//@CacheConfig(cacheNames = "menu")
|
@CacheConfig(cacheNames = "menu")
|
||||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||||
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implements MenuService {
|
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implements MenuService {
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
private final RoleMapper roleMapper;
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//@Cacheable
|
@Cacheable
|
||||||
public Map<String, Object> queryAll(MenuQueryCriteria criteria, Pageable pageable) {
|
public Map<String, Object> queryAll(MenuQueryCriteria criteria, Pageable pageable) {
|
||||||
getPage(pageable);
|
getPage(pageable);
|
||||||
PageInfo<Menu> page = new PageInfo<>(queryAll(criteria));
|
PageInfo<Menu> page = new PageInfo<>(queryAll(criteria));
|
||||||
@ -79,7 +81,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//@Cacheable
|
@Cacheable
|
||||||
public List<Menu> queryAll(MenuQueryCriteria criteria){
|
public List<Menu> queryAll(MenuQueryCriteria criteria){
|
||||||
return baseMapper.selectList(QueryHelpPlus.getPredicate(Menu.class, criteria));
|
return baseMapper.selectList(QueryHelpPlus.getPredicate(Menu.class, criteria));
|
||||||
}
|
}
|
||||||
@ -204,6 +206,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Cacheable(key = "'tree'")
|
||||||
public Object getMenuTree(List<Menu> menus) {
|
public Object getMenuTree(List<Menu> menus) {
|
||||||
List<Map<String,Object>> list = new LinkedList<>();
|
List<Map<String,Object>> list = new LinkedList<>();
|
||||||
menus.forEach(menu -> {
|
menus.forEach(menu -> {
|
||||||
@ -249,6 +252,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Cacheable(key = "'pid:'+#p0")
|
||||||
public List<Menu> findByPid(long pid) {
|
public List<Menu> findByPid(long pid) {
|
||||||
return menuMapper.findByPid(pid);
|
return menuMapper.findByPid(pid);
|
||||||
}
|
}
|
||||||
@ -276,6 +280,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
* @param menuSet /
|
* @param menuSet /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
public void delete(Set<Menu> menuSet) {
|
public void delete(Set<Menu> menuSet) {
|
||||||
for (Menu menu : menuSet) {
|
for (Menu menu : menuSet) {
|
||||||
roleMapper.untiedMenu(menu.getId());
|
roleMapper.untiedMenu(menu.getId());
|
||||||
@ -289,6 +294,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
public void update(Menu resources) {
|
public void update(Menu resources) {
|
||||||
if(resources.getId().equals(resources.getPid())) {
|
if(resources.getId().equals(resources.getPid())) {
|
||||||
throw new BadRequestException("上级不能为自己");
|
throw new BadRequestException("上级不能为自己");
|
||||||
@ -329,4 +335,25 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
|||||||
menu.setType(resources.getType());
|
menu.setType(resources.getType());
|
||||||
this.saveOrUpdate(menu);
|
this.saveOrUpdate(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(allEntries = true)
|
||||||
|
public MenuDto create(Menu resources) {
|
||||||
|
if(this.getOne(lambdaQuery().eq(Menu::getName,resources.getName())) != null){
|
||||||
|
throw new EntityExistException(Menu.class,"name",resources.getName());
|
||||||
|
}
|
||||||
|
if(StringUtils.isNotBlank(resources.getComponentName())){
|
||||||
|
if(this.getOne(lambdaQuery().eq(Menu::getComponentName,resources.getComponentName())) != null){
|
||||||
|
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(resources.getIFrame()){
|
||||||
|
String http = "http://", https = "https://";
|
||||||
|
if (!(resources.getPath().toLowerCase().startsWith(http)||resources.getPath().toLowerCase().startsWith(https))) {
|
||||||
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.save(resources);
|
||||||
|
return generator.convert(resources,MenuDto.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -30,8 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -41,8 +41,6 @@ import cn.hutool.core.util.IdUtil;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -46,8 +46,6 @@ import cn.hutool.core.util.IdUtil;
|
|||||||
//import org.springframework.cache.annotation.Cacheable;
|
//import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import co.yixiang.utils.PageUtil;
|
|
||||||
import co.yixiang.utils.QueryHelp;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
Reference in New Issue
Block a user