|
@@ -1,14 +1,24 @@
|
|
package com.sysu.admin.controller.crop;
|
|
package com.sysu.admin.controller.crop;
|
|
|
|
|
|
|
|
+import com.mysql.jdbc.StringUtils;
|
|
import com.sysu.admin.controller.crop.images.CropImage;
|
|
import com.sysu.admin.controller.crop.images.CropImage;
|
|
import com.sysu.admin.controller.crop.images.CropImageService;
|
|
import com.sysu.admin.controller.crop.images.CropImageService;
|
|
|
|
+import com.sysu.admin.controller.crop.images.ImageType;
|
|
import com.sysu.admin.controller.geo.land.LandTaskStatus;
|
|
import com.sysu.admin.controller.geo.land.LandTaskStatus;
|
|
import com.sysu.admin.support.base.BaseService;
|
|
import com.sysu.admin.support.base.BaseService;
|
|
|
|
+import com.sysu.admin.support.system.config.ConfigContext;
|
|
|
|
+import com.sysu.admin.utils.file.FileUtil;
|
|
import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
|
|
import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.nio.file.StandardOpenOption;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -17,20 +27,27 @@ public class CropLandService extends BaseService<CropLand, Long> {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
CropImageService cropImageService;
|
|
CropImageService cropImageService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ConfigContext configContext;
|
|
|
|
|
|
- public List<CropLand> findByBuffer(Double[] point, Integer meter){
|
|
|
|
|
|
+ public List<CropPoint> findByBuffer(Double[] point, Integer meter){
|
|
double degree = meter / (2 * Math.PI * 6371004) * 360;
|
|
double degree = meter / (2 * Math.PI * 6371004) * 360;
|
|
- return mCropLandRepository.findByBuffer("Point("+point[0]+" "+point[1]+")",degree);
|
|
|
|
|
|
+ return mCropPointRepository.findByBuffer("Point("+point[0]+" "+point[1]+")",degree);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<CropLand> findByExecutor(Long executor){
|
|
|
|
+ QCropLand qCropLand = QCropLand.cropLand;
|
|
|
|
+ return mCropLandRepository.findAll(qCropLand.executor.eq(executor));
|
|
}
|
|
}
|
|
|
|
|
|
- public CropLand findByPoint(double x, double y){
|
|
|
|
- CropLand cityLand = mCropLandRepository.findByPoint("Point("+x+" "+y+")");
|
|
|
|
|
|
+ public CropLand findByPoint(Double[] point){
|
|
|
|
+ CropLand cityLand = mCropLandRepository.findByPoint("Point("+point[0]+" "+point[1]+")");
|
|
return cityLand;
|
|
return cityLand;
|
|
}
|
|
}
|
|
|
|
|
|
public String getBuffer(Double[] point, Integer meter){
|
|
public String getBuffer(Double[] point, Integer meter){
|
|
double degree = meter / (2 * Math.PI * 6371004) * 360;
|
|
double degree = meter / (2 * Math.PI * 6371004) * 360;
|
|
- return mCropLandRepository.getBuffer("Point("+point[0]+" "+point[1]+")", degree);
|
|
|
|
|
|
+ return mCropPointRepository.getBuffer("Point("+point[0]+" "+point[1]+")", degree);
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@@ -44,16 +61,67 @@ public class CropLandService extends BaseService<CropLand, Long> {
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
- public void saveCropAndImages(CropLand bean, CropImage[] cropImages){
|
|
|
|
- for(CropImage cropImage: cropImages){
|
|
|
|
- cropImage.setCropId(bean.getId());
|
|
|
|
- cropImageService.save(cropImage);
|
|
|
|
|
|
+ public int updateCenterPoint(Long id){
|
|
|
|
+ return mCropLandRepository.updateCenterPoint(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ public void saveCropAndImages(CropLand bean){
|
|
|
|
+ CropImage fay = bean.getFay();
|
|
|
|
+ CropImage center = bean.getCenter();
|
|
|
|
+ CropImage near = bean.getNear();
|
|
|
|
+ if(ObjectUtils.isNotEmpty(fay)) {
|
|
|
|
+ cropImageService.deleteAll(cropImageService.findByCropIdAndType(bean.getId(), ImageType.fay));
|
|
|
|
+ fay.setType(ImageType.fay.ordinal());
|
|
|
|
+ fay.setFilename(decryptByBase64(fay.getBase64(), "fay","test"));
|
|
|
|
+ fay.setCropId(bean.getId());
|
|
|
|
+ cropImageService.save(fay);
|
|
|
|
+ }
|
|
|
|
+ if(ObjectUtils.isNotEmpty(center)) {
|
|
|
|
+ cropImageService.deleteAll(cropImageService.findByCropIdAndType(bean.getId(), ImageType.center));
|
|
|
|
+ center.setType(ImageType.center.ordinal());
|
|
|
|
+ center.setFilename(decryptByBase64(center.getBase64(), "center","test"));
|
|
|
|
+ center.setCropId(bean.getId());
|
|
|
|
+ cropImageService.save(center);
|
|
|
|
+ }
|
|
|
|
+ if(ObjectUtils.isNotEmpty(near)) {
|
|
|
|
+ cropImageService.deleteAll(cropImageService.findByCropIdAndType(bean.getId(), ImageType.near));
|
|
|
|
+ near.setType(ImageType.near.ordinal());
|
|
|
|
+ near.setFilename(decryptByBase64(center.getBase64(), "near","test"));
|
|
|
|
+ near.setCropId(bean.getId());
|
|
|
|
+ cropImageService.save(near);
|
|
}
|
|
}
|
|
mCropLandRepository.save(bean);
|
|
mCropLandRepository.save(bean);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 把base64转化为文件.
|
|
|
|
+ *
|
|
|
|
+ * @param base64 base64
|
|
|
|
+ * @return boolean isTrue
|
|
|
|
+ */
|
|
|
|
+ public String decryptByBase64(String base64, String sign, String username) {
|
|
|
|
+ if (StringUtils.isNullOrEmpty(base64)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ int index = base64.indexOf(",");
|
|
|
|
+ if(index > -1){
|
|
|
|
+ base64 = base64.substring(index + 1);
|
|
|
|
+ }
|
|
|
|
+ String imageDirPath = configContext.getImageDirPath();
|
|
|
|
+ String newFileName = System.currentTimeMillis() + "_" + username+"_"+sign+".jpg";
|
|
|
|
+ try {
|
|
|
|
+ Files.write(Paths.get(imageDirPath+ newFileName),
|
|
|
|
+ Base64.decodeBase64(base64), StandardOpenOption.CREATE);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return newFileName;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public JpaPlusRepository<CropLand, Long> r() {
|
|
public JpaPlusRepository<CropLand, Long> r() {
|
|
return mCropLandRepository;
|
|
return mCropLandRepository;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|