mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 18:46:36 +08:00
commit:VO支持以及bug修复
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.orange.demo.common.core.advice;
|
||||
|
||||
import com.orange.demo.common.core.exception.InvalidClassFieldException;
|
||||
import com.orange.demo.common.core.exception.InvalidDataFieldException;
|
||||
import com.orange.demo.common.core.exception.InvalidDataModelException;
|
||||
import com.orange.demo.common.core.exception.*;
|
||||
import com.orange.demo.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.demo.common.core.exception.RedisCacheAccessException;
|
||||
import com.orange.demo.common.core.object.ResponseResult;
|
||||
@@ -113,6 +111,19 @@ public class MyExceptionHandler {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_ACCESS_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作不存在或已逻辑删除数据的异常处理方法。
|
||||
*
|
||||
* @param ex 异常对象。
|
||||
* @param request http请求。
|
||||
* @return 应答对象。
|
||||
*/
|
||||
@ExceptionHandler(value = NoDataAffectException.class)
|
||||
public ResponseResult<Void> noDataEffectExceptionHandle(Exception ex, HttpServletRequest request) {
|
||||
log.error("NoDataAffectException exception from URL [" + request.getRequestURI() + "]", ex);
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis缓存访问异常处理方法。
|
||||
*
|
||||
|
||||
@@ -125,7 +125,7 @@ public abstract class BaseDictService<M, K> extends BaseService<M, K> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> boolean existUniqueKeyList(String inFilterField, Set<T> inFilterValues) {
|
||||
if (CollectionUtils.isEmpty(inFilterValues)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (inFilterField.equals(this.idFieldName)) {
|
||||
List<M> dataList = dictionaryCache.getInList((Set<K>) inFilterValues);
|
||||
|
||||
@@ -20,6 +20,7 @@ import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
@@ -169,7 +170,7 @@ public abstract class BaseService<M, K> {
|
||||
}
|
||||
Example e = new Example(modelClass);
|
||||
e.createCriteria().andEqualTo(fieldName, fieldValue);
|
||||
return mapper().selectByExample(e).size() == 1;
|
||||
return mapper().selectCountByExample(e) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +264,7 @@ public abstract class BaseService<M, K> {
|
||||
*/
|
||||
public boolean existAllPrimaryKeys(Set<K> idSet) {
|
||||
if (CollectionUtils.isEmpty(idSet)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return this.existUniqueKeyList(idFieldName, idSet);
|
||||
}
|
||||
@@ -277,7 +278,7 @@ public abstract class BaseService<M, K> {
|
||||
*/
|
||||
public <T> boolean existUniqueKeyList(String inFilterField, Set<T> inFilterValues) {
|
||||
if (CollectionUtils.isEmpty(inFilterValues)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
Example e = this.makeDefaultInListExample(inFilterField, inFilterValues, null);
|
||||
if (deletedFlagFieldName != null) {
|
||||
@@ -450,20 +451,21 @@ public abstract class BaseService<M, K> {
|
||||
int modifiers = field.getModifiers();
|
||||
// transient类型的字段不能作为查询条件
|
||||
int transientMask = 128;
|
||||
if ((modifiers & transientMask) == 0) {
|
||||
if (field.getName().equals(deletedFlagFieldName)) {
|
||||
c.andEqualTo(deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
} else {
|
||||
ReflectUtil.setAccessible(field);
|
||||
try {
|
||||
Object o = field.get(filter);
|
||||
if (o != null) {
|
||||
c.andEqualTo(field.getName(), field.get(filter));
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
log.error("Failed to call reflection code of BaseService.getListByFilter.", ex);
|
||||
throw new MyRuntimeException(ex);
|
||||
if ((modifiers & transientMask) != 0 || Modifier.isStatic(modifiers)) {
|
||||
return;
|
||||
}
|
||||
if (field.getName().equals(deletedFlagFieldName)) {
|
||||
c.andEqualTo(deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
} else {
|
||||
ReflectUtil.setAccessible(field);
|
||||
try {
|
||||
Object o = field.get(filter);
|
||||
if (o != null) {
|
||||
c.andEqualTo(field.getName(), field.get(filter));
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
log.error("Failed to call reflection code of BaseService.getListByFilter.", ex);
|
||||
throw new MyRuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -492,10 +494,14 @@ public abstract class BaseService<M, K> {
|
||||
*/
|
||||
public List<M> getListByParentId(String parentIdFieldName, K parentId) {
|
||||
Example e = new Example(modelClass);
|
||||
Example.Criteria c = e.createCriteria();
|
||||
if (parentId != null) {
|
||||
e.createCriteria().andEqualTo(parentIdFieldName, parentId);
|
||||
c.andEqualTo(parentIdFieldName, parentId);
|
||||
} else {
|
||||
e.createCriteria().andIsNull(parentIdFieldName);
|
||||
c.andIsNull(parentIdFieldName);
|
||||
}
|
||||
if (deletedFlagFieldName != null) {
|
||||
c.andEqualTo(deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
}
|
||||
return mapper().selectByExample(e);
|
||||
}
|
||||
|
||||
@@ -88,10 +88,12 @@ public class SessionCacheHelper {
|
||||
|
||||
/**
|
||||
* 清除当前session的所有缓存数据。
|
||||
*
|
||||
* @param sessionId 当前会话的SessionId。
|
||||
*/
|
||||
public void removeAllSessionCache() {
|
||||
public void removeAllSessionCache(String sessionId) {
|
||||
for (CacheConfig.CacheEnum c : CacheConfig.CacheEnum.values()) {
|
||||
cacheManager.getCache(c.name()).clear();
|
||||
cacheManager.getCache(c.name()).evict(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ public enum ErrorCodeEnum {
|
||||
INVALID_USERNAME_PASSWORD("用户名或密码错误,请重试!"),
|
||||
INVALID_ACCESS_TOKEN("无效的用户访问令牌!"),
|
||||
INVALID_USER_STATUS("用户状态错误,请刷新后重试!"),
|
||||
INVALID_TENANT_CODE("指定的租户编码并不存在,请刷新后重试!"),
|
||||
INVALID_TENANT_STATUS("当前租户为不可用状态,请刷新后重试!"),
|
||||
INVALID_USER_TENANT("当前用户并不属于当前租户,请刷新后重试!"),
|
||||
|
||||
HAS_CHILDREN_DATA("数据验证失败,子数据存在,请刷新后重试!"),
|
||||
DATA_VALIDATED_FAILED("数据验证失败,请核对!"),
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.orange.demo.common.core.object;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -11,6 +14,8 @@ import java.util.List;
|
||||
* @date 2020-09-24
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MyPageData<T> {
|
||||
/**
|
||||
* 数据列表。
|
||||
@@ -20,4 +25,12 @@ public class MyPageData<T> {
|
||||
* 数据总数量。
|
||||
*/
|
||||
private Long totalCount;
|
||||
|
||||
/**
|
||||
* 为了保持前端的数据格式兼容性,在没有数据的时候,需要返回空分页对象。
|
||||
* @return 空分页对象。
|
||||
*/
|
||||
public static <T> MyPageData<T> emptyPageData() {
|
||||
return new MyPageData<>(new LinkedList<>(), 0L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import javax.persistence.Column;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
@@ -414,6 +415,9 @@ public class MyModelUtil {
|
||||
Function<R, Object> thatIdGetterFunc,
|
||||
String thisRelationField,
|
||||
boolean orderByThatList) {
|
||||
if (CollectionUtils.isEmpty(thisModelList)) {
|
||||
return;
|
||||
}
|
||||
Field thisTargetField = ReflectUtil.getField(thisClazz, thisRelationField);
|
||||
boolean isMap = thisTargetField.getType().equals(Map.class);
|
||||
if (orderByThatList) {
|
||||
@@ -463,12 +467,12 @@ public class MyModelUtil {
|
||||
Example.Criteria c = e.createCriteria();
|
||||
Field[] fields = ReflectUtil.getFields(modelClass);
|
||||
for (Field field : fields) {
|
||||
if (field.getAnnotation(Transient.class) != null) {
|
||||
continue;
|
||||
}
|
||||
int modifiers = field.getModifiers();
|
||||
// transient类型的字段不能作为查询条件
|
||||
if ((modifiers & 128) == 0) {
|
||||
if (field.getAnnotation(Transient.class) == null) {
|
||||
int modifiers = field.getModifiers();
|
||||
// transient类型的字段不能作为查询条件
|
||||
if ((modifiers & 128) != 0 || Modifier.isStatic(modifiers)) {
|
||||
continue;
|
||||
}
|
||||
ReflectUtil.setAccessible(field);
|
||||
try {
|
||||
Object o = field.get(filterModel);
|
||||
|
||||
@@ -3,7 +3,10 @@ package com.orange.demo.common.core.util;
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.Page;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import com.orange.demo.common.core.base.mapper.BaseModelMapper;
|
||||
import com.orange.demo.common.core.object.MyPageData;
|
||||
import com.orange.demo.common.core.object.Tuple2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -65,6 +68,38 @@ public class MyPageUtil {
|
||||
return pageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户构建带有分页信息的数据列表。
|
||||
*
|
||||
* @param dataList 实体对象数据列表。
|
||||
* @param modelMapper 实体对象到DomainVO对象的数据映射器。
|
||||
* @param <D> DomainVO对象类型。
|
||||
* @param <T> 实体对象类型。
|
||||
* @return 返回分页数据对象。
|
||||
*/
|
||||
public static <D, T> MyPageData<D> makeResponseData(List<T> dataList, BaseModelMapper<D, T> modelMapper) {
|
||||
long totalCount = 0L;
|
||||
if (CollectionUtils.isEmpty(dataList)) {
|
||||
// 这里需要构建分页数据对象,统一前端数据格式
|
||||
return MyPageData.emptyPageData();
|
||||
}
|
||||
if (dataList instanceof Page) {
|
||||
totalCount = ((Page<T>) dataList).getTotal();
|
||||
}
|
||||
return MyPageUtil.makeResponseData(modelMapper.fromModelList(dataList), totalCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户构建带有分页信息的数据列表。
|
||||
*
|
||||
* @param responseData 第一个数据时数据列表,第二个是列表数量。
|
||||
* @param <T> 源数据类型。
|
||||
* @return 返回分页数据对象。
|
||||
*/
|
||||
public static <T> MyPageData<T> makeResponseData(Tuple2<List<T>, Long> responseData) {
|
||||
return makeResponseData(responseData.getFirst(), responseData.getSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有构造函数,明确标识该常量类的作用。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user