|
@@ -151,25 +151,33 @@ public class EsNetworkEntryController {
|
151
|
151
|
})
|
152
|
152
|
@PostMapping(value= "/emergencySupport/esNetworkEntry/importByEntity", headers= "content-type= multipart/form-data", consumes= "multipart/*")
|
153
|
153
|
public Map<String,Object> importByEntity(@RequestParam(value= "file", required = true) MultipartFile file) throws Exception {
|
154
|
|
-
|
155
|
|
- Map<String,Object> map = new HashMap<String,Object>();
|
156
|
|
- if(file== null){
|
157
|
|
- map.put("massage","无文件数据");
|
158
|
|
- map.put("status","500");
|
159
|
|
- return map;
|
160
|
|
- }
|
161
|
|
- //获得文件名
|
162
|
|
- String fileName = file.getOriginalFilename();
|
163
|
|
- //判断文件是否是excel文件
|
164
|
|
- if (!fileName.endsWith("xls") && !fileName.endsWith("xlsx")) {
|
165
|
|
- map.put("massage","请使用正确的导入模板");
|
166
|
|
- map.put("status","500");
|
|
154
|
+ Map<String, Object> map = new HashMap<>();
|
|
155
|
+
|
|
156
|
+ try {
|
|
157
|
+ // Check if file is null
|
|
158
|
+ if (file == null) {
|
|
159
|
+ map.put("message", "无文件数据"); // Note: corrected the typo from "massage" to "message"
|
|
160
|
+ map.put("status", "500");
|
|
161
|
+ return map;
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ // Get the file name
|
|
165
|
+ String fileName = file.getOriginalFilename();
|
|
166
|
+
|
|
167
|
+ // Check if the file is an Excel file
|
|
168
|
+ if (fileName == null || (!fileName.endsWith("xls") && !fileName.endsWith("xlsx"))) {
|
|
169
|
+ map.put("message", "请使用正确的导入模板"); // Note: corrected the typo from "massage" to "message"
|
|
170
|
+ map.put("status", "500");
|
|
171
|
+ return map;
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ // Process the file using the service
|
|
175
|
+ return esNetworkEntryService.importByEntityResult(file, map);
|
|
176
|
+ } catch (Exception e) {
|
|
177
|
+ // Handle exceptions
|
|
178
|
+ map.put("message", "文件处理失败: " + e.getMessage());
|
|
179
|
+ map.put("status", "500");
|
167
|
180
|
return map;
|
168
|
181
|
}
|
169
|
|
-
|
170
|
|
- return esNetworkEntryService.importByEntityResult(file,map);
|
171
|
|
-
|
172
|
182
|
}
|
173
|
|
-
|
174
|
|
-
|
175
|
183
|
}
|