Pu Zhibing
2 天以前 cb7e84fe6e40f3ce3ed1fe3fb3b4c0da8c847793
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
@@ -156,7 +156,7 @@
        List<Driver> drivers = driverMapper.queryIdleDriver(type, companyId);
        List<Driver> list = new ArrayList<>();
        for(Driver driver : drivers){
            String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(driver.getId()));
            String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(driver.getId()));
            if(null != value){
                Map<String, Double> distance1 = geodesyUtil.getDistance(lon + "," + lat, value);
                double d = Double.valueOf(distance1.get("WGS84")).doubleValue();
@@ -173,7 +173,7 @@
        List<Driver> drivers = driverMapper.queryIdleDriver_(type, serverCarModelId, companyId);
        List<Driver> list = new ArrayList<>();
        for(Driver driver : drivers){
            String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(driver.getId()));
            String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(driver.getId()));
            if(null != value){
                Map<String, Double> distance1 = geodesyUtil.getDistance(lon + "," + lat, value);
                double d = Double.valueOf(distance1.get("WGS84")).doubleValue();
@@ -412,26 +412,6 @@
        if(registeredWarpper.getCompanyId()==null){
            return ResultUtil.error("请选择服务商");
        }
        String code = registeredWarpper.getPlaceOfEmployment();
        Company query = companyCityService.query(code);
        if(null == query){
            return ResultUtil.error("选择从业地暂未开通业务");
        }
        if(null != query){
            switch (query.getType()){
                case 1://平台
                    driver.setCompanyId(query.getId());
                    break;
                case 2://分公司
                    driver.setCompanyId(query.getId());
                    break;
                case 3://加盟商
                    driver.setCompanyId(query.getSuperiorId());
                    driver.setFranchiseeId(query.getId());
                    break;
            }
        }
        driver.setHeadImgUrl(registeredWarpper.getHeadImgUrl());
        driver.setIdCardImgUrl1(registeredWarpper.getIdCardImgUrl1());
        driver.setIdCardImgUrl2(registeredWarpper.getIdCardImgUrl2());
@@ -658,7 +638,10 @@
                    return ResultUtil.error("车辆正在使用中");
                }
            }
            //专车业务需要校验
//            if(0 == driver.getIsSynchronous() && type.contains("1")){
//                return ResultUtil.error("请先开通钱包");
//            }
            //判断车辆是否正在使用中
            Car car = carService.selectById(driver.getCarId());
            if(car.getUseDriverId() != null && !car.getUseDriverId().equals(uid)){
@@ -932,14 +915,20 @@
        if(driver.getState() == 3){
            return ResultUtil.error("还在服务中,不能更换");
        }
//        boolean idle = carService.idle(carId);
        // 修改是否别司机在使用
        boolean idle = carService.useState(carId,uid);
        if(!idle){
        if(idle){
            return ResultUtil.error("当前车辆已经有其他司机在使用,请更换车辆");
        }
        // 将所有绑定他的车 =null
        carService.updateUseState(carId,uid);
        List<Driver> drivers = this.selectList(new EntityWrapper<Driver>().eq("carId", carId)
                .eq("authState", 2).ne("flag", 3));
        drivers.forEach(d->{
            d.setCarId(null);
        });
        if(drivers.size() > 0){
            this.updateAllColumnBatchById(drivers);
        }
        Car car = carService.selectById(carId);
        car.setUseDriverId(uid);
        carService.updateById( car);
@@ -1330,7 +1319,7 @@
        String s = JwtTokenUtil.generateToken(String.valueOf(driver.getId()));
        redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(driver.getId()), 7, TimeUnit.DAYS);
        redisTemplate.opsForValue().set(driver.getPhone(), s.substring(s.length() - 32));
        redisTemplate.opsForValue().set("DRIVER_" + driver.getId(), s);
        redisTemplate.opsForValue().set("dache:DRIVER_" + driver.getId(), s);
    
    
        LoginWarpper loginWarpper = new LoginWarpper();
@@ -1426,7 +1415,7 @@
        String s = JwtTokenUtil.generateToken(String.valueOf(driver.getId()));
        redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(driver.getId()), 7, TimeUnit.DAYS);
        redisTemplate.opsForValue().set(driver.getPhone(), s.substring(s.length() - 32));
        redisTemplate.opsForValue().set("DRIVER_" + driver.getId(), s);
        redisTemplate.opsForValue().set("dache:DRIVER_" + driver.getId(), s);
    
    
        LoginWarpper loginWarpper = new LoginWarpper();
@@ -1512,7 +1501,7 @@
        String s = JwtTokenUtil.generateToken(String.valueOf(driver.getId()));
        redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(driver.getId()), 7, TimeUnit.DAYS);
        redisTemplate.opsForValue().set(driver.getPhone(), s.substring(s.length() - 32));
        redisTemplate.opsForValue().set("DRIVER_" + driver.getId(), s);
        redisTemplate.opsForValue().set("dache:DRIVER_" + driver.getId(), s);
    
    
        LoginWarpper loginWarpper = new LoginWarpper();
@@ -1620,9 +1609,9 @@
        Driver driver = driverMapper.selectById(id);
        String key = (String) redisTemplate.opsForValue().get(driver.getPhone());
        redisTemplate.delete(key);//删除个人信息数据
        redisTemplate.delete("DRIVER_" + driver.getPhone());//删除后台冻结相关缓存
        redisTemplate.delete("DRIVER_" + id);//清除存储的token
        redisTemplate.delete("DEVICE_" + id);//清除车载端登录的标识
        redisTemplate.delete("dache:DRIVER_" + driver.getPhone());//删除后台冻结相关缓存
        redisTemplate.delete("dache:DRIVER_" + id);//清除存储的token
        redisTemplate.delete("dache:DEVICE_" + id);//清除车载端登录的标识
        return ResultUtil.success();
    }
@@ -1630,18 +1619,23 @@
    public DriverIndexVo queryHomeDataFromDriver(Integer uid) {
        DriverIndexVo driverIndexVo = new DriverIndexVo();
        // 获取快车订单
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().in("state", Arrays.asList(7, 8, 9)).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        // 跨城订单
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().in("state", Arrays.asList(7, 8, 9)).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        // 出租车订单
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().in("state", Arrays.asList(7, 8, 9)).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        driverIndexVo.setTodayOrderNum(orderPrivateCars.size() + orderCrossCities.size() + orderTaxis.size());
        double sum = orderPrivateCars.stream().mapToDouble(OrderPrivateCar::getOrderMoney).sum();
        double sum1 = orderCrossCities.stream().mapToDouble(OrderCrossCity::getOrderMoney).sum();
        double sum2 = orderTaxis.stream().mapToDouble(OrderTaxi::getOrderMoney).sum();
        driverIndexVo.setTodayOrderMoney(new BigDecimal(sum +sum1+sum2));
//
//        double sum1 = orderCrossCities.stream().mapToDouble(OrderCrossCity::getOrderMoney).sum();
//        double sum2 = orderTaxis.stream().filter(e->e.getOrderMoney()!=null).mapToDouble(OrderTaxi::getOrderMoney).sum();
//
        List<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().eq("objectId", uid).eq("userType", 2).eq("type", 2).like("insertTime", LocalDate.now().toString()));
        double sum = incomes.stream().mapToDouble(Income::getMoney).sum();
        driverIndexVo.setTodayOrderMoney(new BigDecimal(sum));
        BigDecimal reduce = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("promotionDriverId", uid).like("insertTime", LocalDate.now().toString())).stream().map(OrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -1696,33 +1690,37 @@
        DriverOrderMoneyDataVo driverOrderDataVo = new DriverOrderMoneyDataVo();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM");
        // 总的订单数
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().in("state",Arrays.asList(8,9)).eq("driverId", uid));
        // 跨城订单
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().in("state",Arrays.asList(8,9)).eq("driverId", uid));
        // 出租车订单
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().in("state",Arrays.asList(8,9)).eq("driverId", uid));
//        // 总的订单数
//        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().in("state",Arrays.asList(8,9)).eq("driverId", uid));
//        // 跨城订单
//        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().in("state",Arrays.asList(8,9)).eq("driverId", uid));
//        // 出租车订单
//        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().in("state",Arrays.asList(8,9)).eq("driverId", uid));
        double sum = orderPrivateCars.stream().mapToDouble(OrderPrivateCar::getOrderMoney).sum();
        double sum1 = orderCrossCities.stream().mapToDouble(OrderCrossCity::getOrderMoney).sum();
        double sum2 = orderTaxis.stream().mapToDouble(OrderTaxi::getOrderMoney).sum();
        driverOrderDataVo.setAllOrderMoney(new BigDecimal(sum +sum1+sum2));
        List<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().eq("objectId", uid).eq("userType", 2).eq("type", 2));
//        double sum = orderPrivateCars.stream().mapToDouble(OrderPrivateCar::getOrderMoney).sum();
//        double sum1 = orderCrossCities.stream().mapToDouble(OrderCrossCity::getOrderMoney).sum();
//        double sum2 = orderTaxis.stream().mapToDouble(OrderTaxi::getOrderMoney).sum();
        double sum4 = incomes.stream().mapToDouble(Income::getMoney).sum();
        driverOrderDataVo.setAllOrderMoney(new BigDecimal(sum4));
        double count = orderPrivateCars.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).mapToDouble(OrderPrivateCar::getOrderMoney).sum();
        double count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).mapToDouble(OrderCrossCity::getOrderMoney).sum();
        double count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).mapToDouble(OrderTaxi::getOrderMoney).sum();
        driverOrderDataVo.setTodayOrderMoney(new BigDecimal(count+count1+count2));
        double count = incomes.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).mapToDouble(Income::getMoney).sum();
//        double count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).mapToDouble(OrderCrossCity::getOrderMoney).sum();
//        double count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).mapToDouble(OrderTaxi::getOrderMoney).sum();
        driverOrderDataVo.setTodayOrderMoney(new BigDecimal(count));
        Date date = new Date();
        String month = simpleDateFormat1.format(date);
        double count3 = orderPrivateCars.stream().filter(e -> simpleDateFormat1.format(e.getInsertTime()).equals(month)).mapToDouble(OrderPrivateCar::getOrderMoney).sum();
        double count4 = orderCrossCities.stream().filter(e -> simpleDateFormat1.format(e.getInsertTime()).equals(month)).mapToDouble(OrderCrossCity::getOrderMoney).sum();
        double count5 = orderTaxis.stream().filter(e -> simpleDateFormat1.format(e.getInsertTime()).equals(month)).mapToDouble(OrderTaxi::getOrderMoney).sum();
        driverOrderDataVo.setMonthOrderMoney(new BigDecimal(count3+count4+count5));
        double count3 = incomes.stream().filter(e -> simpleDateFormat1.format(e.getInsertTime()).equals(month)).mapToDouble(Income::getMoney).sum();
//        double count4 = orderCrossCities.stream().filter(e -> simpleDateFormat1.format(e.getInsertTime()).equals(month)).mapToDouble(OrderCrossCity::getOrderMoney).sum();
//        double count5 = orderTaxis.stream().filter(e -> simpleDateFormat1.format(e.getInsertTime()).equals(month)).mapToDouble(OrderTaxi::getOrderMoney).sum();
        driverOrderDataVo.setMonthOrderMoney(new BigDecimal(count3));
        String sTime=null;
        String eTime=null;
@@ -1744,11 +1742,11 @@
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM");
        // 总的订单数
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().in("state",Arrays.asList(8,9)).eq("promotionDriverId", uid));
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().in("state",Arrays.asList(8,9)).eq("promotionDriverId", uid).isNotNull("successTime"));
        // 跨城订单
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().in("state",Arrays.asList(8,9)).eq("promotionDriverId", uid));
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().in("state",Arrays.asList(8,9)).eq("promotionDriverId", uid).isNotNull("successTime"));
        // 出租车订单
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().in("state",Arrays.asList(8,9)).eq("promotionDriverId", uid));
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().in("state",Arrays.asList(8,9)).eq("promotionDriverId", uid).isNotNull("successTime"));
        BigDecimal sum = orderPrivateCars.stream().map(OrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -1795,16 +1793,16 @@
     */
    private void singlePointLogin(Integer id) {
        //开始验证当前账号是否在别处登录
        String value = (String) redisTemplate.opsForValue().get("DRIVER_" + id);
        String value = (String) redisTemplate.opsForValue().get("dache:DRIVER_" + id);
        if (ToolUtil.isNotEmpty(value)) {//将另外设备上的强迫下线(如果是车载端不需要下线)
            //开始清除redis中无效的数据
            Driver driver = driverMapper.selectById(id);
            String key = (String) redisTemplate.opsForValue().get("DRIVER_" + driver.getPhone());
            String key = (String) redisTemplate.opsForValue().get("dache:DRIVER_" + driver.getPhone());
            if(ToolUtil.isNotEmpty(key)){
                redisTemplate.delete(key);//删除个人信息数据
            }
            redisTemplate.delete("DRIVER_" + driver.getPhone());//删除后台冻结相关缓存
            redisTemplate.delete("DRIVER_" + id);//清除存储的token
            redisTemplate.delete("dache:DRIVER_" + driver.getPhone());//删除后台冻结相关缓存
            redisTemplate.delete("dache:DRIVER_" + id);//清除存储的token
        }
    }
    
@@ -1831,8 +1829,8 @@
                usernamePasswordToken, simpleAuthenticationInfo);
        String s = JwtTokenUtil.generateToken(String.valueOf(driver.getId()));
        redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(driver.getId()), 7, TimeUnit.DAYS);
        redisTemplate.opsForValue().set("DRIVER_" + driver.getPhone(), s.substring(s.length() - 32));
        redisTemplate.opsForValue().set("DRIVER_" + driver.getId(), s);
        redisTemplate.opsForValue().set("dache:DRIVER_" + driver.getPhone(), s.substring(s.length() - 32));
        redisTemplate.opsForValue().set("dache:DRIVER_" + driver.getId(), s);
        return s;
    }