liujie
1 天以前 cbc307682c0ca48d59e7b539d6a2ae58d49cabe1
refactor(driver): 重构司机端收入查询逻辑

- 修改了订单数据查询方式,从直接查询订单表改为通过收入表查询
- 优化了查询效率,减少了数据库查询次数
- 调整了订单类型和时间的处理逻辑
- 移除了不必要的代码,提高了代码可读性
3个文件已修改
170 ■■■■ 已修改文件
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/OrderCrossCityServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/DriverServiceMapper.xml 122 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/OrderCrossCityServiceImpl.java
@@ -942,7 +942,7 @@
        String lat = orderPosition.getLat();
        OrderCrossCity order = this.selectById(orderId);
        if(null == order){
            System.err.println("订单数据异常:" + orderId);
            System.err.println("跨城订单数据异常:" + orderId);
            return false;
        }
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/DriverServiceMapper.xml
@@ -78,57 +78,16 @@
    </select>
    <select id="queryOrderMoneyDataFromDriver" resultType="com.stylefeng.guns.modular.system.model.vo.DriverOrderDataNextVo">
        select * from (
        select
        orderNum,
        1 as type,
        orderType as type,
        insertTime as orderTime,
        id as orderId,
        boardingAddress as startAddress,
        getoffAddress as endAddress,
        state,
        orderMoney
        from t_order_private_car
        where driverId = #{uid} and state in (8,9)
        money as orderMoney
        from t_income
        where userType =2  and objectId = #{uid} and type =2
        <if test="sTime !=null">
            and insertTime between #{sTime} and #{eTime}
        </if>
        union all
        select
        orderNum,
        2 as type,
        insertTime as orderTime,
        id as orderId,
        boardingAddress as startAddress,
        getoffAddress as endAddress,
        state,
        orderMoney
        from t_order_taxi
        where driverId = #{uid} and state in (8,9)
        <if test="sTime !=null">
            and insertTime between #{sTime} and #{eTime}
        </if>
        union all
        select
        orderNum,
        3 as type,
        insertTime as orderTime,
        id as orderId,
        boardingAddress as startAddress,
        getoffAddress as endAddress,
        state,
        orderMoney
        from t_order_cross_city
        where driverId = #{uid} and state in (8,9)
        <if test="sTime !=null">
            and insertTime between #{sTime} and #{eTime}
        </if>
        ) t1
        order by t1.orderTime desc
        order by insertTime desc
@@ -138,65 +97,18 @@
    </select>
    <select id="queryOrderMoneyDataFromDriverAll" resultType="com.stylefeng.guns.modular.system.model.vo.DriverOrderDataNextVo">
        select * from (
        select
        orderNum,
        1 as type,
        orderType as type,
        insertTime as orderTime,
        id as orderId,
        boardingAddress as startAddress,
        getoffAddress as endAddress,
        state,
        orderMoney
        from t_order_private_car
        where driverId = #{uid} and state in (8,9)
        money as orderMoney
        from t_income
        where userType =2  and objectId = #{uid} and type =2
        <if test="sTime !=null">
            and insertTime between #{sTime} and #{eTime}
        </if>
        union all
        select
        orderNum,
        2 as type,
        insertTime as orderTime,
        id as orderId,
        boardingAddress as startAddress,
        getoffAddress as endAddress,
        state,
        orderMoney
        from t_order_taxi
        where driverId = #{uid} and state in (8,9)
        <if test="sTime !=null">
            and insertTime between #{sTime} and #{eTime}
        </if>
        union all
        select
        orderNum,
        3 as type,
        insertTime as orderTime,
        id as orderId,
        boardingAddress as startAddress,
        getoffAddress as endAddress,
        state,
        orderMoney
        from t_order_cross_city
        where driverId = #{uid} and state in (8,9)
        <if test="sTime !=null">
            and insertTime between #{sTime} and #{eTime}
        </if>
        ) t1
        order by t1.orderTime desc
        order by insertTime desc
    </select>
    <select id="queryOrderPromotionFromDriver" resultType="com.stylefeng.guns.modular.system.model.vo.DriverOrderDataNextVo">
        select * from (
        select
@@ -209,7 +121,7 @@
        state,
        promotionMoney as orderMoney
        from t_order_private_car
        where promotionDriverId = #{uid} and state in (8,9)
        where promotionDriverId = #{uid} and state in (8,9)  and successTime is not null
        <if test="sTime !=null">
            and successTime between #{sTime} and #{eTime}
        </if>
@@ -226,7 +138,7 @@
        state,
        promotionMoney as orderMoney
        from t_order_taxi
        where promotionDriverId = #{uid} and state in (8,9)
        where promotionDriverId = #{uid} and state in (8,9) and successTime is not null
        <if test="sTime !=null">
            and successTime between #{sTime} and #{eTime}
        </if>
@@ -243,7 +155,7 @@
        state,
        promotionMoney as orderMoney
        from t_order_cross_city
        where promotionDriverId = #{uid} and state in (8,9)
        where promotionDriverId = #{uid} and state in (8,9) and successTime is not null
        <if test="sTime !=null">
            and successTime between #{sTime} and #{eTime}
        </if>
@@ -270,7 +182,7 @@
        state,
        promotionMoney as orderMoney
        from t_order_private_car
        where promotionDriverId = #{uid} and state in (8,9)
        where promotionDriverId = #{uid} and state in (8,9) and successTime is not null
        <if test="sTime !=null">
            and successTime between #{sTime} and #{eTime}
        </if>
@@ -287,7 +199,7 @@
        state,
        promotionMoney as orderMoney
        from t_order_taxi
        where promotionDriverId = #{uid} and state in (8,9)
        where promotionDriverId = #{uid} and state in (8,9) and successTime is not null
        <if test="sTime !=null">
            and successTime between #{sTime} and #{eTime}
        </if>
@@ -304,7 +216,7 @@
        state,
        promotionMoney as orderMoney
        from t_order_cross_city
        where promotionDriverId = #{uid} and state in (8,9)
        where promotionDriverId = #{uid} and state in (8,9) and successTime is not null
        <if test="sTime !=null">
            and successTime between #{sTime} and #{eTime}
        </if>
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/DriverServiceImpl.java
@@ -1696,33 +1696,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("objectType", 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 +1748,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);