Pu Zhibing
2025-04-25 20fb7c22fd9d4a936a2e9f4b003da51a0c2a0217
ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/TSubsidyController.java
@@ -1,33 +1,32 @@
package com.stylefeng.guns.modular.system.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.vo.GrantMoneyVO;
import com.stylefeng.guns.modular.system.vo.GrantVO;
import com.stylefeng.guns.modular.system.vo.PlatformVO;
import com.stylefeng.guns.modular.system.vo.UseMoneyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * 控制器
@@ -38,1468 +37,1582 @@
@Controller
@RequestMapping("/subsidy")
public class TSubsidyController extends BaseController {
   private String PREFIX = "/system/subsidy/";
   @Autowired
   private IIncomeService tIncomeService;
   @Autowired
   private ITOrderPrivateCarService orderPrivateCarService;
   @Autowired
   private ITOrderLogisticsService orderLogisticsService;
   @Autowired
   private IIncomeService incomeService;
   @Autowired
   private ISettlementRecordService settlementRecordService;
   @Autowired
   private IBalanceUsageRecordService balanceUsageRecordService;
   @Autowired
   private ISettlementDetailService settlementDetailService;
   @Autowired
   private ITDriverService driverService;
   @Autowired
   private ITPubTransactionDetailsService pubTransactionDetailsService;
   @Autowired
   private ITPubWithdrawalService pubWithdrawalService;
   @Autowired
   private IPaymentRecordService paymentRecordService;
   @Autowired
   private ITUserService appUserService;
   @Autowired
   private IUserCouponRecordService userCouponRecordService;
   @Autowired
   private IUserRedPacketRecordService userRedPacketRecordService;
   @Autowired
   private IDriverActivityHistoryService driverActivityHistoryService;
   @Autowired
   private IUserActivityRedenvelopeService userActivityRedenvelopeService;
   @Autowired
   private IUserActivityService userActivityService;
   @Autowired
   private ISysCouponActivityService sysCouponActivityService;
   @Autowired
   private ISysCouponRecordService sysCouponRecordService;
   @Autowired
   private IUserActivityDiscount1Service userActivityDiscount1Service;
   @Autowired
   private ISysRedPacketRecordService sysRedPacketRecordService;
    private String PREFIX = "/system/subsidy/";
    @RequestMapping("/grant")
    public String index( Model model) {
        return PREFIX + "grant.html";
    }
    @RequestMapping("/use")
    public String watter( Model model) {
        return PREFIX + "use.html";
    }
    @Autowired
    private IIncomeService tIncomeService;
    @Autowired
    private ITOrderPrivateCarService orderPrivateCarService;
    @Autowired
    private ITOrderLogisticsService orderLogisticsService;
    @Autowired
    private IIncomeService incomeService;
    @Autowired
    private ISettlementRecordService settlementRecordService;
    @Autowired
    private IBalanceUsageRecordService balanceUsageRecordService;
    @Autowired
    private ISettlementDetailService settlementDetailService;
    @Autowired
    private ITDriverService driverService;
    @Autowired
    private ITPubTransactionDetailsService pubTransactionDetailsService;
    @Autowired
    private ITPubWithdrawalService pubWithdrawalService;
    @Autowired
    private IPaymentRecordService paymentRecordService;
    @Autowired
    private ITUserService appUserService;
    @Autowired
    private IUserCouponRecordService userCouponRecordService;
    @Autowired
    private IUserRedPacketRecordService userRedPacketRecordService;
    @Autowired
    private IDriverActivityHistoryService driverActivityHistoryService;
    @Autowired
    private IUserActivityRedenvelopeService userActivityRedenvelopeService;
    @Autowired
    private IUserActivityService userActivityService;
    @Autowired
    private ISysCouponActivityService sysCouponActivityService;
    @Autowired
    private ISysCouponRecordService sysCouponRecordService;
    @Autowired
    private IUserActivityDiscount1Service userActivityDiscount1Service;
    public static void main(String[] args) {
        String temp = "[{\"money\":14.46,\"id\":91},{\"money\":1,\"id\":90}]";
        JSONArray objects = JSONArray.parseArray(temp);
        BigDecimal temp1 = new BigDecimal(BigInteger.ZERO);
        for (int i = 0; i < objects.size(); i++) {
            String string = objects.getJSONObject(i).getString("money");
            temp1 = temp1.add(new BigDecimal(string));
        }
        System.err.println(temp1);
    }
    /**
     * 使用补贴统计
     */
    @RequestMapping(value = "/use/list")
    @ResponseBody
    public Object list1(Integer time,String insertTime,Integer type) {
        if (time == null){
            time = 1;
        }
        String beginTime = null;
        String endTime = null;
        LocalDateTime start =null;
        LocalDateTime end =null;
        // 获取当前日期
        LocalDate today = LocalDate.now();
        if (ToolUtil.isNotEmpty(insertTime)){
            beginTime = insertTime.split(" - ")[0];
            endTime = insertTime.split(" - ")[1];
            LocalDate s = LocalDate.parse(beginTime);
            LocalDate e = LocalDate.parse(endTime);
            start = s.atStartOfDay();
            end = e.atTime(LocalTime.MAX);
        }else if (time!=null) {
            switch (time) {
   public static void main(String[] args) {
      String temp = "[{\"money\":14.46,\"id\":91},{\"money\":1,\"id\":90}]";
      JSONArray objects = JSONArray.parseArray(temp);
      BigDecimal temp1 = new BigDecimal(BigInteger.ZERO);
      for (int i = 0; i < objects.size(); i++) {
         String string = objects.getJSONObject(i).getString("money");
         temp1 = temp1.add(new BigDecimal(string));
      }
      System.err.println(temp1);
   }
   @RequestMapping("/grant")
   public String index(Model model) {
      return PREFIX + "grant.html";
   }
   @RequestMapping("/use")
   public String watter(Model model) {
      return PREFIX + "use.html";
   }
   /**
    * 使用补贴统计
    */
   @RequestMapping(value = "/use/list")
   @ResponseBody
   public Object list1(Integer time, String insertTime, Integer type) {
      if (time == null) {
         time = 1;
      }
      String beginTime = null;
      String endTime = null;
      LocalDateTime start = null;
      LocalDateTime end = null;
      // 获取当前日期
      LocalDate today = LocalDate.now();
      if (ToolUtil.isNotEmpty(insertTime)) {
         beginTime = insertTime.split(" - ")[0];
         endTime = insertTime.split(" - ")[1];
         LocalDate s = LocalDate.parse(beginTime);
         LocalDate e = LocalDate.parse(endTime);
         start = s.atStartOfDay();
         end = e.atTime(LocalTime.MAX);
      } else if (time != null) {
         switch (time) {
            case 1:
               // 获取当天的 00:00:00 和 23:59:59
               LocalDateTime startOfDay = today.atStartOfDay();
               LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
               start = startOfDay;
               end = endOfDay;
               break;
            case 2:
               // 获取本周第一天的日期和时间
               LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
               LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
               // 获取本周最后一天的日期和时间
               LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
               LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
               start = startOfWeek;
               end = endOfWeek;
               break;
            case 3:
               LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
               LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
               // 获取本月最后一天的日期和时间
               LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
               LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
               start = startOfMonth;
               end = endOfMonth;
               break;
            case 4:
               // 获取本年第一天的日期和时间
               LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
               LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
               // 获取本年最后一天的日期和时间
               LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
               LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
               start = startOfYear;
               end = endOfYear;
               break;
         }
      }
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      // 列表res
      List<GrantVO> res = new ArrayList<>();
      // 专车订单
      List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
      // 小件物流
      List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
      // 优惠券领取记录
      List<TOrderPrivateCar> userCouponRecords = new ArrayList<>();
      List<TOrderLogistics> userCouponRecords1 = new ArrayList<>();
      // 红包领取记录
      List<TOrderPrivateCar> userRedPacketRecords = new ArrayList<>();
      List<TOrderLogistics> userRedPacketRecords1 = new ArrayList<>();
      // 司机消费
      List<BalanceUsageRecord> balanceUsageRecords = new ArrayList<>();
      // 司机提现
      List<TPubWithdrawal> driverWithdrawal = new ArrayList<>();
      Wrapper<TPubWithdrawal> driverWrapper = new EntityWrapper<TPubWithdrawal>();
      // 专车wrapper
      Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>();
      // 小件物流wrapper
      Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>();
      // 已使用优惠券记录wrapper
      Wrapper<TOrderPrivateCar> between2 = new EntityWrapper<TOrderPrivateCar>();
      Wrapper<TOrderLogistics> between22 = new EntityWrapper<TOrderLogistics>();
      // 已使用红包记录wrapper
      Wrapper<TOrderPrivateCar> between3 = new EntityWrapper<TOrderPrivateCar>();
      Wrapper<TOrderLogistics> between33 = new EntityWrapper<TOrderLogistics>();
      // 司机已消费金额
      Wrapper<BalanceUsageRecord> between4 = new EntityWrapper<BalanceUsageRecord>();
      if (time == 5 && !StringUtils.hasLength(insertTime)) {
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
         ;
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
         ;
         // 已使用优惠券记录wrapper
         between2 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
         ;
         between22 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
         ;
         // 已使用红包记录wrapper
         between3 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
         ;
         between33 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
         ;
         // 司机已消费金额
         between4 = new EntityWrapper<BalanceUsageRecord>()
               .eq("type", 1)
               .ne("purpose", 6)
         ;
         // 司机提现
         driverWrapper = new EntityWrapper<TPubWithdrawal>()
               .eq("state", 2)
               .eq("type", 1)
               .eq("userType", 2)
         ;
         ;
      } else {
         driverWrapper = new EntityWrapper<TPubWithdrawal>()
               .eq("state", 2)
               .eq("type", 1)
               .eq("userType", 2)
               .between("insertTime", start, end);
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
               .between("insertTime", start, end);
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
               .between("insertTime", start, end);
         // 已使用优惠券记录wrapper
         between2 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
               .between("insertTime", start, end);
         between22 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
               .between("insertTime", start, end);
         // 已使用红包记录wrapper
         between3 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
               .between("insertTime", start, end);
         between33 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
               .between("insertTime", start, end);
         // 司机已消费金额
         between4 = new EntityWrapper<BalanceUsageRecord>()
               .ne("purpose", 6)
               .eq("type", 1)
               .between("createTime", start, end);
      }
      // 司机提现wrapper
      if (type != null) {
         switch (type) {
            case 1:
               // 红包
               userRedPacketRecords = orderPrivateCarService.selectList(between3);
               userRedPacketRecords1 = orderLogisticsService.selectList(between33);
               break;
            case 2:
               userCouponRecords = orderPrivateCarService.selectList(between2);
               userCouponRecords1 = orderLogisticsService.selectList(between22);
               // 优惠券
               break;
            case 3:
               // 司机消费记录
               balanceUsageRecords = balanceUsageRecordService.selectList(between4);
               driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
               break;
            case 4:
               // 专车订单
               tOrderPrivateCars = orderPrivateCarService.selectList(between);
               // 小件物流订单
               tOrderLogistics = orderLogisticsService.selectList(between1);
               break;
         }
      } else {
         // 红包
         userRedPacketRecords = orderPrivateCarService.selectList(between3);
         userRedPacketRecords1 = orderLogisticsService.selectList(between33);
         // 优惠券
         userCouponRecords = orderPrivateCarService.selectList(between2);
         userCouponRecords1 = orderLogisticsService.selectList(between22);
         // 专车订单
         tOrderPrivateCars = orderPrivateCarService.selectList(between);
         // 小件物流订单
         tOrderLogistics = orderLogisticsService.selectList(between1);
         // 消费
         balanceUsageRecords = balanceUsageRecordService.selectList(between4);
         // 提现
         driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
      }
      // 已发放补贴总额
      BigDecimal total = new BigDecimal("0");
      // 已使用折扣总额(用户端)
      BigDecimal discount = new BigDecimal("0");
      // 已使用红包总额(用户端)
      BigDecimal redPackage = new BigDecimal("0");
      // 已使用优惠券总额(用户端)
      BigDecimal coupon = new BigDecimal("0");
      // 已使用司机奖励总额(司机端)
      BigDecimal driver = new BigDecimal("0");
      // 司机已消费
      BigDecimal driverConsume = new BigDecimal("0");
      // 司机已提现
      BigDecimal driverWithdrawal1 = new BigDecimal("0");
      // 一次性查询所有用户信息
      Map<Integer, TUser> userMap = appUserService.selectList(new EntityWrapper<TUser>())
            .stream()
            .collect(Collectors.toMap(TUser::getId, user -> user));
      Map<Integer, TDriver> driverMap = driverService.selectList(new EntityWrapper<TDriver>())
            .stream()
            .collect(Collectors.toMap(TDriver::getId, user -> user));
      // 查询已使用折扣总额
      for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + tOrderPrivateCar.getOrderNum());
         res.add(grantVO);
      }
      for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + tOrderPrivateCar.getOrderNum());
         res.add(grantVO);
      }
      // 查询已使用红包总额
      for (TOrderPrivateCar userRedPacketRecord : userRedPacketRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
         grantVO.setType("红包");
         if (userRedPacketRecord.getRedPacketMoney() == null) {
            continue;
         }
         if (userRedPacketRecord.getRedPacketMoney().compareTo(new BigDecimal("0")) == 0) {
            continue;
         }
         grantVO.setAmount(userRedPacketRecord.getRedPacketMoney().toString());
         TUser tUser = userMap.get(userRedPacketRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userRedPacketRecord.getOrderNum());
         res.add(grantVO);
         redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getRedPacketMoney().toString()));
      }
      for (TOrderLogistics userRedPacketRecord : userRedPacketRecords1) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
         grantVO.setType("红包");
         if (userRedPacketRecord.getRedPacketMoney() == null) {
            continue;
         }
         if (userRedPacketRecord.getRedPacketMoney().compareTo(new BigDecimal("0")) == 0) {
            continue;
         }
         grantVO.setAmount(userRedPacketRecord.getRedPacketMoney().toString());
         TUser tUser = userMap.get(userRedPacketRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userRedPacketRecord.getOrderNum());
         res.add(grantVO);
         redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getRedPacketMoney().toString()));
      }
      // 查询已领取优惠券总额
      for (TOrderPrivateCar userCouponRecord : userCouponRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
         UserCouponRecord userCouponRecord1 = userCouponRecordService.selectById(userCouponRecord.getCouponId());
         switch (userCouponRecord1.getCouponUseType()){
            case 0:
               grantVO.setType(userCouponRecord1.getCouponType() == 1 ? "通用 抵扣券" : "通用 满减券");
               break;
            case 1:
               grantVO.setType(userCouponRecord1.getCouponType() == 1 ? "打车 抵扣券" : "打车 满减券");
               break;
            case 4:
               grantVO.setType(userCouponRecord1.getCouponType() == 1 ? "包裹 抵扣券" : "包裹 满减券");
               break;
         }
         grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
         TUser tUser = userMap.get(userCouponRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userCouponRecord.getOrderNum());
         coupon = coupon.add(new BigDecimal(userCouponRecord.getCouponMoney().toString()));
         res.add(grantVO);
      }
      for (TOrderLogistics userCouponRecord : userCouponRecords1) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
         UserCouponRecord userCouponRecord1 = userCouponRecordService.selectById(userCouponRecord.getCouponId());
         switch (userCouponRecord1.getCouponUseType()){
            case 0:
               grantVO.setType(userCouponRecord1.getCouponType() == 1 ? "通用 抵扣券" : "通用 满减券");
               break;
            case 1:
               grantVO.setType(userCouponRecord1.getCouponType() == 1 ? "打车 抵扣券" : "打车 满减券");
               break;
            case 4:
               grantVO.setType(userCouponRecord1.getCouponType() == 1 ? "包裹 抵扣券" : "包裹 满减券");
               break;
         }
         grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
         TUser tUser = userMap.get(userCouponRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userCouponRecord.getOrderNum());
         coupon = coupon.add(new BigDecimal(userCouponRecord.getCouponMoney().toString()));
         res.add(grantVO);
      }
      // 司机消费奖励
      for (BalanceUsageRecord balanceUsageRecord : balanceUsageRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(balanceUsageRecord.getCreateTime()));
         grantVO.setType("司机奖励");
         grantVO.setAmount(balanceUsageRecord.getMoney().toString());
         TDriver tUser = driverMap.get(balanceUsageRecord.getDriverId());
         if (tUser != null) {
            grantVO.setName(tUser.getFirstName() + tUser.getLastName());
         }
         switch (balanceUsageRecord.getPurpose()) {
            case 1:
               //打车支付
               grantVO.setRemark("余额支付" + "【打车支付】");
               break;
            case 2:
               grantVO.setRemark("余额支付" + "【包裹支付】");
               // 包裹支付
               break;
            case 3:
               grantVO.setRemark("余额支付" + "【日结算】");
               // 日结算
               break;
            case 4:
               grantVO.setRemark("余额支付" + "【周结算】");
               // 周结算
               break;
            case 5:
               grantVO.setRemark("余额支付" + "【月结算】");
               // 月结算
               break;
         }
         driverConsume = driverConsume.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
         res.add(grantVO);
      }
      // 司机提现
      for (TPubWithdrawal balanceUsageRecord : driverWithdrawal) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(balanceUsageRecord.getInsertTime()));
         grantVO.setType("司机奖励");
         grantVO.setAmount(balanceUsageRecord.getMoney().toString());
         TDriver tUser = driverMap.get(balanceUsageRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getFirstName() + tUser.getLastName());
         }
         grantVO.setRemark("司机提现");
         driverWithdrawal1 = driverWithdrawal1.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
         res.add(grantVO);
      }
      // 总额
      total = total.add(redPackage).add(coupon).add(discount).add(driverConsume).add(driverWithdrawal1);
      // 已使用司机奖励合计
      driver = driverConsume.add(driverWithdrawal1);
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
      // 对集合进行排序
      res.sort((a, b) -> {
         LocalDateTime timeA = LocalDateTime.parse(a.getInsertTime(), formatter);
         LocalDateTime timeB = LocalDateTime.parse(b.getInsertTime(), formatter);
         return timeA.compareTo(timeB);
      });
      return res;
   }
   @RequestMapping(value = "/use/getCount")
   @ResponseBody
   public Object getCount1(Integer time, String insertTime, Integer type) {
      if (time == null) {
         time = 1;
      }
      String beginTime = null;
      String endTime = null;
      LocalDateTime start = null;
      LocalDateTime end = null;
      // 获取当前日期
      LocalDate today = LocalDate.now();
      if (ToolUtil.isNotEmpty(insertTime)) {
         beginTime = insertTime.split(" - ")[0];
         endTime = insertTime.split(" - ")[1];
         LocalDate s = LocalDate.parse(beginTime);
         LocalDate e = LocalDate.parse(endTime);
         start = s.atStartOfDay();
         end = e.atTime(LocalTime.MAX);
      } else if (time != null) {
         switch (time) {
            case 1:
               // 获取当天的 00:00:00 和 23:59:59
               LocalDateTime startOfDay = today.atStartOfDay();
               LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
               start = startOfDay;
               end = endOfDay;
               break;
            case 2:
               // 获取本周第一天的日期和时间
               LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
               LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
               // 获取本周最后一天的日期和时间
               LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
               LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
               start = startOfWeek;
               end = endOfWeek;
               break;
            case 3:
               LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
               LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
               // 获取本月最后一天的日期和时间
               LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
               LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
               start = startOfMonth;
               end = endOfMonth;
               break;
            case 4:
               // 获取本年第一天的日期和时间
               LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
               LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
               // 获取本年最后一天的日期和时间
               LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
               LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
               start = startOfYear;
               end = endOfYear;
               break;
         }
      }
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      // 列表res
      List<GrantVO> res = new ArrayList<>();
      // 专车订单
      List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
      // 小件物流
      List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
      // 优惠券领取记录
      List<TOrderPrivateCar> userCouponRecords = new ArrayList<>();
      List<TOrderLogistics> userCouponRecords1 = new ArrayList<>();
      // 红包领取记录
      List<TOrderPrivateCar> userRedPacketRecords = new ArrayList<>();
      List<TOrderLogistics> userRedPacketRecords1 = new ArrayList<>();
      // 司机消费
      List<BalanceUsageRecord> balanceUsageRecords = new ArrayList<>();
      // 司机提现
      List<TPubWithdrawal> driverWithdrawal = new ArrayList<>();
      Wrapper<TPubWithdrawal> driverWrapper = new EntityWrapper<TPubWithdrawal>();
      // 专车wrapper
      Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>();
      // 小件物流wrapper
      Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>();
      // 已使用优惠券记录wrapper
      Wrapper<TOrderPrivateCar> between2 = new EntityWrapper<TOrderPrivateCar>();
      Wrapper<TOrderLogistics> between22 = new EntityWrapper<TOrderLogistics>();
      // 已使用红包记录wrapper
      Wrapper<TOrderPrivateCar> between3 = new EntityWrapper<TOrderPrivateCar>();
      Wrapper<TOrderLogistics> between33 = new EntityWrapper<TOrderLogistics>();
      // 司机已消费金额
      Wrapper<BalanceUsageRecord> between4 = new EntityWrapper<BalanceUsageRecord>();
      if (time == 5 && !StringUtils.hasLength(insertTime)) {
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
//                    .between("insertTime", start, end)
         ;
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
//                    .between("insertTime", start, end)
         ;
         // 已使用优惠券记录wrapper
         between2 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
//                    .between("insertTime", start, end)
         ;
         between22 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
//                    .between("insertTime", start, end)
         ;
         // 已使用红包记录wrapper
         between3 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
//                    .between("insertTime", start, end)
         ;
         between33 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
//                    .between("insertTime", start, end)
         ;
         // 司机已消费金额
         between4 = new EntityWrapper<BalanceUsageRecord>()
               .eq("type", 1)
               .ne("purpose", 6)
//                    .between("createTime", start, end)
         ;
         // 司机提现
         driverWrapper = new EntityWrapper<TPubWithdrawal>()
               .eq("state", 2)
               .eq("type", 1)
               .eq("userType", 2)
//                    .between("insertTime", start, end)
         ;
      } else {
         driverWrapper = new EntityWrapper<TPubWithdrawal>()
               .eq("state", 2)
               .eq("type", 1)
               .eq("userType", 2)
               .between("insertTime", start, end);
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
               .between("insertTime", start, end);
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("activityId")
               .isNotNull("discountMoney")
               .between("insertTime", start, end);
         // 已使用优惠券记录wrapper
         between2 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
               .between("insertTime", start, end);
         between22 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("couponId")
               .isNotNull("couponMoney")
               .between("insertTime", start, end);
         // 已使用红包记录wrapper
         between3 = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
               .between("insertTime", start, end);
         between33 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("redPacketId")
               .isNotNull("redPacketMoney")
               .between("insertTime", start, end);
         // 司机已消费金额
         between4 = new EntityWrapper<BalanceUsageRecord>()
               .ne("purpose", 6)
               .eq("type", 1)
               .between("createTime", start, end);
      }
      // 司机提现wrapper
      if (type != null) {
         switch (type) {
            case 1:
               // 红包
               userRedPacketRecords = orderPrivateCarService.selectList(between3);
               userRedPacketRecords1 = orderLogisticsService.selectList(between33);
               break;
            case 2:
               userCouponRecords = orderPrivateCarService.selectList(between2);
               userCouponRecords1 = orderLogisticsService.selectList(between22);
               // 优惠券
               break;
            case 3:
               // 司机消费记录
               balanceUsageRecords = balanceUsageRecordService.selectList(between4);
               driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
               break;
            case 4:
               // 专车订单
               tOrderPrivateCars = orderPrivateCarService.selectList(between);
               // 小件物流订单
               tOrderLogistics = orderLogisticsService.selectList(between1);
               break;
         }
      } else {
         // 红包
         userRedPacketRecords = orderPrivateCarService.selectList(between3);
         userRedPacketRecords1 = orderLogisticsService.selectList(between33);
         // 优惠券
         userCouponRecords = orderPrivateCarService.selectList(between2);
         userCouponRecords1 = orderLogisticsService.selectList(between22);
         // 专车订单
         tOrderPrivateCars = orderPrivateCarService.selectList(between);
         // 小件物流订单
         tOrderLogistics = orderLogisticsService.selectList(between1);
         // 消费
         balanceUsageRecords = balanceUsageRecordService.selectList(between4);
         // 提现
         driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
      }
      // 已发放补贴总额
      BigDecimal total = new BigDecimal("0");
      // 已使用折扣总额(用户端)
      BigDecimal discount = new BigDecimal("0");
      // 已使用红包总额(用户端)
      BigDecimal redPackage = new BigDecimal("0");
      // 已使用优惠券总额(用户端)
      BigDecimal coupon = new BigDecimal("0");
      // 已使用司机奖励总额(司机端)
      BigDecimal driver = new BigDecimal("0");
      // 司机已消费
      BigDecimal driverConsume = new BigDecimal("0");
      // 司机已提现
      BigDecimal driverWithdrawal1 = new BigDecimal("0");
      // 一次性查询所有用户信息
      Map<Integer, TUser> userMap = appUserService.selectList(new EntityWrapper<TUser>())
            .stream()
            .collect(Collectors.toMap(TUser::getId, user -> user));
      Map<Integer, TDriver> driverMap = driverService.selectList(new EntityWrapper<TDriver>())
            .stream()
            .collect(Collectors.toMap(TDriver::getId, user -> user));
      // 查询已使用折扣总额
      for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + tOrderPrivateCar.getOrderNum());
         res.add(grantVO);
      }
      for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + tOrderPrivateCar.getOrderNum());
         res.add(grantVO);
      }
      // 查询已使用红包总额
      for (TOrderPrivateCar userRedPacketRecord : userRedPacketRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
         grantVO.setType("红包");
         if (userRedPacketRecord.getRedPacketMoney() == null) {
            continue;
         }
         if (userRedPacketRecord.getRedPacketMoney().compareTo(new BigDecimal("0")) == 0) {
            continue;
         }
         grantVO.setAmount(userRedPacketRecord.getRedPacketMoney().toString());
         TUser tUser = userMap.get(userRedPacketRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userRedPacketRecord.getOrderNum());
         res.add(grantVO);
         redPackage = redPackage.add(userRedPacketRecord.getRedPacketMoney());
      }
      for (TOrderLogistics userRedPacketRecord : userRedPacketRecords1) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
         grantVO.setType("红包");
         if (userRedPacketRecord.getRedPacketMoney() == null) {
            continue;
         }
         if (userRedPacketRecord.getRedPacketMoney().compareTo(new BigDecimal("0")) == 0) {
            continue;
         }
         grantVO.setAmount(userRedPacketRecord.getRedPacketMoney().toString());
         TUser tUser = userMap.get(userRedPacketRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userRedPacketRecord.getOrderNum());
         res.add(grantVO);
         redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getRedPacketMoney().toString()));
      }
      // 查询已领取优惠券总额
      for (TOrderPrivateCar userCouponRecord : userCouponRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
         grantVO.setType("优惠券");
         grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
         TUser tUser = userMap.get(userCouponRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userCouponRecord.getOrderNum());
         coupon = coupon.add(new BigDecimal(userCouponRecord.getCouponMoney().toString()));
         res.add(grantVO);
      }
      for (TOrderLogistics userCouponRecord : userCouponRecords1) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
         grantVO.setType("优惠券");
         grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
         TUser tUser = userMap.get(userCouponRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         grantVO.setRemark("订单号:" + userCouponRecord.getOrderNum());
         coupon = coupon.add(new BigDecimal(userCouponRecord.getCouponMoney().toString()));
         res.add(grantVO);
      }
      // 司机消费奖励
      for (BalanceUsageRecord balanceUsageRecord : balanceUsageRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(balanceUsageRecord.getCreateTime()));
         grantVO.setType("司机奖励");
         grantVO.setAmount(balanceUsageRecord.getMoney().toString());
         TDriver tUser = driverMap.get(balanceUsageRecord.getDriverId());
         if (tUser != null) {
            grantVO.setName(tUser.getFirstName() + tUser.getLastName());
         }
         switch (balanceUsageRecord.getPurpose()) {
            case 1:
               //打车支付
               grantVO.setRemark("余额支付" + "【打车支付】");
               break;
            case 2:
               grantVO.setRemark("余额支付" + "【包裹支付】");
               // 包裹支付
               break;
            case 3:
               grantVO.setRemark("余额支付" + "【日结算】");
               // 日结算
               break;
            case 4:
               grantVO.setRemark("余额支付" + "【周结算】");
               // 周结算
               break;
            case 5:
               grantVO.setRemark("余额支付" + "【月结算】");
               // 月结算
               break;
         }
         driverConsume = driverConsume.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
         res.add(grantVO);
      }
      // 司机提现
      for (TPubWithdrawal balanceUsageRecord : driverWithdrawal) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(balanceUsageRecord.getInsertTime()));
         grantVO.setType("司机奖励");
         grantVO.setAmount(balanceUsageRecord.getMoney().toString());
         TDriver tUser = driverMap.get(balanceUsageRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getFirstName() + tUser.getLastName());
         }
         grantVO.setRemark("司机提现");
         driverWithdrawal1 = driverWithdrawal1.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
         res.add(grantVO);
      }
      // 总额
      total = total.add(redPackage).add(coupon).add(discount).add(driverConsume).add(driverWithdrawal1);
      // 已使用司机奖励合计
      driver = driverConsume.add(driverWithdrawal1);
      UseMoneyVO useMoneyVO = new UseMoneyVO();
      useMoneyVO.setTotal(total);
      useMoneyVO.setDiscount(discount);
      useMoneyVO.setRedPackage(redPackage);
      useMoneyVO.setCoupon(coupon);
      useMoneyVO.setDriver(driver);
      useMoneyVO.setDriverWithdrawal(driverWithdrawal1);
      useMoneyVO.setDriverConsume(driverConsume);
      return useMoneyVO;
   }
   /**
    * 发放补贴统计
    */
   @RequestMapping(value = "/grant/list")
   @ResponseBody
   public Object list(Integer time, String insertTime, Integer type) {
      if (time == null) {
         time = 1;
      }
      String beginTime = null;
      String endTime = null;
      LocalDateTime start = null;
      LocalDateTime end = null;
      // 获取当前日期
      LocalDate today = LocalDate.now();
      if (ToolUtil.isNotEmpty(insertTime)) {
         beginTime = insertTime.split(" - ")[0];
         endTime = insertTime.split(" - ")[1];
         LocalDate s = LocalDate.parse(beginTime);
         LocalDate e = LocalDate.parse(endTime);
         start = s.atStartOfDay();
         end = e.atTime(LocalTime.MAX);
      } else if (time != null) {
         switch (time) {
            case 1:
               // 获取当天的 00:00:00 和 23:59:59
               LocalDateTime startOfDay = today.atStartOfDay();
               LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
               start = startOfDay;
               end = endOfDay;
               break;
            case 2:
               // 获取本周第一天的日期和时间
               LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
               LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
               // 获取本周最后一天的日期和时间
               LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
               LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
               start = startOfWeek;
               end = endOfWeek;
               break;
            case 3:
               LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
               LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
               // 获取本月最后一天的日期和时间
               LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
               LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
               start = startOfMonth;
               end = endOfMonth;
               break;
            case 4:
               // 获取本年第一天的日期和时间
               LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
               LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
               // 获取本年最后一天的日期和时间
               LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
               LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
               start = startOfYear;
               end = endOfYear;
               break;
         }
      }
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      // 列表res
      List<GrantVO> res = new ArrayList<>();
      // 专车订单
      List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
      // 小件物流
      List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
      // 优惠券领取记录
      List<UserCouponRecord> userCouponRecords = new ArrayList<>();
      // 红包领取记录
      List<UserRedPacketRecord> userRedPacketRecords = new ArrayList<>();
      // 司机奖励
      List<DriverActivityHistory> driverActivityHistories = new ArrayList<>();
      // 专车wrapper
      Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>();
      // 小件物流wrapper
      Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>();
      // 优惠券领取记录wrapper
      Wrapper<UserCouponRecord> between2 = new EntityWrapper<UserCouponRecord>();
      // 红包领取记录wrapper
      Wrapper<UserRedPacketRecord> between3 = new EntityWrapper<UserRedPacketRecord>();
      // 司机奖励
      Wrapper<DriverActivityHistory> between4 = new EntityWrapper<DriverActivityHistory>();
      if (time == 5 && !StringUtils.hasLength(insertTime)) {
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("discountMoney")
         ;
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("discountMoney")
         ;
         // 优惠券领取记录wrapper
         between2 = new EntityWrapper<UserCouponRecord>()
               .ne("couponUseType", 2)
               .ne("couponUseType", 3)
         ;
         // 红包领取记录wrapper
         between3 = new EntityWrapper<UserRedPacketRecord>()
               .ne("state", 0)
         ;
         // 司机奖励
         between4 = new EntityWrapper<DriverActivityHistory>()
               .eq("carryOut", 2)
         ;
      } else {
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("discountMoney")
               .between("insertTime", start, end)
         ;
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .between("insertTime", start, end)
               .isNotNull("discountMoney")
         ;
         // 优惠券领取记录wrapper
         between2 = new EntityWrapper<UserCouponRecord>()
               .ne("couponUseType", 2)
               .ne("couponUseType", 3)
               .between("insertTime", start, end);
         // 红包领取记录wrapper
         between3 = new EntityWrapper<UserRedPacketRecord>()
               .ne("state", 0)
               .between("insertTime", start, end);
         // 司机奖励
         between4 = new EntityWrapper<DriverActivityHistory>()
               .eq("carryOut", 2)
               .between("insertTime", start, end);
      }
      if (type != null) {
         switch (type) {
            case 1:
               // 红包
               userRedPacketRecords = userRedPacketRecordService.selectList(between3);
               break;
            case 2:
               userCouponRecords = userCouponRecordService.selectList(between2);
               // 优惠券
               break;
            case 3:
               // 司机奖励
               driverActivityHistories = driverActivityHistoryService.selectList(between4);
               break;
            case 4:
               // 专车订单
               tOrderPrivateCars = orderPrivateCarService.selectList(between);
               // 小件物流订单
               tOrderLogistics = orderLogisticsService.selectList(between1);
               break;
         }
      } else {
         // 专车订单
         tOrderPrivateCars = orderPrivateCarService.selectList(between);
         // 小件物流订单
         tOrderLogistics = orderLogisticsService.selectList(between1);
         // 司机奖励
         driverActivityHistories = driverActivityHistoryService.selectList(between4);
         userCouponRecords = userCouponRecordService.selectList(between2);
         userRedPacketRecords = userRedPacketRecordService.selectList(between3);
      }
      // 已发放补贴总额
      BigDecimal total = new BigDecimal("0");
      // 已使用折扣总额(用户端)
      BigDecimal discount = new BigDecimal("0");
      // 已领取红包总额(用户端)
      BigDecimal redPackage = new BigDecimal("0");
      // 已领取优惠券总额(用户端)
      BigDecimal coupon = new BigDecimal("0");
      // 已领取司机奖励总额(司机端)
      BigDecimal driver = new BigDecimal("0");
      Map<Integer, TUser> userMap = appUserService.selectList(new EntityWrapper<TUser>())
            .stream()
            .collect(Collectors.toMap(TUser::getId, user -> user));
      Map<Integer, TDriver> driverMap = driverService.selectList(new EntityWrapper<TDriver>())
            .stream()
            .collect(Collectors.toMap(TDriver::getId, user -> user));
      Map<Integer, UserActivity> userActivityMap = userActivityService.selectList(new EntityWrapper<UserActivity>())
            .stream()
            .collect(Collectors.toMap(UserActivity::getId, user -> user));
      Map<Integer, UserActivityDiscount1> userActivityDiscountMap = userActivityDiscount1Service.selectList(new EntityWrapper<UserActivityDiscount1>())
            .stream()
            .collect(Collectors.toMap(UserActivityDiscount1::getId, user -> user));
      Map<Integer, UserActivityRedenvelope> userActivityRedenvelopeMap = userActivityRedenvelopeService.selectList(new EntityWrapper<UserActivityRedenvelope>())
            .stream()
            .collect(Collectors.toMap(UserActivityRedenvelope::getId, user -> user));
      Map<Integer, SysCouponActivity> sysCouponActivityMap = sysCouponActivityService.selectList(new EntityWrapper<SysCouponActivity>())
            .stream()
            .collect(Collectors.toMap(SysCouponActivity::getId, user -> user));
      // 查询已使用折扣总额
      for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
         if (tOrderPrivateCar.getDiscountMoney() == null || tOrderPrivateCar.getDiscountMoney() == 0) {
            continue;
         }
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         UserActivityDiscount1 userActivityDiscount1 = userActivityDiscountMap.get(tOrderPrivateCar.getActivityId());
         if (userActivityDiscount1 != null) {
            UserActivity userActivity = userActivityMap.get(userActivityDiscount1.getUserActivityId());
            if (userActivity != null) {
               grantVO.setRemark(userActivity.getName());
            }
         }
         res.add(grantVO);
      }
      for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
         if (tOrderPrivateCar.getDiscountMoney() == null || tOrderPrivateCar.getDiscountMoney() == 0) {
            continue;
         }
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         UserActivityDiscount1 userActivityDiscount1 = userActivityDiscountMap.get(tOrderPrivateCar.getActivityId());
         if (userActivityDiscount1 != null) {
            UserActivity userActivity = userActivityMap.get(userActivityDiscount1.getUserActivityId());
            if (userActivity != null) {
               grantVO.setRemark(userActivity.getName());
            }
         }
         res.add(grantVO);
      }
      // 查询已领取红包总额
      for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
         grantVO.setType("红包");
         grantVO.setAmount(userRedPacketRecord.getMoney().toString());
         TUser tUser = userMap.get(userRedPacketRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         if (userRedPacketRecord.getIsGrant() == 1) {
            // 后台发放的红包
            grantVO.setRemark("指定发放");
         }
         UserActivityRedenvelope userActivityRedenvelope = userActivityRedenvelopeMap.get(userRedPacketRecord.getRedPacketActivityId());
         if (userActivityRedenvelope != null) {
            UserActivity userActivity = userActivityMap.get(userActivityRedenvelope.getUserActivityId());
            if (userActivity != null) {
               grantVO.setRemark(userActivity.getName());
            }
         }
         res.add(grantVO);
         redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getMoney().toString()));
      }
      // 查询已领取优惠券总额
      for (UserCouponRecord userCouponRecord : userCouponRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            switch (userCouponRecord.getCouponUseType()){
                case 0:
                    grantVO.setType(userCouponRecord.getCouponType() == 1 ? "通用 抵扣券" : "通用 满减券");
                    break;
                case 1:
                    // 获取当天的 00:00:00 和 23:59:59
                    LocalDateTime startOfDay = today.atStartOfDay();
                    LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
                    start = startOfDay;
                    end = endOfDay;
                    break;
                case 2:
                    // 获取本周第一天的日期和时间
                    LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
                    LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
                    // 获取本周最后一天的日期和时间
                    LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
                    LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
                    start = startOfWeek;
                    end = endOfWeek;
                    break;
                case 3:
                    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
                    LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
                    // 获取本月最后一天的日期和时间
                    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
                    LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
                    start = startOfMonth;
                    end = endOfMonth;
                    grantVO.setType(userCouponRecord.getCouponType() == 1 ? "打车 抵扣券" : "打车 满减券");
                    break;
                case 4:
                    // 获取本年第一天的日期和时间
                    LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
                    LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
                    // 获取本年最后一天的日期和时间
                    LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
                    LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
                    start = startOfYear;
                    end = endOfYear;
                    grantVO.setType(userCouponRecord.getCouponType() == 1 ? "包裹 抵扣券" : "包裹 满减券");
                    break;
            }
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 列表res
        List<GrantVO> res = new ArrayList<>();
        // 专车订单
        List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
        // 小件物流
        List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
        // 优惠券领取记录
        List<TOrderPrivateCar> userCouponRecords = new ArrayList<>();
        List<TOrderLogistics> userCouponRecords1 = new ArrayList<>();
        // 红包领取记录
        List<TOrderPrivateCar> userRedPacketRecords = new ArrayList<>();
        List<TOrderLogistics> userRedPacketRecords1 = new ArrayList<>();
        // 司机消费
        List<BalanceUsageRecord> balanceUsageRecords = new ArrayList<>();
        // 司机提现
        List<TPubWithdrawal> driverWithdrawal = new ArrayList<>();
        Wrapper<TPubWithdrawal> driverWrapper = new EntityWrapper<TPubWithdrawal>()
                ;
        // 专车wrapper
        Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>()
                ;
        // 小件物流wrapper
        Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>()
                ;
        // 已使用优惠券记录wrapper
        Wrapper<TOrderPrivateCar> between2 = new EntityWrapper<TOrderPrivateCar>()
                ;
        Wrapper<TOrderLogistics> between22 = new EntityWrapper<TOrderLogistics>()
                ;
        // 已使用红包记录wrapper
        Wrapper<TOrderPrivateCar> between3 = new EntityWrapper<TOrderPrivateCar>()
                ;
        Wrapper<TOrderLogistics> between33 = new EntityWrapper<TOrderLogistics>()
                ;
        // 司机已消费金额
        Wrapper<BalanceUsageRecord> between4 = new EntityWrapper<BalanceUsageRecord>()
                ;
        if (time == 5 && insertTime==null){
            driverWrapper = new EntityWrapper<TPubWithdrawal>()
                    .eq("state", 2)
                    .eq("userType", 2)
                    ;
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney");
            // 小件物流wrapper
            between1 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney");
            // 已使用优惠券记录wrapper
           between2 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney");
            between22 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney");
            // 已使用红包记录wrapper
            between3 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney");
            between33 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney");
            // 司机已消费金额
            between4 = new EntityWrapper<BalanceUsageRecord>()
                    .ne("purpose", 6);
            // 司机提现
            driverWrapper = new EntityWrapper<TPubWithdrawal>()
                    .eq("state", 2)
                    .eq("userType", 2)
                    ;
        }else{
            driverWrapper = new EntityWrapper<TPubWithdrawal>()
                    .eq("state", 2)
                    .eq("userType", 2)
                    .between("insertTime", start, end);
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney")
                    .between("insertTime", start, end);
            // 小件物流wrapper
             between1 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney")
                    .between("insertTime", start, end);
            // 已使用优惠券记录wrapper
            between2 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney")
                    .between("insertTime", start, end);
            between22 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney")
                    .between("insertTime", start, end);
            // 已使用红包记录wrapper
            between3 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney")
                    .between("insertTime", start, end);
            between33 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney")
                    .between("insertTime", start, end);
            // 司机已消费金额
            between4 = new EntityWrapper<BalanceUsageRecord>()
                    .ne("purpose", 6)
                    .between("createTime", start, end);
            // 司机提现
        }
        // 司机提现wrapper
        if (type!=null){
            switch (type){
                case 1:
                    // 红包
                    userRedPacketRecords = orderPrivateCarService.selectList(between3);
                    userRedPacketRecords1 = orderLogisticsService.selectList(between33);
                    break;
                case 2:
                    userCouponRecords = orderPrivateCarService.selectList(between2);
                    userCouponRecords1 = orderLogisticsService.selectList(between22);
                    // 优惠券
                    break;
                case 3:
                    // 司机消费记录
                    balanceUsageRecords = balanceUsageRecordService.selectList(between4);
                    driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
                    break;
                case 4:
                    // 专车订单
                    tOrderPrivateCars = orderPrivateCarService.selectList(between);
                    // 小件物流订单
                    tOrderLogistics = orderLogisticsService.selectList(between1);
                    break;
            }
        }else{
            // 红包
            userRedPacketRecords = orderPrivateCarService.selectList(between3);
            userRedPacketRecords1 = orderLogisticsService.selectList(between33);
            // 优惠券
            userCouponRecords = orderPrivateCarService.selectList(between2);
            userCouponRecords1 = orderLogisticsService.selectList(between22);
            // 专车订单
            tOrderPrivateCars = orderPrivateCarService.selectList(between);
            // 小件物流订单
            tOrderLogistics = orderLogisticsService.selectList(between1);
            // 消费
            balanceUsageRecords = balanceUsageRecordService.selectList(between4);
            // 提现
            driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
        }
        // 已发放补贴总额
        BigDecimal total = new BigDecimal("0");
        // 已使用折扣总额(用户端)
        BigDecimal discount = new BigDecimal("0");
        // 已使用红包总额(用户端)
        BigDecimal redPackage = new BigDecimal("0");
        // 已使用优惠券总额(用户端)
        BigDecimal coupon = new BigDecimal("0");
        // 已使用司机奖励总额(司机端)
        BigDecimal driver = new BigDecimal("0");
        // 司机已消费
        BigDecimal driverConsume = new BigDecimal("0");
        // 司机已提现
        BigDecimal driverWithdrawal1 = new BigDecimal("0");
        // 查询已使用折扣总额
        for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+tOrderPrivateCar.getOrderNum());
            res.add(grantVO);
        }
        for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+tOrderPrivateCar.getOrderNum());
            res.add(grantVO);
        }
        // 查询已使用红包总额
        for (TOrderPrivateCar userRedPacketRecord : userRedPacketRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
            grantVO.setType("红包");
            JSONArray objects = JSONArray.parseArray(userRedPacketRecord.getRedPacketId());
            BigDecimal temp = new BigDecimal(BigInteger.ZERO);
            for (int i = 0; i < objects.size(); i++) {
                String string = objects.getJSONObject(i).getString("money");
                temp = temp.add(new BigDecimal(string));
            }
            grantVO.setAmount(temp.toString());
            TUser tUser = appUserService.selectById(userRedPacketRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userRedPacketRecord.getOrderNum());
            res.add(grantVO);
            redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getPayMoney().toString()));
        }
        for (TOrderLogistics userRedPacketRecord : userRedPacketRecords1) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
            grantVO.setType("红包");
            JSONArray objects = JSONArray.parseArray(userRedPacketRecord.getRedPacketId());
            BigDecimal temp = new BigDecimal(BigInteger.ZERO);
            for (int i = 0; i < objects.size(); i++) {
                String string = objects.getJSONObject(i).getString("money");
                temp = temp.add(new BigDecimal(string));
            }
            grantVO.setAmount(temp.toString());
            TUser tUser = appUserService.selectById(userRedPacketRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userRedPacketRecord.getOrderNum());
            res.add(grantVO);
            redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getPayMoney().toString()));
        }
        // 查询已领取优惠券总额
        for (TOrderPrivateCar userCouponRecord : userCouponRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            grantVO.setType("优惠券");
            grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
            TUser tUser = appUserService.selectById(userCouponRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userCouponRecord.getOrderNum());
            coupon = coupon.add(new BigDecimal(userCouponRecord.getPayMoney().toString()));
            res.add(grantVO);
        }
        for (TOrderLogistics userCouponRecord : userCouponRecords1) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            grantVO.setType("优惠券");
            grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
            TUser tUser = appUserService.selectById(userCouponRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userCouponRecord.getOrderNum());
            coupon = coupon.add(new BigDecimal(userCouponRecord.getPayMoney().toString()));
            res.add(grantVO);
        }
        // 司机消费奖励
        for (BalanceUsageRecord balanceUsageRecord : balanceUsageRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(balanceUsageRecord.getCreateTime()));
            grantVO.setType("司机奖励");
            grantVO.setAmount(balanceUsageRecord.getMoney().toString());
            TDriver tUser = driverService.selectById(balanceUsageRecord.getDriverId());
            if (tUser!=null){
                grantVO.setName(tUser.getFirstName()+tUser.getLastName());
            }
            switch (balanceUsageRecord.getPurpose()){
                case 1:
                    //打车支付
                    grantVO.setRemark("余额支付"+"【打车支付】");
                    break;
                case 2:
                    grantVO.setRemark("余额支付"+"【包裹支付】");
                    // 包裹支付
                    break;
                case 3:
                    grantVO.setRemark("余额支付"+"【日结算】");
                    // 日结算
                    break;
                case 4:
                    grantVO.setRemark("余额支付"+"【周结算】");
                    // 周结算
                    break;
                case 5:
                    grantVO.setRemark("余额支付"+"【月结算】");
                    // 月结算
                    break;
            }
            driverConsume = driverConsume.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
            res.add(grantVO);
        }
        // 司机提现
        for (TPubWithdrawal balanceUsageRecord : driverWithdrawal) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(balanceUsageRecord.getInsertTime()));
            grantVO.setType("司机奖励");
            grantVO.setAmount(balanceUsageRecord.getMoney().toString());
            TDriver tUser = driverService.selectById(balanceUsageRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getFirstName()+tUser.getLastName());
            }
            grantVO.setRemark("司机提现");
            driverWithdrawal1 = driverWithdrawal1.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
            res.add(grantVO);
        }
        // 总额
        total = total.add(redPackage).add(coupon).add(discount).add(driverConsume).add(driverWithdrawal1);
        // 已使用司机奖励合计
        driver = driverConsume.add(driverWithdrawal1);
        return res;
    }
    @RequestMapping(value = "/use/getCount")
    @ResponseBody
    public Object getCount1(Integer time,String insertTime,Integer type) {
        if (time == null){
            time = 1;
        }
        String beginTime = null;
        String endTime = null;
        LocalDateTime start =null;
        LocalDateTime end =null;
        // 获取当前日期
        LocalDate today = LocalDate.now();
        if (ToolUtil.isNotEmpty(insertTime)){
            beginTime = insertTime.split(" - ")[0];
            endTime = insertTime.split(" - ")[1];
            LocalDate s = LocalDate.parse(beginTime);
            LocalDate e = LocalDate.parse(endTime);
            start = s.atStartOfDay();
            end = e.atTime(LocalTime.MAX);
        }else if (time!=null) {
            switch (time) {
                case 1:
                    // 获取当天的 00:00:00 和 23:59:59
                    LocalDateTime startOfDay = today.atStartOfDay();
                    LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
                    start = startOfDay;
                    end = endOfDay;
                    break;
                case 2:
                    // 获取本周第一天的日期和时间
                    LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
                    LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
                    // 获取本周最后一天的日期和时间
                    LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
                    LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
                    start = startOfWeek;
                    end = endOfWeek;
                    break;
                case 3:
                    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
                    LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
                    // 获取本月最后一天的日期和时间
                    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
                    LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
                    start = startOfMonth;
                    end = endOfMonth;
                    break;
                case 4:
                    // 获取本年第一天的日期和时间
                    LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
                    LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
                    // 获取本年最后一天的日期和时间
                    LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
                    LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
                    start = startOfYear;
                    end = endOfYear;
                    break;
            }
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 列表res
        List<GrantVO> res = new ArrayList<>();
        // 专车订单
        List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
        // 小件物流
        List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
        // 优惠券领取记录
        List<TOrderPrivateCar> userCouponRecords = new ArrayList<>();
        List<TOrderLogistics> userCouponRecords1 = new ArrayList<>();
        // 红包领取记录
        List<TOrderPrivateCar> userRedPacketRecords = new ArrayList<>();
        List<TOrderLogistics> userRedPacketRecords1 = new ArrayList<>();
        // 司机消费
        List<BalanceUsageRecord> balanceUsageRecords = new ArrayList<>();
        // 司机提现
        List<TPubWithdrawal> driverWithdrawal = new ArrayList<>();
        Wrapper<TPubWithdrawal> driverWrapper = new EntityWrapper<TPubWithdrawal>()
                ;
        // 专车wrapper
        Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>()
                ;
        // 小件物流wrapper
        Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>()
                ;
        // 已使用优惠券记录wrapper
        Wrapper<TOrderPrivateCar> between2 = new EntityWrapper<TOrderPrivateCar>()
                ;
        Wrapper<TOrderLogistics> between22 = new EntityWrapper<TOrderLogistics>()
                ;
        // 已使用红包记录wrapper
        Wrapper<TOrderPrivateCar> between3 = new EntityWrapper<TOrderPrivateCar>()
                ;
        Wrapper<TOrderLogistics> between33 = new EntityWrapper<TOrderLogistics>()
                ;
        // 司机已消费金额
        Wrapper<BalanceUsageRecord> between4 = new EntityWrapper<BalanceUsageRecord>()
                ;
        // 司机提现
        Wrapper<TPubWithdrawal> between44 = new EntityWrapper<TPubWithdrawal>()
                ;
        if (time == 5 && insertTime==null){
            driverWrapper = new EntityWrapper<TPubWithdrawal>()
                    .eq("state", 2)
                    .eq("userType", 2)
            ;
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney");
            // 小件物流wrapper
            between1 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney");
            // 已使用优惠券记录wrapper
            between2 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney");
            between22 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney");
            // 已使用红包记录wrapper
            between3 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney");
            between33 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney");
            // 司机已消费金额
            between4 = new EntityWrapper<BalanceUsageRecord>()
                    .ne("purpose", 6);
        }else{
            driverWrapper = new EntityWrapper<TPubWithdrawal>()
                    .eq("state", 2)
                    .eq("userType", 2)
                    .between("insertTime", start, end);
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney")
                    .between("insertTime", start, end);
            // 小件物流wrapper
            between1 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("activityId")
                    .isNotNull("discountMoney")
                    .between("insertTime", start, end);
            // 已使用优惠券记录wrapper
            between2 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney")
                    .between("insertTime", start, end);
            between22 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("couponId")
                    .isNotNull("couponMoney")
                    .between("insertTime", start, end);
            // 已使用红包记录wrapper
            between3 = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney")
                    .between("insertTime", start, end);
            between33 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("redPacketId")
                    .isNotNull("redPacketMoney")
                    .between("insertTime", start, end);
            // 司机已消费金额
            between4 = new EntityWrapper<BalanceUsageRecord>()
                    .ne("purpose", 6)
                    .between("createTime", start, end);
        }
        if (type!=null){
            switch (type){
                case 1:
                    // 红包
                    userRedPacketRecords = orderPrivateCarService.selectList(between3);
                    userRedPacketRecords1 = orderLogisticsService.selectList(between33);
                    break;
                case 2:
                    userCouponRecords = orderPrivateCarService.selectList(between2);
                    userCouponRecords1 = orderLogisticsService.selectList(between22);
                    // 优惠券
                    break;
                case 3:
                    // 司机消费记录
                    balanceUsageRecords = balanceUsageRecordService.selectList(between4);
                    driverWithdrawal = pubWithdrawalService.selectList(driverWrapper);
                    break;
                case 4:
                    // 专车订单
                    tOrderPrivateCars = orderPrivateCarService.selectList(between);
                    // 小件物流订单
                    tOrderLogistics = orderLogisticsService.selectList(between1);
                    break;
            }
        }else{
            // 红包
            userRedPacketRecords = orderPrivateCarService.selectList(between3);
            userRedPacketRecords1 = orderLogisticsService.selectList(between33);
            // 优惠券
            userCouponRecords = orderPrivateCarService.selectList(between2);
            userCouponRecords1 = orderLogisticsService.selectList(between22);
            // 专车订单
            tOrderPrivateCars = orderPrivateCarService.selectList(between);
            // 小件物流订单
            tOrderLogistics = orderLogisticsService.selectList(between1);
            // 消费
            balanceUsageRecords = balanceUsageRecordService.selectList(between4);
            // 提现
            driverWithdrawal = pubWithdrawalService.selectList(between44);
        }
        // 已发放补贴总额
        BigDecimal total = new BigDecimal("0");
        // 已使用折扣总额(用户端)
        BigDecimal discount = new BigDecimal("0");
        // 已使用红包总额(用户端)
        BigDecimal redPackage = new BigDecimal("0");
        // 已使用优惠券总额(用户端)
        BigDecimal coupon = new BigDecimal("0");
        // 已使用司机奖励总额(司机端)
        BigDecimal driver = new BigDecimal("0");
        // 司机已消费
        BigDecimal driverConsume = new BigDecimal("0");
        // 司机已提现
        BigDecimal driverWithdrawal1 = new BigDecimal("0");
        // 查询已使用折扣总额
        for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
            if (tOrderPrivateCar.getState() != 9 &&tOrderPrivateCar.getState() != 8){
                continue;
            }
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+tOrderPrivateCar.getOrderNum());
            res.add(grantVO);
        }
        for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
            if (tOrderPrivateCar.getState() != 9 &&tOrderPrivateCar.getState() != 8){
                continue;
            }
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+tOrderPrivateCar.getOrderNum());
            res.add(grantVO);
        }
        // 查询已领取红包总额
        for (TOrderPrivateCar userRedPacketRecord : userRedPacketRecords) {
            if (userRedPacketRecord.getState() != 9 &&userRedPacketRecord.getState() != 8){
                continue;
            }
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
            grantVO.setType("红包");
            JSONArray objects = JSONArray.parseArray(userRedPacketRecord.getRedPacketId());
            BigDecimal temp = new BigDecimal(BigInteger.ZERO);
            for (int i = 0; i < objects.size(); i++) {
                String string = objects.getJSONObject(i).getString("money");
                temp = temp.add(new BigDecimal(string));
            }
            grantVO.setAmount(temp.toString());
            TUser tUser = appUserService.selectById(userRedPacketRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userRedPacketRecord.getOrderNum());
            res.add(grantVO);
            redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getPayMoney().toString()));
        }
        for (TOrderLogistics userRedPacketRecord : userRedPacketRecords1) {
            if (userRedPacketRecord.getState() != 9 &&userRedPacketRecord.getState() != 8){
                continue;
            }
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
            grantVO.setType("红包");
            JSONArray objects = JSONArray.parseArray(userRedPacketRecord.getRedPacketId());
            BigDecimal temp = new BigDecimal(BigInteger.ZERO);
            for (int i = 0; i < objects.size(); i++) {
                String string = objects.getJSONObject(i).getString("money");
                temp = temp.add(new BigDecimal(string));
            }
            grantVO.setAmount(temp.toString());
            TUser tUser = appUserService.selectById(userRedPacketRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userRedPacketRecord.getOrderNum());
            res.add(grantVO);
            redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getPayMoney().toString()));
        }
        // 查询已领取优惠券总额
        for (TOrderPrivateCar userCouponRecord : userCouponRecords) {
            if (userCouponRecord.getState() != 9 &&userCouponRecord.getState() != 8){
                continue;
            }
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            grantVO.setType("优惠券");
            grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
            TUser tUser = appUserService.selectById(userCouponRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userCouponRecord.getOrderNum());
            coupon = coupon.add(new BigDecimal(userCouponRecord.getPayMoney().toString()));
            res.add(grantVO);
        }
        for (TOrderLogistics userCouponRecord : userCouponRecords1) {
            if (userCouponRecord.getState() != 9 &&userCouponRecord.getState() != 8){
                continue;
            }
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            grantVO.setType("优惠券");
            grantVO.setAmount(userCouponRecord.getCouponMoney().toString());
            TUser tUser = appUserService.selectById(userCouponRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            grantVO.setRemark("订单号:"+userCouponRecord.getOrderNum());
            coupon = coupon.add(new BigDecimal(userCouponRecord.getPayMoney().toString()));
            res.add(grantVO);
        }
        // 司机消费奖励
        for (BalanceUsageRecord balanceUsageRecord : balanceUsageRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(balanceUsageRecord.getCreateTime()));
            grantVO.setType("司机奖励");
            grantVO.setAmount(balanceUsageRecord.getMoney().toString());
            TDriver tUser = driverService.selectById(balanceUsageRecord.getDriverId());
            if (tUser!=null){
                grantVO.setName(tUser.getFirstName()+tUser.getLastName());
            }
            switch (balanceUsageRecord.getPurpose()){
                case 1:
                    //打车支付
                    grantVO.setRemark("余额支付"+"【打车支付】");
                    break;
                case 2:
                    grantVO.setRemark("余额支付"+"【包裹支付】");
                    // 包裹支付
                    break;
                case 3:
                    grantVO.setRemark("余额支付"+"【日结算】");
                    // 日结算
                    break;
                case 4:
                    grantVO.setRemark("余额支付"+"【周结算】");
                    // 周结算
                    break;
                case 5:
                    grantVO.setRemark("余额支付"+"【月结算】");
                    // 月结算
                    break;
            }
            driverConsume = driverConsume.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
            res.add(grantVO);
        }
        // 司机提现
        for (TPubWithdrawal balanceUsageRecord : driverWithdrawal) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(balanceUsageRecord.getInsertTime()));
            grantVO.setType("司机奖励");
            grantVO.setAmount(balanceUsageRecord.getMoney().toString());
            TDriver tUser = driverService.selectById(balanceUsageRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getFirstName()+tUser.getLastName());
            }
            grantVO.setRemark("司机提现");
            driverWithdrawal1 = driverWithdrawal1.add(new BigDecimal(balanceUsageRecord.getMoney().toString()));
            res.add(grantVO);
        }
        // 总额
        total = total.add(redPackage).add(coupon).add(discount).add(driverConsume).add(driverWithdrawal1);
        // 已使用司机奖励合计
        driver = driverConsume.add(driverWithdrawal1);
        UseMoneyVO useMoneyVO = new UseMoneyVO();
        useMoneyVO.setTotal(total);
        useMoneyVO.setDiscount(discount);
        useMoneyVO.setRedPackage(redPackage);
        useMoneyVO.setCoupon(coupon);
        useMoneyVO.setDriver(driver);
        useMoneyVO.setDriverWithdrawal(driverWithdrawal1);
        useMoneyVO.setDriverConsume(driverConsume);
        return useMoneyVO;
    }
    /**
     * 发放补贴统计
     */
    @RequestMapping(value = "/grant/list")
    @ResponseBody
    public Object list(Integer time,String insertTime,Integer type) {
        if (time == null){
            time = 1;
        }
        String beginTime = null;
        String endTime = null;
        LocalDateTime start =null;
        LocalDateTime end =null;
        // 获取当前日期
        LocalDate today = LocalDate.now();
        if (ToolUtil.isNotEmpty(insertTime)){
            beginTime = insertTime.split(" - ")[0];
            endTime = insertTime.split(" - ")[1];
            LocalDate s = LocalDate.parse(beginTime);
            LocalDate e = LocalDate.parse(endTime);
            start = s.atStartOfDay();
            end = e.atTime(LocalTime.MAX);
        }else if (time!=null) {
            switch (time) {
                case 1:
                    // 获取当天的 00:00:00 和 23:59:59
                    LocalDateTime startOfDay = today.atStartOfDay();
                    LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
                    start = startOfDay;
                    end = endOfDay;
                    break;
                case 2:
                    // 获取本周第一天的日期和时间
                    LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
                    LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
                    // 获取本周最后一天的日期和时间
                    LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
                    LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
                    start = startOfWeek;
                    end = endOfWeek;
                    break;
                case 3:
                    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
                    LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
                    // 获取本月最后一天的日期和时间
                    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
                    LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
                    start = startOfMonth;
                    end = endOfMonth;
                    break;
                case 4:
                    // 获取本年第一天的日期和时间
                    LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
                    LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
                    // 获取本年最后一天的日期和时间
                    LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
                    LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
                    start = startOfYear;
                    end = endOfYear;
                    break;
            }
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 列表res
        List<GrantVO> res = new ArrayList<>();
        // 专车订单
        List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
        // 小件物流
        List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
        // 优惠券领取记录
        List<UserCouponRecord> userCouponRecords = new ArrayList<>();
        // 红包领取记录
        List<UserRedPacketRecord> userRedPacketRecords = new ArrayList<>();
        // 司机奖励
        List<DriverActivityHistory> driverActivityHistories = new ArrayList<>();
        // 专车wrapper
        Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>()
                ;
        // 小件物流wrapper
        Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>()
                ;
        // 优惠券领取记录wrapper
        Wrapper<UserCouponRecord> between2 = new EntityWrapper<UserCouponRecord>()
                ;
        // 红包领取记录wrapper
        Wrapper<UserRedPacketRecord> between3 = new EntityWrapper<UserRedPacketRecord>()
                ;
        // 司机奖励
        Wrapper<DriverActivityHistory> between4 = new EntityWrapper<DriverActivityHistory>()
                ;
        if (time == 5 && insertTime==null){
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("discountMoney")
                    ;
            // 小件物流wrapper
           between1 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("discountMoney")
                    ;
            // 优惠券领取记录wrapper
            between2 = new EntityWrapper<UserCouponRecord>()
                    .ne("couponUseType", 2)
                    .ne("couponUseType", 3)
                    ;
            // 红包领取记录wrapper
            between3 = new EntityWrapper<UserRedPacketRecord>()
                    ;
            // 司机奖励
            between4 = new EntityWrapper<DriverActivityHistory>()
                    .eq("carryOut", 2)
                    ;
        }else{
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("discountMoney")
                    .between("insertTime", start, end)
            ;
            // 小件物流wrapper
            between1 = new EntityWrapper<TOrderLogistics>()
                    .between("insertTime", start, end)
                    .isNotNull("discountMoney")
            ;
            // 优惠券领取记录wrapper
            between2 = new EntityWrapper<UserCouponRecord>()
                    .ne("couponUseType", 2)
                    .ne("couponUseType", 3)
                    .between("insertTime", start, end);
            // 红包领取记录wrapper
            between3 = new EntityWrapper<UserRedPacketRecord>()
                    .between("insertTime", start, end);
            // 司机奖励
            between4 = new EntityWrapper<DriverActivityHistory>()
                    .eq("carryOut", 2)
                    .between("insertTime", start, end);
        }
        if (type!=null){
            switch (type){
                case 1:
                    // 红包
                    userRedPacketRecords = userRedPacketRecordService.selectList(between3);
                    break;
                case 2:
                    userCouponRecords = userCouponRecordService.selectList(between2);
                    // 优惠券
                    break;
                case 3:
                    // 司机奖励
                    driverActivityHistories = driverActivityHistoryService.selectList(between4);
                    break;
                case 4:
                    // 专车订单
                    tOrderPrivateCars = orderPrivateCarService.selectList(between);
                    // 小件物流订单
                    tOrderLogistics = orderLogisticsService.selectList(between1);
                    break;
            }
        }else{
            // 专车订单
            tOrderPrivateCars = orderPrivateCarService.selectList(between);
            // 小件物流订单
            tOrderLogistics = orderLogisticsService.selectList(between1);
            // 司机奖励
            driverActivityHistories = driverActivityHistoryService.selectList(between4);
            userCouponRecords = userCouponRecordService.selectList(between2);
            userRedPacketRecords = userRedPacketRecordService.selectList(between3);
        }
        // 已发放补贴总额
        BigDecimal total = new BigDecimal("0");
        // 已使用折扣总额(用户端)
        BigDecimal discount = new BigDecimal("0");
        // 已领取红包总额(用户端)
        BigDecimal redPackage = new BigDecimal("0");
        // 已领取优惠券总额(用户端)
        BigDecimal coupon = new BigDecimal("0");
        // 已领取司机奖励总额(司机端)
        BigDecimal driver = new BigDecimal("0");
        // 查询已使用折扣总额
        for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
            if (tOrderPrivateCar.getDiscountMoney()==null || tOrderPrivateCar.getDiscountMoney() == 0){
                continue;
            }
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            UserActivityDiscount1 userActivityDiscount1 = userActivityDiscount1Service.selectById(tOrderPrivateCar.getActivityId());
            if (userActivityDiscount1!=null){
                UserActivity userActivity = userActivityService.selectById(userActivityDiscount1.getUserActivityId());
                if (userActivity!=null){
                    grantVO.setRemark(userActivity.getName());
                }
            }
            res.add(grantVO);
        }
        for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
            if (tOrderPrivateCar.getDiscountMoney()==null || tOrderPrivateCar.getDiscountMoney() == 0){
                continue;
            }
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            UserActivityDiscount1 userActivityDiscount1 = userActivityDiscount1Service.selectById(tOrderPrivateCar.getActivityId());
            if (userActivityDiscount1!=null){
                UserActivity userActivity = userActivityService.selectById(userActivityDiscount1.getUserActivityId());
                if (userActivity!=null){
                    grantVO.setRemark(userActivity.getName());
                }
            }
            res.add(grantVO);
        }
        // 查询已领取红包总额
        for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
            grantVO.setType("红包");
            grantVO.setAmount(userRedPacketRecord.getMoney().toString());
            TUser tUser = appUserService.selectById(userRedPacketRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            UserActivityRedenvelope userActivityRedenvelope =
                    userActivityRedenvelopeService.selectById(userRedPacketRecord.getRedPacketActivityId());
            if (userActivityRedenvelope!=null){
                UserActivity userActivity = userActivityService.selectById(userActivityRedenvelope.getUserActivityId());
                if (userActivity!=null){
                    grantVO.setRemark(userActivity.getName());
                }
            }
            res.add(grantVO);
            redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getMoney().toString()));
        }
        // 查询已领取优惠券总额
        for (UserCouponRecord userCouponRecord : userCouponRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            grantVO.setType("优惠券");
            grantVO.setAmount(userCouponRecord.getMoney().toString());
            TUser tUser = appUserService.selectById(userCouponRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            SysCouponRecord sysCouponRecord =
                    sysCouponRecordService.selectById(userCouponRecord.getCouponId());
            if (sysCouponRecord!=null){
                grantVO.setRemark(sysCouponRecord.getName());
            }
            coupon = coupon.add(new BigDecimal(userCouponRecord.getMoney().toString()));
            res.add(grantVO);
        }
        // 已领取司机奖励
        for (DriverActivityHistory driverActivityHistory : driverActivityHistories) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(driverActivityHistory.getInsertTime()));
            grantVO.setType("司机奖励");
            grantVO.setAmount(driverActivityHistory.getMoney().toString());
            TDriver tDriver = driverService.selectById(driverActivityHistory.getDriverId());
            if (tDriver!=null){
                grantVO.setName(tDriver.getFirstName()+tDriver.getLastName());
            }
            Integer type1 = driverActivityHistory.getType();
            switch (type1){
                case 1:
                    grantVO.setRemark("邀请司机注册");
                    break;
                case 2:
                    grantVO.setRemark("邀请用户注册");
                    break;
                case 3:
                    grantVO.setRemark("累计在线");
                    break;
                case 4:
                    grantVO.setRemark("订单量");
                    break;
            }
            driver = driver.add(new BigDecimal(driverActivityHistory.getMoney().toString()));
            res.add(grantVO);
        }
        total = total.add(redPackage).add(coupon).add(discount).add(driver);
        return res;
    }
    @RequestMapping(value = "/grant/getCount")
    @ResponseBody
    public Object getCount(Integer time,String insertTime,Integer type) {
        GrantMoneyVO result = new GrantMoneyVO();
        if (time == null){
            time = 1;
        }
        String beginTime = null;
        String endTime = null;
        LocalDateTime start =null;
        LocalDateTime end =null;
        // 获取当前日期
        LocalDate today = LocalDate.now();
        if (ToolUtil.isNotEmpty(insertTime)){
            beginTime = insertTime.split(" - ")[0];
            endTime = insertTime.split(" - ")[1];
            LocalDate s = LocalDate.parse(beginTime);
            LocalDate e = LocalDate.parse(endTime);
            start = s.atStartOfDay();
            end = e.atTime(LocalTime.MAX);
        }else if (time!=null) {
            switch (time) {
                case 1:
                    // 获取当天的 00:00:00 和 23:59:59
                    LocalDateTime startOfDay = today.atStartOfDay();
                    LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
                    start = startOfDay;
                    end = endOfDay;
                    break;
                case 2:
                    // 获取本周第一天的日期和时间
                    LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
                    LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
                    // 获取本周最后一天的日期和时间
                    LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
                    LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
                    start = startOfWeek;
                    end = endOfWeek;
                    break;
                case 3:
                    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
                    LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
                    // 获取本月最后一天的日期和时间
                    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
                    LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
                    start = startOfMonth;
                    end = endOfMonth;
                    break;
                case 4:
                    // 获取本年第一天的日期和时间
                    LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
                    LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
                    // 获取本年最后一天的日期和时间
                    LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
                    LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
                    start = startOfYear;
                    end = endOfYear;
                    break;
            }
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 列表res
        List<GrantVO> res = new ArrayList<>();
        // 专车订单
        List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
        // 小件物流
        List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
        // 优惠券领取记录
        List<UserCouponRecord> userCouponRecords = new ArrayList<>();
        // 红包领取记录
        List<UserRedPacketRecord> userRedPacketRecords = new ArrayList<>();
        // 司机奖励
        List<DriverActivityHistory> driverActivityHistories = new ArrayList<>();
        // 专车wrapper
        Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>()
                ;
        // 小件物流wrapper
        Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>()
                ;
        // 优惠券领取记录wrapper
        Wrapper<UserCouponRecord> between2 = new EntityWrapper<UserCouponRecord>()
                ;
        // 红包领取记录wrapper
        Wrapper<UserRedPacketRecord> between3 = new EntityWrapper<UserRedPacketRecord>()
                ;
        // 司机奖励
        Wrapper<DriverActivityHistory> between4 = new EntityWrapper<DriverActivityHistory>()
                ;
        if (time == 5 && insertTime==null){
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("discountMoney")
            ;
            // 小件物流wrapper
            between1 = new EntityWrapper<TOrderLogistics>()
                    .isNotNull("discountMoney")
            ;
            // 优惠券领取记录wrapper
            between2 = new EntityWrapper<UserCouponRecord>()
                    .ne("couponUseType", 2)
                    .ne("couponUseType", 3)
            ;
            // 红包领取记录wrapper
            between3 = new EntityWrapper<UserRedPacketRecord>()
            ;
            // 司机奖励
            between4 = new EntityWrapper<DriverActivityHistory>()
                    .eq("carryOut", 2)
            ;
        }else{
            // 专车wrapper
            between = new EntityWrapper<TOrderPrivateCar>()
                    .isNotNull("discountMoney")
                    .between("insertTime", start, end)
            ;
            // 小件物流wrapper
            between1 = new EntityWrapper<TOrderLogistics>()
                    .between("insertTime", start, end)
                    .isNotNull("discountMoney")
            ;
            // 优惠券领取记录wrapper
            between2 = new EntityWrapper<UserCouponRecord>()
                    .ne("couponUseType", 2)
                    .ne("couponUseType", 3)
                    .between("insertTime", start, end);
            // 红包领取记录wrapper
            between3 = new EntityWrapper<UserRedPacketRecord>()
                    .between("insertTime", start, end);
            // 司机奖励
            between4 = new EntityWrapper<DriverActivityHistory>()
                    .eq("carryOut", 2)
                    .between("insertTime", start, end);
        }
        if (type!=null){
            switch (type){
                case 1:
                    // 红包
                    userRedPacketRecords = userRedPacketRecordService.selectList(between3);
                    break;
                case 2:
                    userCouponRecords = userCouponRecordService.selectList(between2);
                    // 优惠券
                    break;
                case 3:
                    // 司机奖励
                    driverActivityHistories = driverActivityHistoryService.selectList(between4);
                    break;
                case 4:
                    // 专车订单
                    tOrderPrivateCars = orderPrivateCarService.selectList(between);
                    // 小件物流订单
                    tOrderLogistics = orderLogisticsService.selectList(between1);
                    break;
            }
        }else{
            // 专车订单
            tOrderPrivateCars = orderPrivateCarService.selectList(between);
            // 小件物流订单
            tOrderLogistics = orderLogisticsService.selectList(between1);
            // 司机奖励
            driverActivityHistories = driverActivityHistoryService.selectList(between4);
            userCouponRecords = userCouponRecordService.selectList(between2);
            userRedPacketRecords = userRedPacketRecordService.selectList(between3);
        }
        // 已发放补贴总额
        BigDecimal total = new BigDecimal("0");
        // 已使用折扣总额(用户端)
        BigDecimal discount = new BigDecimal("0");
        // 已领取红包总额(用户端)
        BigDecimal redPackage = new BigDecimal("0");
        // 已领取优惠券总额(用户端)
        BigDecimal coupon = new BigDecimal("0");
        // 已领取司机奖励总额(司机端)
        BigDecimal driver = new BigDecimal("0");
        // 查询已使用折扣总额
        for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
            if (tOrderPrivateCar.getDiscountMoney()== null){
                continue;
            }
            if (tOrderPrivateCar.getState() != 9 &&tOrderPrivateCar.getState() != 8){
                continue;
            }
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            UserActivityDiscount1 userActivityDiscount1 = userActivityDiscount1Service.selectById(tOrderPrivateCar.getActivityId());
            if (userActivityDiscount1!=null){
                UserActivity userActivity = userActivityService.selectById(userActivityDiscount1.getUserActivityId());
                if (userActivity!=null){
                    grantVO.setRemark(userActivity.getName());
                }
            }
            res.add(grantVO);
        }
        for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
            if (tOrderPrivateCar.getDiscountMoney()== null){
                continue;
            }
            if (tOrderPrivateCar.getState() != 9 &&tOrderPrivateCar.getState() != 8){
                continue;
            }
            discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
            grantVO.setType("折扣");
            grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
            TUser tUser = appUserService.selectById(tOrderPrivateCar.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            UserActivityDiscount1 userActivityDiscount1 = userActivityDiscount1Service.selectById(tOrderPrivateCar.getActivityId());
            if (userActivityDiscount1!=null){
                UserActivity userActivity = userActivityService.selectById(userActivityDiscount1.getUserActivityId());
                if (userActivity!=null){
                    grantVO.setRemark(userActivity.getName());
                }
            }
            res.add(grantVO);
        }
        // 查询已领取红包总额
        for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
            grantVO.setType("红包");
            grantVO.setAmount(userRedPacketRecord.getMoney().toString());
            TUser tUser = appUserService.selectById(userRedPacketRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            UserActivityRedenvelope userActivityRedenvelope =
                    userActivityRedenvelopeService.selectById(userRedPacketRecord.getRedPacketActivityId());
            if (userActivityRedenvelope!=null){
                UserActivity userActivity = userActivityService.selectById(userActivityRedenvelope.getUserActivityId());
                if (userActivity!=null){
                    grantVO.setRemark(userActivity.getName());
                }
            }
            res.add(grantVO);
            redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getMoney().toString()));
        }
        // 查询已领取优惠券总额
        for (UserCouponRecord userCouponRecord : userCouponRecords) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
            grantVO.setType("优惠券");
            grantVO.setAmount(userCouponRecord.getMoney().toString());
            TUser tUser = appUserService.selectById(userCouponRecord.getUserId());
            if (tUser!=null){
                grantVO.setName(tUser.getNickName());
            }
            SysCouponRecord sysCouponRecord =
                    sysCouponRecordService.selectById(userCouponRecord.getCouponId());
            if (sysCouponRecord!=null){
                grantVO.setRemark(sysCouponRecord.getName());
            }
            coupon = coupon.add(new BigDecimal(userCouponRecord.getMoney().toString()));
            res.add(grantVO);
        }
        // 已领取司机奖励
        for (DriverActivityHistory driverActivityHistory : driverActivityHistories) {
            GrantVO grantVO = new GrantVO();
            grantVO.setInsertTime(format.format(driverActivityHistory.getInsertTime()));
            grantVO.setType("司机奖励");
            grantVO.setAmount(driverActivityHistory.getMoney().toString());
            TDriver tDriver = driverService.selectById(driverActivityHistory.getDriverId());
            if (tDriver!=null){
                grantVO.setName(tDriver.getFirstName()+tDriver.getLastName());
            }
            Integer type1 = driverActivityHistory.getType();
            switch (type1){
                case 1:
                    grantVO.setRemark("邀请司机注册");
                    break;
                case 2:
                    grantVO.setRemark("邀请用户注册");
                    break;
                case 3:
                    grantVO.setRemark("累计在线");
                    break;
                case 4:
                    grantVO.setRemark("订单量");
                    break;
            }
            driver = driver.add(new BigDecimal(driverActivityHistory.getMoney().toString()));
            res.add(grantVO);
        }
        total = total.add(redPackage).add(coupon).add(discount).add(driver);
        result.setTotal(total);
        result.setDiscount(discount);
        result.setCoupon(coupon);
        result.setDriver(driver);
        result.setRedPackage(redPackage);
        return result;
    }
         grantVO.setAmount(userCouponRecord.getMoney().toString());
         TUser tUser = userMap.get(userCouponRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         SysCouponActivity sysCouponActivity = sysCouponActivityMap.get(userCouponRecord.getCouponActivityId());
         if (sysCouponActivity != null) {
            grantVO.setRemark(sysCouponActivity.getName());
         }
         coupon = coupon.add(new BigDecimal(userCouponRecord.getMoney().toString()));
         res.add(grantVO);
      }
      // 已领取司机奖励
      for (DriverActivityHistory driverActivityHistory : driverActivityHistories) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(null == driverActivityHistory.getCompletionTime() ? format.format(driverActivityHistory.getInsertTime()) : format.format(driverActivityHistory.getCompletionTime()));
         grantVO.setType("司机奖励");
         grantVO.setAmount(driverActivityHistory.getMoney().toString());
         TDriver tDriver = driverMap.get(driverActivityHistory.getDriverId());
         if (tDriver != null) {
            grantVO.setName(tDriver.getFirstName() + tDriver.getLastName());
         }
         Integer type1 = driverActivityHistory.getType();
         switch (type1) {
            case 1:
               grantVO.setRemark("邀请司机注册");
               break;
            case 2:
               grantVO.setRemark("邀请用户注册");
               break;
            case 3:
               grantVO.setRemark("在线时长奖励");
               break;
            case 4:
               grantVO.setRemark("累计接单奖励");
               break;
         }
         driver = driver.add(new BigDecimal(driverActivityHistory.getMoney().toString()));
         res.add(grantVO);
      }
      List<GrantVO> sortedList = res.stream()
            .sorted((o1, o2) -> o2.getInsertTime().compareTo(o1.getInsertTime()))
            .collect(Collectors.toList());
      total = total.add(redPackage).add(coupon).add(discount).add(driver);
      return sortedList;
   }
   @RequestMapping(value = "/grant/getCount")
   @ResponseBody
   public Object getCount(Integer time, String insertTime, Integer type) {
      GrantMoneyVO result = new GrantMoneyVO();
      if (time == null) {
         time = 1;
      }
      String beginTime = null;
      String endTime = null;
      LocalDateTime start = null;
      LocalDateTime end = null;
      // 获取当前日期
      LocalDate today = LocalDate.now();
      if (ToolUtil.isNotEmpty(insertTime)) {
         beginTime = insertTime.split(" - ")[0];
         endTime = insertTime.split(" - ")[1];
         LocalDate s = LocalDate.parse(beginTime);
         LocalDate e = LocalDate.parse(endTime);
         start = s.atStartOfDay();
         end = e.atTime(LocalTime.MAX);
      } else if (time != null) {
         switch (time) {
            case 1:
               // 获取当天的 00:00:00 和 23:59:59
               LocalDateTime startOfDay = today.atStartOfDay();
               LocalDateTime endOfDay = today.atTime(LocalTime.MAX);
               start = startOfDay;
               end = endOfDay;
               break;
            case 2:
               // 获取本周第一天的日期和时间
               LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
               LocalDateTime startOfWeek = firstDayOfWeek.atStartOfDay();
               // 获取本周最后一天的日期和时间
               LocalDate lastDayOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
               LocalDateTime endOfWeek = lastDayOfWeek.atTime(LocalTime.MAX);
               start = startOfWeek;
               end = endOfWeek;
               break;
            case 3:
               LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
               LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
               // 获取本月最后一天的日期和时间
               LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
               LocalDateTime endOfMonth = lastDayOfMonth.atTime(LocalTime.MAX);
               start = startOfMonth;
               end = endOfMonth;
               break;
            case 4:
               // 获取本年第一天的日期和时间
               LocalDate firstDayOfYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
               LocalDateTime startOfYear = firstDayOfYear.atStartOfDay();
               // 获取本年最后一天的日期和时间
               LocalDate lastDayOfYear = LocalDate.of(today.getYear(), Month.DECEMBER, 31);
               LocalDateTime endOfYear = lastDayOfYear.atTime(LocalTime.MAX);
               start = startOfYear;
               end = endOfYear;
               break;
         }
      }
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      // 列表res
      List<GrantVO> res = new ArrayList<>();
      // 专车订单
      List<TOrderPrivateCar> tOrderPrivateCars = new ArrayList<>();
      // 小件物流
      List<TOrderLogistics> tOrderLogistics = new ArrayList<>();
      // 优惠券领取记录
      List<UserCouponRecord> userCouponRecords = new ArrayList<>();
      // 红包领取记录
      List<UserRedPacketRecord> userRedPacketRecords = new ArrayList<>();
      // 司机奖励
      List<DriverActivityHistory> driverActivityHistories = new ArrayList<>();
      // 专车wrapper
      Wrapper<TOrderPrivateCar> between = new EntityWrapper<TOrderPrivateCar>();
      // 小件物流wrapper
      Wrapper<TOrderLogistics> between1 = new EntityWrapper<TOrderLogistics>();
      // 优惠券领取记录wrapper
      Wrapper<UserCouponRecord> between2 = new EntityWrapper<UserCouponRecord>();
      // 红包领取记录wrapper
      Wrapper<UserRedPacketRecord> between3 = new EntityWrapper<UserRedPacketRecord>();
      // 司机奖励
      Wrapper<DriverActivityHistory> between4 = new EntityWrapper<DriverActivityHistory>();
      if (time == 5 && !StringUtils.hasLength(insertTime)) {
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("discountMoney")
         ;
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .isNotNull("discountMoney")
         ;
         // 优惠券领取记录wrapper
         between2 = new EntityWrapper<UserCouponRecord>()
               .ne("couponUseType", 2)
               .ne("couponUseType", 3)
         ;
         // 红包领取记录wrapper
         between3 = new EntityWrapper<UserRedPacketRecord>()
               .ne("state", 0)
         ;
         // 司机奖励
         between4 = new EntityWrapper<DriverActivityHistory>()
               .eq("carryOut", 2)
         ;
      } else {
         // 专车wrapper
         between = new EntityWrapper<TOrderPrivateCar>()
               .isNotNull("discountMoney")
               .between("insertTime", start, end)
         ;
         // 小件物流wrapper
         between1 = new EntityWrapper<TOrderLogistics>()
               .between("insertTime", start, end)
               .isNotNull("discountMoney")
         ;
         // 优惠券领取记录wrapper
         between2 = new EntityWrapper<UserCouponRecord>()
               .ne("couponUseType", 2)
               .ne("couponUseType", 3)
               .between("insertTime", start, end);
         // 红包领取记录wrapper
         between3 = new EntityWrapper<UserRedPacketRecord>()
               .ne("state", 0)
               .between("insertTime", start, end);
         // 司机奖励
         between4 = new EntityWrapper<DriverActivityHistory>()
               .eq("carryOut", 2)
               .between("insertTime", start, end);
      }
      if (type != null) {
         switch (type) {
            case 1:
               // 红包
               userRedPacketRecords = userRedPacketRecordService.selectList(between3);
               break;
            case 2:
               userCouponRecords = userCouponRecordService.selectList(between2);
               // 优惠券
               break;
            case 3:
               // 司机奖励
               driverActivityHistories = driverActivityHistoryService.selectList(between4);
               break;
            case 4:
               // 专车订单
               tOrderPrivateCars = orderPrivateCarService.selectList(between);
               // 小件物流订单
               tOrderLogistics = orderLogisticsService.selectList(between1);
               break;
         }
      } else {
         // 专车订单
         tOrderPrivateCars = orderPrivateCarService.selectList(between);
         // 小件物流订单
         tOrderLogistics = orderLogisticsService.selectList(between1);
         // 司机奖励
         driverActivityHistories = driverActivityHistoryService.selectList(between4);
         userCouponRecords = userCouponRecordService.selectList(between2);
         userRedPacketRecords = userRedPacketRecordService.selectList(between3);
      }
      // 已发放补贴总额
      BigDecimal total = new BigDecimal("0");
      // 已使用折扣总额(用户端)
      BigDecimal discount = new BigDecimal("0");
      // 已领取红包总额(用户端)
      BigDecimal redPackage = new BigDecimal("0");
      // 已领取优惠券总额(用户端)
      BigDecimal coupon = new BigDecimal("0");
      // 已领取司机奖励总额(司机端)
      BigDecimal driver = new BigDecimal("0");
      Map<Integer, TUser> userMap = appUserService.selectList(new EntityWrapper<TUser>())
            .stream()
            .collect(Collectors.toMap(TUser::getId, user -> user));
      Map<Integer, TDriver> driverMap = driverService.selectList(new EntityWrapper<TDriver>())
            .stream()
            .collect(Collectors.toMap(TDriver::getId, user -> user));
      Map<Integer, UserActivity> userActivityMap = userActivityService.selectList(new EntityWrapper<UserActivity>())
            .stream()
            .collect(Collectors.toMap(UserActivity::getId, user -> user));
      Map<Integer, UserActivityDiscount1> userActivityDiscountMap = userActivityDiscount1Service.selectList(new EntityWrapper<UserActivityDiscount1>())
            .stream()
            .collect(Collectors.toMap(UserActivityDiscount1::getId, user -> user));
      Map<Integer, UserActivityRedenvelope> userActivityRedenvelopeMap = userActivityRedenvelopeService.selectList(new EntityWrapper<UserActivityRedenvelope>())
            .stream()
            .collect(Collectors.toMap(UserActivityRedenvelope::getId, user -> user));
      Map<Integer, SysCouponActivity> sysCouponActivityMap = sysCouponActivityService.selectList(new EntityWrapper<SysCouponActivity>())
            .stream()
            .collect(Collectors.toMap(SysCouponActivity::getId, user -> user));
      // 查询已使用折扣总额
      for (TOrderPrivateCar tOrderPrivateCar : tOrderPrivateCars) {
         if (tOrderPrivateCar.getDiscountMoney() == null || tOrderPrivateCar.getDiscountMoney() == 0) {
            continue;
         }
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         UserActivityDiscount1 userActivityDiscount1 = userActivityDiscountMap.get(tOrderPrivateCar.getActivityId());
         if (userActivityDiscount1 != null) {
            UserActivity userActivity = userActivityMap.get(userActivityDiscount1.getUserActivityId());
            if (userActivity != null) {
               grantVO.setRemark(userActivity.getName());
            }
         }
         res.add(grantVO);
      }
      for (TOrderLogistics tOrderPrivateCar : tOrderLogistics) {
         if (tOrderPrivateCar.getDiscountMoney() == null || tOrderPrivateCar.getDiscountMoney() == 0) {
            continue;
         }
         discount = discount.add(new BigDecimal(tOrderPrivateCar.getDiscountMoney().toString()));
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(tOrderPrivateCar.getInsertTime()));
         grantVO.setType("折扣");
         grantVO.setAmount(tOrderPrivateCar.getDiscountMoney().toString());
         TUser tUser = userMap.get(tOrderPrivateCar.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         UserActivityDiscount1 userActivityDiscount1 = userActivityDiscountMap.get(tOrderPrivateCar.getActivityId());
         if (userActivityDiscount1 != null) {
            UserActivity userActivity = userActivityMap.get(userActivityDiscount1.getUserActivityId());
            if (userActivity != null) {
               grantVO.setRemark(userActivity.getName());
            }
         }
         res.add(grantVO);
      }
      // 查询已领取红包总额
      for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userRedPacketRecord.getInsertTime()));
         grantVO.setType("红包");
         grantVO.setAmount(userRedPacketRecord.getMoney().toString());
         TUser tUser = userMap.get(userRedPacketRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         if (userRedPacketRecord.getIsGrant() == 1) {
            // 后台发放的红包
            grantVO.setRemark("指定发放");
         }
         UserActivityRedenvelope userActivityRedenvelope = userActivityRedenvelopeMap.get(userRedPacketRecord.getRedPacketActivityId());
         if (userActivityRedenvelope != null) {
            UserActivity userActivity = userActivityMap.get(userActivityRedenvelope.getUserActivityId());
            if (userActivity != null) {
               grantVO.setRemark(userActivity.getName());
            }
         }
         res.add(grantVO);
         redPackage = redPackage.add(new BigDecimal(userRedPacketRecord.getMoney().toString()));
      }
      // 查询已领取优惠券总额
      for (UserCouponRecord userCouponRecord : userCouponRecords) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(userCouponRecord.getInsertTime()));
         grantVO.setType("优惠券");
         grantVO.setAmount(userCouponRecord.getMoney().toString());
         TUser tUser = userMap.get(userCouponRecord.getUserId());
         if (tUser != null) {
            grantVO.setName(tUser.getNickName());
         }
         SysCouponActivity sysCouponActivity = sysCouponActivityMap.get(userCouponRecord.getCouponActivityId());
         if (sysCouponActivity != null) {
            grantVO.setRemark(sysCouponActivity.getName());
         }
         coupon = coupon.add(new BigDecimal(userCouponRecord.getMoney().toString()));
         res.add(grantVO);
      }
      // 已领取司机奖励
      for (DriverActivityHistory driverActivityHistory : driverActivityHistories) {
         GrantVO grantVO = new GrantVO();
         grantVO.setInsertTime(format.format(driverActivityHistory.getInsertTime()));
         grantVO.setType("司机奖励");
         grantVO.setAmount(driverActivityHistory.getMoney().toString());
         TDriver tDriver = driverMap.get(driverActivityHistory.getDriverId());
         if (tDriver != null) {
            grantVO.setName(tDriver.getFirstName() + tDriver.getLastName());
         }
         Integer type1 = driverActivityHistory.getType();
         switch (type1) {
            case 1:
               grantVO.setRemark("邀请司机注册");
               break;
            case 2:
               grantVO.setRemark("邀请用户注册");
               break;
            case 3:
               grantVO.setRemark("累计在线");
               break;
            case 4:
               grantVO.setRemark("订单量");
               break;
         }
         driver = driver.add(new BigDecimal(driverActivityHistory.getMoney().toString()));
         res.add(grantVO);
      }
      total = total.add(redPackage).add(coupon).add(discount).add(driver);
      result.setTotal(total);
      result.setDiscount(discount);
      result.setCoupon(coupon);
      result.setDriver(driver);
      result.setRedPackage(redPackage);
      return result;
   }
}