wjc
2025-04-25 18aad0f6f20ce89e2e904a59952f72c194ce085b
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
package com.hdl.photovoltaic.other;
 
import android.os.Build;
import android.text.TextUtils;
 
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
import com.hdl.photovoltaic.listener.CloudCallBeak;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * 本地json缓存逻辑
 */
public class HdlESLocalJsonLogic {
    private static volatile HdlESLocalJsonLogic sHdlESLocalJsonLogic;
 
    /**
     * 获取当前对象
     *
     * @return HdlAccountLogic
     */
    public static synchronized HdlESLocalJsonLogic getInstance() {
        if (sHdlESLocalJsonLogic == null) {
            synchronized (HdlESLocalJsonLogic.class) {
                if (sHdlESLocalJsonLogic == null) {
                    sHdlESLocalJsonLogic = new HdlESLocalJsonLogic();
                }
            }
 
        }
        return sHdlESLocalJsonLogic;
    }
 
    /**
     * 脚本地址域名
     */
    private static final String address = "https://hdl-hz-dev.oss-cn-hangzhou.aliyuncs.com/ecu";
 
    /**
     * 拼接符号
     */
    private final String concatenation_symbol = "%";
 
    /**
     * 拼接新地址
     *
     * @param fileName    json文件名称
     * @param deviceType  设备类型(inv,lc,bms,battery)
     * @param deviceModel 设备型号
     * @return 新地址
     */
    private String getStrJointNewUrl(String fileName, String deviceType, String deviceModel) {
        String joinFileName = fileName + concatenation_symbol + deviceType + concatenation_symbol + deviceModel;
        if (joinFileName.equals(FileName.hdl_inv_ecu_info_pv + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_output + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_item + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_signal + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_pv + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_output + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_item + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_signal + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV)
                || joinFileName.equals(FileName.hdl_inv_ecu_info_input_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV)
        ) {
            return address + "/" + UserConfigManage.getInstance().getCurrentAppLanguage() + "/" + deviceType + "/" + deviceModel + "/info/" + fileName + this.getVersion(joinFileName) + ".json";
        }
        return address + "/" + UserConfigManage.getInstance().getCurrentAppLanguage() + "/" + deviceType + "/" + deviceModel + "/" + fileName + this.getVersion(joinFileName) + ".json";
    }
 
 
    /**
     * 获取办版本号
     *
     * @return map
     */
    private String getVersion(String fileName) {
        Map<String, String> map = this.getFeliAndVersion();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (entry.getKey().equals(fileName)) {
                return entry.getValue();
            }
        }
        return "";
    }
 
    /**
     * 文件对应版本号
     *
     * @return map
     */
    private Map<String, String> getFeliAndVersion() {
        Map<String, String> map = new HashMap<>();
        //拼接规则:文件名_设备类型_设备信号
        map.put(FileName.hdl_lc_ecu_info_item + concatenation_symbol + DeviceType.LC + concatenation_symbol + DeviceModel.LC, Version.v_1_5_0);//获取负载控制中心
        map.put(FileName.hdl_lc_ecu_quick + concatenation_symbol + DeviceType.LC + concatenation_symbol + DeviceModel.LC, Version.v_1_5_2);//创建电站-负载控制中心参数配置
        map.put(FileName.hdl_inv_ecu_quick + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV, Version.v_1_5_1);//创建电站-逆变器参数配置
        map.put(FileName.hdl_inv_ecu + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV, Version.v_1_5_3);//逆变器参数配置//更新到v_1_5_3,目前硬件不支持
        map.put(FileName.hdl_inv_ecu_info_pv + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV, Version.v_1_4_2);// 逆变器详情-pv
        map.put(FileName.hdl_inv_ecu_info_output + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV, Version.v_1_4_2);//逆变器详情-输出
        map.put(FileName.hdl_inv_ecu_info_item + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV, Version.v_1_5_2);//逆变器详情-item项//更新到v_1_5_2,目前硬件不支持¬
        map.put(FileName.hdl_inv_ecu_info_signal + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.INV, Version.v_1_4_1);//逆变器详情-信号点
        map.put(FileName.hdl_bms_ecu + concatenation_symbol + DeviceType.BMS + concatenation_symbol + DeviceModel.INV_BMS, Version.v_1_4_2);//获取BMS信息
        map.put(FileName.hdl_battery_ecu + concatenation_symbol + DeviceType.BATTERY + concatenation_symbol + DeviceModel.INV_BATTERY, Version.v_1_4_2);//电池包信息
        map.put(FileName.hdl_battery_ecu_cell + concatenation_symbol + DeviceType.BATTERY + concatenation_symbol + DeviceModel.INV_BATTERY, Version.v_1_4_2);//电池包-电芯信息
        //离网逆变器
        map.put(FileName.hdl_inv_ecu_quick_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_inv_master_ecu_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_3);//离网逆变器快速配置
        map.put(FileName.hdl_inv_slave_ecu_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_inv_ecu_info_pv_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_inv_ecu_info_input_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_inv_ecu_info_output_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_inv_ecu_info_item_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_inv_ecu_info_signal_off + concatenation_symbol + DeviceType.INV + concatenation_symbol + DeviceModel.OFF_INV, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_bms_ecu_off + concatenation_symbol + DeviceType.BMS + concatenation_symbol + DeviceModel.OFF_INV_BMS, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_battery_ecu_off + concatenation_symbol + DeviceType.BATTERY + concatenation_symbol + DeviceModel.OFF_INV_BATTERY, Version.v_1_5_2);//离网逆变器快速配置
        map.put(FileName.hdl_battery_ecu_cell_off + concatenation_symbol + DeviceType.BATTERY + concatenation_symbol + DeviceModel.OFF_INV_BATTERY, Version.v_1_5_2);//离网逆变器快速配置
        return map;
    }
 
    /**
     * 向云端获取Json【所有】脚本
     */
    public void getAllHdlESLocalJson() {
        for (Map.Entry<String, String> str : this.getFeliAndVersion().entrySet()) {
            if (TextUtils.isEmpty(str.getKey())) {
                continue;
            }
            String[] ary = str.getKey().split(concatenation_symbol);
            String fileName = ary[0];
            String deviceType = ary[1];
            String deviceMode = ary[2];
            this.getHdlESLocalJson(fileName, deviceType, deviceMode, true, null);
        }
 
    }
 
 
    /**
     * 向云端获取Json【单个】脚本
     *
     * @param fileName    文件名
     * @param deviceType  设备类型
     * @param deviceModel 设备型号
     * @param isDelPath   是否删除(true表示删除,否则不删除)
     */
    public void getHdlESLocalJson(String fileName, String deviceType, String deviceModel, boolean isDelPath, CloudCallBeak<String> callBeak) {
        //拼接地址
        String url = getStrJointNewUrl(fileName, deviceType, deviceModel);
        HttpClient.getInstance().requestJsonHttpGet(url, new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String json) {
                saveJson(fileName, deviceModel, json, isDelPath);
                HdlLogLogic.print("获取云端脚本---" + url + "\r\n" + json, false);
                if (callBeak != null) {
                    callBeak.onSuccess(json);
                }
            }
 
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print(e.getMessage(), e.getCode(), false);
                if (callBeak != null) {
                    callBeak.onFailure(e);
                }
            }
        });
    }
 
    /**
     * 读取本地json数据
     *
     * @param fileName    文件名
     * @param deviceModel 设备型号
     */
    public String readHdlESLocalJson(String fileName, String deviceModel) {
        return this.readJson(fileName, deviceModel);
    }
 
    /**
     * 保存json数据
     *
     * @param fileName    文件名
     * @param deviceModel 设备型号(逆变器,负载中心,bms,电池包)
     * @param json        json内容
     * @param isDelPath   是否删除(true表示删除,否则不删除)
     */
    private void saveJson(String fileName, String deviceModel, String json, boolean isDelPath) {
        try {
            if (TextUtils.isEmpty(json)) {
                return;
            }
            //英文文件路径
            String fullPath = HdlFileLogic.getInstance().getHdlESLocalJsonEnFilePath(deviceModel, fileName);
            if (UserConfigManage.getInstance().isZh()) {
                //中文文件路径
                fullPath = HdlFileLogic.getInstance().getHdlESLocalJsonZhFilePath(deviceModel, fileName);
            }
            if (isDelPath) {
                HdlFileLogic.getInstance().deleteFile(fullPath);
            }
            HdlFileLogic.getInstance().writeFile(fullPath, json);
        } catch (Exception ignored) {
        }
    }
 
    /**
     * 读取json数据
     *
     * @param fileName    文件名
     * @param deviceModel 设备型号(逆变器,负载中心,bms,电池包)
     */
    private String readJson(String fileName, String deviceModel) {
        try {
            if (TextUtils.isEmpty(fileName)) {
                return "";
            }
            //英文文件路径
            String fullPath = HdlFileLogic.getInstance().getHdlESLocalJsonEnFilePath(deviceModel, fileName);
            if (UserConfigManage.getInstance().isZh()) {
                //中文文件路径
                fullPath = HdlFileLogic.getInstance().getHdlESLocalJsonZhFilePath(deviceModel, fileName);
            }
            return HdlFileLogic.getInstance().readFile(fullPath);
        } catch (Exception ignored) {
            return "";
        }
    }
 
    /**
     * Json数据配置文件名
     */
    public @interface FileName {
        /**
         * 创建电站-逆变器参数配置
         */
        String hdl_inv_ecu_quick = "modbus_hdl_inv_ecu_quick_v";
 
        /**
         * 逆变器参数配置(config)
         */
        String hdl_inv_ecu = "modbus_hdl_inv_ecu_v";
        /**
         * 逆变器详情-pv
         */
        String hdl_inv_ecu_info_pv = "modbus_hdl_inv_ecu_info_pv_v";
        /**
         * 逆变器详情-输出
         */
        String hdl_inv_ecu_info_output = "modbus_hdl_inv_ecu_info_output_v";
        /**
         * 逆变器详情-item项
         */
        String hdl_inv_ecu_info_item = "modbus_hdl_inv_ecu_info_item_v";
        /**
         * 创建电站-负载控制中心参数配置
         */
        String hdl_lc_ecu_quick = "modbus_hdl_lc_ecu_quick_v";
        /**
         * 获取负载控制中心
         */
        String hdl_lc_ecu_info_item = "modbus_hdl_lc_ecu_info_item_v";
        /**
         * 获取BMS信息
         */
        String hdl_bms_ecu = "modbus_hdl_bms_ecu_v";
        /**
         * 电池包信息
         */
        String hdl_battery_ecu = "modbus_hdl_battery_ecu_v";
 
        /**
         * 电池包-电芯信息
         */
        String hdl_battery_ecu_cell = "modbus_hdl_battery_ecu_cell_v";
 
        /**
         * 逆变器详情-信号点
         */
        String hdl_inv_ecu_info_signal = "modbus_hdl_inv_ecu_info_signal_v";
 
 
        /**
         * 离网逆变器快速配置
         */
        String hdl_inv_ecu_quick_off = "modbus_hdl_inv_ecu_quick_v";
 
        /**
         * 离网逆变器主机配置
         */
        String hdl_inv_master_ecu_off = "modbus_hdl_inv_master_ecu_v";
 
        /**
         * 离网逆变器从机配置
         */
        String hdl_inv_slave_ecu_off = "modbus_hdl_inv_slave_ecu_v";
 
        /**
         * 离网逆变器详情光伏输入
         */
        String hdl_inv_ecu_info_pv_off = "modbus_hdl_inv_ecu_info_pv_v";
 
        /**
         * 离网逆变器详情交流输入
         */
        String hdl_inv_ecu_info_input_off = "modbus_hdl_inv_ecu_info_input_v";
 
        /**
         * 离网逆变器详情交流输出
         */
        String hdl_inv_ecu_info_output_off = "modbus_hdl_inv_ecu_info_output_v";
 
        /**
         * 离网逆变器详情基础参数
         */
        String hdl_inv_ecu_info_item_off = "modbus_hdl_inv_ecu_info_item_v";
 
        /**
         * 离网逆变器详情统计
         */
        String hdl_inv_ecu_info_signal_off = "modbus_hdl_inv_ecu_info_signal_v";
 
        /**
         * 离网逆变器BMS详情
         */
        String hdl_bms_ecu_off = "modbus_hdl_bms_ecu_v";
 
        /**
         * 离网逆变器电池详情
         */
        String hdl_battery_ecu_off = "modbus_hdl_battery_ecu_v";
 
        /**
         * 离网逆变器电池电芯
         */
        String hdl_battery_ecu_cell_off = "modbus_hdl_battery_ecu_cell_v";
 
 
        /**
         * 获取逆变器所有json中文
         */
        String hdl_inv_ecu_all_zh = "/zh/all_v";
        /**
         * 获取逆变器所有json英文
         */
        String hdl_inv_ecu_all_en = "/en/all_v";
 
    }
 
 
    /**
     * 版本号
     */
    public @interface Version {
        String v_1_4_1 = "1.4.1";
        String v_1_4_2 = "1.4.2";
        String v_1_5_0 = "1.5.0";
        String v_1_5_1 = "1.5.1";
        String v_1_5_2 = "1.5.2";
        String v_1_5_3 = "1.5.3";
 
    }
 
    /**
     * 设备型号
     */
    public @interface DeviceModel {
        /**
         * 【逆变器】设备型号
         */
        String INV = "ME-GSE-S5K";
        /**
         * 【负载控制中心】设备型号
         */
        String LC = "ME-GSE-SPG63A";
        /**
         * 【BMS】设备型号
         */
        String INV_BMS = "ME-GSE-BMS15K";
        /**
         * 【电池包】设备型号
         */
        String INV_BATTERY = "ME-GSE-B5K";
 
 
        /**
         * 【离线逆变器】设备型号
         */
        String OFF_INV = "ME-GLE-S5K";
 
        /**
         * 【离网逆变器虚拟BMS】设备型号
         */
        String OFF_INV_BMS = "ME-GLE-S5K-BMS";
        /**
         * 【离网逆变器电池包】设备型号
         */
        String OFF_INV_BATTERY = "ME-GLE-B5K";
    }
 
    /**
     * 设备类型
     */
    public @interface DeviceType {
        /**
         * 【逆变器】类型
         */
        String INV = "inv";
        /**
         * 【负载控制中心】类型
         */
        String LC = "lc";
        /**
         * 【BMS】类型
         */
        String BMS = "bms";
        /**
         * 【电池包】类型
         */
        String BATTERY = "battery";
 
    }
 
}