18582019636
2024-06-26 f23efcba1bbbb84b603403711df00af138bdf3da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.ruoyi.admin.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.entity.Order;
import com.ruoyi.admin.request.OrderQueryRequest;
import com.ruoyi.admin.service.OrderService;
import com.ruoyi.admin.vo.OrderCountVO;
import com.ruoyi.admin.vo.OrderDetailVO;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.SnowflakeIdWorker;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 订单管理 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-05-29
 */
@RestController
@RequestMapping("/order")
@Api(tags = {"后台-订单管理"})
public class OrderController {
 
    @Resource
    private OrderService orderService;
    /**
     * 雪花算法类
     */
    private static final SnowflakeIdWorker SNOW_FLAKE_ID_WORKER = new SnowflakeIdWorker(5, 5);
 
    /**
     * 根据前台用户id查询所有订单信息
     *
     * @param phone 手机号
     */
    @ApiOperation(value = "查询用户所有订单", tags = {"后台-订单管理"})
    @GetMapping(value = "/queryList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号", name = "phone", dataType = "String", required = true)
    })
    public R<List<Order>> queryList(@RequestParam("phone") String phone) {
        return R.ok(orderService.lambdaQuery().eq(Order::getReservationPhone, phone).eq(Order::getIsDelete, 0).list());
    }
 
    /**
     * 订单列表-查询订单详情(包含服务信息、师傅信息、服务记录、订单评价)
     * 用户列表模块 点击订单记录点击详情 也是调用该接口
     * 订单评价管理 点击订单详情 也是调用该接口
     *
     * @param id 订单id
     */
    @ApiOperation(value = "订单列表-查询订单详情(包含服务信息、师傅信息、服务记录、订单评价)", tags = {"后台-订单管理"})
    @GetMapping(value = "/orderDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "id", dataType = "Integer", required = true)
    })
    public R<OrderDetailVO> detail(@RequestParam String id) {
        return R.ok(orderService.orderListDetail(id));
    }
 
    /**
     * 订单列表
     *
     * @param orderQueryRequest 订单列表查询参数
     */
    @ApiOperation(value = "订单列表-分页", tags = {"后台-订单管理"})
    @PostMapping(value = "/queryPage")
    public R<IPage<Order>> queryPage(@RequestBody OrderQueryRequest orderQueryRequest) {
        return R.ok(orderService.queryPage(orderQueryRequest));
    }
 
    /**
     * 站点详情
     *
     * @param id 站点id
     */
    @ApiOperation(value = "订单列表-订单详情", tags = {"后台-订单管理"})
    @GetMapping(value = "/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "站点id", name = "id", dataType = "Integer", required = true)
    })
    public R<Order> detail(@RequestParam Integer id) {
        return R.ok(orderService.getById(id));
    }
 
    /**
     * 新增订单
     * 后台订单与用户端及师傅端无关联
     *
     * @param order 站点信息
     */
    @ApiOperation(value = "订单列表-新增订单", tags = {"后台-订单管理"})
    @PostMapping(value = "/save")
    public R<String> save(@RequestBody Order order) {
        order.setType(Constants.ONE);
        order.setOrderNumber(String.valueOf(SNOW_FLAKE_ID_WORKER.nextId()));
        return orderService.save(order) ? R.ok() : R.fail();
    }
 
    /**
     * 根据id批量删除站点
     *
     * @param ids 站点多条id拼接
     */
    @ApiOperation(value = "订单列表-批量删除订单", tags = {"后台-订单管理"})
    @GetMapping(value = "/batchDelete")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "多个id ',' 拼接", name = "ids", dataType = "String", required = true)
    })
    public R<String> batchDelete(@RequestParam String ids) {
        List<String> idList = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        List<Order> list = orderService.lambdaQuery().in(Order::getId, idList).list();
        list.forEach(data -> data.setIsDelete(1));
        return orderService.updateBatchById(list) ? R.ok() : R.fail();
    }
 
    /**
     * 订单列表-excel导出
     *
     * @param idList 订单id
     */
    @ApiOperation(value = "订单列表-excel导出", tags = {"后台-订单管理"})
    @PostMapping(value = "/excelExport")
    public R<String> excelExport(@RequestBody List<String> idList, HttpServletResponse response) {
        return orderService.excelExport(idList, response);
    }
 
    /**
     * 订单列表-excel导出
     *
     * @param name  师傅姓名
     * @param phone 师傅电话
     */
    @ApiOperation(value = "订单统计", tags = {"后台-订单管理"})
    @GetMapping(value = "/orderCount")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "师傅姓名", name = "name", dataType = "String"),
            @ApiImplicitParam(value = "师傅电话", name = "phone", dataType = "String"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer",required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer",required = true)
    })
    public R<IPage<OrderCountVO>> orderCount(String name, String phone,
                                             @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(orderService.orderCount(name, phone, Page.of(pageNum, pageSize)));
    }
 
}