package com.sandu.ximon.admin.service;
|
|
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.amqp.processor.c3ChargingProcessor;
|
import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3HeartbeatReportInnerFrame;
|
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3OperationReportInnerFrame;
|
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.C3ChargingEnum;
|
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
|
import com.sandu.ximon.admin.utils.RedisUtils;
|
import com.sandu.ximon.dao.domain.C3mCharging;
|
import com.sandu.ximon.dao.mapper.C3mChargingMapper;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
/**
|
* @author ZZQ
|
* C3充电桩
|
* @date 2022/3/4 9:58
|
*/
|
@Service
|
@Slf4j
|
@AllArgsConstructor
|
public class C3ChargingService extends BaseServiceImpl<C3mChargingMapper, C3mCharging> {
|
|
/**
|
* 保存上报C3充电设备心跳数据
|
*
|
* @return 是否成功
|
*/
|
public boolean saveReportData(String deviceName, A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage heartBeatDataPackage) {
|
C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, deviceName));
|
|
if (one == null) {
|
//将设备信息添加到充电桩设备表
|
C3mCharging c3mCharging = new C3mCharging();
|
c3mCharging.setMcuUdid(deviceName);
|
c3mCharging.setC3Mac(heartBeatDataPackage.getC3Mac());
|
c3mCharging.setStatusBit(Integer.valueOf(heartBeatDataPackage.getStatusBit()));
|
c3mCharging.setDeviceTemperature(heartBeatDataPackage.getDeviceTemperature());
|
return save(c3mCharging);
|
} else {
|
one.setStatusBit(Integer.valueOf(heartBeatDataPackage.getStatusBit()));
|
one.setDeviceTemperature(heartBeatDataPackage.getDeviceTemperature());
|
return updateById(one);
|
}
|
}
|
|
/**
|
* 查询C3充电桩设备列表
|
*
|
* @return
|
*/
|
public List<C3mCharging> getC3ChargingList(BaseConditionVO baseConditionVO) {
|
PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
return list();
|
}
|
|
/**
|
* 开始充电
|
*
|
* @param c3Mac
|
* @param chargingCapacity
|
* @param chargeAmount
|
*/
|
public String startCharging(String c3Mac, Integer chargingCapacity, Double chargeAmount) {
|
C3StartChargingReqInnerFrame c3StartChargingReqInnerFrame =
|
new C3StartChargingReqInnerFrame(c3Mac, chargingCapacity, chargeAmount);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3StartChargingReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
|
// String functionCode = commonFrame.getPayload().substring(2, 4);
|
// if (C3ChargingEnum.StartCharging.getCode().equals(functionCode)) {}
|
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
/**
|
* 结束充电
|
*
|
* @param c3Mac
|
*/
|
public String finishCharging(String c3Mac) {
|
C3FinishChargingReqInnerFrame c3FinishChargingReqInnerFrame =
|
new C3FinishChargingReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3FinishChargingReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
|
/**
|
* 同步结束
|
*
|
* @param c3Mac
|
*/
|
public String EndOfTheSynchronization(String c3Mac) {
|
C3EndOfTheSynchronizationReqInnerFrame c3EndOfTheSynchronizationReqInnerFrame =
|
new C3EndOfTheSynchronizationReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3EndOfTheSynchronizationReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
/**
|
* 查询版本
|
*
|
* @param c3Mac
|
*/
|
public String QueryVersion(String c3Mac) {
|
C3QueryVersionReqInnerFrame c3QueryVersionReqInnerFrame =
|
new C3QueryVersionReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3QueryVersionReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
//payload=FE10000800000042010C010CFD913F7D
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
/**
|
* 查询心跳包间隔时间
|
*
|
* @param c3Mac
|
*/
|
public String QueryIntervalTime(String c3Mac) {
|
C3QueryIntervalTimeReqInnerFrame c3QueryIntervalTimeReqInnerFrame =
|
new C3QueryIntervalTimeReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3QueryIntervalTimeReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
/**
|
* 查询电压/电流常数
|
*
|
* @param c3Mac
|
*/
|
public String QueryConstant(String c3Mac) {
|
C3QueryConstantReqInnerFrame c3QueryConstantReqInnerFrame =
|
new C3QueryConstantReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3QueryConstantReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
/**
|
* 查询地址
|
*
|
* @param c3Mac
|
*/
|
public String QueryAddress(String c3Mac) {
|
C3QueryAddressReqInnerFrame c3QueryAddressReqInnerFrame =
|
new C3QueryAddressReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3QueryAddressReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
|
/**
|
* 软重启
|
*
|
* @param c3Mac
|
*/
|
public String restartCharging(String c3Mac) {
|
C3RestartChargingReqInnerFrame c3RestartChargingReqInnerFrame =
|
new C3RestartChargingReqInnerFrame(c3Mac);
|
|
A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3RestartChargingReqInnerFrame);
|
System.out.println(a5Frame + " -----a5Frame");
|
|
CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff0a04ffff", a5Frame);
|
System.out.println(commonFrame + " -----commonFrame");
|
|
A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
|
|
if (operationReportInnerFrame.isValidate()) {
|
return operationReportInnerFrame.getState();
|
} else {
|
throw new BusinessException("数据校验错误,请重新请求");
|
}
|
}
|
}
|