Переглянути джерело

导入支持groupname

4.1.3.A
jueyue 7 роки тому
джерело
коміт
ce5e2f9798
5 змінених файлів з 30 додано та 21 видалено
  1. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonServer.java
  2. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java
  3. +16
    -7
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java
  4. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java
  5. +10
    -10
      easypoi-base/src/main/java/cn/afterturn/easypoi/exception/excel/enums/ExcelImportEnum.java

+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonServer.java Переглянути файл

@@ -84,7 +84,7 @@ public class ExportCommonServer {

private Object dateFormatValue(Object value, ExcelExportEntity entity) throws Exception {
Date temp = null;
if (value instanceof String) {
if (value instanceof String && StringUtils.isNoneEmpty(value.toString())) {
SimpleDateFormat format = new SimpleDateFormat(entity.getDatabaseFormat());
temp = format.parse(value.toString());
} else if (value instanceof Date) {


+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java Переглянути файл

@@ -167,7 +167,7 @@ public class ExcelImportServer extends ImportBaseService {
if (etarget != null) {
targetId = etarget.value();
}
getAllExcelField(targetId, fileds, excelParams, excelCollection, pojoClass, null);
getAllExcelField(targetId, fileds, excelParams, excelCollection, pojoClass, null, null);
}
Iterator<Row> rows = sheet.rowIterator();
for (int j = 0; j < params.getTitleRows(); j++) {
@@ -415,7 +415,7 @@ public class ExcelImportServer extends ImportBaseService {
for (int j = 0; j < rowList.size(); j++) {
if (rowList.get(j).getRowNum() < rowList.get(j).getSheet().getLastRowNum()) {
book.getSheetAt(i).shiftRows(rowList.get(j).getRowNum() + 1, rowList.get(j).getSheet().getLastRowNum(), -1);
} else if(rowList.get(j).getRowNum() == rowList.get(j).getSheet().getLastRowNum()){
} else if (rowList.get(j).getRowNum() == rowList.get(j).getSheet().getLastRowNum()) {
book.getSheetAt(i).shiftRows(rowList.get(j).getRowNum(), rowList.get(j).getSheet().getLastRowNum(), -1);
}
}


+ 16
- 7
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java Переглянути файл

@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.IOUtils;
@@ -39,6 +40,8 @@ import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelCollectionParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelImportEntity;
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
import cn.afterturn.easypoi.exception.excel.enums.ExcelImportEnum;
import cn.afterturn.easypoi.util.PoiPublicUtil;
import cn.afterturn.easypoi.util.PoiReflectorUtil;
@@ -62,7 +65,7 @@ public class ImportBaseService {
*/
public void addEntityToMap(String targetId, Field field, ExcelImportEntity excelEntity,
Class<?> pojoClass, List<Method> getMethods,
Map<String, ExcelImportEntity> temp) throws Exception {
Map<String, ExcelImportEntity> temp, ExcelEntity excelEntityAnn) throws Exception {
Excel excel = field.getAnnotation(Excel.class);
excelEntity = new ExcelImportEntity();
excelEntity.setType(excel.type());
@@ -73,7 +76,7 @@ public class ImportBaseService {
excelEntity.setSuffix(excel.suffix());
excelEntity.setImportField(Boolean
.valueOf(PoiPublicUtil.getValueByTargetId(excel.isImportField(), targetId, "false")));
getExcelField(targetId, field, excelEntity, excel, pojoClass);
getExcelField(targetId, field, excelEntity, excel, pojoClass, excelEntityAnn);
if (getMethods != null) {
List<Method> newMethods = new ArrayList<Method>();
newMethods.addAll(getMethods);
@@ -97,7 +100,7 @@ public class ImportBaseService {
public void getAllExcelField(String targetId, Field[] fields,
Map<String, ExcelImportEntity> excelParams,
List<ExcelCollectionParams> excelCollection, Class<?> pojoClass,
List<Method> getMethods) throws Exception {
List<Method> getMethods, ExcelEntity excelEntityAnn) throws Exception {
ExcelImportEntity excelEntity = null;
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
@@ -121,7 +124,7 @@ public class ImportBaseService {
additionalCollectionName(collection);
excelCollection.add(collection);
} else if (PoiPublicUtil.isJavaClass(field)) {
addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams, excelEntityAnn);
} else {
List<Method> newMethods = new ArrayList<Method>();
if (getMethods != null) {
@@ -130,9 +133,12 @@ public class ImportBaseService {
//
newMethods.add(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName()));
ExcelEntity excel = field.getAnnotation(ExcelEntity.class);
if (excel.show() && StringUtils.isEmpty(excel.name())) {
throw new ExcelImportException("if use ExcelEntity ,name mus has value ,data: " + ReflectionToStringBuilder.toString(excel), ExcelImportEnum.PARAMETER_ERROR);
}
getAllExcelField(StringUtils.isNotEmpty(excel.id()) ? excel.id() : targetId,
PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection,
field.getType(), newMethods);
field.getType(), newMethods, excel);
}
}
}
@@ -152,11 +158,14 @@ public class ImportBaseService {
}
public void getExcelField(String targetId, Field field, ExcelImportEntity excelEntity,
Excel excel, Class<?> pojoClass) throws Exception {
Excel excel, Class<?> pojoClass, ExcelEntity excelEntityAnn) throws Exception {
excelEntity.setName(PoiPublicUtil.getValueByTargetId(excel.name(), targetId, null));
if (StringUtils.isNoneEmpty(excel.groupName())) {
excelEntity.setName(excel.groupName() + "_" + excelEntity.getName());
}
if(excelEntityAnn != null && excelEntityAnn.show()){
excelEntity.setName(excelEntityAnn.name() + "_" + excelEntity.getName());
}
String fieldname = field.getName();
excelEntity.setMethod(PoiReflectorUtil.fromCache(pojoClass).getSetMethod(fieldname));
if (StringUtils.isNotEmpty(excel.importFormat())) {
@@ -176,7 +185,7 @@ public class ImportBaseService {
continue;
}
if (PoiPublicUtil.isJavaClass(field)) {
addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, temp);
addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, temp, null);
} else {
List<Method> newMethods = new ArrayList<Method>();
if (getMethods != null) {


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java Переглянути файл

@@ -88,7 +88,7 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead {
if (etarget != null) {
targetId = etarget.value();
}
getAllExcelField(targetId, fileds, excelParams, excelCollection, pojoClass, null);
getAllExcelField(targetId, fileds, excelParams, excelCollection, pojoClass, null,null);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new ExcelImportException(e.getMessage());


+ 10
- 10
easypoi-base/src/main/java/cn/afterturn/easypoi/exception/excel/enums/ExcelImportEnum.java Переглянути файл

@@ -1,13 +1,13 @@
/**
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing, software
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -21,10 +21,10 @@ package cn.afterturn.easypoi.exception.excel.enums;
* 2014年6月19日 下午10:59:51
*/
public enum ExcelImportEnum {
IS_NOT_A_VALID_TEMPLATE ("不是合法的Excel模板") ,
GET_VALUE_ERROR ("Excel 值获取失败") ,
VERIFY_ERROR ("值校验失败");
PARAMETER_ERROR("参数错误"),
IS_NOT_A_VALID_TEMPLATE("不是合法的Excel模板"),
GET_VALUE_ERROR("Excel 值获取失败"),
VERIFY_ERROR("值校验失败");
private String msg;


Завантаження…
Відмінити
Зберегти