| | |
| | | package com.ruoyi.admin.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.admin.entity.User; |
| | | import com.ruoyi.admin.mapper.UserMapper; |
| | | import com.ruoyi.admin.request.UserDataCountRequest; |
| | | import com.ruoyi.admin.service.OrderService; |
| | | import com.ruoyi.admin.service.UserService; |
| | | import com.ruoyi.admin.service.WithdrawService; |
| | | import com.ruoyi.admin.vo.UserDataCountVO; |
| | | import com.ruoyi.admin.vo.UserTrendsVO; |
| | | import com.ruoyi.common.core.constant.OrderConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.order.api.entity.MoneyQueryRequest; |
| | | import com.ruoyi.order.api.feignClient.OrderClient; |
| | | import com.ruoyi.order.api.feignClient.WithdrawClient; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService { |
| | | |
| | | @Resource |
| | | private OrderService orderService; |
| | | private OrderClient orderClient; |
| | | @Resource |
| | | private WithdrawService withdrawService; |
| | | private WithdrawClient withdrawClient; |
| | | |
| | | @Override |
| | | public List<UserTrendsVO> userTrends(List<String> cityIds) { |
| | | if (null == cityIds || cityIds.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | List<UserTrendsVO> userTrendsList = baseMapper.userTrends(cityIds); |
| | | public List<UserTrendsVO> userTrends(List<String> city) { |
| | | List<UserTrendsVO> userTrendsList = baseMapper.userTrends(city); |
| | | return null == userTrendsList || userTrendsList.isEmpty() ? new ArrayList<>() : userTrendsList; |
| | | } |
| | | |
| | | @Override |
| | | public Object userDataCount(UserDataCountRequest userDataCountRequest) { |
| | | List<String> cityIdList = userDataCountRequest.getCityIdList(); |
| | | List<User> userList = lambdaQuery().eq(User::getIsDelete, 0).list(); |
| | | public UserDataCountVO userDataCount(UserDataCountRequest userDataCountRequest) { |
| | | List<String> cityList = userDataCountRequest.getCityList(); |
| | | String type = userDataCountRequest.getCountType(); |
| | | LambdaQueryChainWrapper<User> userWrapper = lambdaQuery().eq(User::getIsDelete, 0); |
| | | if (null != cityList && !cityList.isEmpty()) { |
| | | userWrapper.in(User::getCityCode, cityList); |
| | | } |
| | | List<User> userList = userWrapper.list(); |
| | | // 判断用户是否在管辖城市内下过订单 |
| | | for (User user : userList) { |
| | | Integer userId = user.getId(); |
| | | R<Boolean> r = orderClient.orderByUserId(userId); |
| | | if (!r.getData()) { |
| | | userList.remove(user); |
| | | } |
| | | } |
| | | Integer userNumber = userList.size(); |
| | | // 用户总量 |
| | | Integer userNumber = null == userList ? 0 : userList.size(); |
| | | // 计算当前季度时间所包含时间 |
| | | int currentYear = Year.now().getValue(); |
| | | // 获取当前月份 |
| | |
| | | String endDateStr = String.valueOf(endDate); |
| | | // 结果数据封装 |
| | | Long increaseNumber; |
| | | BigDecimal totalMoney; |
| | | BigDecimal withdrawalTotalMoney; |
| | | if (OrderConstants.QUARTER.equals(userDataCountRequest.getCountType())) { |
| | | // 交易额 |
| | | BigDecimal totalMoney = orderClient.tradeMoney(cityList, userDataCountRequest.getCountType()).getData(); |
| | | BigDecimal withdrawalTotalMoney = withdrawClient.withdrawalTotalMoney(new MoneyQueryRequest(cityList, type)) |
| | | .getData(); |
| | | if (OrderConstants.QUARTER.equals(type)) { |
| | | // 用户增长数 |
| | | increaseNumber = lambdaQuery().ge(User::getCreateTime, startDateStr).le(User::getCreateTime, endDateStr) |
| | | .in(User::getCityId, cityIdList).eq(User::getIsDelete, 0).count(); |
| | | // 用户总交易额 |
| | | totalMoney = orderService.totalMoneyByQuarter(startDateStr, endDateStr, cityIdList); |
| | | // 用户提现总额 |
| | | withdrawalTotalMoney = withdrawService.withdrawalTotalMoney(cityIdList); |
| | | } else if (OrderConstants.YEAR.equals(userDataCountRequest.getCountType())) { |
| | | LambdaQueryChainWrapper<User> wrapper = lambdaQuery().ge(User::getCreateTime, startDateStr) |
| | | .le(User::getCreateTime, endDateStr); |
| | | if (null != cityList && !cityList.isEmpty()) { |
| | | wrapper.in(User::getCityCode, cityList); |
| | | } |
| | | increaseNumber = wrapper.eq(User::getIsDelete, 0).count(); |
| | | } else if (OrderConstants.YEAR.equals(type)) { |
| | | // 用户增长数 |
| | | increaseNumber = baseMapper.increaseNumberByYear(cityIdList); |
| | | // 用户总交易额 |
| | | totalMoney = orderService.totalMoneyByYear(cityIdList); |
| | | // 用户提现总额 |
| | | withdrawalTotalMoney = withdrawService.withdrawalTotalMoneyByYear(cityIdList); |
| | | } else if (OrderConstants.MONTH.equals(userDataCountRequest.getCountType())) { |
| | | increaseNumber = baseMapper.increaseNumberByYear(cityList); |
| | | } else if (OrderConstants.MONTH.equals(type)) { |
| | | // 用户增长数 |
| | | increaseNumber = baseMapper.increaseNumberByMonth(cityIdList); |
| | | // 用户总交易额 |
| | | totalMoney = orderService.totalMoneyByMonth(cityIdList); |
| | | // 用户提现总额 |
| | | withdrawalTotalMoney = withdrawService.withdrawalTotalMoneyByMonth(cityIdList); |
| | | increaseNumber = baseMapper.increaseNumberByMonth(cityList); |
| | | } else { |
| | | // 数量初始化 |
| | | increaseNumber = 0L; |
| | | totalMoney = BigDecimal.ZERO; |
| | | withdrawalTotalMoney = BigDecimal.ZERO; |
| | | } |
| | | // 查询结果判断 |
| | | increaseNumber = null == increaseNumber ? 0L : increaseNumber; |