From 8a5b6b092754685b4da940d2a35a855832f92465 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期五, 22 四月 2022 16:10:46 +0800
Subject: [PATCH] fix

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java |   47 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
index 9c8ffd5..ac3a1ea 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
@@ -12,28 +12,34 @@
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 @AllArgsConstructor
 public class LEDProgramService extends BaseServiceImpl<LEDProgramMapper, LEDProgram> {
 
-
+    private final ClientService clientService;
 
     public boolean addProgram(LEDProgramParam receiveParam) {
 
         LEDProgram led = new LEDProgram();
-        led.setUserId(SecurityUtils.getClientId());
         if (SecurityUtils.getClientId() != null) {
+            led.setUserId(SecurityUtils.getUserId());
             led.setUserName(SecurityUtils.getUsername());
+            if (clientService.findClientId()) {
+                led.setClientId(clientService.getClientId());
+            }
         }
         led.setName(receiveParam.getName());
         led.setPreview(receiveParam.getPreviewUrl());
+        led.setWidth(receiveParam.getWidth());
+        led.setHeight(receiveParam.getHeight());
         led.setPages(JSON.toJSONString(receiveParam.getPages()));
-//        led.setPages(JSONArray.fromObject(receiveParam.getPages()).toString());
         return save(led);
     }
 
 
-    public boolean updateProgram(Long pid,LEDProgramParam receiveParam) {
+    public boolean updateProgram(Long pid, LEDProgramParam receiveParam) {
 
         LEDProgram byId = getById(pid);
         if (byId == null) {
@@ -45,7 +51,9 @@
         //led.setUserId(SecurityUtils.getClientId());
         led.setName(receiveParam.getName());
         led.setPreview(receiveParam.getPreviewUrl());
-        led.setPages(receiveParam.getPages().toString());
+        led.setWidth(receiveParam.getWidth());
+        led.setHeight(receiveParam.getHeight());
+        led.setPages(JSON.toJSONString(receiveParam.getPages()));
         return updateById(led);
     }
 
@@ -60,13 +68,30 @@
 
     }
 
-
-    public LambdaQueryWrapper<LEDProgram> listProgram() {
-        if (SecurityUtils.getClientId() != null) {
-            return Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId, SecurityUtils.getClientId());
-        } else {
-            return Wrappers.lambdaQuery(LEDProgram.class);
+    public LEDProgramParam getByPid(Long id) {
+        LEDProgram byId = getById(id);
+        if (byId == null) {
+            throw new BusinessException("鏈壘鍒拌鑺傜洰");
         }
+        LEDProgramParam param = new LEDProgramParam();
+        param.setId(byId.getId());
+        param.setHeight(byId.getHeight());
+        param.setWidth(byId.getWidth());
+        param.setName(byId.getName());
+        param.setPreviewUrl(byId.getPreview());
+        param.setPages(JSON.parseObject(byId.getPages(), List.class));
+        return param;
     }
 
+
+    public LambdaQueryWrapper<LEDProgram> listProgram() {
+        if (SecurityUtils.getClientId() == null) {
+            return Wrappers.lambdaQuery(LEDProgram.class);
+        } else {
+            return Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId, SecurityUtils.getUserId())
+                    .or(w -> {
+                        w.eq(LEDProgram::getClientId, SecurityUtils.getClientId());
+                    });
+        }
+    }
 }

--
Gitblit v1.9.3