puzhibing
2023-04-07 eaa20cb58afc80e3612fd6e93d6f27e181a027e7
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -118,7 +118,8 @@
        String city = "";
        District geocode = MapUtil.geocode(estimatedCosts.getStartLng().toString(), estimatedCosts.getStartLat().toString());
        if(null != geocode){
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district"));
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
            city = null != weatherCity ? weatherCity.getId().toString() : "";
        }
        Order order = getOrderPrice(1, d, 0, new Order(), city);
@@ -270,28 +271,36 @@
        }
        //恶劣天气
        boolean badWeather = WeatherUtil.isBadWeather(city);
        if(badWeather){
            order.setBadWeatherDistance(num5);//恶劣天气公里
            order.setBadWeatherPrice(num6);//恶劣天气费
            if(distance.compareTo(num7) > 0){
                BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
                BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
                order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
                order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
            }
        systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8));
        if(null != systemConfig){
            JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent());
            Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价
            if(1 == num11){
                boolean badWeather = WeatherUtil.isBadWeather(city);
                if(badWeather){
                    order.setBadWeatherDistance(num5);//恶劣天气公里
                    order.setBadWeatherPrice(num6);//恶劣天气费
                    if(distance.compareTo(num7) > 0){
                        BigDecimal subtract = new BigDecimal(distance).subtract(new BigDecimal(num7));
                        BigDecimal multiply = subtract.multiply(new BigDecimal(num8));
                        order.setOverBadWeatherDistance(subtract.doubleValue());//恶劣天气超出公里
                        order.setOverBadWeatherPrice(multiply.doubleValue());//恶劣天气超出公里费
                    }
            double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
            if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
                if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
                    order.setBadWeatherPrice(num9);//恶劣天气费
                    order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
                }else{
                    BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
                    order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
                    double add = new BigDecimal(order.getOverBadWeatherPrice()).add(new BigDecimal(order.getBadWeatherPrice())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                    if(num9.compareTo(add) < 0){//超出最高金额(重新调整金额)
                        if(num9.compareTo(num6) < 0){//如果恶劣天气费大于最高金额
                            order.setBadWeatherPrice(num9);//恶劣天气费
                            order.setOverBadWeatherPrice(0D);//恶劣天气超出公里费
                        }else{
                            BigDecimal subtract = new BigDecimal(num9).subtract(new BigDecimal(add));
                            order.setOverBadWeatherPrice(subtract.doubleValue());//恶劣天气超出公里费
                        }
                    }
                }
            }
        }
        //计算总金额
        BigDecimal bigDecimal = new BigDecimal(order.getStartPrice() + order.getOverDrivePrice() + order.getLongDistancePrice() + order.getOverLongDistancePrice() +
@@ -357,6 +366,16 @@
        if(null != order){
            return ResultUtil.error("您还有正在进行的订单");
        }
        String startAddress = travelOrder.getStartAddress();
        startAddress = startAddress.replaceAll("& #40;", "(");
        startAddress = startAddress.replaceAll("& #41;", ")");
        travelOrder.setStartAddress(startAddress);;
        String endAddress = travelOrder.getEndAddress();
        endAddress = endAddress.replaceAll("& #40;", "(");
        endAddress = endAddress.replaceAll("& #41;", ")");
        travelOrder.setEndAddress(endAddress);
        order = new Order();
        BeanUtils.copyProperties(travelOrder, order);
        if(ToolUtil.isEmpty(travelOrder.getUserPhone())){
@@ -382,7 +401,8 @@
        String city = "";
        District geocode = MapUtil.geocode(order.getStartLng(), order.getStartLat());
        if(null != geocode){
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district"));
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
            city = null != weatherCity ? weatherCity.getId().toString() : "";
        }
        order = getOrderPrice(1, d, 0, order, city);
@@ -409,8 +429,11 @@
            //推送状态
            pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState());
            if(null != travelOrder.getDriverId()){
                pushUtil.pushOrderStatus(travelOrder.getDriverId(), 2, order.getId(), order.getState());
            if(null != order.getDriverId()){
                PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
                pushOrderInfoWarpper.setId(order.getId());
                pushOrderInfoWarpper.setState(order.getState());
                pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
            }else{
                //推单
                pushOrder(order);
@@ -446,7 +469,7 @@
        //1
        //找到中心点
        GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLat), Double.valueOf(startLng));
        GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat));
        Double num = num3 / 1000;//范围公里
        //构造半径
        Distance distanceR = new Distance(num, Metrics.KILOMETERS);
