| | |
| | | package com.sandu.ximon.admin.newnova.led; |
| | | |
| | | 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.newnova.grouping.NewNovaGroupService; |
| | | import com.sandu.ximon.admin.newnova.param.NewNovaLedParam; |
| | | import com.sandu.ximon.admin.newnova.param.NewNovaStatusParam; |
| | | import com.sandu.ximon.admin.newnova.program.LEDInfoParam; |
| | | import com.sandu.ximon.admin.newnova.utils.NovaAPIUtil; |
| | | import com.sandu.ximon.admin.security.PermissionConfig; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.dao.domain.NewNovaGroup; |
| | | import com.sandu.ximon.dao.domain.NewNovaLed; |
| | | import com.sandu.ximon.dao.enums.MenuEnum; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | public class NewNovaLedController { |
| | | private final PermissionConfig permissionConfig; |
| | | private final NewNovaLedService newNovaLedService; |
| | | private final NewNovaGroupService groupService; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/listLed") |
| | | public ResponseVO listLed(BaseConditionVO baseConditionVO, @RequestParam(required = false, value = "keyword") String keyword, |
| | | @RequestParam(required = false, value = "onlineStatus") boolean onlineStatus) { |
| | | @RequestParam(required = true, value = "onlineStatus", defaultValue = "false") boolean onlineStatus, |
| | | @RequestParam(required = false, value = "groupId") Long groupId) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | return ResponseUtil.success(newNovaLedService.listLed(baseConditionVO, keyword, onlineStatus)); |
| | | return ResponseUtil.success(newNovaLedService.listLed(baseConditionVO, keyword, groupId, onlineStatus)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 状态列表 |
| | | */ |
| | | @PostMapping("/ledInfo") |
| | | public ResponseVO ledInfo(@RequestBody @Validated LEDInfoParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | return ResponseUtil.success(newNovaLedService.infoList(param)); |
| | | } |
| | | |
| | | /** |
| | |
| | | return ResponseUtil.success(newNovaLedService.getInfo(ledId)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置亮度 |
| | | */ |
| | | @PostMapping("/setBrightness") |
| | | public ResponseVO setScreenBrightness(@RequestBody @Validated NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_VOL.getCode())) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_BRIGHTNESS.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (param.getBrightness() == null) { |
| | |
| | | return ResponseUtil.fail("亮度范围为: 0-100"); |
| | | } |
| | | } |
| | | if (newNovaLedService.getById(param.getId()) == null) { |
| | | NewNovaLed byId = newNovaLedService.getById(param.getId()); |
| | | if (byId == null) { |
| | | return ResponseUtil.fail("设备不存在"); |
| | | } else { |
| | | if (!byId.getSn().equals(param.getSn())) { |
| | | return ResponseUtil.fail("sn与id不匹配"); |
| | | } |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().setScreenBrightness(param)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置音量 |
| | | */ |
| | | @PostMapping("/setVolume") |
| | | public ResponseVO setVolume(@RequestBody @Validated NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_VOL.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (param.getVolume() == null) { |
| | | return ResponseUtil.fail("音量不能为空"); |
| | | } else { |
| | | if (param.getVolume() > 100 || param.getVolume() < 0) { |
| | | return ResponseUtil.fail("音量范围为: 0-100"); |
| | | } |
| | | } |
| | | NewNovaLed byId = newNovaLedService.getById(param.getId()); |
| | | if (byId == null) { |
| | | return ResponseUtil.fail("设备不存在"); |
| | | } else { |
| | | if (!byId.getSn().equals(param.getSn())) { |
| | | return ResponseUtil.fail("sn与id不匹配"); |
| | | } |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().setVolume(param)); |
| | | } |
| | | |
| | | /** |
| | | * 设置同步 |
| | | */ |
| | | @PostMapping("/setSync") |
| | | public ResponseVO setSync(@RequestBody NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_SYNC.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (param.getNovaList() == null || param.getNovaList().isEmpty()) { |
| | | return ResponseUtil.fail("请选择设备"); |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().setSync(param)); |
| | | } |
| | | |
| | | /** |
| | | * 设置屏幕开关 |
| | | */ |
| | | @PostMapping("/setPowerStatus") |
| | | public ResponseVO setPowerStatus(@RequestBody NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_POWER.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | NewNovaLed byId = newNovaLedService.getById(param.getId()); |
| | | if (byId == null) { |
| | | return ResponseUtil.fail("设备不存在"); |
| | | } else { |
| | | if (!byId.getSn().equals(param.getSn())) { |
| | | return ResponseUtil.fail("sn与id不匹配"); |
| | | } |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().setPowerStatus(param)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重启 |
| | | */ |
| | | @PostMapping("/reboot") |
| | | public ResponseVO reboot(@RequestBody NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_REBOOT.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (param.getNovaList() == null || param.getNovaList().isEmpty()) { |
| | | return ResponseUtil.fail("请选择设备"); |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().reboot(param)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * ntp |
| | | */ |
| | | @PostMapping("/ntp") |
| | | public ResponseVO ntp(@RequestBody NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_NTP.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (param.getNovaList() == null || param.getNovaList().isEmpty()) { |
| | | return ResponseUtil.fail("请选择设备"); |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().ntp(param)); |
| | | } |
| | | |
| | | /** |
| | | * 截屏 |
| | | */ |
| | | @PostMapping("/screenShot") |
| | | public ResponseVO screenShot(@RequestBody NewNovaStatusParam param) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_SCREENSHOT.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (param.getScreenShotList() == null || param.getScreenShotList().isEmpty()) { |
| | | return ResponseUtil.fail("请选择设备"); |
| | | } |
| | | return ResponseUtil.success(NovaAPIUtil.getInstanceUtil().screenShot(param)); |
| | | } |
| | | |
| | | /** |
| | | * 根据分组id获取组内的屏幕 |
| | | */ |
| | | @GetMapping("/getByGroupId") |
| | | public ResponseVO<Object> getByGroupId(@RequestParam(value = "groupId", required = true) Long groupId) { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_GROUB_INFO.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | if (groupId == null) { |
| | | throw new BusinessException("groupId不能为空"); |
| | | } |
| | | NewNovaGroup byId = groupService.getById(groupId); |
| | | if (SecurityUtils.getClientId() != null && !SecurityUtils.getUserId().equals(byId.getUserId())) { |
| | | throw new BusinessException("不能查看不属于自己分组的内容!"); |
| | | } |
| | | if (byId == null) { |
| | | throw new BusinessException("分组不存在"); |
| | | } |
| | | return ResponseUtil.success(newNovaLedService.getListByGroupId(groupId)); |
| | | } |
| | | |
| | | /** |
| | | * 推送大气 |
| | | */ |
| | | @GetMapping("/pushAirData") |
| | | public ResponseVO<Object> pushAirData(@RequestParam(value = "id", required = true) Long id |
| | | , @RequestParam(value = "duration", required = true) Long duration |
| | | , @RequestParam(value = "fontSize", required = true) Long fontSize) throws InterruptedException { |
| | | if (!permissionConfig.check(MenuEnum.LED_NEW_PUSH_AIR.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | return ResponseUtil.success(newNovaLedService.pushAirData(id, duration, fontSize)); |
| | | } |
| | | |
| | | |
| | | // @PostMapping("/tranPro") |
| | | // public ResponseVO<Object> tranPro(@RequestBody Map pageInfo) throws InterruptedException { |
| | | // NovaAPIUtil a = NovaAPIUtil.getInstanceUtil(); |
| | | // StatusVO login = a.login("MZVA51930N2113017308"); |
| | | // StatusVO login = a.login("MZVA51930N2113017308", 0); |
| | | // if (login.getStatusCode() != 0) { |
| | | // return ResponseUtil.fail("genVO"); |
| | | // } |