xuhy
2024-09-03 ffd6a8ed2f7c052f9ef7e2450a26fa9df868b670
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package com.ruoyi.integration.rocket.produce;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.integration.iotda.constant.SendTagConstant;
import com.ruoyi.integration.rocket.model.*;
import com.ruoyi.integration.rocket.util.RocketMQEnhanceTemplate;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.UUID;
 
@Slf4j
@Component
public class EnhanceProduce {
 
    //注入增强后的模板,可以自动实现环境隔离,日志记录
    @Setter(onMethod_ = @Autowired)
    private RocketMQEnhanceTemplate rocketMQEnhanceTemplate;
 
    private static final String TOPIC = "rocket_enhance";
 
    /**
     * 充电桩登录认证
     */
    public SendResult onlineMessage(JSONObject jsonObject) {
        OnlineMessage message = JSON.parseObject(jsonObject.toJSONString(),OnlineMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.ONLINE);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.ONLINE, message);
    }
 
    /**
     * 充电桩心跳包
     */
    public SendResult pingMessage(JSONObject jsonObject) {
        PingMessage message = JSON.parseObject(jsonObject.toJSONString(),PingMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.PING);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PING, message);
    }
    /**
     * 充电结束
     */
    public SendResult endChargeMessage(JSONObject jsonObject) {
        PingMessage message = JSON.parseObject(jsonObject.toJSONString(),PingMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.END_CHARGE);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.END_CHARGE, message);
    }
 
    /**
     * 计费模型验证请求
     */
    public SendResult billingModeVerifyMessage(JSONObject jsonObject) {
        BillingModeVerifyMessage message = JSON.parseObject(jsonObject.toJSONString(),BillingModeVerifyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.BILLING_MODE_VERIFY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BILLING_MODE_VERIFY, message);
    }
 
    /**
     * 充电桩计费模型请求
     */
    public SendResult acquisitionBillingModeMessage(JSONObject jsonObject) {
        AcquisitionBillingModeMessage message = JSON.parseObject(jsonObject.toJSONString(),AcquisitionBillingModeMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.ACQUISITION_BILLING_MODE);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.ACQUISITION_BILLING_MODE, message);
    }
 
    /**
     * 上传实时监测数据
     */
    public SendResult uploadRealTimeMonitoringDataMessage(JSONObject jsonObject) {
        UploadRealTimeMonitoringDataMessage message = JSON.parseObject(jsonObject.toJSONString(),UploadRealTimeMonitoringDataMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA, message);
    }
 
    /**
     * 充电握手
     */
    public SendResult chargingHandshakeMessage(JSONObject jsonObject) {
        ChargingHandshakeMessage message = JSON.parseObject(jsonObject.toJSONString(),ChargingHandshakeMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.CHARGING_HANDSHAKE);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_HANDSHAKE, message);
    }
 
    /**
     * 充电阶段BMS中止
     */
    public SendResult bmsAbortMessage(JSONObject jsonObject) {
        BmsAbortMessage message = JSON.parseObject(jsonObject.toJSONString(),BmsAbortMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.BMS_ABORT);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_ABORT, message);
    }
 
    /**
     * 充电阶段充电机中止
     */
    public SendResult motorAbortMessage(JSONObject jsonObject) {
        MotorAbortMessage message = JSON.parseObject(jsonObject.toJSONString(),MotorAbortMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.MOTOR_ABORT);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.MOTOR_ABORT, message);
    }
 
    /**
     * 充电过程BMS需求、充电机输出
     */
    public SendResult bmsDemandAndChargerExportationMessage(JSONObject jsonObject) {
        BmsDemandAndChargerExportationMessage message = JSON.parseObject(jsonObject.toJSONString(),BmsDemandAndChargerExportationMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION, message);
    }
 
    /**
     * 充电过程BMS信息
     */
    public SendResult bmsInformationMessage(JSONObject jsonObject) {
        BmsInformationMessage message = JSON.parseObject(jsonObject.toJSONString(),BmsInformationMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.BMS_INFORMATION);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_INFORMATION, message);
    }
 
    /**
     * 充电桩主动申请启动充电
     */
    public SendResult chargingPileStartsChargingMessage(JSONObject jsonObject) {
        ChargingPileStartsChargingMessage message = JSON.parseObject(jsonObject.toJSONString(),ChargingPileStartsChargingMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.CHARGING_PILE_STARTS_CHARGING);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_PILE_STARTS_CHARGING, message);
    }
 
    /**
     * 远程启机命令回复
     */
    public SendResult platformStartChargingReplyMessage(JSONObject jsonObject) {
        PlatformStartChargingReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),PlatformStartChargingReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.PLATFORM_START_CHARGING_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_START_CHARGING_REPLY, message);
    }
 
    /**
     * 远程停机命令回复
     */
    public SendResult platformStopChargingReplyMessage(JSONObject jsonObject) {
        PlatformStopChargingReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),PlatformStopChargingReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.PLATFORM_STOP_CHARGING_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_STOP_CHARGING_REPLY, message);
    }
 
    /**
     * 交易记录
     */
    public SendResult transactionRecordMessage(JSONObject jsonObject) {
        TransactionRecordMessage message = JSON.parseObject(jsonObject.toJSONString(),TransactionRecordMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.TRANSACTION_RECORD);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.TRANSACTION_RECORD, message);
    }
 
    /**
     * 余额更新应答
     */
    public SendResult updateBalanceReplyMessage(JSONObject jsonObject) {
        UpdateBalanceReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),UpdateBalanceReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.UPDATE_BALANCE_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.UPDATE_BALANCE_REPLY, message);
    }
 
    /**
     * 卡数据同步应答
     */
    public SendResult synchronizeOfflineCardReplyMessage(JSONObject jsonObject) {
        SynchronizeOfflineCardReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),SynchronizeOfflineCardReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY, message);
    }
 
    /**
     * 离线卡数据清除应答
     */
    public SendResult clearOfflineCardReplyMessage(JSONObject jsonObject) {
        ClearOfflineCardReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),ClearOfflineCardReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.CLEAR_OFFLINE_CARD_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CLEAR_OFFLINE_CARD_REPLY, message);
    }
 
    /**
     * 充电桩工作参数设置应答
     */
    public SendResult workingParameterSettingReplyMessage(JSONObject jsonObject) {
        WorkingParameterSettingReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),WorkingParameterSettingReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.WORKING_PARAMETER_SETTING_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.WORKING_PARAMETER_SETTING_REPLY, message);
    }
 
    /**
     * 对时设置应答
     */
    public SendResult timingSettingReplyMessage(JSONObject jsonObject) {
        TimingSettingReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),TimingSettingReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.TIMING_SETTING_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.TIMING_SETTING_REPLY, message);
    }
 
    /**
     * 计费模型应答
     */
    public SendResult setupBillingModelReplyMessage(JSONObject jsonObject) {
        SetupBillingModelReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),SetupBillingModelReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.SETUP_BILLING_MODEL_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.SETUP_BILLING_MODEL_REPLY, message);
    }
 
    /**
     * 地锁数据上送(充电桩上送)
     */
    public SendResult groundLockRealTimeDataMessage(JSONObject jsonObject) {
        GroundLockRealTimeDataMessage message = JSON.parseObject(jsonObject.toJSONString(),GroundLockRealTimeDataMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.GROUND_LOCK_REAL_TIME_DATA);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.GROUND_LOCK_REAL_TIME_DATA, message);
    }
 
    /**
     * 充电桩返回数据(上行)
     */
    public SendResult chargingPileReturnsGroundLockDataMessage(JSONObject jsonObject) {
        ChargingPileReturnsGroundLockDataMessage message = JSON.parseObject(jsonObject.toJSONString(),ChargingPileReturnsGroundLockDataMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA, message);
    }
 
    /**
     * 远程重启应答
     */
    public SendResult platformRestartReplyMessage(JSONObject jsonObject) {
        PlatformRestartReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),PlatformRestartReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.PLATFORM_RESTART_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_RESTART_REPLY, message);
    }
 
    /**
     * 远程更新应答
     */
    public SendResult platformRemoteUpdateReplyMessage(JSONObject jsonObject) {
        PlatformRemoteUpdateReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),PlatformRemoteUpdateReplyMessage.class);
        // 设置业务key
        message.setKey(UUID.randomUUID().toString());
        // 设置消息来源,便于查询
        message.setSource(SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY);
        return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY, message);
    }
}