Administrator %!s(int64=2) %!d(string=hai) anos
pai
achega
abdefa44b6

+ 3 - 0
src/main/java/com/sysu/admin/site/CommonVo.java

@@ -4,10 +4,13 @@ import lombok.Data;
 
 @Data
 public class CommonVo {
+    private Long id;
     private Integer code;
     private Integer level;
     private Double x1;
     private Double y1;
     private Double x2;
     private Double y2;
+    private String tableNames;
+    private String status;
 }

+ 1 - 1
src/main/java/com/sysu/admin/site/SiteCityController.java

@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 /**
- * 镇区域
+ * 城市
  */
 @RequestMapping("/site/city")
 @Controller

+ 49 - 0
src/main/java/com/sysu/admin/site/SiteCropImageController.java

@@ -0,0 +1,49 @@
+package com.sysu.admin.site;
+
+
+import com.sysu.admin.controller.crop.images.CropImage;
+import com.sysu.admin.controller.crop.images.CropImageService;
+import com.xiesx.fastboot.base.result.BaseResult;
+import com.xiesx.fastboot.base.result.R;
+import com.xiesx.fastboot.core.token.annotation.GoToken;
+import com.xiesx.fastboot.core.token.handle.CurrentToken;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/site/crop_image")
+public class SiteCropImageController {
+
+    @Autowired
+    CropImageService cropImageService;
+
+    @RequestMapping("/view")
+    public BaseResult view(@RequestBody CommonVo commonVo, @GoToken CurrentToken currentToken){
+        List<CropImage> cropImageList = cropImageService.findByCropId(commonVo.getId());
+        Map<String ,CropImage> res = new HashMap(3);
+        cropImageList.stream().forEach(cropImage -> {
+            switch (CropImage.getImageType(cropImage.getType())){
+                case fay:
+                    res.put("fay",cropImage);
+                    break;
+                case center:
+                    res.put("center",cropImage);
+                    break;
+                case near:
+                    res.put("near",cropImage);
+                    break;
+            }
+        });
+        return R.succ(res);
+    }
+
+
+}

+ 218 - 0
src/main/java/com/sysu/admin/site/SiteCropLandController.java

@@ -0,0 +1,218 @@
+package com.sysu.admin.site;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.fastjson.JSON;
+import com.sysu.admin.controller.city.CityRepository;
+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;
+import com.sysu.admin.controller.crop.CropPoint;
+import com.sysu.admin.controller.crop.range.LandRangeIndexService;
+import com.sysu.admin.controller.crop.xls.CropExcel;
+import com.sysu.admin.controller.crop.xls.CropExcelService;
+import com.sysu.admin.controller.crop.xls.CustomHandler;
+import com.sysu.admin.controller.crop.xls.PublishCropExcelListener;
+import com.sysu.admin.controller.geo.land.LandTaskStatus;
+import com.sysu.admin.support.base.ServiceContext;
+import com.sysu.admin.support.shiro.ShiroService;
+import com.sysu.admin.utils.shape.GeoCastUtil;
+import com.xiesx.fastboot.base.result.BaseResult;
+import com.xiesx.fastboot.base.result.R;
+import com.xiesx.fastboot.core.token.annotation.GoToken;
+import com.xiesx.fastboot.core.token.handle.CurrentToken;
+import com.xiesx.fastboot.utils.CopyUtils;
+import org.apache.catalina.util.URLEncoder;
+import org.apache.commons.lang3.StringUtils;
+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.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.transaction.Transactional;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Path;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 读取地图数据信息
+ */
+@RequestMapping("/site/crop")
+@Controller
+public class SiteCropLandController extends ServiceContext {
+
+    @Autowired
+    CropLandService cityLandService;
+    @Autowired
+    ShiroService shiroService;
+    @Autowired
+    LandRangeIndexService mLandRangeIndexService;
+    @Autowired
+    DistrictRepository districtRepository;
+    @Autowired
+    CityRepository cityRepository;
+    @Autowired
+    CropExcelService cropExcelService;
+
+    @RequestMapping("/getInfo")
+    @ResponseBody
+    public BaseResult getInfo(Double x, Double y){
+        CropLand cityLand = cityLandService.findByPoint(new Double[]{x,y});
+        if(cityLand == null){
+            return R.fail();
+        }
+        cityLand.setWkt(GeoCastUtil.geomToWkt(cityLand.getGeom()));
+        return R.succ(cityLand);
+    }
+
+    @RequestMapping("/getGeoJson")
+    @ResponseBody
+    public BaseResult getGeojson(@RequestBody CommonVo commonVo, @GoToken() CurrentToken currentToken){
+        List<CropPoint> cropLandList = cityLandService.findCropLandNoGeomByTableNamesAndBBox(commonVo.getTableNames(),
+                commonVo.getX1(),commonVo.getY1(),commonVo.getX2(),commonVo.getY2(), commonVo.getStatus());
+        return R.succ(cropLandList);
+    }
+
+    @RequestMapping("/getBuffer")
+    @ResponseBody
+    public BaseResult getBuffer(Double x, Double y, Integer m){
+        return R.succ(cityLandService.getBuffer(new Double[]{x, y}, m));
+    }
+
+    @RequestMapping("/save")
+    @ResponseBody
+    public BaseResult save(CropLandVo vo){
+        CropLand bean = cityLandService.findOne(vo.getId());
+        if(bean.getStatus().intValue() == LandTaskStatus.unpublished.ordinal()){
+            bean.setCreator(shiroService.getPrincipalId());
+            bean.setCreateDate(new Date());
+        }
+        BeanUtils.copyProperties(vo, bean, CopyUtils.nullNames(vo));
+        bean.setWkt(GeoCastUtil.geomToWkt(bean.getGeom()));
+        bean.setCenterPoint(cityLandService.getCenterPoint(bean.getGeom()));
+        District district = districtRepository.findByPoint(bean.getCenterPoint());
+        if(district != null){
+            cityLandService.setCity(bean, district);
+        }
+        cityLandService.save(bean);
+        return R.succ(bean);
+    }
+
+    @RequestMapping("/publish")
+    @ResponseBody
+    public BaseResult publish(@RequestBody CropLandVo vo, @GoToken() CurrentToken currentToken){
+        CropLand bean = cityLandService.findOne(vo.getId());
+        if(bean.getStatus().intValue() != LandTaskStatus.unpublished.ordinal()){
+            return R.fail("不是未发布的地块!");
+        }
+        if(bean.getDistrict() == null || bean.getCenterPoint() == null){
+            bean.setCenterPoint(cityLandService.getCenterPoint(bean.getGeom()));
+            bean.getCenterPoint().setSRID(4326);
+            District district = districtRepository.findByPoint(bean.getCenterPoint());
+            if(district != null){
+                cityLandService.setCity(bean, district);
+            }
+        }
+        bean.setStatus(LandTaskStatus.published.ordinal());
+        cityLandService.save(bean);
+        return R.succ();
+    }
+
+
+
+    @RequestMapping("/publish_index")
+    public String publishIndex(){
+        return "page/publish_task";
+    }
+
+    @RequestMapping("/batchPublish")
+    @ResponseBody
+    @Transactional
+    public BaseResult batchPublish(CropLandVo vo, String fileBase64){
+        if(StringUtils.isNotBlank(fileBase64)){
+            Path path = cityLandService.fileByBase64(fileBase64,"xls",mShiroService.getPrincipalId());
+            PublishCropExcelListener publishCropExcelListener = new PublishCropExcelListener(mLandRangeIndexService);
+            EasyExcel.read(path.toFile(), CropExcel.class,publishCropExcelListener).doReadAllSync();
+            Map<String,List<Long>> stringListMap = publishCropExcelListener.getTableIdsMap();
+            for(String tableName : stringListMap.keySet()) {
+                cityLandService.batchPublishByIds(tableName, stringListMap.get(tableName));
+            }
+        }else{
+            if(vo.getDistrictId() != null) {
+                String tableName = mLandRangeIndexService.getTableNameByCode(vo.getDistrictId());
+                cityLandService.batchPublishByTableName(tableName);
+            }
+        }
+        return R.succ();
+    }
+
+    @RequestMapping("/export_index")
+    public String exportIndex(){
+        return "page/export";
+    }
+
+    @RequestMapping("/export")
+    @ResponseBody
+    @Transactional
+    public void export(CropLandVo vo, HttpServletResponse response){
+        String tableNames;
+        if(vo.getDistrictId() == null){
+            tableNames = mLandRangeIndexService.getAllTableNames();
+        }else{
+            tableNames = mLandRangeIndexService.getTableNameByCode(vo.getDistrictId());
+        }
+        List<CropLand> cropLandList = cityLandService.findAllByStatusAndDistrict(tableNames, vo.getStatus());
+        List<CropExcel> cropExcelList = cropExcelService.cropLandToCropExcel(cropLandList);
+        String mimetype = "application/x-msdownload";
+        String downFileName = "重庆耕地信息.xlsx";
+        String inlineType = "attachment"; // 是否内联附件
+        response.setContentType(mimetype);
+        response.setHeader("Content-Disposition", inlineType
+                + ";filename=" + URLEncoder.DEFAULT.encode(downFileName, Charset.defaultCharset()));
+        try {
+            EasyExcel.write(response.getOutputStream(), CropExcel.class).registerWriteHandler(new CustomHandler())
+                    .sheet("sheet1").doWrite(cropExcelList);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @RequestMapping("/addTest")
+    @ResponseBody
+    public BaseResult addTest(@RequestBody String data){
+        String wkt = JSON.parseObject(data).get("wkt").toString();
+        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();
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+