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

接口实体适配

上级 b3b08247
......@@ -131,6 +131,7 @@ public class BaseData implements IEntityDTO {
}
else {
focusNull.remove(field);
paramMap.remove(field+"dirtyflag");
}
}
......@@ -275,14 +276,14 @@ public class BaseData implements IEntityDTO {
}
public boolean containsKey(String strName) {
if(getFocusNull().contains(strName))
if(focusNull.contains(strName))
return true;
String fieldRealName= FieldCache.getFieldRealName(this.getClass(),strName);
if(!StringUtils.isEmpty(fieldRealName)) {
if(getFocusNull().contains(strName))
FieldCache.FieldItem fieldItem= FieldCache.getField(this.getClass(),strName);
if(!StringUtils.isEmpty(fieldItem.getCodeName())) {
if(focusNull.contains(fieldItem.getJsonName()))
return true;
return getMap().get(fieldRealName)!=null;
return getMap().get(fieldItem.getCodeName())!=null;
}
else {
return this.paramMap.containsKey(strName);
......@@ -404,10 +405,11 @@ public class BaseData implements IEntityDTO {
}
public void resetObject(String strName) {
String fieldRealName= FieldCache.getFieldRealName(this.getClass(),strName);
if(!StringUtils.isEmpty(fieldRealName)) {
getMap().put(fieldRealName,null);
focusNull.remove(fieldRealName);
FieldCache.FieldItem fieldItem= FieldCache.getField(this.getClass(),strName);
if(fieldItem!=null&&(!StringUtils.isEmpty(fieldItem.getCodeName()))) {
getMap().put(fieldItem.getCodeName(),null);
focusNull.remove(fieldItem.getJsonName());
paramMap.remove(fieldItem.getJsonName()+"dirtyflag");
}
else {
this.paramMap.remove(strName);
......
......@@ -28,14 +28,12 @@ import java.util.Map;
public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends DEServiceBase implements IBootService<T,F> {
private Class<T> tClass;
private Class<F> fClass;
@Override
public T createEntityDTO(IPSDEMethodDTO iPSDEMethodDTO) {
if(iPSDEMethodDTO!=null&&iPSDEMethodDTO.getName()!=null&&iPSDEMethodDTO.getName().endsWith("DTO")) {
try {
T t = (T) tClass.newInstance();
T t = (T) this.getBaseService().getTClass().newInstance();
return t;
} catch (Exception e) {
e.printStackTrace();
......@@ -47,7 +45,7 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
@Override
public F createSearchContextDTO(IPSDEMethodDTO iPSDEMethodDTO) {
try {
F f = (F) fClass.newInstance();
F f = (F) this.getBaseService().getFClass().newInstance();
return f;
} catch (Exception e) {
e.printStackTrace();
......@@ -97,25 +95,7 @@ public class BootServiceImpl<T extends BaseData, F extends BaseFilter> extends D
return;
this.baseService = baseService;
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(){
return baseService;
......
......@@ -36,6 +36,10 @@ public interface IBaseService<T extends BaseData, F extends BaseFilter> {
Method getServiceMethod(String name, Class clazz);
Class<T> getTClass();
Class<F> getFClass();
default IDataEntityRuntimeContext getDataEntityRuntimeContext() {
return getRuntimeService().getDataEntityRuntimeContext();
}
......
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.IDataEntityRuntimeContext;
import net.ibizsys.central.plugin.boot.core.domain.BaseData;
......@@ -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.runtime.IBootService;
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.ds.IPSDEDataSet;
import net.ibizsys.runtime.util.DataTypeUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.util.Assert;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
......@@ -20,48 +30,111 @@ import java.util.List;
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{
return this.getDataEntityRuntimeContext().executeActionReal(strActionName, null, new Object[]{arg}, null);
return onRealAction(strActionName,arg,getTClass());
}
default Object onRealFetch(String dsName,F arg) throws Throwable{
return this.getDataEntityRuntimeContext().fetchDataSetReal("DEFAULT", arg.getDataSet(), new Object[]{arg}, null);
default <K> List<K> onRealActionList(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));
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 {
return (T)onRealAction("Get",key);
default List<T> onRealSearch(String dsName,F arg) throws Throwable{
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 {
return (T)onRealAction("GetDraft",dto);
}
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 {
return (Page) onRealFetch("DEFAULT",dto);
return onRealFetchPage("DEFAULT",dto);
}
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 {
return (List)this.getRuntimeService().getDataEntityRuntime().selectDataQuery("SIMPLE", dto);
return onRealSearch("SIMPLE", dto);
}
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;
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.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 java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
public abstract class BaseServiceImpl<T extends BaseData, F extends BaseFilter> implements IBaseService<T, F> {
private IBootService runtimeService;
@Override
public IBootService getRuntimeService(){
......@@ -24,9 +30,41 @@ public abstract class BaseServiceImpl<T extends BaseData, F extends BaseFilter>
@PostConstruct
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);
}
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 Map<String, Method> serviceMethods=new HashMap<>();
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册