2021与蓝度共同重构项目,服务端
liuhaonan
2022-05-18 7f74c2a4101e25e7889c046e8d3bcc1c30f360d3
ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java
@@ -18,14 +18,14 @@
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
import com.sandu.ximon.admin.param.C3ChargingAddParam;
import com.sandu.ximon.admin.param.C3ChargingParam;
import com.sandu.ximon.admin.param.PoleBindingParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.LogUtils;
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.bo.C3ChargingBo;
import com.sandu.ximon.dao.domain.C3mCharging;
import com.sandu.ximon.dao.domain.C3mChargingCharge;
import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.mapper.C3mChargingMapper;
import lombok.AllArgsConstructor;
@@ -33,6 +33,7 @@
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -108,23 +109,23 @@
                c3mChargingChargeService.initCharge((c3mCharging1.getC3Id()).intValue());
            }
        }
        /**
         * 添加绑定关系开始
         */
        Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName));
        if (pole == null) {
            Pole pole1 = new Pole();
            pole1.setDeviceCode(deviceName);
            pole1.setPoleName(deviceName);
            pole1.setPoleCode(poleService.generatePoleCode());
            poleService.save(pole1);
        }
        Long poleId = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName)).getId();
        PoleBindingParam poleBindingParam = new PoleBindingParam();
        poleBindingParam.setDeviceType(2);
        poleBindingParam.setDeviceCode(mcuUdid);
        bindingService.bindPole(poleId, poleBindingParam);
//        /**
//         * 添加绑定关系开始
//         */
//        Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName));
//        if (pole == null) {
//            Pole pole1 = new Pole();
//            pole1.setDeviceCode(deviceName);
//            pole1.setPoleName(deviceName);
//            pole1.setPoleCode(poleService.generatePoleCode());
//            poleService.save(pole1);
//        }
//
//        Long poleId = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName)).getId();
//        PoleBindingParam poleBindingParam = new PoleBindingParam();
//        poleBindingParam.setDeviceType(2);
//        poleBindingParam.setDeviceCode(mcuUdid);
//        bindingService.bindPole(poleId, poleBindingParam);
        /**
         * 添加绑定关系结束
@@ -240,6 +241,58 @@
        return one;
    }
    /**
     * 首页灯杆绑定信息
     *
     * @return
     */
    public EquipmentInfomation getByC3MacInfo(String udid) {
        EquipmentInfomation equipmentInfo = new EquipmentInfomation();
        equipmentInfo.setEquipmentType("C3充电桩");
        if (udid == null || udid.trim().length() == 0) {
            return equipmentInfo;
        }
        C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, udid));
        if (one != null) {
            String s = RedisUtils.getBean().get(C3mRedisConstant.C3_STATUS.getCode() + one.getC3Mac());
            if (s != null) {
                try {
                    A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage beatDataPackage = JSON.parseObject(s, A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage.class);
                    switch (beatDataPackage.getStatusBit()) {
                        case "1":
                            equipmentInfo.setEquipmentState("空闲");
                            break;
                        case "2":
                            equipmentInfo.setEquipmentState("充电中");
                            break;
                        case "3":
                            equipmentInfo.setEquipmentState("充电中断,等待服务器确认");
                            break;
                        case "4":
                            equipmentInfo.setEquipmentState("充电结束,等待服务器确认");
                            break;
                        case "5":
                            equipmentInfo.setEquipmentState("有故障");
                            break;
                        case "6":
                            equipmentInfo.setEquipmentState("与充电桩对接中");
                            break;
                        default:
                            equipmentInfo.setEquipmentState("未知");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                equipmentInfo.setEquipmentState("离线");
            }
            equipmentInfo.setEquipmentCreateTime(one.getUpdateTime());
            equipmentInfo.setEquipmentMac(one.getMcuUdid());
            equipmentInfo.setEquipmentName(one.getC3Name());
        }
        return equipmentInfo;
    }
    /**
     * 开始充电
@@ -260,6 +313,7 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-开始充电", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -293,7 +347,7 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-结束充电", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
        A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
@@ -323,6 +377,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-同步结束", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -351,6 +407,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-二维码", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -380,6 +438,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-版本查询", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -409,6 +469,7 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-查询心跳包间隔时间", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -438,6 +499,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-查询电压/电流常数", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -467,6 +530,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-查询地址", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -496,6 +561,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-查询故障码", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -525,6 +592,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-读取心跳包", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -558,6 +627,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置心跳包间隔时间", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -589,6 +660,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置电压/电流常数", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -629,6 +702,8 @@
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置地址", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -666,6 +741,7 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置日历", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -697,6 +773,7 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-清除故障码上报", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -728,6 +805,7 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-恢复出厂设置", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -756,7 +834,8 @@
            throw new BusinessException("C3充电桩硬件mcu_udid不存在");
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
//        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff1a06ffff", a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-软重启", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -784,7 +863,23 @@
            c3mCharging.setC3Name(c3ChargingAddParam.getC3Name());
        }
        c3mCharging.setC3Mac(c3ChargingAddParam.getC3Mac());
        return save(c3mCharging);
        /**
         * 添加充电桩 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(c3mCharging.getMcuUdid());
        String content = "{设备code:" + c3mCharging.getMcuUdid() + "设备名:" + c3mCharging.getC3Name() +
                "}";
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "添加充电桩", content);
        /**
         * 添加充电桩 日志记录结束
         */
        return
                save(c3mCharging);
    }
    public boolean updateC3ChargingName(C3ChargingAddParam c3ChargingAddParam) {
@@ -799,6 +894,21 @@
        C3mCharging c3mCharging = new C3mCharging();
        c3mCharging.setC3Id(c3ChargingAddParam.getC3Id());
        c3mCharging.setC3Name(c3ChargingAddParam.getC3Name());
        /**
         * 修改充电桩 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(c3mCharging.getMcuUdid());
        String content = "{设备code:" + c3mCharging.getMcuUdid() + "设备原名:" + one.getC3Name() + "更改后的设备名:" + c3mCharging.getC3Name() +
                "}";
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "编辑充电桩", content);
        /**
         * 修改充电桩 日志记录结束
         */
        return updateById(c3mCharging);
    }
@@ -807,7 +917,7 @@
        if (one == null) {
            throw new BusinessException("未找到绑定关系");
        }
        return getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getC3Mac, one.getDeviceCode()));
        return getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, one.getDeviceCode()));
    }