|
|
@ -236,19 +236,8 @@ public class Controler { |
|
|
|
@ResponseBody |
|
|
|
public AppRet<Object> serviceActionExecute( @RequestBody Map<String, Object> params ) throws Throwable { |
|
|
|
String serviceKey = (String)params.get("serviceKey"); |
|
|
|
Class<?> serviceClass = null; |
|
|
|
var classes = UfClassHelper.getAllClassesInPackage("a8k"); |
|
|
|
for (var clazz : classes) { |
|
|
|
var hardwareServiceAnnotation = clazz.getAnnotation(HardwareService.class); |
|
|
|
if (null == hardwareServiceAnnotation || !clazz.getSimpleName().equals(serviceKey)) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
serviceClass = clazz; |
|
|
|
break; |
|
|
|
} |
|
|
|
if ( null == serviceClass ) { |
|
|
|
return AppRet.success(); |
|
|
|
} |
|
|
|
var service = this.getServiceInstanceByServiceKey(serviceKey); |
|
|
|
assert service != null; |
|
|
|
|
|
|
|
var actionName = (String)params.get("action"); |
|
|
|
var actionParams = (List<Object>)params.get("params"); |
|
|
@ -258,7 +247,7 @@ public class Controler { |
|
|
|
var name = actionParamTypes.get(i); |
|
|
|
parameterTypes[i] = Class.forName(name); |
|
|
|
} |
|
|
|
Method method = serviceClass.getMethod(actionName, parameterTypes); |
|
|
|
Method method = service.getClass().getMethod(actionName, parameterTypes); |
|
|
|
|
|
|
|
var parameters = method.getParameters(); |
|
|
|
for ( int i=0; i<parameters.length; i++ ) { |
|
|
@ -270,20 +259,30 @@ public class Controler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var service = UfApplication.getContext().getBean(serviceClass); |
|
|
|
Object actionResult = null; |
|
|
|
try { |
|
|
|
if ( method.getReturnType().equals(Void.TYPE) ) { |
|
|
|
method.invoke(service, actionParams.toArray()); |
|
|
|
return AppRet.success(); |
|
|
|
var actionParamList = actionParams.toArray(); |
|
|
|
|
|
|
|
var methodAnnotation = method.getAnnotation(HardwareServiceAction.class); |
|
|
|
var beforeExecute = methodAnnotation.beforeExecute(); |
|
|
|
if ( !beforeExecute.isEmpty() ) { |
|
|
|
var beforeExecuteMethod = service.getClass().getMethod(beforeExecute, new Class[]{Method.class, List.class}); |
|
|
|
beforeExecuteMethod.invoke(service, method, actionParams); |
|
|
|
} |
|
|
|
var actionResult = method.invoke(service, actionParams.toArray()); |
|
|
|
if ( actionResult instanceof AppRet ) { |
|
|
|
return (AppRet)actionResult; |
|
|
|
|
|
|
|
if ( method.getReturnType().equals(Void.TYPE) ) { |
|
|
|
method.invoke(service, actionParamList); |
|
|
|
} else { |
|
|
|
actionResult = method.invoke(service, actionParamList); |
|
|
|
} |
|
|
|
return AppRet.success(actionResult); |
|
|
|
} catch ( InvocationTargetException e ) { |
|
|
|
throw e.getTargetException(); |
|
|
|
} |
|
|
|
|
|
|
|
if ( actionResult instanceof AppRet ) { |
|
|
|
return (AppRet<Object>)actionResult; |
|
|
|
} |
|
|
|
return AppRet.success(actionResult); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/api/service-config/class-struct-info-get") |
|
|
@ -296,6 +295,24 @@ public class Controler { |
|
|
|
return AppRet.success(struct); |
|
|
|
} |
|
|
|
|
|
|
|
// get service instance by service key |
|
|
|
private Object getServiceInstanceByServiceKey( String serviceKey ) { |
|
|
|
Class<?> serviceClass = null; |
|
|
|
var classes = UfClassHelper.getAllClassesInPackage("a8k"); |
|
|
|
for (var clazz : classes) { |
|
|
|
var hardwareServiceAnnotation = clazz.getAnnotation(HardwareService.class); |
|
|
|
if (null == hardwareServiceAnnotation || !clazz.getSimpleName().equals(serviceKey)) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
serviceClass = clazz; |
|
|
|
break; |
|
|
|
} |
|
|
|
if ( null == serviceClass ) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return UfApplication.getContext().getBean(serviceClass); |
|
|
|
} |
|
|
|
|
|
|
|
// get service param handler by given service key |
|
|
|
private Object getServiceParamHandlerByServiceKey( String serviceKey ) { |
|
|
|
var classes = UfClassHelper.getAllClassesInPackage("a8k"); |
|
|
|