From e55c8b0a92eb9715edd90c31dfd4de51a47b588b Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 04 十一月 2022 17:40:08 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java |  118 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 99 insertions(+), 19 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 31cdcad..346f302 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
@@ -1,70 +1,150 @@
 package com.sandu.ximon.admin.service;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.PageHelper;
 import com.sandu.common.execption.BusinessException;
+import com.sandu.common.object.BaseConditionVO;
 import com.sandu.common.service.impl.BaseServiceImpl;
 import com.sandu.ximon.admin.param.LEDProgramParam;
 import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.dao.domain.LEDProgram;
+import com.sandu.ximon.dao.enums.OrderByEnums;
 import com.sandu.ximon.dao.mapper.LEDProgramMapper;
 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.setUserName(SecurityUtils.getUsername());
+        led.setUserId(SecurityUtils.getUserId());
+        led.setUserName(SecurityUtils.getUsername());
+        if (clientService.findClientId()) {
+            led.setClientId(clientService.getClientId());
         }
         led.setName(receiveParam.getName());
         led.setPreview(receiveParam.getPreviewUrl());
-        led.setPages(receiveParam.getPages());
+        led.setWidth(receiveParam.getWidth());
+        led.setHeight(receiveParam.getHeight());
+        if (receiveParam.getPages() == null) {
+            throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+        }
+        led.setPages(JSON.toJSONString(receiveParam.getPages()));
         return save(led);
     }
 
 
-    public boolean updateProgram(Long pid,LEDProgramParam receiveParam) {
+    public boolean updateProgram(Long pid, LEDProgramParam receiveParam) {
 
-        LEDProgram byId = getById(pid);
-        if (byId == null) {
+        LEDProgram led = getById(pid);
+        if (led == null) {
             throw new BusinessException("鏈壘鍒拌鑺傜洰");
         }
 
-        LEDProgram led = new LEDProgram();
-        led.setId(pid);
-        //led.setUserId(SecurityUtils.getClientId());
         led.setName(receiveParam.getName());
         led.setPreview(receiveParam.getPreviewUrl());
-        led.setPages(receiveParam.getPages());
+        led.setWidth(receiveParam.getWidth());
+        led.setHeight(receiveParam.getHeight());
+        if (receiveParam.getPages() == null) {
+            throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+        }
+        led.setPages(JSON.toJSONString(receiveParam.getPages()));
         return updateById(led);
     }
 
 
-    public boolean deleteProgram(Long id) {
+    public boolean deleteProgram(List<Long> pids) {
+        List<LEDProgram> ledPrograms = listByIds(pids);
+        if (ledPrograms.isEmpty()) {
+            throw new BusinessException("鏈壘鍒拌鑺傜洰");
+        }
+
+        return removeByIds(pids);
+
+    }
+
+    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;
+    }
 
-        return removeById(id);
+    public List<LEDProgram> listProgram(BaseConditionVO baseConditionVO, Integer order, Integer seq, String keyword) {
+        LambdaQueryWrapper<LEDProgram> wrapper = listPrograms();
 
+        if (keyword != null && !keyword.isEmpty()) {
+            wrapper.like(LEDProgram::getName, keyword);
+        }
+        //鎺掑簭瀛楁
+        String orderByResult = "id";
+        //姝e簭銆佸�掑彊
+        String orderBySeq = OrderByEnums.ASC.getCode();
+        if (order != null) {
+            switch (order) {
+                case 1:
+                    orderByResult = OrderByEnums.LED_N_PROGRAM_CREATE_TIME.getCode();
+                    break;
+                default:
+            }
+        }
+        if (seq != null) {
+            switch (seq) {
+                case 1:
+                    orderBySeq = OrderByEnums.ASC.getCode();
+                    break;
+                case 2:
+                    orderBySeq = OrderByEnums.DESC.getCode();
+                    break;
+                default:
+                    break;
+            }
+        }
+        //鎺掑簭鏂瑰紡
+        String orderBy = orderByResult + " " + orderBySeq;
+
+        if (baseConditionVO != null) {
+            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
+        }
+        return list(wrapper);
+    }
+
+    public List<LEDProgram> listProgramOnBinding(String keyword) {
+        LambdaQueryWrapper<LEDProgram> wrapper = listPrograms();
+
+        if (keyword != null && !keyword.isEmpty()) {
+            wrapper.like(LEDProgram::getName, keyword);
+        }
+
+        return list(wrapper);
     }
 
 
-    public LambdaQueryWrapper<LEDProgram> listProgram() {
-        if (SecurityUtils.getClientId() != null) {
-            return Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId, SecurityUtils.getClientId());
-        } else {
+    public LambdaQueryWrapper<LEDProgram> listPrograms() {
+        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