mirror of https://github.com/elunez/eladmin
去除实时控制台功能,查询方式修改成注解方式
parent
e6c23f816f
commit
7eba9641e0
|
@ -1,4 +1,4 @@
|
|||
package me.zhengjie.aop.limit;
|
||||
package me.zhengjie.annotation;
|
||||
|
||||
import me.zhengjie.aspect.LimitType;
|
||||
|
|
@ -6,23 +6,32 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @描述 : 为生成{@link javax.persistence.criteria.Predicate }提供的注解
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/08/07
|
||||
* @时间 : 16:25
|
||||
* @author jie
|
||||
* @date 2019-6-4 13:52:30
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PredicateInfo {
|
||||
public @interface Query {
|
||||
|
||||
/** Dong ZhaoYang 2017/8/7 基本对象的属性名 */
|
||||
String propName() default "";
|
||||
/** Dong ZhaoYang 2017/8/7 查询方式 */
|
||||
QueryType queryType() default QueryType.BASIC;
|
||||
Type type() default Type.EQUAL;
|
||||
|
||||
enum QueryType {
|
||||
/** Dong ZhaoYang 2017/8/7 基本 */
|
||||
BASIC
|
||||
/**
|
||||
* 连接查询的属性名,如User类中的dept
|
||||
* @return
|
||||
*/
|
||||
String joinName() default "";
|
||||
|
||||
/**
|
||||
* 默认左连接
|
||||
* @return
|
||||
*/
|
||||
Join join() default Join.LEFT;
|
||||
|
||||
enum Type {
|
||||
EQUAL
|
||||
/** Dong ZhaoYang 2017/8/7 大于等于 */
|
||||
, GREATER_THAN
|
||||
/** Dong ZhaoYang 2017/8/7 小于等于 */
|
||||
|
@ -35,6 +44,19 @@ public @interface PredicateInfo {
|
|||
, RIGHT_LIKE
|
||||
/** Dong ZhaoYang 2017/8/7 小于 */
|
||||
, LESS_THAN_NQ
|
||||
//** jie 2019/6/4 包含 */
|
||||
, IN
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询
|
||||
*/
|
||||
enum Join {
|
||||
/** jie 2019-6-4 13:18:30 左连接 */
|
||||
LEFT
|
||||
/** jie 2019-6-4 13:18:30 右连接 */
|
||||
, RIGHT
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package me.zhengjie.aspect;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.zhengjie.aop.limit.Limit;
|
||||
import me.zhengjie.annotation.Limit;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.utils.RequestHolder;
|
||||
import me.zhengjie.utils.StringUtils;
|
||||
|
@ -28,7 +28,7 @@ public class LimitAspect {
|
|||
private static final Logger logger = LoggerFactory.getLogger(LimitAspect.class);
|
||||
|
||||
|
||||
@Pointcut("@annotation(me.zhengjie.aop.limit.Limit)")
|
||||
@Pointcut("@annotation(me.zhengjie.annotation.Limit)")
|
||||
public void pointcut() {
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,6 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
sb.append(target.getClass().getName());
|
||||
sb.append(method.getName());
|
||||
for (Object obj : params) {
|
||||
// 由于参数可能不同, hashCode肯定不一样, 缓存的key也需要不一样
|
||||
sb.append(JSON.toJSONString(obj).hashCode());
|
||||
}
|
||||
return sb.toString();
|
||||
|
|
|
@ -1,521 +0,0 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import me.zhengjie.annotation.PredicateInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @描述 : JavaBean 帮助
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2016/12/01
|
||||
* @时间 : 09:54
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class BeanHelp {
|
||||
|
||||
private final static ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final Logger logger = LoggerFactory.getLogger(BeanHelp.class);
|
||||
|
||||
static {
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <C> 泛型
|
||||
* @param object 对象
|
||||
* @return 属性集合
|
||||
* @描述 : 获取对象的JSON属性Map对象集合
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/02/24
|
||||
* @时间 : 11:12
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <C> Map<String, C> getBeanJSONPropertyMap(Object object, Class<C> clazz) {
|
||||
Map<String, C> result = new LinkedHashMap<>();
|
||||
try {
|
||||
JavaType javaType = objectMapper.getTypeFactory()
|
||||
.constructParametrizedType(Map.class, Map.class, String.class, clazz);
|
||||
result = objectMapper.readValue(objectMapper.writeValueAsString(object), javaType);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <C> 泛型
|
||||
* @param propName 属性名
|
||||
* @param object 对象
|
||||
* @param clazz 返回类型
|
||||
* @return 对象的属性名
|
||||
* @描述 : 获取请求对象的JSON属性的Map集合
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/03/20
|
||||
* @时间 : 12:47
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <C> Map<String, C> getBeanJSONPropertyMap(String propName, Object object, Class<C> clazz) {
|
||||
Map<String, C> result = new LinkedHashMap<>();
|
||||
try {
|
||||
Class<?> oClass = object.getClass();
|
||||
Field[] fields = oClass.getDeclaredFields();
|
||||
fieldLoop:
|
||||
for (Field field : fields) {
|
||||
String name = field.getName();
|
||||
JsonIgnore ignore = oClass.getDeclaredField(name).getAnnotation(JsonIgnore.class);
|
||||
if (ignore != null) {
|
||||
continue;
|
||||
}
|
||||
JsonProperty property = oClass.getDeclaredField(name).getAnnotation(JsonProperty.class);
|
||||
if (property != null) {
|
||||
name = property.value();
|
||||
}
|
||||
name = propName == null ? name : propName + "." + name;
|
||||
field.setAccessible(true);
|
||||
Object prop = field.get(object);
|
||||
if (prop == null) {
|
||||
continue;
|
||||
}
|
||||
if (PropertyType.isBasicClazz(field.getType()) || prop instanceof Class
|
||||
|| prop instanceof Collection) {
|
||||
result.put(name, (C) prop);
|
||||
} else if (prop instanceof Enum) {
|
||||
Method[] methods = prop.getClass().getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
JsonValue jsonValue = method.getAnnotation(JsonValue.class);
|
||||
if (jsonValue != null) {
|
||||
Object enumVal = method.invoke(prop);
|
||||
result.putAll(getBeanJSONPropertyMap(name, enumVal, clazz));
|
||||
continue fieldLoop;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.putAll(getBeanJSONPropertyMap(name, prop, clazz));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <T> 泛型
|
||||
* @param json json字符串
|
||||
* @param parentClass 最外层的父类
|
||||
* @param childrenClasses 属性类
|
||||
* @return 反序列化后的对象
|
||||
* @描述 : 从JSON中获取对象
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/02/24
|
||||
* @时间 : 11:45
|
||||
*/
|
||||
public static <T> T getBeanFromJson(String json,
|
||||
Class<?> parentClass, Class<?>... childrenClasses) {
|
||||
JavaType javaType = objectMapper.getTypeFactory()
|
||||
.constructParametrizedType(parentClass, parentClass, childrenClasses);
|
||||
T o = null;
|
||||
try {
|
||||
o = objectMapper.readValue(json, javaType);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clazz 需要实例化的字节码对象
|
||||
* @param <T> 对象类型
|
||||
* @return 对象实例
|
||||
* @描述 : 获取clazz的初始化对象,所有支持的属性 {@link PropertyType}将设为
|
||||
* 对应的非null默认值
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/3/6
|
||||
* @时间 : 15:07
|
||||
*/
|
||||
public static <T> T getNoEmptyPropertyInstance(Class<T> clazz) {
|
||||
T instance = null;
|
||||
try {
|
||||
instance = clazz.newInstance();
|
||||
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
|
||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
Method writeMethod = propertyDescriptor.getWriteMethod();
|
||||
if (writeMethod != null) {
|
||||
writeMethod.invoke(instance,
|
||||
PropertyType.fromClazz(propertyDescriptor.getPropertyType()).getDefaultValue());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param origin 原始对象数据
|
||||
* @param update 更新对象数据
|
||||
* @param <T> 对象类型
|
||||
* @return 待更新的对象
|
||||
* @描述 : 如果update的属性不为空,则更新对象origin的属性
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/8/7
|
||||
* @时间 : 15:48
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T updateEntityExceptEmptyProps(T origin, T update) {
|
||||
T instance = null;
|
||||
try {
|
||||
Class<T> clazz = (Class<T>) origin.getClass();
|
||||
instance = clazz.newInstance();
|
||||
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
|
||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
Method readMethod = propertyDescriptor.getReadMethod();
|
||||
Method writeMethod = propertyDescriptor.getWriteMethod();
|
||||
if (readMethod != null && writeMethod != null) {
|
||||
Object originProperty = readMethod.invoke(origin);
|
||||
Object updateProperty = readMethod.invoke(update);
|
||||
writeMethod.invoke(instance, NullHelp.isNull(updateProperty) ? originProperty : updateProperty);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @描述 : 转换为Predicate
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/8/7
|
||||
* @时间 : 17:25
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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[list.size()]));
|
||||
}
|
||||
try {
|
||||
List<Field> fields = getAllFields(query.getClass(), new ArrayList<>());
|
||||
for (Field field : fields) {
|
||||
boolean accessible = field.isAccessible();
|
||||
field.setAccessible(true);
|
||||
PredicateInfo predicateInfo = field.getAnnotation(PredicateInfo.class);
|
||||
if (predicateInfo != null) {
|
||||
String propName = predicateInfo.propName();
|
||||
String attributeName = isBlank(propName) ? field.getName() : propName;
|
||||
Class<?> fieldType = field.getType();
|
||||
Object val = field.get(query);
|
||||
if (NullHelp.isNull(val)) {
|
||||
continue;
|
||||
}
|
||||
switch (predicateInfo.queryType()) {
|
||||
case BASIC:
|
||||
list.add(cb.equal(root.get(attributeName).as(fieldType), val));
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
list.add(cb.greaterThanOrEqualTo(root.get(attributeName)
|
||||
.as((Class<? extends Comparable>) fieldType), (Comparable) val));
|
||||
break;
|
||||
case LESS_THAN:
|
||||
list.add(cb.lessThanOrEqualTo(root.get(attributeName)
|
||||
.as((Class<? extends Comparable>) fieldType), (Comparable) val));
|
||||
break;
|
||||
case LESS_THAN_NQ:
|
||||
list.add(cb.lessThan(root.get(attributeName)
|
||||
.as((Class<? extends Comparable>) fieldType), (Comparable) val));
|
||||
break;
|
||||
case INNER_LIKE:
|
||||
list.add(cb.like(root.get(attributeName)
|
||||
.as(String.class), "%" + val.toString() + "%"));
|
||||
break;
|
||||
case LEFT_LIKE:
|
||||
list.add(cb.like(root.get(attributeName)
|
||||
.as(String.class), "%" + val.toString()));
|
||||
break;
|
||||
case RIGHT_LIKE:
|
||||
list.add(cb.like(root.get(attributeName)
|
||||
.as(String.class), val.toString() + "%"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
field.setAccessible(accessible);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return cb.and(list.toArray(new Predicate[list.size()]));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param propName 属性名
|
||||
* @param object 目标实例对象
|
||||
* @param <T> 对象类型
|
||||
* @return 属性值
|
||||
* @描述 : 获取object对象的propName的属性值
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/3/6
|
||||
* @时间 : 15:08
|
||||
*/
|
||||
public static <T> Object getProperty(String propName, T object) {
|
||||
Object result = null;
|
||||
try {
|
||||
Method readMethod = new PropertyDescriptor(propName, object.getClass()).getReadMethod();
|
||||
if (readMethod != null) {
|
||||
result = readMethod.invoke(object);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @描述 : check 属性是否为空,有一个为空则返回false
|
||||
* @作者 : lww
|
||||
* @日期 : 2017/3/23
|
||||
* @时间 : 16:14
|
||||
*/
|
||||
public static <T> boolean checkProperties(T object) {
|
||||
T instance = null;
|
||||
try {
|
||||
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(object.getClass()).getPropertyDescriptors();
|
||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
Method readMethod = propertyDescriptor.getReadMethod();
|
||||
Object result = readMethod.invoke(object);
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object 目标实例对象
|
||||
* @param <T> 对象类型
|
||||
* @param <C> 属性类型
|
||||
* @return 属性值
|
||||
* @描述 : 获取object对象的propertyClazz的属性值
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/3/6
|
||||
* @时间 : 15:08
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, C> C getProperty(T object, Class<C> propertyClazz) {
|
||||
C result = null;
|
||||
try {
|
||||
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(object.getClass()).getPropertyDescriptors();
|
||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
if (propertyDescriptor.getPropertyType().equals(propertyClazz)) {
|
||||
Method readMethod = propertyDescriptor.getReadMethod();
|
||||
if (readMethod != null) {
|
||||
result = (C) readMethod.invoke(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clazz 拥有将获取属性的类
|
||||
* @param propertyClazz 属性的类
|
||||
* @return 属性的名称
|
||||
* @描述 : 获取属性名
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/03/14
|
||||
* @时间 : 13:33
|
||||
*/
|
||||
public static String getPropertyName(Class clazz, Class propertyClazz) {
|
||||
String result = null;
|
||||
try {
|
||||
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
|
||||
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
if (propertyDescriptor.getPropertyType().equals(propertyClazz)) {
|
||||
result = propertyDescriptor.getName();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @描述 : Bean属性的字节码类型及其对应的默认值
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/3/6
|
||||
* @时间 : 15:08
|
||||
*/
|
||||
public enum PropertyType {
|
||||
|
||||
BOX_BOOLEAN(Boolean.class, Boolean.FALSE),
|
||||
BOX_BYTE(Byte.class, 0),
|
||||
BOX_SHORT(Short.class, 0),
|
||||
BOX_CHARACTER(Character.class, '\u0000'),
|
||||
BOX_INTEGER(Integer.class, 0),
|
||||
BOX_LONG(Long.class, 0L),
|
||||
BOX_FLOAT(Float.class, 0.00F),
|
||||
BOX_DOUBLE(Double.class, 0.00D),
|
||||
STRING(String.class, ""),
|
||||
BIG_DECIMAL(BigDecimal.class, BigDecimal.ZERO),
|
||||
BIG_INTEGER(BigInteger.class, BigInteger.ZERO),
|
||||
DATE(Date.class, new Date()),
|
||||
NULL(PropertyType.class, null);
|
||||
|
||||
private Class clazz;
|
||||
private Object defaultValue;
|
||||
|
||||
PropertyType(Class clazz, Object defaultValue) {
|
||||
this.clazz = clazz;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public static boolean isBoxPrimitive(Class clazz) {
|
||||
switch (clazz.getName()) {
|
||||
case "java.lang.Boolean":
|
||||
case "java.lang.Byte":
|
||||
case "java.lang.Short":
|
||||
case "java.lang.Character":
|
||||
case "java.lang.Integer":
|
||||
case "java.lang.Long":
|
||||
case "java.lang.Float":
|
||||
case "java.lang.Double":
|
||||
case "java.lang.String":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBasicClazz(Class clazz) {
|
||||
switch (clazz.getName()) {
|
||||
case "java.lang.Boolean":
|
||||
case "java.lang.Byte":
|
||||
case "java.lang.Short":
|
||||
case "java.lang.Character":
|
||||
case "java.lang.Integer":
|
||||
case "java.lang.Long":
|
||||
case "java.lang.Float":
|
||||
case "java.lang.Double":
|
||||
case "java.lang.String":
|
||||
case "java.math.BigDecimal":
|
||||
case "java.math.BigInteger":
|
||||
case "java.util.Date":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static PropertyType fromClazz(Class clazz) {
|
||||
switch (clazz.getName()) {
|
||||
case "java.lang.Boolean":
|
||||
return BOX_BOOLEAN;
|
||||
case "java.lang.Byte":
|
||||
return BOX_BYTE;
|
||||
case "java.lang.Short":
|
||||
return BOX_SHORT;
|
||||
case "java.lang.Character":
|
||||
return BOX_CHARACTER;
|
||||
case "java.lang.Integer":
|
||||
return BOX_INTEGER;
|
||||
case "java.lang.Long":
|
||||
return BOX_LONG;
|
||||
case "java.lang.Float":
|
||||
return BOX_FLOAT;
|
||||
case "java.lang.Double":
|
||||
return BOX_DOUBLE;
|
||||
case "java.lang.String":
|
||||
return STRING;
|
||||
case "java.math.BigDecimal":
|
||||
return BIG_DECIMAL;
|
||||
case "java.math.BigInteger":
|
||||
return BIG_INTEGER;
|
||||
case "java.util.Date":
|
||||
return DATE;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
public Class getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PropertyType{" +
|
||||
"clazz=" + clazz +
|
||||
", defaultValue=" + defaultValue +
|
||||
"} " + super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<Field> getParentField(Class pc) {
|
||||
List<Field> list = null;
|
||||
while (pc != null) {
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
list.addAll(Arrays.asList(pc.getDeclaredFields()));
|
||||
pc = pc.getSuperclass();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Field> getParentField(Object o) {
|
||||
List<Field> list = null;
|
||||
Class pc = o.getClass();
|
||||
return BeanHelp.getParentField(pc);
|
||||
}
|
||||
public 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)) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @描述 : 用于空对象处理
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/01/19
|
||||
* @时间 : 09:52
|
||||
*/
|
||||
public class NullHelp {
|
||||
|
||||
public static boolean isNull(Object obj) {
|
||||
return obj == null ||
|
||||
(obj instanceof String && isNullStr((String) obj)) ||
|
||||
(obj instanceof Collection && ((Collection) obj).isEmpty());
|
||||
}
|
||||
|
||||
public static boolean isNullStr(String str) {
|
||||
str = str.trim();
|
||||
return str.isEmpty()/* || str.equalsIgnoreCase("null")
|
||||
|| str.equalsIgnoreCase("undefined")*/;
|
||||
}
|
||||
|
||||
public static void check(Object... obj) throws Exception {
|
||||
if (obj == null) {
|
||||
throw new RuntimeException("数组参数不能为空");
|
||||
}
|
||||
for (int i = 0; i < obj.length; i++) {
|
||||
Object o = obj[i];
|
||||
if (o == null) {
|
||||
throw new RuntimeException("obj[" + i + "]不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.annotation.Query;
|
||||
import javax.persistence.criteria.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-6-4 14:59:48
|
||||
*/
|
||||
@Slf4j
|
||||
public class QueryHelp {
|
||||
|
||||
/**
|
||||
* @描述 : 转换为Predicate
|
||||
* @作者 : Dong ZhaoYang
|
||||
* @日期 : 2017/8/7
|
||||
* @时间 : 17:25
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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[list.size()]));
|
||||
}
|
||||
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 attributeName = isBlank(propName) ? field.getName() : propName;
|
||||
Class<?> fieldType = field.getType();
|
||||
Object val = field.get(query);
|
||||
if (ObjectUtil.isNull(val)) {
|
||||
continue;
|
||||
}
|
||||
Join join = null;
|
||||
if (ObjectUtil.isNotEmpty(joinName)) {
|
||||
switch (q.join()) {
|
||||
case LEFT:
|
||||
join = root.join(joinName, JoinType.LEFT);
|
||||
break;
|
||||
case RIGHT:
|
||||
join = root.join(joinName, JoinType.RIGHT);
|
||||
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() + "%"));
|
||||
case IN:
|
||||
if (CollUtil.isNotEmpty((Collection<Long>)val)) {
|
||||
list.add(getExpression(attributeName,join,root).in((Collection<Long>) val));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
field.setAccessible(accessible);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return cb.and(list.toArray(new Predicate[list.size()]));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public 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)) == false) {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package me.zhengjie.rest;
|
||||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.service.LogService;
|
||||
import me.zhengjie.service.query.LogQueryService;
|
||||
import me.zhengjie.service.dto.LogQueryCriteria;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -22,31 +21,28 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("api")
|
||||
public class LogController {
|
||||
|
||||
@Autowired
|
||||
private LogQueryService logQueryService;
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
@GetMapping(value = "/logs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getLogs(Log log, Pageable pageable){
|
||||
log.setLogType("INFO");
|
||||
return new ResponseEntity(logQueryService.queryAll(log,pageable), HttpStatus.OK);
|
||||
public ResponseEntity getLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
return new ResponseEntity(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/user")
|
||||
public ResponseEntity getUserLogs(Log log, Pageable pageable){
|
||||
log.setLogType("INFO");
|
||||
log.setUsername(SecurityUtils.getUsername());
|
||||
return new ResponseEntity(logQueryService.queryAllByUser(log,pageable), HttpStatus.OK);
|
||||
public ResponseEntity getUserLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setUsername(SecurityUtils.getUsername());
|
||||
return new ResponseEntity(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/error")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getErrorLogs(Log log, Pageable pageable){
|
||||
log.setLogType("ERROR");
|
||||
return new ResponseEntity(logQueryService.queryAll(log,pageable), HttpStatus.OK);
|
||||
public ResponseEntity getErrorLogs(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("ERROR");
|
||||
return new ResponseEntity(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/error/{id}")
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
package me.zhengjie.service;
|
||||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.service.dto.LogQueryCriteria;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
public interface LogService {
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Object queryAll(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAllByUser
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 新增日志
|
||||
* @param joinPoint
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* 日志查询类
|
||||
* @author jie
|
||||
* @date 2019-6-4 09:23:07
|
||||
*/
|
||||
@Data
|
||||
public class LogQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String username;
|
||||
|
||||
@Query
|
||||
private String logType;
|
||||
}
|
|
@ -5,9 +5,16 @@ import cn.hutool.json.JSONObject;
|
|||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.repository.LogRepository;
|
||||
import me.zhengjie.service.LogService;
|
||||
import me.zhengjie.service.dto.LogQueryCriteria;
|
||||
import me.zhengjie.service.mapper.LogErrorMapper;
|
||||
import me.zhengjie.service.mapper.LogSmallMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -24,8 +31,29 @@ public class LogServiceImpl implements LogService {
|
|||
@Autowired
|
||||
private LogRepository logRepository;
|
||||
|
||||
@Autowired
|
||||
private LogErrorMapper logErrorMapper;
|
||||
|
||||
@Autowired
|
||||
private LogSmallMapper logSmallMapper;
|
||||
|
||||
private final String LOGINPATH = "login";
|
||||
|
||||
@Override
|
||||
public Object queryAll(LogQueryCriteria criteria, Pageable pageable){
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
if (criteria.getLogType().equals("ERROR")) {
|
||||
return PageUtil.toPage(page.map(logErrorMapper::toDto));
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
|
||||
return PageUtil.toPage(page.map(logSmallMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(String username, String ip, ProceedingJoinPoint joinPoint, Log log){
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
package me.zhengjie.service.query;
|
||||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.repository.LogRepository;
|
||||
import me.zhengjie.service.mapper.LogErrorMapper;
|
||||
import me.zhengjie.service.mapper.LogSmallMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class LogQueryService {
|
||||
|
||||
@Autowired
|
||||
private LogRepository logRepository;
|
||||
|
||||
@Autowired
|
||||
private LogErrorMapper logErrorMapper;
|
||||
|
||||
@Autowired
|
||||
private LogSmallMapper logSmallMapper;
|
||||
|
||||
public Object queryAll(Log log, Pageable pageable){
|
||||
Page<Log> page = logRepository.findAll(new Spec(log),pageable);
|
||||
if (log.getLogType().equals("ERROR")) {
|
||||
return PageUtil.toPage(page.map(logErrorMapper::toDto));
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public Object queryAllByUser(Log log, Pageable pageable) {
|
||||
Page<Log> page = logRepository.findAll(new Spec(log),pageable);
|
||||
return PageUtil.toPage(page.map(logSmallMapper::toDto));
|
||||
}
|
||||
|
||||
class Spec implements Specification<Log> {
|
||||
|
||||
private Log log;
|
||||
|
||||
public Spec(Log log){
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Log> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
|
||||
if(!ObjectUtils.isEmpty(log.getUsername())){
|
||||
list.add(cb.like(root.get("username").as(String.class),"%"+log.getUsername()+"%"));
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(log.getLogType())) {
|
||||
list.add(cb.equal(root.get("logType").as(String.class), log.getLogType()));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,12 +42,6 @@
|
|||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--websocket-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- quartz -->
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -15,7 +14,6 @@ import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBr
|
|||
@EnableAsync
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement
|
||||
@EnableWebSocketMessageBroker
|
||||
public class AppRun {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
package me.zhengjie.modules.monitor.config;
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.classic.spi.IThrowableProxy;
|
||||
import ch.qos.logback.core.filter.Filter;
|
||||
import ch.qos.logback.core.spi.FilterReply;
|
||||
import me.zhengjie.modules.monitor.domain.LogMessage;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 定义Logfilter拦截输出日志
|
||||
* @author jie
|
||||
* @reference https://cloud.tencent.com/developer/article/1096792
|
||||
* @date 2018-12-24
|
||||
*/
|
||||
public class LogFilter extends Filter<ILoggingEvent>{
|
||||
|
||||
@Override
|
||||
public FilterReply decide(ILoggingEvent event) {
|
||||
LogMessage loggerMessage = new LogMessage(
|
||||
event.getFormattedMessage(),
|
||||
DateFormat.getDateTimeInstance().format(new Date(event.getTimeStamp())),
|
||||
event.getThreadName(),
|
||||
event.getLoggerName(),
|
||||
event.getLevel().levelStr
|
||||
);
|
||||
LoggerQueue.getInstance().push(loggerMessage);
|
||||
return FilterReply.ACCEPT;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package me.zhengjie.modules.monitor.config;
|
||||
|
||||
import me.zhengjie.modules.monitor.domain.LogMessage;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* 创建一个阻塞队列,作为日志系统输出的日志的一个临时载体
|
||||
* @author https://cloud.tencent.com/developer/article/1096792
|
||||
* @date 2018-12-24
|
||||
*/
|
||||
public class LoggerQueue {
|
||||
|
||||
/**
|
||||
* 队列大小
|
||||
*/
|
||||
public static final int QUEUE_MAX_SIZE = 10000;
|
||||
|
||||
private static LoggerQueue alarmMessageQueue = new LoggerQueue();
|
||||
/**
|
||||
* 阻塞队列
|
||||
*/
|
||||
private BlockingQueue blockingQueue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE);
|
||||
|
||||
private LoggerQueue() {
|
||||
}
|
||||
|
||||
public static LoggerQueue getInstance() {
|
||||
return alarmMessageQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息入队
|
||||
* @param log
|
||||
* @return
|
||||
*/
|
||||
public boolean push(LogMessage log) {
|
||||
return this.blockingQueue.add(log);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息出队
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LogMessage poll() {
|
||||
LogMessage result = null;
|
||||
try {
|
||||
result = (LogMessage) this.blockingQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package me.zhengjie.modules.monitor.config;
|
||||
|
||||
import me.zhengjie.modules.monitor.service.VisitsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 初始化站点统计
|
||||
* @author jie
|
||||
*/
|
||||
@Component
|
||||
public class VisitsInitialization implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private VisitsService visitsService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
System.out.println("--------------- 初始化站点统计,如果存在今日统计则跳过 ---------------");
|
||||
visitsService.save();
|
||||
System.out.println("--------------- 初始化站点统计完成 ---------------");
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package me.zhengjie.modules.monitor.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.modules.monitor.domain.LogMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 配置WebSocket消息代理端点,即stomp服务端
|
||||
* @author jie
|
||||
* @reference https://cloud.tencent.com/developer/article/1096792
|
||||
* @date 2018-12-24
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||
|
||||
@Autowired
|
||||
private SimpMessagingTemplate messagingTemplate;
|
||||
|
||||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Override
|
||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/websocket")
|
||||
.setAllowedOrigins("*")
|
||||
.withSockJS();
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送日志到/topic/pullLogger
|
||||
*/
|
||||
@PostConstruct
|
||||
public void pushLogger(){
|
||||
Runnable runnable=new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
LogMessage log = LoggerQueue.getInstance().poll();
|
||||
if(log!=null){
|
||||
// 格式化异常堆栈信息
|
||||
if("ERROR".equals(log.getLevel()) && "me.zhengjie.common.exception.handler.GlobalExceptionHandler".equals(log.getClassName())){
|
||||
log.setBody("<pre>"+log.getBody()+"</pre>");
|
||||
}
|
||||
if(log.getClassName().equals("jdbc.resultsettable")){
|
||||
log.setBody("<br><pre>"+log.getBody()+"</pre>");
|
||||
}
|
||||
if(messagingTemplate!=null){
|
||||
messagingTemplate.convertAndSend("/topic/logMsg",log);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
executorService.submit(runnable);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package me.zhengjie.modules.monitor.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author https://cloud.tencent.com/developer/article/1096792
|
||||
* @date 2018-12-24
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class LogMessage {
|
||||
|
||||
private String body;
|
||||
private String timestamp;
|
||||
private String threadName;
|
||||
private String className;
|
||||
private String level;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package me.zhengjie.modules.monitor.rest;
|
||||
|
||||
import me.zhengjie.aop.limit.Limit;
|
||||
import me.zhengjie.annotation.Limit;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
|
@ -4,10 +4,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.quartz.domain.QuartzJob;
|
||||
import me.zhengjie.modules.quartz.domain.QuartzLog;
|
||||
import me.zhengjie.modules.quartz.service.QuartzJobService;
|
||||
import me.zhengjie.modules.quartz.service.query.QuartzJobQueryService;
|
||||
import me.zhengjie.modules.quartz.service.query.QuartzLogQueryService;
|
||||
import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -30,29 +28,17 @@ public class QuartzJobController {
|
|||
@Autowired
|
||||
private QuartzJobService quartzJobService;
|
||||
|
||||
@Autowired
|
||||
private QuartzJobQueryService quartzJobQueryService;
|
||||
|
||||
@Autowired
|
||||
private QuartzLogQueryService quartzLogQueryService;
|
||||
|
||||
@Log("查询定时任务")
|
||||
@GetMapping(value = "/jobs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','JOB_ALL','JOB_SELECT')")
|
||||
public ResponseEntity getJobs(QuartzJob resources, Pageable pageable){
|
||||
return new ResponseEntity(quartzJobQueryService.queryAll(resources,pageable), HttpStatus.OK);
|
||||
public ResponseEntity getJobs(JobQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询定时任务日志
|
||||
* @param resources
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/jobLogs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','JOB_ALL','JOB_SELECT')")
|
||||
public ResponseEntity getJobLogs(QuartzLog resources, Pageable pageable){
|
||||
return new ResponseEntity(quartzLogQueryService.queryAll(resources,pageable), HttpStatus.OK);
|
||||
public ResponseEntity getJobLogs(JobQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(quartzJobService.queryAllLog(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增定时任务")
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package me.zhengjie.modules.quartz.service;
|
||||
|
||||
import me.zhengjie.modules.quartz.domain.QuartzJob;
|
||||
import me.zhengjie.modules.quartz.domain.QuartzLog;
|
||||
import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -12,6 +15,23 @@ import org.springframework.cache.annotation.Cacheable;
|
|||
@CacheConfig(cacheNames = "quartzJob")
|
||||
public interface QuartzJobService {
|
||||
|
||||
/**
|
||||
* queryAll quartzJob
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll quartzLog
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Object queryAllLog(JobQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* create
|
||||
* @param resources
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package me.zhengjie.modules.quartz.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-6-4 10:33:02
|
||||
*/
|
||||
@Data
|
||||
public class JobQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String jobName;
|
||||
|
||||
@Query
|
||||
private Boolean isSuccess;
|
||||
}
|
|
@ -3,11 +3,16 @@ package me.zhengjie.modules.quartz.service.impl;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.quartz.domain.QuartzJob;
|
||||
import me.zhengjie.modules.quartz.repository.QuartzJobRepository;
|
||||
import me.zhengjie.modules.quartz.repository.QuartzLogRepository;
|
||||
import me.zhengjie.modules.quartz.service.QuartzJobService;
|
||||
import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria;
|
||||
import me.zhengjie.modules.quartz.utils.QuartzManage;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.quartz.CronExpression;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -24,9 +29,21 @@ public class QuartzJobServiceImpl implements QuartzJobService {
|
|||
@Autowired
|
||||
private QuartzJobRepository quartzJobRepository;
|
||||
|
||||
@Autowired
|
||||
private QuartzLogRepository quartzLogRepository;
|
||||
|
||||
@Autowired
|
||||
private QuartzManage quartzManage;
|
||||
|
||||
@Override
|
||||
public Object queryAll(JobQueryCriteria criteria, Pageable pageable){
|
||||
return PageUtil.toPage(quartzJobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
|
||||
}
|
||||
|
||||
public Object queryAllLog(JobQueryCriteria criteria, Pageable pageable){
|
||||
return PageUtil.toPage(quartzLogRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuartzJob findById(Long id) {
|
||||
Optional<QuartzJob> quartzJob = quartzJobRepository.findById(id);
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
package me.zhengjie.modules.quartz.service.query;
|
||||
|
||||
import me.zhengjie.modules.quartz.domain.QuartzJob;
|
||||
import me.zhengjie.modules.quartz.repository.QuartzJobRepository;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-01-07
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "quartzJob")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class QuartzJobQueryService {
|
||||
|
||||
@Autowired
|
||||
private QuartzJobRepository quartzJobRepository;
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(QuartzJob quartzJob, Pageable pageable){
|
||||
return PageUtil.toPage(quartzJobRepository.findAll(new Spec(quartzJob),pageable));
|
||||
}
|
||||
|
||||
class Spec implements Specification<QuartzJob> {
|
||||
|
||||
private QuartzJob quartzJob;
|
||||
|
||||
public Spec(QuartzJob quartzJob){
|
||||
this.quartzJob = quartzJob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<QuartzJob> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(quartzJob.getJobName())){
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("jobName").as(String.class),"%"+quartzJob.getJobName()+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package me.zhengjie.modules.quartz.service.query;
|
||||
|
||||
import me.zhengjie.modules.quartz.domain.QuartzLog;
|
||||
import me.zhengjie.modules.quartz.repository.QuartzLogRepository;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-01-07
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class QuartzLogQueryService {
|
||||
|
||||
@Autowired
|
||||
private QuartzLogRepository quartzLogRepository;
|
||||
|
||||
public Object queryAll(QuartzLog quartzLog, Pageable pageable){
|
||||
return PageUtil.toPage(quartzLogRepository.findAll(new Spec(quartzLog),pageable));
|
||||
}
|
||||
|
||||
class Spec implements Specification<QuartzLog> {
|
||||
|
||||
private QuartzLog quartzLog;
|
||||
|
||||
public Spec(QuartzLog quartzLog){
|
||||
this.quartzLog = quartzLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<QuartzLog> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(quartzLog.getJobName())){
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("jobName").as(String.class),"%"+quartzLog.getJobName()+"%"));
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(quartzLog.getIsSuccess())) {
|
||||
list.add(cb.equal(root.get("isSuccess").as(Boolean.class), quartzLog.getIsSuccess()));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.service.DeptService;
|
||||
import me.zhengjie.modules.system.service.dto.DeptDTO;
|
||||
import me.zhengjie.modules.system.service.query.DeptQueryService;
|
||||
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -14,7 +14,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -27,9 +26,6 @@ public class DeptController {
|
|||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
@Autowired
|
||||
private DeptQueryService deptQueryService;
|
||||
|
||||
@Autowired
|
||||
private DataScope dataScope;
|
||||
|
||||
|
@ -38,10 +34,10 @@ public class DeptController {
|
|||
@Log("查询部门")
|
||||
@GetMapping(value = "/dept")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT','DEPT_ALL','DEPT_SELECT')")
|
||||
public ResponseEntity getDepts(DeptDTO resources){
|
||||
public ResponseEntity getDepts(DeptQueryCriteria criteria){
|
||||
// 数据权限
|
||||
Set<Long> deptIds = dataScope.getDeptIds();
|
||||
List<DeptDTO> deptDTOS = deptQueryService.queryAll(resources, deptIds);
|
||||
criteria.setIds(dataScope.getDeptIds());
|
||||
List<DeptDTO> deptDTOS = deptService.queryAll(criteria);
|
||||
return new ResponseEntity(deptService.buildTree(deptDTOS),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.modules.system.domain.Dict;
|
||||
import me.zhengjie.modules.system.service.DictService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDTO;
|
||||
import me.zhengjie.modules.system.service.query.DictQueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -25,16 +24,13 @@ public class DictController {
|
|||
@Autowired
|
||||
private DictService dictService;
|
||||
|
||||
@Autowired
|
||||
private DictQueryService dictQueryService;
|
||||
|
||||
private static final String ENTITY_NAME = "dict";
|
||||
|
||||
@Log("查询字典")
|
||||
@GetMapping(value = "/dict")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','DICT_ALL','DICT_SELECT')")
|
||||
public ResponseEntity getDicts(DictDTO resources, Pageable pageable){
|
||||
return new ResponseEntity(dictQueryService.queryAll(resources,pageable),HttpStatus.OK);
|
||||
return new ResponseEntity(dictService.queryAll(resources,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增字典")
|
||||
|
|
|
@ -4,8 +4,7 @@ import me.zhengjie.aop.log.Log;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.domain.DictDetail;
|
||||
import me.zhengjie.modules.system.service.DictDetailService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
|
||||
import me.zhengjie.modules.system.service.query.DictDetailQueryService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
@ -27,16 +26,13 @@ public class DictDetailController {
|
|||
@Autowired
|
||||
private DictDetailService dictDetailService;
|
||||
|
||||
@Autowired
|
||||
private DictDetailQueryService dictDetailQueryService;
|
||||
|
||||
private static final String ENTITY_NAME = "dictDetail";
|
||||
|
||||
@Log("查询字典详情")
|
||||
@GetMapping(value = "/dictDetail")
|
||||
public ResponseEntity getDictDetails(DictDetailDTO resources,
|
||||
public ResponseEntity getDictDetails(DictDetailQueryCriteria criteria,
|
||||
@PageableDefault(value = 10, sort = {"sort"}, direction = Sort.Direction.ASC) Pageable pageable){
|
||||
return new ResponseEntity(dictDetailQueryService.queryAll(resources,pageable),HttpStatus.OK);
|
||||
return new ResponseEntity(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增字典详情")
|
||||
|
|
|
@ -5,7 +5,7 @@ import me.zhengjie.config.DataScope;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.service.JobService;
|
||||
import me.zhengjie.modules.system.service.query.JobQueryService;
|
||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -27,9 +27,6 @@ public class JobController {
|
|||
@Autowired
|
||||
private JobService jobService;
|
||||
|
||||
@Autowired
|
||||
private JobQueryService jobQueryService;
|
||||
|
||||
@Autowired
|
||||
private DataScope dataScope;
|
||||
|
||||
|
@ -38,13 +35,11 @@ public class JobController {
|
|||
@Log("查询岗位")
|
||||
@GetMapping(value = "/job")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_SELECT','USER_ALL','USER_SELECT')")
|
||||
public ResponseEntity getJobs(@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) Long deptId,
|
||||
@RequestParam(required = false) Boolean enabled,
|
||||
public ResponseEntity getJobs(JobQueryCriteria criteria,
|
||||
Pageable pageable){
|
||||
// 数据权限
|
||||
Set<Long> deptIds = dataScope.getDeptIds();
|
||||
return new ResponseEntity(jobQueryService.queryAll(name, enabled , deptIds, deptId, pageable),HttpStatus.OK);
|
||||
criteria.setDeptIds(dataScope.getDeptIds());
|
||||
return new ResponseEntity(jobService.queryAll(criteria, pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增岗位")
|
||||
|
|
|
@ -2,15 +2,13 @@ package me.zhengjie.modules.system.rest;
|
|||
|
||||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.service.MenuService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.MenuMapper;
|
||||
import me.zhengjie.modules.system.service.query.MenuQueryService;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -31,18 +29,12 @@ public class MenuController {
|
|||
@Autowired
|
||||
private MenuService menuService;
|
||||
|
||||
@Autowired
|
||||
private MenuQueryService menuQueryService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
private static final String ENTITY_NAME = "menu";
|
||||
|
||||
/**
|
||||
|
@ -70,8 +62,8 @@ public class MenuController {
|
|||
@Log("查询菜单")
|
||||
@GetMapping(value = "/menus")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','MENU_ALL','MENU_SELECT')")
|
||||
public ResponseEntity getMenus(@RequestParam(required = false) String name){
|
||||
List<MenuDTO> menuDTOList = menuQueryService.queryAll(name);
|
||||
public ResponseEntity getMenus(CommonQueryCriteria criteria){
|
||||
List<MenuDTO> menuDTOList = menuService.queryAll(criteria);
|
||||
return new ResponseEntity(menuService.buildTree(menuDTOList),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import me.zhengjie.aop.log.Log;
|
|||
import me.zhengjie.modules.system.domain.Permission;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.service.PermissionService;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionDTO;
|
||||
import me.zhengjie.modules.system.service.query.PermissionQueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -26,9 +26,6 @@ public class PermissionController {
|
|||
@Autowired
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired
|
||||
private PermissionQueryService permissionQueryService;
|
||||
|
||||
private static final String ENTITY_NAME = "permission";
|
||||
|
||||
/**
|
||||
|
@ -44,8 +41,8 @@ public class PermissionController {
|
|||
@Log("查询权限")
|
||||
@GetMapping(value = "/permissions")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_SELECT')")
|
||||
public ResponseEntity getPermissions(@RequestParam(required = false) String name){
|
||||
List<PermissionDTO> permissionDTOS = permissionQueryService.queryAll(name);
|
||||
public ResponseEntity getPermissions(CommonQueryCriteria criteria){
|
||||
List<PermissionDTO> permissionDTOS = permissionService.queryAll(criteria);
|
||||
return new ResponseEntity(permissionService.buildTree(permissionDTOS),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,9 @@ import cn.hutool.core.lang.Dict;
|
|||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.query.RoleQueryService;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -19,10 +17,8 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -36,9 +32,6 @@ public class RoleController {
|
|||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private RoleQueryService roleQueryService;
|
||||
|
||||
private static final String ENTITY_NAME = "role";
|
||||
|
||||
/**
|
||||
|
@ -59,15 +52,14 @@ public class RoleController {
|
|||
@GetMapping(value = "/roles/all")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_CREATE','USER_EDIT')")
|
||||
public ResponseEntity getAll(@PageableDefault(value = 2000, sort = {"level"}, direction = Sort.Direction.ASC) Pageable pageable){
|
||||
|
||||
return new ResponseEntity(roleQueryService.queryAll(pageable),HttpStatus.OK);
|
||||
return new ResponseEntity(roleService.queryAll(pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询角色")
|
||||
@GetMapping(value = "/roles")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','ROLES_ALL','ROLES_SELECT')")
|
||||
public ResponseEntity getRoles(@RequestParam(required = false) String name, Pageable pageable){
|
||||
return new ResponseEntity(roleQueryService.queryAll(name,pageable),HttpStatus.OK);
|
||||
public ResponseEntity getRoles(CommonQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(roleService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/roles/level")
|
||||
|
|
|
@ -4,18 +4,16 @@ import me.zhengjie.aop.log.Log;
|
|||
import me.zhengjie.config.DataScope;
|
||||
import me.zhengjie.domain.Picture;
|
||||
import me.zhengjie.domain.VerificationCode;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.service.DeptService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
|
||||
import me.zhengjie.service.PictureService;
|
||||
import me.zhengjie.service.VerificationCodeService;
|
||||
import me.zhengjie.utils.*;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.query.UserQueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -41,9 +39,6 @@ public class UserController {
|
|||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private UserQueryService userQueryService;
|
||||
|
||||
@Autowired
|
||||
private PictureService pictureService;
|
||||
|
||||
|
@ -59,19 +54,16 @@ public class UserController {
|
|||
@Autowired
|
||||
private VerificationCodeService verificationCodeService;
|
||||
|
||||
|
||||
private static final String ENTITY_NAME = "user";
|
||||
|
||||
@Log("查询用户")
|
||||
@GetMapping(value = "/users")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_SELECT')")
|
||||
public ResponseEntity getUsers(UserDTO userDTO, Pageable pageable){
|
||||
public ResponseEntity getUsers(UserQueryCriteria criteria, Pageable pageable){
|
||||
Set<Long> deptSet = new HashSet<>();
|
||||
Set<Long> result = new HashSet<>();
|
||||
|
||||
if (!ObjectUtils.isEmpty(userDTO.getDeptId())) {
|
||||
deptSet.add(userDTO.getDeptId());
|
||||
deptSet.addAll(dataScope.getDeptChildren(deptService.findByPid(userDTO.getDeptId())));
|
||||
if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
|
||||
deptSet.add(criteria.getDeptId());
|
||||
deptSet.addAll(dataScope.getDeptChildren(deptService.findByPid(criteria.getDeptId())));
|
||||
}
|
||||
|
||||
// 数据权限
|
||||
|
@ -85,14 +77,16 @@ public class UserController {
|
|||
result.retainAll(deptIds);
|
||||
|
||||
// 若无交集,则代表无数据权限
|
||||
criteria.setDeptIds(result);
|
||||
if(result.size() == 0){
|
||||
return new ResponseEntity(PageUtil.toPage(null,0),HttpStatus.OK);
|
||||
} else return new ResponseEntity(userQueryService.queryAll(userDTO,result,pageable),HttpStatus.OK);
|
||||
} else return new ResponseEntity(userService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
// 否则取并集
|
||||
} else {
|
||||
result.addAll(deptSet);
|
||||
result.addAll(deptIds);
|
||||
return new ResponseEntity(userQueryService.queryAll(userDTO,result,pageable),HttpStatus.OK);
|
||||
criteria.setDeptIds(result);
|
||||
return new ResponseEntity(userService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package me.zhengjie.modules.system.service;
|
|||
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.service.dto.DeptDTO;
|
||||
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -16,6 +17,14 @@ import java.util.Set;
|
|||
@CacheConfig(cacheNames = "dept")
|
||||
public interface DeptService {
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* findById
|
||||
* @param id
|
||||
|
|
|
@ -2,9 +2,11 @@ package me.zhengjie.modules.system.service;
|
|||
|
||||
import me.zhengjie.modules.system.domain.DictDetail;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -42,4 +44,7 @@ public interface DictDetailService {
|
|||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
|
||||
}
|
|
@ -5,6 +5,7 @@ import me.zhengjie.modules.system.service.dto.DictDTO;
|
|||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -13,6 +14,15 @@ import org.springframework.cache.annotation.Cacheable;
|
|||
@CacheConfig(cacheNames = "dict")
|
||||
public interface DictService {
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* @param dict
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(DictDTO dict, Pageable pageable);
|
||||
|
||||
/**
|
||||
* findById
|
||||
* @param id
|
||||
|
|
|
@ -2,9 +2,11 @@ package me.zhengjie.modules.system.service;
|
|||
|
||||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.service.dto.JobDTO;
|
||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -42,4 +44,12 @@ public interface JobService {
|
|||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void delete(Long id);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
|
||||
}
|
|
@ -2,6 +2,7 @@ package me.zhengjie.modules.system.service;
|
|||
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
|
@ -18,6 +19,14 @@ import java.util.Set;
|
|||
@CacheConfig(cacheNames = "menu")
|
||||
public interface MenuService {
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
List<MenuDTO> queryAll(CommonQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* get
|
||||
* @param id
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package me.zhengjie.modules.system.service;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Permission;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionDTO;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
|
@ -68,4 +69,12 @@ public interface PermissionService {
|
|||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object buildTree(List<PermissionDTO> permissionDTOS);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
List<PermissionDTO> queryAll(CommonQueryCriteria criteria);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@ package me.zhengjie.modules.system.service;
|
|||
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -78,4 +80,19 @@ public interface RoleService {
|
|||
|
||||
@CacheEvict(allEntries = true)
|
||||
void untiedMenu(Menu menu);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Object queryAll(Pageable pageable);
|
||||
|
||||
/**
|
||||
* queryAll
|
||||
* @param pageable
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
Object queryAll(CommonQueryCriteria criteria, Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package me.zhengjie.modules.system.service;
|
|||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.security.security.JwtUser;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -75,4 +77,7 @@ public interface UserService {
|
|||
*/
|
||||
@CacheEvict(allEntries = true)
|
||||
void updateEmail(String username, String email);
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* 公共查询类
|
||||
*/
|
||||
@Data
|
||||
public class CommonQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-03-25
|
||||
*/
|
||||
@Data
|
||||
public class DeptQueryCriteria{
|
||||
|
||||
@Query(type = Query.Type.IN, propName="id")
|
||||
private Set<Long> ids;
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
@Query
|
||||
private Boolean enabled;
|
||||
|
||||
@Query
|
||||
private Long pid;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.PredicateInfo;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
@ -17,12 +17,12 @@ public class DictDTO implements Serializable {
|
|||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
@PredicateInfo(queryType = PredicateInfo.QueryType.INNER_LIKE)
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@PredicateInfo(queryType = PredicateInfo.QueryType.INNER_LIKE)
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String remark;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-04-10
|
||||
*/
|
||||
@Data
|
||||
public class DictDetailQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String label;
|
||||
|
||||
@Query(propName = "name",joinName = "dict")
|
||||
private String dictName;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-6-4 14:49:34
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class JobQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
@Query
|
||||
private Boolean enabled;
|
||||
|
||||
@Query(propName = "id", joinName = "dept")
|
||||
private Long deptId;
|
||||
|
||||
@Query(propName = "id", joinName = "dept", type = Query.Type.IN)
|
||||
private Set<Long> deptIds;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Data
|
||||
public class RoleQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String name;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Data
|
||||
public class UserQueryCriteria implements Serializable {
|
||||
|
||||
@Query
|
||||
private Long id;
|
||||
|
||||
@Query(propName = "id", type = Query.Type.IN, joinName = "dept")
|
||||
private Set<Long> deptIds;
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String username;
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String email;
|
||||
|
||||
@Query
|
||||
private Boolean enabled;
|
||||
|
||||
private Long deptId;
|
||||
}
|
|
@ -2,6 +2,8 @@ package me.zhengjie.modules.system.service.impl;
|
|||
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.modules.system.repository.DeptRepository;
|
||||
import me.zhengjie.modules.system.service.DeptService;
|
||||
|
@ -12,7 +14,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -30,6 +31,11 @@ public class DeptServiceImpl implements DeptService {
|
|||
@Autowired
|
||||
private DeptMapper deptMapper;
|
||||
|
||||
@Override
|
||||
public List<DeptDTO> queryAll(DeptQueryCriteria criteria) {
|
||||
return deptMapper.toDto(deptRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeptDTO findById(Long id) {
|
||||
Optional<Dept> dept = deptRepository.findById(id);
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package me.zhengjie.modules.system.service.impl;
|
||||
|
||||
import me.zhengjie.modules.system.domain.DictDetail;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.modules.system.repository.DictDetailRepository;
|
||||
import me.zhengjie.modules.system.service.DictDetailService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.DictDetailMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -26,6 +31,12 @@ public class DictDetailServiceImpl implements DictDetailService {
|
|||
@Autowired
|
||||
private DictDetailMapper dictDetailMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(DictDetailQueryCriteria criteria, Pageable pageable) {
|
||||
Page<DictDetail> page = dictDetailRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(dictDetailMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictDetailDTO findById(Long id) {
|
||||
Optional<DictDetail> dictDetail = dictDetailRepository.findById(id);
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package me.zhengjie.modules.system.service.impl;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dict;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.modules.system.repository.DictRepository;
|
||||
import me.zhengjie.modules.system.service.DictService;
|
||||
import me.zhengjie.modules.system.service.dto.DictDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.DictMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -26,6 +30,12 @@ public class DictServiceImpl implements DictService {
|
|||
@Autowired
|
||||
private DictMapper dictMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(DictDTO dict, Pageable pageable){
|
||||
Page<Dict> page = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb), pageable);
|
||||
return PageUtil.toPage(page.map(dictMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictDTO findById(Long id) {
|
||||
Optional<Dict> dict = dictRepository.findById(id);
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
package me.zhengjie.modules.system.service.impl;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.repository.DeptRepository;
|
||||
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.modules.system.repository.JobRepository;
|
||||
import me.zhengjie.modules.system.service.JobService;
|
||||
import me.zhengjie.modules.system.service.dto.JobDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.JobMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +34,19 @@ public class JobServiceImpl implements JobService {
|
|||
@Autowired
|
||||
private JobMapper jobMapper;
|
||||
|
||||
@Autowired
|
||||
private DeptRepository deptRepository;
|
||||
|
||||
@Override
|
||||
public Object queryAll(JobQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Job> page = jobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
List<JobDTO> jobs = new ArrayList<>();
|
||||
for (Job job : page.getContent()) {
|
||||
jobs.add(jobMapper.toDto(job,deptRepository.findNameById(job.getDept().getPid())));
|
||||
}
|
||||
return PageUtil.toPage(jobs,page.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobDTO findById(Long id) {
|
||||
Optional<Job> job = jobRepository.findById(id);
|
||||
|
|
|
@ -8,9 +8,11 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.modules.system.repository.MenuRepository;
|
||||
import me.zhengjie.modules.system.service.MenuService;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.MenuMapper;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -29,6 +31,11 @@ public class MenuServiceImpl implements MenuService {
|
|||
@Autowired
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
@Override
|
||||
public List queryAll(CommonQueryCriteria criteria){
|
||||
return menuMapper.toDto(menuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuDTO findById(long id) {
|
||||
Optional<Menu> menu = menuRepository.findById(id);
|
||||
|
|
|
@ -5,8 +5,10 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.modules.system.repository.PermissionRepository;
|
||||
import me.zhengjie.modules.system.service.PermissionService;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.PermissionDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.PermissionMapper;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -28,6 +30,11 @@ public class PermissionServiceImpl implements PermissionService {
|
|||
@Autowired
|
||||
private PermissionMapper permissionMapper;
|
||||
|
||||
@Override
|
||||
public List<PermissionDTO> queryAll(CommonQueryCriteria criteria) {
|
||||
return permissionMapper.toDto(permissionRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDTO findById(long id) {
|
||||
Optional<Permission> permission = permissionRepository.findById(id);
|
||||
|
|
|
@ -2,16 +2,20 @@ package me.zhengjie.modules.system.service.impl;
|
|||
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.exception.EntityExistException;
|
||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.CommonQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.RoleMapper;
|
||||
import me.zhengjie.modules.system.service.mapper.RoleSmallMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -35,6 +39,17 @@ public class RoleServiceImpl implements RoleService {
|
|||
@Autowired
|
||||
private RoleSmallMapper roleSmallMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(Pageable pageable) {
|
||||
return roleMapper.toDto(roleRepository.findAll(pageable).getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAll(CommonQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Role> page = roleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(roleMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleDTO findById(long id) {
|
||||
Optional<Role> role = roleRepository.findById(id);
|
||||
|
|
|
@ -7,9 +7,14 @@ import me.zhengjie.exception.EntityNotFoundException;
|
|||
import me.zhengjie.modules.system.repository.UserRepository;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
|
||||
import me.zhengjie.modules.system.service.mapper.UserMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -33,6 +38,12 @@ public class UserServiceImpl implements UserService {
|
|||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
|
||||
Page<User> page = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(userMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO findById(long id) {
|
||||
Optional<User> user = userRepository.findById(id);
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.service.dto.DeptDTO;
|
||||
import me.zhengjie.modules.system.repository.DeptRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.DeptMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "dept")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class DeptQueryService {
|
||||
|
||||
@Autowired
|
||||
private DeptRepository deptRepository;
|
||||
|
||||
@Autowired
|
||||
private DeptMapper deptMapper;
|
||||
|
||||
/**
|
||||
* 不分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public List queryAll(DeptDTO dept, Set<Long> deptIds){
|
||||
return deptMapper.toDto(deptRepository.findAll(new Spec(dept, deptIds)));
|
||||
}
|
||||
|
||||
class Spec implements Specification<Dept> {
|
||||
|
||||
private DeptDTO dept;
|
||||
|
||||
private Set<Long> deptIds;
|
||||
|
||||
|
||||
public Spec(DeptDTO dept, Set<Long> deptIds){
|
||||
this.dept = dept;
|
||||
this.deptIds = deptIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Dept> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(dept.getName())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+dept.getName()+"%"));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(dept.getEnabled())){
|
||||
/**
|
||||
* 相等
|
||||
*/
|
||||
list.add(cb.equal(root.get("enabled").as(Boolean.class),dept.getEnabled()));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(dept.getPid())){
|
||||
/**
|
||||
* 相等
|
||||
*/
|
||||
list.add(cb.equal(root.get("pid").as(Boolean.class),dept.getPid()));
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(deptIds)) {
|
||||
list.add(root.get("id").in(deptIds));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dict;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.modules.system.domain.DictDetail;
|
||||
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
|
||||
import me.zhengjie.modules.system.repository.DictDetailRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.DictDetailMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import javax.persistence.criteria.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "dictDetail")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class DictDetailQueryService {
|
||||
|
||||
@Autowired
|
||||
private DictDetailRepository dictDetailRepository;
|
||||
|
||||
@Autowired
|
||||
private DictDetailMapper dictDetailMapper;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(DictDetailDTO dictDetail, Pageable pageable){
|
||||
Page<DictDetail> page = dictDetailRepository.findAll(new Spec(dictDetail),pageable);
|
||||
return PageUtil.toPage(page.map(dictDetailMapper::toDto));
|
||||
}
|
||||
|
||||
class Spec implements Specification<DictDetail> {
|
||||
|
||||
private DictDetailDTO dictDetail;
|
||||
|
||||
public Spec(DictDetailDTO dictDetail){
|
||||
this.dictDetail = dictDetail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<DictDetail> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
Join<Dict,DictDetail> join = root.join("dict",JoinType.LEFT);
|
||||
|
||||
if(!ObjectUtils.isEmpty(dictDetail.getLabel())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("label").as(String.class),"%"+dictDetail.getLabel()+"%"));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(dictDetail.getDictName())){
|
||||
list.add(cb.equal(join.get("name").as(String.class),dictDetail.getDictName()));
|
||||
}
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.utils.BeanHelp;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.modules.system.domain.Dict;
|
||||
import me.zhengjie.modules.system.service.dto.DictDTO;
|
||||
import me.zhengjie.modules.system.repository.DictRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.DictMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "dict")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class DictQueryService {
|
||||
|
||||
@Autowired
|
||||
private DictRepository dictRepository;
|
||||
|
||||
@Autowired
|
||||
private DictMapper dictMapper;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(DictDTO dict, Pageable pageable){
|
||||
//Page<Dict> page = dictRepository.findAll(new Spec(dict),pageable);
|
||||
/** Dong ZhaoYang 2019/6/3 修改分页查询方法 */
|
||||
Page<Dict> page = dictRepository.findAll((root, query, cb) -> BeanHelp.getPredicate(root, dict, cb), pageable);
|
||||
return PageUtil.toPage(page.map(dictMapper::toDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 不分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(DictDTO dict){
|
||||
//return dictMapper.toDto(dictRepository.findAll(new Spec(dict)));
|
||||
/** Dong ZhaoYang 2019/6/3 不分页 同理 */
|
||||
return dictMapper.toDto(dictRepository.findAll((root, query, cb) -> BeanHelp.getPredicate(root, dict, cb)));
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.repository.DeptRepository;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.service.dto.JobDTO;
|
||||
import me.zhengjie.modules.system.repository.JobRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.JobMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import javax.persistence.criteria.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "job")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class JobQueryService {
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private DeptRepository deptRepository;
|
||||
|
||||
@Autowired
|
||||
private JobMapper jobMapper;
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(String name , Boolean enabled, Set<Long> deptIds, Long deptId, Pageable pageable){
|
||||
Page<Job> page = jobRepository.findAll(new Spec(new JobDTO(name,enabled), deptIds, deptId),pageable);
|
||||
|
||||
List<JobDTO> jobs = new ArrayList<>();
|
||||
for (Job job : page.getContent()) {
|
||||
jobs.add(jobMapper.toDto(job,deptRepository.findNameById(job.getDept().getPid())));
|
||||
}
|
||||
return PageUtil.toPage(jobs,page.getTotalElements());
|
||||
}
|
||||
|
||||
class Spec implements Specification<Job> {
|
||||
|
||||
private JobDTO job;
|
||||
private Long deptId;
|
||||
private Set<Long> deptIds;
|
||||
|
||||
public Spec(JobDTO job, Set<Long> deptIds, Long deptId){
|
||||
this.job = job;
|
||||
this.deptId = deptId;
|
||||
this.deptIds = deptIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Job> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
// 数据权限
|
||||
Join<Dept, Job> join = root.join("dept",JoinType.LEFT);
|
||||
if (!CollectionUtils.isEmpty(deptIds)) {
|
||||
list.add(join.get("id").in(deptIds));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(job.getEnabled())){
|
||||
/**
|
||||
* 精确
|
||||
*/
|
||||
list.add(cb.equal(root.get("enabled").as(Boolean.class),job.getEnabled()));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(job.getName())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+job.getName()+"%"));
|
||||
}
|
||||
|
||||
if (deptId != null) {
|
||||
/**
|
||||
* 精确
|
||||
*/
|
||||
list.add(cb.equal(join.get("id").as(Long.class),deptId));
|
||||
}
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.repository.MenuRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.MenuMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-17
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "menu")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class MenuQueryService {
|
||||
|
||||
@Autowired
|
||||
private MenuRepository menuRepository;
|
||||
|
||||
@Autowired
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
/**
|
||||
* 不分页
|
||||
*/
|
||||
@Cacheable(key = "'queryAll:'+#p0")
|
||||
public List queryAll(String name){
|
||||
return menuMapper.toDto(menuRepository.findAll(new Spec(name)));
|
||||
}
|
||||
|
||||
class Spec implements Specification<Menu> {
|
||||
|
||||
private String name;
|
||||
|
||||
public Spec(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Menu> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(name)){
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+name+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Permission;
|
||||
import me.zhengjie.modules.system.repository.PermissionRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.PermissionMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "permission")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class PermissionQueryService {
|
||||
|
||||
@Autowired
|
||||
private PermissionRepository permissionRepository;
|
||||
|
||||
@Autowired
|
||||
private PermissionMapper permissionMapper;
|
||||
|
||||
/**
|
||||
* 不分页
|
||||
*/
|
||||
@Cacheable(key = "'queryAll:'+#p0")
|
||||
public List queryAll(String name){
|
||||
return permissionMapper.toDto(permissionRepository.findAll(new Spec(name)));
|
||||
}
|
||||
|
||||
class Spec implements Specification<Permission> {
|
||||
|
||||
private String name;
|
||||
|
||||
public Spec(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Permission> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(name)){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+name+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
import me.zhengjie.modules.system.service.mapper.RoleMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "role")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class RoleQueryService {
|
||||
|
||||
@Autowired
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(String name, Pageable pageable){
|
||||
Page<Role> page = roleRepository.findAll(new Spec(name),pageable);
|
||||
return PageUtil.toPage(page.map(roleMapper::toDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(Pageable pageable){
|
||||
List<Role> roles = roleRepository.findAll(new Spec(null),pageable).getContent();
|
||||
return roleMapper.toDto(roles);
|
||||
}
|
||||
|
||||
class Spec implements Specification<Role> {
|
||||
|
||||
private String name;
|
||||
|
||||
public Spec(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Role> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(name)){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("name").as(String.class),"%"+name+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.repository.UserRepository;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.UserMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import javax.persistence.criteria.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-11-22
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "user")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class UserQueryService {
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepo;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(UserDTO user, Set<Long> deptIds,Pageable pageable){
|
||||
Page<User> page = userRepo.findAll(new Spec(user,deptIds),pageable);
|
||||
return PageUtil.toPage(page.map(userMapper::toDto));
|
||||
}
|
||||
|
||||
|
||||
class Spec implements Specification<User> {
|
||||
|
||||
private UserDTO user;
|
||||
|
||||
private Set<Long> deptIds;
|
||||
|
||||
public Spec(UserDTO user, Set<Long> deptIds){
|
||||
this.deptIds = deptIds;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
// 数据权限, 关联查询
|
||||
Join<Dept,User> join = root.join("dept",JoinType.LEFT);
|
||||
if (!CollectionUtils.isEmpty(deptIds)) {
|
||||
list.add(join.get("id").in(deptIds));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(user.getId())){
|
||||
/**
|
||||
* 相等
|
||||
*/
|
||||
list.add(cb.equal(root.get("id").as(Long.class),user.getId()));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(user.getEnabled())){
|
||||
/**
|
||||
* 相等
|
||||
*/
|
||||
list.add(cb.equal(root.get("enabled").as(Boolean.class),user.getEnabled()));
|
||||
}
|
||||
|
||||
|
||||
if(!ObjectUtils.isEmpty(user.getUsername())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("username").as(String.class),"%"+user.getUsername()+"%"));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(user.getEmail())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("email").as(String.class),"%"+user.getEmail()+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,9 +8,6 @@
|
|||
<pattern>%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!--添加我们自定义的filter-->
|
||||
<filter class="me.zhengjie.modules.monitor.config.LogFilter"></filter>
|
||||
</appender>
|
||||
|
||||
<!--普通日志输出到控制台-->
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.zhengjie.rest;
|
|||
import me.zhengjie.aop.log.Log;
|
||||
import me.zhengjie.domain.Picture;
|
||||
import me.zhengjie.service.PictureService;
|
||||
import me.zhengjie.service.query.PictureQueryService;
|
||||
import me.zhengjie.service.dto.PictureQueryCriteria;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -26,14 +26,11 @@ public class PictureController {
|
|||
@Autowired
|
||||
private PictureService pictureService;
|
||||
|
||||
@Autowired
|
||||
private PictureQueryService pictureQueryService;
|
||||
|
||||
@Log("查询图片")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')")
|
||||
@GetMapping(value = "/pictures")
|
||||
public ResponseEntity getRoles(Picture resources, Pageable pageable){
|
||||
return new ResponseEntity(pictureQueryService.queryAll(resources,pageable),HttpStatus.OK);
|
||||
public ResponseEntity getRoles(PictureQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(pictureService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,7 @@ import me.zhengjie.aop.log.Log;
|
|||
import me.zhengjie.domain.QiniuConfig;
|
||||
import me.zhengjie.domain.QiniuContent;
|
||||
import me.zhengjie.service.QiNiuService;
|
||||
import me.zhengjie.service.query.QiNiuQueryService;
|
||||
import me.zhengjie.service.dto.QiniuQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -29,9 +29,6 @@ public class QiniuController {
|
|||
@Autowired
|
||||
private QiNiuService qiNiuService;
|
||||
|
||||
@Autowired
|
||||
private QiNiuQueryService qiNiuQueryService;
|
||||
|
||||
@GetMapping(value = "/qiNiuConfig")
|
||||
public ResponseEntity get(){
|
||||
return new ResponseEntity(qiNiuService.find(), HttpStatus.OK);
|
||||
|
@ -46,8 +43,8 @@ public class QiniuController {
|
|||
|
||||
@Log("查询文件")
|
||||
@GetMapping(value = "/qiNiuContent")
|
||||
public ResponseEntity getRoles(QiniuContent resources, Pageable pageable){
|
||||
return new ResponseEntity(qiNiuQueryService.queryAll(resources,pageable),HttpStatus.OK);
|
||||
public ResponseEntity getRoles(QiniuQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package me.zhengjie.service;
|
||||
|
||||
import me.zhengjie.domain.Picture;
|
||||
import me.zhengjie.service.dto.PictureQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-27
|
||||
|
@ -13,6 +14,15 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@CacheConfig(cacheNames = "picture")
|
||||
public interface PictureService {
|
||||
|
||||
/**
|
||||
* 查询图片
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @param file
|
||||
|
|
|
@ -2,10 +2,12 @@ package me.zhengjie.service;
|
|||
|
||||
import me.zhengjie.domain.QiniuConfig;
|
||||
import me.zhengjie.domain.QiniuContent;
|
||||
import me.zhengjie.service.dto.QiniuQueryCriteria;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
|
@ -15,6 +17,15 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@CacheConfig(cacheNames = "qiNiu")
|
||||
public interface QiNiuService {
|
||||
|
||||
/**
|
||||
* 查询文件
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查配置
|
||||
* @return
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* sm.ms图床
|
||||
*
|
||||
* @author jie
|
||||
* @date 2019-6-4 09:52:09
|
||||
*/
|
||||
@Data
|
||||
public class PictureQueryCriteria{
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String filename;
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String username;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-6-4 09:54:37
|
||||
*/
|
||||
@Data
|
||||
public class QiniuQueryCriteria{
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String key;
|
||||
}
|
|
@ -9,10 +9,10 @@ import me.zhengjie.domain.Picture;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.repository.PictureRepository;
|
||||
import me.zhengjie.service.PictureService;
|
||||
import me.zhengjie.utils.ElAdminConstant;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.service.dto.PictureQueryCriteria;
|
||||
import me.zhengjie.utils.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -39,6 +39,11 @@ public class PictureServiceImpl implements PictureService {
|
|||
|
||||
public static final String MSG = "msg";
|
||||
|
||||
@Override
|
||||
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
|
||||
return PageUtil.toPage(pictureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public Picture upload(MultipartFile multipartFile, String username) {
|
||||
|
|
|
@ -15,16 +15,15 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.repository.QiNiuConfigRepository;
|
||||
import me.zhengjie.repository.QiniuContentRepository;
|
||||
import me.zhengjie.service.QiNiuService;
|
||||
import me.zhengjie.utils.QiNiuUtil;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.service.dto.QiniuQueryCriteria;
|
||||
import me.zhengjie.utils.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -46,6 +45,11 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
|
||||
private final String TYPE = "公开";
|
||||
|
||||
@Override
|
||||
public Object queryAll(QiniuQueryCriteria criteria, Pageable pageable){
|
||||
return PageUtil.toPage(qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public QiniuConfig find() {
|
||||
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
package me.zhengjie.service.query;
|
||||
|
||||
import me.zhengjie.domain.Picture;
|
||||
import me.zhengjie.repository.PictureRepository;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "picture")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class PictureQueryService {
|
||||
|
||||
@Autowired
|
||||
private PictureRepository pictureRepository;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(Picture picture, Pageable pageable){
|
||||
return PageUtil.toPage(pictureRepository.findAll(new Spec(picture),pageable));
|
||||
}
|
||||
|
||||
class Spec implements Specification<Picture> {
|
||||
|
||||
private Picture picture;
|
||||
|
||||
public Spec(Picture picture){
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<Picture> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(picture.getFilename())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("filename").as(String.class),"%"+picture.getFilename()+"%"));
|
||||
}
|
||||
|
||||
if(!ObjectUtils.isEmpty(picture.getUsername())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("username").as(String.class),"%"+picture.getUsername()+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package me.zhengjie.service.query;
|
||||
|
||||
import me.zhengjie.domain.QiniuContent;
|
||||
import me.zhengjie.repository.QiniuContentRepository;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-12-31
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "qiNiu")
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class QiNiuQueryService {
|
||||
|
||||
@Autowired
|
||||
private QiniuContentRepository qiniuContentRepository;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(QiniuContent qiniuContent, Pageable pageable){
|
||||
return PageUtil.toPage(qiniuContentRepository.findAll(new Spec(qiniuContent),pageable));
|
||||
}
|
||||
|
||||
class Spec implements Specification<QiniuContent> {
|
||||
|
||||
private QiniuContent qiniuContent;
|
||||
|
||||
public Spec(QiniuContent qiniuContent){
|
||||
this.qiniuContent = qiniuContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<QiniuContent> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||||
|
||||
List<Predicate> list = new ArrayList<Predicate>();
|
||||
|
||||
if(!ObjectUtils.isEmpty(qiniuContent.getKey())){
|
||||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("key").as(String.class),"%"+qiniuContent.getKey()+"%"));
|
||||
}
|
||||
|
||||
Predicate[] p = new Predicate[list.size()];
|
||||
return cb.and(list.toArray(p));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue