2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-04-13 b3ce47c84498d60d29e5e9faa813168aa73b9844
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.frame.A5Frame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.*;
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.mainboard.MainBoardInvokeSyncService;
import com.sandu.ximon.admin.param.LightPoleHeelingListParam;
import com.sandu.ximon.dao.domain.Light;
import com.sandu.ximon.dao.domain.LightPoleHeeling;
import com.sandu.ximon.dao.domain.LightPoleHeelingEquipment;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.mapper.LightPoleHeelingMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
@AllArgsConstructor
public class LightPoleHeelingService extends BaseServiceImpl<LightPoleHeelingMapper, LightPoleHeeling> {
    private LightPoleHeelingMapper lightPoleHeelingMapper;
    private LightPoleHeelingEquipmentService lightPoleHeelingEquipmentService;
 
    /**
     * 模糊查询
     */
    public List<LightPoleHeeling> listLightPoleHeelingByKeyword(BaseConditionVO baseConditionVO, LightPoleHeelingListParam lightPoleHeelingListParam) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        if (lightPoleHeelingListParam == null) {
            lightPoleHeelingListParam = new LightPoleHeelingListParam();
        }
 
        //关键字去除空格
        if (lightPoleHeelingListParam.getKeyword() != null) {
            lightPoleHeelingListParam.setKeyword(lightPoleHeelingListParam.getKeyword().trim());
        }
 
        List<LightPoleHeeling> lightPoleHeelings
                = lightPoleHeelingMapper.listLightPoleHeeling(lightPoleHeelingListParam.getKeyword(), lightPoleHeelingListParam.getProcessingState());
 
        return lightPoleHeelings;
    }
 
    /**
     * 根据Mac获取最新数据
     */
    public LightPoleHeeling getLightPoleHeelingByMac(String mac) {
        return getOne(Wrappers.lambdaQuery(LightPoleHeeling.class).eq(LightPoleHeeling::getMac, mac));
    }
 
    /**
     * 灯杆倾斜心跳包
     *
     * @param deviceName
     */
    public A5LightPoleHeelingHeartbeatReportInnerFrame.HeartBeatDataPackage LightPoleHeelingHeartbeatPackage(String deviceName) {
        LightPoleHeelingHeartbeatPackageReqInnerFrame lightPoleHeelingHeartbeatPackageReqInnerFrame = new LightPoleHeelingHeartbeatPackageReqInnerFrame();
 
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), lightPoleHeelingHeartbeatPackageReqInnerFrame);
        System.out.println(a5Frame + "            -----a5Frame");
 
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame);
        System.out.println(commonFrame + "            -----commonFrame");
 
 
        A5LightPoleHeelingHeartbeatReportInnerFrame heartbeatReportInnerFrame
                = new A5LightPoleHeelingHeartbeatReportInnerFrame().transformFrame(commonFrame.getPayload());
 
        if (heartbeatReportInnerFrame.isValidate()) {
 
            //灯杆倾斜心跳包保存数据库
            saveLightPoleHeelingHeartbeat(deviceName, heartbeatReportInnerFrame.getHeartBeatDataPackage());
 
            return heartbeatReportInnerFrame.getHeartBeatDataPackage();
        } else {
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
 
    /**
     * 查询心跳包间隔时间
     *
     * @param deviceName
     */
    public String QueryIntervalTime(String deviceName) {
        LightPoleHeelingQueryIntervalTimeReqInnerFrame queryIntervalTimeReqInnerFrame
                = new LightPoleHeelingQueryIntervalTimeReqInnerFrame();
 
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), queryIntervalTimeReqInnerFrame);
        System.out.println(a5Frame + "            -----a5Frame");
 
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame);
        System.out.println(commonFrame + "            -----commonFrame");
 
 
        A5LightPoleHeelingQueryReportInnerFrame queryReportInnerFrame = new A5LightPoleHeelingQueryReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (queryReportInnerFrame.isValidate()) {
            return queryReportInnerFrame.getIntervalTime();
        } else {
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
 
    /**
     * 软重启
     *
     * @param deviceName
     */
    public String RestartLightPoleHeeling(String deviceName) {
        LightPoleHeelingRestartReqInnerFrame restartReqInnerFrame
                = new LightPoleHeelingRestartReqInnerFrame();
 
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), restartReqInnerFrame);
        System.out.println(a5Frame + "            -----a5Frame");
 
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, a5Frame);
        System.out.println(commonFrame + "            -----commonFrame");
 
 
        A5LightPoleHeelingOperationReportInnerFrame operationReportInnerFrame
                = new A5LightPoleHeelingOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (operationReportInnerFrame.isValidate()) {
            return operationReportInnerFrame.getState();
        } else {
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
 
    /**
     * 设置心跳包间隔时间(秒)
     *
     * @param devicesName
     * @param setTime
     * @return
     */
    public String SetHeartbeatPacketTime(String devicesName, int setTime) {
        if (setTime <= 0) {
            throw new BusinessException("设置的心跳包间隔时间错误!");
        }
        LightPoleHeelingSetHeartbeatPacketTimeReqInnerFrame setHeartbeatPacketTimeReqInnerFrame =
                new LightPoleHeelingSetHeartbeatPacketTimeReqInnerFrame(setTime);
 
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), setHeartbeatPacketTimeReqInnerFrame);
        System.out.println(a5Frame + "            -----a5Frame");
 
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(devicesName, a5Frame);
        System.out.println(commonFrame + "            -----commonFrame");
 
        A5LightPoleHeelingOperationReportInnerFrame operationReportInnerFrame
                = new A5LightPoleHeelingOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (operationReportInnerFrame.isValidate()) {
            return operationReportInnerFrame.getState();
        } else {
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
 
    /**
     * 设置传感器为初始状态
     *
     * @return
     */
    public String SetSensorState(String devicesName) {
        LightPoleHeelingSetSensorStateReqInnerFrame setSensorStateReqInnerFrame =
                new LightPoleHeelingSetSensorStateReqInnerFrame();
 
        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_POLE_MONITOR_DATA.getCode(), setSensorStateReqInnerFrame);
        System.out.println(a5Frame + "            -----a5Frame");
 
        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(devicesName, a5Frame);
        System.out.println(commonFrame + "            -----commonFrame");
 
        A5LightPoleHeelingOperationReportInnerFrame operationReportInnerFrame
                = new A5LightPoleHeelingOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (operationReportInnerFrame.isValidate()) {
            return operationReportInnerFrame.getState();
        } else {
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
 
    /**
     * 保存心跳包数据
     *
     * @param deviceName
     * @param heartBeatDataPackage
     * @return
     */
    public boolean saveLightPoleHeelingHeartbeat(String deviceName, A5LightPoleHeelingHeartbeatReportInnerFrame.HeartBeatDataPackage heartBeatDataPackage) {
 
        LightPoleHeeling lightPoleHeeling = new LightPoleHeeling();
        lightPoleHeeling.setMac(deviceName);
        lightPoleHeeling.setTheXAxis(heartBeatDataPackage.getTheXAxis());
        lightPoleHeeling.setTheYAxis(heartBeatDataPackage.getTheYAxis());
        lightPoleHeeling.setTheZAxis(heartBeatDataPackage.getTheZAxis());
        if (Math.abs(heartBeatDataPackage.getTheXAxis()) >= 10 || Math.abs(heartBeatDataPackage.getTheYAxis()) >= 10) {
            lightPoleHeeling.setWarningLevel(1);//一级警告
        } else if ((Math.abs(heartBeatDataPackage.getTheXAxis()) >= 5 && Math.abs(heartBeatDataPackage.getTheXAxis()) < 10)
                || (Math.abs(heartBeatDataPackage.getTheYAxis()) >= 5 && Math.abs(heartBeatDataPackage.getTheYAxis()) < 10)) {
            lightPoleHeeling.setWarningLevel(2);//二级警告
        } else {
            lightPoleHeeling.setWarningLevel(0);//正常
        }
        /**
         * 将灯杆倾斜硬件添加到硬件表
         */
        LightPoleHeelingEquipment one = lightPoleHeelingEquipmentService.getOne(Wrappers.lambdaQuery(LightPoleHeelingEquipment.class).eq(LightPoleHeelingEquipment::getMac, deviceName));
        if (one == null) {
            LightPoleHeelingEquipment equipment = new LightPoleHeelingEquipment();
            equipment.setMac(deviceName);
            lightPoleHeelingEquipmentService.addLightPoleHeelingEquipment(equipment);
        }
 
        return save(lightPoleHeeling);
    }
}