xuhy
2023-05-17 566c44cc5712ab9c997424ee5a5438e0a81a016e
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TDriverServiceImpl.java
@@ -24,6 +24,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
@@ -37,8 +38,10 @@
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -96,8 +99,8 @@
        // 开始,结束时间
        if(StringUtils.hasLength(createTime)){
            String[] split = createTime.split(" - ");
            Date startTime = DateUtil.getDate_str4(split[0]);
            Date endTime = DateUtil.getDate_str4(split[1]);
            Date startTime = DateUtil.getDate_str3(split[0]+" 00:00:00");
            Date endTime = DateUtil.getDate_str3(split[1]+" 23:59:59");
            wrapper.between("createTime",startTime,endTime);
        }
        wrapper.orderBy(true,"approvalStatus");
@@ -185,11 +188,8 @@
        // 计算驾龄
        if(Objects.nonNull(tDriver.getFirstCertificateTime())){
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDate firstTime = tDriver.getFirstCertificateTime().toInstant().atZone(zoneId).toLocalDate();
            LocalDate now = tDriver.getFirstCertificateTime().toInstant().atZone(zoneId).toLocalDate();
            Period period = Period.between(firstTime, now);
            model.addAttribute("drivingExperience",period.getYears());
            Period period = Period.between(LocalDate.now(), com.stylefeng.guns.modular.system.util.DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime()));
            model.addAttribute("drivingExperience",Math.max(Math.abs(period.getYears()), 1));
        }else {
            model.addAttribute("drivingExperience",0);
        }
@@ -231,17 +231,25 @@
                TDriver tDriver1 = tDriverMapper.selectById(tDriver.getInviterId());
                model.addAttribute("inviterName",tDriver1.getName());
                model.addAttribute("inviterPhone",tDriver1.getPhone());
            }else {
                model.addAttribute("inviterName","");
                model.addAttribute("inviterPhone","");
            }
        }else {
            model.addAttribute("inviterName","");
            model.addAttribute("inviterPhone","");
        }
        // 查询当前用户邀请了哪些人
        List<TDriver> list = tDriverMapper.selectList(new EntityWrapper<TDriver>().eq("inviterId", tDriver.getId()));
        if(!CollectionUtils.isEmpty(list)){
            List<TCashWithdrawal> tCashWithdrawals = tCashWithdrawalMapper.selectList(new EntityWrapper<TCashWithdrawal>()
                    .eq("type", UserTypeEnum.DRIVER.getCode())
                    .eq("userDriverId", tDriver.getId())
                    .eq("businessType", 11)
                    .eq("state", 2));
            Optional<BigDecimal> reduce = tCashWithdrawals.stream().map(TCashWithdrawal::getAmount).reduce(BigDecimal::add);
            BigDecimal bigDecimal = BigDecimal.ZERO;
            reduce.ifPresent(bigDecimal::add);
            model.addAttribute("inviterCommission",bigDecimal.add(tDriver.getCommission()));
            model.addAttribute("inviterCount",list.size());
            model.addAttribute("inviterCommission",0);
        }else {
            model.addAttribute("inviterCommission",0);
            model.addAttribute("inviterCount",0);
@@ -438,11 +446,23 @@
            commissionResp.setConnectedPersons(connectedPersons.get());
            // 已提现佣金  查询该司机的佣金提现记录
            commissionResp.setWithdrawnAmount(BigDecimal.ZERO);
            List<TCashWithdrawal> tCashWithdrawals = tCashWithdrawalMapper.selectList(new EntityWrapper<TCashWithdrawal>()
                    .eq("type", UserTypeEnum.DRIVER.getCode())
                    .eq("userDriverId", driver.getId())
                    .eq("businessType", 11)
                    .eq("state", 2));
            BigDecimal bigDecimal = BigDecimal.ZERO;
            if(!CollectionUtils.isEmpty(tCashWithdrawals)){
                Optional<BigDecimal> reduce = tCashWithdrawals.stream().map(TCashWithdrawal::getAmount).reduce(BigDecimal::add);
                if(reduce.isPresent()){
                    bigDecimal.add(reduce.get());
                    commissionResp.setWithdrawnAmount(bigDecimal);
                }
            }else {
                commissionResp.setWithdrawnAmount(bigDecimal);
            }
            // 累计佣金  可提现佣金+已提现佣金
            commissionResp.setAccumulatedCommission(BigDecimal.ZERO);
            commissionResp.setAccumulatedCommission(bigDecimal.add(commissionResp.getCommission()));
            commissionRespList.add(commissionResp);
        }
@@ -494,11 +514,26 @@
            model.addAttribute("numberPromoters",0);
        }
        model.addAttribute("connectedPersons",connectedPersons.get());
        // 已提现佣金  查询该司机的佣金提现记录
        model.addAttribute("withdrawnAmount",BigDecimal.ZERO);
        List<TCashWithdrawal> tCashWithdrawals = tCashWithdrawalMapper.selectList(new EntityWrapper<TCashWithdrawal>()
                .eq("type", UserTypeEnum.DRIVER.getCode())
                .eq("userDriverId", driver.getId())
                .eq("businessType", 11)
                .eq("state", 2));
        BigDecimal bigDecimal = BigDecimal.ZERO;
        if(!CollectionUtils.isEmpty(tCashWithdrawals)){
            Optional<BigDecimal> reduce = tCashWithdrawals.stream().map(TCashWithdrawal::getAmount).reduce(BigDecimal::add);
            if(reduce.isPresent()){
                bigDecimal.add(reduce.get());
                // 已提现佣金  查询该司机的佣金提现记录
                model.addAttribute("withdrawnAmount",bigDecimal);
            }
        }else {
            // 已提现佣金  查询该司机的佣金提现记录
            model.addAttribute("withdrawnAmount",bigDecimal);
        }
//        commissionResp.setWithdrawnAmount(BigDecimal.ZERO);
        // 累计佣金  可提现佣金+已提现佣金
        model.addAttribute("accumulatedCommission",BigDecimal.ZERO);
        model.addAttribute("accumulatedCommission",bigDecimal.add(driver.getCommission()));
//        commissionResp.setAccumulatedCommission(BigDecimal.ZERO);
    }
@@ -509,11 +544,11 @@
        Integer driverTotal = tDriverMapper.selectCount(new EntityWrapper<TDriver>()
                .eq("agentId", agentId));
        // 司机最近一月数量
        LocalDate now = LocalDate.now();
        LocalDate localDate = now.plusMonths(1);
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime localDateTime = now.minusMonths(1);
        Integer driverMonthTotal = tDriverMapper.selectCount(new EntityWrapper<TDriver>()
                .eq("agentId", agentId)
                .between("createTime", localDate, now));
                .between("createTime", localDateTime, now));
        model.addAttribute("driverTotal",driverTotal);
        model.addAttribute("driverMonthTotal",driverMonthTotal);
        map.put("driverTotal",driverTotal);
@@ -526,8 +561,8 @@
        Integer driverTotal = tDriverMapper.selectCount(new EntityWrapper<TDriver>()
                .in("agentId", ids));
        // 司机最近一月数量
        LocalDate now = LocalDate.now();
        LocalDate localDate = now.plusMonths(1);
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime localDate = now.minusMonths(1);
        Integer driverMonthTotal = tDriverMapper.selectCount(new EntityWrapper<TDriver>()
                .in("agentId", ids)
                .between("createTime", localDate, now));