rain
2024-03-28 a83ae77a98e235cdca07a1bb167a9a43479a2c9a
新增图斑数据返回
3 files modified
33 ■■■■■ changed files
src/main/java/com/dji/sample/patches/controller/ShpToDataSourceController.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java 4 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java 21 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/ShpToDataSourceController.java
@@ -1,6 +1,7 @@
package com.dji.sample.patches.controller;
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.service.impl.ShpToDataSourceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -8,6 +9,7 @@
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("${url.patches.prefix}${url.patches.version}")
@@ -15,9 +17,9 @@
    @Autowired
    private ShpToDataSourceServiceImpl shpToDataSourceServiceImpl;
    @PostMapping("/getGeo")
    public ResponseResult getGeo (@RequestParam("file") MultipartFile file) throws IOException {
        shpToDataSourceServiceImpl.insertGeo(file);
        return  ResponseResult.success();
    public ResponseResult<List<LotInfo>> getGeo (@RequestParam("file") MultipartFile file) throws IOException {
        List<LotInfo> list=shpToDataSourceServiceImpl.insertGeo(file);
        return  ResponseResult.success(list);
    }
src/main/java/com/dji/sample/patches/service/ShpToDataSourceService.java
@@ -1,8 +1,10 @@
package com.dji.sample.patches.service;
import com.dji.sample.patches.model.entity.LotInfo;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface ShpToDataSourceService {
    void insertGeo(MultipartFile file) throws IOException;
    List<LotInfo> insertGeo(MultipartFile file) throws IOException;
}
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -12,6 +12,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -21,29 +22,29 @@
public class ShpToDataSourceServiceImpl implements ShpToDataSourceService {
    @Autowired
    private ShpToDataSourceMapper mapper;
    String Land = "N1C1D";
    String head = POLYGON;
    String json;
    public void insertGeo(MultipartFile file) throws IOException {
        LotInfo patches = new LotInfo();
    public List<LotInfo> insertGeo(MultipartFile file) throws IOException {
        List<LotInfo> list=new ArrayList<>();
        MultipartFileTOFileUtil multipartFileTOFileUtil = new MultipartFileTOFileUtil();
        File file1 = multipartFileTOFileUtil.multipartFile2File(file);
        List<String> s = ShapeFileUtil.shpToGeoJson(file1);
        String[] arr1 = FormatConversionUtil.formatConversion(s);
        for (int i = 0; i < arr1.length; i++) {
            int count = mapper.selectCount(null) + 1;
            LotInfo lotInfo = new LotInfo();
            String temp = arr1[i].trim();
            temp = FormatConversionUtil.modifySpacesAndCommas(temp);
            json = head + temp;
            String uuid = UUID.randomUUID().toString();
            String bsm = uuid.replaceAll("-", "");
            patches.setBsm(bsm);
            patches.setDkfw(json);
            patches.setDkbh(Land + count);
            mapper.insert(patches);
            lotInfo.setBsm(bsm);
            lotInfo.setDkfw(json);
            lotInfo.setDkbh("dkbh"+i);
            mapper.insert(lotInfo);
            list.add(lotInfo);
            System.out.println(lotInfo);
        }
        return list;
    }
}