ソースを参照

滨江一本帐导入和下载

liutao 11 ヶ月 前
コミット
f940aa35cc

+ 43 - 0
BJYSYBZ_S/src/main/java/com/zjugis/ysgzybz/controller/rest/YbzBJController.java

@@ -1,20 +1,28 @@
 package com.zjugis.ysgzybz.controller.rest;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.vividsolutions.jts.io.ParseException;
 import com.zjugis.ysgzybz.controller.BaseRestController;
 import com.zjugis.ysgzybz.domain.dto.CommonDTO;
 import com.zjugis.ysgzybz.domain.dto.WlydDTO;
 import com.zjugis.ysgzybz.domain.entity.BaseFile;
 import com.zjugis.ysgzybz.domain.entity.Bjgddwyjsq;
+import com.zjugis.ysgzybz.domain.entity.UploadTxtResultVO;
 import com.zjugis.ysgzybz.service.BjgddwsqService;
 import com.zjugis.ysgzybz.service.IFileService;
 import com.zjugis.ysgzybz.service.impl.YbzBJService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.FileCopyUtils;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -594,6 +602,41 @@ public class YbzBJController extends BaseRestController {
         }
     }
 
+    @GetMapping("/exportOneShape")
+    public Object exportOneShape(CommonDTO dto, HttpServletResponse response) {
+        try {
+            logger.info("/api/ybz-bj/exportOneShape 接口调用~~~");
+            String zipFilePath = service.exportOneShape(dto);
+            InputStream is = new FileInputStream(zipFilePath);
+
+            response.setContentType("multipart/form-data");
+            response.setCharacterEncoding("utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("地块", "utf-8") + ".zip");
+            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+
+            FileCopyUtils.copy(is, response.getOutputStream());
+            return result(null);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            logger.warn("/api/ybz-bj/exportOneShape 接口异常 -> " + ex.getMessage());
+            return error(ex.getMessage(), ErrorCode.DEFAULT);
+        }
+    }
+
+    @PostMapping("/uploadTxt")
+    public Object uploadTxt(@RequestParam("file") MultipartFile file) {
+        //对file进行校验
+        try {
+            UploadTxtResultVO result = service.uploadFile(file.getInputStream());
+            return result(result);
+        } catch (ParseException e) {
+            return error(e.getMessage(), ErrorCode.DEFAULT);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return error("上传文件失败,请检查文件格式!", ErrorCode.DEFAULT);
+        }
+    }
+
     /**
      * Description: 地块管理删除单条记录
      * Author: WangConvey

+ 5 - 1
BJYSYBZ_S/src/main/java/com/zjugis/ysgzybz/dao/YbzBJDao.java

@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zjugis.ysgzybz.domain.dto.CommonDTO;
 import com.zjugis.ysgzybz.domain.dto.ManageDTO;
 import com.zjugis.ysgzybz.domain.dto.WlydDTO;
-import com.zjugis.ysgzybz.domain.entity.Gdxmjbxxb;
 import com.zjugis.ysgzybz.domain.entity.WlydExcelDO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -92,6 +91,11 @@ public interface YbzBJDao {
     /** 地块管理单条记录 **/
     Map manageOne(CommonDTO dto);
 
+    /** 导出单条数据 **/
+    Map<String, Object> exportOne(CommonDTO dto);
+
+//    void insertLsyd(LsydDTO dto);
+
     /** 地块管理汇总 **/
     Map<String, Object> manageHZ(CommonDTO dto);
 

+ 97 - 11
BJYSYBZ_S/src/main/java/com/zjugis/ysgzybz/service/impl/YbzBJService.java

@@ -5,22 +5,24 @@ import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.write.metadata.WriteSheet;
 import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.ParseException;
-import com.vividsolutions.jts.io.WKBReader;
 import com.vividsolutions.jts.io.WKTReader;
+import com.zjugis.ysgzybz.dao.BjlsydMapper;
 import com.zjugis.ysgzybz.dao.YbzBJDao;
 import com.zjugis.ysgzybz.domain.dto.CommonDTO;
 import com.zjugis.ysgzybz.domain.dto.ManageDTO;
 import com.zjugis.ysgzybz.domain.dto.WlydDTO;
+import com.zjugis.ysgzybz.domain.entity.Bjlsyd;
+import com.zjugis.ysgzybz.domain.entity.UploadTxtResultVO;
 import com.zjugis.ysgzybz.domain.entity.WlydExcelDO;
 import com.zjugis.ysgzybz.domain.entity.ZoneGeometry;
-import com.zjugis.ysgzybz.utils.GeometryUtil;
-import com.zjugis.ysgzybz.utils.JzdUtil;
-import com.zjugis.ysgzybz.utils.StyleUtils;
+import com.zjugis.ysgzybz.utils.*;
+import com.zjugis.ysgzybz.utils.geocomm.JzdDk;
+import com.zjugis.ysgzybz.utils.geocomm.JzdSx;
+import com.zjugis.ysgzybz.utils.geocomm.ParseResult;
+import com.zjugis.ysgzybz.utils.geocomm.TxtReader;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -30,13 +32,10 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.Function;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -45,6 +44,9 @@ public class YbzBJService {
     @Autowired
     private YbzBJDao dao;
 
+    @Autowired
+    private BjlsydMapper bjlsydMapper;
+
     /** 通过id获取未利用地 **/
     public Object getWlydById(CommonDTO dto) {
         return dao.getWlydById(dto);
@@ -255,6 +257,90 @@ public class YbzBJService {
         return dao.manageOne(dto);
     }
 
+    public UploadTxtResultVO uploadFile(InputStream inputStream) throws Exception {
+        //解析上传的txt为ParseResult
+        TxtReader txtReader = new TxtReader(inputStream);
+        ParseResult result = txtReader.read();
+
+        Geometry geometry = result.getGeometry();
+        List<JzdDk> jzdDkList = result.getJzdDkList();
+
+        String dkmc = jzdDkList.get(0).getDkmc();
+
+        double dkmj =0;
+        for (JzdDk jzdDk : jzdDkList) {
+            dkmj += jzdDk.getDkmj();
+        }
+
+        UploadTxtResultVO vo = new UploadTxtResultVO();
+        vo.setErrorList(result.getErrorList());
+
+        Bjlsyd entity = new Bjlsyd();
+        QueryWrapper<Bjlsyd> wrapper = new QueryWrapper<>();
+        wrapper.select("max(id) as id","max(xh) as xh");
+        Bjlsyd bjlsyd = bjlsydMapper.selectOne(wrapper);
+        float id = bjlsyd.getId() + 1;
+        int xh = (int) id + 100;
+        try {
+            xh = Integer.parseInt(bjlsyd.getXh()) + 1;
+        } catch (NumberFormatException ex) {
+            ex.printStackTrace();
+        }
+        entity.setId(id);
+        entity.setObjectid(id);
+        entity.setXh(String.valueOf(xh));
+        entity.setXh1((float) xh);
+        entity.setXmmc(dkmc);
+        entity.setSpmj(dkmj * 10000);
+
+        int insert = bjlsydMapper.insert(entity);
+        if (insert > 0) {
+            bjlsydMapper.updateGeometry(geometry.toText(), id);
+        }
+        return vo;
+    }
+
+    public String exportOneShape(CommonDTO dto) {
+        File rootPath = new File(System.getProperty("user.dir"));
+        String prefix = UUID.randomUUID().toString();
+        String dkFileName = prefix + ".shp";
+        String formatFileName = "shp" + File.separator + dkFileName;
+        File dkFile = new File(rootPath, formatFileName);
+        if (!dkFile.getParentFile().exists()) {
+            dkFile.getParentFile().mkdirs();
+        }
+        String fileFullPath = dkFile.getAbsolutePath();
+        Map<String, Object> resultMap = dao.exportOne(dto);
+        String shape = resultMap.get("shape").toString();
+        Geometry geometry = null;
+        try {
+            geometry = GeometryUtil.wkt2Geometry(shape);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (geometry != null) {
+            resultMap.put("shape", geometry);
+        }
+        List<String> attrKeys = new ArrayList();
+        for (String key : resultMap.keySet()) {
+            attrKeys.add(key.toUpperCase());
+        }
+        List<Map<String, Object>> mapList = new ArrayList<>();
+        mapList.add(resultMap);
+        ShapeUtil.write2Shape(fileFullPath, "GBK", "Polygon", "shape", attrKeys, mapList);
+        //压缩shp
+        ShapeUtil.zipShapeFile(fileFullPath);
+
+        //删除临时生产的.shp文件
+        File shpFile = new File(fileFullPath);
+        String shpRoot = shpFile.getParentFile().getPath();
+        File[] files = new File(shpRoot).listFiles(file -> file.getName().startsWith(prefix) && !file.getName().endsWith(".zip"));
+        for (File file : files) {
+            file.delete();
+        }
+        return fileFullPath.replace(".shp", ".zip");
+    }
+
     /** 地块管理汇总 **/
     public Map<String, Object> manageHZ(CommonDTO dto) {
         return dao.manageHZ(dto);

+ 11 - 0
BJYSYBZ_S/src/main/java/com/zjugis/ysgzybz/utils/GeometryUtil.java

@@ -2,6 +2,7 @@ package com.zjugis.ysgzybz.utils;
 
 import com.vividsolutions.jts.geom.*;
 import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKBReader;
 import com.vividsolutions.jts.io.WKTReader;
 import com.vividsolutions.jts.operation.valid.IsValidOp;
 import lombok.extern.slf4j.Slf4j;
@@ -107,6 +108,16 @@ public class GeometryUtil {
         return reader.read(wkt);
     }
 
+    public static Geometry wkbToGeom(String wkb) {
+        try {
+            byte[] aux = WKBReader.hexToBytes(wkb);
+            return new WKBReader().read(aux);
+        }catch (Exception ex){
+            ex.printStackTrace();
+            return null;
+        }
+    }
+
     public static double getArea(Geometry geometry) {
         Geometry gg = new GeometryFactory().createGeometry(geometry);
         String epsg4490 = "+proj=longlat +ellps=GRS80 +no_defs";

+ 11 - 0
BJYSYBZ_S/src/main/java/com/zjugis/ysgzybz/utils/GisUtils.java

@@ -4,6 +4,7 @@ import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryCollection;
 import com.vividsolutions.jts.geom.GeometryFactory;
 import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKBWriter;
 import com.vividsolutions.jts.io.WKTReader;
 import com.vividsolutions.jts.operation.buffer.BufferOp;
 import com.vividsolutions.jts.operation.buffer.BufferParameters;
@@ -31,6 +32,12 @@ import java.util.List;
 
 public class GisUtils {
 
+    public static String convertGeometry2WKB(Geometry geometry) {
+        WKBWriter writer = new WKBWriter();
+        byte[] write = writer.write(geometry);
+        return WKBWriter.toHex(write);
+    }
+
     public static Geometry parseGeojson(String geojson) throws IOException {
         GeometryJSON geometryJSON = new GeometryJSON(6);
         Geometry geometry = geometryJSON.read(new StringReader(geojson));
@@ -121,6 +128,10 @@ public class GisUtils {
         return null;
     }
 
+    public static double calculateDistance(double x1, double y1, double x2, double y2) {
+        return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
+    }
+
     public static void main(String[] args) throws IOException {
 //        30.20591,120.221557
 //        String geojson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"id\":\"bjwkfly2000.65\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[120.17376215,30.1550689],[120.17371998,30.15505164],[120.17351625,30.1552117],[120.17387465,30.15554496],[120.17380729,30.15560406],[120.17392119,30.15571815],[120.17400582,30.15586233],[120.17405761,30.15579803],[120.17412072,30.1557161],[120.17416208,30.15566551],[120.17416494,30.15561077],[120.17415718,30.15557068],[120.17407017,30.15544573],[120.17392918,30.15523398],[120.17376215,30.1550689]]]]},\"geometry_name\":\"shape\",\"properties\":{\"id\":65,\"objectid\":71,\"OBJECTID_1\":65,\"dkbh\":\"CH-86\",\"dkmj\":\"2230.52957561753\",\"dkwz\":\"长河街道\",\"mj\":3.35,\"dkxz\":\"土方;空地\",\"gddw\":\"城建发展公司\",\"lxr\":\"蒋鹏飞\",\"lxdh\":\"13867121627\",\"bz\":\" \",\"szfw\":\"东至长桥线,南至空地,西至仓库,北至长桥线\",\"st_area_sh\":2.1E-7,\"st_length_\":0.00220052,\"shape_leng\":0.00220052,\"dksyh\":\"480a668a9e4c11ee94c4074096d72126\",\"st_area_shape_\":2.1E-7,\"st_length_shape_\":0.00220052,\"st_area_shape1\":2.1E-7,\"st_length_shape1\":0.00220052,\"st_area_shape1_1\":2.1E-7,\"st_length_shape1_1\":0.00220052,\"st_area_shape1_12\":2.1E-7,\"st_length_shape1_12\":0.00220052,\"shape_Length\":0.0022005175620851926,\"shape_Area\":2.088635342349575E-7}}],\"totalFeatures\":1,\"numberMatched\":1,\"numberReturned\":1,\"timeStamp\":\"2024-06-18T08:00:11.960Z\"}";

+ 14 - 0
BJYSYBZ_S/src/main/resources/mapper/YbzBJMapper.xml

@@ -2,6 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zjugis.ysgzybz.dao.YbzBJDao">
 
+
     <select id="getWlydById" parameterType="com.zjugis.ysgzybz.domain.dto.CommonDTO" resultType="java.util.Map">
         select * from sde.bjwlyd2000 where dkbh = #{id}
     </select>
@@ -903,6 +904,19 @@
         </if>
         order by dkbh asc nulls last
     </select>
+    <select id="exportOne" resultType="java.util.Map">
+        select
+            T1.dkbh,T1.dkmj,T1.dkwz,T1.mj,T1.dkxz,T1.gddw,T1.lxr,T1.lxdh,T1.bz,T1.szfw,st_astext(T1.shape) as shape
+        from
+            sde.bjwkfly2000 T1
+                left join (SELECT
+                               *
+                           FROM
+                               ( SELECT *, ROW_NUMBER ( ) OVER ( PARTITION BY dk_id ORDER BY apply_time DESC ) AS row_num FROM sde.bjgddwyjsq ) T
+                           WHERE
+                               row_num = 1) T2 ON T1.dksyh = T2.DK_ID
+        where T1.dksyh = #{id}
+    </select>
 
     <update id="lsydSave" parameterType="com.zjugis.ysgzybz.domain.dto.CommonDTO">
         update sde.bjlsyd