18582019636
2024-06-25 ca497f8389174bb81e91f840cab70c9579bcdd29
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package com.ruoyi.worker.controller;
 
 
import com.ruoyi.admin.api.entity.ExchangeDispatch;
import com.ruoyi.admin.api.feignClient.AdminClient;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUserInfo;
import com.ruoyi.worker.entity.Evaluate;
import com.ruoyi.worker.entity.MasterWorker;
import com.ruoyi.worker.entity.Order;
import com.ruoyi.worker.entity.ServeRecord;
import com.ruoyi.worker.request.OrderSubmitRequest;
import com.ruoyi.worker.service.EvaluateService;
import com.ruoyi.worker.service.MasterWorkerService;
import com.ruoyi.worker.service.OrderService;
import com.ruoyi.worker.service.ServeRecordService;
import com.ruoyi.worker.vo.OrderDetailVO;
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 java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 订单管理 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-06-05
 */
@RestController
@RequestMapping("/master/order")
@Api(value = "师傅端", tags = "师傅端")
public class OrderController {
 
    @Resource
    private OrderService orderService;
    @Resource
    private TokenService tokenService;
    @Resource
    private AdminClient adminClient;
    @Resource
    private MasterWorkerService masterWorkerService;
    @Resource
    private ServeRecordService serveRecordService;
    @Resource
    private EvaluateService evaluateService;
 
