From 8c46bedb1a637ba04bd406dab7bba889e1d5d658 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期六, 07 五月 2022 18:30:22 +0800
Subject: [PATCH] fix

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/controller/XiXunController.java |  189 ++++++++++++++++++++++------------------------
 1 files changed, 90 insertions(+), 99 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/XiXunController.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/XiXunController.java
index c572062..2e58f80 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/XiXunController.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/controller/XiXunController.java
@@ -1,15 +1,15 @@
 package com.sandu.ximon.admin.controller;
 
-import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.pagehelper.PageHelper;
 import com.sandu.common.domain.CommonPage;
 import com.sandu.common.domain.ResponseVO;
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.object.BaseConditionVO;
+import com.sandu.common.security.annotation.AnonymousAccess;
 import com.sandu.common.util.ResponseUtil;
+import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.entity.ProgramPro;
 import com.sandu.ximon.admin.param.LEDScheduleParam_xixun;
 import com.sandu.ximon.admin.param.SetBrightnessParam;
@@ -19,11 +19,9 @@
 import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.admin.service.*;
 import com.sandu.ximon.admin.utils.LightemitUtils;
-import com.sandu.ximon.dao.domain.Pole;
-import com.sandu.ximon.dao.domain.PoleBinding;
+import com.sandu.ximon.admin.vo.LedScheduleVO;
 import com.sandu.ximon.dao.domain.PoleLightemitEntity;
 import com.sandu.ximon.dao.domain.PoleXixunPlayerEntity;
-import com.sandu.ximon.dao.enums.AdministratorEnums;
 import com.sandu.ximon.dao.enums.MenuEnum;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
@@ -115,31 +113,10 @@
         if (!permissionConfig.check(MenuEnum.LED_PROGRAM_LIST.getCode())) {
             return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
         }
+        LambdaQueryWrapper<PoleXixunPlayerEntity> wrapper = xiXunPlayerService.XixunPlayerList(keyword);
         PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
 
-        LambdaQueryWrapper<PoleXixunPlayerEntity> wrapper = Wrappers.lambdaQuery(PoleXixunPlayerEntity.class).like(PoleXixunPlayerEntity::getProgramName, keyword);
-//        if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())){
-//            boolean clientId = clientService.findClientId();
-//            if(clientId){
-//                wrapper= wrapper.eq(PoleXixunPlayerEntity::getUserId,SecurityUtils.getUserId());
-//            }
-//            wrapper= wrapper.eq(PoleXixunPlayerEntity::getClientId,clientService.getClientId());
-//        }
-//        wrapper=Wrappers.lambdaQuery(PoleXixunPlayerEntity.class);
-//        if(StrUtil.isNotBlank(keyword)){
-//            wrapper.like(PoleXixunPlayerEntity::getLightemitName,keyword).or(
-//                    lambdaQueryWrapper -> {
-//                        lambdaQueryWrapper.like(PoleXixunPlayerEntity::getLightemitControlCode, keyword);
-//                    }
-//            );
-//        }
-//        return ResponseUtil.success(poleLightemitService.list(wrapper));
-        if (AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) {
-
-            return ResponseUtil.success(xiXunPlayerService.list(wrapper)); //  todo
-        } else {
-            return ResponseUtil.success(xiXunPlayerService.list(wrapper));
-        }
+        return ResponseUtil.success(xiXunPlayerService.list(wrapper));
     }
 
 
@@ -156,6 +133,13 @@
         return ResponseUtil.success("鎺ㄩ�佹垚鍔�");
     }
 
