electripper-v2/ruoyi-web/src/main/java/com/ruoyi/web/app/AppOrderController.java

163 lines
7.2 KiB
Java
Raw Normal View History

2025-03-25 18:03:57 +08:00
package com.ruoyi.web.app;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
2025-03-27 18:03:33 +08:00
import org.springframework.web.bind.annotation.PutMapping;
2025-03-26 18:05:24 +08:00
import org.springframework.web.bind.annotation.RequestBody;
2025-03-25 18:03:57 +08:00
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.OrderVO;
2025-04-22 12:00:46 +08:00
import com.ruoyi.bst.order.domain.dto.OrderCalcFeeDTO;
2025-03-25 18:03:57 +08:00
import com.ruoyi.bst.order.domain.dto.OrderCalcPrePriceDTO;
2025-04-02 17:24:20 +08:00
import com.ruoyi.bst.order.domain.dto.OrderChangeDeviceDTO;
2025-04-11 18:08:08 +08:00
import com.ruoyi.bst.order.domain.dto.OrderCloseDeviceDTO;
2025-03-25 18:03:57 +08:00
import com.ruoyi.bst.order.domain.dto.OrderCreateDTO;
import com.ruoyi.bst.order.domain.dto.OrderEndDTO;
2025-05-13 11:13:58 +08:00
import com.ruoyi.bst.order.domain.dto.OrderOpenDeviceDTO;
2025-04-16 15:00:52 +08:00
import com.ruoyi.bst.order.domain.enums.OrderReturnType;
import com.ruoyi.bst.order.domain.enums.OrderStatus;
2025-04-15 18:16:16 +08:00
import com.ruoyi.bst.order.domain.vo.OrderEndVO;
2025-04-01 21:30:47 +08:00
import com.ruoyi.bst.order.domain.vo.OrderFeeVO;
2025-03-25 18:03:57 +08:00
import com.ruoyi.bst.order.domain.vo.OrderPrePriceVO;
import com.ruoyi.bst.order.service.OrderConverter;
import com.ruoyi.bst.order.service.OrderService;
2025-03-26 18:05:24 +08:00
import com.ruoyi.bst.order.service.OrderValidator;
2025-04-22 12:00:46 +08:00
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
2025-03-25 18:03:57 +08:00
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
2025-04-22 12:00:46 +08:00
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;
2025-03-26 18:05:24 +08:00
import com.ruoyi.common.utils.ServiceUtil;
2025-03-25 18:03:57 +08:00
import io.swagger.annotations.ApiOperation;
@RestController
@RequestMapping("/app/order")
public class AppOrderController extends BaseController {
@Autowired
private OrderService orderService;
@Autowired
private OrderConverter orderConverter;
2025-03-26 18:05:24 +08:00
@Autowired
private OrderValidator orderValidator;
2025-03-25 18:03:57 +08:00
@ApiOperation("获取我的订单列表")
@GetMapping("/mineList")
public TableDataInfo getMineList(OrderQuery query) {
query.setUserId(getUserId());
startPage();
List<OrderVO> list = orderService.selectOrderList(query);
return getDataTable(list);
}
@ApiOperation("获取我的订单详情")
@GetMapping("/mineDetail")
public AjaxResult getMineDetail(Long id) {
OrderQuery query = new OrderQuery();
query.setId(id);
query.setUserId(getUserId());
return success(orderService.selectOne(query));
}
@ApiOperation("获取我正在进行的订单")
@GetMapping("/mineProcessing")
public AjaxResult getMineProcessing() {
OrderQuery query = new OrderQuery();
query.setUserId(getUserId());
query.setStatus(OrderStatus.PROCESSING.getCode());
return success(orderService.selectOne(query));
}
2025-03-25 18:03:57 +08:00
@ApiOperation("支付前计算订单价格")
2025-03-27 18:03:33 +08:00
@PostMapping("/calculatePrice")
2025-04-22 12:00:46 +08:00
@Log(title = "支付前计算订单价格", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.SUIT)
2025-04-16 15:00:52 +08:00
@Anonymous
2025-03-25 18:03:57 +08:00
public AjaxResult calculatePrice(@RequestBody @Validated OrderCalcPrePriceDTO dto) {
OrderPrePriceVO vo = orderConverter.toOrderPrePriceVO(dto);
if (vo == null) {
return error("计算价格失败,请检查");
}
return success(vo);
}
2025-04-10 16:46:29 +08:00
@ApiOperation("下单并支付")
2025-03-25 18:03:57 +08:00
@PostMapping
2025-04-22 12:00:46 +08:00
@Log(title = "下单并支付", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.SUIT)
2025-03-25 18:03:57 +08:00
public AjaxResult createOrder(@RequestBody @Validated OrderCreateDTO dto) {
dto.setUserId(getUserId());
return success(orderService.createOrder(dto));
}
2025-03-26 18:05:24 +08:00
2025-05-13 11:13:58 +08:00
@ApiOperation("结束订单(还车)")
2025-03-27 18:03:33 +08:00
@PutMapping("/end")
2025-05-13 11:13:58 +08:00
@Log(title = "结束订单(还车)", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
public AjaxResult endOrder(@RequestBody @Validated OrderEndDTO dto) {
OrderVO order = orderService.selectOrderById(dto.getOrderId());
2025-03-27 18:03:33 +08:00
ServiceUtil.assertion(!orderValidator.canEnd(order, getUserId()), "您无权结束ID为%s的订单", order.getId());
2025-04-16 15:00:52 +08:00
dto.setReturnType(OrderReturnType.NORMAL.getCode());
2025-03-29 18:06:55 +08:00
dto.setEndReason("用户【" + getNickName() + "】手动还车");
2025-04-14 18:07:16 +08:00
OrderEndVO vo = orderService.endOrder(dto);
if (vo.getDb() > 0) {
return success(vo);
}
return error("关闭订单失败");
}
@ApiOperation("计算订单费用")
@PostMapping("/calcFee")
2025-04-22 12:00:46 +08:00
@Log(title = "计算订单费用", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
public AjaxResult calcFee(@RequestBody @Validated OrderCalcFeeDTO dto) {
2025-04-16 15:00:52 +08:00
OrderFeeVO fee = orderService.calcFee(dto);
2025-03-29 18:06:55 +08:00
ServiceUtil.assertion(fee == null, "价格计算失败");
return success(fee);
}
2025-05-12 17:55:20 +08:00
@ApiOperation("订单开锁")
2025-03-29 18:06:55 +08:00
@PutMapping("/openDevice")
2025-05-12 17:55:20 +08:00
@Log(title = "订单开锁", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
2025-05-13 11:13:58 +08:00
public AjaxResult openDevice(@Validated OrderOpenDeviceDTO dto) {
OrderVO order = orderService.selectOrderById(dto.getOrderId());
2025-03-29 18:06:55 +08:00
ServiceUtil.assertion(order == null, "订单不存在");
ServiceUtil.assertion(!orderValidator.canOpenDevice(order, getUserId()), "您无权操作ID为%s的订单设备开启", order.getId());
2025-04-30 10:38:36 +08:00
ServiceUtil.assertion(orderValidator.isTimeout(order), "当前订单已超时,请在安全的区域还车");
2025-05-13 11:13:58 +08:00
dto.setRequiredIot(true);
return success(orderService.openDevice(dto));
2025-03-29 18:06:55 +08:00
}
2025-05-12 17:55:20 +08:00
@ApiOperation("临时锁车")
2025-03-29 18:06:55 +08:00
@PutMapping("/closeDevice")
2025-05-12 17:55:20 +08:00
@Log(title = "临时锁车", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
2025-04-12 16:15:50 +08:00
public AjaxResult closeDevice(@Validated OrderCloseDeviceDTO dto) {
2025-04-11 18:08:08 +08:00
OrderVO order = orderService.selectOrderById(dto.getOrderId());
2025-03-29 18:06:55 +08:00
ServiceUtil.assertion(order == null, "订单不存在");
ServiceUtil.assertion(!orderValidator.canCloseDevice(order, getUserId()), "您无权操作ID为%s的订单设备关闭", order.getId());
2025-04-30 10:38:36 +08:00
ServiceUtil.assertion(orderValidator.isTimeout(order), "当前订单已超时,请在安全的区域还车");
2025-04-11 18:08:08 +08:00
dto.setRequiredIot(true);
2025-04-14 18:07:16 +08:00
return success(orderService.closeDevice(dto));
2025-03-27 18:03:33 +08:00
}
2025-05-12 17:55:20 +08:00
@ApiOperation("换车")
2025-04-02 17:24:20 +08:00
@PutMapping("/changeDevice")
2025-05-12 17:55:20 +08:00
@Log(title = "换车", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.ORDER)
2025-04-02 17:24:20 +08:00
public AjaxResult changeDevice(@RequestBody @Validated OrderChangeDeviceDTO dto) {
OrderVO order = orderService.selectOrderById(dto.getOrderId());
ServiceUtil.assertion(!orderValidator.canChangeDevice(order, getUserId()), "您无权操作ID为%s的订单换车", order.getId());
2025-04-30 10:38:36 +08:00
ServiceUtil.assertion(orderValidator.isTimeout(order), "当前订单已超时,请在安全的区域还车");
2025-04-02 17:24:20 +08:00
dto.setUserId(getUserId());
dto.setUserName(getNickName());
return toAjax(orderService.changeDevice(dto));
}
2025-03-25 18:03:57 +08:00
}