|
|
@@ -11,6 +11,7 @@ import com.izouma.nineth.enums.TradeAuctionStatus;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.TradeAuctionRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
+import com.izouma.nineth.utils.ObjUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.security.PrivateKey;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@@ -41,6 +43,18 @@ public class TradeAuctionService {
|
|
|
.findAll(JpaUtils.toSpecification(pageQuery, TradeAuction.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
+ public TradeAuction save(TradeAuction record) {
|
|
|
+ if (record.getId() != null) {
|
|
|
+ TradeAuction orig = tradeAuctionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ ObjUtils.merge(orig, record);
|
|
|
+ return tradeAuctionRepo.save(orig);
|
|
|
+ }
|
|
|
+ record.setCurrentEndTime(record.getStartTime());
|
|
|
+ record.setCurrentPrice(record.getPrice());
|
|
|
+ record.setStatus(TradeAuctionStatus.WAITING);
|
|
|
+ return tradeAuctionRepo.save(record);
|
|
|
+ }
|
|
|
+
|
|
|
// public void transfer(Long id) {
|
|
|
// TradeAuctionRecord tradeAuctionRecord = new TradeAuctionRecord();
|
|
|
// TradeAuction tradeAuction = tradeAuctionRepo.findById(id).orElseThrow(new BusinessException("暂无"));
|
|
|
@@ -116,8 +130,11 @@ public class TradeAuctionService {
|
|
|
|
|
|
@Scheduled(fixedRate = 6000)
|
|
|
public void batchStartAuction() {
|
|
|
+ List<TradeAuctionStatus> tradeAuctionStatuses = new ArrayList<>();
|
|
|
+ tradeAuctionStatuses.add(TradeAuctionStatus.WAITING);
|
|
|
+ tradeAuctionStatuses.add(TradeAuctionStatus.NOTSTARTED);
|
|
|
List<TradeAuction> tradeAuctions = tradeAuctionRepo
|
|
|
- .findByStatusAndCurrentEndTimeAfter(TradeAuctionStatus.WAITING,
|
|
|
+ .findByStatusInAndCurrentEndTimeAfter(tradeAuctionStatuses,
|
|
|
LocalDateTime.now().plusMinutes(1));
|
|
|
tradeAuctions.parallelStream().forEach(o -> {
|
|
|
try {
|