|
|
@ -2,13 +2,18 @@ package awesome.group.game.service; |
|
|
|
|
|
|
|
import awesome.group.game.dao.bean.MatrixAdvAggregationSub; |
|
|
|
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.QueryWrapper; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.YearMonth; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class AggregationSubService { |
|
|
@ -31,4 +36,38 @@ public class AggregationSubService { |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|