gps定位

This commit is contained in:
attiya 2025-10-31 10:07:37 +08:00
parent e5f6e16d8c
commit 38aa18053e
7 changed files with 91 additions and 29 deletions

View File

@ -9,6 +9,7 @@ import com.cdzy.operations.model.vo.EbikeEcuInfoVo;
import com.cdzy.operations.service.EbikeEcuInfoService; import com.cdzy.operations.service.EbikeEcuInfoService;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -132,7 +133,7 @@ public class EbikeEcuInfoController {
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("checkSnOrBikeCode") @GetMapping("checkSnOrBikeCode")
public JsonResult<?> checkSnOrBikeCode(String ecuSn,String bikeCode) throws IOException { public JsonResult<?> checkSnOrBikeCode(String ecuSn,String bikeCode) {
boolean result = ebikeEcuInfoService.checkSnOrBikeCode(ecuSn,bikeCode); boolean result = ebikeEcuInfoService.checkSnOrBikeCode(ecuSn,bikeCode);
return JsonResult.success(result); return JsonResult.success(result);
} }
@ -151,13 +152,13 @@ public class EbikeEcuInfoController {
/** /**
* 寻车铃 * 执行命令
* *
* @return 执行结构 * @return 执行结构
*/ */
@GetMapping("findBike") @GetMapping("executeCommand")
public JsonResult<?> findBike(String ecuSn,String bikeCode) { public JsonResult<?> executeCommand(String ecuSn,String bikeCode,@NotNull(message = "命令编码不能为空") String commandCode) {
boolean findBike = ebikeEcuInfoService.findBike(ecuSn,bikeCode); boolean findBike = ebikeEcuInfoService.executeCommand(ecuSn,bikeCode,commandCode);
return JsonResult.success(findBike); return JsonResult.success(findBike);
} }

View File

@ -5,5 +5,14 @@ package com.cdzy.operations.enums;
* @since 2025-10-30 * @since 2025-10-30
*/ */
public interface CommandType { public interface CommandType {
/**
* 寻车铃
*/
String FIND_BIKE = "FIND_BIKE"; String FIND_BIKE = "FIND_BIKE";
/**
* GPS
*/
String GPS = "GPS";
} }

View File

@ -17,6 +17,13 @@ public interface CommandService{
*/ */
boolean findBike(EbikeEcuInfo ebikeEcuInfo); boolean findBike(EbikeEcuInfo ebikeEcuInfo);
/**
* GPS定位上报
* @param ebikeEcuInfo 中控信息
* @return 执行结果
*/
boolean gps(EbikeEcuInfo ebikeEcuInfo);
/** /**
* 回调事件 * 回调事件
* @param taskId 任务ID * @param taskId 任务ID

View File

@ -45,11 +45,17 @@ public interface EbikeEcuInfoService extends IService<EbikeEcuInfo> {
/** /**
* 寻车铃命令 * 寻车铃命令
* @param ecuSn 中控SN码 * @param ebikeEcuInfo 中控信息
* @param bikeCode 车辆编号
* @return 结果 * @return 结果
*/ */
boolean findBike(String ecuSn, String bikeCode); boolean findBike(EbikeEcuInfo ebikeEcuInfo);
/**
* GPS命令
* @param ebikeEcuInfo 中控信息
* @return 结果
*/
boolean gps(EbikeEcuInfo ebikeEcuInfo);
/** /**
* 校验参数 * 校验参数
@ -58,4 +64,13 @@ public interface EbikeEcuInfoService extends IService<EbikeEcuInfo> {
* @return 结果 * @return 结果
*/ */
boolean checkSnOrBikeCode(String ecuSn, String bikeCode); boolean checkSnOrBikeCode(String ecuSn, String bikeCode);
/**
* 执行命令
* @param ecuSn 中控SN码
* @param bikeCode 车辆编号
* @param commandCode 命令编码
* @return 执行结果
*/
boolean executeCommand(String ecuSn, String bikeCode, String commandCode);
} }

View File

@ -36,7 +36,6 @@ public class CommandServiceImpl implements CommandService {
@Override @Override
public boolean findBike(EbikeEcuInfo ebikeEcuInfo) { public boolean findBike(EbikeEcuInfo ebikeEcuInfo) {
boolean result = false;
String taskId = createTaskId(); String taskId = createTaskId();
switch (ebikeEcuInfo.getEcuBrand()){ switch (ebikeEcuInfo.getEcuBrand()){
case EcuBrand.GUANG_HE_TONG: case EcuBrand.GUANG_HE_TONG:
@ -46,12 +45,27 @@ public class CommandServiceImpl implements CommandService {
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
result = submitTaskAndWait(topic, taskId,command); return submitTaskAndWait(topic, taskId,command);
break; default :
throw new EbikeException("该品牌中控暂未接入");
}
}
@Override
public boolean gps(EbikeEcuInfo ebikeEcuInfo) {
String taskId = createTaskId();
switch (ebikeEcuInfo.getEcuBrand()){
case EcuBrand.GUANG_HE_TONG:
String command = null;
try {
command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.GPS);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return submitTaskAndWait(topic, taskId,command);
default : default :
throw new EbikeException("该品牌中控暂未接入"); throw new EbikeException("该品牌中控暂未接入");
} }
return result;
} }
@Override @Override
@ -90,9 +104,7 @@ public class CommandServiceImpl implements CommandService {
*/ */
private void sendMessageToQueue(String topic, String taskData) { private void sendMessageToQueue(String topic, String taskData) {
executor.submit(() -> { executor.submit(() -> kafkaProducer.send(topic, taskData));
kafkaProducer.send(topic, taskData);
});
} }
/** /**

View File

@ -2,6 +2,7 @@ package com.cdzy.operations.service.impl;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.ex.EbikeException; import com.cdzy.common.ex.EbikeException;
import com.cdzy.operations.enums.CommandType;
import com.cdzy.operations.mapper.EbikeBikeInfoMapper; import com.cdzy.operations.mapper.EbikeBikeInfoMapper;
import com.cdzy.operations.model.dto.EbikeEcuInOverview; import com.cdzy.operations.model.dto.EbikeEcuInOverview;
import com.cdzy.operations.model.entity.EbikeBikeInfo; import com.cdzy.operations.model.entity.EbikeBikeInfo;
@ -121,15 +122,13 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
} }
@Override @Override
public boolean findBike(String ecuSn, String bikeCode) { public boolean findBike(EbikeEcuInfo ebikeEcuInfo) {
check(ecuSn, bikeCode);
if (StringUtil.hasText(ecuSn)) {
EbikeEcuInfo ebikeEcuInfo = checkEcuSn(ecuSn);
return commandService.findBike(ebikeEcuInfo); return commandService.findBike(ebikeEcuInfo);
} else { }
EbikeEcuInfo ebikeEcuInfo = getEcu(bikeCode);
return commandService.findBike(ebikeEcuInfo); @Override
} public boolean gps(EbikeEcuInfo ebikeEcuInfo) {
return commandService.gps(ebikeEcuInfo);
} }
@Override @Override
@ -138,16 +137,31 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
check(ecuSn, bikeCode); check(ecuSn, bikeCode);
if (StringUtil.hasText(ecuSn)) { if (StringUtil.hasText(ecuSn)) {
checkEcuSn(ecuSn); checkEcuSn(ecuSn);
return true;
} else { } else {
getEcu(bikeCode); getEcu(bikeCode);
return true;
} }
return true;
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
} }
@Override
public boolean executeCommand(String ecuSn, String bikeCode, String commandCode) {
check(ecuSn, bikeCode);
EbikeEcuInfo ebikeEcuInfo = null;
if (StringUtil.hasText(ecuSn)) {
ebikeEcuInfo = checkEcuSn(ecuSn);
} else {
ebikeEcuInfo = getEcu(bikeCode);
}
return switch (commandCode) {
case CommandType.FIND_BIKE -> findBike(ebikeEcuInfo);
case CommandType.GPS -> gps(ebikeEcuInfo);
default -> throw new EbikeException("该命令不存在/未接入");
};
}
private EbikeEcuInfo checkEcuSn(String ecuSn) { private EbikeEcuInfo checkEcuSn(String ecuSn) {
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ECU_INFO.ECU_SN.eq(ecuSn)); .where(EBIKE_ECU_INFO.ECU_SN.eq(ecuSn));

View File

@ -23,10 +23,14 @@ public class CommandUtil {
switch (code) { switch (code) {
case CommandType.FIND_BIKE: case CommandType.FIND_BIKE:
String json = "{\"c\":14,\"tid\":\""+ taskId+"\",\"param\":{\"volume\":50,\"idx\":5}}"; String command_14 = "{\"c\":14,\"tid\":\""+ taskId+"\",\"param\":{\"volume\":50,\"idx\":5}}";
ObjectNode objectNode = mapper.readValue(json,ObjectNode.class); ObjectNode objectNode_14 = mapper.readValue(command_14,ObjectNode.class);
objectNode.put("tid",taskId); jsonNode.put("command",objectNode_14.toString());
jsonNode.put("command",objectNode.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; break;
default : default :
throw new EbikeException("该命令暂未接入"); throw new EbikeException("该命令暂未接入");