Ver código fonte

[update] message:1.从缓存中读取飞鸟看园数据

kelei 6 meses atrás
pai
commit
e7c1791974

+ 6 - 0
admin/pom.xml

@@ -57,6 +57,12 @@
             <version>7.13.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.locationtech.jts</groupId>
+            <artifactId>jts-core</artifactId>
+            <version>1.18.1</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 85 - 0
admin/src/main/java/com/flyer/foster/pojo/LzTree.java

@@ -0,0 +1,85 @@
+package com.flyer.foster.pojo;
+
+import lombok.Data;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.Point;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ * LzTree
+ *
+ * @author kelei
+ * @since 2024/5/13/19:53
+ */
+@Data
+public class LzTree {
+    private Integer id;
+
+    private String code;
+
+    private Integer fruitsTypeItemId;
+
+    private Integer fruitsType;
+
+    private Integer age;
+
+    private Integer areaId;
+
+    private Integer userId;
+
+    private Point point;
+
+    private Double canopyArea;
+
+    private Double dbh;
+
+    private String label;
+
+    private String colorName;
+
+    private String pz;
+
+    private String img;
+
+    private LocalDateTime updateDate;
+
+    private Boolean noImg;
+
+    private String wkt;
+
+    private Integer warning ;
+
+    private String partImgUrl;
+
+    private LzTreeGrowData growData;
+
+    private String pzIcon;
+
+    private Integer growDataId;
+
+    private Integer organId;
+
+    private Boolean virtual;
+
+    /**
+     * 聚合点id
+     */
+    private Integer polymerId;
+
+    /**
+     * 相对像素坐标
+     */
+    private String px;
+
+    /**
+     * 小程序地图底图id
+     */
+    private Integer organMiniMapImageId;
+
+    /**
+     * 最后更新平均数据时间
+     */
+    private LocalDate updateGrowDataAvgDate;
+}

+ 126 - 0
admin/src/main/java/com/flyer/foster/pojo/LzTreeGrowData.java

@@ -0,0 +1,126 @@
+package com.flyer.foster.pojo;
+
+import lombok.Data;
+
+import java.time.LocalDate;
+
+@Data
+public class LzTreeGrowData {
+
+    private Integer id;
+
+    private Integer treeId;
+
+    private Integer imgId;
+
+    private String resFilename;
+
+    private Integer periodId;
+
+    private String resSuolveFilename;
+
+    private LocalDate createDate;
+
+    private Float csqszb = 0.0f;
+
+    private Float nyqszb = 0.0f;
+
+    private Float hyqszb= 0.0f;
+
+    private LocalDate xinShaoDate1;
+
+    private LocalDate xinShaoDate2;
+
+    private LocalDate xinShaoDate3;
+
+    private LocalDate laoShuDate1;
+
+    private LocalDate laoShuDate2;
+
+    private LocalDate laoShuDate3;
+
+    private Integer dongShaoYuJing;
+
+    private Integer baiDianYuJing;
+
+    private Float whitePoint = 0.0f;
+
+    private Float redLeafPercent = 0.0f;
+
+    private Float flowerLength = 0F;
+
+    private Float flowerAmount = 0F;
+
+    private Float flowerLeafPercent = 0.0f;
+
+    /**
+     * 花带叶预警
+     */
+    private Integer huaDaiYeYuJing;
+
+    /**
+     * 单果数量
+     */
+    private Integer danGuoShuLiang;
+
+    /**
+     * 双果数量
+     */
+    private Integer shuangGuoShuLiang;
+
+    /**
+     * 病害 毛毡
+     */
+    private Integer bhMz;
+
+    /**
+     * 病害 叶瘿蚊
+     */
+    private Integer bhYyw;
+
+    /**
+     * 病害 炭疽
+     */
+    private Integer bhTj;
+
+    /**
+     * 病害 霜疫霉
+     */
+    private Integer bhSym;
+
+    /**
+     * 病害 裂果
+     */
+    private Integer bhLg;
+
+    /**
+     * 雌花比
+     */
+    private Float flowerPercent = 0.0f;
+
+    /**
+     * 爆花率
+     */
+    private Float boFlowerPercent = 0.0f;
+
+    /**
+     * 小果率
+     */
+    private Float miniPercent = 0.0f;
+
+    /**
+     * 产量(预估值千克)
+     */
+    private Integer yield = 0;
+
+    /**
+     * 自动数据为1 手动更新的为0
+     */
+    private Boolean isAutoData = false;
+
+    /**
+     * 临时附加的字段
+     */
+    private String code;
+
+}

