| | |
| | | */ |
| | | public boolean bindPole(Long poleId, PoleBindingParam param) { |
| | | Integer deviceType = param.getDeviceType(); |
| | | // if (PoleBindingEnums.LIGHT.getCode().equals(deviceType)) { |
| | | // } |
| | | |
| | | int size = 0; |
| | | switch (deviceType.toString()) { |
| | |
| | | size = SpringContextHolder.getBean(C3ChargingService.class).list(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, param.getDeviceCode())).size(); |
| | | break; |
| | | case PoleBindingEnums.ATMOSPHERIC: |
| | | size = SpringContextHolder.getBean(AirEquipmentService.class).list(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, param.getDeviceCode())).size(); |
| | | Pole byId = SpringContextHolder.getBean(PoleService.class).getById(poleId); |
| | | if (byId == null) { |
| | | throw new BusinessException("未找到灯杆"); |
| | | } |
| | | if (byId.getDeviceCode() != null || !byId.getDeviceCode().isEmpty()) { |
| | | if (!param.getDeviceCode().equals(byId.getDeviceCode())) { |
| | | throw new BusinessException("灯杆mac和大气mac不一致, 无法绑定"); |
| | | } |
| | | } else { |
| | | throw new BusinessException("灯杆mac为空,无法绑定大气设备"); |
| | | } |
| | | |
| | | int size1 = SpringContextHolder.getBean(AirEquipmentService.class).list(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, param.getDeviceCode())).size(); |
| | | int size2 = SpringContextHolder.getBean(AirEquipmentNongGengService.class).list(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, param.getDeviceCode())).size(); |
| | | //一键求助两类硬件 |
| | | if (size1 > 0 || size2 > 0) { |
| | | size = 1; |
| | | } |
| | | break; |
| | | case PoleBindingEnums.WATER: |
| | | size = SpringContextHolder.getBean(WaterQualityEquipmentService.class).list(Wrappers.lambdaQuery(WaterQualityEquipment.class).eq(WaterQualityEquipment::getWaterQualityEquipmentCode, param.getDeviceCode())).size(); |
| | |
| | | size = SpringContextHolder.getBean(LightPoleHeelingEquipmentService.class).list(Wrappers.lambdaQuery(LightPoleHeelingEquipment.class).eq(LightPoleHeelingEquipment::getMac, param.getDeviceCode())).size(); |
| | | break; |
| | | case PoleBindingEnums.FOR_HELP: |
| | | int size1 = SpringContextHolder.getBean(InterphoneHostService.class).list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, param.getDeviceCode())).size(); |
| | | int size2 = SpringContextHolder.getBean(InterphoneSubService.class).list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, param.getDeviceCode())).size(); |
| | | int size3 = SpringContextHolder.getBean(InterphoneHostService.class).list(Wrappers.lambdaQuery(InterphoneHost.class).eq(InterphoneHost::getHostMac, param.getDeviceCode())).size(); |
| | | int size4 = SpringContextHolder.getBean(InterphoneSubService.class).list(Wrappers.lambdaQuery(InterphoneSub.class).eq(InterphoneSub::getSubMac, param.getDeviceCode())).size(); |
| | | //一键求助两类硬件 |
| | | if (size1 > 0 || size2 > 0) { |
| | | if (size3 > 0 || size4 > 0) { |
| | | size = 1; |
| | | } |
| | | break; |
| | |
| | | } |
| | | |
| | | |
| | | LambdaQueryWrapper<PoleBinding> eq = Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, poleId); |
| | | LambdaQueryWrapper<PoleBinding> eq = Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceType, param.getDeviceType()).eq(PoleBinding::getPoleId, poleId); |
| | | List<PoleBinding> list = list(eq); |
| | | if (list.size() != 0) { |
| | | for (PoleBinding poleBinding : list) { |
| | |
| | | } |
| | | } |
| | | |
| | | PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode())); |
| | | PoleBinding one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, param.getDeviceCode()) |
| | | .eq(PoleBinding::getDeviceType, param.getDeviceType())); |
| | | if (one == null) { |
| | | //充电桩保存绑定关系需要先判断是不是正确的灯杆 |
| | | if (deviceType == 2) { |
| | | C3mCharging mCharging = SpringContextHolder.getBean(C3ChargingService.class). |
| | | getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, param.getDeviceCode())); |
| | | Pole poleInfo = SpringContextHolder.getBean(PoleService.class).getById(poleId); |
| | | |
| | | if (!mCharging.getPoleDevicesCode().equals(poleInfo.getDeviceCode())) { |
| | | throw new BusinessException("绑定出错!该充电桩硬件绑定的灯杆mac为:" + mCharging.getPoleDevicesCode()); |
| | | } |
| | | |
| | | } |
| | | PoleBinding poleBinding = new PoleBinding(); |
| | | poleBinding.setPoleId(poleId); |
| | | poleBinding.setDeviceType(deviceType); |
| | | poleBinding.setDeviceName(param.getDeviceName()); |
| | | poleBinding.setDeviceCode(param.getDeviceCode()); |
| | | return save(poleBinding); |
| | | |
| | | } else { |
| | | //修改单灯的绑定关系的时候要额外处理的事务 |
| | | // 删除灯杆的devicescode |
| | |
| | | } |
| | | } |
| | | |
| | | //充电桩保存绑定关系需要先判断是不是正确的灯杆 |
| | | if (deviceType == 2) { |
| | | C3mCharging mCharging = SpringContextHolder.getBean(C3ChargingService.class). |
| | | getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, param.getDeviceCode())); |
| | | Pole poleInfo = SpringContextHolder.getBean(PoleService.class).getById(poleId); |
| | | |
| | | if (!mCharging.getPoleDevicesCode().equals(poleInfo.getDeviceCode())) { |
| | | throw new BusinessException("绑定出错!该充电桩硬件绑定的灯杆mac为:" + mCharging.getPoleDevicesCode()); |
| | | } |
| | | |
| | | } |
| | | |
| | | one.setPoleId(poleId); |
| | | one.setDeviceType(param.getDeviceType()); |
| | | one.setDeviceName(param.getDeviceName()); |
| | | one.setDeviceCode(param.getDeviceCode()); |
| | | return updateById(one); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode)); |
| | | } else { |
| | | one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getPoleId, poleId)); |
| | | } |
| | | if (one != null) { |
| | | return removeById(one.getId()); |
| | | } else { |
| | | throw new BusinessException("设备不存在绑定情况或灯杆ID不正确"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 灯杆解绑设备,删除设备前需要解绑 |
| | | * |
| | | * @param deviceCode |
| | | */ |
| | | public boolean unBindPole(Long poleId, String deviceCode, Integer deviceType) { |
| | | if (deviceCode == null) { |
| | | throw new BusinessException("设备编号不能为空"); |
| | | } |
| | | PoleBinding one; |
| | | //直接删除设备不需要灯杆ID |
| | | if (poleId == null) { |
| | | one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getDeviceType, deviceType)); |
| | | } else { |
| | | one = getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode) |
| | | .eq(PoleBinding::getDeviceType, deviceType).eq(PoleBinding::getPoleId, poleId)); |
| | | } |
| | | if (one != null) { |
| | | return removeById(one.getId()); |
| | |
| | | } |
| | | |
| | | public PoleBinding getPoleIdByMac(String deviceCode) { |
| | | return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode)); |
| | | return getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode).eq(PoleBinding::getDeviceType, 0)); |
| | | } |
| | | |
| | | |