org.jeecgframework.poi.excel.annotation.ExcelCollection Java Examples

The following examples show how to use org.jeecgframework.poi.excel.annotation.ExcelCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExcelPublicUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是否不要在这个excel操作中
 * @param field
 * @param targetId
 * @return
 */
public static boolean isNotUserExcelUserThis(Field field, String targetId) {
	boolean boo = true;
	if(field.getAnnotation(ExcelIgnore.class)!=null){
		boo = true;
	}else if(boo&&field.getAnnotation(ExcelCollection.class)!=null
			&&isUseInThis(field.getAnnotation(ExcelCollection.class).exportName(),targetId)){
		boo = false;
	}else if(boo&&field.getAnnotation(Excel.class)!=null
			&&isUseInThis(field.getAnnotation(Excel.class).exportName(),targetId)){
		boo = false;
	}else if(boo&&field.getAnnotation(ExcelEntity.class)!=null
			&&isUseInThis(field.getAnnotation(ExcelEntity.class).exportName(),targetId)){
		boo = false;
	}
	return boo;
}
 
Example #2
Source File: ImportBaseService.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取需要导出的全部字段
 * 
 * 
 * @param exclusions
 * @param targetId
 *            目标ID
 * @param fields
 * @param excelCollection
 * @throws Exception
 */
public void getAllExcelField(String targetId, Field[] fields, Map<String, ExcelImportEntity> excelParams, List<ExcelCollectionParams> excelCollection, Class<?> pojoClass, List<Method> getMethods) throws Exception {
	ExcelImportEntity excelEntity = null;
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
			continue;
		}
		if (PoiPublicUtil.isCollection(field.getType())) {
			// 集合对象设置属性
			ExcelCollectionParams collection = new ExcelCollectionParams();
			collection.setName(field.getName());
			Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>();
			ParameterizedType pt = (ParameterizedType) field.getGenericType();
			Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0];
			collection.setType(clz);
			getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null);
			collection.setExcelParams(temp);
			collection.setExcelName(field.getAnnotation(ExcelCollection.class).name());
			additionalCollectionName(collection);
			excelCollection.add(collection);
		} else if (PoiPublicUtil.isJavaClass(field)) {
			addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
		} else {
			List<Method> newMethods = new ArrayList<Method>();
			if (getMethods != null) {
				newMethods.addAll(getMethods);
			}
			newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass));
			getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection, field.getType(), newMethods);
		}
	}
}
 
Example #3
Source File: PoiPublicUtil.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 彻底创建一个对象
 * 
 * @param clazz
 * @return
 */
public static Object createObject(Class<?> clazz, String targetId) {
	Object obj = null;
	Method setMethod;
	try {
		if (clazz.equals(Map.class)) {
			return new HashMap<String, Object>();
		}
		obj = clazz.newInstance();
		Field[] fields = getClassFields(clazz);
		for (Field field : fields) {
			if (isNotUserExcelUserThis(null, field, targetId)) {
				continue;
			}
			if (isCollection(field.getType())) {
				ExcelCollection collection = field.getAnnotation(ExcelCollection.class);
				setMethod = getMethod(field.getName(), clazz, field.getType());
				setMethod.invoke(obj, collection.type().newInstance());
			} else if (!isJavaClass(field)) {
				setMethod = getMethod(field.getName(), clazz, field.getType());
				setMethod.invoke(obj, createObject(field.getType(), targetId));
			}
		}

	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		throw new RuntimeException("创建对象异常");
	}
	return obj;

}
 
Example #4
Source File: PoiPublicUtil.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否不要在这个excel操作中
 * 
 * @param
 * @param field
 * @param targetId
 * @return
 */
public static boolean isNotUserExcelUserThis(List<String> exclusionsList, Field field, String targetId) {
	boolean boo = true;
	if (field.getAnnotation(ExcelIgnore.class) != null) {
		boo = true;
	} else if (boo && field.getAnnotation(ExcelCollection.class) != null && isUseInThis(field.getAnnotation(ExcelCollection.class).name(), targetId) && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(ExcelCollection.class).name()))) {
		boo = false;
	} else if (boo && field.getAnnotation(Excel.class) != null && isUseInThis(field.getAnnotation(Excel.class).name(), targetId) && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(Excel.class).name()))) {
		boo = false;
	} else if (boo && field.getAnnotation(ExcelEntity.class) != null && isUseInThis(field.getAnnotation(ExcelEntity.class).name(), targetId) && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(ExcelEntity.class).name()))) {
		boo = false;
	}
	return boo;
}
 
