|
|
@@ -12,6 +12,7 @@ import com.izouma.nineth.domain.User;
|
|
|
import com.izouma.nineth.enums.BalanceType;
|
|
|
import com.izouma.nineth.enums.CollectionSource;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
+import com.izouma.nineth.enums.OrderType;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.netease.CheckSumBuilder;
|
|
|
@@ -47,7 +48,9 @@ public class StatisticService {
|
|
|
if (user1.isAdmin()) {
|
|
|
long user = userRepo.countAllByDelFalse();
|
|
|
total.put("userNum", user);
|
|
|
- orders = orderRepo.findAllByStatusAndCompanyId(OrderStatus.FINISH, companyId);
|
|
|
+ Set<OrderType> orderTypes = new HashSet<>();
|
|
|
+ orderTypes.add(OrderType.MIX);
|
|
|
+ orders = orderRepo.findAllByStatusAndCompanyIdAndOrderTypeNotIn(OrderStatus.FINISH, companyId, orderTypes);
|
|
|
BigDecimal allRecharged = balanceRecordRepo.sumRechargeAll();
|
|
|
total.put("rechargePrice", allRecharged);
|
|
|
} else {
|
|
|
@@ -56,19 +59,19 @@ public class StatisticService {
|
|
|
|
|
|
Map<CollectionSource, List<Order>> orderMap = orders.stream().collect(Collectors.groupingBy(Order::getSource));
|
|
|
List<Order> officialOrders = Optional.ofNullable(orderMap.get(CollectionSource.OFFICIAL))
|
|
|
- .orElse(Collections.emptyList());
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
List<Order> transferOrders = Optional.ofNullable(orderMap.get(CollectionSource.TRANSFER))
|
|
|
- .orElse(Collections.emptyList());
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
|
|
|
total.put("officialNum", officialOrders.size());
|
|
|
total.put("transferNum", transferOrders.size());
|
|
|
|
|
|
BigDecimal officialPrice = officialOrders.stream()
|
|
|
- .map(Order::getTotalPrice)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ .map(Order::getTotalPrice)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
BigDecimal transferPrice = transferOrders.stream()
|
|
|
- .map(Order::getTotalPrice)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ .map(Order::getTotalPrice)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
total.put("officialPrice", officialPrice);
|
|
|
total.put("transferPrice", transferPrice);
|
|
|
|
|
|
@@ -107,8 +110,8 @@ public class StatisticService {
|
|
|
User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
List<Order> orders;
|
|
|
if (user.isAdmin()) {
|
|
|
- orders = orderRepo.findAllByCreatedAtIsAfterAndStatusInAndCompanyId(start,
|
|
|
- Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), companyId);
|
|
|
+ orders = orderRepo.findAllByCreatedAtIsAfterAndStatusInAndCompanyIdAndOrderTypeNot(start,
|
|
|
+ Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), companyId, OrderType.MIX);
|
|
|
} else {
|
|
|
orders = orderRepo.findAllByCreatedAtIsAfterAndMinterIdAndStatusIn(start, userId,
|
|
|
Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
|
|
|
@@ -121,14 +124,14 @@ public class StatisticService {
|
|
|
if (CollUtil.isNotEmpty(orderMap.get(CollectionSource.OFFICIAL))) {
|
|
|
official = orderMap.get(CollectionSource.OFFICIAL).stream().collect(Collectors.groupingBy(
|
|
|
item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
- .format(item.getCreatedAt()), Collectors.counting()));
|
|
|
+ .format(item.getCreatedAt()), Collectors.counting()));
|
|
|
}
|
|
|
|
|
|
Map<String, Long> transfer = null;
|
|
|
if (CollUtil.isNotEmpty(orderMap.get(CollectionSource.TRANSFER))) {
|
|
|
transfer = orderMap.get(CollectionSource.TRANSFER).stream().collect(Collectors.groupingBy(
|
|
|
item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
- .format(item.getCreatedAt()), Collectors.counting()));
|
|
|
+ .format(item.getCreatedAt()), Collectors.counting()));
|
|
|
}
|
|
|
|
|
|
Map<String, Map<String, Long>> trend = new HashMap<>();
|
|
|
@@ -145,16 +148,20 @@ public class StatisticService {
|
|
|
List<Order> orders;
|
|
|
Map<String, Map<String, BigDecimal>> trend = new HashMap<>();
|
|
|
if (user.isAdmin()) {
|
|
|
- orders = orderRepo.findAllByCreatedAtIsAfterAndStatusInAndCompanyId(start,
|
|
|
- Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), companyId);
|
|
|
+ orders = orderRepo.findAllByCreatedAtIsAfterAndStatusInAndCompanyIdAndOrderTypeNot(start,
|
|
|
+ Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), companyId, OrderType.MIX);
|
|
|
List<BalanceRecord> balanceRecords = balanceRecordRepo
|
|
|
.findByTypeAndCreatedAtBetween(BalanceType.RECHARGE, start, LocalDateTime.now());
|
|
|
Map<String, BigDecimal> recharged = null;
|
|
|
if (balanceRecords.size() > 0) {
|
|
|
recharged = balanceRecords.stream()
|
|
|
- .collect(Collectors.groupingBy(item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
- .format(item.getCreatedAt()), Collectors.mapping(BalanceRecord::getAmount,
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+ .collect(Collectors
|
|
|
+ .groupingBy(item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
+ .format(item
|
|
|
+ .getCreatedAt()), Collectors
|
|
|
+ .mapping(BalanceRecord::getAmount,
|
|
|
+ Collectors
|
|
|
+ .reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
}
|
|
|
trend.put("recharged", recharged);
|
|
|
} else {
|
|
|
@@ -166,21 +173,23 @@ public class StatisticService {
|
|
|
Map<String, BigDecimal> official = null;
|
|
|
if (CollUtil.isNotEmpty(orderMap.get(CollectionSource.OFFICIAL))) {
|
|
|
official = orderMap.get(CollectionSource.OFFICIAL)
|
|
|
- .stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
- .format(item.getCreatedAt()), Collectors.mapping(Order::getTotalPrice,
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
+ .format(item.getCreatedAt()), Collectors
|
|
|
+ .mapping(Order::getTotalPrice,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
}
|
|
|
|
|
|
Map<String, BigDecimal> transfer = null;
|
|
|
if (CollUtil.isNotEmpty(orderMap.get(CollectionSource.TRANSFER))) {
|
|
|
transfer = orderMap.get(CollectionSource.TRANSFER)
|
|
|
- .stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
- .format(item.getCreatedAt()), Collectors.mapping(Order::getTotalPrice,
|
|
|
- Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ item -> DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
|
+ .format(item.getCreatedAt()), Collectors
|
|
|
+ .mapping(Order::getTotalPrice,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
}
|
|
|
|
|
|
trend.put("official", official);
|
|
|
@@ -202,8 +211,8 @@ public class StatisticService {
|
|
|
List<Order> orders;
|
|
|
Map<String, BigDecimal> map = new HashMap<>();
|
|
|
if (user.isAdmin()) {
|
|
|
- orders = orderRepo.findAllByCreatedAtBetweenAndStatusInAndCompanyId(start, end,
|
|
|
- Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), companyId);
|
|
|
+ orders = orderRepo.findAllByCreatedAtBetweenAndStatusInAndCompanyIdAndOrderTypeNot(start, end,
|
|
|
+ Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), companyId, OrderType.MIX);
|
|
|
BigDecimal allRecharged = balanceRecordRepo.sumRechargeToday(start, end);
|
|
|
map.put("recharged", allRecharged);
|
|
|
} else {
|
|
|
@@ -211,9 +220,9 @@ public class StatisticService {
|
|
|
Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH));
|
|
|
}
|
|
|
map.put("official", orders.stream().filter(order -> order.getSource().equals(CollectionSource.OFFICIAL))
|
|
|
- .map(Order::getPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
|
|
|
+ .map(Order::getPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
|
|
|
map.put("transfer", orders.stream().filter(order -> order.getSource().equals(CollectionSource.TRANSFER))
|
|
|
- .map(Order::getPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
|
|
|
+ .map(Order::getPrice).reduce(BigDecimal::add).orElse(BigDecimal.ZERO));
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@@ -374,10 +383,10 @@ public class StatisticService {
|
|
|
headers.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
headers.put("Accept", "application/json, text/plain, */*");
|
|
|
return HttpRequest.post(url)
|
|
|
- .contentType(HttpRequest.CONTENT_TYPE_JSON)
|
|
|
- .headers(headers)
|
|
|
- .send(JSON.toJSONString(params))
|
|
|
- .body();
|
|
|
+ .contentType(HttpRequest.CONTENT_TYPE_JSON)
|
|
|
+ .headers(headers)
|
|
|
+ .send(JSON.toJSONString(params))
|
|
|
+ .body();
|
|
|
}
|
|
|
|
|
|
public String getToken(String username, String password, String url) {
|
|
|
@@ -386,10 +395,10 @@ public class StatisticService {
|
|
|
params.put("username", username);
|
|
|
params.put("password", password);
|
|
|
return HttpRequest.post(url)
|
|
|
- .contentType("application/x-www-form-urlencoded")
|
|
|
- .headers(headers)
|
|
|
- .form(params)
|
|
|
- .body();
|
|
|
+ .contentType("application/x-www-form-urlencoded")
|
|
|
+ .headers(headers)
|
|
|
+ .form(params)
|
|
|
+ .body();
|
|
|
}
|
|
|
|
|
|
public Map<String, Map<String, Object>> statisticDetail() {
|
|
|
@@ -414,17 +423,18 @@ public class StatisticService {
|
|
|
Map<String, Object> today = new HashMap<>();
|
|
|
//充值
|
|
|
BigDecimal rcToday = Optional.ofNullable(balanceRecordRepo.sumRechargeToday(todayStart, todayEnd))
|
|
|
- .orElse(BigDecimal.ZERO);
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
today.put("recharge", rcToday);
|
|
|
//提现
|
|
|
BigDecimal wdToday = Optional.ofNullable(balanceRecordRepo.sumWithdrawToday(todayStart, todayEnd))
|
|
|
- .orElse(BigDecimal.ZERO);
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
today.put("withdraw", wdToday);
|
|
|
//星图
|
|
|
BigDecimal paToday = Optional.ofNullable(photoAssetRepo.sumPaid(todayStart, todayEnd)).orElse(BigDecimal.ZERO);
|
|
|
today.put("photoAsset", paToday);
|
|
|
- List<Order> orders = orderRepo.findAllByCreatedAtBetweenAndStatusInAndCompanyId(todayStart, todayEnd,
|
|
|
- Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), 1L);
|
|
|
+ List<Order> orders = orderRepo
|
|
|
+ .findAllByCreatedAtBetweenAndStatusInAndCompanyIdAndOrderTypeNot(todayStart, todayEnd,
|
|
|
+ Arrays.asList(OrderStatus.PROCESSING, OrderStatus.FINISH), 1L, OrderType.MIX);
|
|
|
///手续费
|
|
|
List<BigDecimal> ros = new ArrayList<>();
|
|
|
List<BigDecimal> scs = new ArrayList<>();
|
|
|
@@ -439,7 +449,7 @@ public class StatisticService {
|
|
|
scs.add(orderSc);
|
|
|
}
|
|
|
BigDecimal todayRo = Optional.of(ros.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO))
|
|
|
- .orElse(BigDecimal.ZERO);
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
today.put("royalties", todayRo);
|
|
|
//版权费
|
|
|
BigDecimal todaySc = scs.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|