命令集成

This commit is contained in:
attiya 2025-11-05 09:45:29 +08:00
parent 3eef1b847f
commit 95a513c684
7 changed files with 48 additions and 1 deletions

View File

@ -40,4 +40,9 @@ public interface CommandType {
* 打开头盔锁
*/
String OPEN_HELMET = "OPEN_HELMET";
/**
* 关闭电源
*/
String POWER_OFF = "POWER_OFF";
}

View File

@ -66,4 +66,11 @@ public interface CommandService{
* @return 执行结果
*/
boolean openHelmet(EbikeEcuInfo ebikeEcuInfo);
/**
* 关闭电源
* @param ebikeEcuInfo 中控信息
* @return 执行结果
*/
boolean powerOff(EbikeEcuInfo ebikeEcuInfo);
}

View File

@ -101,6 +101,13 @@ public interface EbikeEcuInfoService extends IService<EbikeEcuInfo> {
*/
boolean openHelmet(EbikeEcuInfo ebikeEcuInfo);
/**
* 打开头盔锁
* @param ebikeEcuInfo 中控信息
* @return 结果
*/
boolean powerOff(EbikeEcuInfo ebikeEcuInfo);
/**
* 执行命令
* @param ecuSn 中控SN码

View File

@ -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("该品牌中控暂未接入");
}
}
/**
* 提交异步任务并等待布尔结果

View File

@ -156,6 +156,11 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
return commandService.openHelmet(ebikeEcuInfo);
}
@Override
public boolean powerOff(EbikeEcuInfo ebikeEcuInfo) {
return commandService.powerOff(ebikeEcuInfo);
}
@Override
public boolean checkSnOrBikeCode(String ecuSn, String bikeCode) {
try {
@ -188,6 +193,7 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
case CommandType.LOCK -> lock(ebikeEcuInfo);
case CommandType.UNLOCK -> unLock(ebikeEcuInfo);
case CommandType.OPEN_HELMET -> openHelmet(ebikeEcuInfo);
case CommandType.POWER_OFF -> powerOff(ebikeEcuInfo);
default -> throw new EbikeException("该命令不存在/未接入");
};
}

View File

@ -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("该命令暂未接入");
}

View File

@ -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);
}
}