rain
2024-03-25 471b033688cf85f503081e7401163bcc5fa45351
图斑
10 files modified
1 files added
143 ■■■■ changed files
src/main/java/com/dji/sample/patches/controller/DemoController.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/PatchesController.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/dao/DemoMapper.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/dao/PatchesMapper.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/model/PatchesEntity.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/DemoService.java 7 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/PatchesService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/DemoServiceImpl.java 38 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/PatchesServiceImpl.java 7 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/utils/MultipartFileTOFile.java 41 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java 7 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/DemoController.java
@@ -2,8 +2,8 @@
import com.dji.sample.patches.service.impl.DemoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@@ -11,11 +11,14 @@
import java.io.IOException;
@RestController
@RequestMapping("${url.patches.prefix}${url.patches.version}")
public class DemoController {
    @Autowired
    private  DemoServiceImpl demoServiceImpl;
    @GetMapping("/getGeo")
    public void getGeo (File file) throws IOException {
    @PostMapping("/getGeo")
    public void getGeo (@RequestParam("file") MultipartFile file) throws IOException {
        demoServiceImpl.insertGeo(file);
    }
}
src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -1,26 +1,23 @@
package com.dji.sample.patches.controller;
import com.dji.sample.patches.model.PageBean;
import com.dji.sample.patches.service.impl.PatchesServiceImpl;
import com.dji.sample.patches.service.PatchesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Array;
@RequestMapping("${url.patches.prefix}${url.patches.version}")
@RestController
public class PatchesController {
    @Autowired
    private PatchesServiceImpl patchesServiceimpl;
    private PatchesService patchesService;
    @GetMapping("/getPatches")
    public PageBean page(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "5") Integer pageSize,
                         Integer id, String dkbh, String dkfw){
                         @RequestParam(defaultValue = "5") Integer pageSize) {
        //调用service分页查询
        PageBean pageBean =patchesServiceimpl.limitGet( id,  dkbh, dkfw,page, pageSize);
        PageBean pageBean = patchesService.limitGet(page, pageSize);
        return pageBean;
    }
}
src/main/java/com/dji/sample/patches/dao/DemoMapper.java
@@ -2,9 +2,15 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dji.sample.patches.model.DemoEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
@Mapper
public interface DemoMapper extends BaseMapper<DemoEntity> {
    void insertJson(String json);
    @Insert("insert into tb_lot_info (dkfw,bsm,create_time,update_time) values (#{json},#{bsm},#{createTime},#{updateTime})")
    void insertJson(String json,String bsm, int createTime, int updateTime);
}
src/main/java/com/dji/sample/patches/dao/PatchesMapper.java
@@ -7,5 +7,5 @@
public interface PatchesMapper {
    @Select("select id ,dkbh,dkfw  from tb_lot_info")
    List<PatchesEntity> limitGet(@Param("id") Integer id, @Param("dkbh") String dkbh, @Param("dkfw") String dkfw);
    List<PatchesEntity> limitGet();
}
src/main/java/com/dji/sample/patches/model/PatchesEntity.java
@@ -62,11 +62,10 @@
    private String sjlx;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private LocalDateTime createTime;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private int createTime;
    @TableField("update_time")
    private LocalDateTime updateTime;
    private int updateTime;
}
src/main/java/com/dji/sample/patches/service/DemoService.java
@@ -1,8 +1,13 @@
package com.dji.sample.patches.service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
public interface DemoService {
    void insertGeo(File file) throws IOException;
    public static void main(String[] args) {
    }
    void insertGeo(MultipartFile file) throws IOException;
}
src/main/java/com/dji/sample/patches/service/PatchesService.java
@@ -7,5 +7,5 @@
import java.sql.Array;
public interface PatchesService {
    PageBean limitGet (Integer id, String dkbh, String dkfw , int page, int pageSize);
    PageBean limitGet (int page, int pageSize);
}
src/main/java/com/dji/sample/patches/service/impl/DemoServiceImpl.java
@@ -1,19 +1,47 @@
package com.dji.sample.patches.service.impl;
import cn.hutool.core.io.FileUtil;
import com.dji.sample.patches.dao.DemoMapper;
import com.dji.sample.patches.service.DemoService;
import com.dji.sample.patches.utils.MultipartFileTOFile;
import com.dji.sample.patches.utils.ShapeFileUtil;
import com.dji.sample.patches.utils.ZipUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@Service
public class DemoServiceImpl implements DemoService {
    @Autowired
    private DemoMapper mapper;
    private ShapeFileUtil shapeFileUtil;
      @Override
      public void insertGeo(File file) throws IOException {
          System.out.println(shapeFileUtil.shpToGeoJson(file));
    private int createTime=0;
    private int updateTime=0;
    private String bsm;
      public void insertGeo(MultipartFile file) throws IOException {
          ShapeFileUtil shapeFileUtil=new ShapeFileUtil();
          MultipartFileTOFile multipartFileTOFile= new MultipartFileTOFile();
          File file1= multipartFileTOFile.multipartFile2File(file);
          List<String> s=shapeFileUtil.shpToGeoJson(file1);
          String[] arr=new String[10];
          String str=s.toString();
          String ses=str.substring(0, str.length()-3);
          String[] arr1=ses.split("]],");
          for (int i = 0; i < arr1.length; i++) {
              bsm=UUID.randomUUID().toString()+1;
              String json= arr1[i].substring(3);
              arr[i]=json;
              mapper.insertJson(json,bsm,createTime,updateTime);
          }
      }
  }
}
src/main/java/com/dji/sample/patches/service/impl/PatchesServiceImpl.java
@@ -20,15 +20,12 @@
    private PatchesMapper mapper;
    @Override
    public PageBean limitGet(Integer id, String dkbh, String dkfw,int page, int pageSize) {
    public PageBean limitGet(int page, int pageSize) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);
        //2. 执行查询
        List<PatchesEntity> PatchersList = mapper.limitGet(id,dkbh,dkfw);
        List<PatchesEntity> PatchersList = mapper.limitGet();
        com.github.pagehelper.Page<PatchesEntity> p = (Page<PatchesEntity>) PatchersList;
        //3. 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
