yanghb
2023-04-24 8bb76b7c08556c9344bbaa6079265fbfe5433667
DriverTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/service/impl/OrderTaxiServiceImpl.java
@@ -2,20 +2,21 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
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.Driver;
import com.stylefeng.guns.modular.system.model.OrderPosition;
import com.stylefeng.guns.modular.system.model.Region;
import com.stylefeng.guns.modular.system.model.UserRedPacketRecord;
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.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
@@ -27,6 +28,7 @@
import java.util.*;
@Service
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class OrderTaxiServiceImpl extends ServiceImpl<OrderTaxiMapper, OrderTaxi> implements IOrderTaxiService {
    @Resource
@@ -36,7 +38,13 @@
    private IDriverService driverService;
    @Autowired
    private IUserRedPacketRecordService userRedPacketRecordService;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
    @Autowired
    private GDFalconUtil gdFalconUtil;
@@ -56,17 +64,14 @@
    @Autowired
    private GeodesyUtil geodesyUtil;
    @Resource
    private RegionMapper regionMapper;
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IOrderAdditionalFeeService orderAdditionalFeeService;
@@ -179,7 +184,9 @@
        orderTaxi.setTrackId(track);
        //调用移动的小号接口
        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), (System.currentTimeMillis() + 86400000));
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
        Region region = regionMapper.query(geocode.get("districtCode"));
        Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1)));
        if(String.valueOf(map.get("code")).equals("200")){
            orderTaxi.setTelX(map.get("telX"));
            orderTaxi.setBindId(map.get("bindId"));
@@ -194,7 +201,7 @@
                            .eq("userId", orderTaxi.getUserId())
                            .ne("state", 1)
                            .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId())
                            .eq("place", orderTaxi.getPlace()).ne("id", orderTaxi.getId())
                            .eq("place", orderTaxi.getPlace())
            );
            List<OrderPrivateCar> list1 = orderPrivateCarService.selectList(
                    new EntityWrapper<OrderPrivateCar>()
@@ -241,8 +248,8 @@
            }
        }).start();
        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId(), 1);
        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId(), 1);
        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId());
        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId());
        return ResultUtil.success();
    }
@@ -326,8 +333,8 @@
            }
        }).start();
        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId(), 1);
        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId(), 1);
        systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId());
        systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId());
        return ResultUtil.success();
    }
@@ -362,12 +369,12 @@
            case 3://出发前往预约点
                orderTaxi.setState(3);
                orderTaxi.setSetOutTime(new Date());
                systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderTaxi.getUserId(), 1);
                systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderTaxi.getUserId());
                break;
            case 4://到达预约点,等待客户上车
                orderTaxi.setState(4);
                orderTaxi.setArriveTime(new Date());
                systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点,请及时上车", orderTaxi.getUserId(), 1);
                systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点,请及时上车", orderTaxi.getUserId());
                break;
            case 5://开始服务
                orderTaxi.setBoardingLon(lon);
@@ -388,7 +395,7 @@
                orderTaxi.setEndServiceTime(new Date());
                pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
                systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId(), 1);
                systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
                break;
        }
        this.updateById(orderTaxi);
@@ -453,46 +460,6 @@
    }
    @Override
    public ResultUtil confirmFees1(Integer orderId, Integer type, Double travelFee, String additionalFee) throws Exception {
        OrderTaxi orderTaxi = this.selectById(orderId);
        orderTaxi.setPayManner(type);
        if(type == 2){//其他支付,不需要操作,直接完成订单
            orderTaxi.setOrderMoney(0D);
            orderTaxi.setTravelMoney(0D);
            orderTaxi.setParkMoney(0D);
            orderTaxi.setRoadTollMoney(0D);
            orderTaxi.setHolidayFee(0D);
            orderTaxi.setRedPacketMoney(0D);
            orderTaxi.setCouponMoney(0D);
            orderTaxi.setDiscount(0D);
            orderTaxi.setDiscountMoney(0D);
            orderTaxi.setPayMoney(0D);
            orderTaxi.setState(8);
        }else{
            orderTaxi = this.setMoney1(orderTaxi, travelFee, additionalFee);
            orderTaxi.setState(7);
        }
        this.updateById(orderTaxi);
        //回滚司机状态为空闲
        Driver driver = driverService.selectById(orderTaxi.getDriverId());
        driver.setState(2);
        driverService.updateById(driver);
        OrderTaxi finalOrderTaxi = orderTaxi;
        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());
            }
        }).start();
        return ResultUtil.success();
    }
    /**
     * 确认费用(车载端)
     * @param orderId
@@ -519,7 +486,7 @@
            this.updateById(orderTaxi);
            pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
            systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId(), 1);
            systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
            //回滚司机状态为空闲
            Driver driver = driverService.selectById(orderTaxi.getDriverId());
@@ -612,7 +579,7 @@
        this.updateById(orderTaxi);
        pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
        systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId(), 1);
        systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
        //回滚司机状态为空闲
        Driver driver = driverService.selectById(orderTaxi.getDriverId());
@@ -753,39 +720,7 @@
        orderTaxi.setTravelMoney(travelFee);
        orderTaxi.setParkMoney(parkingFee);
        orderTaxi.setRoadTollMoney(crossingFee);
        BigDecimal sum = new BigDecimal(null == travelFee ? 0 : travelFee).add(new BigDecimal(null == parkingFee ? 0 : parkingFee))
                .add(new BigDecimal(null == crossingFee ? 0 : crossingFee)).add(new BigDecimal(null == orderTaxi.getTipMoney() ? 0 : orderTaxi.getTipMoney()));
        orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
        return orderTaxi;
    }
    public OrderTaxi setMoney1(OrderTaxi orderTaxi, Double travelFee, String additionalFee) throws Exception{
        orderTaxi.setTravelMoney(travelFee);
        orderTaxi.setParkMoney(0D);
        orderTaxi.setRoadTollMoney(0D);
        Company company = companyService.selectById(orderTaxi.getCompanyId());
        BigDecimal t = new BigDecimal(0);
        if(ToolUtil.isNotEmpty(additionalFee)){//附加费
            JSONArray jsonArray = JSON.parseArray(additionalFee);
            for(int i = 0; i < jsonArray.size(); i++){
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Integer id = jsonObject.getInteger("id");
                Double amount = jsonObject.getDouble("amount");
                OrderAdditionalFee orderAdditionalFee = new OrderAdditionalFee();
                orderAdditionalFee.setOrderType(2);
                orderAdditionalFee.setOrderId(orderTaxi.getId());
                orderAdditionalFee.setAdditionalFeeId(id);
                orderAdditionalFee.setAmount(amount);
                orderAdditionalFeeService.insert(orderAdditionalFee);
                t = t.add(new BigDecimal(amount));
            }
        }
        orderTaxi.setHolidayFee(null == company.getHolidayFee() ? 0D : company.getHolidayFee());
        BigDecimal sum = new BigDecimal(null == travelFee ? 0 : travelFee).add(new BigDecimal(0))
                .add(new BigDecimal(0)).add(new BigDecimal(orderTaxi.getHolidayFee()))
                .add(new BigDecimal(null == orderTaxi.getTipMoney() ? 0 : orderTaxi.getTipMoney())).add(t);
        BigDecimal sum = new BigDecimal(travelFee).add(new BigDecimal(parkingFee)).add(new BigDecimal(crossingFee)).add(new BigDecimal(orderTaxi.getTipMoney()));
        orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
        return orderTaxi;
    }