|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.nineth.service;
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.izouma.nineth.annotations.Debounce;
|
|
import com.izouma.nineth.annotations.Debounce;
|
|
|
import com.izouma.nineth.config.RedisKeys;
|
|
import com.izouma.nineth.config.RedisKeys;
|
|
|
import com.izouma.nineth.domain.Asset;
|
|
import com.izouma.nineth.domain.Asset;
|
|
@@ -9,7 +10,10 @@ import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.auction.AuctionInputDTO;
|
|
import com.izouma.nineth.dto.auction.AuctionInputDTO;
|
|
|
import com.izouma.nineth.enums.*;
|
|
import com.izouma.nineth.enums.*;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
-import com.izouma.nineth.repo.*;
|
|
|
|
|
|
|
+import com.izouma.nineth.repo.AssetRepo;
|
|
|
|
|
+import com.izouma.nineth.repo.AuctionActivityRepo;
|
|
|
|
|
+import com.izouma.nineth.repo.TokenHistoryRepo;
|
|
|
|
|
+import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
@@ -139,13 +143,13 @@ public class AuctionActivityService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//是否二次拍卖
|
|
//是否二次拍卖
|
|
|
- AuctionActivity activity = auctionActivityRepo.findByAssetId(asset.getId());
|
|
|
|
|
- if (ObjectUtils.isNotEmpty(activity)) {
|
|
|
|
|
- if (!AuctionStatus.PASS.equals(activity.getStatus())) {
|
|
|
|
|
|
|
+ List<AuctionActivity> activity = auctionActivityRepo.findByAssetId(asset.getId());
|
|
|
|
|
+ if (CollUtil.isNotEmpty(activity)) {
|
|
|
|
|
+ if (activity.stream().anyMatch(ac -> !AuctionStatus.PASS.equals(ac.getStatus()))) {
|
|
|
throw new BusinessException("已有拍卖");
|
|
throw new BusinessException("已有拍卖");
|
|
|
}
|
|
}
|
|
|
- log.info("下架流拍拍卖:id-{},assetId-{}", activity.getId(), activity.getAssetId());
|
|
|
|
|
- auctionActivityRepo.updateOnShelf(activity.getId(), false);
|
|
|
|
|
|
|
+ log.info("下架流拍拍卖:assetId-{}", asset.getId());
|
|
|
|
|
+ auctionActivityRepo.updateOnShelf(asset.getId(), false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
asset.setStatus(AssetStatus.AUCTIONING);
|
|
asset.setStatus(AssetStatus.AUCTIONING);
|
|
@@ -185,6 +189,7 @@ public class AuctionActivityService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
private void onShelfTask(AuctionActivity record) {
|
|
private void onShelfTask(AuctionActivity record) {
|
|
|
ScheduledFuture<?> task = tasks.get(record.getId());
|
|
ScheduledFuture<?> task = tasks.get(record.getId());
|
|
|
if (task != null) {
|
|
if (task != null) {
|
|
@@ -196,45 +201,46 @@ public class AuctionActivityService {
|
|
|
if (record.getStartTime().minusSeconds(2).isAfter(LocalDateTime.now())) {
|
|
if (record.getStartTime().minusSeconds(2).isAfter(LocalDateTime.now())) {
|
|
|
Date date = Date.from(record.getStartTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
Date date = Date.from(record.getStartTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
|
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
|
|
- AuctionActivity recordNew1 = auctionActivityRepo.findById(record.getId())
|
|
|
|
|
- .orElseThrow(new BusinessException("无数据"));
|
|
|
|
|
- auctionActivityRepo.scheduleOnShelf(record.getId(), AuctionStatus.ONGOING);
|
|
|
|
|
|
|
+// AuctionActivity recordNew1 = auctionActivityRepo.findById(record.getId())
|
|
|
|
|
+// .orElseThrow(new BusinessException("无数据"));
|
|
|
|
|
+ this.changeStatus(record.getId(), AuctionStatus.ONGOING);
|
|
|
tasks.remove(record.getId());
|
|
tasks.remove(record.getId());
|
|
|
- offShelfTask(recordNew1);
|
|
|
|
|
|
|
+ offShelfTask(auctionActivityRepo.findById(record.getId()).orElseThrow(new BusinessException("无数据")));
|
|
|
}, date);
|
|
}, date);
|
|
|
tasks.put(record.getId(), future);
|
|
tasks.put(record.getId(), future);
|
|
|
} else {
|
|
} else {
|
|
|
- auctionActivityRepo.scheduleOnShelf(record.getId(), AuctionStatus.ONGOING);
|
|
|
|
|
- offShelfTask(record);
|
|
|
|
|
|
|
+ this.changeStatus(record.getId(), AuctionStatus.ONGOING);
|
|
|
|
|
+ offShelfTask(auctionActivityRepo.findById(record.getId()).orElseThrow(new BusinessException("无数据")));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void offShelfTask(AuctionActivity record) {
|
|
public void offShelfTask(AuctionActivity record) {
|
|
|
- ScheduledFuture<?> task = tasks.get(record.getId());
|
|
|
|
|
|
|
+ Long id = record.getId();
|
|
|
|
|
+ ScheduledFuture<?> task = tasks.get(id);
|
|
|
if (task != null) {
|
|
if (task != null) {
|
|
|
if (!task.cancel(true)) {
|
|
if (!task.cancel(true)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-// AuctionActivity recordNew1 = auctionActivityRepo.findById(record.getId())
|
|
|
|
|
|
|
+// AuctionActivity recordNew = auctionActivityRepo.findById(id)
|
|
|
// .orElseThrow(new BusinessException("无数据"));
|
|
// .orElseThrow(new BusinessException("无数据"));
|
|
|
if (record.getStatus().equals(AuctionStatus.ONGOING)) {
|
|
if (record.getStatus().equals(AuctionStatus.ONGOING)) {
|
|
|
if (record.getEndTime().minusSeconds(2).isAfter(LocalDateTime.now())) {
|
|
if (record.getEndTime().minusSeconds(2).isAfter(LocalDateTime.now())) {
|
|
|
Date date = Date.from(record.getEndTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
Date date = Date.from(record.getEndTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
|
ScheduledFuture<?> future = taskScheduler.schedule(() -> {
|
|
|
- AuctionActivity recordNew1 = auctionActivityRepo.findById(record.getId())
|
|
|
|
|
|
|
+ AuctionActivity recordNew1 = auctionActivityRepo.findById(id)
|
|
|
.orElseThrow(new BusinessException("无数据"));
|
|
.orElseThrow(new BusinessException("无数据"));
|
|
|
|
|
|
|
|
if (ObjectUtils.isNotEmpty(recordNew1.getPurchasePrice())) {
|
|
if (ObjectUtils.isNotEmpty(recordNew1.getPurchasePrice())) {
|
|
|
log.info("拍卖成交{}", recordNew1.getId());
|
|
log.info("拍卖成交{}", recordNew1.getId());
|
|
|
- auctionActivityRepo.scheduleOffShelf(recordNew1.getId(), AuctionStatus.PURCHASED);
|
|
|
|
|
|
|
+ this.changeStatus(recordNew1.getId(), AuctionStatus.PURCHASED);
|
|
|
} else {
|
|
} else {
|
|
|
//没有成交价,无人出价过
|
|
//没有成交价,无人出价过
|
|
|
log.info("拍卖流拍Task-else{}", recordNew1.getId());
|
|
log.info("拍卖流拍Task-else{}", recordNew1.getId());
|
|
|
auctionActivityRepo.scheduleOffShelf(recordNew1.getId(), AuctionStatus.PASS);
|
|
auctionActivityRepo.scheduleOffShelf(recordNew1.getId(), AuctionStatus.PASS);
|
|
|
|
|
|
|
|
- if (record.getAuctionType().equals(AuctionType.NFT)) {
|
|
|
|
|
|
|
+ if (AuctionSource.TRANSFER.equals(recordNew1.getSource())) {
|
|
|
Asset asset = assetRepo.findById(recordNew1.getAssetId())
|
|
Asset asset = assetRepo.findById(recordNew1.getAssetId())
|
|
|
.orElseThrow(new BusinessException("暂无"));
|
|
.orElseThrow(new BusinessException("暂无"));
|
|
|
asset.setStatus(AssetStatus.NORMAL);
|
|
asset.setStatus(AssetStatus.NORMAL);
|
|
@@ -243,19 +249,21 @@ public class AuctionActivityService {
|
|
|
assetRepo.save(asset);
|
|
assetRepo.save(asset);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- tasks.remove(record.getId());
|
|
|
|
|
|
|
+ tasks.remove(id);
|
|
|
}, date);
|
|
}, date);
|
|
|
- tasks.put(record.getId(), future);
|
|
|
|
|
|
|
+ tasks.put(id, future);
|
|
|
} else {
|
|
} else {
|
|
|
- if (ObjectUtils.isNotEmpty(record.getPurchasePrice())) {
|
|
|
|
|
- log.info("拍卖成交{}", record.getId());
|
|
|
|
|
- auctionActivityRepo.scheduleOffShelf(record.getId(), AuctionStatus.PURCHASED);
|
|
|
|
|
|
|
+ AuctionActivity recordNew1 = auctionActivityRepo.findById(id)
|
|
|
|
|
+ .orElseThrow(new BusinessException("无数据"));
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(recordNew1.getPurchasePrice())) {
|
|
|
|
|
+ log.info("拍卖成交{}", id);
|
|
|
|
|
+ auctionActivityRepo.scheduleOffShelf(id, AuctionStatus.PURCHASED);
|
|
|
} else {
|
|
} else {
|
|
|
- log.info("拍卖流拍Task-else-else{}", record.getId());
|
|
|
|
|
- auctionActivityRepo.scheduleOffShelf(record.getId(), AuctionStatus.PASS);
|
|
|
|
|
|
|
+ log.info("拍卖流拍Task-else-else{}", id);
|
|
|
|
|
+ auctionActivityRepo.scheduleOffShelf(id, AuctionStatus.PASS);
|
|
|
|
|
|
|
|
- if (record.getAuctionType().equals(AuctionType.NFT)) {
|
|
|
|
|
- Asset asset = assetRepo.findById(record.getAssetId())
|
|
|
|
|
|
|
+ if (AuctionSource.TRANSFER.equals(recordNew1.getSource())) {
|
|
|
|
|
+ Asset asset = assetRepo.findById(recordNew1.getAssetId())
|
|
|
.orElseThrow(new BusinessException("暂无"));
|
|
.orElseThrow(new BusinessException("暂无"));
|
|
|
asset.setStatus(AssetStatus.NORMAL);
|
|
asset.setStatus(AssetStatus.NORMAL);
|
|
|
asset.setConsignment(false);
|
|
asset.setConsignment(false);
|