Search in sources :

Example 1 with RemoteBindDTO

use of com.diboot.core.binding.binder.remote.RemoteBindDTO 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 RemoteBindDTO

use of com.diboot.core.binding.binder.remote.RemoteBindDTO in project diboot by dibo-software.

the class EntityListBinder method bind.

@Override
public void bind() {
    if (V.isEmpty(annoObjectList)) {
        return;
    }
    if (V.isEmpty(refObjJoinCols)) {
        throw new InvalidUsageException("调用错误:无法从condition中解析出字段关联.");
    }
    // 构建跨模块绑定DTO
    RemoteBindDTO remoteBindDTO = V.isEmpty(this.module) ? null : new RemoteBindDTO(referencedEntityClass);
    Map<String, List> valueEntityListMap = new HashMap<>();
    if (middleTable == null) {
        super.simplifySelectColumns(remoteBindDTO);
        super.buildQueryWrapperJoinOn(remoteBindDTO);
        // 查询条件为空时不进行查询
        if (queryWrapper.isEmptyOfNormal()) {
            return;
        }
        // 处理orderBy,附加排序
        this.appendOrderBy(remoteBindDTO);
        List<T> entityList = null;
        // 查询entity列表: List<Role>
        if (V.isEmpty(this.module)) {
            // 本地查询获取匹配结果的entityList
            entityList = getEntityList(queryWrapper);
        } else {
            // 远程调用获取
            entityList = RemoteBindingManager.fetchEntityList(module, remoteBindDTO, referencedEntityClass);
        }
        if (V.notEmpty(entityList)) {
            valueEntityListMap = this.buildMatchKey2EntityListMap(entityList);
        }
        ResultAssembler.bindPropValue(annoObjectField, annoObjectList, getAnnoObjJoinFlds(), valueEntityListMap, this.splitBy);
    } else {
        if (refObjJoinCols.size() > 1) {
            throw new InvalidUsageException(NOT_SUPPORT_MSG);
        }
        // 提取注解条件中指定的对应的列表
        Map<String, List> trunkObjCol2ValuesMap = super.buildTrunkObjCol2ValuesMap();
        Map<String, List> middleTableResultMap = middleTable.executeOneToManyQuery(trunkObjCol2ValuesMap);
        if (V.isEmpty(middleTableResultMap)) {
            return;
        }
        super.simplifySelectColumns(remoteBindDTO);
        // 收集查询结果values集合
        List entityIdList = extractIdValueFromMap(middleTableResultMap);
        if (V.notEmpty(this.splitBy)) {
            entityIdList = ResultAssembler.unpackValueList(entityIdList, this.splitBy);
        }
        // 处理orderBy,附加排序
        this.appendOrderBy(remoteBindDTO);
        // 构建查询条件
        String refObjJoinOnCol = refObjJoinCols.get(0);
        List<T> entityList = null;
        // 查询entity列表: List<Role>
        if (V.isEmpty(this.module)) {
            // 本地查询获取匹配结果的entityList
            queryWrapper.in(refObjJoinOnCol, entityIdList);
            entityList = getEntityList(queryWrapper);
        } else {
            // 远程调用获取
            remoteBindDTO.setRefJoinCol(refObjJoinOnCol).setInConditionValues(entityIdList);
            entityList = RemoteBindingManager.fetchEntityList(module, remoteBindDTO, referencedEntityClass);
        }
        if (V.isEmpty(entityList)) {
            return;
        }
        String refObjJoinOnField = toRefObjField(refObjJoinOnCol);
        // 转换entity列表为Map<ID, Entity>
        Map<String, T> entityMap = BeanUtils.convertToStringKeyObjectMap(entityList, refObjJoinOnField);
        for (Map.Entry<String, List> entry : middleTableResultMap.entrySet()) {
            // List<roleId>
            List annoObjFKList = entry.getValue();
            if (V.isEmpty(annoObjFKList)) {
                continue;
            }
            List valueList = new ArrayList();
            for (Object obj : annoObjFKList) {
                if (obj == null) {
                    continue;
                }
                String valStr = String.valueOf(obj);
                T ent = entityMap.get(valStr);
                if (ent != null) {
                    valueList.add(cloneOrConvertBean(ent));
                } else if (V.notEmpty(splitBy) && valStr.contains(splitBy)) {
                    for (String key : valStr.split(splitBy)) {
                        ent = entityMap.get(key);
                        if (ent != null) {
                            valueList.add(cloneOrConvertBean(ent));
                        }
                    }
                }
            }
            valueEntityListMap.put(entry.getKey(), valueList);
        }
        // 绑定结果
        ResultAssembler.bindEntityPropValue(annoObjectField, annoObjectList, middleTable.getTrunkObjColMapping(), valueEntityListMap, getAnnoObjColumnToFieldMap());
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteBindDTO(com.diboot.core.binding.binder.remote.RemoteBindDTO) ArrayList(java.util.ArrayList) List(java.util.List) BindEntityList(com.diboot.core.binding.annotation.BindEntityList) HashMap(java.util.HashMap) Map(java.util.Map) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Example 3 with RemoteBindDTO

use of com.diboot.core.binding.binder.remote.RemoteBindDTO in project diboot by dibo-software.

the class FieldListBinder 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.");
    }
    Map<String, List> valueEntityListMap = new HashMap<>();
    // 构建跨模块绑定DTO
    RemoteBindDTO remoteBindDTO = V.isEmpty(this.module) ? null : new RemoteBindDTO(referencedEntityClass);
    // 直接关联
    if (middleTable == null) {
        super.simplifySelectColumns(remoteBindDTO);
        super.buildQueryWrapperJoinOn(remoteBindDTO);
        // 查询条件为空时不进行查询
        if (queryWrapper.isEmptyOfNormal()) {
            return;
        }
        // 处理orderBy,附加排序
        this.appendOrderBy(remoteBindDTO);
        List<T> entityList = null;
        // 查询entity列表: List<Role>
        if (V.isEmpty(this.module)) {
            // 本地查询获取匹配结果的entityList
            entityList = getEntityList(queryWrapper);
        } else {
            // 远程调用获取
            entityList = RemoteBindingManager.fetchEntityList(module, remoteBindDTO, referencedEntityClass);
        }
        if (V.notEmpty(entityList)) {
            valueEntityListMap = this.buildMatchKey2FieldListMap(entityList);
        }
        // 遍历list并赋值
        ResultAssembler.bindFieldListPropValue(annoObjectList, getAnnoObjJoinFlds(), valueEntityListMap, annoObjectSetterPropNameList, referencedGetterFieldNameList, this.splitBy);
    } else // 通过中间表关联
    {
        if (refObjJoinCols.size() > 1) {
            throw new InvalidUsageException(NOT_SUPPORT_MSG);
        }
        // 提取注解条件中指定的对应的列表
        Map<String, List> trunkObjCol2ValuesMap = super.buildTrunkObjCol2ValuesMap();
        // 处理中间表, 将结果转换成map
        Map<String, List> middleTableResultMap = middleTable.executeOneToManyQuery(trunkObjCol2ValuesMap);
        if (V.isEmpty(middleTableResultMap)) {
            return;
        }
        super.simplifySelectColumns(remoteBindDTO);
        // 处理orderBy,附加排序
        this.appendOrderBy(remoteBindDTO);
        // 收集查询结果values集合
        List entityIdList = extractIdValueFromMap(middleTableResultMap);
        if (V.notEmpty(this.splitBy)) {
            entityIdList = ResultAssembler.unpackValueList(entityIdList, this.splitBy);
        }
        // 构建查询条件
        String refObjJoinOnCol = refObjJoinCols.get(0);
        List<T> entityList = null;
        // 查询entity列表: List<Role>
        if (V.isEmpty(this.module)) {
            // 本地查询获取匹配结果的entityList
            queryWrapper.in(refObjJoinOnCol, entityIdList);
            entityList = getEntityList(queryWrapper);
        } else {
            // 远程调用获取
            remoteBindDTO.setRefJoinCol(refObjJoinOnCol).setInConditionValues(entityIdList);
            entityList = RemoteBindingManager.fetchEntityList(module, remoteBindDTO, referencedEntityClass);
        }
        if (V.isEmpty(entityList)) {
            return;
        }
        String refObjJoinOnField = toRefObjField(refObjJoinOnCol);
        // 转换entity列表为Map<ID, Entity>
        Map<String, T> entityMap = BeanUtils.convertToStringKeyObjectMap(entityList, refObjJoinOnField);
        for (Map.Entry<String, List> entry : middleTableResultMap.entrySet()) {
            // List<roleId>
            List annoObjFKList = entry.getValue();
            if (V.isEmpty(annoObjFKList)) {
                continue;
            }
            List valueList = new ArrayList();
            for (Object obj : annoObjFKList) {
                String valStr = String.valueOf(obj);
                T ent = entityMap.get(valStr);
                if (ent != null) {
                    valueList.add(ent);
                } else if (V.notEmpty(splitBy) && valStr.contains(splitBy)) {
                    for (String key : valStr.split(splitBy)) {
                        ent = entityMap.get(key);
                        if (ent != null) {
                            valueList.add(ent);
                        }
                    }
                }
            }
            valueEntityListMap.put(entry.getKey(), valueList);
        }
        // 遍历list并赋值
        bindPropValue(annoObjectList, middleTable.getTrunkObjColMapping(), valueEntityListMap);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteBindDTO(com.diboot.core.binding.binder.remote.RemoteBindDTO) ArrayList(java.util.ArrayList) List(java.util.List) BindFieldList(com.diboot.core.binding.annotation.BindFieldList) HashMap(java.util.HashMap) Map(java.util.Map) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Example 4 with RemoteBindDTO

use of com.diboot.core.binding.binder.remote.RemoteBindDTO in project diboot by dibo-software.

the class EntityBinder method bind.

@Override
public void bind() {
    if (V.isEmpty(annoObjectList)) {
        return;
    }
    if (V.isEmpty(refObjJoinCols)) {
        throw new InvalidUsageException("调用错误:无法从condition中解析出字段关联.");
    }
    // 构建跨模块绑定DTO
    RemoteBindDTO remoteBindDTO = V.isEmpty(this.module) ? null : new RemoteBindDTO(referencedEntityClass);
    // 直接关联Entity
    if (middleTable == null) {
        this.simplifySelectColumns(remoteBindDTO);
        // @BindEntity(entity = Department.class, condition="this.department_id=id AND this.type=type")
        // Department department;
        super.buildQueryWrapperJoinOn(remoteBindDTO);
        // 查询条件为空时不进行查询
        if (queryWrapper.isEmptyOfNormal()) {
            return;
        }
        List<T> entityList = null;
        // 查询entity列表: List<T>
        if (V.isEmpty(this.module)) {
            // 本地查询获取匹配结果的entityList
            entityList = getEntityList(queryWrapper);
        } else {
            // 远程调用获取
            entityList = RemoteBindingManager.fetchEntityList(module, remoteBindDTO, referencedEntityClass);
        }
        if (V.notEmpty(entityList)) {
            Map<String, Object> valueEntityMap = this.buildMatchKey2EntityMap(entityList);
            ResultAssembler.bindPropValue(annoObjectField, annoObjectList, getAnnoObjJoinFlds(), valueEntityMap, null);
        }
    } else // 通过中间表关联Entity
    {
        if (refObjJoinCols.size() > 1) {
            throw new InvalidUsageException(NOT_SUPPORT_MSG);
        }
        // 提取注解条件中指定的对应的列表
        Map<String, List> trunkObjCol2ValuesMap = super.buildTrunkObjCol2ValuesMap();
        Map<String, Object> middleTableResultMap = middleTable.executeOneToOneQuery(trunkObjCol2ValuesMap);
        if (V.isEmpty(middleTableResultMap)) {
            return;
        }
        // 结果转换Map
        Map<String, Object> valueEntityMap = new HashMap<>();
        this.simplifySelectColumns(remoteBindDTO);
        // 提取entity主键值集合
        Collection refObjValues = middleTableResultMap.values().stream().distinct().collect(Collectors.toList());
        // 构建查询条件
        String refObjJoinOnCol = refObjJoinCols.get(0);
        // 查询entity列表
        List<T> entityList = null;
        // 查询entity列表: List<T>
        if (V.isEmpty(this.module)) {
            queryWrapper.in(refObjJoinOnCol, refObjValues);
            // 本地查询获取匹配结果的entityList
            entityList = getEntityList(queryWrapper);
        } else {
            // 远程调用获取
            remoteBindDTO.setRefJoinCol(refObjJoinOnCol).setInConditionValues(refObjValues);
            entityList = RemoteBindingManager.fetchEntityList(module, remoteBindDTO, referencedEntityClass);
        }
        if (V.isEmpty(entityList)) {
            return;
        }
        String refObjJoinOnField = toRefObjField(refObjJoinOnCol);
        // 转换entity列表为Map<ID, Entity>
        Map<String, T> listMap = BeanUtils.convertToStringKeyObjectMap(entityList, refObjJoinOnField);
        if (V.notEmpty(listMap)) {
            // List<String> joinOnValues = new ArrayList<>(refObjJoinFlds.size());
            for (Map.Entry<String, Object> entry : middleTableResultMap.entrySet()) {
                Object fetchValueId = entry.getValue();
                if (fetchValueId == null) {
                    continue;
                }
                String key = entry.getKey();
                T entity = listMap.get(String.valueOf(fetchValueId));
                valueEntityMap.put(key, cloneOrConvertBean(entity));
            }
        }
        // 绑定结果
        ResultAssembler.bindEntityPropValue(annoObjectField, annoObjectList, middleTable.getTrunkObjColMapping(), valueEntityMap, getAnnoObjColumnToFieldMap());
    }
}
Also used : HashMap(java.util.HashMap) RemoteBindDTO(com.diboot.core.binding.binder.remote.RemoteBindDTO) Collection(java.util.Collection) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) InvalidUsageException(com.diboot.core.exception.InvalidUsageException)

Aggregations

RemoteBindDTO (com.diboot.core.binding.binder.remote.RemoteBindDTO)4 InvalidUsageException (com.diboot.core.exception.InvalidUsageException)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 BindEntityList (com.diboot.core.binding.annotation.BindEntityList)1 BindFieldList (com.diboot.core.binding.annotation.BindFieldList)1 Collection (java.util.Collection)1