+ 42 - 13
admin/src/main/java/com/flyer/foster/service/impl/FosterRecordServiceImpl.java

@@ -1,11 +1,14 @@
 package com.flyer.foster.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.flyer.exception.BusinessException;
 import com.flyer.foster.dto.app.FosterRecordAddDTO;
 import com.flyer.foster.entity.FosterRecord;
 import com.flyer.foster.entity.Garden;
 import com.flyer.foster.mapper.IFosterRecordMapper;
+import com.flyer.foster.pojo.LzTree;
 import com.flyer.foster.pojo.StpAppUtil;
 import com.flyer.foster.service.IFosterRecordService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -15,6 +18,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.LocalDateTime;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -38,20 +45,42 @@ public class FosterRecordServiceImpl extends ServiceImpl<IFosterRecordMapper, Fo
     @Override
     public boolean addFosterRecord(FosterRecordAddDTO addDTO) {
         int tenantId = StpAppUtil.getTokenSession().getInt("tenantId");
-        // 根据果园id找到配置的飞鸟看园果园id
-        Garden garden = iGardenService.getById(addDTO.getGardenId());
-        if (garden == null) {
-            throw new BusinessException("无效的果园id");
-        }
-        // 飞鸟看园果园id
-        Integer birdseyeGardenId = garden.getBirdseyeGardenId();
-        // 从缓存中取出果园下的树,获取一个未曾分配的树id,
-        Map<Object, Object> treeCache = redisUtil.hmget("birdseye:tree");
+        // 一个用户在同一个果园只能认领一棵树
+        FosterRecord fosterRecord = this.lambdaQuery()
+                .eq(FosterRecord::getAppUserId, addDTO.getAppUserId())
+                .eq(FosterRecord::getGardenId, addDTO.getGardenId())
+                .one();
+        if (fosterRecord == null) {
+            // 根据果园id找到配置的飞鸟看园果园id
+            Garden garden = iGardenService.getById(addDTO.getGardenId());
+            if (garden == null) {
+                throw new BusinessException("无效的果园id");
+            }
+            // 飞鸟看园果园id
+            Integer birdseyeGardenId = garden.getBirdseyeGardenId();
+            // 从缓存中取出果园下的树,获取一个未曾分配的树id,
+            Map<Object, Object> treeCache = redisUtil.hmget("birdseye:tree");
 
-        FosterRecord fosterRecord = new FosterRecord();
-        BeanUtil.copyProperties(addDTO, fosterRecord);
-        fosterRecord.setTenantId(tenantId);
-//        return this.save(fosterRecord);
+            Integer birdseyeTreeId = 0;
+            for (Map.Entry<Object, Object> map : treeCache.entrySet()) {
+                if (map.getKey().equals(birdseyeGardenId.toString())) {
+                    List<LzTree> lzTreeList = JSON.parseArray(map.getValue().toString(), LzTree.class);
+                    Collections.shuffle(lzTreeList);
+                    // 获取一个飞鸟看园树id
+                    birdseyeTreeId = lzTreeList.get(0).getId();
+                    break;
+                }
+            }
+            fosterRecord = new FosterRecord();
+            BeanUtil.copyProperties(addDTO, fosterRecord);
+            fosterRecord.setTenantId(tenantId);
+            fosterRecord.setBirdseyeTreeId(birdseyeTreeId);
+            fosterRecord.setCreatedBy("kelei");
+            fosterRecord.setCreatedTime(LocalDateTime.now());
+            fosterRecord.setUpdatedBy("kelei");
+            fosterRecord.setUpdatedTime(LocalDateTime.now());
+            this.save(fosterRecord);
+        }
         return true;
     }
 }

+ 0 - 1
admin/src/main/resources/application-dev.yml

@@ -25,7 +25,6 @@ spring:
       pool-prepared-statements: true
       max-pool-prepared-statement-per-connection-size: 20
   redis:
-    database: 1
     host: 106.53.222.208
     lettuce:
       pool: