|
|
@@ -1,9 +1,11 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.izouma.nineth.TokenHistory;
|
|
|
import com.izouma.nineth.annotations.Debounce;
|
|
|
import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.config.RedisKeys;
|
|
|
+import com.izouma.nineth.converter.LongArrayConverter;
|
|
|
import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.*;
|
|
|
@@ -43,6 +45,7 @@ import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@@ -481,7 +484,7 @@ public class CollectionService {
|
|
|
public List<PointDTO> savePoint(Long collectionId, LocalDateTime time) {
|
|
|
Collection collection = collectionRepo.findById(collectionId).orElseThrow(new BusinessException("无藏品"));
|
|
|
//库存
|
|
|
- int stock = collection.getStock();
|
|
|
+// int stock = collection.getStock();
|
|
|
//是否开启白名单
|
|
|
int assignment = collection.getAssignment();
|
|
|
if (assignment <= 0) {
|
|
|
@@ -496,17 +499,26 @@ public class CollectionService {
|
|
|
AtomicInteger sum = new AtomicInteger();
|
|
|
AtomicInteger sum1 = new AtomicInteger();
|
|
|
List<PointDTO> dtos = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> historyMap = tokenHistoryRepo.userBuy(userMap.keySet())
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(TokenHistory::getToUserId, Collectors.reducing(BigDecimal.ZERO,
|
|
|
+ TokenHistory::getPrice,
|
|
|
+ BigDecimal::add)));
|
|
|
+
|
|
|
+ DateTimeFormatter dft = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
userMap.forEach((key, value) -> {
|
|
|
//邀请达到数量
|
|
|
if (value.size() >= collection.getAssignment()) {
|
|
|
value.sort(Comparator.comparing(User::getCreatedAt));
|
|
|
- BigDecimal buy = tokenHistoryRepo.userBuy(key);
|
|
|
+ BigDecimal buy = historyMap.get(key);
|
|
|
//满足条件的时间
|
|
|
User user = value.get(collection.getAssignment() - 1);
|
|
|
+ //作弊得已屏蔽
|
|
|
if ((ObjectUtils.isEmpty(buy) || buy.compareTo(BigDecimal.valueOf(500)) < 0) && user.getCreatedAt()
|
|
|
.isBefore(time)) {
|
|
|
sum1.getAndIncrement();
|
|
|
- System.out.println(key + "," + user.getCreatedAt() + "," + buy);
|
|
|
+ System.out.println(key + "," + dft.format(user.getCreatedAt()) + "," + buy);
|
|
|
} else {
|
|
|
//实名数量
|
|
|
long identitySum = value.stream().filter(u -> AuthStatus.SUCCESS.equals(u.getAuthStatus())).count();
|
|
|
@@ -518,15 +530,43 @@ public class CollectionService {
|
|
|
log.info("完成任务人数:{}", sum);
|
|
|
log.info("作弊任务人数:{}", sum1);
|
|
|
|
|
|
- //只留库存数量
|
|
|
- List<PointDTO> result = dtos.stream()
|
|
|
- .sorted(Comparator.comparing(PointDTO::getCreatedAt))
|
|
|
- .limit(stock)
|
|
|
+ LongArrayConverter longArrayConverter = new LongArrayConverter();
|
|
|
+
|
|
|
+ List<Long> collect = dtos.stream()
|
|
|
+ .filter(dto -> time.isBefore(dto.getCreatedAt()))
|
|
|
+ .map(PointDTO::getId)
|
|
|
.collect(Collectors.toList());
|
|
|
- List<Long> userIds = result.stream().map(PointDTO::getId).collect(Collectors.toList());
|
|
|
- Map<Long, User> resultMap = userRepo.findAllById(userIds)
|
|
|
- .stream()
|
|
|
- .collect(Collectors.toMap(User::getId, user -> user));
|
|
|
+ log.info(dft.format(time) + "前完成任务人数:{}", collect.size());
|
|
|
+ log.info("sql: update user set vip_point = 1 where id in ({})", longArrayConverter.convertToDatabaseColumn(collect));
|
|
|
+
|
|
|
+ List<PointDTO> collect1 = dtos.stream().filter(dto -> time.isAfter(dto.getCreatedAt())).collect(Collectors.toList());
|
|
|
+ log.info(dft.format(time) + "后完成任务人数:{}", collect1.size());
|
|
|
+
|
|
|
+ List<Long> collect2 = dtos.stream().filter(dto -> dto.getIdentitySum() > 0).map(PointDTO::getId).collect(Collectors.toList());
|
|
|
+ log.info("邀请实名认证人量:{}", collect2.size());
|
|
|
+ log.info("sql: update user set vip_point = 1 where id in ({})", longArrayConverter.convertToDatabaseColumn(collect2));
|
|
|
+
|
|
|
+ //只留库存数量
|
|
|
+// List<PointDTO> result = dtos.stream()
|
|
|
+// .sorted(Comparator.comparing(PointDTO::getCreatedAt))
|
|
|
+// .collect(Collectors.toList());
|
|
|
+// List<Long> userIds = result.stream().map(PointDTO::getId).collect(Collectors.toList());
|
|
|
+// Map<Long, User> resultMap = userRepo.findAllById(userIds)
|
|
|
+// .stream()
|
|
|
+// .collect(Collectors.toMap(User::getId, user -> user));
|
|
|
+//
|
|
|
+// List<PointDTO> result2 = new ArrayList<>();
|
|
|
+// List<PointDTO> result3 = new ArrayList<>();
|
|
|
+// result.forEach(dto -> {
|
|
|
+// if (dto.getIdentitySum() > 0) {
|
|
|
+// result2.add(dto);
|
|
|
+// } else {
|
|
|
+// result3.add(dto);
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// result2.addAll(result3);
|
|
|
+
|
|
|
|
|
|
//加积分,存记录
|
|
|
// result.forEach(pointDTO -> {
|
|
|
@@ -534,7 +574,6 @@ public class CollectionService {
|
|
|
// if (user.getVipPoint() <= 0) {
|
|
|
// user.setVipPoint(1);
|
|
|
// userRepo.save(user);
|
|
|
-//// userRepo.updateVipPoint(pointDTO.getId(), 1);
|
|
|
// pointRecordRepo.save(PointRecord.builder()
|
|
|
// .collectionId(collectionId)
|
|
|
// .userId(pointDTO.getId())
|