Search in sources :

Example 1 with InvalidUsageException

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);
        }
    }
}
Also used : RemoteBindDTO(com.diboot.core.binding.binder.remote.RemoteBindDTO) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Example 2 with InvalidUsageException

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());
    }
}
Also used : IService(com.baomidou.mybatisplus.extension.service.IService) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Example 3 with InvalidUsageException

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());
    }
}
Also used : IService(com.baomidou.mybatisplus.extension.service.IService) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Example 4 with InvalidUsageException

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);
    }
}
Also used : Field(java.lang.reflect.Field) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Example 5 with InvalidUsageException

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();
    }
}
Also used : ExcelBindDict(com.diboot.file.excel.annotation.ExcelBindDict) BindDict(com.diboot.core.binding.annotation.BindDict) DictionaryServiceExtProvider(com.diboot.core.service.DictionaryServiceExtProvider) LabelValue(com.diboot.core.vo.LabelValue) ExcelBindDict(com.diboot.file.excel.annotation.ExcelBindDict) InvalidUsageException(com.diboot.core.exception.InvalidUsageException) ExcelBindField(com.diboot.file.excel.annotation.ExcelBindField)

Aggregations

InvalidUsageException (com.diboot.core.exception.InvalidUsageException)13 RemoteBindDTO (com.diboot.core.binding.binder.remote.RemoteBindDTO)4 HashMap (java.util.HashMap)4 IService (com.baomidou.mybatisplus.extension.service.IService)3 BusinessException (com.diboot.core.exception.BusinessException)3 List (java.util.List)3 Map (java.util.Map)3 DynamicJoinQueryWrapper (com.diboot.core.binding.query.dynamic.DynamicJoinQueryWrapper)2 DictionaryServiceExtProvider (com.diboot.core.service.DictionaryServiceExtProvider)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 LambdaMeta (com.baomidou.mybatisplus.core.toolkit.support.LambdaMeta)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BindDict (com.diboot.core.binding.annotation.BindDict)1 BindEntityList (com.diboot.core.binding.annotation.BindEntityList)1 BindFieldList (com.diboot.core.binding.annotation.BindFieldList)1 EntityInfoCache (com.diboot.core.binding.parser.EntityInfoCache)1