diff --git a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBikeInfoController.java b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBikeInfoController.java index 5814e7c..f5ff4a5 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBikeInfoController.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/controller/EbikeBikeInfoController.java @@ -99,4 +99,15 @@ public class EbikeBikeInfoController { List list = ebikeBikeInfoService.userRadiusList(radiusVo); return JsonResult.success(list); } + + /** + * 用户开锁 + * + * @return 结果 + */ + @GetMapping("/api/openLock") + public JsonResult openLock(@RequestParam("bikeCode") String bikeCode) { + ebikeBikeInfoService.openLock(bikeCode); + return JsonResult.success(); + } } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/mapper/EbikeRegionMapper.java b/ebike-operations/src/main/java/com/cdzy/operations/mapper/EbikeRegionMapper.java index d669bb1..3966873 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/mapper/EbikeRegionMapper.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/mapper/EbikeRegionMapper.java @@ -11,4 +11,10 @@ import com.cdzy.operations.model.entity.EbikeRegion; */ public interface EbikeRegionMapper extends BaseMapper { + /** + * 检查车辆是否在运营区内 + * @param bikeCode 车辆编号 + * @return 结果 + */ + boolean checkBikeInRegion(String bikeCode); } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java b/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java index e97dd38..ca315a4 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/EbikeBikeInfoService.java @@ -67,4 +67,10 @@ public interface EbikeBikeInfoService extends IService { * @return 车辆列表 */ List userRadiusList(EbikeBikeRadiusVo radiusVo); + + /** + * 用户开锁 + * @param bikeCode 车辆编号 + */ + void openLock(String bikeCode); } 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 7466ad0..66c362a 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 @@ -116,4 +116,12 @@ public interface EbikeEcuInfoService extends IService { * @return 执行结果 */ boolean executeCommand(String ecuSn, String bikeCode, String commandCode); + + /** + * 根据车辆编号获取中控信息 + * @param bikeCode 车辆编号 + * @return 中控信息 + */ + EbikeEcuInfo getEcu(String bikeCode); + } 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 6b8669c..26fa959 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 @@ -37,16 +37,16 @@ public class CommandServiceImpl implements CommandService { @Override public boolean findBike(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.FIND_BIKE); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.FIND_BIKE); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -54,16 +54,16 @@ public class CommandServiceImpl implements CommandService { @Override public boolean gps(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.GPS); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.GPS); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -71,16 +71,16 @@ public class CommandServiceImpl implements CommandService { @Override public boolean openBatteryLock(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.OPEN_BATTERY_LOCK); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.OPEN_BATTERY_LOCK); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -88,16 +88,16 @@ public class CommandServiceImpl implements CommandService { @Override public boolean closeBatteryLock(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.CLOSE_BATTERY_LOCK); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.CLOSE_BATTERY_LOCK); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -105,16 +105,16 @@ public class CommandServiceImpl implements CommandService { @Override public boolean lock(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.LOCK); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.LOCK); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -122,38 +122,38 @@ public class CommandServiceImpl implements CommandService { @Override public boolean unLock(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.UNLOCK); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.UNLOCK); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @Override public void onComplete(String taskId, boolean success) { - completeRequest(taskId,success); + completeRequest(taskId, success); } @Override public boolean openHelmet(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.OPEN_HELMET); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.OPEN_HELMET); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -161,16 +161,16 @@ public class CommandServiceImpl implements CommandService { @Override public boolean powerOff(EbikeEcuInfo ebikeEcuInfo) { String taskId = createTaskId(); - switch (ebikeEcuInfo.getEcuBrand()){ + switch (ebikeEcuInfo.getEcuBrand()) { case EcuBrand.GUANG_HE_TONG: String command; try { - command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(),taskId, CommandType.POWER_OFF); + command = CommandUtil.guang_he_tong(ebikeEcuInfo.getEcuSn(), taskId, CommandType.POWER_OFF); } catch (JsonProcessingException e) { throw new RuntimeException(e); } - return submitTaskAndWait(topic, taskId,command); - default : + return submitTaskAndWait(topic, taskId, command); + default: throw new EbikeException("该品牌中控暂未接入"); } } @@ -197,7 +197,7 @@ public class CommandServiceImpl implements CommandService { } catch (Exception e) { pendingRequests.remove(taskId); log.info("任务提交失败: {}", e.getMessage()); - return false; + throw new EbikeException("超时未响应"); } } @@ -222,7 +222,7 @@ public class CommandServiceImpl implements CommandService { } } - String createTaskId(){ + String createTaskId() { return UUID.randomUUID().toString().replaceAll("-", ""); } diff --git a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java index 64ab5b3..8df1233 100644 --- a/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java +++ b/ebike-operations/src/main/java/com/cdzy/operations/service/impl/EbikeBikeInfoServiceImpl.java @@ -10,6 +10,7 @@ import com.cdzy.operations.model.dto.EbikeDto; import com.cdzy.operations.model.entity.*; import com.cdzy.operations.model.vo.*; import com.cdzy.operations.service.EbikeBikeInfoService; +import com.cdzy.operations.service.EbikeEcuInfoService; import com.cdzy.operations.service.EbikeInventoryRecordService; import com.cdzy.operations.service.EbikeInventoryService; import com.mybatisflex.core.paginate.Page; @@ -59,6 +60,9 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl launchPage(PageParam pageParam) { QueryWrapper query = QueryWrapper.create() - .select(EBIKE_BIKE_INFO.ALL_COLUMNS,EBIKE_REGION.REGION_NAME) + .select(EBIKE_BIKE_INFO.ALL_COLUMNS, EBIKE_REGION.REGION_NAME) .from(EBIKE_BIKE_INFO) .leftJoin(EBIKE_REGION).on(EBIKE_BIKE_INFO.REGION_ID.eq(EBIKE_REGION.REGION_ID)) .where(EBIKE_BIKE_INFO.STATUS.eq(BikeStatus.LAUNCH)); - return this.mapper.paginateAs(pageParam.getPage(),query, EbikeBikeInfoDto.class); + return this.mapper.paginateAs(pageParam.getPage(), query, EbikeBikeInfoDto.class); } @Override public Page unLaunchPage(PageParam pageParam) { QueryWrapper query = QueryWrapper.create() - .select(EBIKE_BIKE_INFO.ALL_COLUMNS,EBIKE_REGION.REGION_NAME) + .select(EBIKE_BIKE_INFO.ALL_COLUMNS, EBIKE_REGION.REGION_NAME) .from(EBIKE_BIKE_INFO) .leftJoin(EBIKE_REGION).on(EBIKE_BIKE_INFO.REGION_ID.eq(EBIKE_REGION.REGION_ID)) .where(EBIKE_BIKE_INFO.STATUS.eq(BikeStatus.UN_LAUNCH)); - return this.mapper.paginateAs(pageParam.getPage(),query, EbikeBikeInfoDto.class); + return this.mapper.paginateAs(pageParam.getPage(), query, EbikeBikeInfoDto.class); } @Override @@ -243,7 +247,41 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl userRadiusList(EbikeBikeRadiusVo radiusVo) { - return this.mapper.selectRadiusGeometryWithOrder(radiusVo.getPoint(),radiusVo.getRadius()*1000); + return this.mapper.selectRadiusGeometryWithOrder(radiusVo.getPoint(), radiusVo.getRadius() * 1000); + } + + @Override + public void openLock(String bikeCode) { + QueryWrapper query = QueryWrapper.create() + .where(EBIKE_BIKE_INFO.BIKE_CODE.eq(bikeCode)); + EbikeBikeInfo info = this.mapper.selectOneByQuery(query); + + //车辆状态检查 + if (info.getStatus() != BikeStatus.LAUNCH) { + throw new RuntimeException("车辆未上架,不可骑行"); + } + if (info.getUsageStatus() != BikeUsageStatus.WAIT) { + throw new RuntimeException("车辆已被占用或故障"); + } + + query.clear(); + query.where(EBIKE_REGION.REGION_ID.eq(info.getRegionId())); + EbikeRegion region = regionMapper.selectOneByQuery(query); + + //运营区是否运营中 + if (region == null || region.getStatus() != RegionStatus.OPERATION) { + throw new RuntimeException("该区暂停运营中"); + } + + //车辆是否在运营区内 + boolean result = regionMapper.checkBikeInRegion(bikeCode); + if (!result) { + throw new RuntimeException("该车辆在运营区外,暂不能骑行"); + } + EbikeEcuInfo ebikeEcuInfo = ebikeEcuInfoService.getEcu(bikeCode); + + ebikeEcuInfoService.unLock(ebikeEcuInfo); + } } 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 5dfb20e..bfe2a38 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 @@ -106,6 +106,7 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl + + + + + + + + \ No newline at end of file