liujie
昨天 ee7208a3bb7770e24fa135916fa5f7165b25fee6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.stylefeng.guns.modular.system.service.impl;
 
import cn.hutool.system.UserInfo;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.dao.TDriverPromotionActivityMapper;
import com.stylefeng.guns.modular.system.service.*;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 司机推广活动主表 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2025-07-31
 */
@Service
public class TDriverPromotionActivityServiceImpl extends ServiceImpl<TDriverPromotionActivityMapper, TDriverPromotionActivity> implements ITDriverPromotionActivityService {
 
    @Autowired
    private ITDriverService driverService;
    @Autowired
    private ITUserService userService;
    @Autowired
    private ITOrderPrivateCarService orderPrivateCarService;
    @Autowired
    private ITOrderTaxiService orderTaxiService;
    @Autowired
    private ITOrderCrossCityService orderCrossCityService;
 
    @Override
    public Object list(String beginTime, String endTime, String name, Integer status) {
        return this.baseMapper.list(beginTime, endTime, name, status);
    }
 
    @Override
    public List<DriverRankVo> list1(Long id, String driverName) {
       List<DriverRankVo> hashMaps = new ArrayList<>();
 
        // 获取所有的司机
        Wrapper<TDriver> flag = new EntityWrapper<TDriver>().ne("flag", 3);
        if (driverName != null && !"".equals(driverName)) {
            flag.like("name", driverName);
        }
 
        List<TDriver> tDrivers = driverService.selectList(flag);
 
        // 获取绑定的司机的用户
        List<TUser> tUsers = userService.selectList(new EntityWrapper<TUser>().isNotNull("bindDriverId").gt("bindExpireDate", new Date()));
 
        // 获取所有获得司机收益的订单
        List<TOrderPrivateCar> tOrderPrivateCars = orderPrivateCarService.selectList(new EntityWrapper<TOrderPrivateCar>().eq("promotionActivityId",id).isNotNull("promotionDriverId").isNotNull("successTime"));
        List<TOrderTaxi> tOrderTaxis = orderTaxiService.selectList(new EntityWrapper<TOrderTaxi>().eq("promotionActivityId",id).isNotNull("promotionDriverId").isNotNull("successTime"));
        List<TOrderCrossCity> tOrderCrossCities = orderCrossCityService.selectList(new EntityWrapper<TOrderCrossCity>().eq("promotionActivityId",id).isNotNull("promotionDriverId").isNotNull("successTime"));
 
 
        for (TDriver tDriver : tDrivers) {
            DriverRankVo driverRankVo = new DriverRankVo();
            driverRankVo.setDriverId(tDriver.getId());
            driverRankVo.setDriverName(tDriver.getName());
            long count = tUsers.stream().filter(e -> tDriver.getId().equals(e.getBindDriverId())).count();
            driverRankVo.setUserNum((int) count);
 
            BigDecimal reduce = tOrderPrivateCars.stream().filter(e -> tDriver.getId().equals(e.getPromotionDriverId())).map(TOrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce1 = tOrderTaxis.stream().filter(e -> tDriver.getId().equals(e.getPromotionDriverId())).map(TOrderTaxi::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce2 = tOrderCrossCities.stream().filter(e -> tDriver.getId().equals(e.getPromotionDriverId())).map(TOrderCrossCity::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
            driverRankVo.setMoney(reduce.add(reduce1).add(reduce2));
            hashMaps.add(driverRankVo);
        }
//        hashMaps.stream().sorted(Comparator.comparing(e -> Integer.valueOf(e.get("userNum").toString())).reversed()).collect(Collectors.toList())
        // hashMaps 通过userNUm 倒叙
        List<DriverRankVo> collect = hashMaps.stream().sorted(Comparator.comparing(DriverRankVo::getUserNum).reversed()).collect(Collectors.toList());
        return collect;
    }
 
    @Override
    public  ArrayList<HashMap<String, Object>> list2(Long driverId, String name) {
        ArrayList<HashMap<String, Object>> hashMaps = new ArrayList<>();
 
        Wrapper<TUser> gt = new EntityWrapper<TUser>().eq("bindDriverId", driverId).gt("bindExpireDate", new Date());
        if (name != null && !"".equals(name)) {
            gt.like("nickName", name);
        }
 
        // 获取所有获得司机收益的订单
        List<TOrderPrivateCar> tOrderPrivateCars = orderPrivateCarService.selectList(new EntityWrapper<TOrderPrivateCar>().eq("promotionDriverId",driverId).isNotNull("successTime"));
        List<TOrderTaxi> tOrderTaxis = orderTaxiService.selectList(new EntityWrapper<TOrderTaxi>().eq("promotionDriverId",driverId).isNotNull("successTime"));
        List<TOrderCrossCity> tOrderCrossCities = orderCrossCityService.selectList(new EntityWrapper<TOrderCrossCity>().eq("promotionDriverId",driverId).isNotNull("successTime"));
 
        // 找出绑定这个司机的用户
        List<TUser> tUsers = userService.selectList(gt);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (TUser tUser : tUsers) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("userId", tUser.getId());
            map.put("userName", tUser.getNickName());
            map.put("userPhone", tUser.getPhone());
            map.put("bindDate",simpleDateFormat.format( tUser.getBindDate()));
            map.put("bindExpireDate",simpleDateFormat.format( tUser.getBindExpireDate()));
            BigDecimal reduce = tOrderPrivateCars.stream().filter(e -> e.getUserId().equals(tUser.getId())).map(TOrderPrivateCar::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce1 = tOrderTaxis.stream().filter(e -> e.getUserId().equals(tUser.getId())).map(TOrderTaxi::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce2 = tOrderCrossCities.stream().filter(e -> e.getUserId().equals(tUser.getId())).map(TOrderCrossCity::getPromotionMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
            map.put("money", reduce.add(reduce1).add(reduce2));
            hashMaps.add( map);
        }
        return hashMaps;
    }
}