规范拦截器

v1.4.1
Parker 4 years ago
parent a3dff6ff88
commit 89ab9bcb91

@ -23,7 +23,7 @@ import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.utils.Props;
import org.opsli.core.aspect.CacheDataAop;
import org.opsli.core.filters.aspect.CacheDataAop;
import org.opsli.plugins.cache.EhCachePlugin;
import org.opsli.plugins.redis.RedisPlugin;
import org.springframework.beans.factory.annotation.Autowired;

@ -16,10 +16,9 @@
package org.opsli.core.conf;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.opsli.core.conf.mybatis.AutoFillInterceptor;
import org.opsli.core.filters.interceptor.MybatisAutoFillInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@ -52,7 +51,7 @@ public class MyBatisPlusConfig {
*/
@Bean
public String myInterceptor(SqlSessionFactory sqlSessionFactory) {
sqlSessionFactory.getConfiguration().addInterceptor(new AutoFillInterceptor());
sqlSessionFactory.getConfiguration().addInterceptor(new MybatisAutoFillInterceptor());
return "interceptor";
}

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;

@ -13,9 +13,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.TypeUtil;
import cn.hutool.crypto.asymmetric.RSA;
@ -35,8 +37,10 @@ import org.opsli.core.utils.EncryptAndDecryptByRsaUtil;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import static org.opsli.common.constants.OrderConstants.ENCRYPT_ADN_DECRYPT_AOP_SORT;
@ -130,7 +134,22 @@ public class InterfaceEncryptAndDecryptAop {
// 根据方法类型转化对象
Type type = TypeUtil.getParamType(method, i);
args[i] = Convert.convert(type, dataToObj);
Object obj = Convert.convert(type, dataToObj);
// 修改缓存中设备数据 空值不覆盖
Map<String, Object> modelBeanMap = BeanUtil.beanToMap(obj);
modelBeanMap.entrySet().removeIf(entry -> entry.getValue() == null);
// 反射赋值
Field[] fields = ReflectUtil.getFields(arg.getClass());
for (Field f : fields) {
Object val = modelBeanMap.get(f.getName());
if(val == null){
continue;
}
//根据需要,将相关属性赋上默认值
BeanUtil.setProperty(arg, f.getName(), val);
}
}
}
}

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import lombok.extern.slf4j.Slf4j;

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import cn.hutool.core.convert.Convert;
import lombok.extern.slf4j.Slf4j;

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.aspect;
package org.opsli.core.filters.aspect;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.conf.mybatis;
package org.opsli.core.filters.interceptor;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
@ -46,11 +46,13 @@ import java.util.*;
* SQL
*
* https://www.cnblogs.com/qingshan-tang/p/13299701.html
*
* @author Parker
*/
@Component
@Slf4j
@Intercepts(@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}))
public class AutoFillInterceptor implements Interceptor {
public class MybatisAutoFillInterceptor implements Interceptor {
private static final String ET = "et";
@ -104,7 +106,6 @@ public class AutoFillInterceptor implements Interceptor {
Date currDate = DateUtil.date();
Field[] fields = ReflectUtil.getFields(arg.getClass());
for (Field f : fields) {
f.setAccessible(true);
switch (f.getName()) {
// 创建人
case MyBatisConstants.FIELD_CREATE_BY:
@ -150,7 +151,6 @@ public class AutoFillInterceptor implements Interceptor {
default:
break;
}
f.setAccessible(false);
}
}
@ -179,7 +179,6 @@ public class AutoFillInterceptor implements Interceptor {
}
fields = ReflectUtil.getFields(arg.getClass());
for (Field f : fields) {
f.setAccessible(true);
switch (f.getName()) {
// 更新人
case MyBatisConstants.FIELD_UPDATE_BY:
@ -196,7 +195,6 @@ public class AutoFillInterceptor implements Interceptor {
default:
break;
}
f.setAccessible(false);
}
}

@ -32,7 +32,7 @@ import org.opsli.common.exception.TokenException;
import org.opsli.common.thread.refuse.AsyncProcessQueueReFuse;
import org.opsli.common.utils.IPUtil;
import org.opsli.common.utils.OutputStreamUtil;
import org.opsli.core.aspect.InterfaceEncryptAndDecryptAop;
import org.opsli.core.filters.aspect.InterfaceEncryptAndDecryptAop;
import org.opsli.core.msg.TokenMsg;
import org.opsli.core.security.shiro.realm.JwtRealm;
import org.opsli.core.utils.*;

Loading…
Cancel
Save