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.admin.manager.iot.frame.A5Frame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.report.*;
|
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.dao.domain.Light;
|
import com.sandu.ximon.dao.domain.LightPoleHeeling;
|
import com.sandu.ximon.dao.domain.LightPoleHeelingEquipment;
|
import com.sandu.ximon.dao.domain.PoleBinding;
|
import com.sandu.ximon.dao.mapper.LightPoleHeelingMapper;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
@Service
|
@AllArgsConstructor
|
public class LightPoleHeelingService extends BaseServiceImpl<LightPoleHeelingMapper, LightPoleHeeling> {
|
private LightPoleHeelingMapper lightPoleHeelingMapper;
|
private LightPoleHeelingEquipmentService lightPoleHeelingEquipmentService;
|
|
/**
|
* 模糊查询
|
*/
|
public List<LightPoleHeeling> listLightPoleHeelingByKeyword(BaseConditionVO baseConditionVO, LightPoleHeelingListParam lightPoleHeelingListParam) {
|
if (baseConditionVO != null) {
|
PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
}
|
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 LightPoleHeeling getLightPoleHeelingByMac(String mac) {
|
return getOne(Wrappers.lambdaQuery(LightPoleHeeling.class).eq(LightPoleHeeling::getMac, mac));
|
}
|
|
/**
|
* 灯杆倾斜心跳包
|
*
|
* @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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
}
|
}
|