|
|
@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -79,15 +80,50 @@ public class BidServiceImpl implements IBidService
|
|
|
live = rebuildLive(bid);
|
|
|
}
|
|
|
Long previousEndTime = live.getCurrentEndTime();
|
|
|
+ log.info("addPrice live snapshot auctionId:{} lotId:{} bidAmount:{} liveClass:{} ruleType:{} liveLotStatus:{} currentEndTime:{} currentPrice:{} currentStartPrice:{} currentOnceAddPrice:{} onceDelayTime:{} round:{}",
|
|
|
+ bid.getAuctionId(),
|
|
|
+ bid.getLotId(),
|
|
|
+ bid.getAmount(),
|
|
|
+ live.getClass().getSimpleName(),
|
|
|
+ ruleType(live),
|
|
|
+ Objects.nonNull(live.getLot()) ? live.getLot().getStatus() : null,
|
|
|
+ previousEndTime,
|
|
|
+ currentPrice(live),
|
|
|
+ currentStartPrice(live),
|
|
|
+ currentOnceAddPrice(live),
|
|
|
+ onceDelayTime(live),
|
|
|
+ live.getRound());
|
|
|
// 插入新的出价
|
|
|
insertCurrBid(bid, live.getRound());
|
|
|
// 执行addPrice方法之前已进行了拍卖状态的判断
|
|
|
// 但由于是在分布式锁之外判断的 这里做二次判断 以防并发问题
|
|
|
String currentStatus = ruleHandlerHolder.getCurrentStatus(live);
|
|
|
+ log.info("addPrice status check auctionId:{} lotId:{} currentStatus:{} previousEndTime:{} serverTime:{} remainingMs:{}",
|
|
|
+ bid.getAuctionId(),
|
|
|
+ bid.getLotId(),
|
|
|
+ currentStatus,
|
|
|
+ previousEndTime,
|
|
|
+ System.currentTimeMillis(),
|
|
|
+ Objects.nonNull(previousEndTime) ? previousEndTime - System.currentTimeMillis() : null);
|
|
|
if (Objects.equals(Constants.LOT_STATUS_STARTING, currentStatus) || Objects.equals(Constants.LOT_STATUS_BIDDING, currentStatus)) {
|
|
|
Lot dbUpdate = Lot.builder().id(live.getLot().getId()).build();
|
|
|
LiveContext liveContext = LiveContext.builder().dbLot(dbUpdate).live(live).dbBid(bid).build();
|
|
|
+ Long beforeRuleEndTime = live.getCurrentEndTime();
|
|
|
ruleHandlerHolder.addPrice(liveContext); // 实时计算中。。。。
|
|
|
+ log.info("addPrice rule calculated auctionId:{} lotId:{} ruleType:{} onceDelayTime:{} error:{} beforeEndTime:{} afterEndTime:{} delayChanged:{} serverTime:{} remainingMs:{} currentPrice:{} currentStartPrice:{} currentOnceAddPrice:{}",
|
|
|
+ bid.getAuctionId(),
|
|
|
+ bid.getLotId(),
|
|
|
+ ruleType(live),
|
|
|
+ onceDelayTime(live),
|
|
|
+ liveContext.getError(),
|
|
|
+ beforeRuleEndTime,
|
|
|
+ live.getCurrentEndTime(),
|
|
|
+ !Objects.equals(beforeRuleEndTime, live.getCurrentEndTime()),
|
|
|
+ System.currentTimeMillis(),
|
|
|
+ Objects.nonNull(live.getCurrentEndTime()) ? live.getCurrentEndTime() - System.currentTimeMillis() : null,
|
|
|
+ currentPrice(live),
|
|
|
+ currentStartPrice(live),
|
|
|
+ currentOnceAddPrice(live));
|
|
|
if (StringUtils.isEmpty(liveContext.getError())) {
|
|
|
// 到这一步 已经完成了实时数据的计算 以下代码就需要对这些计算结果落库或者更新缓存
|
|
|
runnable.run(); // 实际这里执行的是扣减积分的操作
|
|
|
@@ -96,6 +132,9 @@ public class BidServiceImpl implements IBidService
|
|
|
redisCache.setList(String.format(Constants.REDIS_MAP_AUC_LOT_BID_TEMPLATE, live.getLot().getId()), bidList);
|
|
|
live.getLot().setProperties(null);
|
|
|
redisCache.setCacheMapValue(String.format(Constants.REDIS_MAP_AUC_LOT_TEMPLATE, live.getLot().getAuctionId()), live.getLot().getId().toString(), live);
|
|
|
+ if (Objects.nonNull(cacheMap)) {
|
|
|
+ cacheMap.putLive(live);
|
|
|
+ }
|
|
|
publishRealtime(live, previousEndTime);
|
|
|
// 这里发送 状态变更消息 其中同步内存中的缓存和发送IM消息给APP
|
|
|
//TODO 异常问题
|
|
|
@@ -196,6 +235,49 @@ public class BidServiceImpl implements IBidService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String ruleType(Live live) {
|
|
|
+ return Objects.nonNull(live) && Objects.nonNull(live.getLot()) ? live.getLot().getRuleType() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long onceDelayTime(Live live) {
|
|
|
+ if (live instanceof TraditionLive && Objects.nonNull(((TraditionLive) live).getTraditionRule())) {
|
|
|
+ return ((TraditionLive) live).getTraditionRule().getOnceDelayTime();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal currentPrice(Live live) {
|
|
|
+ if (live instanceof TraditionLive) {
|
|
|
+ return ((TraditionLive) live).getCurrentPrice();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal currentStartPrice(Live live) {
|
|
|
+ if (live instanceof TraditionLive) {
|
|
|
+ return ((TraditionLive) live).getCurrentStartPrice();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal currentOnceAddPrice(Live live) {
|
|
|
+ if (live instanceof TraditionLive) {
|
|
|
+ return ((TraditionLive) live).getCurrentOnceAddPrice();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+// private void publishChange(Live live, List<Bid> bidList) {
|
|
|
+// try {
|
|
|
+// if (Objects.nonNull(eventPublisher)) {
|
|
|
+// eventPublisher.publishChangeEvent(new ChangeEvent(live, null, bidList));
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("publish addPrice change event error, lotId:{}",
|
|
|
+// Objects.nonNull(live) && Objects.nonNull(live.getLot()) ? live.getLot().getId() : null, e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
private void insertCurrBid(BidVO bid, Long round) {
|
|
|
bidMapper.clearCurrentBid(bid.getLotId());
|
|
|
bid.setDelFlag(Constants.DEL_FLAG_NO_DELETE);
|