| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.stylefeng.guns.core.base.tips.SuccessTip; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TDriverCommissionResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TDriverResp; |
| | | import com.stylefeng.guns.modular.system.controller.util.HttpUtils; |
| | |
| | | import com.stylefeng.guns.modular.system.enums.StatusEnum; |
| | | import com.stylefeng.guns.modular.system.enums.UserTypeEnum; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.IDriverOnlineTimeService; |
| | | import com.stylefeng.guns.modular.system.service.ITDriverService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.system.service.ITRegionService; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | |
| | | @Service |
| | | public class TDriverServiceImpl extends ServiceImpl<TDriverMapper, TDriver> implements ITDriverService { |
| | | |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private TAgentMapper tAgentMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TBranchOfficeMapper tBranchOfficeMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TOrderMapper tOrderMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TDriverMapper tDriverMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TAppUserMapper tAppUserMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TOrderRefusalMapper tOrderRefusalMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TRegionMapper tRegionMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TRevenueMapper tRevenueMapper; |
| | | @Autowired |
| | | private ITRegionService itRegionService; |
| | | @Autowired |
| | | private HttpUtils httpUtils; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private TRechargeRecordMapper tRechargeRecordMapper; |
| | | @Autowired |
| | | @Resource |
| | | private TCashWithdrawalMapper tCashWithdrawalMapper; |
| | | |
| | | @Autowired |
| | | private IDriverOnlineTimeService driverOnlineTimeService; |
| | | |
| | | private Logger log = LoggerFactory.getLogger(this.getClass()); |
| | | @Override |
| | |
| | | TDriverResp tDriverResp = new TDriverResp(); |
| | | BeanUtils.copyProperties(tDriver,tDriverResp); |
| | | |
| | | if(Objects.nonNull(tDriver.getBackgroundBalance()) && Objects.nonNull(tDriver.getBalance())){ |
| | | if(Objects.nonNull(tDriver.getBackgroundBalance()) && Objects.nonNull(tDriver.getBalance()) && Objects.nonNull(tDriver.getCouponBalance())){ |
| | | // 设置余额 |
| | | tDriverResp.setBalance(tDriver.getBackgroundBalance().add(tDriver.getBalance())); |
| | | tDriverResp.setBalance(tDriver.getBackgroundBalance().add(tDriver.getBalance()).add(tDriver.getCouponBalance())); |
| | | } |
| | | |
| | | // 所属代理商 |
| | |
| | | model.addAttribute("score",tDriver.getScore()); |
| | | model.addAttribute("source",tDriver.getSource()); |
| | | model.addAttribute("createTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tDriver.getCreateTime())); |
| | | model.addAttribute("balance", tDriver.getBalance().add(tDriver.getCouponBalance()).add(tDriver.getBackgroundBalance()).add(tDriver.getCommission()).doubleValue()); |
| | | |
| | | // 计算驾龄 |
| | | if(Objects.nonNull(tDriver.getFirstCertificateTime())){ |
| | |
| | | model.addAttribute("drivingExperience",Math.max(Math.abs(period.getYears()), 1)); |
| | | }else { |
| | | model.addAttribute("drivingExperience",0); |
| | | } |
| | | |
| | | List<TOrder> tOrders = tOrderMapper.selectList(new EntityWrapper<TOrder>()); |
| | | |
| | | String monthDate = new SimpleDateFormat("yyyyMM").format(new Date()); |
| | | |
| | | if(Objects.nonNull(tDriver.getBackgroundBalance()) && Objects.nonNull(tDriver.getBalance())){ |
| | | // 设置余额 |
| | | tDriver.setBalance(tDriver.getBackgroundBalance().add(tDriver.getBalance())); |
| | | model.addAttribute("balance",tDriver.getBalance()); |
| | | }else { |
| | | model.addAttribute("balance",BigDecimal.ZERO); |
| | | } |
| | | |
| | | // 所属代理商 |
| | |
| | | |
| | | // 查询当前用户邀请了哪些人 |
| | | 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()); |
| | | }else { |
| | | model.addAttribute("inviterCommission",0); |
| | | model.addAttribute("inviterCount",0); |
| | | } |
| | | List<TAppUser> tAppUsers = tAppUserMapper.selectList(new EntityWrapper<TAppUser>().eq("inviterType", 2).eq("inviterId", tDriver.getId())); |
| | | model.addAttribute("inviterDriverCount",list.size()); |
| | | model.addAttribute("inviterUserCount",tAppUsers.size()); |
| | | 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())); |
| | | |
| | | if(!CollectionUtils.isEmpty(tOrders)){ |
| | | //累计订单量 |
| | | List<TOrder> cumulativeOrderCount = tOrders.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) |
| | | && (order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList()); |
| | | model.addAttribute("cumulativeOrderCount",cumulativeOrderCount.size()); |
| | | //当月订单量 |
| | | List<TOrder> monthOrderCount = tOrders.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) |
| | | && (order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode()) || order.getState().equals(OrderStateEnum.FINISH.getCode())) |
| | | && new SimpleDateFormat("yyyyMM").format(order.getCreateTime()).equals(monthDate)).collect(Collectors.toList()); |
| | | model.addAttribute("monthOrderCount",monthOrderCount.size()); |
| | | // 拒单次数 |
| | | List<TOrderRefusal> driverRefusalList = tOrderRefusalMapper.selectList(new EntityWrapper<TOrderRefusal>().eq("driver_id", tDriver.getId())); |
| | | model.addAttribute("refusalCount",driverRefusalList.size()); |
| | | // 累计收入 司机提现记录加上余额减去充值金额,为累计收入 |
| | | List<TCashWithdrawal> tCashWithdrawals = tCashWithdrawalMapper.selectList(new EntityWrapper<TCashWithdrawal>() |
| | | .eq("type", UserTypeEnum.DRIVER.getCode()) |
| | | .eq("userDriverId", tDriver.getId()) |
| | | .eq("state", 2)); |
| | | BigDecimal balance = tDriver.getBalance(); |
| | | // if(!CollectionUtils.isEmpty(tCashWithdrawals)){ |
| | | // Optional<BigDecimal> reduce = tCashWithdrawals.stream().map(TCashWithdrawal::getAmount).reduce(BigDecimal::add); |
| | | // if(reduce.isPresent()){ |
| | | // balance = balance.add(reduce.get()); |
| | | // } |
| | | // } |
| | | // List<TRechargeRecord> tRechargeRecords = tRechargeRecordMapper.selectList(new EntityWrapper<TRechargeRecord>() |
| | | // .eq("type", UserTypeEnum.DRIVER.getCode()) |
| | | // .eq("userId", tDriver.getId()) |
| | | // .eq("payType", 1) |
| | | // .eq("payStatus", PayStatusEnum.FINISH.getCode())); |
| | | // if(!CollectionUtils.isEmpty(tRechargeRecords)){ |
| | | // Optional<BigDecimal> reduce = tRechargeRecords.stream().map(TRechargeRecord::getAmount).reduce(BigDecimal::add); |
| | | // if(reduce.isPresent()){ |
| | | // balance = balance.subtract(reduce.get()); |
| | | // } |
| | | // } |
| | | List<TRevenue> tRevenues = tRevenueMapper.selectList(new EntityWrapper<TRevenue>() |
| | | .eq("userType", 2) |
| | | .eq("userId", tDriver.getId())); |
| | | Optional<BigDecimal> reduce = tRevenues.stream().map(TRevenue::getAmount).reduce(BigDecimal::add); |
| | | // 减去充值金额 |
| | | if(reduce.isPresent()){ |
| | | model.addAttribute("cumulativeIncome", reduce.get()); |
| | | }else { |
| | | model.addAttribute("cumulativeIncome",0); |
| | | } |
| | | //累计订单量 |
| | | Integer cumulativeOrderCount = tOrderMapper.selectCount(new EntityWrapper<TOrder>().eq("driverId", tDriver.getId()).eq("status", 1)); |
| | | model.addAttribute("cumulativeOrderCount", cumulativeOrderCount); |
| | | //有效订单数 |
| | | Integer effectiveOrderCount = tOrderMapper.selectCount(new EntityWrapper<TOrder>().eq("driverId", tDriver.getId()).eq("status", 1).in("state", Arrays.asList(106, 107, 108))); |
| | | model.addAttribute("effectiveOrderCount", effectiveOrderCount); |
| | | model.addAttribute("commission", tDriver.getCommission().doubleValue()); |
| | | // 拒单次数 |
| | | List<TOrderRefusal> driverRefusalList = tOrderRefusalMapper.selectList(new EntityWrapper<TOrderRefusal>().eq("driver_id", tDriver.getId())); |
| | | model.addAttribute("refusalCount",driverRefusalList.size()); |
| | | List<TRevenue> tRevenues = tRevenueMapper.selectList(new EntityWrapper<TRevenue>() |
| | | .eq("userType", 2) |
| | | .eq("userId", tDriver.getId())); |
| | | Optional<BigDecimal> reduce1 = tRevenues.stream().map(TRevenue::getAmount).reduce(BigDecimal::add); |
| | | // 减去充值金额 |
| | | if(reduce1.isPresent()){ |
| | | model.addAttribute("cumulativeIncome", reduce1.get()); |
| | | }else { |
| | | model.addAttribute("cumulativeOrderCount",0); |
| | | model.addAttribute("monthOrderCount",0); |
| | | model.addAttribute("refusalCount",0); |
| | | // 累计收入 |
| | | model.addAttribute("cumulativeIncome",0); |
| | | } |
| | | //消单次数 |
| | | Integer cancelOrderCount = tOrderMapper.selectCount(new EntityWrapper<TOrder>().eq("driverId", tDriver.getId()).eq("status", 1).in("state", Arrays.asList(301))); |
| | | model.addAttribute("cancelOrderCount",cancelOrderCount); |
| | | //有效在线时长 |
| | | Long onlineTime = tDriver.getOnlineTime(); |
| | | Long s = onlineTime % 60; |
| | | Long m = onlineTime / 60; |
| | | model.addAttribute("onlineTime", (m < 10 ? ("0" + m) : m) + ":" + (s < 10 ? ("0" + s) : s)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | tBranchOffice = tBranchOfficeMapper.selectList(new EntityWrapper<TBranchOffice>().eq("provinceCode", province.getCode()) |
| | | .eq("cityCode", city.getCode()) |
| | | .eq("status", StatusEnum.NORMAL.getCode()) |
| | | .eq("districtCode", city.getCode()) |
| | | .last("LIMIT 1")); |
| | | // tBranchOffice = tBranchOfficeMapper.selectList(new EntityWrapper<TBranchOffice>().eq("provinceCode", province.getCode()) |
| | | // .eq("cityCode", city.getCode()) |
| | | // .eq("status", StatusEnum.NORMAL.getCode()) |
| | | // .eq("districtCode", city.getCode()) |
| | | // .last("LIMIT 1")); |
| | | } |
| | | if(!CollectionUtils.isEmpty(tBranchOffice)){ |
| | | tDriver.setBranchOfficeId(tBranchOffice.get(0).getId()); |
| | |
| | | map.put("driverTotal",driverTotal); |
| | | map.put("driverMonthTotal",driverMonthTotal); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取司机详情汇总数据 |
| | | * @param driverId |
| | | * @param time |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, Object> querySummaryData(Integer driverId, String time) { |
| | | String startTime = ""; |
| | | String endTime = ""; |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | String[] split = time.split(" - "); |
| | | startTime = split[0]; |
| | | endTime = split[1]; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | TDriver tDriver = this.selectById(driverId); |
| | | //累计订单量 |
| | | Wrapper<TOrder> cumulativeOrderCountWrapper = new EntityWrapper<TOrder>().eq("driverId", tDriver.getId()).eq("status", 1); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | cumulativeOrderCountWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | Integer cumulativeOrderCount = tOrderMapper.selectCount(cumulativeOrderCountWrapper); |
| | | map.put("cumulativeOrderCount", cumulativeOrderCount); |
| | | //有效订单数 |
| | | Wrapper<TOrder> effectiveOrderCountWrapper = new EntityWrapper<TOrder>().eq("driverId", tDriver.getId()).eq("status", 1).in("state", Arrays.asList(106, 107, 108)); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | effectiveOrderCountWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | Integer effectiveOrderCount = tOrderMapper.selectCount(effectiveOrderCountWrapper); |
| | | map.put("effectiveOrderCount", effectiveOrderCount); |
| | | map.put("commission", tDriver.getCommission().doubleValue()); |
| | | map.put("balance", tDriver.getBalance().add(tDriver.getCouponBalance()).add(tDriver.getBackgroundBalance()).add(tDriver.getCommission()).doubleValue()); |
| | | // 查询当前用户邀请了哪些人 |
| | | Wrapper<TDriver> inviterDriverCountWrapper = new EntityWrapper<TDriver>().eq("inviterId", tDriver.getId()); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | inviterDriverCountWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | List<TDriver> list = tDriverMapper.selectList(inviterDriverCountWrapper); |
| | | map.put("inviterDriverCount",list.size()); |
| | | Wrapper<TAppUser> inviterUserCountWrapper = new EntityWrapper<TAppUser>().eq("inviterType", 2).eq("inviterId", tDriver.getId()); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | inviterUserCountWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | List<TAppUser> tAppUsers = tAppUserMapper.selectList(inviterUserCountWrapper); |
| | | map.put("inviterUserCount",tAppUsers.size()); |
| | | Wrapper<TRevenue> cumulativeIncomeWrapper = new EntityWrapper<TRevenue>().eq("userType", 2).eq("userId", tDriver.getId()); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | cumulativeIncomeWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | List<TRevenue> tRevenues = tRevenueMapper.selectList(cumulativeIncomeWrapper); |
| | | Optional<BigDecimal> reduce1 = tRevenues.stream().map(TRevenue::getAmount).reduce(BigDecimal::add); |
| | | // 减去充值金额 |
| | | if(reduce1.isPresent()){ |
| | | map.put("cumulativeIncome", reduce1.get()); |
| | | }else { |
| | | map.put("cumulativeIncome",0); |
| | | } |
| | | Wrapper<TCashWithdrawal> inviterCommissionWrapper = new EntityWrapper<TCashWithdrawal>().eq("type", UserTypeEnum.DRIVER.getCode()).eq("userDriverId", tDriver.getId()) |
| | | .eq("businessType", 11).eq("state", 2); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | inviterCommissionWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | List<TCashWithdrawal> tCashWithdrawals = tCashWithdrawalMapper.selectList(inviterCommissionWrapper); |
| | | Optional<BigDecimal> reduce = tCashWithdrawals.stream().map(TCashWithdrawal::getAmount).reduce(BigDecimal::add); |
| | | BigDecimal bigDecimal = BigDecimal.ZERO; |
| | | reduce.ifPresent(bigDecimal::add); |
| | | map.put("inviterCommission",bigDecimal.add(tDriver.getCommission())); |
| | | //消单次数 |
| | | Wrapper<TOrder> cancelOrderCountWrapper = new EntityWrapper<TOrder>().eq("driverId", tDriver.getId()).eq("status", 1).in("state", Arrays.asList(301)); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | cancelOrderCountWrapper.last(" and DATE_FORMAT(createTime, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | Integer cancelOrderCount = tOrderMapper.selectCount(cancelOrderCountWrapper); |
| | | map.put("cancelOrderCount",cancelOrderCount); |
| | | Wrapper<DriverOnlineTime> driverOnlineTimeWrapper = new EntityWrapper<DriverOnlineTime>().eq("driverId", driverId); |
| | | if(ToolUtil.isNotEmpty(time)){ |
| | | driverOnlineTimeWrapper.last(" and DATE_FORMAT(`day`, '$Y-$m-$d') between '" + startTime + "' and '" + endTime + "'"); |
| | | } |
| | | Long onlineTime = 0L; |
| | | List<DriverOnlineTime> driverOnlineTimes = driverOnlineTimeService.selectList(driverOnlineTimeWrapper); |
| | | for (DriverOnlineTime driverOnlineTime : driverOnlineTimes) { |
| | | onlineTime += driverOnlineTime.getOnlineTime().longValue(); |
| | | } |
| | | Long s = onlineTime % 60; |
| | | Long m = onlineTime / 60; |
| | | map.put("onlineTime", (m < 10 ? ("0" + m) : m) + ":" + (s < 10 ? ("0" + s) : s)); |
| | | return map; |
| | | } |
| | | } |