Browse Source

设备主收入统计

master
nili 5 months ago
parent
commit
6159d677ca
  1. 17
      game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java
  2. 10
      game-service/src/main/java/awesome/group/game/service/AdminService.java
  3. 39
      game-service/src/main/java/awesome/group/game/service/AggregationSubService.java
  4. 1
      game-service/src/main/java/awesome/group/game/service/bo/MatrixAdminBo.java

17
game-service/src/main/java/awesome/group/game/service/AdminDeviceService.java

@ -138,6 +138,23 @@ public class AdminDeviceService {
return incomeOverviewByAppIds(appIds, adminId); return incomeOverviewByAppIds(appIds, adminId);
} }
public Map<Integer, OverviewBo> incomeOverview(List<Integer> adminIds) {
if (CollectionUtils.isEmpty(adminIds)) {
return new HashMap<>();
}
Map<Integer, OverviewBo> res = adminIds.stream().collect(Collectors.toMap(x -> x, x -> new OverviewBo()));
Map<Integer, Long> totalIncome = aggregationSubService.getIncome(adminIds, null, null);
Map<Integer, Long> lastMonthIncome = aggregationSubService.getIncomeLastMonth(adminIds);
Map<Integer, Long> thisMonthIncome = aggregationSubService.getIncomeThisMonth(adminIds);
adminIds.forEach(x->{
OverviewBo bo = res.get(x);
bo.totalIncome = totalIncome.getOrDefault(x, 0L);
bo.lastMonthIncome = lastMonthIncome.getOrDefault(x, 0L);
bo.thisMonthIncome = thisMonthIncome.getOrDefault(x, 0L);
});
return res;
}
private OverviewBo incomeOverviewByAppIds(List<Integer> appIds, int adminId) { private OverviewBo incomeOverviewByAppIds(List<Integer> appIds, int adminId) {
if (CollectionUtils.isEmpty(appIds)) { if (CollectionUtils.isEmpty(appIds)) {
return new OverviewBo(); return new OverviewBo();

10
game-service/src/main/java/awesome/group/game/service/AdminService.java

@ -61,6 +61,10 @@ public class AdminService {
@Autowired @Autowired
private AdminService adminService; private AdminService adminService;
@Lazy
@Autowired
private AdminDeviceService deviceService;
public static final int SUPER_ADMIN = 1;//超级管理员 public static final int SUPER_ADMIN = 1;//超级管理员
public static final int NORMAL_ADMIN = 2;//普通管理员 public static final int NORMAL_ADMIN = 2;//普通管理员
public static final int OTHER = 3;//普通账号 public static final int OTHER = 3;//普通账号
@ -170,7 +174,11 @@ public class AdminService {
query.eq(MatrixAdmin::getParentAdminId, adminId); query.eq(MatrixAdmin::getParentAdminId, adminId);
List<MatrixAdmin> res = adminMapper.selectList(query); List<MatrixAdmin> res = adminMapper.selectList(query);
return res.stream().map(MatrixAdminBo::new).toList(); List<MatrixAdminBo> data = res.stream().map(MatrixAdminBo::new).toList();
List<Integer> deviceOwners = data.stream().filter(x -> x.getRole() == DEVICE_OWNER).map(MatrixAdminBo::getId).toList();
Map<Integer, OverviewBo> overviewBoMap = deviceService.incomeOverview(deviceOwners);
data.forEach(x -> x.overview = overviewBoMap.get(x.getId()));
return data;
} }
public void saveAdmin(int adminId, MatrixAdminBo bo, String channel) { public void saveAdmin(int adminId, MatrixAdminBo bo, String channel) {

39
game-service/src/main/java/awesome/group/game/service/AggregationSubService.java

@ -2,13 +2,18 @@ package awesome.group.game.service;
import awesome.group.game.dao.bean.MatrixAdvAggregationSub; import awesome.group.game.dao.bean.MatrixAdvAggregationSub;
import awesome.group.game.dao.mapper.MatrixAdvAggregationSubMapper; import awesome.group.game.dao.mapper.MatrixAdvAggregationSubMapper;
import awesome.group.game.service.util.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
public class AggregationSubService { public class AggregationSubService {
@ -31,4 +36,38 @@ public class AggregationSubService {
return data.getIncome(); return data.getIncome();
} }
public Map<Integer, Long> getIncome(List<Integer> adminIds, Integer startDate, Integer endDate) {
LambdaQueryWrapper<MatrixAdvAggregationSub> query = new QueryWrapper<MatrixAdvAggregationSub>()
.select("sum(income_real) as income").lambda();
query.in(MatrixAdvAggregationSub::getAdminId, adminIds);
if (startDate != null) {
query.ge(MatrixAdvAggregationSub::getDate, startDate);
}
if (endDate != null) {
query.le(MatrixAdvAggregationSub::getDate, endDate);
}
query.groupBy(MatrixAdvAggregationSub::getAdminId);
List<MatrixAdvAggregationSub> data = subMapper.selectList(query);
return data.stream().collect(Collectors.toMap(MatrixAdvAggregationSub::getAdminId, MatrixAdvAggregationSub::getIncome));
}
public Map<Integer, Long> getIncomeLastMonth(List<Integer> adminIds) {
LocalDate now = LocalDate.now();
// 获取上个月的年份和月份
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
// 获取上个月的第一天和最后一天
LocalDate firstDayOfLastMonth = lastMonth.atDay(1);
LocalDate lastDayOfLastMonth = lastMonth.atEndOfMonth();
return getIncome(adminIds, DateUtil.date2Number(firstDayOfLastMonth), DateUtil.date2Number(lastDayOfLastMonth));
}
public Map<Integer, Long> getIncomeThisMonth(List<Integer> adminIds) {
LocalDate now = LocalDate.now();
YearMonth thisMonth = YearMonth.from(now);
LocalDate firstDayOfThisMonth = thisMonth.atDay(1);
return getIncome(adminIds, DateUtil.date2Number(firstDayOfThisMonth), DateUtil.currentDate());
}
} }

1
game-service/src/main/java/awesome/group/game/service/bo/MatrixAdminBo.java

@ -17,6 +17,7 @@ public class MatrixAdminBo {
private Integer role;//1超级管理员,2管理员,3普通账号 private Integer role;//1超级管理员,2管理员,3普通账号
private Integer deviceCnt; private Integer deviceCnt;
private Integer incomeRate; private Integer incomeRate;
public OverviewBo overview;
public MatrixAdminBo() { public MatrixAdminBo() {
} }

Loading…
Cancel
Save