Example #5
Source File: ImportBaseService.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取需要导出的全部字段
 * 
 * 
 * @param exclusions
 * @param targetId
 *            目标ID
 * @param fields
 * @param excelCollection
 * @throws Exception
 */
public void getAllExcelField(String targetId, Field[] fields, Map<String, ExcelImportEntity> excelParams, List<ExcelCollectionParams> excelCollection, Class<?> pojoClass, List<Method> getMethods) throws Exception {
	ExcelImportEntity excelEntity = null;
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
			continue;
		}
		if (PoiPublicUtil.isCollection(field.getType())) {
			// 集合对象设置属性
			ExcelCollectionParams collection = new ExcelCollectionParams();
			collection.setName(field.getName());
			Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>();
			ParameterizedType pt = (ParameterizedType) field.getGenericType();
			Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0];
			collection.setType(clz);
			getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null);
			collection.setExcelParams(temp);
			collection.setExcelName(field.getAnnotation(ExcelCollection.class).name());
			additionalCollectionName(collection);
			excelCollection.add(collection);
		} else if (PoiPublicUtil.isJavaClass(field)) {
			addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
		} else {
			List<Method> newMethods = new ArrayList<Method>();
			if (getMethods != null) {
				newMethods.addAll(getMethods);
			}
			newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass));
			getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection, field.getType(), newMethods);
		}
	}
}
 
Example #6
Source File: PoiPublicUtil.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 彻底创建一个对象
 * 
 * @param clazz
 * @return
 */
public static Object createObject(Class<?> clazz, String targetId) {
	Object obj = null;
	Method setMethod;
	try {
		if (clazz.equals(Map.class)) {
			return new HashMap<String, Object>();
		}
		obj = clazz.newInstance();
		Field[] fields = getClassFields(clazz);
		for (Field field : fields) {
			if (isNotUserExcelUserThis(null, field, targetId)) {
				continue;
			}
			if (isCollection(field.getType())) {
				ExcelCollection collection = field.getAnnotation(ExcelCollection.class);
				setMethod = getMethod(field.getName(), clazz, field.getType());
				setMethod.invoke(obj, collection.type().newInstance());
			} else if (!isJavaClass(field)) {
				setMethod = getMethod(field.getName(), clazz, field.getType());
				setMethod.invoke(obj, createObject(field.getType(), targetId));
			}
		}

	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		throw new RuntimeException("创建对象异常");
	}
	return obj;

}
 
Example #7
Source File: PoiPublicUtil.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否不要在这个excel操作中
 * 
 * @param
 * @param field
 * @param targetId
 * @return
 */
public static boolean isNotUserExcelUserThis(List<String> exclusionsList, Field field, String targetId) {
	boolean boo = true;
	if (field.getAnnotation(ExcelIgnore.class) != null) {
		boo = true;
	} else if (boo && field.getAnnotation(ExcelCollection.class) != null && isUseInThis(field.getAnnotation(ExcelCollection.class).name(), targetId) && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(ExcelCollection.class).name()))) {
		boo = false;
	} else if (boo && field.getAnnotation(Excel.class) != null && isUseInThis(field.getAnnotation(Excel.class).name(), targetId) && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(Excel.class).name()))) {
		boo = false;
	} else if (boo && field.getAnnotation(ExcelEntity.class) != null && isUseInThis(field.getAnnotation(ExcelEntity.class).name(), targetId) && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(ExcelEntity.class).name()))) {
		boo = false;
	}
	return boo;
}
 
Example #8
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取需要导出的全部字段
 * 
 * 
 * @param exclusions
 * @param targetId
 *            目标ID
 * @param fields
 * @param excelCollection
 * @throws Exception
 */
