use of com.diboot.core.exception.InvalidUsageException in project diboot by dibo-software.
the class FieldBinder method bind.
@Override
public void bind() {
if (V.isEmpty(annoObjectList)) {
return;
}
if (V.isEmpty(refObjJoinCols)) {
throw new InvalidUsageException("调用错误:无法从condition中解析出字段关联.");
}
if (referencedGetterFieldNameList == null) {
throw new InvalidUsageException("调用错误:字段绑定必须指定字段field");
}
// 构建跨模块绑定DTO
RemoteBindDTO remoteBindDTO = V.isEmpty(this.module) ? null : new RemoteBindDTO(referencedEntityClass);
// 直接关联
if (middleTable == null) {
List<Map<String, Object>> mapList = null;
this.simplifySelectColumns(remoteBindDTO);
super.buildQueryWrapperJoinOn(remoteBindDTO);
// 查询条件为空时不进行查询
if (queryWrapper.isEmptyOfNormal()) {
return;
}
if (V.isEmpty(this.module)) {
// 本地查询获取匹配结果的mapList
mapList = getMapList(queryWrapper);
} else {
// 远程调用获取
mapList = RemoteBindingManager.fetchMapList(module, remoteBindDTO);
}
if (V.isEmpty(mapList)) {
return;
}
// 将结果list转换成map
Map<String, Map<String, Object>> key2DataMap = this.buildMatchKey2ResultMap(mapList);
// 遍历list并赋值
for (Object annoObject : annoObjectList) {
String matchKey = buildMatchKey(annoObject);
setFieldValueToTrunkObj(key2DataMap, annoObject, matchKey);
}
} else {
if (refObjJoinCols.size() > 1) {
throw new InvalidUsageException(NOT_SUPPORT_MSG);
}
// 提取注解条件中指定的对应的列表
Map<String, List> trunkObjCol2ValuesMap = super.buildTrunkObjCol2ValuesMap();
// 中间表查询结果map
Map<String, Object> middleTableResultMap = middleTable.executeOneToOneQuery(trunkObjCol2ValuesMap);
if (V.isEmpty(middleTableResultMap)) {
return;
}
// 收集查询结果values集合
Collection refObjValues = middleTableResultMap.values().stream().distinct().collect(Collectors.toList());
this.simplifySelectColumns(remoteBindDTO);
// 构建查询条件
String refObjJoinOnCol = refObjJoinCols.get(0);
// 获取匹配结果的mapList
List<Map<String, Object>> mapList = null;
if (V.isEmpty(this.module)) {
// 本地查询获取匹配结果的mapList
queryWrapper.in(refObjJoinOnCol, refObjValues);
mapList = getMapList(queryWrapper);
} else {
// 远程调用获取
remoteBindDTO.setRefJoinCol(refObjJoinOnCol).setInConditionValues(refObjValues);
mapList = RemoteBindingManager.fetchMapList(module, remoteBindDTO);
}
if (V.isEmpty(mapList)) {
return;
}
// 将结果list转换成map
Map<String, Map<String, Object>> key2DataMap = this.buildMatchKey2ResultMap(mapList);
// 遍历list并赋值
for (Object annoObject : annoObjectList) {
String matchKey = buildMatchKey(annoObject, middleTableResultMap);
setFieldValueToTrunkObj(key2DataMap, annoObject, matchKey);
}
}
}
use of com.diboot.core.exception.InvalidUsageException in project diboot by dibo-software.
the class ExtQueryWrapper method queryList.
/**
* 查询一条数据
* @param entityClazz
* @return
*/
public List queryList(Class<E> entityClazz, Pagination pagination) {
this.mainEntityClass = entityClazz;
IService iService = ContextHelper.getIServiceByEntity(entityClazz);
if (iService != null) {
return ServiceAdaptor.queryList(iService, (QueryWrapper) this, pagination, entityClazz);
} else {
throw new InvalidUsageException("查询对象无BaseService/IService实现: " + entityClazz.getSimpleName());
}
}
use of com.diboot.core.exception.InvalidUsageException in project diboot by dibo-software.
the class ExtQueryWrapper method queryList.
/**
* 查询一条数据
* @param entityClazz
* @return
*/
public List<E> queryList(Class<E> entityClazz) {
this.mainEntityClass = entityClazz;
IService iService = ContextHelper.getIServiceByEntity(entityClazz);
if (iService != null) {
return ServiceAdaptor.queryList(iService, this);
} else {
throw new InvalidUsageException("查询对象无BaseService/IService实现: " + entityClazz.getSimpleName());
}
}
use of com.diboot.core.exception.InvalidUsageException in project diboot by dibo-software.
the class DataAccessAnnoCache method initClassCheckpoint.
/**
* 初始化entityDto的检查点缓存
* @param entityDto
*/
private static void initClassCheckpoint(Class<?> entityDto) {
String key = entityDto.getName();
if (!DATA_PERMISSION_ANNO_CACHE.containsKey(key)) {
String[] results = { "", "", "", "", "", "" };
List<Field> fieldList = BeanUtils.extractFields(entityDto, DataAccessCheckpoint.class);
if (V.notEmpty(fieldList)) {
for (Field fld : fieldList) {
DataAccessCheckpoint checkpoint = fld.getAnnotation(DataAccessCheckpoint.class);
if (V.notEmpty(results[checkpoint.type().index()])) {
throw new InvalidUsageException(entityDto.getSimpleName() + "中DataPermissionCheckpoint同类型注解重复!");
}
results[checkpoint.type().index()] = BeanUtils.getColumnName(fld);
}
}
DATA_PERMISSION_ANNO_CACHE.put(key, results);
}
}
use of com.diboot.core.exception.InvalidUsageException in project diboot by dibo-software.
the class ExcelBindAnnoHandler method convertToNameValueMap.
/**
* 转换为name-value map
* @param annotation
* @param nameList
* @return
*/
public static Map<String, List> convertToNameValueMap(Annotation annotation, List<String> nameList) {
// 字典
if (annotation instanceof ExcelBindDict || annotation instanceof BindDict) {
String dictType = null;
if (annotation instanceof ExcelBindDict) {
dictType = ((ExcelBindDict) annotation).type();
} else {
dictType = ((BindDict) annotation).type();
}
DictionaryServiceExtProvider bindDictService = ContextHelper.getBean(DictionaryServiceExtProvider.class);
if (bindDictService == null) {
throw new InvalidUsageException("DictionaryService未实现,无法使用ExcelBindDict注解!");
}
List<LabelValue> list = bindDictService.getLabelValueList(dictType);
return convertLabelValueListToMap(list);
} else if (annotation instanceof ExcelBindField) {
ExcelBindField bindField = (ExcelBindField) annotation;
return executeBindField(bindField, nameList);
} else {
return Collections.emptyMap();
}
}
Aggregations