10 files modified
1 files added
| | |
| | | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | |
| | | 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); |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | 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(); |
| | | } |
| | |
| | | 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; |
| | | |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | 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; |
| New file |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | * @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); |
| | |
| | | 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(); |
| | |
| | | }catch (Exception e){ |
| | | throw e; |
| | | } |
| | | return geoJsonObject; |
| | | return strings; |
| | | } |
| | | |
| | | } |