|
|
@@ -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();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|