Pu Zhibing
9 天以前 ed02b20b31e013159c55ab14b81772e41b36649c
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -8,19 +8,18 @@
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.dao.RegionMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.model.Company;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.model.OrderAdditionalFee;
import com.stylefeng.guns.modular.system.model.OrderPosition;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -32,28 +31,28 @@
    @Resource
    private OrderTaxiMapper orderTaxiMapper;
    @Autowired
    private IDriverService driverService;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private GDFalconUtil gdFalconUtil;
    @Autowired
    private RedisUtil redisUtil;
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private IOrderPositionService orderPositionService;
    @Autowired
    private ISystemNoticeService systemNoticeService;
    @Autowired
    private ChinaMobileUtil chinaMobileUtil;
    @Autowired
    private GeodesyUtil geodesyUtil;
@@ -134,13 +133,13 @@
     * @throws Exception
     */
    @Override
    public synchronized ResultUtil grabOrder(Integer orderId, Integer uid) throws Exception {
    public ResultUtil grabOrder(Integer orderId, Integer uid) throws Exception {
        OrderPrivateCar orderPrivateCar1 = orderPrivateCarService.selectById(orderId);
        if(null != orderPrivateCar1 && orderPrivateCar1.getType() == 3 && orderPrivateCar1.getState() != 1){
        if(null != orderPrivateCar1 && orderPrivateCar1.getType() == 3 && orderPrivateCar1.getState() != 1&& orderPrivateCar1.getState() != 11){
            return ResultUtil.error("订单已被抢了");
        }
        OrderTaxi orderTaxi = null;
        if(null != orderPrivateCar1 && orderPrivateCar1.getType() == 3 && orderPrivateCar1.getState() == 1){
        if(null != orderPrivateCar1 && orderPrivateCar1.getType() == 3 && orderPrivateCar1.getState() == 1&& orderPrivateCar1.getState() == 11){
            orderPrivateCarService.deleteById(orderId);
            OrderTaxi orderTaxi1 = setOrderTaxi(orderPrivateCar1);
            this.insert(orderTaxi1);
@@ -180,8 +179,13 @@
        if(orderTaxi.getState() == 10){
            return ResultUtil.error("订单已取消");
        }
        if(orderTaxi.getState() != 1){
        if(orderTaxi.getState() != 1 && orderTaxi.getState() != 11 ){
            return ResultUtil.error("手速有点慢哦,订单已被抢啦!");
        }
        Integer oldDriverId = null;
        if(orderTaxi.getState()==11){
            oldDriverId= orderTaxi.getDriverId();
        }
        Driver driver = driverService.selectById(uid);
        orderTaxi.setDriverId(uid);
@@ -192,16 +196,16 @@
        orderTaxi.setSnatchOrderTime(new Date());
        //调用高德创建轨迹
        String s = gdFalconUtil.selectTerminal(driver.getPhone());
        String track = gdFalconUtil.createTrack(s);
        orderTaxi.setTrackId(track);
        //调用移动的小号接口
        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
        if(String.valueOf(map.get("code")).equals("200")){
            orderTaxi.setTelX(map.get("telX"));
            orderTaxi.setBindId(map.get("bindId"));
        }
//        String s = gdFalconUtil.selectTerminal(driver.getPhone());
//        String track = gdFalconUtil.createTrack(s);
//        orderTaxi.setTrackId(track);
//
//        //调用移动的小号接口
//        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
//        if(String.valueOf(map.get("code")).equals("200")){
//            orderTaxi.setTelX(map.get("telX"));
//            orderTaxi.setBindId(map.get("bindId"));
//        }
        this.updateById(orderTaxi);
@@ -241,15 +245,25 @@
        //推送相关代码------------------start----------------
        OrderTaxi finalOrderTaxi = orderTaxi;
        Integer finalOldDriverId = oldDriverId;
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
                pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
                if(finalOrderTaxi.getType() == 2){
                    pushUtil.pushFerryOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, 2);
                    System.err.println("----------------------------------推送摆渡订单-----------------------------");
                if(finalOldDriverId !=null){
                    // 推送3个 1推送原司机 2推送新司机 3推送用户
                    pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
                    pushUtil.pushOrderReassign(finalOrderTaxi.getUserId(),1 , finalOrderTaxi.getId(), 2);
                    pushUtil.pushOrderReassign(finalOldDriverId,2, finalOrderTaxi.getId(), 2);
                }else {
                    pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
                    pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
                    if(finalOrderTaxi.getType() == 2){
                        pushUtil.pushFerryOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, 2);
                        System.err.println("----------------------------------推送摆渡订单-----------------------------");
                    }
                }
            }
        }).start();
@@ -331,20 +345,20 @@
        orderTaxi.setArriveTime(date);
        orderTaxi.setStartServiceTime(date);
        orderTaxi.setBoardingTime(date);
        String value = redisUtil.getValue("DRIVER" + uid);
        if(ToolUtil.isNotEmpty(value)){
        String value = (String) redisTemplate.opsForValue().get("DRIVER" + uid);
        if (ToolUtil.isNotEmpty(value)) {
            String[] split = value.split(",");
            Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(split[0], split[1]);
            orderTaxi.setBoardingAddress(geocode1.get("address"));
            orderTaxi.setBoardingLon(Double.valueOf(split[0]));
            orderTaxi.setBoardingLat(Double.valueOf(split[1]));
        }
        //调用高德创建轨迹
        String s = gdFalconUtil.selectTerminal(driver.getPhone());
        String track = gdFalconUtil.createTrack(s);
        orderTaxi.setTrackId(track);
//        String s = gdFalconUtil.selectTerminal(driver.getPhone());
//        String track = gdFalconUtil.createTrack(s);
//        orderTaxi.setTrackId(track);
        //调用移动的小号接口 TODO 车载端使用真实号码
//        Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
@@ -589,13 +603,13 @@
                }
            }).start();
            //添加定时任务6分钟司机不确认收款自动完成支付(仅车载端),6分钟之内司机无法接单
            String vehicle = redisUtil.getValue("VEHICLE");
            String vehicle = (String) redisTemplate.opsForValue().get("VEHICLE");
            JSONArray jsonArray = new JSONArray();
            if(ToolUtil.isNotEmpty(vehicle)){
                jsonArray = JSON.parseArray(vehicle);
            }
            jsonArray.add(orderTaxi.getDriverId());
            redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识
            redisTemplate.opsForValue().set("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识
            TimerTask timerTask = new TimerTask() {
                @Override
@@ -610,8 +624,8 @@
                        orderTaxi1.setPayMoney(orderTaxi1.getOrderMoney());
                        orderTaxi1.setState(8);
                        OrderTaxiServiceImpl.this.updateById(orderTaxi1);
                        String vehicle = redisUtil.getValue("VEHICLE");
                        String vehicle = (String) redisTemplate.opsForValue().get("VEHICLE");
                        if(ToolUtil.isNotEmpty(vehicle)){
                            JSONArray jsonArray = JSON.parseArray(vehicle);
                            for(int i = 0; i < jsonArray.size(); i++){
@@ -620,7 +634,7 @@
                                    break;
                                }
                            }
                            redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
                            redisTemplate.opsForValue().set("VEHICLE", jsonArray.toJSONString());
                        }
                        new Thread(new Runnable() {
@@ -683,13 +697,13 @@
        }).start();
        //添加定时任务6分钟司机不确认收款自动完成支付(仅车载端),6分钟之内司机无法接单
        String vehicle = redisUtil.getValue("VEHICLE");
        String vehicle = (String) redisTemplate.opsForValue().get("VEHICLE");
        JSONArray jsonArray = new JSONArray();
        if(ToolUtil.isNotEmpty(vehicle)){
            jsonArray = JSON.parseArray(vehicle);
        }
        jsonArray.add(orderTaxi.getDriverId());
        redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识
        redisTemplate.opsForValue().set("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识
        TimerTask timerTask = new TimerTask() {
            @Override
@@ -704,8 +718,8 @@
                    orderTaxi1.setPayMoney(orderTaxi1.getOrderMoney());
                    orderTaxi1.setState(8);
                    OrderTaxiServiceImpl.this.updateById(orderTaxi1);
                    String vehicle = redisUtil.getValue("VEHICLE");
                    String vehicle = (String) redisTemplate.opsForValue().get("VEHICLE");
                    if(ToolUtil.isNotEmpty(vehicle)){
                        JSONArray jsonArray = JSON.parseArray(vehicle);
                        for(int i = 0; i < jsonArray.size(); i++){
@@ -714,7 +728,7 @@
                                break;
                            }
                        }
                        redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
                        redisTemplate.opsForValue().set("VEHICLE", jsonArray.toJSONString());
                    }
                    new Thread(new Runnable() {
@@ -754,7 +768,7 @@
        }else{
            orderTaxi.setMileage(0D);
            this.updateById(orderTaxi);
//            return true;//第一条数据不作处理,直接存储
            return true;//第一条数据不作处理,直接存储
        }
        Map<String, Double> distance = geodesyUtil.getDistance(now, old);
        if(null != distance){
@@ -765,13 +779,10 @@
            if(orderTaxi.getState() == 5){//大于50米表示在移动,且正在服务中的时候存入里程
                orderTaxi.setMileage(new BigDecimal(orderTaxi.getMileage()).add(new BigDecimal(distance1)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                this.updateById(orderTaxi);
//                return true;
                return true;
            }
//            return false;
        }else{
            System.err.println("调用高德计算距离出错");
        }
        return true;
        return false;
    }