张延森 hace 4 años
padre
commit
cb9acb6158

+ 1
- 1
pom.xml Ver fichero

@@ -10,7 +10,7 @@
10 10
 	</parent>
11 11
 	<groupId>com.huiju</groupId>
12 12
 	<artifactId>xiangsong</artifactId>
13
-	<version>1.0.54</version>
13
+	<version>1.0.55</version>
14 14
 	<name>xiangsong</name>
15 15
 	<description>香颂</description>
16 16
 

+ 29
- 9
src/main/java/com/huiju/estateagents/property/service/impl/BuildingTreeServiceImpl.java Ver fichero

@@ -11,9 +11,7 @@ import com.huiju.estateagents.property.dao.*;
11 11
 import com.huiju.estateagents.property.model.*;
12 12
 import com.huiju.estateagents.property.service.BuildingTreeServiceI;
13 13
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14
-import org.apache.poi.ss.usermodel.Row;
15
-import org.apache.poi.ss.usermodel.Sheet;
16
-import org.apache.poi.ss.usermodel.Workbook;
14
+import org.apache.poi.ss.usermodel.*;
17 15
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
18 16
 import org.slf4j.Logger;
19 17
 import org.slf4j.LoggerFactory;
@@ -100,13 +98,24 @@ public class BuildingTreeServiceImpl implements BuildingTreeServiceI {
100 98
 			for (int j = 3; j <= lastRowNum; j++) {
101 99
 				Row row = sheet.getRow(j);
102 100
 				TpBuildingOwnerInfo tpBuildingOwnerInfo = new TpBuildingOwnerInfo();
103
-				String phase = row.getCell(0).getStringCellValue().trim();
104
-				String building = row.getCell(1).getStringCellValue().trim();
105
-				String unit = row.getCell(2).getStringCellValue().trim();
106
-				String level = row.getCell(3).getStringCellValue().trim();
107
-				String roomNo = row.getCell(4).getStringCellValue().trim();
108
-				
101
+				String phase = null;
102
+				String building = null;
103
+				String unit = null;
104
+				String level = null;
105
+				String roomNo = null;
109 106
 				int currentRow = j+1;
107
+				try {
108
+					phase = getStringOfCell(row.getCell(0));
109
+					building = getStringOfCell(row.getCell(1));
110
+					unit = getStringOfCell(row.getCell(2));
111
+					level = getStringOfCell(row.getCell(3));
112
+					roomNo = getStringOfCell(row.getCell(4));
113
+				} catch (Exception e) {
114
+					e.printStackTrace();
115
+					responseBean.addError(String.format("第 %d 行, 格式错误, 数据只能为字符或数字格式", currentRow));
116
+					return responseBean;
117
+				}
118
+
110 119
 				if (StringUtils.isEmpty(phase)){
111 120
 					responseBean.addError("第" + currentRow + "行" + "期/区不能为空!");
112 121
 					return responseBean;
@@ -154,6 +163,17 @@ public class BuildingTreeServiceImpl implements BuildingTreeServiceI {
154 163
 		responseBean.addSuccess(data);
155 164
 		return responseBean;
156 165
 	}
166
+
167
+	private String getStringOfCell(Cell cell) throws Exception {
168
+		CellType cellTypeEnum = cell.getCellTypeEnum();
169
+		if (cellTypeEnum.equals(CellType.STRING)) {
170
+			return cell.getStringCellValue().trim();
171
+		} else if (cellTypeEnum.equals(CellType.NUMERIC)) {
172
+			return String.valueOf((int) cell.getNumericCellValue()).trim();
173
+		} else {
174
+			throw new Exception("数据内容格式错误");
175
+		}
176
+	}
157 177
 	
158 178
 	/**
159 179
 	 * 上传小区的基础数据