Parcourir la source

添加房屋信息

gushoubang il y a 10 mois
Parent
commit
5e9817d0ea

BIN
data/excel/三亚山水国际峰秀阁10栋.xlsx


+ 14 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/fcfh/FcfhController.java

@@ -5,11 +5,13 @@ import com.onemap.apply.service.fcfh.FcfhService;
 import com.onemap.common.core.web.domain.RequestResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
+import java.io.IOException;
 
 @RestController
 @RequestMapping("fcfh")
@@ -17,6 +19,18 @@ public class FcfhController {
     @Autowired
     FcfhService fcfhService;
 
+    /**
+     * 通过excel插入全部的住户数据
+     *
+     * @return
+     * @throws IOException
+     */
+    @GetMapping("/AddHouseInfo")
+    public RequestResult AddList() throws IOException {
+        RequestResult requestResult = fcfhService.insertData();
+        return requestResult;
+    }
+
     @GetMapping("/GetHouseInfo")
     public RequestResult GetList(@Valid @NotNull String id) {
         HouseDTO houseDTO = fcfhService.getById(id);

+ 15 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/fcfh/HouseDTO.java

@@ -1,5 +1,6 @@
 package com.onemap.apply.domain.fcfh;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
@@ -8,13 +9,27 @@ import lombok.Data;
 @Data
 public class HouseDTO {
     private String id;
+    // 小区名称
     private String community;
+    // 栋
     private String building;
+    // 楼层
     private Integer floor;
+    // 房间
     private String room;
+    // 权利人,住户名称
+    @TableField(value = "resident_name")
     private String residentName;
+    // 证件号,身份证/军官证/营业执照
+    @TableField(value = "id_number")
     private String idNumber;
+    // 套内面积
+    @TableField(value = "inner_area")
     private Float innerArea;
+    // 证书号
+    @TableField(value = "certificate_number")
     private String certificateNumber;
+    // 房号
+    @TableField(value = "room_info")
     private String roomInfo;
 }

+ 2 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/mapper/fcfh/FcfhMapper.java

@@ -5,4 +5,6 @@ import com.onemap.apply.domain.fcfh.HouseDTO;
 
 public interface FcfhMapper extends BaseMapper<HouseDTO> {
     HouseDTO getById(String id);
+
+    void delAll();
 }

+ 5 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/fcfh/FcfhService.java

@@ -1,7 +1,12 @@
 package com.onemap.apply.service.fcfh;
 
 import com.onemap.apply.domain.fcfh.HouseDTO;
+import com.onemap.common.core.web.domain.RequestResult;
+
+import java.io.IOException;
 
 public interface FcfhService {
+    RequestResult insertData() throws IOException;
+
     HouseDTO getById(String id);
 }

+ 65 - 1
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/impl/fcfh/FcfhServiceImpl.java

@@ -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);

+ 5 - 1
onemap-modules/onemap-apply/src/main/resources/mapper/postgresql/fcfh/GdMapper.xml

@@ -20,6 +20,10 @@
     <select id="getById" resultMap="tHouseMap">
         SELECT *
         FROM t_yzt_house
-        WHERE id = #{id}::uuid
+        WHERE id = #{id}
     </select>
+    <delete id="delAll" >
+        delete
+        from t_yzt_house
+    </delete>
 </mapper>