提交 0f5782d5 作者: 925993793@qq.com

测试bug修改

上级 d4a0d3b8
package com.zzsn.thinktank.config;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.MapperMethod.ParamMap;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.util.*;
/**
* mybatis拦截器,自动注入创建人、创建时间、修改人、修改时间
*
* @Author scott
* @Date 2019-01-19
*/
@Slf4j
@Component
@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
public class MybatisInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
String sqlId = mappedStatement.getId();
log.debug("------sqlId------" + sqlId);
SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
Object parameter = invocation.getArgs()[1];
log.debug("------sqlCommandType------" + sqlCommandType);
if (parameter == null) {
return invocation.proceed();
}
Date date = new Date();
if (SqlCommandType.INSERT == sqlCommandType) {
Field[] fields = getAllFields(parameter);
for (Field field : fields) {
String fieldName = field.getName();
// 注入创建时间
if ("createTime".equals(fieldName)) {
field.setAccessible(true);
Object localCreateDate = field.get(parameter);
field.setAccessible(false);
if (localCreateDate == null || localCreateDate.equals("")) {
changeData(field, parameter, date);
}
}
}
}
if (SqlCommandType.UPDATE == sqlCommandType) {
Field[] fields;
if (parameter instanceof ParamMap) {
ParamMap<?> p = (ParamMap<?>) parameter;
if (p.containsKey("et")) {
parameter = p.get("et");
} else {
parameter = p.get("param1");
}
if (parameter == null) {
return invocation.proceed();
}
fields = getAllFields(parameter);
} else {
fields = getAllFields(parameter);
}
for (Field field : fields) {
String fieldName = field.getName();
log.debug("------field.name------" + fieldName);
if ("updateTime".equals(fieldName)) {
changeData(field, parameter, date);
}
}
}
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
}
//修改对应字段的值
private void changeData(Field field, Object parameter,Object data){
try {
field.setAccessible(true);
field.set(parameter,data);
field.setAccessible(false);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private Field[] getAllFields(Object object) {
Class<?> clazz = object.getClass();
List<Field> fieldList = new ArrayList<>();
while (clazz != null) {
fieldList.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields())));
clazz = clazz.getSuperclass();
}
Field[] fields = new Field[fieldList.size()];
fieldList.toArray(fields);
return fields;
}
}
......@@ -143,12 +143,12 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
return ;
}
if (sourceBindType == 1) {
//解绑通用信息源组
//解绑通用信息源栏目
unBindInfoSource(bindVO, BindTypeEnum.INFO_SOURCE_GROUP.getvalue());
}
if (sourceBindType == 2) {
//解绑定向信息源
unBindInfoSource(bindVO,BindTypeEnum.DIRECTIONA_INFO_SOURCE_GROUP.getvalue());
if (sourceBindType == 3) {
//解绑屏蔽信息源栏目
unBindInfoSource(bindVO,BindTypeEnum.EXCLUDE_INFO_SOURCE_GROUP.getvalue());
}
}
private void unBindInfoSourceColumn(BindVO bindVO) {
......@@ -158,12 +158,12 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
return ;
}
if (sourceBindType == 1) {
//解绑通用信息源
//解绑通用信息源栏目
unBindInfoSource(bindVO, BindTypeEnum.INFO_SOURCE.getvalue());
}
if (sourceBindType == 2) {
//解绑定向信息源组
unBindInfoSource(bindVO,BindTypeEnum.DIRECTIONA_INFO_SOURCE.getvalue());
if (sourceBindType == 3) {
//解绑屏蔽信息源栏目
unBindInfoSource(bindVO,BindTypeEnum.EXCLUDE_INFO_SOURCE.getvalue());
}
}
......@@ -177,9 +177,9 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
//解绑通用信息源组
unBindInfoSource(bindVO, BindTypeEnum.INFO_MAIN_SOURCE_GROUP.getvalue());
}
if (sourceBindType == 2) {
//解绑定向信息源组
unBindInfoSource(bindVO,BindTypeEnum.DIRECTIONA_MAIN_INFO_SOURCE_GROUP.getvalue());
if (sourceBindType == 3) {
//解绑屏蔽信息源组
unBindInfoSource(bindVO,BindTypeEnum.EXCLUDE_MAIN_INFO_SOURCE_GROUP.getvalue());
}
}
private void unBindInfoSource(BindVO bindVO) {
......@@ -192,9 +192,9 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
//解绑通用信息源
unBindInfoSource(bindVO, BindTypeEnum.INFO_MAIN_SOURCE.getvalue());
}
if (sourceBindType == 2) {
//解绑定向信息源
unBindInfoSource(bindVO,BindTypeEnum.DIRECTIONA_MAIN_INFO_SOURCE.getvalue());
if (sourceBindType == 3) {
//解绑屏蔽信息源
unBindInfoSource(bindVO,BindTypeEnum.EXCLUDE_MAIN_INFO_SOURCE.getvalue());
}
}
......@@ -205,12 +205,12 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
return ;
}
if (sourceBindType == 1) {
//解绑通用标签
//解绑通用信息源栏目标签
unBindLabel(bindVO, BindTypeEnum.INFO_SOURCE_LABEL.getvalue());
}
if (sourceBindType == 2) {
//解绑定向标签
unBindLabel(bindVO, BindTypeEnum.DIRECTIONA_INFO_SOURCE_LABEL.getvalue());
if (sourceBindType == 3) {
//解绑屏蔽信息源栏目标签
unBindLabel(bindVO, BindTypeEnum.EXCLUDE_INFO_SOURCE_LABEL.getvalue());
}
}
private void unBindInfoSourceLabels(BindVO bindVO) {
......@@ -220,12 +220,12 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
return ;
}
if (sourceBindType == 1) {
//解绑通用标签
//解绑通用信息源标签
unBindLabel(bindVO, BindTypeEnum.INFO_SOURCE_MAIN_LABEL.getvalue());
}
if (sourceBindType == 2) {
//解绑定向标签
unBindLabel(bindVO, BindTypeEnum.DIRECTIONA_INFO_MAIN_SOURCE_LABEL.getvalue());
if (sourceBindType == 3) {
//解绑屏蔽信息源标签
unBindLabel(bindVO, BindTypeEnum.EXCLUDE_INFO_MAIN_SOURCE_LABEL.getvalue());
}
}
......@@ -239,9 +239,9 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
//绑定通用信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.INFO_SOURCE_GROUP.getvalue());
}
if (sourceBindType == 2) {
//绑定定向信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.DIRECTIONA_INFO_SOURCE_GROUP.getvalue());
if (sourceBindType == 3) {
//绑定屏蔽信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.EXCLUDE_INFO_SOURCE_GROUP.getvalue());
}
}
......@@ -255,9 +255,9 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
//绑定通用信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.INFO_SOURCE.getvalue());
}
if (sourceBindType == 2) {
//绑定定向信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.DIRECTIONA_INFO_SOURCE.getvalue());
if (sourceBindType == 3) {
//绑定屏蔽信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.EXCLUDE_INFO_SOURCE.getvalue());
}
}
......@@ -269,12 +269,12 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
return;
}
if (sourceBindType == 1) {
//绑定通用标签信息源
//绑定通用信息源栏目标签
bindLabels(thinkTankId, bindLabels, BindTypeEnum.INFO_SOURCE_LABEL.getvalue());
}
if (sourceBindType == 2) {
//绑定定向标签信息源
bindLabels(thinkTankId, bindLabels, BindTypeEnum.DIRECTIONA_INFO_SOURCE_LABEL.getvalue());
if (sourceBindType == 3) {
//绑定屏蔽信息源栏目标签
bindLabels(thinkTankId, bindLabels, BindTypeEnum.EXCLUDE_INFO_SOURCE_LABEL.getvalue());
}
}
......@@ -286,12 +286,12 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
return;
}
if (sourceBindType == 1) {
//绑定通用标签信息源
//绑定通用信息源标签
bindLabels(thinkTankId, bindLabels, BindTypeEnum.INFO_SOURCE_MAIN_LABEL.getvalue());
}
if (sourceBindType == 2) {
//绑定定向标签信息源
bindLabels(thinkTankId, bindLabels, BindTypeEnum.DIRECTIONA_INFO_MAIN_SOURCE_LABEL.getvalue());
if (sourceBindType == 3) {
//绑定屏蔽信息源标签
bindLabels(thinkTankId, bindLabels, BindTypeEnum.EXCLUDE_INFO_MAIN_SOURCE_LABEL.getvalue());
}
}
......@@ -305,9 +305,9 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
//绑定通用信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.INFO_MAIN_SOURCE_GROUP.getvalue());
}
if (sourceBindType == 2) {
//绑定定向信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.DIRECTIONA_MAIN_INFO_SOURCE_GROUP.getvalue());
if (sourceBindType == 3) {
//绑定屏蔽信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.EXCLUDE_MAIN_INFO_SOURCE_GROUP.getvalue());
}
}
......@@ -321,9 +321,9 @@ public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMa
//绑定通用信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.INFO_MAIN_SOURCE.getvalue());
}
if (sourceBindType == 2) {
//绑定定向信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.DIRECTIONA_MAIN_INFO_SOURCE.getvalue());
if (sourceBindType == 3) {
//绑定屏蔽信息源组
bindInfoSource(bindVO, idList, BindTypeEnum.EXCLUDE_MAIN_INFO_SOURCE.getvalue());
}
}
......
......@@ -19,7 +19,7 @@ public class BindVO {
private List<String> bindIds;
//信息源标签
private List<BindLabelVo> bindLabels;
//绑定类型类型(1:通用 2:定向)
//绑定类型类型(1:通用 2:定向 3:屏蔽
private Integer sourceBindType;
//信息源类型(1:信息源栏目组 2:信息源栏目 3:信息源栏目标签 4:信息源组 5:信息源 6:信息源标签)
private Integer sourceType;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论