ebike-plus/ebike-user/src/main/java/com/cdzy/user/controller/EbikeOrderController.java
2025-11-07 17:42:06 +08:00

176 lines
5.4 KiB
Java

package com.cdzy.user.controller;
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.entity.EbikeOrder;
import com.cdzy.user.service.EbikeOrderService;
import com.ebike.feign.clients.OperationsFeignClient;
import com.ebike.feign.model.dto.FeignEbikeDto;
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
import com.ebike.feign.model.vo.FeignEbikeBikeRadiusVo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
import static com.cdzy.user.model.entity.table.EbikeOrderTableDef.EBIKE_ORDER;
/**
* 用户订单 控制层
*
* @author: yanglei
* @since: 2025-10-15 17:15
*/
@RestController
@RequestMapping("/ebikeOrder")
public class EbikeOrderController {
@Resource
private EbikeOrderService ebikeOrderService;
@Resource
private OperationsFeignClient operationsFeignClient;
/**
* 开始骑行(生成订单、开锁)
*
* @param orderDto 骑行信息
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@PostMapping("saveRide")
public JsonResult<?> saveRide(@RequestBody @Validated EbikeUserCyclingDto orderDto) {
Long orderId = ebikeOrderService.saveRide(orderDto);
return JsonResult.success(orderId);
}
/**
* 查看用户是否有未完成订单。
*
* @param userId 用户id
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@GetMapping("checkHistoryOrder")
public JsonResult<?> checkHistoryOrder(@Validated @NotBlank(message = "用户id不能为空") @RequestParam("userId") Long userId) {
EbikeOrder userOrders = ebikeOrderService.checkHistoryOrder(userId);
return JsonResult.success(userOrders);
}
/**
* 订单支付。
*
* @param orderPaymentDto 支付信息
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@PostMapping("payment")
public JsonResult<?> payment(@RequestBody @Validated FeignOrderPaymentDto orderPaymentDto) {
ebikeOrderService.payment(orderPaymentDto);
return JsonResult.success();
}
/**
* 订单退款申请。
*
* @param orderId 订单ID
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@GetMapping("refundApply")
public JsonResult<?> refundApply(@RequestParam("orderId") Long orderId) {
ebikeOrderService.refundApply(orderId);
return JsonResult.success();
}
/**
* 订单退款。
*
* @param orderId 订单ID
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@GetMapping("refund")
public JsonResult<?> refund(@RequestParam("orderId") Long orderId) {
ebikeOrderService.refund(orderId);
return JsonResult.success();
}
/**
* 订单退款完成。
*
* @param orderId 订单ID
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@GetMapping("doneRefund")
public JsonResult<?> doneRefund(@RequestParam("orderId") Long orderId) {
ebikeOrderService.doneRefund(orderId);
return JsonResult.success();
}
/**
* 订单退款失败。
*
* @param orderId 订单ID
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@GetMapping("failRefund")
public JsonResult<?> failRefund(@RequestParam("orderId") Long orderId) {
ebikeOrderService.failRefund(orderId);
return JsonResult.success();
}
/**
* 订单退款驳回。
*
* @param orderId 订单ID
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@GetMapping("rejectRefund")
public JsonResult<?> rejectRefund(@RequestParam("orderId") Long orderId) {
ebikeOrderService.rejectRefund(orderId);
return JsonResult.success();
}
/**
* 根据用户订单表主键获取详细信。
*
* @param orderId 用户订单表主键
* @ 用户订单表详情
*/
@GetMapping("getInfo/{orderId}")
public JsonResult<?> getInfo(@PathVariable("orderId") Long orderId) {
EbikeOrder userOrder = ebikeOrderService.getById(orderId);
return JsonResult.success(userOrder);
}
/**
* 分页查询用户订单。
*
* @param pageParam 分页对象
* @ 分页对象
*/
@GetMapping("page")
public JsonResult<?> page(@Validated PageParam pageParam, @RequestParam(value = "bikeId", required = false) Long bikeId) {
QueryWrapper queryWrapper = QueryWrapper.create()
.from(EBIKE_ORDER)
.where(EBIKE_ORDER.BIKE_ID.eq(bikeId, Objects.nonNull(bikeId)));
Page<EbikeOrder> page = ebikeOrderService.page(pageParam.getPage(), queryWrapper);
return JsonResult.success(page);
}
/**
* 车辆列表
*
* @param feignEbikeBikeRadiusVo 坐标信息
* @ {@code 200} 添加成功,{@code 500} 添加失败
*/
@PostMapping("bikeList")
public JsonResult<?> bikeList(@RequestBody @Validated FeignEbikeBikeRadiusVo feignEbikeBikeRadiusVo) {
List<FeignEbikeDto> result = ebikeOrderService.userRadiusList(feignEbikeBikeRadiusVo);
return JsonResult.success(result);
}
}