公共导入方法 新增校验模板功能 过滤excel纯空行数据功能
This commit is contained in:
@@ -71,7 +71,9 @@ public class exportWkExcel {
|
|||||||
public ResponseMessage<?> importSplitItemsZip(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
|
public ResponseMessage<?> importSplitItemsZip(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
|
||||||
StringBuilder stringBuilder=new StringBuilder();
|
StringBuilder stringBuilder=new StringBuilder();
|
||||||
List<importExcelDTO> res=exportService.delWithWkData(file,stringBuilder);
|
List<importExcelDTO> res=exportService.delWithWkData(file,stringBuilder);
|
||||||
if (stringBuilder.toString().length()>0){
|
if(null==res){
|
||||||
|
return Result.error("-1","","请严格按照模板上传文件");
|
||||||
|
}else if (stringBuilder.toString().length()>0){
|
||||||
return Result.error("-1","",stringBuilder.toString());
|
return Result.error("-1","",stringBuilder.toString());
|
||||||
}else {
|
}else {
|
||||||
return Result.success(res);
|
return Result.success(res);
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface IExportService {
|
public interface IExportService {
|
||||||
|
|
||||||
List<importExcelDTO> delWithWkData(MultipartFile file ,StringBuilder stringBuilder);
|
List<importExcelDTO> delWithWkData(MultipartFile file ,StringBuilder stringBuilder) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -39,7 +39,7 @@ public class IExportServiceImpl implements IExportService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<importExcelDTO> delWithWkData(MultipartFile file ,StringBuilder stringBuilder) {
|
public List<importExcelDTO> delWithWkData(MultipartFile file ,StringBuilder stringBuilder) throws Exception {
|
||||||
|
|
||||||
// //获取数据字典数据
|
// //获取数据字典数据
|
||||||
// Map<String, Object> dicTypeEO = dicTypeEOService.getDicTypeListCode();
|
// Map<String, Object> dicTypeEO = dicTypeEOService.getDicTypeListCode();
|
||||||
@@ -64,6 +64,7 @@ public class IExportServiceImpl implements IExportService {
|
|||||||
tsUserMap.put(tsUser.getAccount(),tsUser.getUname());
|
tsUserMap.put(tsUser.getAccount(),tsUser.getUname());
|
||||||
});
|
});
|
||||||
List<importExcelDTO> res= ExcelImportUtilByWk.readExcelpublic(importExcelDTO.class,file);
|
List<importExcelDTO> res= ExcelImportUtilByWk.readExcelpublic(importExcelDTO.class,file);
|
||||||
|
if (null!=res) {
|
||||||
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
|
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (importExcelDTO importExcelDTO : res) {
|
for (importExcelDTO importExcelDTO : res) {
|
||||||
@@ -116,5 +117,8 @@ public class IExportServiceImpl implements IExportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
}else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
|
|||||||
import com.adc.da.slrs.processModel.entity.importExcelDTO;
|
import com.adc.da.slrs.processModel.entity.importExcelDTO;
|
||||||
import com.adc.da.util.DateUtils;
|
import com.adc.da.util.DateUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
@@ -83,8 +84,15 @@ public class ExcelImportUtilByWk {
|
|||||||
mapExcel.put(Integer.valueOf(excel.orderNum()), excel);
|
mapExcel.put(Integer.valueOf(excel.orderNum()), excel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Row headRow=sheet.getRow(firstRowNum);
|
||||||
|
for (int j=0;j<mapExcel.keySet().size();j++){
|
||||||
|
if (!headRow.getCell(j).toString().equals(mapExcel.get(j).name())){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
|
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
|
||||||
T o = tClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
|
T o = tClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
|
||||||
|
int nums=0;
|
||||||
Row row = sheet.getRow(rowNum);
|
Row row = sheet.getRow(rowNum);
|
||||||
if (null == row) {
|
if (null == row) {
|
||||||
continue;
|
continue;
|
||||||
@@ -96,16 +104,24 @@ public class ExcelImportUtilByWk {
|
|||||||
String value = convertCellValueToString(cell);
|
String value = convertCellValueToString(cell);
|
||||||
Date date= DateUtils.stringToDate(TrainFormDate.dealWithTimeZoneyyyy(value,mapExcel.get(a).exportFormat()),mapExcel.get(a).exportFormat());
|
Date date= DateUtils.stringToDate(TrainFormDate.dealWithTimeZoneyyyy(value,mapExcel.get(a).exportFormat()),mapExcel.get(a).exportFormat());
|
||||||
// Date date= DateUtils.stringToDate(value,mapExcel.get(a).exportFormat());
|
// Date date= DateUtils.stringToDate(value,mapExcel.get(a).exportFormat());
|
||||||
|
if (null==date){
|
||||||
|
nums++;
|
||||||
|
}
|
||||||
map.get(a).set(o, date);
|
map.get(a).set(o, date);
|
||||||
}else {
|
}else {
|
||||||
String value = convertCellValueToString(cell);
|
String value = convertCellValueToString(cell);
|
||||||
|
if (StringUtils.isBlank(value)){
|
||||||
|
nums++;
|
||||||
|
}
|
||||||
map.get(a).set(o, value);
|
map.get(a).set(o, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (nums==0) {
|
||||||
resultDataList.add(o);
|
resultDataList.add(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user