|
@@ -16,13 +16,22 @@ import com.huiju.estateagents.mapper.TaPreselectionRecordMapper;
|
16
|
16
|
import com.huiju.estateagents.po.TaHousingResourcesPO;
|
17
|
17
|
import com.huiju.estateagents.service.ITaHousingResourcesService;
|
18
|
18
|
import org.apache.commons.collections.CollectionUtils;
|
|
19
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
20
|
+import org.apache.poi.ss.usermodel.Row;
|
|
21
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
22
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
23
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
19
|
24
|
import org.slf4j.Logger;
|
20
|
25
|
import org.slf4j.LoggerFactory;
|
21
|
26
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
27
|
import org.springframework.stereotype.Service;
|
|
28
|
+import org.springframework.web.multipart.MultipartFile;
|
|
29
|
+
|
23
|
30
|
import java.time.LocalDateTime;
|
24
|
31
|
import java.util.ArrayList;
|
|
32
|
+import java.util.HashMap;
|
25
|
33
|
import java.util.List;
|
|
34
|
+import java.util.Map;
|
26
|
35
|
|
27
|
36
|
/**
|
28
|
37
|
* <p>
|
|
@@ -324,6 +333,106 @@ public class TaHousingResourcesServiceImpl extends ServiceImpl<TaHousingResource
|
324
|
333
|
return ResponseBean.success(taHousingResources);
|
325
|
334
|
}
|
326
|
335
|
|
|
336
|
+ /**
|
|
337
|
+ * 获取表格中的数据
|
|
338
|
+ *
|
|
339
|
+ * @param file
|
|
340
|
+ * @return
|
|
341
|
+ */
|
|
342
|
+ @Override
|
|
343
|
+ public ResponseBean getExcelData(MultipartFile file) {
|
|
344
|
+ ResponseBean responseBean = new ResponseBean();
|
|
345
|
+ List<TaHousingResources> list = new ArrayList<>();
|
|
346
|
+ if (file == null) {
|
|
347
|
+ responseBean.addError("对象不能为空");
|
|
348
|
+ return responseBean;
|
|
349
|
+ }
|
|
350
|
+ //获取文件的名字
|
|
351
|
+ String originalFilename = file.getOriginalFilename();
|
|
352
|
+ Workbook workbook = null;
|
|
353
|
+ try {
|
|
354
|
+ if (originalFilename.endsWith(CommConstant.SUFFIX_2003)) {
|
|
355
|
+ workbook = new HSSFWorkbook(file.getInputStream());
|
|
356
|
+ } else if (originalFilename.endsWith(CommConstant.SUFFIX_2007)) {
|
|
357
|
+ workbook = new XSSFWorkbook(file.getInputStream());
|
|
358
|
+ }
|
|
359
|
+ } catch (Exception e) {
|
|
360
|
+ logger.info(originalFilename);
|
|
361
|
+ e.printStackTrace();
|
|
362
|
+ responseBean.addError("格式错误");
|
|
363
|
+ return responseBean;
|
|
364
|
+ }
|
|
365
|
+ if (workbook == null) {
|
|
366
|
+ logger.info(originalFilename);
|
|
367
|
+ responseBean.addError("格式错误");
|
|
368
|
+ return responseBean;
|
|
369
|
+ } else {
|
|
370
|
+ List<String> temHousingList = new ArrayList<String>();
|
|
371
|
+ //获取一个sheet也就是一个工作簿
|
|
372
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
373
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
374
|
+ //从第一行开始第一行一般是标题
|
|
375
|
+ for (int j = 3; j <= lastRowNum; j++) {
|
|
376
|
+ Row row = sheet.getRow(j);
|
|
377
|
+ TaHousingResources taHousingResources = new TaHousingResources();
|
|
378
|
+ String termName = row.getCell(0).getStringCellValue().trim();
|
|
379
|
+ String blockName = row.getCell(1).getStringCellValue().trim();
|
|
380
|
+ String unitName = row.getCell(2).getStringCellValue().trim();
|
|
381
|
+ String floorName = row.getCell(3).getStringCellValue().trim();
|
|
382
|
+ String roomName = row.getCell(4).getStringCellValue().trim();
|
|
383
|
+ String price = row.getCell(5).getStringCellValue().trim();
|
|
384
|
+ String heat = row.getCell(6).getStringCellValue().trim();
|
|
385
|
+ Integer status = row.getCell(7).getStringCellValue().trim().equals("是") ? 1 : 0;
|
|
386
|
+
|
|
387
|
+ int currentRow = j+1;
|
|
388
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isEmpty(termName)){
|
|
389
|
+ responseBean.addError("第" + currentRow + "行" + "期/区不能为空!");
|
|
390
|
+ return responseBean;
|
|
391
|
+ }
|
|
392
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isEmpty(blockName)){
|
|
393
|
+ responseBean.addError("第" + currentRow + "行" + "楼栋不能为空!");
|
|
394
|
+ return responseBean;
|
|
395
|
+ }
|
|
396
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isEmpty(unitName)){
|
|
397
|
+ responseBean.addError("第" + currentRow + "行" + "单元不能为空!");
|
|
398
|
+ return responseBean;
|
|
399
|
+ }
|
|
400
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isEmpty(floorName)){
|
|
401
|
+ responseBean.addError("第" + currentRow + "行" + "层不能为空!");
|
|
402
|
+ return responseBean;
|
|
403
|
+ }
|
|
404
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isEmpty(roomName)){
|
|
405
|
+ responseBean.addError("第" + currentRow + "行" + "房号不能为空!");
|
|
406
|
+ return responseBean;
|
|
407
|
+ }
|
|
408
|
+
|
|
409
|
+ String houseInfo = termName + blockName + unitName + floorName + roomName;
|
|
410
|
+ if (temHousingList.contains(houseInfo)){
|
|
411
|
+ logger.info("存在重复房源:{}",houseInfo);
|
|
412
|
+ responseBean.addError("第"+ currentRow +"行存在重复房源");
|
|
413
|
+ return responseBean;
|
|
414
|
+ }
|
|
415
|
+
|
|
416
|
+ //把数据塞入temList校验是否有重复的数据
|
|
417
|
+ temHousingList.add(houseInfo);
|
|
418
|
+ //构建数据
|
|
419
|
+ taHousingResources.setTermName(termName);
|
|
420
|
+ taHousingResources.setBlockName(blockName);
|
|
421
|
+ taHousingResources.setUnitName(unitName);
|
|
422
|
+ taHousingResources.setFloorName(floorName);
|
|
423
|
+ taHousingResources.setRoomName(roomName);
|
|
424
|
+ list.add(taHousingResources);
|
|
425
|
+ }
|
|
426
|
+ }
|
|
427
|
+ //构建分页
|
|
428
|
+ Map<String,Object> data = new HashMap<String, Object>();
|
|
429
|
+ data.put("list",list);
|
|
430
|
+ data.put("total",list.size());
|
|
431
|
+
|
|
432
|
+ responseBean.addSuccess(data);
|
|
433
|
+ return responseBean;
|
|
434
|
+ }
|
|
435
|
+
|
327
|
436
|
//更新房号
|
328
|
437
|
private void updateRoom(TaHousingResources taHousingResources) {
|
329
|
438
|
TaBuildingRoom taBuildingRoom = new TaBuildingRoom();
|