Prechádzať zdrojové kódy

支出记录导入,时间格式错误提示

zouxuan 4 rokov pred
rodič
commit
c8b629a474

+ 12 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/FinancialExpenditureServiceImpl.java

@@ -17,6 +17,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
+import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.IniFileUtil;
 import com.ym.mec.util.excel.POIUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -30,10 +31,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -130,6 +128,15 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
 							objectMap.put("cooperationOrganId", integer);
 						}
 					}
+					if (columnValue.equals("paymentTime") && StringUtils.isNotEmpty(row.get(s).toString())) {
+						String toString = row.get(s).toString();
+						if(StringUtils.isNotEmpty(toString)){
+							Date date = DateUtil.stringToDate(toString, DateUtil.DEFAULT_PATTERN);
+							if(date == null){
+								throw new BizException("导入数据错误  付款时间格式错误");
+							}
+						}
+					}
 					objectMap.put(columnValue, row.get(s));
 				}
 				FinancialExpenditure financialExpenditure = null;
@@ -137,7 +144,7 @@ public class FinancialExpenditureServiceImpl extends BaseServiceImpl<Long, Finan
 					financialExpenditure = JSONObject.parseObject(objectMap.toJSONString(),FinancialExpenditure.class);
 					financialExpenditures.add(financialExpenditure);
 				} catch (Exception ex) {
-					throw new BizException("导入数据出错");
+					throw new BizException("导入数据出错,请检查Excel表格");
 				}
 			}
 		}

+ 1 - 1
mec-util/src/main/java/com/ym/mec/util/excel/POIUtil.java

@@ -479,7 +479,7 @@ public class POIUtil {
 					cellIter = row.iterator();
 					// 列号清零
 					currentCellNum = 0;
-					while (cellIter.hasNext()) {
+					while (cellIter.hasNext() && currentCellNum < fieldsName.length) {
 						cell = cellIter.next();
 						int columnIndex = cell.getColumnIndex();
 						cell.setCellType(Cell.CELL_TYPE_STRING);

BIN
mec-web/src/main/resources/excelTemplate/财务支出导入模板.xls