liujie
2025-08-04 fe2489749de15476eb1ad736577b7eaf69176b5f
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
@@ -44,7 +44,7 @@
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -97,6 +97,8 @@
    
    @Autowired
    private ICompanyCityService companyCityService;
    @Autowired
    private IOpenCityService openCityService;
    
    @Autowired
    private GDFalconUtil gdFalconUtil;
@@ -129,9 +131,6 @@
    private CarServiceMapper carServiceMapper;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
    @Value("${pushMinistryOfTransport}")
@@ -139,15 +138,13 @@
    private String salt = "SA;d5#";
    @Autowired
    @Resource
    private OrderPrivateCarMapper orderPrivateCarMapper;
    @Autowired
    @Resource
    private OrderCrossCityMapper orderCrossCityMapper;
    @Autowired
    @Resource
    private OrderTaxiMapper orderTaxiMapper;
    @Autowired
@@ -410,6 +407,10 @@
        driver.setCityCode(registeredWarpper.getCityCode());
        driver.setProvince(registeredWarpper.getProvince());
        driver.setProvinceCode(registeredWarpper.getProvinceCode());
        driver.setCompanyId(registeredWarpper.getCompanyId());
        if(registeredWarpper.getCompanyId()==null){
            return ResultUtil.error("请选择服务商");
        }
        String code = registeredWarpper.getAreaCode();
        Company query = companyCityService.query(code);
@@ -509,14 +510,10 @@
     */
    @Override
    public Map<String, Object> queryPhone(String code) throws Exception {
        Company query = companyCityService.query(code);
        Map<String, Object> map = new HashMap<>();
        if(null == query){
            map.put("phone", "");
        }else{
            Phone phone = phoneMapper.queryInfo(query.getId(), 2);
            map.put("phone", null != phone ? phone.getPhone() : "");
        }
        OpenCity openCity = openCityService.openCity1(code);
        Phone phone = phoneMapper.queryInfo(openCity.getId(), 2, 2);
        map.put("phone", null != phone ? phone.getPhone() : "");
        return map;
    }
@@ -569,9 +566,9 @@
        loginWarpper.setRongYunToken(token1.getToken());
        //创建高德猎鹰的终端数据
        String tid = gdFalconUtil.createTerminal(phone);
        loginWarpper.setServerId(gdFalconUtil.getServerId());
        loginWarpper.setTerminalId(tid);
//        String tid = gdFalconUtil.createTerminal(phone);
//        loginWarpper.setServerId(gdFalconUtil.getServerId());
//        loginWarpper.setTerminalId(tid);
        return ResultUtil.success(loginWarpper);
    }
@@ -640,6 +637,10 @@
            driverWorkMapper.updateById(driverWork);
            driver.setState(1);
            //   更新车辆使用状态
            carService.updateUseState(uid);
            new Thread(new Runnable() {
                @Override
                public void run() {
@@ -656,6 +657,18 @@
                    return ResultUtil.error("车辆正在使用中");
                }
            }
            //判断车辆是否正在使用中
            Car car = carService.selectById(driver.getCarId());
            if(car.getUseDriverId() != null && !car.getUseDriverId().equals(uid)){
                return ResultUtil.error("当前绑定车辆正在使用中,请更换车辆");
            }else if(car.getUseDriverId()==null){
                car.setUseDriverId(uid);
                carService.updateById(car);
            }
            driverWork = new DriverWork();
            driverWork.setState(1);
            driverWork.setDriverId(uid);
@@ -703,6 +716,9 @@
            driverWorkMapper.updateById(driverWork);
            driver.setState(1);
            //   更新车辆使用状态
            carService.updateUseState(uid);
            new Thread(new Runnable() {
                @Override
                public void run() {
@@ -712,6 +728,18 @@
                }
            }).start();
        }else{
            //判断车辆是否正在使用中
            Car car = carService.selectById(driver.getCarId());
            if(car.getUseDriverId() != null && !car.getUseDriverId().equals(uid)){
                return ResultUtil.error("当前绑定车辆正在使用中,请更换车辆");
            }else if(car.getUseDriverId()==null){
                car.setUseDriverId(uid);
                carService.updateById(car);
            }
            driverWork = new DriverWork();
            driverWork.setState(1);
            driverWork.setDriverId(uid);
@@ -903,10 +931,17 @@
        if(driver.getState() == 3){
            return ResultUtil.error("还在服务中,不能更换");
        }
        boolean idle = carService.idle(carId);
//        boolean idle = carService.idle(carId);
        // 修改是否别司机在使用
        boolean idle = carService.useState(carId,uid);
        if(!idle){
            return ResultUtil.error("当前车辆已经有其他司机在使用,请更换车辆");
        }
        // 将所有绑定他的车 =null
        carService.updateUseState(carId,uid);
        Car car = carService.selectById(carId);
        car.setUseDriverId(uid);
        carService.updateById( car);
        driver.setCarId(carId);
        this.updateById(driver);
        return ResultUtil.success();
@@ -920,47 +955,31 @@
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryPhone(Integer uid) throws Exception {
    public Map<String, Object> queryPhone(Integer uid, String code) throws Exception {
        Driver driver = this.selectById(uid);
        Company company = companyMapper.selectById(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
                driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
        OpenCity openCity = openCityService.openCity1(code);
        Company company = companyMapper.selectById(driver.getCompanyId());
        Map<String, Object> map = new HashMap<>();
        if(company.getType() == 3){//加盟商
            Phone phone = phoneMapper.queryInfo(company.getId(), 2);
            map.put("branch", "");
            Phone phone = phoneMapper.queryInfo(openCity.getId(), 2, 2);
            map.put("franchisee", null != phone ? phone.getPhone() : "");
            company = companyMapper.selectById(company.getSuperiorId());
            if(null != company){
                phone = phoneMapper.queryInfo(company.getId(), 2);
                map.put("branch", null != phone ? phone.getPhone() : "");
            }else{
                map.put("branch", "");
            }
            company = companyMapper.selectById(company.getSuperiorId());
            if(null != company){
                phone = phoneMapper.queryInfo(company.getId(), 2);
                map.put("platform", null != phone ? phone.getPhone() : "");
            }else{
                map.put("platform", "");
            }
            phone = phoneMapper.queryInfo(openCity.getId(), 2, 1);
            map.put("platform",null != phone ? phone.getPhone() : "");
            return map;
        }
        if(company.getType() == 2){//分公司
            map.put("franchisee", "");
            Phone phone = phoneMapper.queryInfo(company.getId(), 2);
            Phone phone = phoneMapper.queryInfo(openCity.getId(), 2, 2);
            map.put("branch", null != phone ? phone.getPhone() : "");
            company = companyMapper.selectById(company.getSuperiorId());
            if(null != company){
                phone = phoneMapper.queryInfo(company.getId(), 2);
                map.put("platform",null != phone ? phone.getPhone() : "");
            }else{
                map.put("platform", "");
            }
            phone = phoneMapper.queryInfo(openCity.getId(), 2, 1);
            map.put("platform",null != phone ? phone.getPhone() : "");
            return map;
        }
        if(company.getType() == 1){//平台
            map.put("franchisee", "");
            map.put("branch", "");
            Phone phone = phoneMapper.queryInfo(company.getId(), 2);
            Phone phone = phoneMapper.queryInfo(company.getId(), 2, 1);
            map.put("platform", null != phone ? phone.getPhone() : "");
            return map;
        }
@@ -1319,9 +1338,9 @@
        loginWarpper.setAppid(UUIDUtil.getRandomCode());
    
        //创建高德猎鹰的终端数据
        String tid = gdFalconUtil.createTerminal(driver.getPhone());
        loginWarpper.setServerId(gdFalconUtil.getServerId());
        loginWarpper.setTerminalId(tid);
//        String tid = gdFalconUtil.createTerminal(driver.getPhone());
//        loginWarpper.setServerId(gdFalconUtil.getServerId());
//        loginWarpper.setTerminalId(tid);
        return ResultUtil.success(loginWarpper);
    }
@@ -1415,9 +1434,9 @@
        loginWarpper.setAppid(UUIDUtil.getRandomCode());
    
        //创建高德猎鹰的终端数据
        String tid = gdFalconUtil.createTerminal(driver.getPhone());
        loginWarpper.setServerId(gdFalconUtil.getServerId());
        loginWarpper.setTerminalId(tid);
//        String tid = gdFalconUtil.createTerminal(driver.getPhone());
//        loginWarpper.setServerId(gdFalconUtil.getServerId());
//        loginWarpper.setTerminalId(tid);
        return ResultUtil.success(loginWarpper);
    }
@@ -1501,9 +1520,9 @@
        loginWarpper.setAppid(UUIDUtil.getRandomCode());
    
        //创建高德猎鹰的终端数据
        String tid = gdFalconUtil.createTerminal(driver.getPhone());
        loginWarpper.setServerId(gdFalconUtil.getServerId());
        loginWarpper.setTerminalId(tid);
//        String tid = gdFalconUtil.createTerminal(driver.getPhone());
//        loginWarpper.setServerId(gdFalconUtil.getServerId());
//        loginWarpper.setTerminalId(tid);
        return ResultUtil.success(loginWarpper);
    }
@@ -1610,11 +1629,11 @@
    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", LocalDateTime.now().toString()));
        List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        // 跨城订单
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDateTime.now().toString()));
        List<OrderCrossCity> orderCrossCities = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        // 出租车订单
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDateTime.now().toString()));
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().ne("state", 10).eq("driverId", uid).like("insertTime", LocalDate.now().toString()));
        driverIndexVo.setTodayOrderNum(orderPrivateCars.size() + orderCrossCities.size() + orderTaxis.size());
@@ -1624,9 +1643,9 @@
        driverIndexVo.setTodayOrderMoney(new BigDecimal(sum +sum1+sum2));
        BigDecimal reduce = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("promotionDriverId", uid).like("insertTime", LocalDateTime.now().toString())).stream().map(OrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal reduce1 = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().eq("promotionDriverId", uid).like("insertTime", LocalDateTime.now().toString())).stream().map(OrderCrossCity::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal reduce2 = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().eq("promotionDriverId", uid).like("insertTime", LocalDateTime.now().toString())).stream().map(OrderTaxi::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal reduce = orderPrivateCarMapper.selectList(new EntityWrapper<OrderPrivateCar>().eq("promotionDriverId", uid).like("insertTime", LocalDate.now().toString())).stream().map(OrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal reduce1 = orderCrossCityMapper.selectList(new EntityWrapper<OrderCrossCity>().eq("promotionDriverId", uid).like("insertTime", LocalDate.now().toString())).stream().map(OrderCrossCity::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal reduce2 = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().eq("promotionDriverId", uid).like("insertTime", LocalDate.now().toString())).stream().map(OrderTaxi::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        driverIndexVo.setTodayPromotionMoney(reduce.add(reduce1).add(reduce2));
        return driverIndexVo;
    };
@@ -1645,9 +1664,9 @@
        List<OrderTaxi> orderTaxis = orderTaxiMapper.selectList(new EntityWrapper<OrderTaxi>().ne("state", 10).eq("driverId", uid));
        DriverOrderDataVo driverOrderDataVo = new DriverOrderDataVo();
        driverOrderDataVo.setAllOrderNum(orderPrivateCars.size() + orderCrossCities.size() + orderTaxis.size());
        long count = orderPrivateCars.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).count();
        long count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).count();
        long count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).count();
        long count = orderPrivateCars.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).count();
        long count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).count();
        long count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).count();
        driverOrderDataVo.setTodayOrderNum((int) (count+count1+count2));
        Date date = new Date();
@@ -1691,9 +1710,9 @@
        double count = orderPrivateCars.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).mapToDouble(OrderPrivateCar::getOrderMoney).sum();
        double count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).mapToDouble(OrderCrossCity::getOrderMoney).sum();
        double count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).mapToDouble(OrderTaxi::getOrderMoney).sum();
        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));
@@ -1738,9 +1757,9 @@
        BigDecimal count = orderPrivateCars.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).map(OrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).map(OrderCrossCity::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDateTime.now().toString())).map(OrderTaxi::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal count = orderPrivateCars.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).map(OrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal count1 = orderCrossCities.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).map(OrderCrossCity::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal count2 = orderTaxis.stream().filter(e -> simpleDateFormat.format(e.getInsertTime()).equals(LocalDate.now().toString())).map(OrderTaxi::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        driverOrderDataVo.setTodayOrderMoney(count.add(count1).add(count2));