Administrator 2 anni fa
parent
commit
8c94192e66

+ 5 - 0
src/main/java/com/sysu/admin/controller/city/DistrictRepository.java

@@ -1,9 +1,14 @@
 package com.sysu.admin.controller.city;
 
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
+import org.locationtech.jts.geom.Geometry;
+import org.springframework.data.jpa.repository.Query;
 
 public interface DistrictRepository extends JpaPlusRepository<District, Integer> {
 
     District findByCode(int code);
 
+    @Query(value = "SELECT * FROM \"p_district\" where St_within(?1, geom) limit 1", nativeQuery = true)
+    District findByPoint(Geometry point);
+
 }

+ 11 - 0
src/main/java/com/sysu/admin/controller/crop/CropLand.java

@@ -37,6 +37,10 @@ public class CropLand {
     @Column(columnDefinition = "geom")
     private MultiPolygon geom;
 
+    @JSONField(serialize = false)
+    @Column(columnDefinition = "center_point")
+    private Point centerPoint;
+
     @Transient
     private String wkt;
     @Transient
@@ -111,5 +115,12 @@ public class CropLand {
     @Transient
     private CropImage near;
 
+    @Column
+    private Integer province;
+    @Column
+    private Integer city;
+    @Column
+    private Integer district;
+
 
 }

+ 41 - 2
src/main/java/com/sysu/admin/controller/crop/CropLandController.java

@@ -2,6 +2,8 @@ package com.sysu.admin.controller.crop;
 
 import com.alibaba.fastjson.JSON;
 import com.sysu.admin.api.crop.CropVo;
+import com.sysu.admin.controller.city.District;
+import com.sysu.admin.controller.city.DistrictRepository;
 import com.sysu.admin.controller.crop.CropLand;
 import com.sysu.admin.controller.crop.CropLandService;
 import com.sysu.admin.controller.crop.CropLandVo;
@@ -15,24 +17,31 @@ import com.xiesx.fastboot.utils.CopyUtils;
 import org.locationtech.jts.geom.MultiPolygon;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
+
+import javax.transaction.Transactional;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 读取地图数据信息
  */
 @RequestMapping("/crop")
-@RestController
+@Controller
 public class CropLandController {
 
     @Autowired
     CropLandService cityLandService;
     @Autowired
     ShiroService shiroService;
+    @Autowired
+    DistrictRepository districtRepository;
 
     @RequestMapping("/getInfo")
+    @ResponseBody
     public BaseResult getInfo(Double x, Double y){
         CropLand cityLand = cityLandService.findByPoint(new Double[]{x,y});
         if(cityLand == null){
@@ -53,14 +62,27 @@ public class CropLandController {
         }
         BeanUtils.copyProperties(vo, bean, CopyUtils.nullNames(vo));
         bean.setWkt(GeoCastUtil.geomToWkt(bean.getGeom()));
+        bean.setCenterPoint(cityLandService.getCenterPoint(bean.getId()));
+        bean.getCenterPoint().setSRID(4326);
+        District district = districtRepository.findByPoint(bean.getCenterPoint());
+        if(district != null){
+            cityLandService.setCity(bean, district);
+        }
         cityLandService.save(bean);
-        cityLandService.updateCenterPoint(bean.getId());
         return R.succ(bean);
     }
 
+
+
+    @RequestMapping("/publish_index")
+    public String publishIndex(){
+        return "page/publish_task";
+    }
+
     @RequestMapping("/batchPublish")
     @ResponseBody
     public BaseResult batchPublish(CropLandVo vo){
+
         return R.succ();
     }
 
@@ -69,10 +91,27 @@ public class CropLandController {
     public BaseResult addTest(String wkt){
         CropLand bean = new CropLand().setGeom((MultiPolygon)GeoCastUtil.wktToGeom(wkt))
                 .setGridcode(2L).setStatus(LandTaskStatus.unpublished.ordinal());
+        bean.setCenterPoint(cityLandService.getCenterPoint(bean.getGeom()));
+        bean.getCenterPoint().setSRID(4326);
+        District district = districtRepository.findByPoint(bean.getCenterPoint());
+        if(district != null) {
+            cityLandService.setCity(bean, district);
+        }
         cityLandService.save(bean);
         return R.succ();
     }
 
+    @Transactional
+    public BaseResult saveTest(){
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                cityLandService.saveCityAll();
+            }
+        });
+        return R.succ();
+    }
+
 }
 
 

+ 17 - 1
src/main/java/com/sysu/admin/controller/crop/CropLandRepository.java

