|
|
|
@ -26,14 +26,12 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
@ -82,6 +80,7 @@ public class ExcelUtil {
|
|
|
|
|
* @param data 导出的数据
|
|
|
|
|
* @param exportClass 导出数据类型
|
|
|
|
|
* @param exportCol 需要导出的列
|
|
|
|
|
* @return 导出文件
|
|
|
|
|
*/
|
|
|
|
|
public static File exportData(File excelFile, List data, Class exportClass, String[] exportCol) throws Exception {
|
|
|
|
|
FileOutputStream fos = null;
|
|
|
|
@ -141,8 +140,8 @@ public class ExcelUtil {
|
|
|
|
|
if (outputColumn.refClass().isEnum()) {
|
|
|
|
|
method = outputColumn.refClass().getDeclaredMethod(
|
|
|
|
|
outputColumn.refForeignKey() + "Of" + StringTool.toUpperCaseFirstOne(outputColumn.value()),
|
|
|
|
|
outputColumn.refClass().getDeclaredMethod("get"
|
|
|
|
|
+ StringTool.toUpperCaseFirstOne(outputColumn.refForeignKey())).getReturnType());
|
|
|
|
|
outputColumn.refClass().getDeclaredMethod("get"+
|
|
|
|
|
StringTool.toUpperCaseFirstOne(outputColumn.refForeignKey())).getReturnType());
|
|
|
|
|
cellValue = method.invoke(data.get(i), cellValue);
|
|
|
|
|
}else if(outputColumn.refClass().equals(SysDictionary.class) && cellValue != null){
|
|
|
|
|
cellValue = sysDictionaryService.getSysDictionaryByParentCodeAndValue(outputColumn.refForeignKey(), String.valueOf(cellValue)).getName();
|
|
|
|
@ -180,7 +179,9 @@ public class ExcelUtil {
|
|
|
|
|
* @param fileName 文件名
|
|
|
|
|
* @param inputStream 输入流
|
|
|
|
|
* @param importClass 导入类型
|
|
|
|
|
* @param <T> 实体
|
|
|
|
|
* @return 导入数据集合
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static <T> List<T> importData(String fileName, InputStream inputStream, Class importClass) throws Exception {
|
|
|
|
|
List dataList = new ArrayList<T>();
|
|
|
|
@ -253,8 +254,8 @@ public class ExcelUtil {
|
|
|
|
|
if (inputColumn.refClass().isEnum()) {
|
|
|
|
|
method = inputColumn.refClass().getDeclaredMethod(
|
|
|
|
|
inputColumn.value() + "Of" + StringTool.toUpperCaseFirstOne(inputColumn.refForeignKey()),
|
|
|
|
|
inputColumn.refClass().getDeclaredMethod("get"
|
|
|
|
|
+ StringTool.toUpperCaseFirstOne(inputColumn.value())).getReturnType());
|
|
|
|
|
inputColumn.refClass().getDeclaredMethod("get"+
|
|
|
|
|
StringTool.toUpperCaseFirstOne(inputColumn.value())).getReturnType());
|
|
|
|
|
cellValue = method.invoke(null, cellValue);
|
|
|
|
|
}else if(inputColumn.refClass().equals(SysDictionary.class) && cellValue != null){
|
|
|
|
|
cellValue = sysDictionaryService.getSysDictionaryByParentCodeAndName(inputColumn.refForeignKey(), String.valueOf(cellValue)).getName();
|
|
|
|
@ -279,8 +280,8 @@ public class ExcelUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入模板
|
|
|
|
|
*
|
|
|
|
|
* @param exportClass
|
|
|
|
|
* @param exportClass 需要生成模板的类
|
|
|
|
|
* @return 模板文件
|
|
|
|
|
*/
|
|
|
|
|
public static byte[] importTemplate(Class exportClass) {
|
|
|
|
|
File excelFile = null;
|
|
|
|
@ -347,8 +348,8 @@ public class ExcelUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取实体列集合
|
|
|
|
|
* @param pojoClass
|
|
|
|
|
* @return
|
|
|
|
|
* @param pojoClass 实体类
|
|
|
|
|
* @return 列集合
|
|
|
|
|
*/
|
|
|
|
|
public static Map getColName(Class pojoClass) {
|
|
|
|
|
Map colName = new LinkedHashMap();
|
|
|
|
@ -381,7 +382,7 @@ public class ExcelUtil {
|
|
|
|
|
* @param value
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static Object selectByProperty(Class persistentClass, String colName, String propertyName, Object value) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
|
|
|
|
public static Object selectByProperty(Class persistentClass, String colName, String propertyName, Object value) {
|
|
|
|
|
String queryString = "select model." + colName + " from " + persistentClass.getSimpleName()
|
|
|
|
|
+ " as model where model." + propertyName + "= :" + propertyName;
|
|
|
|
|
return entityManager.createQuery(queryString).setParameter(propertyName, value).getSingleResult();
|
|
|
|
|