From 38aa18053ec0e3be9a431effa6d43e4e6ea4cdf73c467e13104e8cb4ce87498a Mon Sep 17 00:00:00 2001 From: attiya <2413103649@qq.com> Date: Fri, 31 Oct 2025 10:07:37 +0800 Subject: [PATCH] =?UTF-8?q?gps=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EbikeEcuInfoController.java | 11 +++--- .../cdzy/operations/enums/CommandType.java | 9 +++++ .../operations/service/CommandService.java | 7 ++++ .../service/EbikeEcuInfoService.java | 21 ++++++++++-- .../service/impl/CommandServiceImpl.java | 26 ++++++++++---- .../service/impl/EbikeEcuInfoServiceImpl.java | 34 +++++++++++++------ .../cdzy/operations/utils/CommandUtil.java | 12 ++++--- 7 files changed, 91 insertions(+), 29 deletions(-) diff --git a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java index 7827d97..b4bdeb8 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeEcuInfoController.java @@ -9,6 +9,7 @@ import com.cdzy.operations.model.vo.EbikeEcuInfoVo; import com.cdzy.operations.service.EbikeEcuInfoService; import com.mybatisflex.core.paginate.Page; import jakarta.annotation.Resource; +import jakarta.validation.constraints.NotNull; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -132,7 +133,7 @@ public class EbikeEcuInfoController { * @return 执行结构 */ @GetMapping("checkSnOrBikeCode") - public JsonResult checkSnOrBikeCode(String ecuSn,String bikeCode) throws IOException { + public JsonResult checkSnOrBikeCode(String ecuSn,String bikeCode) { boolean result = ebikeEcuInfoService.checkSnOrBikeCode(ecuSn,bikeCode); return JsonResult.success(result); } @@ -151,13 +152,13 @@ public class EbikeEcuInfoController { /** - * 寻车铃 + * 执行命令 * * @return 执行结构 */ - @GetMapping("findBike") - public JsonResult findBike(String ecuSn,String bikeCode) { - boolean findBike = ebikeEcuInfoService.findBike(ecuSn,bikeCode); + @GetMapping("executeCommand") + public JsonResult executeCommand(String ecuSn,String bikeCode,@NotNull(message = "命令编码不能为空") String commandCode) { + boolean findBike = ebikeEcuInfoService.executeCommand(ecuSn,bikeCode,commandCode); return JsonResult.success(findBike); } 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 e047f57..4af0b75 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 @@ -5,5 +5,14 @@ package com.cdzy.operations.enums; * @since 2025-10-30 */ public interface CommandType { + + /** + * 寻车铃 + */ String FIND_BIKE = "FIND_BIKE"; + + /** + * GPS + */ + String GPS = "GPS"; } 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 4d7f865..cfc3d58 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 @@ -17,6 +17,13 @@ public interface CommandService{ */ boolean findBike(EbikeEcuInfo ebikeEcuInfo); + /** + * GPS定位上报 + * @param ebikeEcuInfo 中控信息 + * @return 执行结果 + */ + boolean gps(EbikeEcuInfo ebikeEcuInfo); + /** * 回调事件 * @param taskId 任务ID 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 3c1559c..7258fa2 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 @@ -45,11 +45,17 @@ public interface EbikeEcuInfoService extends IService { /** * 寻车铃命令 - * @param ecuSn 中控SN码 - * @param bikeCode 车辆编号 + * @param ebikeEcuInfo 中控信息 * @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 { * @return 结果 */ boolean checkSnOrBikeCode(String ecuSn, String bikeCode); + + /** + * 执行命令 + * @param ecuSn 中控SN码 + * @param bikeCode 车辆编号 + * @param commandCode 命令编码 + * @return 执行结果 + */ + boolean executeCommand(String ecuSn, String bikeCode, String commandCode); } 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 eafbe77..24f628b 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 @@ -36,7 +36,6 @@ public class CommandServiceImpl implements CommandService { @Override public boolean findBike(EbikeEcuInfo ebikeEcuInfo) { - boolean result = false; String taskId = createTaskId(); switch (ebikeEcuInfo.getEcuBrand()){ case EcuBrand.GUANG_HE_TONG: @@ -46,12 +45,27 @@ public class CommandServiceImpl implements CommandService { } catch (JsonProcessingException e) { throw new RuntimeException(e); } - result = submitTaskAndWait(topic, taskId,command); - break; + return submitTaskAndWait(topic, taskId,command); + 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 : throw new EbikeException("该品牌中控暂未接入"); } - return result; } @Override @@ -90,9 +104,7 @@ public class CommandServiceImpl implements CommandService { */ private void sendMessageToQueue(String topic, String taskData) { - executor.submit(() -> { - kafkaProducer.send(topic, taskData); - }); + executor.submit(() -> kafkaProducer.send(topic, taskData)); } /** 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 b9a34b1..d32e4e3 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 @@ -2,6 +2,7 @@ package com.cdzy.operations.service.impl; import cn.dev33.satoken.stp.StpUtil; import com.cdzy.common.ex.EbikeException; +import com.cdzy.operations.enums.CommandType; import com.cdzy.operations.mapper.EbikeBikeInfoMapper; import com.cdzy.operations.model.dto.EbikeEcuInOverview; import com.cdzy.operations.model.entity.EbikeBikeInfo; @@ -121,15 +122,13 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl findBike(ebikeEcuInfo); + case CommandType.GPS -> gps(ebikeEcuInfo); + default -> throw new EbikeException("该命令不存在/未接入"); + }; + } + private EbikeEcuInfo checkEcuSn(String ecuSn) { QueryWrapper queryWrapper = QueryWrapper.create() .where(EBIKE_ECU_INFO.ECU_SN.eq(ecuSn)); 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 5fd6a8f..fad3884 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 @@ -23,10 +23,14 @@ public class CommandUtil { switch (code) { case CommandType.FIND_BIKE: - String json = "{\"c\":14,\"tid\":\""+ taskId+"\",\"param\":{\"volume\":50,\"idx\":5}}"; - ObjectNode objectNode = mapper.readValue(json,ObjectNode.class); - objectNode.put("tid",taskId); - jsonNode.put("command",objectNode.toString()); + 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; default : throw new EbikeException("该命令暂未接入");