From 96747dd8a534a10cd950b720e23ebf97e42fa2d3 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 21 三月 2024 14:15:48 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/service/MapService.java |   46 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/service/MapService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/service/MapService.java
index ee3728c..0ec2113 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/service/MapService.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/service/MapService.java
@@ -4,14 +4,16 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.common.domain.enums.DictType;
 import com.zy.asrs.wcs.core.map.controller.param.MapDataParam;
 import com.zy.asrs.wcs.core.map.controller.param.MapQueryParam;
 import com.zy.asrs.wcs.system.entity.Dict;
-import com.zy.asrs.wcs.system.entity.User;
 import com.zy.asrs.wcs.system.service.DictService;
 import com.zy.asrs.wcs.system.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+
+import java.util.Date;
 
 /**
  * Created by vincent on 3/15/2024
@@ -26,13 +28,14 @@
 
     public MapDataParam getMapData(MapQueryParam param, Long userId) {
 
-        String dictFlag = "map-" + param.getFloor();
-        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, dictFlag));
+        String mapKey = getMapKey(param.getFloor());
+        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, mapKey));
         if (Cools.isEmpty(dict)) {
             return null;
         } else {
             return JSON.parseObject(dict.getValue(), MapDataParam.class) ;
         }
+
 
 //        User user = userService.getById(userId);
 //        if (Cools.isEmpty(user.getMemo())) {
@@ -42,11 +45,40 @@
     }
 
     public void saveMapData(MapDataParam param, Long userId) {
-        User user = userService.getById(userId);
-        user.setMemo(JSON.toJSONString(param));
-        if (!userService.updateById(user)) {
-            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+
+        String mapKey = getMapKey(param.getFloor());
+        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, mapKey));
+        if (Cools.isEmpty(dict)) {
+           dict = new Dict();
+           dict.setName(mapKey);
+           dict.setFlag(mapKey);
+           dict.setType(DictType.JSON.flag);
+           dict.setValue(JSON.toJSONString(param.getItemList()));
+           if (!dictService.save(dict)) {
+               throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+           }
+        } else {
+            dict.setValue(JSON.toJSONString(param.getItemList()));
+            dict.setUpdateTime(new Date());
+            if (!dictService.updateById(dict)) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
         }
+
+//
+//        User user = userService.getById(userId);
+//        user.setMemo(JSON.toJSONString(param));
+//        if (!userService.updateById(user)) {
+//            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+//        }
+    }
+
+
+    private String getMapKey(Integer floor) {
+        if (null != floor) {
+            return "map-" + floor;
+        }
+        return "map";
     }
 
 }

--
Gitblit v1.9.1