6.5
luodangjia
2024-06-05 06c5eda038f967dc0c0261e16eff0ad1a18e41e7
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.common.constant.state.Order;
import com.stylefeng.guns.core.util.ToolUtil;
 
import com.stylefeng.guns.modular.system.dao.*;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
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.util.StringUtils;
import org.springframework.web.client.RestTemplate;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
 
 
@Service
public class OrderTransferServiceImpl extends ServiceImpl<OrderTransferMapper, OrderTransferCar> implements IOrderTransferService {
    @Autowired
    private IDispatchService dispatchService;
    @Autowired
    private IOrderCancelService orderCancelService;
 
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private ISystemNoticeService systemNoticeService;
    @Value("${pushMinistryOfTransport}")
    private boolean pushMinistryOfTransport;
    @Autowired
    private PushMinistryOfTransportUtil pushMinistryOfTransportUtil;
 
    @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 this.baseMapper.queryOrderList(search, orderSources, states, companyId, pageNum, size);
    }
 
    @Override
    public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception {
        return this.baseMapper.queryOrderInfo(orderId);
    }
 
    @Override
    public ResultUtil cancelOrder(Integer orderId) throws Exception {
        OrderTransferCar 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, 7, 10, 0);
                if(null != orderPrivateCar.getDriverId()){
                    //修改司机为空闲
                    Driver driver = driverService.selectById(orderPrivateCar.getDriverId());
                    driver.setState(2);
                    driverService.updateById(driver);
                    pushUtil.pushOrderState(2, orderPrivateCar.getDriverId(), orderId, 7, 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();
    }
 
}