|
|
@ -40,28 +40,13 @@ public class Controler { |
|
|
|
public AppRet<Object> serviceParams( @RequestBody Map<String, Object> params ) |
|
|
|
throws InvocationTargetException, IllegalAccessException { |
|
|
|
String serviceKey = (String)params.get("serviceKey"); |
|
|
|
Class<?> paramClass = null; |
|
|
|
var classes = UfClassHelper.getAllClassesInPackage("a8k"); |
|
|
|
for (var clazz : classes) { |
|
|
|
var hardwareServiceParamsAnnotation = clazz.getAnnotation(HardwareServiceParams.class); |
|
|
|
if (null == hardwareServiceParamsAnnotation) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
var serviceClass = hardwareServiceParamsAnnotation.service(); |
|
|
|
if (!serviceClass.getSimpleName().equals(serviceKey)) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
paramClass = clazz; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
var paramService = this.getServiceParamHandlerByServiceKey(serviceKey); |
|
|
|
List<Map<String,Object>> list = new ArrayList<>(); |
|
|
|
if ( null == paramClass ) { |
|
|
|
if ( null == paramService ) { |
|
|
|
return AppRet.success(list); |
|
|
|
} |
|
|
|
|
|
|
|
var paramService = UfApplication.getContext().getBean(paramClass); |
|
|
|
var methods = paramClass.getMethods(); |
|
|
|
var methods = paramService.getClass().getMethods(); |
|
|
|
for ( var method : methods ) { |
|
|
|
var methodName = method.getName(); |
|
|
|
if ( !methodName.startsWith("get") ) { |
|
|
@ -88,12 +73,39 @@ public class Controler { |
|
|
|
public AppRet<Object> serviceParamsUpdate( @RequestBody Map<String, Object> params ) throws Exception { |
|
|
|
String serviceKey = (String)params.get("serviceKey"); |
|
|
|
Map<String,Object> newParams = (Map<String,Object>)params.get("params"); |
|
|
|
|
|
|
|
var paramService = this.getServiceParamHandlerByServiceKey(serviceKey); |
|
|
|
assert paramService != null; |
|
|
|
var paramServiceClass = paramService.getClass(); |
|
|
|
for ( var param : newParams.entrySet() ) { |
|
|
|
var name = param.getKey(); |
|
|
|
var value = param.getValue(); |
|
|
|
var options = HardwareServiceSetting.getOption(serviceKey, name); |
|
|
|
options.setValue(value); |
|
|
|
options.save(); |
|
|
|
|
|
|
|
var setterName = String.format("set%s", name); |
|
|
|
var methods = paramServiceClass.getMethods(); |
|
|
|
var isSetterHasBeenFound = false; |
|
|
|
for ( var method : methods ) { |
|
|
|
if ( !setterName.equals(method.getName()) || 1 < method.getParameterTypes().length ) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
var setParam = method.getParameters()[0]; |
|
|
|
if ( !setParam.getType().isAssignableFrom(value.getClass())) { |
|
|
|
if ( !(value instanceof Map) ) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
var objValue = MyClassHelper.initializeByMap(setParam.getType(), (Map<String, Object>)value); |
|
|
|
method.invoke(paramService, objValue); |
|
|
|
} else { |
|
|
|
method.invoke(paramService, value); |
|
|
|
} |
|
|
|
isSetterHasBeenFound = true; |
|
|
|
} |
|
|
|
|
|
|
|
if ( !isSetterHasBeenFound ) { |
|
|
|
var options = HardwareServiceSetting.getOption(serviceKey, name); |
|
|
|
options.setValue(value); |
|
|
|
options.save(); |
|
|
|
} |
|
|
|
} |
|
|
|
return AppRet.success(); |
|
|
|
} |
|
|
@ -172,6 +184,10 @@ public class Controler { |
|
|
|
var actionParam = new HashMap<String, Object>(); |
|
|
|
actionParam.put("key", param.getName()); |
|
|
|
actionParam.put("type", param.getType().getName()); |
|
|
|
actionParam.put("value", null); |
|
|
|
if ( param.getType().equals(Boolean.class) ) { |
|
|
|
actionParam.put("value", false); |
|
|
|
} |
|
|
|
if ( param.getType().isEnum() ) { |
|
|
|
actionParam.put("type", "Enum"); |
|
|
|
actionParam.put("typeEnum", param.getType().getName()); |
|
|
@ -257,6 +273,23 @@ public class Controler { |
|
|
|
return AppRet.success(struct); |
|
|
|
} |
|
|
|
|
|
|
|
// get service param handler by given service key |
|
|
|
private Object getServiceParamHandlerByServiceKey( String serviceKey ) { |
|
|
|
var classes = UfClassHelper.getAllClassesInPackage("a8k"); |
|
|
|
for (var clazz : classes) { |
|
|
|
var hardwareServiceParamsAnnotation = clazz.getAnnotation(HardwareServiceParams.class); |
|
|
|
if (null == hardwareServiceParamsAnnotation) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
var serviceClass = hardwareServiceParamsAnnotation.service(); |
|
|
|
if (!serviceClass.getSimpleName().equals(serviceKey)) { |
|
|
|
continue ; |
|
|
|
} |
|
|
|
return UfApplication.getContext().getBean(clazz); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
// fill up struct info |
|
|
|
private void classStructInfoFill( Class<?> clazz, List<Map<String,Object>> struct ) { |
|
|
|
var fields = clazz.getFields(); |
|
|
|