@@ -467,6 +490,10 @@
                if(ToolUtil.isEmpty(value)){
                    continue;
                }
                Driver driver1 = driverService.selectById(youTuiDriver.getDriverId());
                if(driver1.getServerStatus() == 2){
                    continue;
                }
                Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
                Double wgs84 = distance.get("WGS84");
                if(d == null || d.compareTo(wgs84) > 0){
@@ -484,6 +511,9 @@
        //开始范围查找
        if(null == driver){
            for (int i = 1; i < 4; i++) {
                if(null != driver){
                    break;
                }
                num = jsonObject.getDouble("num" + i) / 1000;//范围公里
                //构造半径
                distanceR = new Distance(num, Metrics.KILOMETERS);
@@ -504,6 +534,10 @@
                    Double score = null;
                    Double d = null;
                    for (Driver driver1 : drivers) {
                        String value = redisUtil.getValue("DRIVER" + driver1.getId());
                        if(ToolUtil.isEmpty(value)){
                            continue;
                        }
                        if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大
                            integral = driver1.getIntegral();
                            score = driver1.getScore();
@@ -517,10 +551,6 @@
                            continue;
                        }
                        if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
                            String value = redisUtil.getValue("DRIVER" + driver1.getId());
                            if(ToolUtil.isEmpty(value)){
                                continue;
                            }
                            Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat());
                            Double wgs84 = distance.get("WGS84");
                            if(d == null || d.compareTo(wgs84) > 0){
@@ -577,9 +607,24 @@
        cancelOrder.setStatus(1);
        cancelOrder.setCreateTime(new Date());
        cancelOrderService.insert(cancelOrder);
        order.setState(301);
        this.updateById(order);
        AppUser appUser = appUserService.selectById(uid);
        appUser.setCancelCount(appUser.getCancelCount() + 1);
        appUserService.updateById(appUser);
        Driver driver = driverService.selectById(order.getDriverId());
        if(null != driver){
            driver.setServerStatus(1);
            driverService.updateById(driver);
        }
        pushUtil.pushOrderStatus(uid, 1, orderId, order.getState());
        if(null != order.getDriverId()){
            PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
            pushOrderInfoWarpper.setId(order.getId());
            pushOrderInfoWarpper.setState(order.getState());
            pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
        }
        return ResultUtil.success();
    }
@@ -593,7 +638,19 @@
     */
    @Override
    public OrderInfoWarpper queryOrderInfo(Integer uid, Long orderId) throws Exception {
        return this.baseMapper.queryOrderInfo(uid, orderId);
        OrderInfoWarpper orderInfoWarpper = this.baseMapper.queryOrderInfo(uid, orderId);
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7));
        if(null != systemConfig){
            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
            orderInfoWarpper.setServiceCell(jsonObject.getString("num1"));
        }
        String value = redisUtil.getValue("DRIVER" + orderInfoWarpper.getDriverId());
        if(ToolUtil.isNotEmpty(value)){
            String[] split = value.split(",");
            orderInfoWarpper.setDriverLon(split[0]);
            orderInfoWarpper.setDriverLat(split[1]);
        }
        return orderInfoWarpper;
    }
@@ -623,7 +680,8 @@
        String city = "";
        District geocode = MapUtil.geocode(order.getStartLng().toString(), order.getStartLat().toString());
        if(null != geocode){
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>().where(" '" + geocode.getDistrict() + "' like district"));
            WeatherCity weatherCity = weatherCityService.selectOne(new EntityWrapper<WeatherCity>()
                    .where("'" + geocode.getCity() + "' like CONCAT('%', city, '%') and '" + geocode.getDistrict() + "' like CONCAT('%', district, '%') "));
            city = null != weatherCity ? weatherCity.getId().toString() : "";
        }
        Order order1 = new Order();
@@ -827,6 +885,15 @@
        order.setState(108);
        this.updateById(order);
        pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState());
        if(null != order.getDriverId()) {
            PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
            pushOrderInfoWarpper.setId(order.getId());
            pushOrderInfoWarpper.setState(order.getState());
            pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
        }
        AccountChangeDetail accountChangeDetail = new AccountChangeDetail();
        accountChangeDetail.setUserType(1);
        accountChangeDetail.setUserId(appUser.getId());
