|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.nineth.service;
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
|
|
import com.izouma.nineth.TokenHistory;
|
|
import com.izouma.nineth.TokenHistory;
|
|
|
|
|
+import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.domain.*;
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.UserHistory;
|
|
import com.izouma.nineth.dto.UserHistory;
|
|
@@ -17,6 +18,9 @@ import com.izouma.nineth.utils.TokenUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
|
|
|
|
+import org.apache.rocketmq.common.message.Message;
|
|
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
@@ -25,6 +29,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -44,8 +49,9 @@ public class AssetService {
|
|
|
private ApplicationContext applicationContext;
|
|
private ApplicationContext applicationContext;
|
|
|
private OrderRepo orderRepo;
|
|
private OrderRepo orderRepo;
|
|
|
private TokenHistoryRepo tokenHistoryRepo;
|
|
private TokenHistoryRepo tokenHistoryRepo;
|
|
|
- private AssetMintService assetMintService;
|
|
|
|
|
private SysConfigService sysConfigService;
|
|
private SysConfigService sysConfigService;
|
|
|
|
|
+ private RocketMQTemplate rocketMQTemplate;
|
|
|
|
|
+ private GeneralProperties generalProperties;
|
|
|
|
|
|
|
|
public Page<Asset> all(PageQuery pageQuery) {
|
|
public Page<Asset> all(PageQuery pageQuery) {
|
|
|
return assetRepo.findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
|
|
return assetRepo.findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
|
|
@@ -57,7 +63,7 @@ public class AssetService {
|
|
|
asset.setNumber(number);
|
|
asset.setNumber(number);
|
|
|
asset.setOrderId(orderId);
|
|
asset.setOrderId(orderId);
|
|
|
asset.setPrice(price);
|
|
asset.setPrice(price);
|
|
|
- assetRepo.save(asset);
|
|
|
|
|
|
|
+ assetRepo.saveAndFlush(asset);
|
|
|
|
|
|
|
|
tokenHistoryRepo.save(TokenHistory.builder()
|
|
tokenHistoryRepo.save(TokenHistory.builder()
|
|
|
.tokenId(asset.getTokenId())
|
|
.tokenId(asset.getTokenId())
|
|
@@ -70,7 +76,7 @@ public class AssetService {
|
|
|
.operation(type)
|
|
.operation(type)
|
|
|
.price(price)
|
|
.price(price)
|
|
|
.build());
|
|
.build());
|
|
|
- assetMintService.mint(asset);
|
|
|
|
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getMintTopic(), asset.getId());
|
|
|
return asset;
|
|
return asset;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -93,7 +99,7 @@ public class AssetService {
|
|
|
.operation(type)
|
|
.operation(type)
|
|
|
.price(price)
|
|
.price(price)
|
|
|
.build());
|
|
.build());
|
|
|
- assetMintService.mint(asset.getId(), user.getId());
|
|
|
|
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getMintTopic(), asset.getId());
|
|
|
return asset;
|
|
return asset;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -367,7 +373,7 @@ public class AssetService {
|
|
|
|
|
|
|
|
public String mint() {
|
|
public String mint() {
|
|
|
for (Asset asset : assetRepo.findByTxHashIsNullAndTokenIdNotNullAndCreatedAtBefore(LocalDateTime.now())) {
|
|
for (Asset asset : assetRepo.findByTxHashIsNullAndTokenIdNotNullAndCreatedAtBefore(LocalDateTime.now())) {
|
|
|
- assetMintService.mint(asset);
|
|
|
|
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getMintTopic(), asset.getId());
|
|
|
}
|
|
}
|
|
|
return "ok";
|
|
return "ok";
|
|
|
}
|
|
}
|