package com.cdzy.user.controller; import com.cdzy.common.enums.Code; import com.cdzy.common.ex.EbikeException; import com.cdzy.common.model.request.PageParam; import com.cdzy.common.model.response.JsonResult; import com.cdzy.user.model.dto.EbikeUserCyclingDto; import com.cdzy.user.model.dto.EbikeUserCyclingEndDto; import com.cdzy.user.model.entity.EbikeOrder; import com.cdzy.user.model.vo.EbikeBikeInfoVo; import com.cdzy.user.model.vo.EbikeOrderDetailVo; import com.cdzy.user.model.vo.EbikeRevenueStatisticsVo; import com.cdzy.user.model.vo.EbikeUserAllOrdersVo; import com.cdzy.user.service.EbikeOrderService; import com.ebike.feign.clients.PaymentFeignClient; import com.ebike.feign.model.dto.FeignEbikeDto; import com.ebike.feign.model.dto.FeignEbikeOrderStatisticsDto; import com.ebike.feign.model.vo.FeignEbikeBikeRadiusVo; import com.ebike.feign.model.vo.FeignEbikeOrderStatisticsVo; import com.ebike.feign.model.vo.FeignEbikeWxHandleNotifyVo; 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.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * 用户订单 控制层 * * @author yanglei * @since 2025-10-15 17:15 */ @RestController @RequestMapping("/ebikeOrder") public class EbikeOrderController { @Resource private EbikeOrderService ebikeOrderService; @Resource private PaymentFeignClient paymentFeignClient; /** * 车辆列表 * * @param feignEbikeBikeRadiusVo 坐标信息 */ @PostMapping("bikeList") public JsonResult bikeList(@RequestBody @Validated FeignEbikeBikeRadiusVo feignEbikeBikeRadiusVo) { List result = ebikeOrderService.userRadiusList(feignEbikeBikeRadiusVo); return JsonResult.success(result); } /** * 获取车辆基本信息 * * @param bikeCode 车辆编码 */ @GetMapping("queryBikeInfo") public JsonResult queryBikeInfo(@RequestParam("bikeCode") String bikeCode) { EbikeBikeInfoVo result = ebikeOrderService.queryBikeInfo(bikeCode); return JsonResult.success(result); } /** * 开始骑行(生成订单、开锁) * * @param orderDto 骑行信息 (返回订单开始时间、开始点位) */ @PostMapping("saveRide") public JsonResult saveRide(@RequestBody @Validated EbikeUserCyclingDto orderDto) { EbikeOrder result = ebikeOrderService.saveRide(orderDto); return JsonResult.success(result); } /** * 查看用户是否有未完成订单。 * * @param userId 用户id */ @GetMapping("checkHistoryOrder") public JsonResult checkHistoryOrder(@Validated @NotNull(message = "用户id不能为空") @RequestParam("userId") Long userId) { EbikeOrder userOrders = ebikeOrderService.checkHistoryOrder(userId); return JsonResult.success(userOrders); } /** * 完成骑行(关锁还车)。 * * @param endDto 骑行信息 */ @PostMapping("doneRide") public JsonResult doneRide(@RequestBody @Validated EbikeUserCyclingEndDto endDto) { Long orderId = ebikeOrderService.doneRide(endDto); return JsonResult.success(orderId); } /** * 根据用户订单表主键获取详细信。 * * @param orderId 用户订单表主键 */ @GetMapping("getInfo") public JsonResult getInfo(@RequestParam("orderId") Long orderId) { EbikeOrderDetailVo userOrder = ebikeOrderService.getInfo(orderId); return JsonResult.success(userOrder); } /** * 根据用户订单表主键获取订单状态。 * * @param orderId 用户订单表主键 */ @GetMapping("getOrderStatus") public JsonResult getOrderStatus(@RequestParam("orderId") Long orderId) { Integer orderStatus = ebikeOrderService.getOrderStatus(orderId); return JsonResult.success(orderStatus); } /** * 根据用户id获取用户所有订单。 * * @param userId 用户订单表主键 */ @GetMapping("getUserAllOrder") public JsonResult getUserAllOrder(Long userId, Integer orderStatus, PageParam page) { Page userAllOrders = ebikeOrderService.getUserAllOrder(userId, orderStatus, page); return JsonResult.success(userAllOrders); } /** * 查询营收统计。 */ @GetMapping("getRevenueStatistics") public JsonResult getRevenueStatistics() { List revenueStatistics = ebikeOrderService.getRevenueStatistics(); return JsonResult.success(revenueStatistics); } /** * 通过商户(骑行)订单订单号查询支付订单状态 * * @param orderId 订单id */ @GetMapping("queryOrderStatus") public JsonResult queryOrderStatusById(@RequestParam("orderId") Long orderId) { JsonResult jsonResult = paymentFeignClient.queryOrderStatusById(orderId); if (jsonResult.getCode() != Code.SUCCESS) { throw new EbikeException(jsonResult.getMessage()); } return JsonResult.success(jsonResult.getData()); } /** * 查询不同运营商的订单数据及订单金额 * * @param dto 订单请求参数 * @return 订单数据及订单金额 */ @PostMapping("/api/getOrderStatistics") public JsonResult getOrderStatistics(@RequestBody @Validated FeignEbikeOrderStatisticsDto dto) { List result = ebikeOrderService.getOrderStatistics(dto); return JsonResult.success(result); } }