    /**
     * 师傅端-获取订单列表
     *
     * @param state 订单状态(0:全部、1:待上门、2:已完结)
     */
    @ApiOperation(value = "订单列表", tags = {"师傅端-订单列表"})
    @GetMapping(value = "/orderList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单状态(0:全部、1:待上门、2:已完结)", name = "state", dataType = "Integer", required = true)
    })
    public R<List<Order>> orderList(@RequestParam Integer state) {
        LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
        if (null == loginWorker) {
            return R.loginExpire("登录失效!");
        }
        return R.ok(orderService.orderList(loginWorker.getUserid(), state));
    }
 
    /**
     * 师傅端-申请订单改派
     *
     * @param orderId 订单id
     */
    @ApiOperation(value = "申请订单改派", tags = {"师傅端-订单列表"})
    @GetMapping(value = "/applyChange")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "改派原因", name = "reason", dataType = "String", required = true)
    })
    public R<String> applyChange(@RequestParam Integer orderId, @RequestParam String reason) {
        LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
        if (null == loginWorker) {
            return R.loginExpire("登录失效!");
        }
        MasterWorker masterWorker = masterWorkerService.getById(loginWorker.getUserid());
        // 订单改派信息
        ExchangeDispatch exchangeDispatch = new ExchangeDispatch();
        exchangeDispatch.setWorkerId(masterWorker.getId());
        exchangeDispatch.setWorkerName(masterWorker.getRealName());
        exchangeDispatch.setApplyReason(reason);
        exchangeDispatch.setApplyTime(DateUtils.getNowDate());
        exchangeDispatch.setState(0);
        Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one();
        if (null == order) {
            throw new GlobalException("订单信息异常!");
        }
        exchangeDispatch.setOrderId(orderId);
        exchangeDispatch.setOrderNumber(order.getOrderNumber());
        exchangeDispatch.setUserId(order.getUserId());
        exchangeDispatch.setUserName(order.getReservationName());
        // 添加改派信息
        Boolean save = adminClient.changeDispatchSave(exchangeDispatch).getData();
        return save ? R.ok() : R.fail();
    }
 
    /**
     * 师傅端-已到达预约地点
     *
     * @param orderId 订单id
     */
    @ApiOperation(value = "订单路线导航", tags = {"师傅端-首页"})
    @GetMapping(value = "/orderNavigation")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "师傅所在经度", name = "longitude", dataType = "String", required = true),
            @ApiImplicitParam(value = "师傅所在纬度", name = "latitude", dataType = "String", required = true)
    })
    public R<Object> orderNavigation(@RequestParam Integer orderId, @RequestParam String longitude,
                                     @RequestParam String latitude) {
        LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
        if (null == loginWorker) {
            return R.loginExpire("登录失效!");
        }
        Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getServerId, loginWorker.getUserid())
                .eq(Order::getIsDelete, 0).one();
        if (null == order) {
            throw new GlobalException("请确认当前订单所派单师傅是否是您!");
        }
        // 用户下单经纬度
        Double userLongitude = order.getLongitude();
        Double userLatitude = order.getLatitude();
        String userPosition = userLongitude + "," + userLatitude;
        // 师傅当前位置 经纬度
        String workerPosition = longitude + "," + latitude;
        return R.ok(orderService.orderNavigation(userPosition, workerPosition));
    }
 
    /**
     * 师傅端-已到达预约地点
     *
     * @param orderId 订单id
     */
    @ApiOperation(value = "已到达预约地点", tags = {"师傅端-订单列表"})
    @GetMapping(value = "/reachPosition")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "orderId", name = "orderId", dataType = "Integer", required = true)
    })
    public R<Boolean> reachPosition(@RequestParam Integer orderId) {
        LoginUserInfo loginWorker = tokenService.getLoginUserByWorker();
        if (null == loginWorker) {
            return R.loginExpire("登录失效!");
        }
        Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getServerId, loginWorker.getUserid())
                .eq(Order::getIsDelete, 0).one();
        if (null == order) {
            throw new GlobalException("请确认当前订单所派单师傅是否是您!");
        }
        order.setState(Constants.THREE);
        return R.ok(orderService.updateById(order));
    }
 
    /**
     * 师傅端-订单详情
     *
     * @param orderId 订单id
     */
    @ApiOperation(value = "订单详情", tags = {"师傅端-订单列表"})
    @GetMapping(value = "/orderDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "orderId", name = "orderId", dataType = "Integer", required = true)
    })
    public R<OrderDetailVO> orderDetail(@RequestParam Integer orderId) {
        // 订单信息
        Order order = orderService.lambdaQuery().eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one();
        // 服务信息(服务备注、上门时间、完成时间、完成所拍现场照片)
        ServeRecord serveRecord = serveRecordService.lambdaQuery().eq(ServeRecord::getOrderId, orderId)
                .eq(ServeRecord::getIsDelete, 0).one();
        // 评价信息
        Evaluate evaluate = evaluateService.lambdaQuery().eq(Evaluate::getOrderId, orderId).eq(Evaluate::getIsDelete, 0).one();
        return R.ok(new OrderDetailVO(order, serveRecord, evaluate));
    }
 
    /**
     * 师傅端-订单详情
     *
     * @param orderSubmitRequest 提交订单信息
     */
    @ApiOperation(value = "订单完工-提交订单", tags = {"师傅端-订单列表"})
    @PostMapping(value = "/orderSubmit")
    public R<Boolean> orderSubmit(@RequestBody OrderSubmitRequest orderSubmitRequest) {
        // 订单信息
        Order order = orderService.lambdaQuery().eq(Order::getId, orderSubmitRequest.getOrderId())
                .eq(Order::getIsDelete, 0).one();
        // 订单不存在,或订单状态异常(订单状态为2才可提交)
        if (null == order || !Constants.TWO.equals(order.getState())) {
            throw new GlobalException("订单不存在或订单状态异常!");
        }
        order.setCompleteTime(new Date());
        order.setState(Constants.THREE);
        boolean update = orderService.updateById(order);
        // 服务记录
        ServeRecord serveRecord = new ServeRecord();
        serveRecord.setOrderId(order.getId());
        serveRecord.setPhoto(String.join(",", orderSubmitRequest.getPhoto()));
        boolean save = serveRecordService.save(serveRecord);
        return R.ok(update && save);
    }
 
}