公共导入方法 新增校验模板功能 过滤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 {
|
||||
StringBuilder stringBuilder=new 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());
|
||||
}else {
|
||||
return Result.success(res);
|
||||
|
||||
@@ -7,6 +7,6 @@ import java.util.List;
|
||||
|
||||
public interface IExportService {
|
||||
|
||||
List<importExcelDTO> delWithWkData(MultipartFile file ,StringBuilder stringBuilder);
|
||||
List<importExcelDTO> delWithWkData(MultipartFile file ,StringBuilder stringBuilder) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
+48
-44
@@ -39,7 +39,7 @@ public class IExportServiceImpl implements IExportService {
|
||||
|
||||
|
||||
@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();
|
||||
@@ -64,57 +64,61 @@ public class IExportServiceImpl implements IExportService {
|
||||
tsUserMap.put(tsUser.getAccount(),tsUser.getUname());
|
||||
});
|
||||
List<importExcelDTO> res= ExcelImportUtilByWk.readExcelpublic(importExcelDTO.class,file);
|
||||
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
|
||||
int i=1;
|
||||
for (importExcelDTO importExcelDTO: res) {
|
||||
if (null!=importExcelDTO.getWgLeader() && !"".equals(importExcelDTO.getWgLeader())) {
|
||||
importExcelDTO.setWgLeaderName(tsUserMap.get(importExcelDTO.getWgLeader()));
|
||||
if (null == tsUserMap.get(importExcelDTO.getWgLeader())) {
|
||||
stringBuilder.append("第" + i + "行第7列工作组组长填写不符合格式要求请检查;");
|
||||
if (null!=res) {
|
||||
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
|
||||
int i = 1;
|
||||
for (importExcelDTO importExcelDTO : res) {
|
||||
if (null != importExcelDTO.getWgLeader() && !"".equals(importExcelDTO.getWgLeader())) {
|
||||
importExcelDTO.setWgLeaderName(tsUserMap.get(importExcelDTO.getWgLeader()));
|
||||
if (null == tsUserMap.get(importExcelDTO.getWgLeader())) {
|
||||
stringBuilder.append("第" + i + "行第7列工作组组长填写不符合格式要求请检查;");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null!=importExcelDTO.getUnitName() && !"".equals(importExcelDTO.getUnitName())){
|
||||
importExcelDTO.setUnit(tsInstitutionMap.get(importExcelDTO.getUnitName()));
|
||||
if (null==tsInstitutionMap.get(importExcelDTO.getUnitName())){
|
||||
stringBuilder.append("第"+i+"行第4列起草责任单位填写不符合格式要求请检查;");
|
||||
if (null != importExcelDTO.getUnitName() && !"".equals(importExcelDTO.getUnitName())) {
|
||||
importExcelDTO.setUnit(tsInstitutionMap.get(importExcelDTO.getUnitName()));
|
||||
if (null == tsInstitutionMap.get(importExcelDTO.getUnitName())) {
|
||||
stringBuilder.append("第" + i + "行第4列起草责任单位填写不符合格式要求请检查;");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null!=importExcelDTO.getDrafter() && !"".equals(importExcelDTO.getDrafter())){
|
||||
importExcelDTO.setDrafterName(tsUserMap.get(importExcelDTO.getDrafter()));
|
||||
if ( null==tsUserMap.get(importExcelDTO.getDrafter())){
|
||||
stringBuilder.append("第"+i+"行第5列起草人填写不符合格式要求请检查;");
|
||||
if (null != importExcelDTO.getDrafter() && !"".equals(importExcelDTO.getDrafter())) {
|
||||
importExcelDTO.setDrafterName(tsUserMap.get(importExcelDTO.getDrafter()));
|
||||
if (null == tsUserMap.get(importExcelDTO.getDrafter())) {
|
||||
stringBuilder.append("第" + i + "行第5列起草人填写不符合格式要求请检查;");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null!=importExcelDTO.getResPerson() && !"".equals(importExcelDTO.getResPerson())){
|
||||
importExcelDTO.setResPersonName(tsUserMap.get(importExcelDTO.getResPerson()));
|
||||
if ( null==tsUserMap.get(importExcelDTO.getResPerson())){
|
||||
stringBuilder.append("第"+i+"行第6列评审责任人填写不符合格式要求请检查;");
|
||||
if (null != importExcelDTO.getResPerson() && !"".equals(importExcelDTO.getResPerson())) {
|
||||
importExcelDTO.setResPersonName(tsUserMap.get(importExcelDTO.getResPerson()));
|
||||
if (null == tsUserMap.get(importExcelDTO.getResPerson())) {
|
||||
stringBuilder.append("第" + i + "行第6列评审责任人填写不符合格式要求请检查;");
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (null!=importExcelDTO.getEndTime() && !"".equals(importExcelDTO.getEndTime())) {
|
||||
importExcelDTO.setEndTime(formater.format(HSSFDateUtil.getJavaDate(Double.valueOf(importExcelDTO.getEndTime()))));
|
||||
try {
|
||||
if (null != importExcelDTO.getEndTime() && !"".equals(importExcelDTO.getEndTime())) {
|
||||
importExcelDTO.setEndTime(formater.format(HSSFDateUtil.getJavaDate(Double.valueOf(importExcelDTO.getEndTime()))));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stringBuilder.append("第" + i + "行第10列立项完成时间填写不符合格式要求请检查;");
|
||||
}
|
||||
}catch (Exception e){
|
||||
stringBuilder.append("第"+i+"行第10列立项完成时间填写不符合格式要求请检查;");
|
||||
}
|
||||
try {
|
||||
if (null!=importExcelDTO.getReleaseTime() && !"".equals(importExcelDTO.getReleaseTime())) {
|
||||
importExcelDTO.setReleaseTime(formater.format(HSSFDateUtil.getJavaDate(Double.valueOf(importExcelDTO.getReleaseTime()))));
|
||||
try {
|
||||
if (null != importExcelDTO.getReleaseTime() && !"".equals(importExcelDTO.getReleaseTime())) {
|
||||
importExcelDTO.setReleaseTime(formater.format(HSSFDateUtil.getJavaDate(Double.valueOf(importExcelDTO.getReleaseTime()))));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stringBuilder.append("第" + i + "行第9列计划标准发布时间填写不符合格式要求请检查;");
|
||||
}
|
||||
}catch (Exception e){
|
||||
stringBuilder.append("第"+i+"行第9列计划标准发布时间填写不符合格式要求请检查;");
|
||||
}
|
||||
try {
|
||||
if (null!=importExcelDTO.getDraftTime() && !"".equals(importExcelDTO.getDraftTime())) {
|
||||
importExcelDTO.setDraftTime(formater.format(HSSFDateUtil.getJavaDate(Double.valueOf(importExcelDTO.getDraftTime()))));
|
||||
try {
|
||||
if (null != importExcelDTO.getDraftTime() && !"".equals(importExcelDTO.getDraftTime())) {
|
||||
importExcelDTO.setDraftTime(formater.format(HSSFDateUtil.getJavaDate(Double.valueOf(importExcelDTO.getDraftTime()))));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
stringBuilder.append("第" + i + "行第8列计划初稿完成日期填写不符合格式要求请检查;");
|
||||
}
|
||||
}catch (Exception e){
|
||||
stringBuilder.append("第"+i+"行第8列计划初稿完成日期填写不符合格式要求请检查;");
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import com.adc.da.slrs.processModel.entity.importExcelDTO;
|
||||
import com.adc.da.util.DateUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
@@ -33,7 +34,7 @@ public class ExcelImportUtilByWk {
|
||||
* @param file 上传的Excel文件
|
||||
* @return 读取结果列表,读取失败时返回null
|
||||
*/
|
||||
public static <T> List<T> readExcelpublic(Class<T> tClass,MultipartFile file) {
|
||||
public static <T> List<T> readExcelpublic(Class<T> tClass,MultipartFile file) {
|
||||
|
||||
Workbook workbook = null;
|
||||
|
||||
@@ -83,8 +84,15 @@ public class ExcelImportUtilByWk {
|
||||
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++) {
|
||||
T o = tClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
|
||||
int nums=0;
|
||||
Row row = sheet.getRow(rowNum);
|
||||
if (null == row) {
|
||||
continue;
|
||||
@@ -96,13 +104,21 @@ public class ExcelImportUtilByWk {
|
||||
String value = convertCellValueToString(cell);
|
||||
Date date= DateUtils.stringToDate(TrainFormDate.dealWithTimeZoneyyyy(value,mapExcel.get(a).exportFormat()),mapExcel.get(a).exportFormat());
|
||||
// Date date= DateUtils.stringToDate(value,mapExcel.get(a).exportFormat());
|
||||
if (null==date){
|
||||
nums++;
|
||||
}
|
||||
map.get(a).set(o, date);
|
||||
}else {
|
||||
String value = convertCellValueToString(cell);
|
||||
if (StringUtils.isBlank(value)){
|
||||
nums++;
|
||||
}
|
||||
map.get(a).set(o, value);
|
||||
}
|
||||
}
|
||||
resultDataList.add(o);
|
||||
if (nums==0) {
|
||||
resultDataList.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user