From d877cf557db5452093087fabb4479a10497ee218 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期一, 28 二月 2022 18:25:32 +0800
Subject: [PATCH] fix

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/controller/XiXunController.java |  229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 222 insertions(+), 7 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 9fab077..1181a0c 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,27 +1,32 @@
 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.baomidou.mybatisplus.extension.api.R;
 import com.github.pagehelper.PageHelper;
 import com.sandu.common.domain.ResponseVO;
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.object.BaseConditionVO;
 import com.sandu.common.util.ResponseUtil;
 import com.sandu.ximon.admin.entity.ProgramPro;
+import com.sandu.ximon.admin.param.LEDScheduleParam_xixun;
+import com.sandu.ximon.admin.param.SetVolumeParam;
 import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.admin.service.ClientService;
+import com.sandu.ximon.admin.service.LedScheduleService;
 import com.sandu.ximon.admin.service.PoleLightemitService;
 import com.sandu.ximon.admin.service.XiXunPlayerService;
-import com.sandu.ximon.dao.domain.LedPlayerEntity;
+import com.sandu.ximon.admin.utils.LightemitUtils;
 import com.sandu.ximon.dao.domain.PoleLightemitEntity;
 import com.sandu.ximon.dao.domain.PoleXixunPlayerEntity;
 import com.sandu.ximon.dao.enums.AdministratorEnums;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Date;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -37,30 +42,87 @@
     private final XiXunPlayerService xiXunPlayerService;
     private final ClientService clientService;
     private final PoleLightemitService poleLightemitService;
+    private final LightemitUtils lightemitUtils;
+    private final LedScheduleService scheduleService;
 
+    /**
+     * 鏂板鑺傜洰
+     * @param programPro
+     * @return
+     */
     @PostMapping("/addProgram")
     public ResponseVO<Object> addProgram(@RequestBody ProgramPro programPro){
        return ResponseUtil.success(xiXunPlayerService.insert(programPro));
     }
 
+    /**
+     * 淇敼
+     */
+    @PostMapping("/updateProgram")
+   // @RequiresPermissions("pole:polexixunplayer:update")
+    public ResponseVO<Object> update(@RequestBody ProgramPro programPro){
+        PoleXixunPlayerEntity byId = xiXunPlayerService.getById(programPro.getProgramId());
+        if(byId==null){
+            throw  new BusinessException("鍙傛暟閿欒");
+        }
+//        QueryWrapper<PoleXixunPlayerEntity> queryWrapper = new QueryWrapper<>();
+//        queryWrapper.eq("program_code", programPro.get_id());
+        boolean insert=false;
+        if(xiXunPlayerService.removeById(programPro.getProgramId())){
+             insert = xiXunPlayerService.insert(programPro);
+        };
+        return  ResponseUtil.success(insert);
+    }
+
+    /**
+     * 鍒犻櫎鑺傜洰
+     * @param pid
+     * @return
+     */
     @PostMapping("/deleteProgram/{pid}")
     public ResponseVO<Object> deleteProgram(@PathVariable Long pid){
         return ResponseUtil.success(xiXunPlayerService.deleteProgram(pid));
     }
 
+    /**
+     * 鑾峰彇鑺傜洰璇︽儏
+     * @param pid
+     * @return
+     */
     @GetMapping("/getByPid/{pid}")
     public ResponseVO<Object> getByPid(@PathVariable Long pid){
         return ResponseUtil.success(xiXunPlayerService.getByPid(pid));
     }
+
+    /**
+     * 鑺傜洰鍒楄〃
+     * @param baseConditionVO
+     * @param keyword
+     * @return
+     */
     @GetMapping("/list")
     public ResponseVO<Object> list(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String 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())) {
-//            clientService.findClientId()
-//            wrapper.eq(PoleXixunPlayerEntity::getCreateUserId,)
-            //wrapper.eq(LedPlayerEntity::get)
+
             return ResponseUtil.success(xiXunPlayerService.list(wrapper)); //  todo
         }else {
             return ResponseUtil.success(xiXunPlayerService.list(wrapper));
@@ -68,12 +130,23 @@
     }
 
 
+    /**
+     * 鑺傜洰鎺ㄩ��
+     * @param pid
+     * @param lightemitIds
+     * @return
+     */
     @GetMapping("/pushToXixun/{pid}")
     public ResponseVO<Object> getByPid(@PathVariable Long pid, @RequestBody List<Long> lightemitIds ){
         xiXunPlayerService.videoXixunPlayer(pid,lightemitIds);
         return ResponseUtil.success("鎺ㄩ�佹垚鍔�");
     }
 
+    /**
+     * LED灞忓箷鏂板
+     * @param poleLightemit
+     * @return
+     */
     @PostMapping("/saveLed")
     public ResponseVO<Object> save(@RequestBody PoleLightemitEntity poleLightemit){
         int count = poleLightemitService.count(new QueryWrapper<PoleLightemitEntity>().eq("lightemit_control_code", poleLightemit.getLightemitControlCode()));
@@ -85,7 +158,149 @@
 
         poleLightemitService.savePoleLightemit(poleLightemit);
 
-        return ResponseUtil.success("");
+
+        return ResponseUtil.success("鏂板鎴愬姛");
     }
 