@@ -1,6 +1,8 @@
 package com.sysu.admin.controller.crop;
 
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.Point;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
@@ -10,11 +12,25 @@ import java.util.List;
 public interface CropLandRepository extends JpaPlusRepository<CropLand, Long> {
 
 
-    @Query(value = "SELECT * FROM \"p_crop\" where St_within(st_geomfromtext(?1), geom) limit 1", nativeQuery = true)
+    @Query(value = "SELECT * FROM \"p_crop\" where St_within(st_geomfromtext(?1,4326), geom) limit 1", nativeQuery = true)
     CropLand findByPoint(String pointWKT);
+
     @Query(value = "update p_crop set center_point = st_centroid(geom) where id = ?1",nativeQuery = true)
     @Modifying
     int updateCenterPoint(Long id);
 
+    @Query(value = "select st_astext(st_centroid(geom)) from p_crop  where id = ?1",nativeQuery = true)
+    String getCenterPoint(Long id);
+
+    @Query(value = "select st_astext(st_centroid(?1))",nativeQuery = true)
+    String getCenterPoint(Geometry geom);
+
+
+    @Query(value = "update p_crop set province = ?2,city = ?3,district = ?4, where id = ?1",nativeQuery = true)
+    @Modifying
+    int updateCity(Long id,Integer province, Integer city, Integer district);
+
+
+
 
 }

+ 48 - 1
src/main/java/com/sysu/admin/controller/crop/CropLandService.java

@@ -1,6 +1,7 @@
 package com.sysu.admin.controller.crop;
 
 import com.mysql.jdbc.StringUtils;
+import com.sysu.admin.controller.city.*;
 import com.sysu.admin.controller.crop.images.CropImage;
 import com.sysu.admin.controller.crop.images.CropImageService;
 import com.sysu.admin.controller.crop.images.ImageType;
@@ -8,9 +9,14 @@ import com.sysu.admin.controller.geo.land.LandTaskStatus;
 import com.sysu.admin.support.base.BaseService;
 import com.sysu.admin.support.system.config.ConfigContext;
 import com.sysu.admin.utils.file.FileUtil;
