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.core.util.ToolUtil;
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;
/**
*
* 司机推广活动主表 服务实现类
*
*
* @author stylefeng
* @since 2025-07-31
*/
@Service
public class TDriverPromotionActivityServiceImpl extends ServiceImpl 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 list1(Long id, String driverName) {
List driverPromotionActivity = orderPrivateCarService.getDriverPromotionActivity(id.intValue(), driverName);
return driverPromotionActivity;
}
@Override
public ArrayList> list2(Long driverId, String name) {
ArrayList> hashMaps = new ArrayList<>();
Wrapper gt = new EntityWrapper().eq("bindDriverId", driverId).gt("bindExpireDate", new Date());
if (name != null && !"".equals(name)) {
gt.like("nickName", name);
}
// 获取所有获得司机收益的订单
List tOrderPrivateCars = orderPrivateCarService.selectList(new EntityWrapper().eq("promotionDriverId",driverId).isNotNull("successTime"));
List tOrderTaxis = orderTaxiService.selectList(new EntityWrapper().eq("promotionDriverId",driverId).isNotNull("successTime"));
List tOrderCrossCities = orderCrossCityService.selectList(new EntityWrapper().eq("promotionDriverId",driverId).isNotNull("successTime"));
// 找出绑定这个司机的用户
List tUsers = userService.selectList(gt);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (TUser tUser : tUsers) {
HashMap 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;
}
}