提交 613fe641 编写于 作者: ibiz4j's avatar ibiz4j

接口实体适配

上级 b3b08247
...@@ -131,6 +131,7 @@ public class BaseData implements IEntityDTO { ...@@ -131,6 +131,7 @@ public class BaseData implements IEntityDTO {
} }
else { else {
focusNull.remove(field); focusNull.remove(field);
paramMap.remove(field+"dirtyflag");
} }
} }
...@@ -275,14 +276,14 @@ public class BaseData implements IEntityDTO { ...@@ -275,14 +276,14 @@ public class BaseData implements IEntityDTO {
} }
public boolean containsKey(String strName) { public boolean containsKey(String strName) {
if(getFocusNull().contains(strName)) if(focusNull.contains(strName))
return true; return true;
String fieldRealName= FieldCache.getFieldRealName(this.getClass(),strName); FieldCache.FieldItem fieldItem= FieldCache.getField(this.getClass(),strName);
if(!StringUtils.isEmpty(fieldRealName)) { if(!StringUtils.isEmpty(fieldItem.getCodeName())) {
if(getFocusNull().contains(strName)) if(focusNull.contains(fieldItem.getJsonName()))
return true; return true;
return getMap().get(fieldRealName)!=null; return getMap().get(fieldItem.getCodeName())!=null;
} }
else { else {
return this.paramMap.containsKey(strName); return this.paramMap.containsKey(strName);
...@@ -404,10 +405,11 @@ public class BaseData implements IEntityDTO { ...@@ -404,10 +405,11 @@ public class BaseData implements IEntityDTO {
} }
public void resetObject(String strName) { public void resetObject(String strName) {
String fieldRealName= FieldCache.getFieldRealName(this.getClass(),strName); FieldCache.FieldItem fieldItem= FieldCache.getField(this.getClass(),strName);
if(!StringUtils.isEmpty(fieldRealName)) { if(fieldItem!=null&&(!StringUtils.isEmpty(fieldItem.getCodeName()))) {
getMap().put(fieldRealName,null); getMap().put(fieldItem.getCodeName(),null);
focusNull.remove(fieldRealName); focusNull.remove(fieldItem.getJsonName());
paramMap.remove(fieldItem.getJsonName()+"dirtyflag");
} }
else { else {
this.paramMap.remove(strName); this.paramMap.remove(strName);
......
...@@ -28,14 +28,12 @@ import java.util.Map; ...@@ -28,14 +28,12 @@ import java.util.Map;
public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends DEServiceBase implements IBootService<T,F> { public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends DEServiceBase implements IBootService<T,F> {
private Class<T> tClass;
private Class<F> fClass;
@Override @Override
public T createEntityDTO(IPSDEMethodDTO iPSDEMethodDTO) { public T createEntityDTO(IPSDEMethodDTO iPSDEMethodDTO) {
if(iPSDEMethodDTO!=null&&iPSDEMethodDTO.getName()!=null&&iPSDEMethodDTO.getName().endsWith("DTO")) { if(iPSDEMethodDTO!=null&&iPSDEMethodDTO.getName()!=null&&iPSDEMethodDTO.getName().endsWith("DTO")) {
try { try {
T t = (T) tClass.newInstance(); T t = (T) this.getBaseService().getTClass().newInstance();
return t; return t;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -47,7 +45,7 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D ...@@ -47,7 +45,7 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
@Override @Override
public F createSearchContextDTO(IPSDEMethodDTO iPSDEMethodDTO) { public F createSearchContextDTO(IPSDEMethodDTO iPSDEMethodDTO) {
try { try {
F f = (F) fClass.newInstance(); F f = (F) this.getBaseService().getFClass().newInstance();
return f; return f;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -97,25 +95,7 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D ...@@ -97,25 +95,7 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
return; return;
this.baseService = baseService; this.baseService = baseService;
this.setDataEntityId(baseService.getDataEntityId()); this.setDataEntityId(baseService.getDataEntityId());
Class serviceClass=baseService.getClass();
while (serviceClass!=null) {
if(!ObjectUtils.isEmpty(serviceClass.getInterfaces())) {
Class interfaceClass=serviceClass.getInterfaces()[0];
if(!ObjectUtils.isEmpty(interfaceClass.getInterfaces())) {
if(interfaceClass.getInterfaces()[0].isAssignableFrom(IBaseService.class)
||interfaceClass.getInterfaces()[0].isAssignableFrom(IMPService.class)) {
serviceClass=interfaceClass;
break;
}
}
}
serviceClass = serviceClass.getSuperclass();
}
if(!ObjectUtils.isEmpty(serviceClass.getGenericInterfaces())) {
ParameterizedType ptype = (ParameterizedType) serviceClass.getGenericInterfaces()[0];
tClass = (Class) ptype.getActualTypeArguments()[0];
fClass = (Class) ptype.getActualTypeArguments()[1];
}
} }
public IBaseService getBaseService(){ public IBaseService getBaseService(){
return baseService; return baseService;
......
...@@ -36,6 +36,10 @@ public interface IBaseService<T extends BaseData, F extends BaseFilter> { ...@@ -36,6 +36,10 @@ public interface IBaseService<T extends BaseData, F extends BaseFilter> {
Method getServiceMethod(String name, Class clazz); Method getServiceMethod(String name, Class clazz);
Class<T> getTClass();
Class<F> getFClass();
default IDataEntityRuntimeContext getDataEntityRuntimeContext() { default IDataEntityRuntimeContext getDataEntityRuntimeContext() {
return getRuntimeService().getDataEntityRuntimeContext(); return getRuntimeService().getDataEntityRuntimeContext();
} }
......
package net.ibizsys.central.plugin.boot.core.service; package net.ibizsys.central.plugin.boot.core.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.util.TypeUtils;
import net.ibizsys.central.dataentity.IDataEntityRuntime; import net.ibizsys.central.dataentity.IDataEntityRuntime;
import net.ibizsys.central.dataentity.IDataEntityRuntimeContext; import net.ibizsys.central.dataentity.IDataEntityRuntimeContext;
import net.ibizsys.central.plugin.boot.core.domain.BaseData; import net.ibizsys.central.plugin.boot.core.domain.BaseData;
...@@ -7,9 +11,15 @@ import net.ibizsys.central.plugin.boot.core.filter.BaseFilter; ...@@ -7,9 +11,15 @@ import net.ibizsys.central.plugin.boot.core.filter.BaseFilter;
import net.ibizsys.central.plugin.boot.core.helper.StringAdvUtils; import net.ibizsys.central.plugin.boot.core.helper.StringAdvUtils;
import net.ibizsys.central.plugin.boot.core.runtime.IBootService; import net.ibizsys.central.plugin.boot.core.runtime.IBootService;
import net.ibizsys.central.plugin.boot.core.runtime.IBootSystemRuntime; import net.ibizsys.central.plugin.boot.core.runtime.IBootSystemRuntime;
import net.ibizsys.central.service.client.IWebClientRep;
import net.ibizsys.central.util.IEntityDTO;
import net.ibizsys.central.util.PageRequest;
import net.ibizsys.model.dataentity.action.IPSDEAction; import net.ibizsys.model.dataentity.action.IPSDEAction;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet; import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import net.ibizsys.runtime.util.DataTypeUtils;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.util.Assert;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
...@@ -20,48 +30,111 @@ import java.util.List; ...@@ -20,48 +30,111 @@ import java.util.List;
public interface IServiceApiService<T extends BaseData, F extends BaseFilter> extends IBaseService<T,F>{ public interface IServiceApiService<T extends BaseData, F extends BaseFilter> extends IBaseService<T,F>{
default void beforeAction(String strActionName,Object arg) throws Throwable{
if(arg.getClass().isAssignableFrom(getTClass())) {
T data=((T)arg);
data.getFocusNull().forEach(item->{
data.setObject(item+"dirtyflag",1);
});
data.setObject("dirtyflagenable",1);
}
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 onRealAction(String strActionName,Object arg) throws Throwable{ default Object onRealAction(String strActionName,Object arg) throws Throwable{
return this.getDataEntityRuntimeContext().executeActionReal(strActionName, null, new Object[]{arg}, null); return onRealAction(strActionName,arg,getTClass());
} }
default <K> List<K> onRealActionList(String strActionName,Object arg,Class<K> clazz) throws Throwable{
default Object onRealFetch(String dsName,F arg) throws Throwable{ Object obj = this.getDataEntityRuntimeContext().executeActionReal(strActionName, null, new Object[]{arg}, null);
return this.getDataEntityRuntimeContext().fetchDataSetReal("DEFAULT", arg.getDataSet(), new Object[]{arg}, null); if(obj instanceof IWebClientRep) {
String body=((IWebClientRep<String>)obj).getBody();
Assert.hasText(body,String.format("[{}]接口服务返回为空",strActionName));
return JSON.parseArray(body,clazz);
}
return (List<K>)obj;
} }
default <K> K onRealAction(String strActionName,Object arg,Class<K> clazz) throws Throwable{
Object obj = this.getDataEntityRuntimeContext().executeActionReal(strActionName, null, new Object[]{arg}, null);
if(obj instanceof IWebClientRep) {
String body=((IWebClientRep<String>)obj).getBody();
Assert.hasText(body,String.format("[{}]接口服务返回为空",strActionName));
K ret = JSON.parseObject(body,clazz);
if(arg.getClass().isAssignableFrom(getTClass())&&clazz.isAssignableFrom(getTClass()))
((T) arg).reload(((T)ret).any(), true);
}
return (K)obj;
}
default Object onRealFetch(String dsName,F arg) throws Throwable{
return onRealFetchPage(dsName,arg);
}
default <K extends Serializable> T onGet(K key) throws Throwable { default List<T> onRealSearch(String dsName,F arg) throws Throwable{
return (T)onRealAction("Get",key); Object obj = this.getRuntimeService().getDataEntityRuntime().selectDataQuery(dsName, arg);
if(obj instanceof IWebClientRep) {
IWebClientRep<String> rep=(IWebClientRep)obj;
Assert.hasText(rep.getBody(),String.format("[{}]查询服务返回为空",dsName));
JSON json=(JSON)JSON.parse(rep.getBody());
if(json instanceof JSONArray) {
return JSON.parseArray(rep.getBody(),getTClass());
}
else if(json instanceof JSONObject){
if(((JSONObject) json).containsKey("content"))
return JSON.parseArray(JSON.toJSONString(((JSONObject) json).getJSONArray("content")),getTClass());
}
}
return (List)obj;
} }
default Page<T> onRealFetchPage(String dsName,F arg) throws Throwable{
Object obj = this.getDataEntityRuntimeContext().fetchDataSetReal("DEFAULT", arg.getDataSet(), new Object[]{arg}, null);
if(obj instanceof IWebClientRep) {
IWebClientRep<String> rep=(IWebClientRep)obj;
Assert.hasText(rep.getBody(),String.format("[{}]查询服务返回为空",dsName));
JSON json=(JSON)JSON.parse(rep.getBody());
if(json instanceof JSONArray) {
Long nTotal = DataTypeUtils.getLongValue(rep.getHeader("x-total"), 0L);
return new PageImpl(JSON.parseArray(rep.getBody(),getTClass()), arg.getPageable(), nTotal);
}
else if(json instanceof JSONObject){
Long nTotal=DataTypeUtils.getLongValue(((JSONObject) json).getLongValue("totalElements"), 0L);
return new PageImpl(JSON.parseArray(JSON.toJSONString(((JSONObject) json).getJSONArray("content")),getTClass()), arg.getPageable(), nTotal);
}
}
return (Page)obj;
}
default T onGetDraft(T dto) throws Throwable { default T onGetDraft(T dto) throws Throwable {
return (T)onRealAction("GetDraft",dto); return (T)onRealAction("GetDraft",dto);
} }
default Integer onCheckKey(T dto) throws Throwable { default Integer onCheckKey(T dto) throws Throwable {
return (Integer) onRealAction("CheckKey",dto); return onRealAction("CheckKey",dto,Integer.class);
} }
default Page<T> onFetchDefault(F dto) throws Throwable { default Page<T> onFetchDefault(F dto) throws Throwable {
return (Page) onRealFetch("DEFAULT",dto); return onRealFetchPage("DEFAULT",dto);
} }
default List<T> selectDefault(F dto) throws Throwable { default List<T> selectDefault(F dto) throws Throwable {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("DEFAULT", dto); return onRealSearch("DEFAULT", dto);
} }
default List<T> selectSimple(F dto) throws Throwable { default List<T> selectSimple(F dto) throws Throwable {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("SIMPLE", dto); return onRealSearch("SIMPLE", dto);
} }
default List<T> selectView(F dto) throws Throwable { default List<T> selectView(F dto) throws Throwable {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("VIEW", dto); return onRealSearch("VIEW", dto);
} }
} }
...@@ -5,13 +5,19 @@ import net.ibizsys.central.plugin.boot.core.filter.BaseFilter; ...@@ -5,13 +5,19 @@ import net.ibizsys.central.plugin.boot.core.filter.BaseFilter;
import net.ibizsys.central.plugin.boot.core.runtime.BootServiceImpl; import net.ibizsys.central.plugin.boot.core.runtime.BootServiceImpl;
import net.ibizsys.central.plugin.boot.core.runtime.IBootService; import net.ibizsys.central.plugin.boot.core.runtime.IBootService;
import net.ibizsys.central.plugin.boot.core.service.IBaseService; import net.ibizsys.central.plugin.boot.core.service.IBaseService;
import net.ibizsys.central.plugin.boot.core.service.IMPService;
import net.ibizsys.central.plugin.boot.core.service.IServiceApiService;
import org.apache.commons.lang3.ObjectUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public abstract class BaseServiceImpl<T extends BaseData, F extends BaseFilter> implements IBaseService<T, F> { public abstract class BaseServiceImpl<T extends BaseData, F extends BaseFilter> implements IBaseService<T, F> {
private IBootService runtimeService; private IBootService runtimeService;
@Override @Override
public IBootService getRuntimeService(){ public IBootService getRuntimeService(){
...@@ -24,9 +30,41 @@ public abstract class BaseServiceImpl<T extends BaseData, F extends BaseFilter> ...@@ -24,9 +30,41 @@ public abstract class BaseServiceImpl<T extends BaseData, F extends BaseFilter>
@PostConstruct @PostConstruct
private void postConstruct() throws Exception { private void postConstruct() throws Exception {
Class serviceClass=this.getClass();
while (serviceClass!=null) {
if(!ObjectUtils.isEmpty(serviceClass.getInterfaces())) {
Class interfaceClass=serviceClass.getInterfaces()[0];
if(!ObjectUtils.isEmpty(interfaceClass.getInterfaces())) {
if(interfaceClass.getInterfaces()[0].isAssignableFrom(IBaseService.class)
||interfaceClass.getInterfaces()[0].isAssignableFrom(IMPService.class)
||interfaceClass.getInterfaces()[0].isAssignableFrom(IServiceApiService.class)) {
serviceClass=interfaceClass;
break;
}
}
}
serviceClass = serviceClass.getSuperclass();
}
if(!ObjectUtils.isEmpty(serviceClass.getGenericInterfaces())) {
ParameterizedType ptype = (ParameterizedType) serviceClass.getGenericInterfaces()[0];
tClass = (Class) ptype.getActualTypeArguments()[0];
fClass = (Class) ptype.getActualTypeArguments()[1];
}
runtimeService = new BootServiceImpl<T,F>(this); runtimeService = new BootServiceImpl<T,F>(this);
} }
private Class<T> tClass;
private Class<F> fClass;
public Class<T> getTClass() {
return tClass;
}
public Class<F> getFClass() {
return fClass;
}
private Object lockMethods = new Object(); private Object lockMethods = new Object();
private Map<String, Method> serviceMethods=new HashMap<>(); private Map<String, Method> serviceMethods=new HashMap<>();
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册