2021与蓝度共同重构项目,服务端
Van333
2022-12-29 727a69f859060093e685582fa10e5de82dcc138a
ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -22,6 +22,7 @@
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3HeartbeatReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A1TernaryCodeReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightResetReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A7PlcResetReqInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.EmptyRequestInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.response.A1DeviceMacRespInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.response.A1TernaryCodeRespInnerFrame;
@@ -45,6 +46,7 @@
import com.sandu.ximon.dao.domain.*;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.PoleMapper;
import eu.bitwalker.useragentutils.DeviceType;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils;
@@ -885,11 +887,21 @@
        if (deviceName.isEmpty()) {
            throw new BusinessException("该灯杆Mac为空");
        }
        IRequestFrame build = FrameBuilder.builderA5().orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).innerFrame(new A5LightResetReqInnerFrame()).build();
        Integer deviceType = byId.getDeviceType();
        IRequestFrame build = null;
        if (deviceType < 2){
            build = FrameBuilder.builderA5().orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).innerFrame(new A5LightResetReqInnerFrame()).build();
        }
        else if (deviceType == 2){
            build = FrameBuilder.builderA7().orderType(A7OrderEnum.REQUEST_PLC_DATA.getCode()).innerFrame(new A7PlcResetReqInnerFrame()).build();
        }
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, build);
        StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "灯杆恢复出厂设置", build, commonFrame);
        System.out.println(commonFrame.toString());
        IRequestFrame iRequestFrame = FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame()).orderType(A2OrderEnum.REQUEST_MAIN_BOARD_RESET.getCode()).build();
        CommonFrame rebootFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, iRequestFrame);
        StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "灯杆重启", iRequestFrame, commonFrame);
@@ -1001,6 +1013,8 @@
            pole.setDeviceType(0);
        } else if ("01".equals(a1DeviceMacRespInnerFrame.getType())) {
            pole.setDeviceType(1);
        } else if ("02".equals(a1DeviceMacRespInnerFrame.getType())) {
            pole.setDeviceType(2);
        }
        pole.setPoleCode(generatePoleCode());
@@ -1008,12 +1022,24 @@
        boolean result = saveOrUpdate(pole);
        if (result) {
            Light light = SpringContextHolder.getBean(LightService.class).getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
            if (light == null) {
                light = new Light();
                light.setDeviceCode(uniqueMac);
                light.setLightCount(2);
                SpringContextHolder.getBean(LightService.class).save(light);
            if (pole.getDeviceType() < 2) {
                Light light = SpringContextHolder.getBean(LightService.class).
                        getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
                if (light == null) {
                    light = new Light();
                    light.setDeviceCode(uniqueMac);
                    light.setLightCount(2);
                    SpringContextHolder.getBean(LightService.class).save(light);
                }
            } else if (pole.getDeviceType() == 2) {
                Plc plc = SpringContextHolder.getBean(PlcService.class).
                        getOne(Wrappers.lambdaQuery(Plc.class).eq(Plc::getDeviceCode,pole.getDeviceCode()).last("limit 1"));
                if (plc == null){
                    plc = new Plc();
                    plc.setDeviceCode(uniqueMac);
                    plc.setPlcCount(3);
                    SpringContextHolder.getBean(PlcService.class).save(plc);
                }
            }
        }
@@ -1419,4 +1445,4 @@
    }
}
}