+import com.sysu.admin.utils.shape.GeoCastUtil;
+import com.xiesx.fastboot.base.result.BaseResult;
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang3.ObjectUtils;
+import org.geolatte.geom.crs.CoordinateReferenceSystems;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.Point;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -29,10 +35,18 @@ public class CropLandService extends BaseService<CropLand, Long> {
     CropImageService cropImageService;
     @Autowired
     ConfigContext configContext;
+    @Autowired
+    ProvinceRepository provinceRepository;
+    @Autowired
+    CityRepository cityRepository;
+    @Autowired
+    DistrictRepository districtRepository;
 
     public List<CropPoint> findByBuffer(Double[] point, Integer meter){
         double degree = meter / (2 * Math.PI * 6371004) * 360;
-        return mCropPointRepository.findByBuffer("Point("+point[0]+" "+point[1]+")",degree);
+        return mCropPointRepository.findByBufferAndStatus("Point("+point[0]+" "+point[1]+")",degree, new Integer[]{
+                LandTaskStatus.published.ordinal(),LandTaskStatus.receive.ordinal()
+        });
     }
 
     public List<CropLand> findByExecutor(Long executor){
@@ -65,6 +79,22 @@ public class CropLandService extends BaseService<CropLand, Long> {
         return  mCropLandRepository.updateCenterPoint(id);
     }
 
+    public Point getCenterPoint(Long id){
+        return (Point)GeoCastUtil.wktToGeom(mCropLandRepository.getCenterPoint(id));
+    }
+    public Point getCenterPoint(Geometry geometry){
+        geometry.setSRID(4326);
+        return (Point)GeoCastUtil.wktToGeom(mCropLandRepository.getCenterPoint(geometry));
+    }
+
+
+
+    public void setCity(CropLand bean, District district){
+        bean.setProvince(((int)(district.getCode() / 10000)) * 10000);
+        bean.setCity(((int)(district.getCode() / 100)) * 100);
+        bean.setDistrict(district.getCode());
+    }
+
     @Transactional
     public void saveCropAndImages(CropLand bean){
         CropImage fay = bean.getFay();
@@ -119,6 +149,23 @@ public class CropLandService extends BaseService<CropLand, Long> {
         return newFileName;
     }
 
+    @Transactional
+    public void saveCityAll(){
+        QCropLand qCropLand = QCropLand.cropLand;
+        List<CropLand> landList = findAll(qCropLand.district.isNull());
+        System.out.println("landList load finnish");
+        int size = landList.size();
+        for(CropLand bean : landList){
+            bean.getCenterPoint().setSRID(4326);
+            District district = districtRepository.findByPoint(bean.getCenterPoint());
+            if(district != null){
+                setCity(bean, district);
+                System.out.println("剩余:" + (--size));
+            }
+        }
+        saveAll(landList);
+    }
+
     @Override
     public JpaPlusRepository<CropLand, Long> r() {
         return mCropLandRepository;

+ 3 - 3
src/main/java/com/sysu/admin/controller/crop/CropPointRepository.java

@@ -9,10 +9,10 @@ import java.util.List;
 public interface CropPointRepository extends JpaPlusRepository<CropPoint, Long> {
 
 
-    @Query(value = "SELECT id,crop_type,st_asgeojson(center_point) as geojson,status from \"p_crop\" where St_within(center_point," +
-            " ST_Buffer(st_geomfromtext(?1),?2, 'quad_segs=8')" +
+    @Query(value = "SELECT id,crop_type,st_asgeojson(center_point) as geojson,status from \"p_crop\" where status in ?3 and St_within(center_point," +
+            " ST_Buffer(st_geomfromtext(?1,4326),?2, 'quad_segs=8')" +
             ");",nativeQuery = true)
-    List<CropPoint> findByBuffer(String pointWKT, Double degree);
+    List<CropPoint> findByBufferAndStatus(String pointWKT, Double degree, Integer[] status);
 
     @Query(value = "select ST_AsText(ST_Buffer(st_geomfromtext(?1),?2, 'quad_segs=8'))", nativeQuery = true)
     String getBuffer(String pointWKT, Double degree);

+ 0 - 15
src/main/java/com/sysu/admin/controller/geo/task/TaskController.java

@@ -1,15 +0,0 @@
-package com.sysu.admin.controller.geo.task;
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-@RequestMapping("/task")
-@Controller
-public class TaskController {
-
-    @RequestMapping("/publish_index")
-    public String publishIndex(){
-        return "page/publish_task";
-    }
-
-}

+ 1 - 1
src/main/webapp/WEB-INF/jsp/comm/admin2.jsp

@@ -60,7 +60,7 @@
                 var target = "map"
 
                 view1 = new ol.View({
-                    center: [114.42386133133742,30.50481808578734],
+                    center: [113.37966949,23.06685869],
                     projection: projection,
                     zoom: 14
                 })

+ 1 - 1
src/main/webapp/WEB-INF/jsp/page/publish_task.jsp

@@ -47,7 +47,7 @@
             });
             function publish(){
                 let data = $("#form1").serializeArray();
-                layui.tool.submit('${base}/organ/submit', data);
+                layui.tool.submit('${base}/crop/batchPublish', data);
             }
         </script>
 

+ 1 - 1
src/main/webapp/static/package/publish_task_action.js

@@ -13,7 +13,7 @@ PublishTaskAction.prototype = {
         //     console.log("startStatus is true")
         //     return
         // }
-        layui.tool.dialog2("/task/publish_index","40%","70%",{buttons:["确定","取消"],funs:[
+        layui.tool.dialog2("/crop/publish_index","40%","70%",{buttons:["确定","取消"],funs:[
             function(index) {
                     var iframeBody = parent.layer.getChildFrame('body', index);
                     iframeBody.find('#submit').click();

+ 43 - 0
src/test/java/com/sysu/admin/controller/crop/CropLandControllerTest.java

@@ -0,0 +1,43 @@
+package com.sysu.admin.controller.crop;
+
+import com.sysu.admin.MarkApplication;
+import com.sysu.admin.api.base.BaseTest;
+import com.sysu.admin.controller.city.District;
+import com.sysu.admin.controller.city.DistrictRepository;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.transaction.Transactional;
+import java.util.List;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MarkApplication.class)
+public class CropLandControllerTest extends BaseTest {
+    @Autowired
+    CropLandController cropLandController;
+    @Autowired
+    CropLandService cityLandService;
+    @Autowired
+    DistrictRepository districtRepository;
+    @Test
+    @Transactional
+    public void saveTest(){
+        QCropLand qCropLand = QCropLand.cropLand;
+        List<CropLand>  landList = cityLandService.findAll(qCropLand.district.isNull());
+        System.out.println("landList load finnish");
+        int size = landList.size();
+        for(CropLand bean : landList){
+            bean.getCenterPoint().setSRID(4326);
+            District district = districtRepository.findByPoint(bean.getCenterPoint());
+            if(district != null){
+                cityLandService.setCity(bean, district);
+                System.out.println("剩余:" + (--size));
+            }
+        }
+        cityLandService.saveAll(landList);
+    }
+}