public void getAllExcelField(String targetId, Field[] fields,
                             Map<String, ExcelImportEntity> excelParams,
                             List<ExcelCollectionParams> excelCollection, Class<?> pojoClass,
                             List<Method> getMethods) throws Exception {
    ExcelImportEntity excelEntity = null;
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
            continue;
        }
        if (PoiPublicUtil.isCollection(field.getType())) {
            // 集合对象设置属性
            ExcelCollectionParams collection = new ExcelCollectionParams();
            collection.setName(field.getName());
            Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>();
            ParameterizedType pt = (ParameterizedType) field.getGenericType();
            Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0];
            collection.setType(clz);
            getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null);
            collection.setExcelParams(temp);
            collection.setExcelName(field.getAnnotation(ExcelCollection.class).name());
            additionalCollectionName(collection);
            excelCollection.add(collection);
        } else if (PoiPublicUtil.isJavaClass(field)) {
            addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
        } else {
            List<Method> newMethods = new ArrayList<Method>();
            if (getMethods != null) {
                newMethods.addAll(getMethods);
            }
            newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass));
            getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()),
                excelParams, excelCollection, field.getType(), newMethods);
        }
    }
}
 
Example #9
Source File: PoiPublicUtil.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 彻底创建一个对象
 * 
 * @param clazz
 * @return
 */
public static Object createObject(Class<?> clazz, String targetId) {
    Object obj = null;
    Method setMethod;
    try {
        if (clazz.equals(Map.class)) {
            return new HashMap<String, Object>();
        }
        obj = clazz.newInstance();
        Field[] fields = getClassFields(clazz);
        for (Field field : fields) {
            if (isNotUserExcelUserThis(null, field, targetId)) {
                continue;
            }
            if (isCollection(field.getType())) {
                ExcelCollection collection = field.getAnnotation(ExcelCollection.class);
                setMethod = getMethod(field.getName(), clazz, field.getType());
                setMethod.invoke(obj, collection.type().newInstance());
            } else if (!isJavaClass(field)) {
                setMethod = getMethod(field.getName(), clazz, field.getType());
                setMethod.invoke(obj, createObject(field.getType(), targetId));
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException("创建对象异常");
    }
    return obj;

}
 
Example #10
Source File: PoiPublicUtil.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否不要在这个excel操作中
 * 
 * @param
 * @param field
 * @param targetId
 * @return
 */
public static boolean isNotUserExcelUserThis(List<String> exclusionsList, Field field,
                                             String targetId) {
    boolean boo = true;
    if (field.getAnnotation(ExcelIgnore.class) != null) {
        boo = true;
    } else if (boo
               && field.getAnnotation(ExcelCollection.class) != null
               && isUseInThis(field.getAnnotation(ExcelCollection.class).name(), targetId)
               && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(
                   ExcelCollection.class).name()))) {
        boo = false;
    } else if (boo
               && field.getAnnotation(Excel.class) != null
               && isUseInThis(field.getAnnotation(Excel.class).name(), targetId)
               && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(
                   Excel.class).name()))) {
        boo = false;
    } else if (boo
               && field.getAnnotation(ExcelEntity.class) != null
               && isUseInThis(field.getAnnotation(ExcelEntity.class).name(), targetId)
               && (exclusionsList == null || !exclusionsList.contains(field.getAnnotation(
                   ExcelEntity.class).name()))) {
        boo = false;
    }
    return boo;
}
 
Example #11
Source File: ExcelPublicUtil.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 彻底创建一个对象
 * @param clazz
 * @return
 */
public static Object createObject(Class<?> clazz,String targetId) {
	Object obj = null;
	String fieldname;
	Method setMethod;
	try {
		obj = clazz.newInstance();
		Field[] fields = getClassFields(clazz);
		for(Field field:fields){
			if(isNotUserExcelUserThis(field, targetId)){continue;}
			if(isCollection(field.getType())){
				ExcelCollection collection = field
						.getAnnotation(ExcelCollection.class);
				fieldname = field.getName();
				setMethod = getMethod(fieldname,clazz,field.getType());
				setMethod.invoke(obj,ExcelPublicUtil.class.getClassLoader().loadClass(collection.type()).newInstance());
			}else if(!isJavaClass(field)){
				fieldname = field.getName();
				setMethod = getMethod(fieldname,clazz,field.getType() );
				setMethod.invoke(obj, createObject(field.getType(),targetId));
			}
		}
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	return obj; 
	
}