2025-11-19 10:55:39 +08:00

93 lines
4.6 KiB
Java

package com.cdzy.operations.utils;
import cn.hutool.core.io.FileUtil;
import com.cdzy.common.ex.EbikeException;
import com.cdzy.common.utils.RemoteFileUtils;
import com.cdzy.operations.enums.CommandType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.File;
import java.io.IOException;
/**
* @author attiya
* @since 2025-10-30
*/
public class CommandUtil {
private static final ObjectMapper mapper = new ObjectMapper();
private static final String guang_he_tong_prefix = "ecu/cmd/cdzybms/";
private static final String guang_he_tong_broadcast = "ecu/cmd/cdzybms/broadcast";
public static String guang_he_tong(String ecuSn, String taskId, String code, String url, Integer idx, Boolean fullUpgrade) throws IOException {
String topic = guang_he_tong_prefix + ecuSn;
ObjectNode jsonNode = mapper.createObjectNode();
if (fullUpgrade) {
topic = guang_he_tong_broadcast;
}
jsonNode.put("topic", topic);
switch (code) {
case CommandType.FIND_BIKE:
String command_14 = "{\"c\":14,\"tid\":\"" + taskId + "\",\"param\":{\"volume\":50,\"idx\":5}}";
ObjectNode objectNode_14 = mapper.readValue(command_14, ObjectNode.class);
jsonNode.put("command", objectNode_14.toString());
break;
case CommandType.GPS:
String command_34 = "{\"c\":34,\"tid\":\"" + taskId + "\"}";
ObjectNode objectNode_34 = mapper.readValue(command_34, ObjectNode.class);
jsonNode.put("command", objectNode_34.toString());
break;
case CommandType.OPEN_BATTERY_LOCK:
String command_29 = "{\"c\":29,\"tid\":\"" + taskId + "\"}";
ObjectNode objectNode_29 = mapper.readValue(command_29, ObjectNode.class);
jsonNode.put("command", objectNode_29.toString());
break;
case CommandType.CLOSE_BATTERY_LOCK:
String command_94 = "{\"c\":94,\"tid\":\"" + taskId + "\"}";
ObjectNode objectNode_94 = mapper.readValue(command_94, ObjectNode.class);
jsonNode.put("command", objectNode_94.toString());
break;
case CommandType.UNLOCK:
String command_33 = "{\"c\":33,\"tid\":\"" + taskId + "\",\"param\":{\"acc\":1,\"idx\":14,\"stamp\":" + System.currentTimeMillis() + "}}";
ObjectNode objectNode_33 = mapper.readValue(command_33, ObjectNode.class);
jsonNode.put("command", objectNode_33.toString());
break;
case CommandType.LOCK:
String command_4 = "{\"c\":4,\"tid\":\"" + taskId + "\",\"param\":{\"defend\":1,\"idx\":14,\"isTBeacon\":0}}";
ObjectNode objectNode_4 = mapper.readValue(command_4, ObjectNode.class);
jsonNode.put("command", objectNode_4.toString());
break;
case CommandType.OPEN_HELMET:
String command_89 = "{\"tid\":\"" + taskId + "\",\"c\":89,\"param\":{\"opt\":0}}";
ObjectNode objectNode_89 = mapper.readValue(command_89, ObjectNode.class);
jsonNode.put("command", objectNode_89.toString());
break;
case CommandType.POWER_OFF:
String command_100 = "{\"c\":100,\"tid\":\"" + taskId + "\",\"param\":{\"Dsg\":0}}";
ObjectNode objectNode_100 = mapper.readValue(command_100, ObjectNode.class);
jsonNode.put("command", objectNode_100.toString());
break;
case CommandType.UPGRADE:
File tempFile = RemoteFileUtils.getRemoteFile(url);
long size = FileUtil.size(tempFile);
String command_35 = "{\"tid\":\"" + taskId + "\",\"c\":35,\"param\":{\"len\":" + size + ",\"url\":\"" + url + "\"}}";
ObjectNode objectNode_35 = mapper.readValue(command_35, ObjectNode.class);
jsonNode.put("command", objectNode_35.toString());
break;
case CommandType.UPGRADE_AUDIO:
String command_30 = "{\"tid\":\"" + taskId + "\",\"c\":30,\"param\":{\"idx\":" + idx + ",\"url\":\"" + url + "\",\"default\":0}}";
ObjectNode objectNode_30 = mapper.readValue(command_30, ObjectNode.class);
jsonNode.put("command", objectNode_30.toString());
break;
default:
throw new EbikeException("该命令暂未接入");
}
return jsonNode.toString();
}
}