无关风月
2024-08-23 26079aa3c34f47e952a9538a93d6f8a3bab9a0fc
ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TOrderPrivateCarController.java
@@ -20,6 +20,7 @@
import com.stylefeng.guns.modular.system.dao.TSystemPriceMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.ChinaMobileUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil;
import com.stylefeng.guns.modular.system.util.HttpRequestUtil;
import com.stylefeng.guns.modular.system.util.PushURL;
@@ -217,11 +218,15 @@
    @ResponseBody
    public Object frozenOrder(@RequestParam Integer tOrderPrivateCarId) throws Exception {
        TOrderPrivateCar orderPrivateCar = tOrderPrivateCarService.selectById(tOrderPrivateCarId);
        //添加已收入明细
        TDriver tDriver = driverService.selectById(orderPrivateCar.getDriverId());
        orderPrivateCar = this.setMoney(orderPrivateCar, 0D, 0D);//计算费用
        //添加已收入明细
        TCompany company = companyService.selectById(orderPrivateCar.getCompanyId());
        TDriver tDriver = driverService.selectById(orderPrivateCar.getDriverId());
        Double taxi = company.getSpeMoney().doubleValue();
        Integer language =tDriver.getLanguage();
        BigDecimal d = null;//企业收入
        BigDecimal c = null;//司机收入
        if(company.getIsSpeFixedOrProportional() == 2){//固定
@@ -249,8 +254,100 @@
            driverService.updateById(driver);
        }
        if (orderPrivateCar.getIsFrozen() == 1){
            TOrderPrivateCar orderPrivateCar1 = tOrderPrivateCarService.selectById(tOrderPrivateCarId);
            if(orderPrivateCar1.getArriveTime()==null){
                orderPrivateCar1.setArriveTime(orderPrivateCar1.getStartServiceTime());
            }
            orderPrivateCar1 = this.setMoney(orderPrivateCar1, 0D, 0D);//计算费用
            orderPrivateCar1.setOrderMoney(orderPrivateCar1.getOrderMoney().add(orderPrivateCar1.getParkMoney()).add(orderPrivateCar1.getRoadTollMoney()));
            //判断是否首单免费-免费直接完成
            Integer orderNumber = tOrderPrivateCarService.selectCount(new EntityWrapper<TOrderPrivateCar>().eq("userId",orderPrivateCar1.getUserId()).last("and (state=8 or state=9)"));
            if(orderNumber<=0){//判断是否是首单
                //判断是否免单
                TUser userInfo = userService.selectById(orderPrivateCar1.getUserId());
                if(userInfo.getFreeMoney().doubleValue()>0d){
                    if(orderPrivateCar1.getOrderMoney().compareTo(userInfo.getFreeMoney())<=-1){
                        orderPrivateCar1.setState(8);
                        orderPrivateCar1.setIsFree(2);
                        //添加已收入明细
                        TCompany tCompany = companyService.selectById(orderPrivateCar1.getCompanyId());
                        BigDecimal speMoney = tCompany.getSpeMoney();
                        if(tCompany.getIsSpeFixedOrProportional() == 2){//固定
                            d = speMoney;
                            c = orderPrivateCar1.getOrderMoney().subtract(d);//只有出行金额参与抽成,其余归属司机
                        }
                        if(tCompany.getIsSpeFixedOrProportional() == 1){//比例
                            BigDecimal price = orderPrivateCar1.getStartMoney().add(orderPrivateCar1.getMileageMoney()).add(new BigDecimal(orderPrivateCar1.getWaitMoney())).add(orderPrivateCar1.getDurationMoney()).add(orderPrivateCar1.getLongDistanceMoney());
                            d = price.multiply(speMoney).divide(new BigDecimal(100), new MathContext(2, RoundingMode.HALF_EVEN));
                            c = orderPrivateCar1.getOrderMoney().subtract(d).setScale(2, BigDecimal.ROUND_HALF_EVEN);
                        }
                        incomeService.saveData(1, orderPrivateCar1.getCompanyId(), 2, orderPrivateCar1.getId(), 1, d.doubleValue());
                        incomeService.saveData(2, orderPrivateCar1.getDriverId(), 2, orderPrivateCar1.getId(), 1, c.doubleValue());
                        TDriver driver = driverService.selectById(orderPrivateCar1.getDriverId());
                        driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                        driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                        if (null != driver.getBalance()){
                            driver.setBalance(driver.getBalance().add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN));
                        }else{
                            driver.setBalance(BigDecimal.ZERO.add(c).setScale(2, BigDecimal.ROUND_HALF_EVEN));
                        }
                        driverService.updateById(driver);
                    }else{
                        orderPrivateCar1.setState(7);
                        orderPrivateCar1.setOrderMoney(orderPrivateCar1.getOrderMoney().subtract(userInfo.getFreeMoney()));
                        orderPrivateCar1.setFreeMoney(userInfo.getFreeMoney());
                    }
                }else{
                    orderPrivateCar1.setState(7);
                }
            }else{
                orderPrivateCar1.setState(7);
            }
            Map<String, String> map = chinaMobileUtil.midAxbUnBindSend(orderPrivateCar1.getBindId(),orderPrivateCar1.getTelX());
            if(String.valueOf(map.get("code")).equals("200")){
                orderPrivateCar1.setTelX("");
                orderPrivateCar1.setBindId("");
            }
            tOrderPrivateCarService.updateById(orderPrivateCar1);
            pushUtil.removeTask(orderPrivateCar1.getId(), 1);//删除定时任务,结束推送数据
            systemNoticeService.addSystemNotice(1, language == 1 ? "司机已结束本次行程,谢谢使用" : language == 2 ?
                    "The driver has finished the trip,thank you for using I-GO" : "Le chauffeur a terminé le trajet, merci d'utiliser I-GO", orderPrivateCar1.getUserId());
            //回滚司机状态为空闲
            TDriver driver = driverService.selectById(orderPrivateCar1.getDriverId());
            driver.setState(2);
            driverService.updateById(driver);
            TOrderPrivateCar finalOrderTaxi = orderPrivateCar1;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 1, finalOrderTaxi.getState(), 0, "");
                    pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 1, finalOrderTaxi.getState(), 0, "");
                }
            }).start();
            TOrderPrivateCar finalOrderPrivateCar = orderPrivateCar1;
            new Thread(()->{
                try {
                    //上报google
                    fleetEngineUtil.reportBillableEvent(finalOrderPrivateCar.getTripId());
                    System.err.println("上报时间:{},tripid:{},created_at:{},completed_at:{}"+ System.currentTimeMillis()+ finalOrderPrivateCar.getTripId()+
                            finalOrderPrivateCar.getInsertTime().getTime()+finalOrderPrivateCar.getEndServiceTime().getTime());
                }catch (Exception e){
                    e.printStackTrace();
                }
            }).start();
            // 冻结订单需要给司机推送一个消息;
            TOrderPrivateCar finalOrderPrivateCar = orderPrivateCar;
            new Thread(new Runnable() {
                @Override
                public void run() {
@@ -265,7 +362,11 @@
        return SUCCESS_TIP;
    }
    @Autowired
    private ChinaMobileUtil chinaMobileUtil;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private ITSystemNoticeService systemNoticeService;
    @Resource
    private TSystemPriceMapper systemPriceMapper;
    public TOrderPrivateCar setMoney(TOrderPrivateCar orderPrivateCar, Double parkingFee, Double crossingFee) throws Exception {