src/main/java/com/dji/sample/patches/utils/MultipartFileTOFile.java
New file
@@ -0,0 +1,41 @@
package com.dji.sample.patches.utils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.UUID;
public class MultipartFileTOFile {
    public File multipartFile2File (MultipartFile multipartFile) {
        String tmpFileDir = null;
        // 创建临时文件
        String randomFileName = UUID.randomUUID().toString();
        tmpFileDir = "D:/tmp/"+randomFileName;
        File file = new File(tmpFileDir);
        InputStream inputStream = null;
        FileOutputStream outputStream = null;
        try {
            // 获取文件输入流
            inputStream = multipartFile.getInputStream();
            if (!file.exists()) {
                file.createNewFile();
            }
            // 创建输出流
            outputStream = new FileOutputStream(file);
            byte[] bytes = new byte[1024];
            int len;
            // 写入到创建的临时文件
            while ((len = ((InputStream) inputStream).read(bytes)) > 0) {
                outputStream.write(bytes, 0, len);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        ZipUtil.deleteFiles(tmpFileDir);
        return file;
    }
}
src/main/java/com/dji/sample/patches/utils/ShapeFileUtil.java
@@ -65,10 +65,11 @@
     * @description 通过shp压缩文件,将其转换为GeoJson格式
     * @date 2023/7/18 16:04
     */
    public static JSONObject shpToGeoJson(File zipFile) throws IOException {
    public static List<String> shpToGeoJson(File zipFile) throws IOException {
        FeatureJSON fjson = new FeatureJSON();
        JSONObject geoJsonObject=new JSONObject();
        geoJsonObject.put("type","FeatureCollection");
        List<String> strings=new ArrayList<>();
        try {
            // 获取FeatureCollection
            FeatureCollection collection = getFeatureCollectionByShpFile(zipFile);
@@ -84,6 +85,8 @@
                byte[] b = temp.getBytes("iso8859-1");
                temp = new String(b, "gbk");
                JSONObject json = JSONObject.parseObject(temp);
                String str2 = json.getJSONObject("geometry").get("coordinates").toString();
                strings.add(str2);
                array.add(json);
            }
            iterator.close();
@@ -94,7 +97,7 @@
        }catch (Exception e){
            throw e;
        }
        return geoJsonObject;
        return strings;
    }
}