From 80e5ee8049eefe7039d77048f43e6e0566a07953 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 25 三月 2024 09:10:43 +0800
Subject: [PATCH] Merge branch 'Four-Way-Rack' of http://47.97.1.152:5880/r/zy-asrs-master into Four-Way-Rack

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/service/MapService.java |   52 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 10 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 8a4dd70..5622fc3 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
@@ -1,14 +1,19 @@
 package com.zy.asrs.wcs.core.map.service;
 
 import com.alibaba.fastjson.JSON;
+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.User;
+import com.zy.asrs.wcs.system.entity.Dict;
+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
@@ -18,21 +23,48 @@
 
     @Autowired
     private UserService userService;
+    @Autowired
+    private DictService dictService;
 
-    public MapDataParam getMapData(MapQueryParam param, Long userId) {
-        User user = userService.getById(userId);
-        if (Cools.isEmpty(user.getMemo())) {
-            return new MapDataParam();
+    public String getMapData(MapQueryParam param, Long userId) {
+        String mapKey = getMapKey(param.getFloor());
+        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, mapKey));
+        if (Cools.isEmpty(dict)) {
+            return null;
+        } else {
+            return dict.getValue();
         }
-        return JSON.parseObject(user.getMemo(), MapDataParam.class);
     }
 
     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()));
+           dict.setCreateBy(userId);
+           dict.setUpdateBy(userId);
+           if (!dictService.save(dict)) {
+               throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+           }
+        } else {
+            dict.setValue(JSON.toJSONString(param.getItemList()));
+            dict.setUpdateTime(new Date());
+            dict.setUpdateBy(userId);
+            if (!dictService.updateById(dict)) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
         }
     }
 
+    private String getMapKey(Integer floor) {
+        if (null != floor) {
+            return "map-" + floor;
+        }
+        return "map";
+    }
+
 }

--
Gitblit v1.9.1