2021与蓝度共同重构项目,服务端
liuhaonan
2022-03-22 55f49e493396d14689103f1912cb77fd653461cc
ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java
@@ -15,6 +15,7 @@
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
import com.sandu.ximon.dao.domain.C3mCharging;
import com.sandu.ximon.dao.domain.C3mChargingCharge;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.mapper.C3mChargingMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -33,6 +34,7 @@
public class C3ChargingService extends BaseServiceImpl<C3mChargingMapper, C3mCharging> {
    private final C3mChargingChargeService c3mChargingChargeService;
    private final PoleBindingService bindingService;
    /**
     * 保存上报C3充电设备心跳数据
@@ -349,6 +351,113 @@
    }
    /**
     * 设置地址
     *
     * @param c3Mac
     * @param address
     * @return
     */
    public String SetAddress(String c3Mac, String address) {
        if (address == null || address.length() != 8) {
            throw new BusinessException("地址信息错误!");
        }
        C3SetAddressReqInnerFrame setAddressReqInnerFrame =
                new C3SetAddressReqInnerFrame(c3Mac, address);
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), setAddressReqInnerFrame);
        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("数据校验错误,请重新请求");
        }
    }
    /**
     * 设置日历(同心跳包中的6字节日期时间)
     *
     * @param c3Mac
     * @return
     */
    public String SetCalendar(String c3Mac, int year, int month, int day, int hour, int min, int sec) {
        C3SetCalendarReqInnerFrame setCalendarReqInnerFrame =
                new C3SetCalendarReqInnerFrame(c3Mac, year, month, day, hour, min, sec);
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), setCalendarReqInnerFrame);
        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
     * @return
     */
    public String ClearedFaultCode(String c3Mac) {
        C3ClearedFaultCodeReqInnerFrame clearedFaultCodeReqInnerFrame =
                new C3ClearedFaultCodeReqInnerFrame(c3Mac);
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), clearedFaultCodeReqInnerFrame);
        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
     * @return
     */
    public String RestoreFactoryValue(String c3Mac) {
        C3RestoreFactoryValueReqInnerFrame restoreFactoryValueReqInnerFrame =
                new C3RestoreFactoryValueReqInnerFrame(c3Mac);
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), restoreFactoryValueReqInnerFrame);
        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
@@ -371,4 +480,12 @@
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
    public C3mCharging getC3mByPoleId(Long poleId) {
        PoleBinding one = bindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceType, 2).eq(PoleBinding::getPoleId, poleId));
        if (one == null) {
            throw new BusinessException("未找到绑定关系");
        }
        return getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getC3Mac, one.getDeviceCode()));
    }
}