|
@@ -3,15 +3,79 @@ package com.onemap.apply.service.impl.fcfh;
|
|
|
import com.onemap.apply.domain.fcfh.HouseDTO;
|
|
|
import com.onemap.apply.mapper.fcfh.FcfhMapper;
|
|
|
import com.onemap.apply.service.fcfh.FcfhService;
|
|
|
-import com.onemap.common.datasource.annotation.Slave;
|
|
|
+import com.onemap.common.core.utils.uuid.IdUtils;
|
|
|
+import com.onemap.common.core.web.domain.RequestResult;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class FcfhServiceImpl implements FcfhService {
|
|
|
@Autowired(required = false)
|
|
|
FcfhMapper gdMapper;
|
|
|
|
|
|
+ // 数据导入
|
|
|
+ @Override
|
|
|
+ public RequestResult insertData() throws IOException {
|
|
|
+ String fileName = "F:/project/sanya-data-management-back/data/excel/三亚山水国际峰秀阁10栋.xlsx";
|
|
|
+ File file = new File(fileName);
|
|
|
+ if (!file.exists()) {
|
|
|
+ return RequestResult.error("文件不存在");
|
|
|
+ }
|
|
|
+ // 清空全部的
|
|
|
+ gdMapper.delAll();
|
|
|
+
|
|
|
+ InputStream fin = new FileInputStream(file);
|
|
|
+ // 获取工作簿
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(fin);
|
|
|
+ // 获取sheet页
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ // 获取标题行数据
|
|
|
+ Map<String, Integer> headMap = new HashMap<>();
|
|
|
+ if (sheet.getLastRowNum() != 0) {
|
|
|
+ Row head = sheet.getRow(0);
|
|
|
+ for (Cell cell : head) {
|
|
|
+ headMap.put(cell.getStringCellValue(), cell.getColumnIndex());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 1; i < sheet.getLastRowNum(); i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ HouseDTO houseDTO = new HouseDTO();
|
|
|
+ houseDTO.setId(IdUtils.fastUUID());
|
|
|
+ String roomInfo = row.getCell(headMap.get("房号")).getStringCellValue();
|
|
|
+ String[] infos = roomInfo.split("-");
|
|
|
+ houseDTO.setBuilding(infos[0]);
|
|
|
+ // houseDTO.setFloor();
|
|
|
+ houseDTO.setRoom(infos[1]);
|
|
|
+ houseDTO.setResidentName(row.getCell(headMap.get("权利人")).getStringCellValue());
|
|
|
+ houseDTO.setIdNumber(row.getCell(headMap.get("身份证/军官证/营业执照")).getStringCellValue());
|
|
|
+ String areaInfo = row.getCell(headMap.get("套内面积")).getStringCellValue();
|
|
|
+ areaInfo = areaInfo.replaceAll("㎡", "");
|
|
|
+ houseDTO.setInnerArea(Float.parseFloat(areaInfo));
|
|
|
+ houseDTO.setCertificateNumber(row.getCell(headMap.get("证书号")).getStringCellValue());
|
|
|
+ houseDTO.setRoomInfo(roomInfo);
|
|
|
+ gdMapper.insert(houseDTO);
|
|
|
+ }
|
|
|
+ // 数据入库
|
|
|
+ return RequestResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public HouseDTO getById(String id) {
|
|
|
HouseDTO houseDTO = gdMapper.getById(id);
|