+    //鎵ц涓殑鑺傜洰
+    @GetMapping("/getProgram/{lightemitId}")
+    public ResponseVO<Object> getProgram(@PathVariable Long lightemitId) {
+        return ResponseUtil.success(xiXunPlayerService.getByPid(lightemitId));
+    }
+
+
     /**
      * LED灞忓箷鏂板
      *
@@ -169,7 +153,11 @@
             throw new BusinessException("LED鎺у埗鍗$紪鍙蜂笉鑳介噸澶�");
         }
 
-        poleLightemit.setCreateUserId(SecurityUtils.getClientId());
+        if (SecurityUtils.getClientId() == null) {
+            poleLightemit.setClientId(clientService.getClientId());
+            poleLightemit.setUserId(SecurityUtils.getUserId());
+            poleLightemit.setCreateUserId(SecurityUtils.getUserId());
+        }
 
         poleLightemitService.savePoleLightemit(poleLightemit);
 
@@ -219,84 +207,30 @@
         if (!permissionConfig.check(MenuEnum.LED_LIST.getCode())) {
             return ResponseUtil.fail("缂哄皯瀵瑰簲鐢ㄦ埛鏉冮檺");
         }
-        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
-        LambdaQueryWrapper<PoleLightemitEntity> wrapper = Wrappers.lambdaQuery(PoleLightemitEntity.class);
-        if (AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) {
-            boolean clientId = clientService.findClientId();
-            if (clientId) {
-                wrapper = wrapper.eq(PoleLightemitEntity::getUserId, SecurityUtils.getUserId());
-            }
-            wrapper = wrapper.eq(PoleLightemitEntity::getClientId, clientService.getClientId());
+        List<PoleLightemitEntity> poleLightemitEntityList = poleLightemitService.listLed(keyword, isOnLine);
+        poleLightemitEntityList.forEach(
+                led -> {
+                    led.setStreetlightId(led.getPoleId());
+                    led.setStreetlightName(led.getPoleName());
+                }
+        );
+
+        CommonPage commonPage = CommonPage.restPage(poleLightemitEntityList);
+        int size = poleLightemitEntityList.size();
+        commonPage.setTotal((long) size);
+        commonPage.setTotalPage(size / baseConditionVO.getPageSize() + 1);
+        if (size % baseConditionVO.getPageSize() == 0) {
+            commonPage.setTotalPage(size / baseConditionVO.getPageSize());
         }
-        wrapper = Wrappers.lambdaQuery(PoleLightemitEntity.class);
-        if (StrUtil.isNotBlank(keyword)) {
-            wrapper.like(PoleLightemitEntity::getLightemitName, keyword).or(
-                    lambdaQueryWrapper -> {
-                        lambdaQueryWrapper.like(PoleLightemitEntity::getLightemitControlCode, keyword);
-                    }
-            );
-        }
-        List<PoleBinding> bindings = bindingService.list(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceType, 1));
-        List<PoleLightemitEntity> list = poleLightemitService.list(wrapper);
-        if (isOnLine) {
-            List<PoleLightemitEntity> results = poleLightemitService.ledOnline(list);
-            results.forEach(
-                    led -> {
-                        bindings.forEach(
-                                bind -> {
-                                    if (bind.getDeviceCode() != null && led.getLightemitControlCode() == bind.getDeviceCode()) {
-                                        led.setStreetlightId(bind.getPoleId());
-                                        System.out.println("鏈夋病鏈夎繍琛屽埌杩欓噷?---------------" + bind.getPoleId());
-                                        led.setStreetlightName(poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, bind.getPoleId())).getPoleName());
-                                    }
-                                }
-                        );
-                    }
-            );
-            CommonPage commonPage = CommonPage.restPage(results);
-            int size = results.size();
-            commonPage.setTotal((long) size);
-            commonPage.setTotalPage(size / baseConditionVO.getPageSize() + 1);
-            if (size % baseConditionVO.getPageSize() == 0) {
-                commonPage.setTotalPage(size / baseConditionVO.getPageSize());
-            }
-            return ResponseUtil.success(commonPage);
-        } else {
-            poleLightemitService.ledOnlineCheck(list);
-            list.forEach(
-                    led -> {
-                        bindings.forEach(
-                                bind -> {
-                                    if (bind.getDeviceCode() != null && led.getLightemitControlCode().equals(bind.getDeviceCode())) {
-                                        led.setStreetlightId(bind.getPoleId());
-                                        System.out.println("鏈夋病鏈夎繍琛屽埌杩欓噷?---------------" + bind.getPoleId());
-                                        led.setStreetlightName(poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, bind.getPoleId())).getPoleName());
-                                    }
-                                }
-                        );
-                    }
-            );
-            CommonPage commonPage = CommonPage.restPage(list);
-            int size = list.size();
-            commonPage.setTotal((long) size);
-            commonPage.setTotalPage(size / baseConditionVO.getPageSize() + 1);
-            if (size % baseConditionVO.getPageSize() == 0) {
-                commonPage.setTotalPage(size / baseConditionVO.getPageSize());
-            }
-            return ResponseUtil.success(commonPage);
-            // return ResponseUtil.success(list);
-        }
-//        return ResponseUtil.success(poleLightemitService.list(wrapper));
+        return ResponseUtil.success(commonPage);
     }
 
     /**
-     *
-     *
      * @param
      * @return
      */
     @GetMapping("/getbycode")
