| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package com.ruoyi.app.unifiedorder;
- import com.ruoyi.common.annotation.Anonymous;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.utils.MessageUtils;
- import com.ruoyi.system.utils.Auth;
- import com.ruoyi.system.utils.JwtUtil;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestHeader;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- /** 用户端统一订单列表接口:外卖与闪送合并,tab 归类、来源筛选、游标滚动分页。 */
- @RestController
- @RequestMapping("/system/unifiedOrder")
- public class UnifiedOrderQueryController extends BaseController {
- private final UnifiedOrderQueryService service;
- public UnifiedOrderQueryController(UnifiedOrderQueryService service) {
- this.service = service;
- }
- /**
- * 统一订单列表。
- *
- * @param token 登录令牌
- * @param tab 归类 tab:all/unpaid/active/completed/cancelled/refund,默认 all
- * @param source 来源筛选:all/takeaway/dinein/pickup/flash,默认 all;takeaway 仅外送单,dinein=堂食,pickup=自取
- * @param cursor 上一页返回的游标,首页不传
- * @param size 每页条数,默认 10,服务端钳制 1-50
- */
- @GetMapping("/list")
- @Auth
- @Anonymous
- public AjaxResult list(@RequestHeader String token,
- @RequestParam(defaultValue = "all") String tab,
- @RequestParam(defaultValue = "all") String source,
- @RequestParam(required = false) String cursor,
- @RequestParam(defaultValue = "10") int size) {
- UnifiedOrderTab parsedTab = UnifiedOrderTab.fromCode(tab);
- if (parsedTab == null) {
- return error(MessageUtils.message("no.unifiedorder.param.invalid"));
- }
- OrderSource parsedSource = null;
- if (source != null && !source.isBlank() && !"all".equals(source)) {
- parsedSource = OrderSource.fromCode(source);
- if (parsedSource == null) {
- return error(MessageUtils.message("no.unifiedorder.param.invalid"));
- }
- }
- UnifiedCursor parsedCursor = null;
- if (cursor != null && !cursor.isBlank()) {
- try {
- parsedCursor = UnifiedCursor.parse(cursor);
- } catch (IllegalArgumentException e) {
- return error(MessageUtils.message("no.unifiedorder.cursor.invalid"));
- }
- }
- String userId = new JwtUtil().getusid(token);
- if (userId == null || userId.isBlank()) {
- return error(MessageUtils.message("no.unifiedorder.param.invalid"));
- }
- Long parsedUserId;
- try {
- parsedUserId = Long.valueOf(userId);
- } catch (NumberFormatException e) {
- return error(MessageUtils.message("no.unifiedorder.param.invalid"));
- }
- return success(service.query(parsedUserId, parsedTab, parsedSource, parsedCursor, size));
- }
- }
|