| | |
| | | package com.sandu.ximon.admin.newnova.led; |
| | | |
| | | 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.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.newnova.param.NewNovaLedParam; |
| | | import com.sandu.ximon.admin.newnova.utils.NovaAPIUtil; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.service.PoleBindingService; |
| | | import com.sandu.ximon.admin.service.PoleService; |
| | | import com.sandu.ximon.dao.domain.NewNovaLed; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.mapper.NewNovaLedMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author LiuHaoNan |
| | |
| | | NewNovaLed led = new NewNovaLed(); |
| | | led.setSn(param.getSn()); |
| | | led.setName(param.getName()); |
| | | led.setOnlineSign(0); |
| | | return save(led); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 编辑屏幕名称 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public boolean editLed(NewNovaLedParam param) { |
| | | if (param.getId() == null) { |
| | | throw new BusinessException("屏幕id不能为空"); |
| | | } |
| | | if (param.getName() == null || param.getName().isEmpty()) { |
| | | throw new BusinessException("屏幕名称不能为空"); |
| | | } |
| | | |
| | | NewNovaLed one = getById(param.getId()); |
| | | if (one == null) { |
| | | throw new BusinessException("设备不存在!"); |
| | | } |
| | | // one.setSn(param.getSn()); |
| | | one.setName(param.getName()); |
| | | return updateById(one); |
| | | } |
| | | |
| | | /** |
| | | * 删除LED |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | public boolean delLed(List<Long> ids) { |
| | | if (ids.isEmpty()) { |
| | | throw new BusinessException("id不能为空"); |
| | | } |
| | | List<NewNovaLed> newNovaLeds = listByIds(ids); |
| | | if (newNovaLeds.isEmpty()) { |
| | | throw new BusinessException("设备不存在!"); |
| | | } |
| | | //获取删除设备的设备码 |
| | | List<String> snList = newNovaLeds.stream().map(NewNovaLed::getSn).collect(Collectors.toList()); |
| | | //删除绑定关系 |
| | | SpringContextHolder.getBean(PoleBindingService.class).remove(Wrappers.lambdaQuery(PoleBinding.class) |
| | | .eq(PoleBinding::getDeviceType, 12).in(PoleBinding::getDeviceCode, snList)); |
| | | //删除设备 |
| | | return removeByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * LED列表 |
| | | * |
| | | * @param baseConditionVO |
| | | * @param keyword |
| | | * @param onlineStatus |
| | | * @return |
| | | */ |
| | | public List<NewNovaLed> listLed(BaseConditionVO baseConditionVO, String keyword, boolean onlineStatus) { |
| | | |
| | | NovaAPIUtil instanceUtil = NovaAPIUtil.getInstanceUtil(); |
| | | //排序 |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | List<NewNovaLed> newNovaListBos = baseMapper.listLed(keyword, SecurityUtils.getClientId()); |
| | | //获取在线状态 |
| | | instanceUtil.getOnlineStatus(newNovaListBos); |
| | | //获取屏幕开关 |
| | | instanceUtil.getScreenPowerState(newNovaListBos); |
| | | //获取音量 |
| | | instanceUtil.getVolumeState(newNovaListBos); |
| | | //获取亮度 |
| | | instanceUtil.getScreenBrightness(newNovaListBos); |
| | | //获取同步状态 |
| | | instanceUtil.getSync(newNovaListBos); |
| | | |
| | | updateBatchById(newNovaListBos); |
| | | return newNovaListBos; |
| | | } |
| | | |
| | | public NewNovaLed getInfo(Long ledId) { |
| | | NovaAPIUtil instanceUtil = NovaAPIUtil.getInstanceUtil(); |
| | | NewNovaLed byId = getById(ledId); |
| | | if (byId == null) { |
| | | throw new BusinessException("设备不存在或id不正确 !"); |
| | | } |
| | | PoleBinding poleBinding = SpringContextHolder.getBean(PoleBindingService.class).getOne(Wrappers.lambdaQuery(PoleBinding.class) |
| | | .eq(PoleBinding::getDeviceCode, byId.getSn()).eq(PoleBinding::getDeviceType, 12)); |
| | | if (poleBinding != null) { |
| | | Pole pole = SpringContextHolder.getBean(PoleService.class).getById(poleBinding.getPoleId()); |
| | | byId.setPoleId(pole.getId()); |
| | | byId.setPoleName(pole.getPoleName()); |
| | | } |
| | | List<NewNovaLed> list = new ArrayList<>(); |
| | | list.add(byId); |
| | | //获取在线状态 |
| | | instanceUtil.getOnlineStatus(list); |
| | | //获取屏幕开关 |
| | | instanceUtil.getScreenPowerState(list); |
| | | //获取音量 |
| | | instanceUtil.getVolumeState(list); |
| | | //获取亮度 |
| | | instanceUtil.getScreenBrightness(list); |
| | | //获取同步状态 |
| | | instanceUtil.getSync(list); |
| | | //获取详情 |
| | | instanceUtil.getInfo(byId); |
| | | return list.get(0); |
| | | } |
| | | } |