@@ -834,6 +901,7 @@
        accountChangeDetail.setOldData(appUser.getAccountBalance());
        accountChangeDetail.setType(1);
        accountChangeDetail.setChangeType(2);
        accountChangeDetail.setOrderId(order.getId());
        accountChangeDetail.setExplain("代驾服务费");
        appUser.setAccountBalance(appUser.getAccountBalance() - payMoney);
        accountChangeDetail.setNewData(appUser.getAccountBalance());
@@ -878,6 +946,7 @@
        accountChangeDetail.setOldData(appUser.getAccountBalance());
        accountChangeDetail.setType(1);
        accountChangeDetail.setChangeType(2);
        accountChangeDetail.setOrderId(order.getId());
        accountChangeDetail.setExplain("代驾服务费");
        appUser.setAccountBalance(appUser.getAccountBalance() > payMoney ? appUser.getAccountBalance() - payMoney : 0);
        accountChangeDetail.setNewData(appUser.getAccountBalance());
@@ -943,6 +1012,18 @@
                                    Thread.sleep(wait);
                                    num++;
                                }
                            }else{
                                Thread.sleep(wait);
                                num++;
                            }
                            if(10 == num){
                                AccountChangeDetail accountChangeDetail1 = accountChangeDetailService.selectById(accountChangeDetail.getId());
                                AppUser appUser1 = appUserService.selectById(accountChangeDetail1.getUserId());
                                Double b = accountChangeDetail1.getOldData() - accountChangeDetail1.getNewData();
                                appUser1.setAccountBalance(appUser1.getAccountBalance() + b);
                                appUserService.updateById(appUser1);
                                accountChangeDetailService.deleteById(accountChangeDetail.getId());
                            }
                        }
                    }catch (Exception e){
@@ -977,6 +1058,14 @@
        this.updateById(order);
        //添加收入明细
        saveCommission(order);
        pushUtil.pushOrderStatus(order.getUserId(), 1, order.getId(), order.getState());
        if(null != order.getDriverId()) {
            PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper();
            pushOrderInfoWarpper.setId(order.getId());
            pushOrderInfoWarpper.setState(order.getState());
            pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper);
        }
        return ResultUtil.success();
    }
@@ -1007,7 +1096,7 @@
        evaluate.setUserId(uid);
        evaluateService.insert(evaluate);
        Driver driver = driverService.selectById(order.getDriverId());
        driver.setScore((driver.getScore() + score) / 2);
        driver.setScore(((null == driver.getScore() ? 0 : driver.getScore()) + score) / 2);
        if(score == 5){//司机积分奖励
            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4));
            if(null != systemConfig){
@@ -1306,6 +1395,7 @@
        accountChangeDetail.setUserId(driver.getId());
        accountChangeDetail.setType(1);
        accountChangeDetail.setChangeType(1);
        accountChangeDetail.setOrderId(order.getId());
        accountChangeDetail.setOldData(driver.getBalance() + driver.getCouponBalance());
        accountChangeDetail.setExplain("订单收入");
        accountChangeDetail.setCreateTime(new Date());
@@ -1317,4 +1407,32 @@
        driverService.updateById(driver);
        accountChangeDetailService.saveData(accountChangeDetail);
    }
    /**
     * 获取乘客行程
     * @param uid
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public List<OrderListWarpper> queryMyOrder(Integer uid, Integer pageNum, Integer pageSize) throws Exception {
        pageNum = (pageNum - 1) * pageSize;
        return this.baseMapper.queryMyOrder(uid, pageNum, pageSize);
    }
    /**
     * 获取未开票订单
     * @param uid
     * @return
     * @throws Exception
     */
    @Override
    public List<OrderListWarpper> queryNotInvoiceOrder(Integer uid, NotInvoiceOrder notInvoiceOrder) throws Exception {
        notInvoiceOrder.setPageNum((notInvoiceOrder.getPageNum() - 1) * notInvoiceOrder.getPageSize());;
        return this.baseMapper.queryNotInvoiceOrder(uid, notInvoiceOrder);
    }
}