(1)dns策略Id类型修复,解决不能copy value
(2)导入模板验证是否合法,根据title判断,如果不同语言的导入模板,也会被判定不合法。 (3)注掉部分废弃导入方法
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
@@ -29,6 +30,10 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.nis.domain.configuration.template.ComplexStringAllTemplate;
|
||||
import com.nis.domain.configuration.template.IpAllTemplate;
|
||||
import com.nis.domain.configuration.template.StringAllTemplate;
|
||||
import com.nis.exceptions.ServiceException;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.util.Reflections;
|
||||
|
||||
@@ -280,7 +285,7 @@ public class ImportExcel {
|
||||
* @param cls 导入对象类型
|
||||
* @param groups 导入分组
|
||||
*/
|
||||
public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException{
|
||||
public <E> List<E> getDataList(Class<E> cls,Properties props, int... groups) throws InstantiationException, IllegalAccessException{
|
||||
List<Object[]> annotationList = Lists.newArrayList();
|
||||
// Get annotation field
|
||||
// Field[] fs = cls.getDeclaredFields();
|
||||
@@ -338,22 +343,76 @@ public class ImportExcel {
|
||||
}
|
||||
}
|
||||
}
|
||||
//log.debug("Import column count:"+annotationList.size());
|
||||
// Get excel data
|
||||
List<E> dataList = Lists.newArrayList();
|
||||
Row header = this.getRow(headerNum);
|
||||
List<Object[]> annotationListCopy=Lists.newArrayList();
|
||||
for(int i=header.getFirstCellNum();i<=header.getLastCellNum();i++) {
|
||||
Object value=this.getCellValue(header, i);
|
||||
for(Object[] os:annotationList) {
|
||||
ExcelField ef = (ExcelField)os[0];
|
||||
String title=ef.title();
|
||||
if(props.getProperty(title).equals(value.toString())) {
|
||||
annotationListCopy.add(os);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(annotationListCopy.size()==0) {
|
||||
throw new ServiceException(props.getProperty("template_error"));
|
||||
}
|
||||
if(IpAllTemplate.class.isAssignableFrom(cls)||cls.getSimpleName().equals("IpAllTemplate")) {
|
||||
boolean has=false;
|
||||
for(Object[] os:annotationListCopy) {
|
||||
ExcelField ef = (ExcelField)os[0];
|
||||
if(ef.title().equals("client_ip")||ef.title().equals("server_ip")) {
|
||||
has=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!has) {
|
||||
throw new ServiceException(props.getProperty("template_error"));
|
||||
}
|
||||
}else if(StringAllTemplate.class.isAssignableFrom(cls)||cls.getSimpleName().equals("StringAllTemplate")){
|
||||
boolean has=false;
|
||||
for(Object[] os:annotationListCopy) {
|
||||
ExcelField ef = (ExcelField)os[0];
|
||||
if(ef.title().equals("key_word")) {
|
||||
has=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!has) {
|
||||
throw new ServiceException(props.getProperty("template_error"));
|
||||
}
|
||||
}else if(ComplexStringAllTemplate.class.isAssignableFrom(cls)||cls.getSimpleName().equals("ComplexStringAllTemplate")){
|
||||
boolean has=false;
|
||||
for(Object[] os:annotationListCopy) {
|
||||
ExcelField ef = (ExcelField)os[0];
|
||||
if(ef.title().equals("key_word")) {
|
||||
has=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!has) {
|
||||
throw new ServiceException(props.getProperty("template_error"));
|
||||
}
|
||||
}
|
||||
// Field sorting
|
||||
Collections.sort(annotationList, new Comparator<Object[]>() {
|
||||
Collections.sort(annotationListCopy, new Comparator<Object[]>() {
|
||||
public int compare(Object[] o1, Object[] o2) {
|
||||
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
|
||||
new Integer(((ExcelField)o2[0]).sort()));
|
||||
};
|
||||
});
|
||||
//log.debug("Import column count:"+annotationList.size());
|
||||
// Get excel data
|
||||
List<E> dataList = Lists.newArrayList();
|
||||
annotationList.clear();
|
||||
for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) {
|
||||
E e = (E)cls.newInstance();
|
||||
int column = 0;
|
||||
Row row = this.getRow(i);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object[] os : annotationList){
|
||||
for (Object[] os : annotationListCopy){
|
||||
Object val = this.getCellValue(row, column++);
|
||||
if (val != null){
|
||||
ExcelField ef = (ExcelField)os[0];
|
||||
|
||||
Reference in New Issue
Block a user