diff --git a/ebike-operations/src/main/java/com/cdzy/operations/enums/CommandType.java b/ebike-operations/src/main/java/com/cdzy/operations/enums/CommandType.java index 80a0973..633d54e 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/enums/CommandType.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/enums/CommandType.java @@ -40,4 +40,9 @@ public interface CommandType { * 打开头盔锁 */ String OPEN_HELMET = "OPEN_HELMET"; + + /** + * 关闭电源 + */ + String POWER_OFF = "POWER_OFF"; } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/CommandService.java b/ebike-operations/src/main/java/com/cdzy/operations/service/CommandService.java index 111ad38..b222dfc 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/CommandService.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/CommandService.java @@ -66,4 +66,11 @@ public interface CommandService{ * @return 执行结果 */ boolean openHelmet(EbikeEcuInfo ebikeEcuInfo); + + /** + * 关闭电源 + * @param ebikeEcuInfo 中控信息 + * @return 执行结果 + */ + boolean powerOff(EbikeEcuInfo ebikeEcuInfo); } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeEcuInfoService.java b/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeEcuInfoService.java index 44ce107..7466ad0 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeEcuInfoService.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeEcuInfoService.java @@ -101,6 +101,13 @@ public interface EbikeEcuInfoService extends IService { */ boolean openHelmet(EbikeEcuInfo ebikeEcuInfo); + /** + * 打开头盔锁 + * @param ebikeEcuInfo 中控信息 + * @return 结果 + */ + boolean powerOff(EbikeEcuInfo ebikeEcuInfo); + /** * 执行命令 * @param ecuSn 中控SN码 diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/CommandServiceImpl.java b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/CommandServiceImpl.java index 3e9158a..6b8669c 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/CommandServiceImpl.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/CommandServiceImpl.java @@ -158,6 +158,23 @@ public class CommandServiceImpl implements CommandService { } } + @Override + public boolean powerOff(EbikeEcuInfo ebikeEcuInfo) { + String taskId = createTaskId(); + switch (ebikeEcuInfo.getEcuBrand()){ + case EcuBrand.GUANG_HE_TONG: + String command; + try { + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.POWER_OFF); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + return submitTaskAndWait(topic, taskId,command); + default : + throw new EbikeException("该品牌中控暂未接入"); + } + } + /** * 提交异步任务并等待布尔结果 diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeEcuInfoServiceImpl.java b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeEcuInfoServiceImpl.java index 665b820..23f61ae 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeEcuInfoServiceImpl.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeEcuInfoServiceImpl.java @@ -156,6 +156,11 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl lock(ebikeEcuInfo); case CommandType.UNLOCK -> unLock(ebikeEcuInfo); case CommandType.OPEN_HELMET -> openHelmet(ebikeEcuInfo); + case CommandType.POWER_OFF -> powerOff(ebikeEcuInfo); default -> throw new EbikeException("该命令不存在/未接入"); }; } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/utils/CommandUtil.java b/ebike-operations/src/main/java/com/cdzy/operations/utils/CommandUtil.java index 91eb5ab..beb8615 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/utils/CommandUtil.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/utils/CommandUtil.java @@ -58,6 +58,11 @@ public class CommandUtil { 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; default: throw new EbikeException("该命令暂未接入"); } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/utils/VehicleNumberUtil.java b/ebike-operations/src/main/java/com/cdzy/operations/utils/VehicleNumberUtil.java index 5155d95..03537c9 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/utils/VehicleNumberUtil.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/utils/VehicleNumberUtil.java @@ -211,7 +211,7 @@ public final class VehicleNumberUtil { } else { // 电池编号使用不同的数字范围:50000000000-89999999999 (400亿个编号空间) long formattedId = BATTERY_RANGE_START + (positiveId % BATTERY_RANGE_SIZE); - return String.format("%011d", formattedId); + return "B"+String.format("%011d", formattedId); } }