Administrator 2 yıl önce
ebeveyn
işleme
dabcaf8c16

+ 8 - 0
src/main/java/com/sysu/admin/controller/crop/CropLandController.java

@@ -97,6 +97,14 @@ public class CropLandController extends ServiceContext {
         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();

+ 16 - 24
src/main/java/com/sysu/admin/controller/crop/CropLandService.java

@@ -56,7 +56,7 @@ public class CropLandService extends BaseService<CropLand, Long> {
 
     public List<CropLand> findIdAndNameByExecutor(Long executor){
         QCropLand qCropLand = QCropLand.cropLand;
-        QBean<CropLand> selectBean = Projections.fields(qCropLand, qCropLand.id, qCropLand.name);
+        QBean<CropLand> selectBean = Projections.fields(qCropLand, qCropLand.id, qCropLand.name, qCropLand.updateDate);
         JPAQuery<CropLand> jpaQuery = mJPAQueryFactory.select(selectBean)
                 .from(qCropLand)
                 .where(qCropLand.executor.eq(executor));
@@ -110,37 +110,29 @@ public class CropLandService extends BaseService<CropLand, Long> {
         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);
-        }
+        saveImage(fay, bean.getId(), ImageType.fay, bean.getExecutor());
+        saveImage(center, bean.getId(), ImageType.center, bean.getExecutor());
+        saveImage(near, bean.getId(), ImageType.near, bean.getExecutor());
         mCropLandRepository.save(bean);
     }
 
+    private void saveImage(CropImage image, Long cropId, ImageType type, Long userId){
+        if(ObjectUtils.isNotEmpty(image)) {
+            cropImageService.deleteAll(cropImageService.findByCropIdAndType(cropId, type));
+            image.setType(type.ordinal());
+            image.setFilename(decryptByBase64(image.getBase64(), type.name(), userId));
+            image.setCropId(cropId);
+            cropImageService.save(image);
+        }
+    }
+
     /**
      * 把base64转化为文件.
      *
      * @param base64   base64
      * @return boolean isTrue
      */
-    public String decryptByBase64(String base64, String sign, String username) {
+    public String decryptByBase64(String base64, String sign, Long userId) {
         if (StringUtils.isNullOrEmpty(base64)) {
             return null;
         }
@@ -149,7 +141,7 @@ public class CropLandService extends BaseService<CropLand, Long> {
             base64 = base64.substring(index + 1);
         }
         String imageDirPath = configContext.getImageDirPath();
-        String newFileName = System.currentTimeMillis() + "_" + username+"_"+sign+".jpg";
+        String newFileName = System.currentTimeMillis() + "_" + userId+"_"+sign+".jpg";
         try {
             Files.write(Paths.get(imageDirPath+ newFileName),
                     Base64.decodeBase64(base64), StandardOpenOption.CREATE);

+ 6 - 4
src/main/webapp/static/package/cityland.js

@@ -153,7 +153,7 @@ CityLandAction.prototype = {
             }
         }
         point.set("isPoint",1)
-        point.setId(f.getId().substring(f.getId().indexOf(".") + 1))
+        point.setId(f.get("id"))
         return point;
     }
     ,loadTempVectorLayer(){
@@ -180,7 +180,8 @@ CityLandAction.prototype = {
                         const features = vectorSource.getFormat().readFeatures(xhr.responseText);
                         vectorSource.addFeatures(features);
                         for(let feature of features){
-                            feature.set("id",feature.getId().substring(feature.getId().indexOf(".") + 1))
+                            let id = feature.getId().substring(feature.getId().indexOf(".") + 1)
+                            feature.set("id",id)
                             let area = feature.getGeometry().getArea()
                             area = (area + area / 2) / 1000
                             feature.set("area", area.toFixed(2));
@@ -225,7 +226,7 @@ CityLandAction.prototype = {
             "名称":feature.get("name"),
             "地址":feature.get("address"),
             "作物":cropTypes[feature.get("crop_type")],
-            "地块图斑编号":feature.get("id"),
+            "地块图斑编号":feature.get("id") || feature.getId(),
             "地块状态":this.taskStatus[feature.get("status")],
             "地块面积(亩)":feature.get("area"),
             "生长期":cropPeriods[feature.get("growing_period")],
@@ -243,7 +244,8 @@ CityLandAction.prototype = {
     ,
     saveTask(that, feature){
         console.log(feature.getKeys())
-        layui.tool.submit("/crop/publish",{"id":feature.get("id")},function(res){
+        let id = feature.getId()
+        layui.tool.submit("/crop/publish",{"id":feature.get("id") || id.substring(id.indexOf(".") + 1)},function(res){
             if(res.code == 0){
                 that.addFieldPointOfTempLayer(res.data)
             }

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

@@ -27,7 +27,7 @@ public class CropLandControllerTest extends BaseTest {
     @Transactional
     public void saveTest(){
         QCropLand qCropLand = QCropLand.cropLand;
-        List<CropLand>  landList = cityLandService.findAll(qCropLand.district.isNull());
+        List<CropLand>  landList = cityLandService.findAll(qCropLand.centerPoint.isNull());
         System.out.println("landList load finnish");
         int size = landList.size();
         for(CropLand bean : landList){