2021与蓝度共同重构项目,服务端
Van333
2022-12-05 694d691291f6ee89061fdbb9fd451ecb5519b69b
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
@@ -51,7 +51,6 @@
import java.util.*;
import java.util.stream.Collectors;
import static com.sandu.ximon.admin.localMQTT.callback.StatusMqttCallBack.localMqttConnectStatusMap;
/**
 * @author chenjiantian
@@ -88,6 +87,14 @@
                light.setLight2Percent(heartBeatDataPackage.getLight2Percent());
                save(light);
                log.info("新增路灯");
                Pole pole = new Pole();
                pole.setDeviceCode(deviceName);
                pole.setPoleName(deviceName);
                pole.setDeviceType(0);
                pole.setPoleCode(SpringContextHolder.getBean(PoleService.class).generatePoleCode());
                boolean result = SpringContextHolder.getBean(PoleService.class).saveOrUpdate(pole);
                log.info("新增灯杆:"+result);
            }
            redisService.set(LightKey.REPORT_MAC.key(deviceName), 1, LightKey.REPORT_MAC.expireSeconds());
        } else {
@@ -1013,9 +1020,7 @@
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), setCalendarReqInnerFrame);
        System.out.println(a5Frame + "            -----a5Frame");
        CommonFrame commonFrame;
        commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(one.getDeviceCode(), a5Frame);
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(one.getDeviceCode(), a5Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(one.getDeviceCode(), "单灯帧-设置日历", a5Frame, commonFrame);
        System.out.println(commonFrame + "            -----commonFrame");
@@ -1034,22 +1039,22 @@
    public void timeSynchronizationInitiative(String deviceCode, String lightAddress) {
        //单灯信息
        Light light = getLight(deviceCode);
//        if (light == null) {
//            log.error("单灯主动同步时间请求异常,单灯信息不存在!");
//            return;
//        }
        if (light == null) {
            log.error("单灯主动同步时间请求异常,单灯信息不存在!");
            return;
        }
        //单灯任务信息
        LightTaskPoleRelation lightTaskPoleRelation = SpringContextHolder.getBean(LightTaskPoleRelationService.class)
                .getOne(Wrappers.lambdaQuery(LightTaskPoleRelation.class)
                        .eq(LightTaskPoleRelation::getDeviceCode, deviceCode).eq(LightTaskPoleRelation::getLightAddress, lightAddress));
//        LightTaskPoleRelation lightTaskPoleRelation = SpringContextHolder.getBean(LightTaskPoleRelationService.class)
//                .getOne(Wrappers.lambdaQuery(LightTaskPoleRelation.class)
//                        .eq(LightTaskPoleRelation::getDeviceCode, deviceCode).eq(LightTaskPoleRelation::getLightAddress, lightAddress));
        LightTask lightTask = null;
        //灯头没有任务
        if (lightTaskPoleRelation != null) {
            if (lightTaskPoleRelation.getDeviceScheduled() != null) {
                lightTask = JSONObject.parseObject(lightTaskPoleRelation.getDeviceScheduled(), LightTask.class);
            }
        }
//        //灯头没有任务
//        if (lightTaskPoleRelation != null) {
//            if (lightTaskPoleRelation.getDeviceScheduled() != null) {
//                lightTask = JSONObject.parseObject(lightTaskPoleRelation.getDeviceScheduled(), LightTask.class);
//            }
//        }
        timeSynchronization(light, lightAddress, lightTask);
@@ -1062,16 +1067,18 @@
     * @param lightTask 单灯任务实体(为空标识单灯没有定时任务)
     */
    public void timeSynchronization(Light light, String lightAddress, LightTask lightTask) {
        lightTask = null;
        LightTask finalLightTask = lightTask;
        new Thread(new Runnable() {
            @Override
            public void run() {
                //获取当前时间时、分
                Calendar cal = Calendar.getInstance();
                if (lightTask != null) {
                    String closeOrder = lightTask.getCloseOrder();
                    String openOrder = lightTask.getOpenOrder();
                    String controlOrder = lightTask.getControlOrder() == null ? null : lightTask.getControlOrder();
                if (finalLightTask != null) {
                    String closeOrder = finalLightTask.getCloseOrder();
                    String openOrder = finalLightTask.getOpenOrder();
                    String controlOrder = finalLightTask.getControlOrder() == null ? null : finalLightTask.getControlOrder();
                    List<String> timeList = new ArrayList<>();
                    timeList.add(openOrder.substring(0, 4));
@@ -1096,14 +1103,15 @@
                        count++;
                    }
                    if (haveTime) {
                        try {
                            long longTime = cal.getTimeInMillis() - System.currentTimeMillis();
                            log.error("睡眠时间(毫秒):" + longTime);
                            Thread.sleep(longTime);
                            SetCalendar(light.getLightId(), lightAddress);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        log.error("存在定时任务:" + light.getLightId()+","+light.getDeviceCode());
//                        try {
//                            long longTime = cal.getTimeInMillis() - System.currentTimeMillis();
//                            log.error("睡眠时间(毫秒):" + longTime);
//                            Thread.sleep(longTime);
//                            SetCalendar(light.getLightId(), lightAddress);
//                        } catch (InterruptedException e) {
//                            e.printStackTrace();
//                        }
                    } else {
                        log.error("灯杆ID为:" + light.getLightId() + ",灯头地址为:" + lightAddress + "没有找到可同步的时间,请检查任务!");
                    }