8 changed files with 88 additions and 409 deletions
@ -1,32 +0,0 @@ |
|||||
package io.sc.engine.rule.server.common.controller; |
|
||||
|
|
||||
import io.sc.engine.rule.server.common.service.AutoCompletionService; |
|
||||
import io.sc.engine.rule.server.common.service.support.AutoCompletion; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.web.bind.annotation.GetMapping; |
|
||||
import org.springframework.web.bind.annotation.PathVariable; |
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||
import org.springframework.web.bind.annotation.RestController; |
|
||||
|
|
||||
import java.util.Locale; |
|
||||
|
|
||||
@RestController("io.sc.engine.rule.server.common.controller.AutoCompletionWebController") |
|
||||
@RequestMapping("/api/re/common") |
|
||||
public class AutoCompletionWebController { |
|
||||
@Autowired private AutoCompletionService service; |
|
||||
|
|
||||
@GetMapping("autoCompletionByParameterId/{parameterId}") |
|
||||
public AutoCompletion autoCompletionByParameterId(@PathVariable(name="parameterId",required=true)String parameterId, Locale locale) throws Exception{ |
|
||||
return service.autoCompletionByParameterId(parameterId,locale); |
|
||||
} |
|
||||
|
|
||||
@GetMapping("autoCompletionByIndicatorId/{indicatorId}") |
|
||||
public AutoCompletion autoCompletionByIndicatorId(@PathVariable(name="indicatorId",required=true)String indicatorId, Locale locale) throws Exception{ |
|
||||
return service.autoCompletionByIndicatorId(indicatorId,locale); |
|
||||
} |
|
||||
|
|
||||
@GetMapping("autoCompletionByDictionaryId/{dictionaryId}") |
|
||||
public AutoCompletion autoCompletionByDictionaryId(@PathVariable(name="dictionaryId",required=true)String dictionaryId, Locale locale) throws Exception{ |
|
||||
return service.autoCompletionByDictionaryId(dictionaryId,locale); |
|
||||
} |
|
||||
} |
|
@ -1,11 +0,0 @@ |
|||||
package io.sc.engine.rule.server.common.service; |
|
||||
|
|
||||
import io.sc.engine.rule.server.common.service.support.AutoCompletion; |
|
||||
|
|
||||
import java.util.Locale; |
|
||||
|
|
||||
public interface AutoCompletionService { |
|
||||
public AutoCompletion autoCompletionByParameterId(String parameterId, Locale locale) throws Exception; |
|
||||
public AutoCompletion autoCompletionByIndicatorId(String indicatorId, Locale locale) throws Exception; |
|
||||
public AutoCompletion autoCompletionByDictionaryId(String dictionaryId, Locale locale) throws Exception; |
|
||||
} |
|
@ -1,323 +0,0 @@ |
|||||
package io.sc.engine.rule.server.common.service.impl; |
|
||||
|
|
||||
import io.sc.engine.rule.core.enums.DictionaryType; |
|
||||
import io.sc.engine.rule.core.enums.EnumDictionaryItemValueType; |
|
||||
import io.sc.engine.rule.core.util.IdReplacer; |
|
||||
import io.sc.engine.rule.core.util.ValueTypeUtil; |
|
||||
import io.sc.engine.rule.server.common.service.AutoCompletionService; |
|
||||
import io.sc.engine.rule.server.common.service.DictionaryItemPluginsService; |
|
||||
import io.sc.engine.rule.server.common.service.support.*; |
|
||||
import io.sc.engine.rule.server.dictionary.entity.*; |
|
||||
import io.sc.engine.rule.server.dictionary.service.DictionaryService; |
|
||||
import io.sc.engine.rule.server.lib.entity.IndicatorEntity; |
|
||||
import io.sc.engine.rule.server.lib.entity.IndicatorLibEntity; |
|
||||
import io.sc.engine.rule.server.lib.service.IndicatorService; |
|
||||
import io.sc.engine.rule.server.lib.service.LibService; |
|
||||
import io.sc.engine.rule.server.model.entity.ModelEntity; |
|
||||
import io.sc.engine.rule.server.model.entity.ParameterEntity; |
|
||||
import io.sc.engine.rule.server.model.entity.parameter.OutParameterEntity; |
|
||||
import io.sc.engine.rule.server.model.service.ParameterProcessorService; |
|
||||
import io.sc.engine.rule.server.model.service.ParameterService; |
|
||||
import io.sc.engine.rule.server.common.plugins.item.DictionaryItem; |
|
||||
import io.sc.platform.util.CollectionUtil; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.context.MessageSource; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.springframework.util.StringUtils; |
|
||||
|
|
||||
import java.lang.reflect.Field; |
|
||||
import java.util.List; |
|
||||
import java.util.Locale; |
|
||||
|
|
||||
@Service("io.sc.engine.rule.server.common.service.impl.AutoCompletionServiceImpl") |
|
||||
public class AutoCompletionServiceImpl implements AutoCompletionService { |
|
||||
@Autowired private ParameterProcessorService parameterProcessorService; |
|
||||
@Autowired private ParameterService parameterService; |
|
||||
@Autowired private LibService libService; |
|
||||
@Autowired private IndicatorService indicatorService; |
|
||||
@Autowired private DictionaryService dictionaryService; |
|
||||
@Autowired private MessageSource messageSource; |
|
||||
@Autowired private DictionaryItemPluginsService dictionaryItemPluginsService; |
|
||||
|
|
||||
@Override |
|
||||
public AutoCompletion autoCompletionByParameterId(String parameterId, Locale locale) throws Exception { |
|
||||
if(!StringUtils.hasText(parameterId)){ |
|
||||
return null; |
|
||||
} |
|
||||
ParameterEntity parameterEntity =parameterService.findById(parameterId); |
|
||||
if(parameterEntity==null){ |
|
||||
return null; |
|
||||
} |
|
||||
ModelEntity modelEntity =parameterEntity.getModel(); |
|
||||
if(modelEntity==null){ |
|
||||
return null; |
|
||||
} |
|
||||
AutoCompletion autoCompletion =new AutoCompletion(); |
|
||||
buildEnumParameters(autoCompletion); |
|
||||
buildEnumValueTypes(autoCompletion); |
|
||||
buildAutoCompletion(autoCompletion,modelEntity,locale); |
|
||||
return autoCompletion; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public AutoCompletion autoCompletionByIndicatorId(String indicatorId, Locale locale) throws Exception { |
|
||||
if(!StringUtils.hasText(indicatorId)){ |
|
||||
return null; |
|
||||
} |
|
||||
IndicatorLibEntity indicatorLibEntity =libService.findByIndicatorId(indicatorId); |
|
||||
if(indicatorLibEntity==null){ |
|
||||
return null; |
|
||||
} |
|
||||
AutoCompletion autoCompletion =new AutoCompletion(); |
|
||||
buildEnumParameters(autoCompletion); |
|
||||
buildEnumValueTypes(autoCompletion); |
|
||||
buildAutoCompletion(autoCompletion,indicatorLibEntity,locale); |
|
||||
return autoCompletion; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public AutoCompletion autoCompletionByDictionaryId(String dictionaryId, Locale locale) throws Exception { |
|
||||
if(!StringUtils.hasText(dictionaryId)){ |
|
||||
return null; |
|
||||
} |
|
||||
UserDefinedJavaClassDictionaryEntity dictionaryEntity =dictionaryService.getRepository().findUserDefinedJavaClassDictionaryEntityById(dictionaryId); |
|
||||
if(dictionaryEntity==null){ |
|
||||
return null; |
|
||||
} |
|
||||
AutoCompletion autoCompletion =new AutoCompletion(); |
|
||||
buildEnumParameters(autoCompletion); |
|
||||
buildEnumValueTypes(autoCompletion); |
|
||||
buildAutoCompletion(autoCompletion,dictionaryEntity,locale); |
|
||||
return autoCompletion; |
|
||||
} |
|
||||
|
|
||||
private void buildAutoCompletion(AutoCompletion autoCompletion,ModelEntity modelEntity, Locale locale) throws Exception{ |
|
||||
//子模型结果值参数作为本模型输入值参数
|
|
||||
List<OutParameterEntity> subModelOutParameters =parameterService.findOutParameterEntitiesOfSubModels(modelEntity.getId()); |
|
||||
if(subModelOutParameters!=null && subModelOutParameters.size()>0) { |
|
||||
for(OutParameterEntity entity : subModelOutParameters) { |
|
||||
Parameter parameter =new Parameter(); |
|
||||
parameter.setCode(entity.getCode()); |
|
||||
parameter.setName(entity.getName()); |
|
||||
parameter.setValueType(entity.getValueType()); |
|
||||
parameter.setValueTypeVersion(entity.getValueTypeVersion()); |
|
||||
parameter.setValueTypeIsList(entity.getValueTypeIsList()); |
|
||||
autoCompletion.addParameter(parameter); |
|
||||
buildValueType(autoCompletion,entity.getValueType(),entity.getValueTypeVersion(),locale); |
|
||||
} |
|
||||
} |
|
||||
//本模型其他参数
|
|
||||
List<ParameterEntity> parameterEntities =modelEntity.getParameters(); |
|
||||
if(parameterEntities!=null && parameterEntities.size()>0) { |
|
||||
for(ParameterEntity entity : parameterEntities) { |
|
||||
Parameter parameter =new Parameter(); |
|
||||
parameter.setCode(entity.getCode()); |
|
||||
parameter.setName(entity.getName()); |
|
||||
parameter.setValueType(entity.getValueType()); |
|
||||
parameter.setValueTypeVersion(entity.getValueTypeVersion()); |
|
||||
parameter.setValueTypeIsList(entity.getValueTypeIsList()); |
|
||||
autoCompletion.addParameter(parameter); |
|
||||
buildValueType(autoCompletion,entity.getValueType(),entity.getValueTypeVersion(),locale); |
|
||||
} |
|
||||
} |
|
||||
//父模型参数
|
|
||||
ModelEntity parentModelEntity =modelEntity.getParent(); |
|
||||
while(parentModelEntity!=null){ |
|
||||
List<ParameterEntity> parentParameterEntities =parentModelEntity.getParameters(); |
|
||||
if(CollectionUtil.hasElements(parentParameterEntities)){ |
|
||||
for(ParameterEntity entity : parentParameterEntities) { |
|
||||
switch(entity.getType()) { |
|
||||
case CONSTANT: |
|
||||
case IN_OPTION: |
|
||||
case IN: |
|
||||
case INDICATOR: |
|
||||
Parameter parameter =new Parameter(); |
|
||||
parameter.setCode(entity.getCode()); |
|
||||
parameter.setName(entity.getName()); |
|
||||
parameter.setValueType(entity.getValueType()); |
|
||||
parameter.setValueTypeVersion(entity.getValueTypeVersion()); |
|
||||
parameter.setValueTypeIsList(entity.getValueTypeIsList()); |
|
||||
autoCompletion.addParameter(parameter); |
|
||||
buildValueType(autoCompletion,entity.getValueType(),entity.getValueTypeVersion(),locale); |
|
||||
break; |
|
||||
default: |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
parentModelEntity =parentModelEntity.getParent(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void buildAutoCompletion(AutoCompletion autoCompletion,IndicatorLibEntity indicatorLibEntity, Locale locale) throws Exception{ |
|
||||
if(indicatorLibEntity==null){ |
|
||||
return; |
|
||||
} |
|
||||
List<IndicatorEntity> indicators =indicatorLibEntity.getIndicators(); |
|
||||
if(indicators==null || indicators.isEmpty()){ |
|
||||
return; |
|
||||
} |
|
||||
for(IndicatorEntity entity : indicators) { |
|
||||
Parameter parameter =new Parameter(); |
|
||||
parameter.setCode(entity.getCode()); |
|
||||
parameter.setName(entity.getName()); |
|
||||
parameter.setValueType(entity.getValueType()); |
|
||||
parameter.setValueTypeVersion(entity.getValueTypeVersion()); |
|
||||
parameter.setValueTypeIsList(entity.getValueTypeIsList()); |
|
||||
autoCompletion.addParameter(parameter); |
|
||||
buildValueType(autoCompletion,entity.getValueType(),entity.getValueTypeVersion(),locale); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void buildAutoCompletion(AutoCompletion autoCompletion,UserDefinedJavaClassDictionaryEntity dictionaryEntity, Locale locale) throws Exception{ |
|
||||
if(dictionaryEntity==null){ |
|
||||
return; |
|
||||
} |
|
||||
List<UserDefinedJavaClassFieldEntity> fields =dictionaryEntity.getFields(); |
|
||||
if(fields==null || fields.isEmpty()){ |
|
||||
return; |
|
||||
} |
|
||||
for(UserDefinedJavaClassFieldEntity entity : fields) { |
|
||||
Parameter parameter =new Parameter(); |
|
||||
parameter.setCode(entity.getCode()); |
|
||||
parameter.setName(entity.getName()); |
|
||||
parameter.setValueType(entity.getValueType()); |
|
||||
parameter.setValueTypeVersion(entity.getValueTypeVersion()); |
|
||||
parameter.setValueTypeIsList(entity.getValueTypeIsList()); |
|
||||
autoCompletion.addParameter(parameter); |
|
||||
buildValueType(autoCompletion,entity.getValueType(),entity.getValueTypeVersion(),locale); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void buildValueType(AutoCompletion autoCompletion,String valueTypeCode, Integer valueTypeVersion, Locale locale) throws Exception{ |
|
||||
if(dictionaryItemPluginsService.contains(valueTypeCode)){ |
|
||||
// 引擎内置类型
|
|
||||
DictionaryItem item =dictionaryItemPluginsService.getByCode(valueTypeCode); |
|
||||
if(DictionaryType.JAVA_CLASS.equals(item.getType())){ |
|
||||
buildJavaClassValueTypes(autoCompletion,item.getCode(),item.getCode(),messageSource.getMessage(item.getCode(),null,locale),item.getVersion(),locale); |
|
||||
} |
|
||||
}else{ |
|
||||
// 用户自定义结构体
|
|
||||
DictionaryEntity dictionaryEntity =dictionaryService.findDictionaryByCodeAndVersion(valueTypeCode,valueTypeVersion); |
|
||||
if(dictionaryEntity!=null && dictionaryEntity instanceof UserDefinedJavaClassDictionaryEntity){ |
|
||||
UserDefinedJavaClassDictionaryEntity userDefinedJavaClassDictionaryEntity =(UserDefinedJavaClassDictionaryEntity)dictionaryEntity; |
|
||||
ValueType valueType =new ValueType(); |
|
||||
valueType.setCode(userDefinedJavaClassDictionaryEntity.getCode()); |
|
||||
valueType.setName(userDefinedJavaClassDictionaryEntity.getName()); |
|
||||
valueType.setVersion(userDefinedJavaClassDictionaryEntity.getVersion()); |
|
||||
List<UserDefinedJavaClassFieldEntity> fieldEntities =userDefinedJavaClassDictionaryEntity.getFields(); |
|
||||
if(CollectionUtil.hasElements(fieldEntities)){ |
|
||||
for(UserDefinedJavaClassFieldEntity fieldEntity : fieldEntities){ |
|
||||
Property property =new Property(); |
|
||||
property.setCode(fieldEntity.getCode()); |
|
||||
property.setName(fieldEntity.getName()); |
|
||||
property.setValueType(fieldEntity.getValueType()); |
|
||||
property.setValueTypeVersion(fieldEntity.getValueTypeVersion()); |
|
||||
valueType.addProperty(property); |
|
||||
buildValueType(autoCompletion, property.getValueType(), property.getValueTypeVersion(), locale); |
|
||||
} |
|
||||
} |
|
||||
autoCompletion.addValueType(valueType); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void buildEnumParameters(AutoCompletion autoCompletion){ |
|
||||
List<EnumDictionaryEntity> enumDictionaryEntities =dictionaryService.getRepository().findAllEnumDictionaryEntities(); |
|
||||
if(CollectionUtil.hasElements(enumDictionaryEntities)){ |
|
||||
for(EnumDictionaryEntity enumDictionary : enumDictionaryEntities){ |
|
||||
Parameter parameter =new Parameter(); |
|
||||
parameter.setCode(IdReplacer.className(enumDictionary.getCode(),enumDictionary.getVersion())); |
|
||||
parameter.setName(enumDictionary.getName()); |
|
||||
parameter.setType("enum"); |
|
||||
parameter.setValueType(enumDictionary.getCode()); |
|
||||
parameter.setValueTypeVersion(enumDictionary.getVersion()); |
|
||||
parameter.setValueTypeIsList(false); |
|
||||
autoCompletion.addParameter(parameter); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void buildEnumValueTypes(AutoCompletion autoCompletion){ |
|
||||
List<EnumDictionaryEntity> enumDictionaryEntities =dictionaryService.getRepository().findAllEnumDictionaryEntities(); |
|
||||
if(CollectionUtil.hasElements(enumDictionaryEntities)){ |
|
||||
for(EnumDictionaryEntity enumDictionary : enumDictionaryEntities){ |
|
||||
ValueType valueType =new ValueType(); |
|
||||
valueType.setCode(enumDictionary.getCode()); |
|
||||
valueType.setName(enumDictionary.getName()); |
|
||||
valueType.setVersion(enumDictionary.getVersion()); |
|
||||
List<EnumItemEntity> items =enumDictionary.getItems(); |
|
||||
if(CollectionUtil.hasElements(items)){ |
|
||||
for(EnumItemEntity item : items){ |
|
||||
Property property =new Property(); |
|
||||
property.setCode(item.getCode()); |
|
||||
property.setName(item.getName()); |
|
||||
property.setType("enum"); |
|
||||
if(EnumDictionaryItemValueType.STRING.equals(item.getValueType())){ |
|
||||
property.setValueType("java.lang.String"); |
|
||||
}else if(EnumDictionaryItemValueType.INTEGER.equals(item.getValueType())){ |
|
||||
property.setValueType("java.lang.Long"); |
|
||||
}else if(EnumDictionaryItemValueType.DECIMAL.equals(item.getValueType())){ |
|
||||
property.setValueType("java.math.BigDecimal"); |
|
||||
} |
|
||||
valueType.addProperty(property); |
|
||||
} |
|
||||
} |
|
||||
autoCompletion.addValueType(valueType); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void buildJavaClassValueTypes(AutoCompletion autoCompletion,String className,String valueTypeCode, String valueTypeName,Integer valueTypeVersion,Locale locale) throws Exception { |
|
||||
Class<?> clazz =Class.forName(className); |
|
||||
buildJavaClassValueTypes(autoCompletion,clazz,valueTypeCode,valueTypeName,valueTypeVersion,locale); |
|
||||
} |
|
||||
|
|
||||
private void buildJavaClassValueTypes(AutoCompletion autoCompletion,Class<?> clazz,String valueTypeCode, String valueTypeName,Integer valueTypeVersion,Locale locale) throws Exception { |
|
||||
if(ValueTypeUtil.isBase(clazz) || ValueTypeUtil.isEnum(clazz)) { |
|
||||
ValueType valueType =new ValueType(); |
|
||||
valueType.setCode(clazz.getName()); |
|
||||
valueType.setName(messageSource.getMessage(clazz.getName(),null,locale)); |
|
||||
valueType.setVersion(null); |
|
||||
autoCompletion.addValueType(valueType); |
|
||||
return; |
|
||||
} |
|
||||
ValueType valueType =new ValueType(); |
|
||||
valueType.setCode(StringUtils.hasText(valueTypeCode)?valueTypeCode:clazz.getName()); |
|
||||
valueType.setName(StringUtils.hasText(valueTypeName)?valueTypeName:messageSource.getMessage(clazz.getName(), new Object[]{}, clazz.getName(), locale)); |
|
||||
valueType.setVersion(valueTypeVersion); |
|
||||
autoCompletion.addValueType(valueType); |
|
||||
|
|
||||
Field[] fields =clazz.getDeclaredFields(); |
|
||||
for(Field field : fields){ |
|
||||
Class<?> fieldTypeClass =field.getType(); |
|
||||
Property property = new Property(); |
|
||||
if(ValueTypeUtil.isBase(fieldTypeClass)) { |
|
||||
property.setCode(field.getName()); |
|
||||
String nameI18nKey =clazz.getPackage().getName() + "." + clazz.getSimpleName() + "." + field.getName(); |
|
||||
String name=messageSource.getMessage(nameI18nKey, new Object[]{}, nameI18nKey, locale); |
|
||||
property.setName(name); |
|
||||
property.setValueType(fieldTypeClass.getName()); |
|
||||
property.setValueTypeVersion(null); |
|
||||
}else if(ValueTypeUtil.isList(fieldTypeClass)){ |
|
||||
Class<?> elementClass =CollectionUtil.getListElementJavaType(field.getGenericType()); |
|
||||
property.setCode(field.getName()); |
|
||||
String nameI18nKey =clazz.getPackage().getName() + "." + elementClass.getSimpleName(); |
|
||||
String name=messageSource.getMessage(nameI18nKey, new Object[]{}, nameI18nKey, locale); |
|
||||
property.setName(name); |
|
||||
property.setValueType(elementClass.getName()); |
|
||||
property.setValueTypeVersion(valueTypeVersion); |
|
||||
property.setValueTypeIsList(true); |
|
||||
buildJavaClassValueTypes(autoCompletion,elementClass,null,null,valueTypeVersion,locale); |
|
||||
}else{ |
|
||||
property.setCode(field.getName()); |
|
||||
String nameI18nKey =fieldTypeClass.getPackage().getName() + "." + fieldTypeClass.getSimpleName(); |
|
||||
String name=messageSource.getMessage(nameI18nKey, new Object[]{}, nameI18nKey, locale); |
|
||||
property.setName(name); |
|
||||
property.setValueType(fieldTypeClass.getName()); |
|
||||
property.setValueTypeVersion(valueTypeVersion); |
|
||||
} |
|
||||
valueType.addProperty(property); |
|
||||
buildJavaClassValueTypes(autoCompletion,fieldTypeClass,null,null,valueTypeVersion,locale); |
|
||||
} |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue