| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.manager.iot.frame.A5Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartBeatTimeReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereOperationReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereQuerySensorInfoReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereQueryVersionReportInnerFrame; |
| | | 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.AtmoFunctionCode; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3mRedisConstant; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.redis.DeviceRedisKey; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.dao.bo.AirDataBo; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.StringUtil; |
| | | import com.sandu.ximon.admin.vo.EquipmentInfomation; |
| | | import com.sandu.ximon.admin.vo.RedisDeviceStatus; |
| | | import com.sandu.ximon.dao.bo.AirEquipmentBo; |
| | | import com.sandu.ximon.dao.domain.AirData; |
| | | import com.sandu.ximon.dao.domain.AirEquipment; |
| | | import com.sandu.ximon.dao.domain.Monitor; |
| | | import com.sandu.ximon.dao.mapper.AirDataMapper; |
| | | import com.sandu.ximon.dao.mapper.AirEquipmentMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | public class AirEquipmentService extends BaseServiceImpl<AirEquipmentMapper, AirEquipment> { |
| | | |
| | | private final AirEquipmentMapper airEquipmentMapper; |
| | | private final RedisUtils redisUtils; |
| | | |
| | | |
| | | /** |
| | | * 模糊查询 |
| | | * 大气设备列表模糊查询 |
| | | */ |
| | | public List<AirEquipmentBo> listAirEquipmentByKeyword(BaseConditionVO baseConditionVO, String keyword) { |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | PageHelper.startPage(baseConditionVO.getPageNo(),baseConditionVO.getPageSize()); |
| | | if (baseConditionVO != null) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | } |
| | | List<AirEquipmentBo> airEquipmentBos; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | airEquipmentBos = airEquipmentMapper.listAirEquipmentByIds(keyword, null); |
| | | } else { |
| | | airEquipmentBos = airEquipmentMapper.listAirEquipmentByIds(keyword, SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | List<AirEquipmentBo> airEquipmentBos = airEquipmentMapper.listAirEquipmentByIds(keyword,clientId); |
| | | return airEquipmentBos; |
| | | } |
| | | |
| | | /** |
| | | * 大气设备劣列表(用于首页数据统计) |
| | | */ |
| | | public List<AirEquipmentBo> listAirEquipmentOnHome() { |
| | | List<AirEquipmentBo> airEquipmentBos; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | airEquipmentBos = airEquipmentMapper.listAirEquipmentByIds(null, null); |
| | | } else { |
| | | airEquipmentBos = airEquipmentMapper.listAirEquipmentByIds(null, SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | return airEquipmentBos; |
| | | } |
| | | |
| | |
| | | */ |
| | | public void addAirEquipment(AirEquipment airEquipment) { |
| | | AirEquipment one = getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, airEquipment.getMac())); |
| | | //存储设备状态到缓存 |
| | | RedisUtils.getBean().set(AtmoFunctionCode.AIR_EQUIPMENT_STATE.getCode() + airEquipment.getMac() |
| | | , 1, 300L); |
| | | |
| | | if (one == null) { |
| | | save(airEquipment); |
| | | /** |
| | | * 添加大气设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(airEquipment.getMac()); |
| | | String content = "{ 设备id:" + airEquipment.getId() + "设备code:" + airEquipment.getMac() + |
| | | "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "添加大气设备", content); |
| | | /** |
| | | * 添加大气设备 日志记录结束 |
| | | */ |
| | | } |
| | | } |
| | | |
| | |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("找不到大气设备数据"); |
| | | } |
| | | /** |
| | | * 删除大气设备 日志记录开始 |
| | | */ |
| | | List<String> listCode = new ArrayList<>(1); |
| | | listCode.add(airEquipment.getMac()); |
| | | String content = "{设备code:" + airEquipment.getMac() + "}"; |
| | | |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "删除大气设备", content); |
| | | /** |
| | | * 删除大气设备 日志记录结束 |
| | | */ |
| | | return removeById(Id); |
| | | } |
| | | |
| | | /** |
| | | * 根据Mac大气设备数据详情 |
| | | */ |
| | | public EquipmentInfomation getAirEquipmentInfo(String mac) { |
| | | EquipmentInfomation equipmentInfo = new EquipmentInfomation(); |
| | | equipmentInfo.setEquipmentType("大气设备"); |
| | | if (mac == null || mac.trim().length() == 0) { |
| | | return equipmentInfo; |
| | | } |
| | | |
| | | if (RedisUtils.getBean().get(AtmoFunctionCode.AIR_HEARTBEAT_STATE.getCode() + mac) != null) { |
| | | equipmentInfo.setEquipmentState("在线"); |
| | | } else { |
| | | equipmentInfo.setEquipmentState("离线"); |
| | | } |
| | | |
| | | AirEquipment one = getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac)); |
| | | if (one != null) { |
| | | equipmentInfo.setEquipmentMac(mac); |
| | | equipmentInfo.setEquipmentCreateTime(one.getCreateTime()); |
| | | } |
| | | return equipmentInfo; |
| | | } |
| | | |
| | | /** |
| | | * 查询大气设备心跳包时间 |
| | | */ |
| | | public String QueryHeartBeatTime(String mac) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1")); |
| | | |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | |
| | | AtmosphereQueryHeartBeatTimeReqInnerFrame atmosphereQueryHeartBeatTimeReqInnerFrame = new AtmosphereQueryHeartBeatTimeReqInnerFrame(); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereQueryHeartBeatTimeReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | // FEA504000AFE020002FFFF014062EC --------a5Frame |
| | | // FEA584000CFE020004FFFF003CB081260CCC1C105D -----------commonFrame |
| | | A5AtmosphereHeartBeatTimeReportInnerFrame a5AtmosphereHeartBeatTimeReportInnerFrame |
| | | = new A5AtmosphereHeartBeatTimeReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | |
| | | if (a5AtmosphereHeartBeatTimeReportInnerFrame != null && a5AtmosphereHeartBeatTimeReportInnerFrame.isValidate()) { |
| | | return "该大气设备心跳包间隔时间为:" + a5AtmosphereHeartBeatTimeReportInnerFrame.getIntervalTime() + "s"; |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置大气设备心跳包间隔时间 |
| | | * |
| | | * @param mac |
| | | * @param time |
| | | */ |
| | | public String setHeartBeatTime(String mac, Integer time) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | if (time == null) { |
| | | throw new BusinessException("心跳包间隔时间不能为空!"); |
| | | } |
| | | |
| | | if (time < 30) { |
| | | throw new BusinessException("心跳包间隔时间不能少于30s!"); |
| | | } |
| | | AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1")); |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | |
| | | AtmosphereSetHeartBeatTimeReqInnerFrame atmosphereSetHeartBeatTimeReqInnerFrame = new AtmosphereSetHeartBeatTimeReqInnerFrame(time); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereSetHeartBeatTimeReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | //FEA584000BFE110003FFFF00464116EC58FC0C8F |
| | | A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame |
| | | = new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (a5AtmosphereOperationReportInnerFrame != null && a5AtmosphereOperationReportInnerFrame.isValidate()) { |
| | | return a5AtmosphereOperationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询传感器数量/故障 |
| | | * |
| | | * @param mac |
| | | * @return |
| | | */ |
| | | public A5AtmosphereQuerySensorInfoReportInnerFrame.SensorInfoPackage QuerySensorInfo(String mac) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | |
| | | AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1")); |
| | | |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | |
| | | AtmosphereQuerySensorInfoReqInnerFrame atmosphereQuerySensorInfoReqInnerFrame = new AtmosphereQuerySensorInfoReqInnerFrame(); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereQuerySensorInfoReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | A5AtmosphereQuerySensorInfoReportInnerFrame atmosphereQuerySensorInfoReportInnerFrame |
| | | = new A5AtmosphereQuerySensorInfoReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | |
| | | if (atmosphereQuerySensorInfoReportInnerFrame != null && atmosphereQuerySensorInfoReportInnerFrame.isValidate()) { |
| | | return atmosphereQuerySensorInfoReportInnerFrame.getSensorInfoPackage(); |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询软硬件版本 |
| | | * |
| | | * @param mac |
| | | * @return |
| | | */ |
| | | public String QueryVersion(String mac) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1")); |
| | | |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | |
| | | AtmosphereQueryVersionReqInnerFrame atmosphereQueryVersionReqInnerFrame = new AtmosphereQueryVersionReqInnerFrame(); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereQueryVersionReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | // FEA504000AFE040002FFFF8E00974C --------a5Frame |
| | | // FEA584000CFE040004FFFF0105954FAA7F1123C0CB -----------commonFrame |
| | | A5AtmosphereQueryVersionReportInnerFrame a5AtmosphereQueryVersionReportInnerFrame = |
| | | new A5AtmosphereQueryVersionReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (a5AtmosphereQueryVersionReportInnerFrame != null && a5AtmosphereQueryVersionReportInnerFrame.isValidate()) { |
| | | return a5AtmosphereQueryVersionReportInnerFrame.getVersion(); |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 软重启 |
| | | * |
| | | * @param mac |
| | | * @return |
| | | */ |
| | | public String Reboot(String mac) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | |
| | | AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1")); |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | |
| | | AtmosphereRebootReqInnerFrame atmosphereRebootReqInnerFrame = new AtmosphereRebootReqInnerFrame(); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereRebootReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame = |
| | | new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | |
| | | if (a5AtmosphereOperationReportInnerFrame != null && a5AtmosphereOperationReportInnerFrame.isValidate()) { |
| | | return a5AtmosphereOperationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置数据修正值 |
| | | * |
| | | * @param mac 灯杆MAC |
| | | * @param type 数据修正设备类型 |
| | | * @param valueOfReal 传感器数值 |
| | | * @param valueOfStandard 标准仪器数值 |
| | | */ |
| | | public String ModifiedData(String mac, String type, String valueOfReal, String valueOfStandard) { |
| | | if (StringUtil.strIsNullOrEmpty(mac)) { |
| | | throw new BusinessException("灯杆mac参数错误!"); |
| | | } |
| | | if (StringUtil.strIsNullOrEmpty(type)) { |
| | | throw new BusinessException("数据修正设备类型错误!"); |
| | | } |
| | | if (valueOfReal == null || valueOfStandard == null) { |
| | | throw new BusinessException("传感器数值或标准仪器数值错误!"); |
| | | } |
| | | AirEquipment airEquipment = SpringContextHolder.getBean(AirEquipmentService.class). |
| | | getOne(Wrappers.lambdaQuery(AirEquipment.class).eq(AirEquipment::getMac, mac).last("limit 1")); |
| | | if (airEquipment == null) { |
| | | throw new BusinessException("大气设备不存在!"); |
| | | } |
| | | AtmosphereModifiedDataReqInnerFrame atmosphereModifiedDataReqInnerFrame = new AtmosphereModifiedDataReqInnerFrame(type, valueOfReal, valueOfStandard); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereModifiedDataReqInnerFrame); |
| | | System.out.println(a5Frame + " --------a5Frame"); |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame); |
| | | System.out.println(commonFrame + " -----------commonFrame"); |
| | | |
| | | |
| | | A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame |
| | | = new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (a5AtmosphereOperationReportInnerFrame.isValidate()) { |
| | | return a5AtmosphereOperationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验异常!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 向Redis中存入设备状态 |
| | | */ |
| | | public void setCacheData() { |
| | | list().forEach( |
| | | device -> { |
| | | RedisDeviceStatus deviceStatus = new RedisDeviceStatus(); |
| | | deviceStatus.setDeviceId(device.getMac()); |
| | | |
| | | if (RedisUtils.getBean().get(AtmoFunctionCode.AIR_HEARTBEAT_STATE.getCode() + device.getMac()) != null) { |
| | | deviceStatus.setStatus(0); |
| | | } else { |
| | | deviceStatus.setStatus(1); |
| | | } |
| | | redisUtils.set(DeviceRedisKey.AIR + device.getMac(), JSON.toJSONString(deviceStatus)); |
| | | // redisUtils.delete(DeviceRedisKey.AIR + device.getAirMac()); |
| | | } |
| | | ); |
| | | } |
| | | } |