用户开锁

This commit is contained in:
attiya 2025-11-10 16:25:04 +08:00
parent fb118431ac
commit 4764f9aaa0
8 changed files with 137 additions and 44 deletions

View File

@ -99,4 +99,15 @@ public class EbikeBikeInfoController {
List<EbikeDto> 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();
}
}

View File

@ -11,4 +11,10 @@ import com.cdzy.operations.model.entity.EbikeRegion;
*/
public interface EbikeRegionMapper extends BaseMapper<EbikeRegion> {
/**
* 检查车辆是否在运营区内
* @param bikeCode 车辆编号
* @return 结果
*/
boolean checkBikeInRegion(String bikeCode);
}

View File

@ -67,4 +67,10 @@ public interface EbikeBikeInfoService extends IService<EbikeBikeInfo> {
* @return 车辆列表
*/
List<EbikeDto> userRadiusList(EbikeBikeRadiusVo radiusVo);
/**
* 用户开锁
* @param bikeCode 车辆编号
*/
void openLock(String bikeCode);
}

View File

@ -116,4 +116,12 @@ public interface EbikeEcuInfoService extends IService<EbikeEcuInfo> {
* @return 执行结果
*/
boolean executeCommand(String ecuSn, String bikeCode, String commandCode);
/**
* 根据车辆编号获取中控信息
* @param bikeCode 车辆编号
* @return 中控信息
*/
EbikeEcuInfo getEcu(String bikeCode);
}

View File

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

View File

@ -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<EbikeBikeInfoMapper, E
@Resource
EbikeInventoryRecordService recordService;
@Resource
private EbikeEcuInfoService ebikeEcuInfoService;
@Override
@Transactional
public void bind(EbikeBikeBindVo bindVo) {
@ -100,7 +104,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
if (!Objects.equals(batteryInfo.getOperatorId(), ecuInfo.getOperatorId()) && !Objects.equals(ecuInfo.getOperatorId(), ebikeBikeQr.getOperatorId()) && !Objects.equals(batteryInfo.getOperatorId(), ebikeBikeQr.getOperatorId())) {
throw new EbikeException("所选组件属于不同的运营商");
}
}else {
} else {
if (!Objects.equals(ecuInfo.getOperatorId(), ebikeBikeQr.getOperatorId())) {
throw new EbikeException("所选组件属于不同的运营商");
}
@ -157,7 +161,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
}
}else if (bindVo.getHasHelme()) {
} else if (bindVo.getHasHelme()) {
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(i)
@ -185,7 +189,7 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
.usageStatus(BikeUsageStatus.BIND)
.createdBy(StpUtil.getLoginIdAsLong())
.build();
if (batteryInfo != null){
if (batteryInfo != null) {
bikeInfo.setBatteryId(batteryInfo.getBatteryId());
}
this.mapper.insert(bikeInfo);
@ -203,21 +207,21 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
@Override
public Page<EbikeBikeInfoDto> 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<EbikeBikeInfoDto> 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<EbikeBikeInfoMapper, E
@Override
public List<EbikeDto> 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);
}
}

View File

@ -106,6 +106,7 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
EBIKE_ECU_INFO.OPERATOR_ID,
QueryMethods.count().as(EbikeEcuInOverview::getCount)
)
.where(EBIKE_ECU_INFO.IS_CLAIM.eq(Boolean.FALSE))
.from(EBIKE_ECU_INFO)
.groupBy(EBIKE_ECU_INFO.OPERATOR_ID);
return ebikeEcuInfoMapper.selectListByQueryAs(queryWrapper, EbikeEcuInOverview.class);
@ -216,7 +217,8 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
}
}
private EbikeEcuInfo getEcu(String bikeCode) {
@Override
public EbikeEcuInfo getEcu(String bikeCode) {
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_BIKE_INFO.BIKE_CODE.eq(bikeCode));
EbikeBikeInfo ebikeBikeInfo = bikeInfoMapper.selectOneByQuery(queryWrapper);

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cdzy.operations.mapper.EbikeRegionMapper">
<!-- 查询车辆是否在指定运营区内 -->
<select id="checkBikeInRegion" resultType="boolean">
SELECT
ST_Contains(
r.region_polygon::geometry,
ST_MakePoint((b.location[0])::float, (b.location[1])::float)::geometry
) as in_region
FROM
ebike_bike_info b
INNER JOIN
ebike_region r ON b.region_id = r.region_id
WHERE
b.bike_code = #{bikeCode}
</select>
</mapper>