puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.OrderCrossCityMapper;
import com.stylefeng.guns.modular.system.dao.OrderPrivateCarMapper;
import com.stylefeng.guns.modular.system.model.Dispatch;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.model.OrderCancel;
import com.stylefeng.guns.modular.system.model.OrderPrivateCar;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
 
 
@Service
public class OrderPrivateCarServiceImpl extends ServiceImpl<OrderPrivateCarMapper, OrderPrivateCar> implements IOrderPrivateCarService {
 
    @Resource
    private OrderPrivateCarMapper orderPrivateCarMapper;
 
    @Autowired
    private IDispatchService dispatchService;
 
    @Autowired
    private IOrderCancelService orderCancelService;
 
    @Autowired
    private PushMinistryOfTransportUtil pushMinistryOfTransportUtil;
 
    @Autowired
    private PushUtil pushUtil;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
 
    @Value("${callbackPath}")
    private String callbackPath;
 
    @Value("${pushMinistryOfTransport}")
    private boolean pushMinistryOfTransport;
 
 
    /**
     * 获取订单列表
     * @param search
     * @param orderSource
     * @param state
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryOrderList(String search, String orderSource, String state, Integer pageNum, Integer size, Integer uid) throws Exception {
        Dispatch dispatch = dispatchService.selectById(uid);
        Integer companyId = null != dispatch.getFranchiseeId() ? dispatch.getFranchiseeId() : dispatch.getCompanyId();
        pageNum = (pageNum - 1) * size;
        List<String> orderSources = null;
        if(ToolUtil.isNotEmpty(orderSource)){
            orderSources = Arrays.asList(orderSource.split(","));
        }
        List<String> states = null;
        if(ToolUtil.isNotEmpty(state)){
            states = Arrays.asList(state.split(","));
        }
        return orderPrivateCarMapper.queryOrderList(search, orderSources, states, companyId, pageNum, size);
    }
 
 
    /**
     * 获取订单详情
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception {
        return orderPrivateCarMapper.queryOrderInfo(orderId);
    }
 
 
    /**
     * 取消订单
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil cancelOrder(Integer orderId) throws Exception {
        OrderPrivateCar orderPrivateCar = this.selectById(orderId);
        if(orderPrivateCar.getState() == 10 || orderPrivateCar.getState() == 12){
            return ResultUtil.error("不允许重复取消");
        }
        if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){
            return ResultUtil.error("订单已完成,不允许取消");
        }
        orderPrivateCar.setState(10);
        this.updateById(orderPrivateCar);
 
        //添加取消记录
        OrderCancel orderCancel = new OrderCancel();
        orderCancel.setOrderId(orderId);
        orderCancel.setOrderType(1);
        orderCancel.setReason("调度端取消");
        orderCancel.setRemark("调度端取消");
        orderCancel.setState(2);
        orderCancel.setInsertTime(new Date());
        orderCancel.setUserType(2);
        orderCancelService.insert(orderCancel);
 
        new Thread(new Runnable() {//发送消息提醒
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderPrivateCar.getUserId(), orderId, 1, 10, 0);
                if(null != orderPrivateCar.getDriverId()){
                    //修改司机为空闲
                    Driver driver = driverService.selectById(orderPrivateCar.getDriverId());
                    driver.setState(2);
                    driverService.updateById(driver);
                    pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderId, 1, 10, 0);
                }
            }
        }).start();
        //添加消息
        systemNoticeService.addSystemNotice(1, "调度已成功取消出行订单,谢谢使用!", orderPrivateCar.getUserId(), 1);
 
        new Thread(new Runnable() {
            @Override
            public void run() {
                if(pushMinistryOfTransport){//上传数据
                    pushMinistryOfTransportUtil.orderCancel(orderId);
                }
            }
        }).start();
 
        return ResultUtil.success();
    }
}