-  public ResponseVO<Object> getLedByLightControlCode(String lightemitControlCode) {
+    public ResponseVO<Object> getLedByLightControlCode(String lightemitControlCode) {
         return ResponseUtil.success(poleLightemitService.getLedByLightControlCode(lightemitControlCode));
     }
 
@@ -304,6 +238,7 @@
     璁剧疆灞忓箷寮�鍏�
      */
 
+    @AnonymousAccess
     @PostMapping("/setScreenOpen")
     public ResponseVO<Object> setScreenOpen(@RequestBody SetScreenOpenParam setScreenOpenEntity) {
         if (setScreenOpenEntity.getIds() == null || setScreenOpenEntity.getIds().length == 0 || setScreenOpenEntity.getBool() == null) {
@@ -366,6 +301,18 @@
         } else {
             throw new BusinessException("鏈�夋嫨LED灞�");
         }
+    }
+
+
+    /**
+     * 娴嬭瘯
+     * @param
+     * @return
+     */
+    @AnonymousAccess
+    @PostMapping("/test/{str}")
+    public ResponseVO<Object> setBrightness(@PathVariable String str) {
+       return ResponseUtil.success(lightemitUtils.getIsScreenOpen(str));
     }
 
 
@@ -459,7 +406,51 @@
         return ResponseUtil.success("璁剧疆鎴愬姛");
     }
 
+    /**
+     * 鑾峰彇鎵ц涓殑瀹氭椂
+     *
+     * @param
+     * @return
+     */
+
+    @GetMapping("/getPushSchedule")
+    public ResponseVO<Object> getPushSchedule(@RequestBody List<Long> ids) {
+        if (ids.isEmpty()) {
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+        List<LedScheduleVO> list = new ArrayList<>();
+        for (Long id : ids) {
+            LedScheduleVO ledScheduleVO = scheduleService.getledschedules(id);
+            list.add(ledScheduleVO);
+        }
+        return ResponseUtil.success(list);
+    }
 
 
+    /**
+     * 鍏抽棴澶╂皵鎺ㄩ��
+     */
+    @GetMapping("/closeWeatherPush/{id}")
+    public ResponseVO<Object> closeWeatherPush(@PathVariable Long id) {
+        if (id == null) {
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+        SpringContextHolder.getBean(PoleService.class).closeXiXunAirPush(id);
+        return ResponseUtil.success("鍏抽棴鎴愬姛");
+    }
 
+    /**
+     * 娓呭睆鎿嶄綔
+     */
+    @GetMapping("/clearScreen")
+    public ResponseVO<Object> clearScreen(@RequestBody List<Long> ids) {
+        List<PoleLightemitEntity> list = poleLightemitService.listByIds(ids);
+        if (ids.isEmpty() && list.isEmpty()) {
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+        for (PoleLightemitEntity playerId : list) {
+            lightemitUtils.clear(playerId.getLightemitControlCode());
+        }
+        return ResponseUtil.success("娓呭睆鎴愬姛");
+    }
 }

--
Gitblit v1.9.3