| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.ximon.dao.domain.AirData; |
| | | import com.sandu.ximon.dao.domain.ForHelp; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A5Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightPoleHeelingHeartbeatReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightPoleHeelingOperationReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightPoleHeelingQueryReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.request.*; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.LightPoleHeelingEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.param.LightPoleHeelingListParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.vo.EquipmentInfomation; |
| | | import com.sandu.ximon.dao.domain.LightPoleHeeling; |
| | | import com.sandu.ximon.dao.domain.LightPoleHeelingEquipment; |
| | | import com.sandu.ximon.dao.mapper.LightPoleHeelingMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class LightPoleHeelingService extends BaseServiceImpl<LightPoleHeelingMapper, LightPoleHeeling> { |
| | | /** |
| | | * 查询全部灯杆倾侧告警 |
| | | */ |
| | | public List<LightPoleHeeling> listLightPoleHeeling() { |
| | | LambdaQueryWrapper<LightPoleHeeling> wrapper = Wrappers.lambdaQuery(LightPoleHeeling.class); |
| | | List<LightPoleHeeling> list = list(wrapper); |
| | | |
| | | return list; |
| | | } |
| | | private LightPoleHeelingMapper lightPoleHeelingMapper; |
| | | private LightPoleHeelingEquipmentService lightPoleHeelingEquipmentService; |
| | | |
| | | /** |
| | | * 模糊查询 |
| | | */ |
| | | public List<LightPoleHeeling> listLightPoleHeelingByKeyword(String keyword) { |
| | | |
| | | LambdaQueryWrapper<LightPoleHeeling> wrapper = Wrappers.lambdaQuery(LightPoleHeeling.class); |
| | | if (keyword != null) { |
| | | wrapper.like(LightPoleHeeling::getLightPoleName, keyword).or( |
| | | lambdaQueryWrapper -> { |
| | | lambdaQueryWrapper.like(LightPoleHeeling::getLightPoleId, keyword); |
| | | } |
| | | ).or( |
| | | lambdaQueryWrapper -> { |
| | | lambdaQueryWrapper.like(LightPoleHeeling::getWarningNumber, keyword); |
| | | } |
| | | ); |
| | | public List<LightPoleHeeling> listLightPoleHeelingByKeyword(BaseConditionVO baseConditionVO, LightPoleHeelingListParam lightPoleHeelingListParam) { |
| | | if (baseConditionVO != null) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | } |
| | | List<LightPoleHeeling> forHelpList = list(wrapper); |
| | | return forHelpList; |
| | | if (lightPoleHeelingListParam == null) { |
| | | lightPoleHeelingListParam = new LightPoleHeelingListParam(); |
| | | } |
| | | |
| | | //关键字去除空格 |
| | | if (lightPoleHeelingListParam.getKeyword() != null) { |
| | | lightPoleHeelingListParam.setKeyword(lightPoleHeelingListParam.getKeyword().trim()); |
| | | } |
| | | |
| | | List<LightPoleHeeling> lightPoleHeelings; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | lightPoleHeelings = lightPoleHeelingMapper.listLightPoleHeeling(lightPoleHeelingListParam.getKeyword() |
| | | , lightPoleHeelingListParam.getProcessingState(), null); |
| | | } else { |
| | | lightPoleHeelings = lightPoleHeelingMapper.listLightPoleHeeling(lightPoleHeelingListParam.getKeyword() |
| | | , lightPoleHeelingListParam.getProcessingState(), SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | return lightPoleHeelings; |
| | | } |
| | | |
| | | /** |
| | | * 根据Mac获取最新数据 |
| | | */ |
| | | public EquipmentInfomation getLightPoleHeelingByMac(String mac) { |
| | | EquipmentInfomation equipmentInfo = new EquipmentInfomation(); |
| | | equipmentInfo.setEquipmentType("杆体倾测"); |
| | | if (mac == null || mac.trim().length() == 0) { |
| | | return equipmentInfo; |
| | | } |
| | | |
| | | LightPoleHeeling one = getOne(Wrappers.lambdaQuery(LightPoleHeeling.class).eq(LightPoleHeeling::getMac, mac)); |
| | | if (one != null) { |
| | | equipmentInfo.setEquipmentCreateTime(one.getCreateTime()); |
| | | equipmentInfo.setEquipmentMac(one.getMac()); |
| | | |
| | | } |
| | | //存储设备状态到缓存 |
| | | String s = RedisUtils.getBean().get(LightPoleHeelingEnum.LIGHT_POLE_HEELING_STATE.getCode() + mac); |
| | | if (s == null) { |
| | | equipmentInfo.setEquipmentState("离线"); |
| | | } else { |
| | | equipmentInfo.setEquipmentState("在线"); |
| | | } |
| | | return equipmentInfo; |
| | | } |
| | | |
| | | /** |
| | | * 灯杆倾斜心跳包 |
| | | * |
| | | * @param deviceName |
| | | */ |
| | | public A5LightPoleHeelingHeartbeatReportInnerFrame.HeartBeatDataPackage LightPoleHeelingHeartbeatPackage(String deviceName) { |
| | | LightPoleHeelingHeartbeatPackageReqInnerFrame lightPoleHeelingHeartbeatPackageReqInnerFrame = new LightPoleHeelingHeartbeatPackageReqInnerFrame(); |
| | | |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), lightPoleHeelingHeartbeatPackageReqInnerFrame); |
| | | System.out.println(a5Frame + " -----a5Frame"); |
| | | |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "杆体倾斜-心跳包", a5Frame, commonFrame); |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |
| | | |
| | | A5LightPoleHeelingHeartbeatReportInnerFrame heartbeatReportInnerFrame |
| | | = new A5LightPoleHeelingHeartbeatReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | |
| | | if (heartbeatReportInnerFrame.isValidate()) { |
| | | |
| | | //灯杆倾斜心跳包保存数据库 |
| | | saveLightPoleHeelingHeartbeat(deviceName, heartbeatReportInnerFrame.getHeartBeatDataPackage()); |
| | | |
| | | return heartbeatReportInnerFrame.getHeartBeatDataPackage(); |
| | | } else { |
| | | throw new BusinessException("数据校验错误,请重新请求"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询心跳包间隔时间 |
| | | * |
| | | * @param deviceName |
| | | */ |
| | | public String QueryIntervalTime(String deviceName) { |
| | | LightPoleHeelingQueryIntervalTimeReqInnerFrame queryIntervalTimeReqInnerFrame |
| | | = new LightPoleHeelingQueryIntervalTimeReqInnerFrame(); |
| | | |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), queryIntervalTimeReqInnerFrame); |
| | | System.out.println(a5Frame + " -----a5Frame"); |
| | | |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "杆体倾斜-查询心跳包间隔时间", a5Frame, commonFrame); |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |
| | | |
| | | A5LightPoleHeelingQueryReportInnerFrame queryReportInnerFrame = new A5LightPoleHeelingQueryReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (queryReportInnerFrame.isValidate()) { |
| | | return queryReportInnerFrame.getIntervalTime(); |
| | | } else { |
| | | throw new BusinessException("数据校验错误,请重新请求"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 软重启 |
| | | * |
| | | * @param deviceName |
| | | */ |
| | | public String RestartLightPoleHeeling(String deviceName) { |
| | | LightPoleHeelingRestartReqInnerFrame restartReqInnerFrame |
| | | = new LightPoleHeelingRestartReqInnerFrame(); |
| | | |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), restartReqInnerFrame); |
| | | System.out.println(a5Frame + " -----a5Frame"); |
| | | |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "杆体倾斜-软重启", a5Frame, commonFrame); |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |
| | | |
| | | A5LightPoleHeelingOperationReportInnerFrame operationReportInnerFrame |
| | | = new A5LightPoleHeelingOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (operationReportInnerFrame.isValidate()) { |
| | | return operationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验错误,请重新请求"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置心跳包间隔时间(秒) |
| | | * |
| | | * @param devicesName |
| | | * @param setTime |
| | | * @return |
| | | */ |
| | | public String SetHeartbeatPacketTime(String devicesName, int setTime) { |
| | | if (setTime <= 0) { |
| | | throw new BusinessException("设置的心跳包间隔时间错误!"); |
| | | } |
| | | LightPoleHeelingSetHeartbeatPacketTimeReqInnerFrame setHeartbeatPacketTimeReqInnerFrame = |
| | | new LightPoleHeelingSetHeartbeatPacketTimeReqInnerFrame(setTime); |
| | | |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), setHeartbeatPacketTimeReqInnerFrame); |
| | | System.out.println(a5Frame + " -----a5Frame"); |
| | | |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(devicesName, a5Frame); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(devicesName, "杆体倾斜-设置心跳包间隔时间", a5Frame, commonFrame); |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |
| | | A5LightPoleHeelingOperationReportInnerFrame operationReportInnerFrame |
| | | = new A5LightPoleHeelingOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (operationReportInnerFrame.isValidate()) { |
| | | return operationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验错误,请重新请求"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置传感器为初始状态 |
| | | * |
| | | * @return |
| | | */ |
| | | public String SetSensorState(String devicesName) { |
| | | LightPoleHeelingSetSensorStateReqInnerFrame setSensorStateReqInnerFrame = |
| | | new LightPoleHeelingSetSensorStateReqInnerFrame(); |
| | | |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), setSensorStateReqInnerFrame); |
| | | System.out.println(a5Frame + " -----a5Frame"); |
| | | |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(devicesName, a5Frame); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(devicesName, "杆体倾斜-设置传感器为初始状态", a5Frame, commonFrame); |
| | | |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |
| | | A5LightPoleHeelingOperationReportInnerFrame operationReportInnerFrame |
| | | = new A5LightPoleHeelingOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (operationReportInnerFrame.isValidate()) { |
| | | return operationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验错误,请重新请求"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存心跳包数据 |
| | | * |
| | | * @param deviceName |
| | | * @param heartBeatDataPackage |
| | | * @return |
| | | */ |
| | | public boolean saveLightPoleHeelingHeartbeat(String deviceName, A5LightPoleHeelingHeartbeatReportInnerFrame.HeartBeatDataPackage heartBeatDataPackage) { |
| | | |
| | | LightPoleHeeling lightPoleHeeling = new LightPoleHeeling(); |
| | | lightPoleHeeling.setMac(deviceName); |
| | | lightPoleHeeling.setTheXAxis(heartBeatDataPackage.getTheXAxis()); |
| | | lightPoleHeeling.setTheYAxis(heartBeatDataPackage.getTheYAxis()); |
| | | lightPoleHeeling.setTheZAxis(heartBeatDataPackage.getTheZAxis()); |
| | | if (Math.abs(heartBeatDataPackage.getTheXAxis()) >= 10 || Math.abs(heartBeatDataPackage.getTheYAxis()) >= 10) { |
| | | lightPoleHeeling.setWarningLevel(1);//一级警告 |
| | | } else if ((Math.abs(heartBeatDataPackage.getTheXAxis()) >= 5 && Math.abs(heartBeatDataPackage.getTheXAxis()) < 10) |
| | | || (Math.abs(heartBeatDataPackage.getTheYAxis()) >= 5 && Math.abs(heartBeatDataPackage.getTheYAxis()) < 10)) { |
| | | lightPoleHeeling.setWarningLevel(2);//二级警告 |
| | | } else { |
| | | lightPoleHeeling.setWarningLevel(0);//正常 |
| | | } |
| | | |
| | | //存储设备状态到缓存 |
| | | RedisUtils.getBean().set(LightPoleHeelingEnum.LIGHT_POLE_HEELING_STATE.getCode() + deviceName |
| | | , heartBeatDataPackage, 300L); |
| | | /** |
| | | * 将灯杆倾斜硬件添加到硬件表 |
| | | */ |
| | | LightPoleHeelingEquipment one = lightPoleHeelingEquipmentService.getOne(Wrappers.lambdaQuery(LightPoleHeelingEquipment.class).eq(LightPoleHeelingEquipment::getMac, deviceName)); |
| | | if (one == null) { |
| | | LightPoleHeelingEquipment equipment = new LightPoleHeelingEquipment(); |
| | | equipment.setMac(deviceName); |
| | | } |
| | | |
| | | return save(lightPoleHeeling); |
| | | } |
| | | } |