package com.stylefeng.guns.modular.api;
|
|
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
//import com.stylefeng.guns.modular.system.util.ICBCPayUtil;
|
import com.stylefeng.guns.modular.system.util.PayMoneyUtil;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import com.stylefeng.guns.modular.system.util.SystemException;
|
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
|
import com.stylefeng.guns.modular.system.warpper.OrderCrossCityWarpper;
|
import com.stylefeng.guns.modular.system.warpper.OrderInfoWarpper;
|
import com.stylefeng.guns.modular.system.warpper.OrderListWarpper;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 订单相关
|
*/
|
@Api
|
@RestController
|
@RequestMapping("")
|
public class OrderController {
|
|
@Autowired
|
private IOrderCrossCityService orderCrossCityService;
|
|
@Autowired
|
private IOrderPrivateCarService orderPrivateCarService;
|
|
@Autowired
|
private IDispatchService dispatchService;
|
|
@Autowired
|
private IOrderPositionService orderPositionService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
@Autowired
|
private IReassignService reassignService;
|
|
|
// @Autowired
|
// private ICBCPayUtil icbcPayUtil;
|
|
@Autowired
|
private IOrderTransferService orderTransferService;
|
/**
|
* 获取订单列表
|
* @param type
|
* @param search
|
* @param orderSource
|
* @param state
|
* @param lineId
|
* @param pageNum
|
* @param size
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/order/queryOrderList")
|
@ApiOperation(value = "获取订单列表", tags = {"调度端-订单管理"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "数据类型(1=专车,2=跨城)", name = "type", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "搜索条件", name = "search", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "订单来源(1:APP下单,2:扫码下单,3:小程序下单,4:司机下单,5:调度下单)多个以逗号分隔", name = "orderSource", required = false, dataType = "string"),
|
@ApiImplicitParam(value = "订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中,12=取消待支付)多个以逗号分隔", name = "state", required = false, dataType = "string"),
|
@ApiImplicitParam(value = "线路id(多个以逗号分隔)", name = "lineId", required = false, dataType = "string"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<List<OrderListWarpper>> queryOrderList(Integer type, String search, String orderSource, String state, String lineId, Integer pageNum, Integer size, HttpServletRequest request){
|
try {
|
Integer uid = dispatchService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
List<Map<String, Object>> list = null;
|
if(type == 1){//专车
|
list = orderPrivateCarService.queryOrderList(search, orderSource, state, pageNum, size, uid);
|
}
|
if(type == 2){//跨城
|
list = orderCrossCityService.queryOrderList(search, orderSource, state, lineId, pageNum, size, uid);
|
}
|
|
if(type ==7){//接送机
|
list = orderTransferService.queryOrderList(search, orderSource, state, pageNum, size, uid);
|
}
|
|
return ResultUtil.success(OrderListWarpper.getOrderListWarppers(list));
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 获取订单详情
|
* @param orderId
|
* @param orderType
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/order/queryOrderInfo")
|
@ApiOperation(value = "获取订单详情", tags = {"调度端-订单管理"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "订单类型(1=专车,2=跨城)", name = "orderType", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<OrderInfoWarpper> queryOrderInfo(Integer orderId, Integer orderType){
|
try {
|
Map<String, Object> map = null;
|
if(orderType == 1){//专车
|
map = orderPrivateCarService.queryOrderInfo(orderId);
|
}
|
if(orderType == 2){//跨城
|
map = orderCrossCityService.queryOrderInfo(orderId);
|
}
|
if(orderType == 7){//专车
|
map = orderTransferService.queryOrderInfo(orderId);
|
}
|
return ResultUtil.success(OrderInfoWarpper.getOrderInfoWarpper(map));
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 取消订单
|
* @param orderId
|
* @param orderType
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/order/cancelOrder")
|
@ApiOperation(value = "取消订单", tags = {"调度端-订单管理"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "订单类型(1=专车,2=跨城)", name = "orderType", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil cancelOrder(Integer orderId, Integer orderType){
|
try {
|
if(orderType == 1){//专车
|
return orderPrivateCarService.cancelOrder(orderId);
|
}
|
if(orderType == 2){//跨城
|
return orderCrossCityService.cancelOrder(orderId);
|
}
|
if(orderType == 7){//接送机
|
return orderTransferService.cancelOrder(orderId);
|
}
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 获取订单坐标轨迹数据
|
* @param orderId
|
* @param orderType
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/order/queryOrderPosition")
|
@ApiOperation(value = "获取订单坐标", tags = {"调度端-订单管理"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "订单类型(1=专车,3=跨城)", name = "orderType", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<List<BaseWarpper>> queryOrderPosition(Integer orderId, Integer orderType){
|
try {
|
List<OrderPosition> orderPositions = orderPositionService.queryPosition(orderId, orderType);
|
List<BaseWarpper> list = new ArrayList<>();
|
for(OrderPosition orderPosition : orderPositions){
|
BaseWarpper baseWarpper = new BaseWarpper();
|
baseWarpper.setLon(Double.valueOf(orderPosition.getLon()));
|
baseWarpper.setLat(Double.valueOf(orderPosition.getLat()));
|
list.add(baseWarpper);
|
}
|
return ResultUtil.success(list);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 跨城下单操作
|
* @param orderCrossCityWarpper
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping(value = "/api/order/orderCrossCity", method = RequestMethod.POST)
|
@ApiOperation(value = "跨城出行下单操作", tags = {"调度端-添加订单"}, notes = "先进行下单操作,再根据返回数据生成收款二维码")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<BaseWarpper> orderCrossCity(OrderCrossCityWarpper orderCrossCityWarpper, HttpServletRequest request){
|
try {
|
Integer uid = dispatchService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return orderCrossCityService.orderCrossCity(orderCrossCityWarpper, uid);
|
}catch (SystemException se){
|
return ResultUtil.error(se.getMessage());
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 扫码支付成功回调处理
|
* @param request
|
* @param response
|
*/
|
@ResponseBody
|
@PostMapping("/base/order/generatePay")
|
public void generatePay(HttpServletRequest request, HttpServletResponse response){
|
try {
|
// Map<String, String> map = icbcPayUtil.generatePayCallback(request);
|
// if(null != map){
|
// String out_trade_no = map.get("out_trade_no");
|
// String order_id = map.get("order_id");
|
// String s = icbcPayUtil.queryGeneratePayState("", order_id);
|
// if(s.equals("0")){
|
// icbcPayUtil.answer(response);//回调应答
|
// }
|
// if(ToolUtil.isNotEmpty(out_trade_no) && ToolUtil.isNotEmpty(order_id) && s.equals("0")){
|
// String[] split = out_trade_no.split(",");
|
// Integer id = Integer.valueOf(split[0]);
|
// Integer type = Integer.valueOf(split[1]);
|
// switch (type){
|
// case 1:
|
// break;
|
// case 2:
|
// break;
|
// case 3:
|
// orderCrossCityService.generatePayCallback(id, order_id);
|
// break;
|
// }
|
// }
|
// }
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 改派拒绝后的退款回调处理
|
* @param request
|
* @param response
|
*/
|
@ResponseBody
|
@PostMapping("/base/order/reassignRefundCallback")
|
public void reassignRefundCallback(HttpServletRequest request, HttpServletResponse response){
|
try {
|
Map<String, String> map = payMoneyUtil.wxRefundCallback(request);
|
if(null != map){
|
String refund_id = map.get("refund_id");
|
String out_refund_no = map.get("out_refund_no");
|
String result = map.get("result");
|
String id = out_refund_no.split("_")[1];
|
|
Reassign reassign = reassignService.selectById(id);
|
reassign.setState(5);//拒绝
|
reassign.setCompleteTime(new Date());
|
reassignService.updateById(reassign);
|
|
if(reassign.getOrderType() == 1){//专车
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
orderPrivateCar.setState(orderPrivateCar.getOldState());
|
orderPrivateCar.setOldState(null);
|
orderPrivateCarService.updateAllColumnById(orderPrivateCar);
|
}
|
if(reassign.getOrderType() == 7){//专车
|
OrderTransferCar orderPrivateCar = orderTransferService.selectById(reassign.getOrderId());
|
orderPrivateCar.setState(orderPrivateCar.getOldState());
|
orderPrivateCar.setOldState(null);
|
orderTransferService.updateAllColumnById(orderPrivateCar);
|
}
|
if(reassign.getOrderType() == 3){//跨城
|
OrderCrossCity orderCrossCity = orderCrossCityService.selectById(reassign.getOrderId());
|
orderCrossCity.setState(orderCrossCity.getOldState());
|
orderCrossCity.setOldState(null);
|
orderCrossCityService.updateAllColumnById(orderCrossCity);
|
}
|
|
PrintWriter out = response.getWriter();
|
out.print(result);
|
out.flush();
|
out.close();
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
}
|