|
|
@@ -2,7 +2,6 @@ package com.cyksj.service.mange.statistics.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
@@ -23,7 +22,10 @@ import com.cyksj.model.excel.statistics.ExcelRegisterAccountData;
|
|
|
import com.cyksj.model.excel.statistics.ExcelStreamingAccountData;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
|
-import com.cyksj.model.views.*;
|
|
|
+import com.cyksj.model.views.BackgroundDataView;
|
|
|
+import com.cyksj.model.views.DistributeOrdersView;
|
|
|
+import com.cyksj.model.views.ExpiredAccountDataView;
|
|
|
+import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
import com.cyksj.service.mange.CmsAccountService;
|
|
|
import com.cyksj.service.mange.statistics.StatisticsDataDayService;
|
|
|
import com.cyksj.service.mange.statistics.StatisticsDataService;
|
|
|
@@ -74,6 +76,8 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
private final StatisticsUserDataMapper statisticsUserDataMapper;
|
|
|
|
|
|
private final StatisticsFashionGoodsDataMapper statisticsFashionGoodsDataMapper;
|
|
|
@@ -83,7 +87,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
@Override
|
|
|
- public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) throws InterruptedException {
|
|
|
+ public Result<BackgroundDataView> getStatisticsByCondition(Integer type, Long startTime, Long endTime) {
|
|
|
BackgroundDataView backgroundDataView = new BackgroundDataView();
|
|
|
Date startDate = null;
|
|
|
Date endDate = null;
|
|
|
@@ -93,34 +97,37 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
if (endTime != null) {
|
|
|
endDate = DateUtil.date(endTime);
|
|
|
}
|
|
|
- CountDownLatch countDownLatch = new CountDownLatch(2);
|
|
|
- final Date f_st = startDate;
|
|
|
- final Date f_et = endDate;
|
|
|
- //头部数据
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- try {
|
|
|
- headerData(backgroundDataView, f_st, f_et);
|
|
|
- } finally {
|
|
|
- countDownLatch.countDown();
|
|
|
- }
|
|
|
- });
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- try {
|
|
|
+ switch (type) {
|
|
|
+ case 1:
|
|
|
//流媒体账号
|
|
|
- getStreamingAccountDataView(backgroundDataView, f_st, f_et);
|
|
|
+ getStreamingAccountDataView(backgroundDataView, startDate, endDate);
|
|
|
//appleOne
|
|
|
- getAppleOneDataView(backgroundDataView, f_st, f_et);
|
|
|
+ getAppleOneDataView(backgroundDataView, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
//实物数据
|
|
|
- getRealGoodsData(backgroundDataView, f_st, f_et);
|
|
|
+ getRealGoodsData(backgroundDataView, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
//注册账号数据
|
|
|
- getRegisterAccountData(backgroundDataView, f_st, f_et);
|
|
|
+ getRegisterAccountData(backgroundDataView, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
//潮玩好物数据
|
|
|
- getFashionGoodsData(backgroundDataView, f_st, f_et);
|
|
|
- } finally {
|
|
|
- countDownLatch.countDown();
|
|
|
- }
|
|
|
- });
|
|
|
- countDownLatch.await();
|
|
|
+ getFashionGoodsData(backgroundDataView, startDate, endDate);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //流媒体账号
|
|
|
+ getStreamingAccountDataView(backgroundDataView, startDate, endDate);
|
|
|
+ //appleOne
|
|
|
+ getAppleOneDataView(backgroundDataView, startDate, endDate);
|
|
|
+ //实物数据
|
|
|
+ getRealGoodsData(backgroundDataView, startDate, endDate);
|
|
|
+ //注册账号数据
|
|
|
+ getRegisterAccountData(backgroundDataView, startDate, endDate);
|
|
|
+ //潮玩好物数据
|
|
|
+ getFashionGoodsData(backgroundDataView, startDate, endDate);
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(backgroundDataView);
|
|
|
}
|
|
|
|
|
|
@@ -328,6 +335,20 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
return excelSheetDataList;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result<BackgroundDataView> getStatisticsHeader(Long startTime, Long endTime) {
|
|
|
+ Date startDate = null;
|
|
|
+ Date endDate = null;
|
|
|
+ if (startTime != null) {
|
|
|
+ startDate = DateUtil.date(startTime);
|
|
|
+ }
|
|
|
+ if (endTime != null) {
|
|
|
+ endDate = DateUtil.date(endTime);
|
|
|
+ }
|
|
|
+ BackgroundDataView backgroundDataView = getHeaderData(startDate, endDate);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(backgroundDataView);
|
|
|
+ }
|
|
|
+
|
|
|
public void exportAllTypeData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
|
|
|
CountDownLatch latch = new CountDownLatch(2);
|
|
|
TASK_POOL.execute(() -> {
|
|
|
@@ -681,6 +702,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
}
|
|
|
|
|
|
private void getStreamingAccountDataView(BackgroundDataView backgroundDataView, Date startDate, Date endDate) {
|
|
|
+ //当天
|
|
|
if (DateUtil.beginOfDay(DateTime.now()).equals(startDate) && (DateUtil.beginOfDay(DateUtil.offsetDay(DateTime.now(), 1)).equals(endDate) || DateUtil.endOfDay(DateTime.now()).equals(endDate))) {
|
|
|
List<StreamingAccountData> streamingAccountData = statistics.statisticsStreamingAccountData(startDate, endDate, true);
|
|
|
List<StreamingAccountData> collect = streamingAccountData.stream().filter(data -> {
|
|
|
@@ -721,13 +743,10 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
} else {
|
|
|
List<RealGoodsData> realGoodsData = realGoodsDataMapper.statisticsRealGoodsData(startDate, endDate);
|
|
|
Optional.ofNullable(realGoodsData).ifPresent(list -> list.forEach(data -> {
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getId, data.getGoodsId()).last("limit 1"));
|
|
|
- if (goodsDon != null) {
|
|
|
- data.setGoodsTitle(goodsDon.getTitle());
|
|
|
- }
|
|
|
- GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getId, data.getSkuId()).last("limit 1"));
|
|
|
- if (goodsDonSku != null) {
|
|
|
- data.setSpecVal(goodsDonSku.getSpecVal());
|
|
|
+ GoodsDonSkuView goodsDonSkuView = beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, data.getSkuId()).build());
|
|
|
+ if (goodsDonSkuView != null) {
|
|
|
+ data.setGoodsTitle(goodsDonSkuView.getGoodsTitle());
|
|
|
+ data.setSpecVal(goodsDonSkuView.getSpecVal());
|
|
|
}
|
|
|
data.setRefundMoney(getRefundMoney(null, data.getSkuId(), startDate, endDate));
|
|
|
data.setNumOfRefundOrder(getNumOfRefundOrder(null, data.getSkuId(), startDate, endDate));
|
|
|
@@ -736,37 +755,31 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void headerData(BackgroundDataView backgroundDataView, Date startDate, Date endDate) {
|
|
|
- //总订单数
|
|
|
- List<OrderDon> orderDons = Optional.ofNullable(orderDonService.list(Wrappers.lambdaQuery(OrderDon.class).notIn(OrderDon::getStatus, Constant.noOrderStatus).ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate).lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, endDate))).orElse(new ArrayList<>());
|
|
|
- backgroundDataView.setTotalNumOfOrder(orderDons.size());
|
|
|
- //总下单用户数
|
|
|
- backgroundDataView.setTotalNumOfUser(orderDons.stream().map(OrderDon::getUserId).collect(Collectors.toSet()).size());
|
|
|
- Optional<BigDecimal> totalMoney = orderDons.stream().map(OrderDon::getMoney).reduce(BigDecimal::add);
|
|
|
- //总订单金额
|
|
|
- backgroundDataView.setTotalOrderAmount(totalMoney.isPresent() ? totalMoney.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
|
|
|
- //退款列表
|
|
|
- List<OrderDon> refundOrders = Optional.ofNullable(orderDonService.list(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getStatus, OrderDon.Status.refund).ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate).lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, endDate).select(OrderDon::getId, OrderDon::getRefundMoney))).orElse(new ArrayList<>());
|
|
|
- backgroundDataView.setTotalNumOfRefundOrder(refundOrders.size());
|
|
|
- //退款金额
|
|
|
- Optional<BigDecimal> totalRefundAmount = refundOrders.stream().map(OrderDon::getRefundMoney).reduce(BigDecimal::add);
|
|
|
- backgroundDataView.setTotalRefundAmount(totalRefundAmount.isPresent() ? totalRefundAmount.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
|
|
|
+ private BackgroundDataView getHeaderData(Date startDate, Date endDate) {
|
|
|
+ BackgroundDataView backgroundDataView = orderDonMapper.getBackgroundDataView(startDate, endDate, Constant.noOrderStatus);
|
|
|
//近5天将要到期的主账号总数
|
|
|
DateTime now = DateTime.now();
|
|
|
DateTime zero = DateUtil.beginOfDay(now);
|
|
|
DateTime fiveDays = DateUtil.offsetDay(zero, 5);
|
|
|
//5天后将到期的主账号
|
|
|
- List<Account> willExpireAccounts = Optional.ofNullable(accountService.list(Wrappers.lambdaQuery(Account.class).between(Account::getExpiryTime, zero, fiveDays))).orElse(new ArrayList<>());
|
|
|
- backgroundDataView.setTotalNumOfWillExpireAccount(willExpireAccounts.size());
|
|
|
+ Integer willExpireAccounts = accountService.count(Wrappers.lambdaQuery(Account.class).between(Account::getExpiryTime, zero, fiveDays));
|
|
|
+ backgroundDataView.setTotalNumOfWillExpireAccount(willExpireAccounts);
|
|
|
//已到期主账号
|
|
|
- List<Account> expiredAccounts = Optional.ofNullable(accountService.list(Wrappers.lambdaQuery(Account.class).le(Account::getExpiryTime, now))).orElse(new ArrayList<>());
|
|
|
- backgroundDataView.setTotalExpiredAccountNum(expiredAccounts.size());
|
|
|
+ Integer expiredAccounts = accountService.count(Wrappers.lambdaQuery(Account.class).le(Account::getExpiryTime, now));
|
|
|
+ backgroundDataView.setTotalExpiredAccountNum(expiredAccounts);
|
|
|
//虚物
|
|
|
setGoodsMoneyAndOrder(1, startDate, endDate, backgroundDataView);
|
|
|
//实物
|
|
|
setGoodsMoneyAndOrder(2, startDate, endDate, backgroundDataView);
|
|
|
//潮玩
|
|
|
setGoodsMoneyAndOrder(3, startDate, endDate, backgroundDataView);
|
|
|
+ //已使用余额
|
|
|
+ BigDecimal usedBalance = orderDonMapper.statisticsUsedBalance(startDate, endDate, Constant.noOrderAllStatus);
|
|
|
+ backgroundDataView.setUsedBalance(usedBalance);
|
|
|
+ //剩余余额
|
|
|
+ BigDecimal remainBalance = userMapper.statisticsRemainBalance();
|
|
|
+ backgroundDataView.setRemainBalance(remainBalance);
|
|
|
+ return backgroundDataView;
|
|
|
}
|
|
|
|
|
|
/**
|