anderx лет назад: 4
Родитель
Сommit
d3d924d49d

+ 6 - 0
src/main/java/com/goafanti/common/error/SystemExceptionResolver.java

@@ -75,6 +75,12 @@ public class SystemExceptionResolver extends SimpleMappingExceptionResolver{
 				message = errorResource.getProperty(ex.getClass().getName());
 			}
 			error = new Error((String) message);
+		}else if (ex instanceof ClassCastException) {
+			Object message = errorResource.getProperty(ex.getMessage());
+			if (message == null) {
+				message = errorResource.getProperty(ex.getClass().getName());
+			}
+			error = new Error((String) message);
 		} else {
 			error = new Error((String) errorResource.getProperty(ex.getClass().getName()));
 			LoggerUtils.fmtError(getClass(), ex, "系统异常。");

+ 61 - 11
src/main/java/com/goafanti/user/service/impl/UserChannelServiceImpl.java

@@ -1,8 +1,11 @@
 package com.goafanti.user.service.impl;
 
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -10,6 +13,7 @@ import java.util.UUID;
 
 import javax.annotation.Resource;
 
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.Row;
@@ -151,25 +155,25 @@ public class UserChannelServiceImpl extends BaseMybatisDao<UserChannelMapper> im
 			    	try {
 			        switch (cellNum) {
 						case 0:
-							in.setUserName(ExcelUtils.getCellValue(cell));
+							in.setUserName(getCellValue(cell));
 							break;
 						case 1:
-							in.setProvince(getProvinceId(pList,ExcelUtils.getCellValue(cell)));
+							in.setProvince(getProvinceId(pList,getCellValue(cell)));
 							break;
 						case 2:
-							in.setCity(getCityId(cList,ExcelUtils.getCellValue(cell)));
+							in.setCity(getCityId(cList,getCellValue(cell)));
 							break;
 						case 3:
-							in.setSocietyTag(SocietyTag.getCodeByValue(ExcelUtils.getCellValue(cell)).toString());
+							in.setSocietyTag(SocietyTag.getCodeByValue(getCellValue(cell)).toString());
 							break;
 						case 4:
-							in.setContacts(ExcelUtils.getCellValue(cell));
+							in.setContacts(getCellValue(cell));
 							break;
 						case 5:
-							in.setContactMobile(ExcelUtils.getCellValue(cell));
+							in.setContactMobile(getCellValue(cell));
 							break;
 				    	case 6:
-							in.setRemarks(ExcelUtils.getCellValue(cell));
+							in.setRemarks(getCellValue(cell));
 							break;
 						}
 			    	} catch (Exception e) {
@@ -226,16 +230,62 @@ public class UserChannelServiceImpl extends BaseMybatisDao<UserChannelMapper> im
     	if(list2.isEmpty()&&list3.isEmpty()) {
     		return 1;
     	}else {
-    		userMapper.insertBatch(list3);
-    		organizationIdentityMapper.insertBatch(list3);
-    		organizationContactBookMapper.insertBatch(list3);
-    		list2.addAll(list3);
+    		if(!list3.isEmpty()){
+    			userMapper.insertBatch(list3);
+    			organizationIdentityMapper.insertBatch(list3);
+    			organizationContactBookMapper.insertBatch(list3);
+    			list2.addAll(list3);
+    		}
     		userChannelMapper.insertBatch(list2);
     		return  getErorrList(1,10);
     	}
     	
     	
     }
+	
+	
+	  /**
+     * 获取Excel单元格的值
+     *
+     * @param cell
+     * @return
+     */
+    public static String  getCellValue(Cell cell) {
+        String value = "";
+        if (cell != null) {
+            switch (cell.getCellTypeEnum()) {
+                case NUMERIC:  //数字
+                    value = cell.getNumericCellValue() + "";
+                    if (HSSFDateUtil.isCellDateFormatted(cell)) {
+                        Date date = cell.getDateCellValue();
+                        if (date != null) {
+                            value = new SimpleDateFormat("yyyy-MM-dd").format(date);//日期格式化
+                        } else {
+                            value = "";
+                        }
+                    } else {
+                        //在解析cell的时候,数字类型默认是double的,但是想要的的整数的类型,需要格式化,很重要
+                        value = new DecimalFormat("0").format(cell.getNumericCellValue());
+                    }
+                    break;
+                case STRING://字符串
+                    value = cell.getStringCellValue();
+                    break;
+                case BOOLEAN://boolean类型
+                    value = cell.getBooleanCellValue() + "";
+                    break;
+                case BLANK://空值
+                    value = "";
+                    break;
+                case ERROR://错误类型
+                    value = "非法字符";
+                    break;
+                default:
+                    value = "未知类型";
+            }
+        }
+        return value.trim();
+    }
 
 	
 

+ 6 - 6
src/main/resources/props/config_local.properties

@@ -1,13 +1,13 @@
 #Driver
 jdbc.driverClassName=com.mysql.jdbc.Driver
 #本地
-#jdbc.url=jdbc\:mysql://localhost:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
-#jdbc.username=root
-#jdbc.password=123456
-#测试
-jdbc.url=jdbc:mysql://101.37.32.31:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+jdbc.url=jdbc\:mysql://localhost:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
 jdbc.username=root
-jdbc.password=aftdev
+jdbc.password=123456
+#测试
+#jdbc.url=jdbc:mysql://101.37.32.31:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+#jdbc.username=root
+#jdbc.password=aftdev
 #\u68c0\u6d4b\u6570\u636e\u5e93\u94fe\u63a5\u662f\u5426\u6709\u6548\uff0c\u5fc5\u987b\u914d\u7f6e
 jdbc.validationQuery=SELECT 'x'
 #\u521d\u59cb\u8fde\u63a5\u6570