+    /**
+     * LED灞忓箷淇敼
+     * @param ledId
+     * @param poleLightemit
+     * @return
+     */
+    @PostMapping("/updateLed/{ledId}")
+    public ResponseVO<Object> updatePoleLightemit(@PathVariable Long ledId,@RequestBody PoleLightemitEntity poleLightemit){
+        poleLightemitService.updatePoleLightemit(ledId,poleLightemit);
+        return ResponseUtil.success("淇敼鎴愬姛");
+    }
+
+    /**
+     * LED灞忓箷鍒犻櫎
+     * @param ledIds
+     * @return
+     */
+    @PostMapping("/deleteLed")
+    public ResponseVO<Object> deleteLed(@RequestBody List<Long> ledIds){
+        boolean b = poleLightemitService.deletePoleLightemit(ledIds);
+        if(b){
+            return ResponseUtil.success("鍒犻櫎鎴愬姛");
+        }else {
+            return ResponseUtil.success("鍒犻櫎澶辫触");
+        }
+    }
+
+    /**
+     * LED灞忓箷鍒楄〃
+     * @param baseConditionVO
+     * @param keyword
+     * @return
+     */
+    @GetMapping("/listLed")
+    public ResponseVO<Object> listLed(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) {
+        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());
+        }
+        wrapper=Wrappers.lambdaQuery(PoleLightemitEntity.class);
+        if(StrUtil.isNotBlank(keyword)){
+            wrapper.like(PoleLightemitEntity::getLightemitName,keyword).or(
+                    lambdaQueryWrapper -> {
+                        lambdaQueryWrapper.like(PoleLightemitEntity::getLightemitControlCode, keyword);
+                    }
+            );
+        }
+        return ResponseUtil.success(poleLightemitService.list(wrapper));
+    }
+
+    @GetMapping("/onLineLed")
+    public ResponseVO<Object> onlineLed() {
+        return ResponseUtil.success(poleLightemitService.ledList());
+    }
+
+
+    /*
+  鑾峰彇led瀹炴椂鐢婚潰
+   */
+    @GetMapping("/getPicture/{id}")
+    public ResponseVO<Object> getPicture(@PathVariable Long id){
+        if(id == null){
+           throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+        PoleLightemitEntity poleLightemitEntity = poleLightemitService.getById(id);
+        if(poleLightemitEntity != null){
+            String result = lightemitUtils.getPicture(poleLightemitEntity.getLightemitControlCode());
+            return ResponseUtil.success(result);
+        }else {
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+    }
+
+    /*
+  鑾峰彇闊抽噺
+   */
+    @PostMapping("/getVolume/{id}")
+    public ResponseVO<Object> getVolume(@PathVariable Long id){
+        if(id == null){
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+        PoleLightemitEntity poleLightemitEntity = poleLightemitService.getById(id);
+        if(poleLightemitEntity != null){
+            String result = lightemitUtils.getVoiume(poleLightemitEntity.getLightemitControlCode());
+            return ResponseUtil.success(result);
+        }else {
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+    }
+
+
+    /*
+  璁剧疆闊抽噺
+   */
+    @PostMapping("/setVolume")
+    public ResponseVO<Object> setVolume(@RequestBody SetVolumeParam setVolumeEntity){
+
+        if(setVolumeEntity == null || setVolumeEntity.getIds() == null || setVolumeEntity.getVolume() > 15){
+            throw new BusinessException("鍙傛暟閿欒");
+        }
+
+        Collection poleLightemitControllers = poleLightemitService.listByIds(Arrays.asList(setVolumeEntity.getIds()));
+        if (!poleLightemitControllers.isEmpty()) {
+            Iterator iterator = poleLightemitControllers.iterator();
+            while (iterator.hasNext()) {
+                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
+                poleLightemitService.setVolume(poleLightemitEntity.getLightemitControlCode(), setVolumeEntity.getVolume());
+            }
+            return ResponseUtil.success("璁剧疆闊抽噺鎴愬姛");
+        }else {
+            throw new BusinessException("鏈�夋嫨LED灞�");
+        }
+    }
+
+    @PostMapping("/addSchedule")
+    public ResponseVO<Object> addSchedule(@RequestBody LEDScheduleParam_xixun ledEntity){
+        return ResponseUtil.success(scheduleService.insert(ledEntity));
+    }
+
+    @PostMapping("/updateSchedule")
+    public ResponseVO<Object> updateSchedule(@RequestBody LEDScheduleParam_xixun ledEntity){
+        return ResponseUtil.success(scheduleService.updateSchedule(ledEntity));
+    }
+
+    @GetMapping("/getSchedule/{id}")
+    public ResponseVO<Object> getSchedule(@PathVariable Integer id){
+        return ResponseUtil.success(scheduleService.getSchedule(id));
+    }
+
+    @PostMapping("/pushSchedule/{id}")
+    public ResponseVO<Object> pushSchedule(@PathVariable Integer id,@RequestBody Long[] lightemitIds){
+        scheduleService.ledschedulepush(id,lightemitIds);
+        return ResponseUtil.success("璁剧疆鎴愬姛");
+    }
+
+
 }

--
Gitblit v1.9.3