| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.domain.CommonPage; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.redis.RedisService; |
| | |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.dto.DeviceStatus; |
| | | import com.sandu.ximon.admin.dto.WaterQualityDataDto; |
| | | import com.sandu.ximon.admin.entity.Command; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A1Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.IRequestFrame; |
| | |
| | | import com.sandu.ximon.admin.redis.LightKey; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.LightemitUtils; |
| | | import com.sandu.ximon.admin.utils.ListPagingUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.utils.response.VnnoxResult; |
| | | import com.sandu.ximon.admin.vo.PoleBindVO; |
| | |
| | | Pole pole = getById(poleId); |
| | | if (pole == null) { |
| | | throw new BusinessException("未找到该灯杆"); |
| | | } |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | //非超管 |
| | | if (clientId != null) { |
| | | if (!Objects.equals(SecurityUtils.getUserId(), pole.getUserId()) && !Objects.equals(SecurityUtils.getUserId(), pole.getClientId())) { |
| | | throw new BusinessException("该灯杆不属于您"); |
| | | } |
| | | } |
| | | Pole update = new Pole(); |
| | | BeanUtils.copyProperties(param, update); |
| | |
| | | return result; |
| | | } |
| | | |
| | | public List<Pole> queryAllStatesAndList(Integer pageNo, Integer pageSize, PoleStatesParam param) { |
| | | |
| | | List<Pole> list = new ArrayList<>(); |
| | | LambdaQueryWrapper<Pole> wrapper = new LambdaQueryWrapper<>(); |
| | | public CommonPage queryAllStatesAndList(Integer pageNo, Integer pageSize, PoleStatesParam param) { |
| | | if (param == null) { |
| | | param = new PoleStatesParam(); |
| | | } |
| | | System.out.println(param); |
| | | List<Pole> poleList; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | wrapper = Wrappers.lambdaQuery(Pole.class); |
| | | poleList = poleMapper.queryPoleOnLineStatesList(null, param.getIsTrue(), param.getBingStates(), param.getGroupid(), param.getKeyword()); |
| | | } else { |
| | | wrapper = Wrappers.lambdaQuery(Pole.class).eq(Pole::getClientId, SecurityUtils.getUserId()).or( |
| | | w -> { |
| | | w.eq(Pole::getUserId, SecurityUtils.getUserId()); |
| | | }); |
| | | } |
| | | if (param.getKeyword() != null && !param.getKeyword().isEmpty()) { |
| | | wrapper.like(Pole::getPoleCode, param.getKeyword()).or( |
| | | wrappers -> { |
| | | wrappers.like(Pole::getPoleName, param.getKeyword()); |
| | | } |
| | | ); |
| | | poleList = poleMapper.queryPoleOnLineStatesList(SecurityUtils.getUserId(), param.getIsTrue(), param.getBingStates(), param.getGroupid(), param.getKeyword()); |
| | | } |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | list = list(wrapper); |
| | | if (param.getGroupid() != null) { |
| | | // List<Long> poleIds = new ArrayList<>(); |
| | | List<Pole> pole = new ArrayList<>(); |
| | | List<PoleGroupRelation> relations = groupRelationService.list(Wrappers.lambdaQuery(PoleGroupRelation.class) |
| | | .eq(PoleGroupRelation::getPoleGroupId, param.getGroupid())); |
| | | relations.forEach(relation -> { |
| | | pole.add(getById(relation.getPoleId())); |
| | | } |
| | | ); |
| | | list = pole; |
| | | } |
| | | List<Pole> PoleResult = isOnLine(poleList, param); |
| | | setCount(PoleResult); |
| | | |
| | | if (param.getBingStates() != 2) {//是否绑定 |
| | | list = isBind(list, param);// 绑定/未绑定 |
| | | if (param.getIsTrue() != 2) {//已绑定的是否是真实灯杆 |
| | | list = isTrue(list, param); |
| | | if (param.getOnLineStates() != 2) {//绑定的真实灯杆是否在线 |
| | | list = isOnLine(list, param); |
| | | } |
| | | } else {//全部灯杆 实体/虚拟 |
| | | if (param.getOnLineStates() != 2) { //查询全部灯杆是否在线 |
| | | list = isOnLine(list, param); |
| | | } |
| | | } |
| | | } else {//全部 绑定/未绑定 |
| | | if (param.getIsTrue() != 2) {// 判断灯杆类型 |
| | | list = isTrue(list, param);// 实体/虚拟 |
| | | if (param.getOnLineStates() != 2) {// 灯杆的在线判断 |
| | | list = isOnLine(list, param);//在线/离线 |
| | | } |
| | | } else {//全类型灯杆 |
| | | if (param.getOnLineStates() != 2) {//判断在线状态 |
| | | list = isOnLine(list, param);//在线/离线 |
| | | } |
| | | } |
| | | } |
| | | CommonPage commonPage = ListPagingUtils.pages(PoleResult, pageNo, pageSize); |
| | | |
| | | setCount(list); |
| | | return list; |
| | | return commonPage; |
| | | } |
| | | |
| | | /** |
| | | * 设置绑定设备数量 |
| | | * 获取绑定设备详情 |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public List<Pole> setCount(List<Pole> list) { |
| | | for (Pole post : list) { |
| | | int size = poleBindingService.list(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, post.getId())).size(); |
| | | // System.out.println("size:----------------------"+size); |
| | | post.setBindingCount(size); |
| | | BindEquipments bindEquipments; |
| | | for (Pole pole : list) { |
| | | bindEquipments = new BindEquipments(); |
| | | List<PoleBinding> poleBindings = poleBindingService.list(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, pole.getId())); |
| | | pole.setBindingCount(poleBindings.size()); |
| | | for (PoleBinding poleBinding : poleBindings) { |
| | | bindEquipments.setInfo(poleBinding.getDeviceType()); |
| | | } |
| | | pole.setBindEquipments(bindEquipments); |
| | | } |
| | | return list; |
| | | } |
| | |
| | | } |
| | | |
| | | public List<Pole> isTrue(List<Pole> list, PoleStatesParam param) { |
| | | List<Pole> isTrue = new ArrayList<>();//实体灯杆 |
| | | List<Pole> isFalse = new ArrayList<>();//虚拟灯杆 |
| | | //实体灯杆 |
| | | List<Pole> isTrue = new ArrayList<>(); |
| | | //虚拟灯杆 |
| | | List<Pole> isFalse = new ArrayList<>(); |
| | | list.forEach(bindwarpper -> { |
| | | // Long clientId = bindwarpper.getClientId(); |
| | | if (bindwarpper.getDeviceCode() == null) { |
| | | //判断是否绑定 |
| | | if (bindwarpper.getDeviceType() == -1) { |
| | | isFalse.add(bindwarpper); |
| | | } else { |
| | | isTrue.add(bindwarpper); |
| | |
| | | if (deviceStatuses != null) { |
| | | for (Pole post : list) { |
| | | for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) { |
| | | // System.out.println("DeviceCode:---------------------"+post.getDeviceCode()); |
| | | // System.out.println("DeviceName:---------------------"+deviceStatus.getDeviceName()); |
| | | |
| | | if (post.getDeviceCode() != null && post.getDeviceCode().equals(deviceStatus.getDeviceName())) { |
| | | post.setOnLineState(deviceStatus.getStatus()); |
| | | // int size = poleBindingService.list(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, post.getId())).size(); |
| | | //// System.out.println("size:----------------------"+size); |
| | | // post.setBindingCount(size); |
| | | |
| | | } |
| | | } |
| | | // MacCodes.add(post.getDeviceCode()); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public List<Pole> queryStatesAndList(Integer pageNo, Integer pageSize, String keyword, Long groupid) { |
| | | // List<LampPost> list = list(Wrappers.lambdaQuery(LampPost.class).eq(LampPost::getClientId, SecurityUtils.getUserId())); |
| | | //List<Pole> list = list(Wrappers.lambdaQuery(Pole.class)); |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | List<Pole> list = new ArrayList<>(); |
| | | LambdaQueryWrapper<Pole> wrapper = new LambdaQueryWrapper<>(); |
| | |
| | | List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(MacCodes); |
| | | for (Pole post : list) { |
| | | for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) { |
| | | // System.out.println("DeviceCode:---------------------"+post.getDeviceCode()); |
| | | // System.out.println("DeviceName:---------------------"+deviceStatus.getDeviceName()); |
| | | if (post.getDeviceCode() != null && post.getDeviceCode().equals(deviceStatus.getDeviceName())) { |
| | | post.setOnLineState(deviceStatus.getStatus()); |
| | | int size = poleBindingService.list(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, post.getId())).size(); |
| | | // System.out.println("size:----------------------"+size); |
| | | post.setBindingCount(size); |
| | | } |
| | | } |
| | | // MacCodes.add(post.getDeviceCode()); |
| | | } |
| | | |
| | | |