electripper-v2/ruoyi-web/src/main/java/com/ruoyi/web/bst/OrderController.java

143 lines
4.7 KiB
Java
Raw Normal View History

2025-03-24 18:05:02 +08:00
package com.ruoyi.web.bst;
2025-04-02 21:02:17 +08:00
import java.util.Collections;
2025-03-24 18:05:02 +08:00
import java.util.List;
import javax.servlet.http.HttpServletResponse;
2025-04-14 18:07:16 +08:00
import com.ruoyi.bst.order.domain.vo.OrderEndVO;
2025-03-24 18:05:02 +08:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
2025-03-29 18:06:55 +08:00
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
2025-04-02 21:02:17 +08:00
import org.springframework.web.bind.annotation.RequestParam;
2025-03-29 18:06:55 +08:00
import org.springframework.web.bind.annotation.RestController;
2025-03-24 18:05:02 +08:00
import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.OrderVO;
import com.ruoyi.bst.order.domain.dto.OrderEndDTO;
2025-03-29 18:06:55 +08:00
import com.ruoyi.bst.order.domain.dto.OrderRefundDTO;
2025-04-02 21:02:17 +08:00
import com.ruoyi.bst.order.domain.dto.OrderVerifyDTO;
import com.ruoyi.bst.order.service.OrderAssembler;
2025-03-25 18:03:57 +08:00
import com.ruoyi.bst.order.service.OrderService;
2025-03-24 18:05:02 +08:00
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServiceUtil;
2025-03-24 18:05:02 +08:00
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
* 订单Controller
*
* @author ruoyi
* @date 2025-03-24
*/
@RestController
@RequestMapping("/bst/order")
public class OrderController extends BaseController
{
@Autowired
2025-03-25 18:03:57 +08:00
private OrderService orderService;
2025-03-24 18:05:02 +08:00
2025-04-02 21:02:17 +08:00
@Autowired
private OrderAssembler orderAssembler;
2025-03-24 18:05:02 +08:00
/**
* 查询订单列表
*/
@PreAuthorize("@ss.hasPermi('bst:order:list')")
@GetMapping("/list")
public TableDataInfo list(OrderQuery query)
{
startPage();
startOrderBy();
query.setScope(true);
List<OrderVO> list = orderService.selectOrderList(query);
2025-04-02 21:02:17 +08:00
orderAssembler.assembleOrderDeviceList(list);
2025-03-24 18:05:02 +08:00
return getDataTable(list);
}
/**
* 导出订单列表
*/
@PreAuthorize("@ss.hasPermi('bst:order:export')")
@Log(title = "订单", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, OrderQuery query)
{
query.setScope(true);
List<OrderVO> list = orderService.selectOrderList(query);
ExcelUtil<OrderVO> util = new ExcelUtil<OrderVO>(OrderVO.class);
util.exportExcel(response, list, "订单数据");
}
/**
* 获取订单详细信息
*/
@PreAuthorize("@ss.hasPermi('bst:order:query')")
@GetMapping(value = "/{id}")
2025-04-10 14:06:52 +08:00
public AjaxResult getInfo(@PathVariable("id") Long id,
2025-04-02 21:02:17 +08:00
@RequestParam(required = false, defaultValue = "false") Boolean assembleOrderDeviceList)
2025-03-24 18:05:02 +08:00
{
2025-04-02 21:02:17 +08:00
OrderVO order = orderService.selectOrderById(id, true);
if (assembleOrderDeviceList) {
orderAssembler.assembleOrderDeviceList(Collections.singletonList(order));
}
return success(order);
2025-03-24 18:05:02 +08:00
}
/**
* 结束订单辅助还车
*/
@PreAuthorize("@ss.hasPermi('bst:order:end')")
@PutMapping("/end")
public AjaxResult end(@RequestBody @Validated OrderEndDTO dto) {
OrderVO order = orderService.selectOrderById(dto.getOrderId(), true);
ServiceUtil.assertion(order == null, "订单不存在");
2025-04-10 14:06:52 +08:00
dto.setIsAdmin(true);
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("订单关闭失败");
}
2025-03-29 18:06:55 +08:00
/**
* 退款
*/
@PreAuthorize("@ss.hasPermi('bst:order:refund')")
@PutMapping("/refund")
public AjaxResult refund(@RequestBody @Validated OrderRefundDTO dto) {
// 查询订单
OrderVO order = orderService.selectOrderById(dto.getOrderId(), true);
ServiceUtil.assertion(order == null, "订单不存在");
// 退款
dto.setUserId(getUserId());
dto.setUserName(getNickName());
return toAjax(orderService.refund(dto));
}
2025-04-02 21:02:17 +08:00
/**
* 还车审核
*/
@PreAuthorize("@ss.hasPermi('bst:order:verify')")
@PutMapping("/verify")
public AjaxResult verify(@RequestBody @Validated OrderVerifyDTO dto) {
// 查询订单
OrderVO order = orderService.selectOrderById(dto.getId(), true);
ServiceUtil.assertion(order == null, "订单不存在");
return toAjax(orderService.verify(dto));
}
2025-03-24 18:05:02 +08:00
}