提交 e9a0b07f 编写于 作者: sq3536's avatar sq3536

反射

上级 bca585b2
package net.ibizsys.central.plugin.boot.core.domain;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.util.TypeUtils;
import com.baomidou.mybatisplus.annotation.TableField;
......@@ -183,15 +185,7 @@ public class BaseData implements IEntityDTO {
if(_allParamMap==null)
_allParamMap = new HashMap<>();
_allParamMap.clear();
_allParamMap.putAll(this.paramMap);
getMap().keySet().forEach(key->{
Object obj=getMap().get(key);
if(obj==null)
return;
if((!key.equals("map"))&&(!key.equals("_allParamMap"))&&(!key.equals("paramMap")))
_allParamMap.put(key.toString(),obj);
});
focusNull.forEach(item->_allParamMap.put(item,null));
_allParamMap.putAll(toMap());
return _allParamMap;
}
......@@ -776,8 +770,7 @@ public class BaseData implements IEntityDTO {
public Map<String, Object> toMap()
{
Map<String, Object> map = new HashMap<>();
map.putAll(this.paramMap);
map.putAll(this.getMap());
map.putAll((JSONObject)JSON.toJSON(this));
focusNull.forEach(item->map.put(item,null));
return map;
......
......@@ -19,6 +19,7 @@ import net.ibizsys.runtime.dataentity.service.DEMethodReturnTypes;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.util.Assert;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
......@@ -134,9 +135,19 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
if (method != null) {
Object rt = null;
if (iPSDEAction != null && iPSDEAction.getPSDEActionReturn() != null && DEMethodReturnTypes.VOID.equals(iPSDEAction.getPSDEActionReturn().getType()))
try{
method.invoke(this.getBaseService(), args[0]);
else
} catch (InvocationTargetException ex){
throw ex.getTargetException();
}
else {
try {
rt = method.invoke(this.getBaseService(), args[0]);
} catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
return rt;
}
}
......@@ -154,9 +165,20 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
if (method != null) {
Object rt = null;
if (iPSDEAction != null && iPSDEAction.getPSDEActionReturn() != null && DEMethodReturnTypes.VOID.equals(iPSDEAction.getPSDEActionReturn().getType()))
{
try {
method.invoke(this.getBaseService(), args[0]);
else
} catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
else {
try {
rt = method.invoke(this.getBaseService(), args[0]);
}catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
return rt;
}
......@@ -173,8 +195,13 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
if(args.length>0&&args[0]!=null) {
((F) args[0]).setDataSet(iPSDEDataSet);
Method method = getBaseService().getServiceMethod("fetch" + StringAdvUtils.pascalcase(strDataSetName), args[0].getClass());
if (method != null)
if (method != null) {
try {
return method.invoke(this.getBaseService(), args[0]);
}catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
}
return getBaseService().fetchDataSet(strDataSetName,iPSDEDataSet,args);
}
......@@ -188,8 +215,13 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
if(args.length>0&&args[0]!=null) {
((F) args[0]).setDataSet(iPSDEDataSet);
Method method = getBaseService().getServiceMethod("onFetch" + StringAdvUtils.pascalcase(strDataSetName), args[0].getClass());
if (method != null)
if (method != null) {
try {
return method.invoke(this.getBaseService(), args[0]);
}catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
}
return getBaseService().fetchDataSetReal(iDataEntityRuntimeContext, strDataSetName, iPSDEDataSet, args, actionData);
}
......
......@@ -11,6 +11,7 @@ import net.ibizsys.model.dataentity.action.IPSDEAction;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import org.springframework.data.domain.Page;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
......@@ -50,9 +51,13 @@ public interface IBaseService<T extends BaseData, F extends BaseFilter> {
}
default void beforeAction(String strActionName,Object arg) throws Throwable{
Method beforeMethod = getServiceMethod("before"+ StringAdvUtils.pascalcase(strActionName), arg.getClass());
try {
Method beforeMethod = getServiceMethod("before" + StringAdvUtils.pascalcase(strActionName), arg.getClass());
if (beforeMethod != null)
beforeMethod.invoke(this, arg);
}catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
default Object forwardAction(String strActionName,Object arg) throws Throwable{
......@@ -68,9 +73,13 @@ public interface IBaseService<T extends BaseData, F extends BaseFilter> {
}
default void afterAction(String strActionName,Object arg) throws Throwable{
Method afterMethod = getServiceMethod("after"+ StringAdvUtils.pascalcase(strActionName), arg.getClass());
try {
Method afterMethod = getServiceMethod("after" + StringAdvUtils.pascalcase(strActionName), arg.getClass());
if (afterMethod != null)
afterMethod.invoke(this, arg);
} catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
default Object fetchDataSet(String strDataSetName, IPSDEDataSet iPSDEDataSet, Object[] args) throws Throwable {
......@@ -78,9 +87,13 @@ public interface IBaseService<T extends BaseData, F extends BaseFilter> {
}
default void beforeFetch(String strActionName,Object arg) throws Throwable{
Method beforeMethod = getServiceMethod("beforeFetch"+ StringAdvUtils.pascalcase(strActionName), arg.getClass());
try {
Method beforeMethod = getServiceMethod("beforeFetch" + StringAdvUtils.pascalcase(strActionName), arg.getClass());
if (beforeMethod != null)
beforeMethod.invoke(this, arg);
} catch (InvocationTargetException ex){
throw ex.getTargetException();
}
}
default Object forwardFetch(String dsName,F arg) throws Throwable{
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册