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();
|
}
|
}
|