| | |
| | | package com.dji.sample.patches.service.impl; |
| | | |
| | | import com.dji.sample.patches.dao.ShpToDataSourceMapper; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.service.ShpToDataSourceService; |
| | | import com.dji.sample.patches.utils.FormatConversionUtil; |
| | | import com.dji.sample.patches.utils.MultipartFileTOFileUtil; |
| | | import com.dji.sample.patches.utils.ShapeFileUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static org.locationtech.jts.io.WKTConstants.POLYGON; |
| | | |
| | | @Service |
| | | public class ShpToDataSourceServiceImpl implements ShpToDataSourceService { |
| | | @Autowired |
| | | private ShpToDataSourceMapper mapper; |
| | | |
| | | private int createTime=0; |
| | | private int updateTime=0; |
| | | |
| | | private String bsm; |
| | | public void insertGeo(MultipartFile file) throws IOException { |
| | | ShapeFileUtil shapeFileUtil=new ShapeFileUtil(); |
| | | MultipartFileTOFileUtil multipartFileTOFileUtil = new MultipartFileTOFileUtil(); |
| | | File file1= multipartFileTOFileUtil.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); |
| | | } |
| | | } |
| | | String head = POLYGON; |
| | | String json; |
| | | 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++) { |
| | | 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("-", ""); |
| | | lotInfo.setBsm(bsm); |
| | | lotInfo.setDkfw(json); |
| | | lotInfo.setDkbh("dkbh"+i); |
| | | mapper.insert(lotInfo); |
| | | list.add(lotInfo); |
| | | System.out.println(lotInfo); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | } |