|
@@ -1,35 +1,87 @@
|
|
|
package com.sysu.admin.api.crop;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.sysu.admin.controller.geo.CityLand;
|
|
|
-import com.sysu.admin.controller.geo.CityLandService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.sysu.admin.controller.crop.CropLand;
|
|
|
+import com.sysu.admin.controller.crop.CropLandService;
|
|
|
+import com.sysu.admin.support.base.BaseComponent;
|
|
|
+import com.sysu.admin.support.shiro.ShiroService;
|
|
|
+import com.sysu.admin.support.system.config.SConfigService;
|
|
|
+import com.sysu.admin.utils.TextUtil;
|
|
|
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.utils.CopyUtils;
|
|
|
import org.opengis.referencing.FactoryException;
|
|
|
import org.opengis.referencing.operation.TransformException;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-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;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
@RequestMapping("/api/crop")
|
|
|
@RestController
|
|
|
-public class CropController {
|
|
|
+public class CropController extends BaseComponent {
|
|
|
+ @Autowired
|
|
|
+ CropLandService cityLandService;
|
|
|
+ @Autowired
|
|
|
+ SConfigService mSConfigService;
|
|
|
@Autowired
|
|
|
- CityLandService cityLandService;
|
|
|
+ ShiroService mShiroService;
|
|
|
|
|
|
@RequestMapping("/list")
|
|
|
public BaseResult list(@RequestBody String data) throws FactoryException, TransformException {
|
|
|
CropVo vo = JSON.parseObject(data, CropVo.class);
|
|
|
- List<CityLand> cityLandList = cityLandService.findByBuffer(vo.getPoint(),vo.getMeter());
|
|
|
+ List<CropLand> cityLandList = cityLandService.findByBuffer(vo.getPoint(),vo.getMeter());
|
|
|
cityLandList.stream().forEach(cityLand -> {
|
|
|
- cityLand.setWkt(GeoCastUtil.geomToWkt(cityLand.getGeom()));
|
|
|
+ cityLand.setGeojson(GeoCastUtil.gjson.toString(cityLand.getGeom()));
|
|
|
});
|
|
|
return R.succ(cityLandList);
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("/updateStatus")
|
|
|
+ public BaseResult updateStatus(@RequestBody String data){
|
|
|
+ CropVo vo = JSON.parseObject(data, CropVo.class);
|
|
|
+ cityLandService.updateStatus(vo.getId(),vo.getStatus());
|
|
|
+ return R.succ();
|
|
|
+ }
|
|
|
|
|
|
+ @PostMapping("/uploadData")
|
|
|
+ public BaseResult uploadData(@RequestParam("fay") MultipartFile fay,
|
|
|
+ @RequestParam("center") MultipartFile center,
|
|
|
+ @RequestParam("near") MultipartFile near,
|
|
|
+ String json){
|
|
|
+ CropVo vo = JSON.parseObject(json, CropVo.class);
|
|
|
+ CropLand bean = cityLandService.findOne(vo.getId());
|
|
|
+ BeanUtils.copyProperties(vo, bean, CopyUtils.nullNames(vo));
|
|
|
+ saveFile(fay, "fay");
|
|
|
+ saveFile(center, "center");
|
|
|
+ saveFile(near, "near");
|
|
|
+
|
|
|
+ return R.succ();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String saveFile(MultipartFile file, String sign){
|
|
|
+ if(file != null){
|
|
|
+ String imageDirPath = mSConfigService.getV("imageDirPath");
|
|
|
+ String hz = TextUtil.rightSubstring(".",file.getOriginalFilename());
|
|
|
+ String newFileName = System.currentTimeMillis() + "_" + mShiroService.getPrincipalId()+"_"+sign+"." + hz;
|
|
|
+ try {
|
|
|
+ //复制到零时文件
|
|
|
+ File target = new File(imageDirPath + newFileName);
|
|
|
+ file.transferTo(target);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return newFileName;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
|
|
|
}
|