package com.cdzy.operations.controller; import com.cdzy.common.model.dto.ResGPSDto; import com.cdzy.common.model.request.PageParam; import com.cdzy.common.model.response.JsonResult; import com.cdzy.operations.model.dto.EbikeBikeInfoDto; import com.cdzy.operations.model.dto.EbikeDto; import com.cdzy.operations.model.dto.EbikeUserBikeInfo; import com.cdzy.operations.model.dto.EbikeUserLockDto; import com.cdzy.operations.model.entity.EbikeBikeInfo; import com.cdzy.operations.model.vo.EbikeBatchLaunchVo; import com.cdzy.operations.model.vo.EbikeBatchUnLaunchVo; import com.cdzy.operations.model.vo.EbikeBikeBindVo; import com.cdzy.operations.model.vo.EbikeBikeRadiusVo; import com.cdzy.operations.service.EbikeBikeInfoService; import com.ebike.feign.model.vo.EbikeLockVo; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.update.UpdateChain; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.PrecisionModel; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; import static com.cdzy.operations.model.entity.table.EbikeBikeInfoTableDef.EBIKE_BIKE_INFO; import static com.cdzy.operations.model.entity.table.EbikeEcuInfoTableDef.EBIKE_ECU_INFO; /** * 车辆基本信息 控制层。 * * @author attiya * @since 2025-10-17 */ @Slf4j @Validated @RestController @RequestMapping("/ebikeBikeInfo") public class EbikeBikeInfoController { @Resource private EbikeBikeInfoService ebikeBikeInfoService; /** * 整车绑定 * * @param bindVo 绑定信息 * @return 绑定结果 */ @PostMapping("bind") public JsonResult bind(@Validated @RequestBody EbikeBikeBindVo bindVo) { ebikeBikeInfoService.bind(bindVo); return JsonResult.success(); } /** * 未上架车辆分页查询 * * @param pageParam 分页参数 * @return 结果 */ @GetMapping("unLaunchPage") public JsonResult unLaunchPage(PageParam pageParam) { Page page = ebikeBikeInfoService.unLaunchPage(pageParam); return JsonResult.success(page); } /** * 上架车辆分页查询 * * @param pageParam 分页参数 * @return 结果 */ @GetMapping("launchPage") public JsonResult launchPage(PageParam pageParam) { Page page = ebikeBikeInfoService.launchPage(pageParam); return JsonResult.success(page); } /** * 批量上架 * * @return 结果 */ @PostMapping("batchLaunch") public JsonResult batchLaunch(@Validated @RequestBody EbikeBatchLaunchVo launchVo) { ebikeBikeInfoService.batchLaunch(launchVo); return JsonResult.success(); } /** * 批量下架 * * @return 结果 */ @PostMapping("batchUnLaunch") public JsonResult batchUnLaunch(@Validated @RequestBody EbikeBatchUnLaunchVo launchVo) { ebikeBikeInfoService.batchUnLaunch(launchVo); return JsonResult.success(); } /** * 用户半径范围内车辆 * * @return 结果 */ @PostMapping("/api/userRadiusList") public JsonResult userRadiusList(@Validated @RequestBody EbikeBikeRadiusVo radiusVo) { 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(); } /** * 用户关锁 * * @return 结果 */ @PostMapping("/api/lock") public JsonResult lock(@RequestBody @Validated EbikeLockVo lockVo) { EbikeUserLockDto result = ebikeBikeInfoService.lock(lockVo); return JsonResult.success(result); } /** * 用户获取车辆详情 * * @return 结果 */ @GetMapping("/api/bikeInfo") public JsonResult bikeInfo(@RequestParam("bikeCode") String bikeCode) { EbikeUserBikeInfo info = ebikeBikeInfoService.bikeInfo(bikeCode); return JsonResult.success(info); } /** * 中控换绑 * * @param bikeCode 车辆编号 * @param ecuSn 中控编号 * @return 结果 */ @GetMapping("/changeEcu") public JsonResult changeEcu(@RequestParam("bikeCode") String bikeCode, @RequestParam("ecuSn") String ecuSn) { ebikeBikeInfoService.changeEcu(bikeCode, ecuSn); return JsonResult.success(); } /** * 根据中控编号获取设备信息 * * @param ecuSn 中控编号 * @return 结果 */ @GetMapping("/getEcuMsg") public JsonResult getEcuMsg(@RequestParam("ecuSn") String ecuSn) { ResGPSDto ecuMsg = ebikeBikeInfoService.getEcuMsg(ecuSn); return JsonResult.success(ecuMsg); } /** * 保存车辆最新位置 * * @param ecuSn 中控编号 * @return 结果 */ @GetMapping("/changeLocation") public JsonResult changeLocation(@RequestParam("ecuSn") String ecuSn, @RequestParam("longitude") Double longitude,@RequestParam("latitude") Double latitude) { QueryWrapper queryWrapper = QueryWrapper.create() .leftJoin(EBIKE_ECU_INFO).on(EBIKE_ECU_INFO.ECU_ID.eq(EBIKE_BIKE_INFO.ECU_ID)) .where(EBIKE_ECU_INFO.ECU_SN.eq(ecuSn)); EbikeBikeInfo bikeInfo = ebikeBikeInfoService.getOne(queryWrapper); if (bikeInfo == null) { log.warn("中控未绑定车辆或不存在,SN={}", ecuSn); return JsonResult.failed(); }else { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326); Point location = geometryFactory.createPoint(new Coordinate(longitude, latitude)); UpdateChain.of(EbikeBikeInfo.class) .set(EBIKE_BIKE_INFO.LOCATION,location) .where(EBIKE_BIKE_INFO.BIKE_INFO_ID.eq(bikeInfo.getBikeInfoId())) .update(); log.info("更新车辆位置成功,SN={}", ecuSn); } return JsonResult.success(); } }