记得上下班打卡 | git大法好,push需谨慎

Commit eb1ea742 authored by anjiabin's avatar anjiabin

实现xuper相关艺术品上传

parent 6982f6fe
......@@ -3,6 +3,7 @@ package com.liquidnet.common.third.xuper.config;
import com.baidu.xasset.client.xasset.Asset;
import com.baidu.xasset.common.config.Config;
import com.liquidnet.commons.lang.util.MD5Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
......@@ -18,6 +19,7 @@ import java.util.logging.Logger;
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/4/18 17:42
*/
@Slf4j
@Configuration
public class XuperConfig {
@Value("${liquidnet.service.galaxy.xuper.appId:110381}")
......@@ -33,6 +35,9 @@ public class XuperConfig {
private Asset asset = null;
private static Asset staticAsset = null;
private static Logger logger = Logger.getLogger(XuperConfig.class.getCanonicalName());
@PostConstruct
public void init(){
long _appId = Long.parseLong(appId);
......@@ -46,6 +51,11 @@ public class XuperConfig {
cfg.setEndPoint(nftApiUrl);
// 初始化接口类
// Logger logger = Logger.getGlobal();
// logger.getParent().setLevel(Level.INFO);
log.info("logger.getParent().getLevel() === {}",logger.getParent().getLevel());
// logger.setLevel(Level.INFO);
log.info("logger.getLevel() === {}",logger.getLevel());
asset = new Asset(cfg, Logger.getGlobal());
}
//
......
package com.liquidnet.common.third.xuper.dto;
import lombok.Data;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
......@@ -9,7 +11,12 @@ package com.liquidnet.common.third.xuper.dto;
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/4/18 15:10
*/
@Data
public class Xuper004PublishAssetRespDto {
public long requestId;
public int errNo;
public String errMsg;
private static final Xuper004PublishAssetRespDto obj = new Xuper004PublishAssetRespDto();
public static Xuper004PublishAssetRespDto getNew() {
try {
......
package com.liquidnet.service.galaxy.biz;
import com.liquidnet.common.third.antchain.constant.AntchainEnum;
import com.liquidnet.common.third.xuper.constant.XuperEnum;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
......@@ -46,6 +47,20 @@ public class GalaxyEnumBiz {
taskStatusEnum = GalaxyEnum.TaskStatusEnum.TASK_FAIL;
break;
}
case "xuper":
if(code.equalsIgnoreCase(XuperEnum.AssetStatusEnum.INIT.getCode())||code.equalsIgnoreCase(XuperEnum.AssetStatusEnum.PUBLISHING.getCode())){
taskStatusEnum = GalaxyEnum.TaskStatusEnum.PROCESSING;
break;
}else if(code.equalsIgnoreCase(XuperEnum.AssetStatusEnum.PUBLISH_SUCCESS.getCode())){
taskStatusEnum = GalaxyEnum.TaskStatusEnum.TASK_SUCCESS;
break;
}else if(code.equalsIgnoreCase(XuperEnum.AssetStatusEnum.FREEZING.getCode())
||code.equalsIgnoreCase(XuperEnum.AssetStatusEnum.BANNEDING.getCode())
||code.equalsIgnoreCase(XuperEnum.AssetStatusEnum.BANNEDED.getCode())
){
taskStatusEnum = GalaxyEnum.TaskStatusEnum.TASK_FAIL;
break;
}
}
return taskStatusEnum;
}
......
package com.liquidnet.service.galaxy.router.xuper.biz;
import com.liquidnet.common.third.xuper.dto.Xuper007GrantShardReqDto;
import com.liquidnet.common.third.xuper.dto.Xuper007GrantShardRespDto;
import com.liquidnet.common.third.xuper.dto.XuperResponseDto;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
import com.liquidnet.common.third.zxlnft.dto.Nft044BuyResultReqDto;
import com.liquidnet.common.third.zxlnft.dto.Nft044BuyResultRespDto;
import com.liquidnet.common.third.zxlnft.dto.ZxlnftResponseDto;
import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.galaxy.biz.GalaxyBeanTransferBiz;
import com.liquidnet.service.galaxy.biz.GalaxyEnumBiz;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
import com.liquidnet.service.galaxy.constant.GalaxyErrorEnum;
import com.liquidnet.service.galaxy.dto.bo.GalaxyNftOrderBindBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxyNftOrderBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
......@@ -20,13 +27,11 @@ import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishAndBuyReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishAndBuyRespDto;
import com.liquidnet.service.galaxy.dto.vo.mongo.GalaxyNftOrderFailLogVo;
import com.liquidnet.service.galaxy.exception.GalaxyNftBuyException;
import com.liquidnet.service.galaxy.exception.GalaxyNftPublishException;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.Date;
......@@ -57,261 +62,7 @@ public class XuperTradeCommonBiz {
@Autowired
private GalaxyBeanTransferBiz galaxyBeanTransferBiz;
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
log.info("开始执行nftPublishAndBuy 请求参数:{}",reqDto.toString());
//获取用户信息
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId());
if(StringUtil.isNull(userInfoBo)){
log.error("开始执行nftPublishAndBuy error msg:{}",GalaxyErrorEnum.NFT_BUY_FAIL_USER_NOT_EXIST.getMessage());
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL_USER_NOT_EXIST.getCode(), GalaxyErrorEnum.NFT_BUY_FAIL_USER_NOT_EXIST.getMessage());
}
//获取sku信息
GalaxySeriesNftInfoBo seriesNftInfoBo = dataUtils.getSeriesNftInfoBo(reqDto.getRouterType(),reqDto.getSkuId());
if(StringUtil.isNull(seriesNftInfoBo)||StringUtil.isEmpty(seriesNftInfoBo.getSeriesId())){
log.error("开始执行nftPublishAndBuy error msg:{}",GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getMessage());
return ResponseDto.failure(GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getCode(), GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getMessage());
}
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
//初始化订单数据
if(nftOrderBo==null){
nftOrderBo = galaxyBeanTransferBiz.buildNftOrderBo(reqDto.getNftOrderPayId(),userInfoBo,seriesNftInfoBo);
dataUtils.setNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}else if(StringUtil.isNotNull(nftOrderBo)){
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())
&&nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
nftPublishAndBuyRespDto.setUserId(reqDto.getUserId());
nftPublishAndBuyRespDto.setNftId(nftOrderBo.getNftId());
log.error("开始执行nftPublishAndBuy error msg:{}", GalaxyErrorEnum.PUBLISH_FAIL_ALREADY_EXIST.toString());
return ResponseDto.success(nftPublishAndBuyRespDto);
}
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())
&&(nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.INIT.getCode())
||nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.PROCESSING.getCode()))){
//再次发起购买
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = this.executeBuyBusiness(reqDto,userInfoBo,seriesNftInfoBo,nftOrderBo);
if(StringUtil.isNotNull(nftPublishAndBuyRespDto)&&StringUtil.isNotEmpty(nftPublishAndBuyRespDto.getNftId())){
return ResponseDto.success(nftPublishAndBuyRespDto);
}else{
log.error("开始执行nftPublishAndBuy-->executeBuyBusiness error msg:{}",GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL.getCode(),GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
}
}
}
String author = seriesNftInfoBo.getAuthor();
String nftName = seriesNftInfoBo.getNftName();
String nftUrl = seriesNftInfoBo.getNftUrl();
String displayUrl = seriesNftInfoBo.getDisplayUrl();
String nftDesc = seriesNftInfoBo.getNftDesc();
String nftFlag = seriesNftInfoBo.getNftFlag();
//发行个数
Long publishCount = 1L;
//开始索引
Integer seriesBeginIndex = null;
//发行金额
Long sellCount = seriesNftInfoBo.getSellCount().longValue(); //积分
/**
* 根据sku获取系列Id
*/
String seriesId = seriesNftInfoBo.getSeriesId();
//返回参数nftId
String nftId = null;
String publishTaskId = null;
Long nftPublishChainTimestamp = null;
Integer nftPublishStatus = null;
String nftPublishTradeHash = null;
//定义失败信息
String failDesc = null;
try{
/**
* 获取订单和nft绑定信息
*/
GalaxyNftOrderBindBo nftOrderBindBo = dataUtils.getGalaxyNftOrderBindBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNull(nftOrderBindBo)){
//获取发行索引
long nftIdNo = dataUtils.incrNftIdNo(reqDto.getRouterType(),reqDto.getSkuId());
//如果发行数大于最大发行数量
if(nftIdNo > seriesNftInfoBo.getNftTotalCount()){
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"该sku:"+reqDto.getSkuId()+" 总共"+seriesNftInfoBo.getNftTotalCount()+"个NFT已经发行完毕,没有剩余库存!");
}
nftOrderBindBo = GalaxyNftOrderBindBo.getNew();
nftOrderBindBo.setNftOrderPayId(reqDto.getNftOrderPayId());
nftOrderBindBo.setSeriesId(seriesNftInfoBo.getSeriesId());
nftOrderBindBo.setSeriesCode(seriesNftInfoBo.getSeriesCode());
nftOrderBindBo.setNftIdIndex(Integer.valueOf(String.valueOf(nftIdNo)));
nftOrderBindBo.setRouterType(reqDto.getRouterType());
String nowTimeStr = DateUtil.Formatter.yyyyMMddHHmmss.format(LocalDateTime.now());
nftOrderBindBo.setCreatedAt(nowTimeStr);
dataUtils.setGalaxyNftOrderBindBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBindBo);
}
seriesBeginIndex = nftOrderBindBo.getNftIdIndex();
// //查询系列信息(暂时不通过系列查询获取发行序列号)
// Nft032SeriesReqDto nft032ReqDto = Nft032SeriesReqDto.getNew();
// nft032ReqDto.setSeriesId(seriesId);
// ZxlnftResponseDto<Nft032SeriesRespDto> resp = zxlnftSdkUtil.nft032Series(nft032ReqDto);
//
// if(resp.isSuccess()){
// //该系列已经发行多少个nft
// Long crtCount = resp.getData().getSeriesInfo().getCrtCount();
// log.info("系列:{} 已发行 :{}", seriesId, crtCount);
// //设置开始索引
// seriesBeginIndex = Integer.parseInt(String.valueOf(crtCount.longValue() + 1));
// }
/**
* 如果已经发行购买成功
*/
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.PROCESSING.getCode())){
if(StringUtil.isNotEmpty(nftOrderBo.getNftPublishTaskId())){
publishTaskId = nftOrderBo.getNftPublishTaskId();
}
}else if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.INIT.getCode())){
//3.1.2调用NFT发行接口
/**
* 发行无限制系列
*/
Nft034PublishReqDto nft034ReqDto = Nft034PublishReqDto.getNew();
nft034ReqDto.setAuthor(author);
nft034ReqDto.setName(nftName);
nft034ReqDto.setUrl(nftUrl);
nft034ReqDto.setDisplayUrl(displayUrl);
nft034ReqDto.setDesc(nftDesc);
nft034ReqDto.setFlag(nftFlag);
nft034ReqDto.setPublishCount(publishCount);
//无限制零系列
nft034ReqDto.setSeriesId(seriesId);
nft034ReqDto.setSeriesBeginIndex(seriesBeginIndex);
nft034ReqDto.setSellStatus(Integer.parseInt(ZxlnftEnum.SellStatusEnum.CAN_SELL.getCode()));
nft034ReqDto.setSellCount(sellCount);
nft034ReqDto.setOperateId(IDGenerator.get32UUID());
nft034ReqDto.setMetaData(seriesNftInfoBo.getNftHash());
ZxlnftResponseDto<Nft034PublishRespDto> nft034RespDto = zxlnftSdkUtil.nft034Publish(nft034ReqDto);
if (nft034RespDto.isSuccess()){
publishTaskId = nft034RespDto.getData().getTaskId();
nftOrderBo.setNftPublishTaskId(publishTaskId);
}
}
if (StringUtil.isNotEmpty(publishTaskId)){
try{
//3.1.4查询 NFT发行结果
Nft035PublishResultReqDto nft035ReqDto = Nft035PublishResultReqDto.getNew();
nft035ReqDto.setTaskId(publishTaskId);
int count = 0;
String nftIdBegin = null;
long timeStart = System.currentTimeMillis();
while (StringUtil.isEmpty(nftIdBegin)) {
Thread.sleep(500l);
count++;
ZxlnftResponseDto<Nft035PublishResultRespDto> nft035RespDtoTemp = zxlnftSdkUtil.nft035PublishResult(nft035ReqDto);
log.info("=======执行第{}次查询,taskId:{}", count, nft035ReqDto.getTaskId());
if (nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())) {
nftIdBegin = nft035RespDtoTemp.getData().getNftIdBegin();
nftPublishChainTimestamp = nft035RespDtoTemp.getData().getChainTimestamp();
nftPublishStatus = nft035RespDtoTemp.getData().getTaskStatus();
nftPublishTradeHash = nft035RespDtoTemp.getData().getTxHash();
} else if (nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())) {
log.info("任务执行失败!taskId:{}", nft035ReqDto.getTaskId());
nftPublishStatus = nft035RespDtoTemp.getData().getTaskStatus();
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), "nft035PublishResult_resp:"+GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}else if(nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.PROCESSING.getCode())){
log.info("任务执行中!taskId:{}", nft035ReqDto.getTaskId());
nftPublishStatus = nft035RespDtoTemp.getData().getTaskStatus();
}
if (count == 20) {
log.info("=======查询共20次,跳出循环!taskId:{}", nft035ReqDto.getTaskId());
break;
}
}
//赋值返回参数
nftId = nftIdBegin;
nftOrderBo.setNftId(nftId);
log.info("发行NFT后返回给前端nftID:{}", nftIdBegin);
log.info("总共执行了{}次查询 总耗时:{} MS", count, (System.currentTimeMillis() - timeStart));
}catch (GalaxyNftPublishException e){
throw new GalaxyNftPublishException(e.getCode(),e.getMessage());
}catch(Exception e){
log.error(e.getMessage(),e);
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"nft035PublishResult_exception:"+e.getMessage());
}
}else{
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"nft034Publish_resp:taskId : "+publishTaskId);
}
}catch (GalaxyNftPublishException e) {
failDesc = e.getMessage();
}catch(Exception e){
failDesc = e.getMessage();
log.error(e.getMessage(),e);
}
if(StringUtil.isNotEmpty(failDesc)){
//记录发行异常信息
try{
//发行异常或者失败记录任务id
if(StringUtil.isNotNull(nftOrderBo)&&StringUtil.isNotEmpty(nftOrderBo.getNftPublishTaskId())){
nftOrderBo.setNftPublishStatus(GalaxyEnum.TaskStatusEnum.PROCESSING.getCode());
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//更新nft发行状态为处理中
dataUtils.updateNftOrderPublishInfo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}else{
//记录错误信息
GalaxyNftOrderFailLogVo nftOrderFailLogVo = galaxyBeanTransferBiz.buildNftOrderFailLogVo(GalaxyEnum.TradeTypeEnum.TRADE_PUBLISH,reqDto,GalaxyEnum.OrderDealWithStatusEnum.DATA_INIT,failDesc,null
,userInfoBo,seriesNftInfoBo,nftOrderBo);
dataUtils.setNftOrderFailLogVo(reqDto.getRouterType(),nftOrderFailLogVo);
}
}catch(Exception e){
log.error(reqDto.getNftOrderPayId()+"发行setNftOrderFailLogVo记录异常:"+e.getMessage(),e);
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
//更新订单缓存数据状态
if(StringUtil.isNotEmpty(nftOrderBo.getNftId())){
if(StringUtil.isNotNull(nftPublishChainTimestamp)){
//设置时间
String nftPublishChainTimestampStr = DateUtil.format(new Date(nftPublishChainTimestamp*1000),DateUtil.Formatter.yyyyMMddHHmmss);
nftOrderBo.setNftPublishChainTimestamp(nftPublishChainTimestampStr);
}
if(StringUtil.isNotNull(nftPublishStatus)){
//转换任务状态
String nftPublishStatusStr = GalaxyEnumBiz.getTaskStatusEnum(reqDto.getRouterType(),nftPublishStatus.toString()).getCode();
nftOrderBo.setNftPublishStatus(nftPublishStatusStr);
}
nftOrderBo.setNftPublishTradeHash(nftPublishTradeHash);
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//先更新nft发行数据
dataUtils.updateNftOrderPublishInfo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}
//第二步:执行购买逻辑
if(StringUtil.isNotEmpty(nftOrderBo.getNftId())){
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = this.executeBuyBusiness(reqDto,userInfoBo,seriesNftInfoBo,nftOrderBo);
if(StringUtil.isNotNull(nftPublishAndBuyRespDto)&&StringUtil.isNotEmpty(nftPublishAndBuyRespDto.getNftId())){
return ResponseDto.success(nftPublishAndBuyRespDto);
}else{
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL.getCode(),GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
}
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
private GalaxyNftPublishAndBuyRespDto executeBuyBusiness(GalaxyNftPublishAndBuyReqDto reqDto,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo,GalaxyNftOrderBo nftOrderBo){
public GalaxyNftPublishAndBuyRespDto executeBuyBusiness(GalaxyNftPublishAndBuyReqDto reqDto,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo,GalaxyNftOrderBo nftOrderBo){
String buyFailDesc = null;
//执行购买逻辑
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
......@@ -337,6 +88,7 @@ public class XuperTradeCommonBiz {
}
return nftPublishAndBuyRespDto;
}
/**
* 保持线程循环查询
* @param nftId
......@@ -358,40 +110,30 @@ public class XuperTradeCommonBiz {
}
if(StringUtil.isEmpty(nftBuyTaskId)){
// 3.2.2调用购买NFT接口
Nft043BuyReqDto nft043BuyReqDto = Nft043BuyReqDto.getNew();
nft043BuyReqDto.setNftId(nftId);
nft043BuyReqDto.setApplyScore(seriesNftInfoBo.getSellCount().intValue());
try {
nft043BuyReqDto.setReceiverPubKey(BASE64Util.decode(userInfoBo.getUserPubKey()));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
nft043BuyReqDto.setPointReceiverAddr(zxlnftConfig.getNftPlatformAddress());
nft043BuyReqDto.setOfferCount(seriesNftInfoBo.getSellCount().longValue());
nft043BuyReqDto.setOperateId(IDGenerator.get32UUID());
//购买
Xuper007GrantShardReqDto xuper007GrantShardReqDto = Xuper007GrantShardReqDto.getNew();
// 定义返回结果对象
Xuper007GrantShardRespDto xuper007GrantShardRespDto = null;
long assetId = 171095615845019437l;
// long assetId = 1532351545249738541l;
/**
* 接收人的私钥签名,签名对象是(platformPubKey_receiverPubKey_pointReceiverAddr_applyScore_接口名_nftId_offerCount_operateId)
* 接口名:buy_nft
*/
String signMetaData = zxlnftConfig.getNftPlatformPubKey()
.concat("_").concat(nft043BuyReqDto.getReceiverPubKey())
.concat("_").concat(nft043BuyReqDto.getPointReceiverAddr())
.concat("_").concat(nft043BuyReqDto.getApplyScore().toString())
.concat("_").concat("buy_nft")
.concat("_").concat(nft043BuyReqDto.getNftId())
.concat("_").concat(nft043BuyReqDto.getOfferCount().toString())
.concat("_").concat(nft043BuyReqDto.getOperateId());
String signature = null;
try {
signature = zxlnftBiz.createSign(BASE64Util.decode(userInfoBo.getUserPriKey()),signMetaData);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
xuper007GrantShardReqDto.setMnemonic(creatorMnemonic);
xuper007GrantShardReqDto.setAssetId(assetId);
xuper007GrantShardReqDto.setShardId(1l);
xuper007GrantShardReqDto.setToAddr(xuperSdkUtil.getAccount(customerMnemonic).getAddress());
xuper007GrantShardReqDto.setToUserId(100000l);
xuper007GrantShardReqDto.setPrice(1234l);
XuperResponseDto<Xuper007GrantShardRespDto> xuperResponseDto = xuperSdkUtil.xuper007GrantShard(reqDto);
if(xuperResponseDto.isSuccess()){
xuper007GrantShardRespDto = xuperResponseDto.getParseData(Xuper007GrantShardRespDto.class);
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
nft043BuyReqDto.setSignature(signature);
ZxlnftResponseDto<Nft043BuyRespDto> nft043RespDto = zxlnftSdkUtil.nft043Buy(nft043BuyReqDto);
log.info("testXuper007GrantShard resp : "+ JsonUtils.toJson(respDto));
if(nft043RespDto.isSuccess()){
nftBuyTaskId = nft043RespDto.getData().getTaskId();
nftOrderBo.setNftBuyTaskId(nftBuyTaskId);
......
package com.liquidnet.service.galaxy.router.xuper.biz;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.common.third.xuper.config.XuperConfig;
import com.liquidnet.common.third.xuper.dto.*;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.xuper.util.XuperSdkUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.biz.GalaxyBeanTransferBiz;
......@@ -25,9 +26,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
......@@ -42,7 +41,10 @@ import java.util.Date;
@Component
public class XuperPublishBiz {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
private XuperSdkUtil xuperSdkUtil;
@Autowired
private XuperConfig xuperConfig;
@Autowired
private GalaxyDataUtils dataUtils;
......@@ -110,43 +112,32 @@ public class XuperPublishBiz {
String nftId = null;
String taskId = null;
//查询系列信息 暂时不通过系列信息控制发行索引
// Nft032SeriesReqDto nft032ReqDto = Nft032SeriesReqDto.getNew();
// nft032ReqDto.setSeriesId(seriesId);
// ZxlnftResponseDto<Nft032SeriesRespDto> resp = zxlnftSdkUtil.nft032Series(nft032ReqDto);
//
// if(resp.isSuccess()){
// //该系列已经发行多少个nft
// Long crtCount = resp.getData().getSeriesInfo().getCrtCount();
// log.info("系列:{} 已发行 :{}", seriesId, crtCount);
// //设置开始索引
// seriesBeginIndex = Integer.parseInt(String.valueOf(crtCount.longValue() + 1));
// }
//3.1.2调用NFT发行接口
/**
* 发行无限制系列
*/
Nft034PublishReqDto nft034ReqDto = Nft034PublishReqDto.getNew();
nft034ReqDto.setAuthor(author);
nft034ReqDto.setName(nftName);
nft034ReqDto.setUrl(nftUrl);
nft034ReqDto.setDisplayUrl(displayUrl);
nft034ReqDto.setDesc(nftDesc);
nft034ReqDto.setFlag(nftFlag);
nft034ReqDto.setPublishCount(publishCount);
//无限制零系列
nft034ReqDto.setSeriesId(seriesId);
nft034ReqDto.setSeriesBeginIndex(seriesBeginIndex);
nft034ReqDto.setSellStatus(Integer.parseInt(ZxlnftEnum.SellStatusEnum.CAN_SELL.getCode()));
nft034ReqDto.setSellCount(sellCount);
nft034ReqDto.setOperateId(IDGenerator.get32UUID());
nft034ReqDto.setMetaData("");
//发行
Xuper004PublishAssetReqDto xuper004PublishAssetReqDto = Xuper004PublishAssetReqDto.getNew();
// 定义返回结果对象
Xuper004PublishAssetRespDto xuper004PublishAssetRespDto = null;
long assetId = Long.parseLong(seriesNftInfoBo.getSeriesId());
try {
xuper004PublishAssetReqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
xuper004PublishAssetReqDto.setAssetId(assetId);
XuperResponseDto<Xuper004PublishAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper004PublishAsset(xuper004PublishAssetReqDto);
if(xuperResponseDto.isSuccess()){
xuper004PublishAssetRespDto = xuperResponseDto.getParseData(Xuper004PublishAssetRespDto.class);
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("xuper004PublishAsset resp : "+ JsonUtils.toJson(xuper004PublishAssetRespDto));
ZxlnftResponseDto<Nft034PublishRespDto> nft034RespDto = zxlnftSdkUtil.nft034Publish(nft034ReqDto);
if (Integer.parseInt(ErrorCode.SUCCESS.getCode()) == xuper004PublishAssetRespDto.errNo){
//赋值返回参数
taskId = String.valueOf(assetId);
nftId = seriesId.concat("_").concat(seriesBeginIndex.toString());
if (nft034RespDto.isSuccess()) {
taskId = nft034RespDto.getData().getTaskId();
nftOrderBo.setNftId(nftId);
nftOrderBo.setNftPublishTaskId(taskId);
}
GalaxyNftPublishRespDto nftPublishRespDto = GalaxyNftPublishRespDto.getNew();
......@@ -176,28 +167,44 @@ public class XuperPublishBiz {
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_ORDER_NOT_EXIST.getCode(), GalaxyErrorEnum.PUBLISH_ORDER_NOT_EXIST.getMessage());
}
//3.1.4查询 NFT发行结果
Nft035PublishResultReqDto nft035ReqDto = Nft035PublishResultReqDto.getNew();
nft035ReqDto.setTaskId(nftOrderBo.getNftPublishTaskId());
//NFT发行结果查询
Xuper005QueryAssetReqDto xuper005QueryAssetReqDto = Xuper005QueryAssetReqDto.getNew();
xuper005QueryAssetReqDto.setAssetId(Long.parseLong(nftOrderBo.getSeriesId()));
// 定义返回结果对象
Xuper005QueryAssetRespDto xuper005QueryAssetRespDto = null;
try {
XuperResponseDto<Xuper005QueryAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper005QueryAsset(xuper005QueryAssetReqDto);
if(xuperResponseDto.isSuccess()){
xuper005QueryAssetRespDto = xuperResponseDto.getParseData(Xuper005QueryAssetRespDto.class);
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("xuper005QueryAsset resp : "+ JsonUtils.toJson(xuper005QueryAssetRespDto));
ZxlnftResponseDto<Nft035PublishResultRespDto> nft035RespDtoTemp = zxlnftSdkUtil.nft035PublishResult(nft035ReqDto);
if(nft035RespDtoTemp.isSuccess()){
if (Integer.parseInt(ErrorCode.SUCCESS.getCode()) == xuper005QueryAssetRespDto.getErrNo()){
//获取资产信息
Xuper005QueryAssetRespDto.AssetMeta assetMeta = xuper005QueryAssetRespDto.getMeta();
//设置时间
String nftPublishChainTimestampStr = DateUtil.format(new Date(nft035RespDtoTemp.getData().getChainTimestamp().longValue()*1000),DateUtil.Formatter.yyyyMMddHHmmss);
String nftPublishChainTimestampStr = DateUtil.getNowTime();
//转换任务状态
String nftPublishStatusStr = GalaxyEnumBiz.getTaskStatusEnum(reqDto.getRouterType(),nft035RespDtoTemp.getData().getTaskStatus().toString()).getCode();
String nftPublishStatusStr = GalaxyEnumBiz.getTaskStatusEnum(reqDto.getRouterType(),String.valueOf(assetMeta.getStatus())).getCode();
//更新缓存数据状态
nftOrderBo.setNftId(nft035RespDtoTemp.getData().getNftIdBegin());
nftOrderBo.setNftId(nftOrderBo.getNftId());
nftOrderBo.setNftPublishChainTimestamp(nftPublishChainTimestampStr);
nftOrderBo.setNftPublishStatus(nftPublishStatusStr);
nftOrderBo.setNftPublishTradeHash(nft035RespDtoTemp.getData().getTxHash());
nftOrderBo.setNftPublishTradeHash(nftOrderBo.getSeriesId());
nftOrderBo.setUpdatedAt(LocalDateTime.now());
dataUtils.updateNftOrderPublishInfo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
//构造返回结果
GalaxyNftPublishResultQueryRespDto nftPublishResultQueryRespDto = GalaxyNftPublishResultQueryRespDto.getNew();
BeanUtil.copy(nft035RespDtoTemp.getData(),nftPublishResultQueryRespDto);
nftPublishResultQueryRespDto.setNftIdBegin(nftOrderBo.getNftId());
nftPublishResultQueryRespDto.setTaskMsg(nftOrderBo.getNftId());
nftPublishResultQueryRespDto.setTxHash(nftOrderBo.getNftId());
nftPublishResultQueryRespDto.setChainTimestamp(nftPublishChainTimestampStr);
nftPublishResultQueryRespDto.setTaskStatus(Integer.valueOf(nftPublishStatusStr));
......@@ -206,143 +213,4 @@ public class XuperPublishBiz {
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
}
/**
* 以下为nft发行同步返回方法(暂时废弃)
* @param reqDto
* @return
*/
public ResponseDto<GalaxyNftPublishRespDto> nftPublishSync(GalaxyNftPublishReqDto reqDto) {
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNotNull(nftOrderBo)&& StringUtil.isNotEmpty(nftOrderBo.getNftId())){
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL_ALREADY_EXIST.getCode(), GalaxyErrorEnum.PUBLISH_FAIL_ALREADY_EXIST.getMessage());
}
//获取用户信息
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId());
//获取sku信息
GalaxySeriesNftInfoBo seriesNftInfoBo = dataUtils.getSeriesNftInfoBo(reqDto.getRouterType(),reqDto.getSkuId());
String author = seriesNftInfoBo.getAuthor();
String nftName = seriesNftInfoBo.getNftName();
String nftUrl = seriesNftInfoBo.getNftUrl();
String displayUrl = seriesNftInfoBo.getDisplayUrl();
String nftDesc = seriesNftInfoBo.getNftDesc();
String nftFlag = seriesNftInfoBo.getNftFlag();
//发行个数
Long publishCount = 1L;
//开始索引
Integer seriesBeginIndex = 0;
Long sellCount = Long.valueOf(seriesNftInfoBo.getSellCount().multiply(BigDecimal.valueOf(100l)).longValue()); //积分
/**
* 根据sku获取系列Id
*/
String seriesId = seriesNftInfoBo.getSeriesId();
//返回参数nftId
String nftId = null;
String taskId = null;
Long nftPublishChainTimestamp = null;
Integer nftPublishStatus = null;
String nftPublishTradeHash = null;
//查询系列信息
Nft032SeriesReqDto nft032ReqDto = Nft032SeriesReqDto.getNew();
nft032ReqDto.setSeriesId(seriesId);
ZxlnftResponseDto<Nft032SeriesRespDto> resp = zxlnftSdkUtil.nft032Series(nft032ReqDto);
if(resp.isSuccess()){
//该系列已经发行多少个nft
Long crtCount = resp.getData().getSeriesInfo().getCrtCount();
log.info("系列:{} 已发行 :{}", seriesId, crtCount);
//设置开始索引
seriesBeginIndex = Integer.parseInt(String.valueOf(crtCount.longValue() + 1));
}
//3.1.2调用NFT发行接口
/**
* 发行无限制系列
*/
Nft034PublishReqDto nft034ReqDto = Nft034PublishReqDto.getNew();
nft034ReqDto.setAuthor(author);
nft034ReqDto.setName(nftName);
nft034ReqDto.setUrl(nftUrl);
nft034ReqDto.setDisplayUrl(displayUrl);
nft034ReqDto.setDesc(nftDesc);
nft034ReqDto.setFlag(nftFlag);
nft034ReqDto.setPublishCount(publishCount);
//无限制零系列
nft034ReqDto.setSeriesId(seriesId);
nft034ReqDto.setSeriesBeginIndex(seriesBeginIndex);
nft034ReqDto.setSellStatus(Integer.parseInt(ZxlnftEnum.SellStatusEnum.CAN_SELL.getCode()));
nft034ReqDto.setSellCount(sellCount);
nft034ReqDto.setOperateId(IDGenerator.get32UUID());
nft034ReqDto.setMetaData("");
ZxlnftResponseDto<Nft034PublishRespDto> nft034RespDto = zxlnftSdkUtil.nft034Publish(nft034ReqDto);
if (nft034RespDto.isSuccess()) {
//3.1.4查询 NFT发行结果
Nft035PublishResultReqDto nft035ReqDto = Nft035PublishResultReqDto.getNew();
taskId = nft034RespDto.getData().getTaskId();
nft035ReqDto.setTaskId(taskId);
int count = 0;
String nftIdBegin = null;
long timeStart = System.currentTimeMillis();
while (StringUtil.isEmpty(nftIdBegin)) {
count++;
ZxlnftResponseDto<Nft035PublishResultRespDto> nft035RespDtoTemp = zxlnftSdkUtil.nft035PublishResult(nft035ReqDto);
log.info("=======执行第{}次查询,taskId:{}", count, nft035ReqDto.getTaskId());
if (nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())) {
nftIdBegin = nft035RespDtoTemp.getData().getNftIdBegin();
nftPublishChainTimestamp = nft035RespDtoTemp.getData().getChainTimestamp();
nftPublishStatus = nft035RespDtoTemp.getData().getTaskStatus();
nftPublishTradeHash = nft035RespDtoTemp.getData().getTxHash();
} else if (nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())) {
log.info("任务执行失败!taskId:{}", nft035ReqDto.getTaskId());
return null;
}
if (count == 5) {
log.info("=======查询共5次,跳出循环!taskId:{}", nft035ReqDto.getTaskId());
break;
}
}
//赋值返回参数
nftId = nftIdBegin;
log.info("发行NFT后返回给前端nftID:{}", nftIdBegin);
log.info("总共执行了{}次查询 总耗时:{} MS", count, (System.currentTimeMillis() - timeStart));
}
if(StringUtil.isEmpty(nftId)){
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
GalaxyNftPublishRespDto nftPublishRespDto = GalaxyNftPublishRespDto.getNew();
nftPublishRespDto.setUserId(reqDto.getUserId());
nftPublishRespDto.setNftId(nftId);
//构造缓存数据
if(nftOrderBo==null){
nftOrderBo = galaxyBeanTransferBiz.buildNftOrderBo(reqDto.getNftOrderPayId(),userInfoBo,seriesNftInfoBo);
nftOrderBo.setNftId(nftId);
nftOrderBo.setNftPublishTaskId(taskId);
//设置时间
String nftPublishChainTimestampStr = DateUtil.format(new Date(nftPublishChainTimestamp*1000),DateUtil.Formatter.yyyyMMddHHmmss);
//转换任务状态
String nftPublishStatusStr = GalaxyEnumBiz.getTaskStatusEnum(reqDto.getRouterType(),nftPublishStatus.toString()).getCode();
nftOrderBo.setNftPublishChainTimestamp(nftPublishChainTimestampStr);
nftOrderBo.setNftPublishStatus(nftPublishStatusStr);
nftOrderBo.setNftPublishTradeHash(nftPublishTradeHash);
nftOrderBo.setUpdatedAt(LocalDateTime.now());
dataUtils.setNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}
return ResponseDto.success(nftPublishRespDto);
}
}
package com.liquidnet.service.galaxy.router.xuper.biz;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig;
import com.liquidnet.common.third.zxlnft.dto.Nft044BuyResultReqDto;
import com.liquidnet.common.third.zxlnft.dto.Nft044BuyResultRespDto;
import com.liquidnet.common.third.zxlnft.dto.ZxlnftResponseDto;
import com.liquidnet.common.third.zxlnft.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.common.third.xuper.config.XuperConfig;
import com.liquidnet.common.third.xuper.dto.*;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.xuper.util.XuperSdkUtil;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.dto.*;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.biz.GalaxyBeanTransferBiz;
import com.liquidnet.service.galaxy.biz.GalaxyEnumBiz;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
import com.liquidnet.service.galaxy.constant.GalaxyErrorEnum;
import com.liquidnet.service.galaxy.dto.bo.GalaxyNftOrderBindBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxyNftOrderBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
import com.liquidnet.service.galaxy.dto.param.*;
import com.liquidnet.service.galaxy.router.zxin.biz.ZxinPublishBiz;
import com.liquidnet.service.galaxy.dto.vo.mongo.GalaxyNftOrderFailLogVo;
import com.liquidnet.service.galaxy.exception.GalaxyNftPublishException;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import com.liquidnet.service.galaxy.utils.QueueUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Date;
/**
......@@ -38,13 +42,10 @@ import java.util.Date;
@Component
public class XuperTradeBiz {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
private XuperSdkUtil xuperSdkUtil;
@Autowired
private ZxlnftBiz zxlnftBiz;
@Autowired
private ZxlnftConfig zxlnftConfig;
private XuperConfig xuperConfig;
@Autowired
private GalaxyDataUtils dataUtils;
......@@ -52,9 +53,6 @@ public class XuperTradeBiz {
@Autowired
private GalaxyBeanTransferBiz galaxyBeanTransferBiz;
@Autowired
private ZxinPublishBiz zxinPublishBiz;
@Autowired
private XuperTradeCommonBiz xuperTradeCommonBiz;
......@@ -66,7 +64,213 @@ public class XuperTradeBiz {
* @return
*/
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
return xuperTradeCommonBiz.nftPublishAndBuy(reqDto);
log.info("开始执行nftPublishAndBuy 请求参数:{}",reqDto.toString());
//获取用户信息
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId());
if(StringUtil.isNull(userInfoBo)){
log.error("开始执行nftPublishAndBuy error msg:{}",GalaxyErrorEnum.NFT_BUY_FAIL_USER_NOT_EXIST.getMessage());
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL_USER_NOT_EXIST.getCode(), GalaxyErrorEnum.NFT_BUY_FAIL_USER_NOT_EXIST.getMessage());
}
//获取sku信息
GalaxySeriesNftInfoBo seriesNftInfoBo = dataUtils.getSeriesNftInfoBo(reqDto.getRouterType(),reqDto.getSkuId());
if(StringUtil.isNull(seriesNftInfoBo)||StringUtil.isEmpty(seriesNftInfoBo.getSeriesId())){
log.error("开始执行nftPublishAndBuy error msg:{}",GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getMessage());
return ResponseDto.failure(GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getCode(), GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getMessage());
}
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
//初始化订单数据
if(nftOrderBo==null){
nftOrderBo = galaxyBeanTransferBiz.buildNftOrderBo(reqDto.getNftOrderPayId(),userInfoBo,seriesNftInfoBo);
dataUtils.setNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}else if(StringUtil.isNotNull(nftOrderBo)){
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())
&&nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
nftPublishAndBuyRespDto.setUserId(reqDto.getUserId());
nftPublishAndBuyRespDto.setNftId(nftOrderBo.getNftId());
log.error("开始执行nftPublishAndBuy error msg:{}", GalaxyErrorEnum.PUBLISH_FAIL_ALREADY_EXIST.toString());
return ResponseDto.success(nftPublishAndBuyRespDto);
}
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())
&&(nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.INIT.getCode())
||nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.PROCESSING.getCode()))){
//再次发起购买
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = xuperTradeCommonBiz.executeBuyBusiness(reqDto,userInfoBo,seriesNftInfoBo,nftOrderBo);
if(StringUtil.isNotNull(nftPublishAndBuyRespDto)&&StringUtil.isNotEmpty(nftPublishAndBuyRespDto.getNftId())){
return ResponseDto.success(nftPublishAndBuyRespDto);
}else{
log.error("开始执行nftPublishAndBuy-->executeBuyBusiness error msg:{}",GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL.getCode(),GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
}
}
}
String author = seriesNftInfoBo.getAuthor();
String nftName = seriesNftInfoBo.getNftName();
String nftUrl = seriesNftInfoBo.getNftUrl();
String displayUrl = seriesNftInfoBo.getDisplayUrl();
String nftDesc = seriesNftInfoBo.getNftDesc();
String nftFlag = seriesNftInfoBo.getNftFlag();
//发行个数
Long publishCount = 1L;
//开始索引
Integer seriesBeginIndex = null;
//发行金额
Long sellCount = seriesNftInfoBo.getSellCount().longValue(); //积分
/**
* 根据sku获取系列Id
*/
String seriesId = seriesNftInfoBo.getSeriesId();
//返回参数nftId
String nftId = null;
String publishTaskId = null;
Long nftPublishChainTimestamp = null;
Integer nftPublishStatus = null;
String nftPublishTradeHash = null;
//定义失败信息
String failDesc = null;
try{
/**
* 获取订单和nft绑定信息
*/
GalaxyNftOrderBindBo nftOrderBindBo = dataUtils.getGalaxyNftOrderBindBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNull(nftOrderBindBo)){
//获取发行索引
long nftIdNo = dataUtils.incrNftIdNo(reqDto.getRouterType(),reqDto.getSkuId());
//如果发行数大于最大发行数量
if(nftIdNo > seriesNftInfoBo.getNftTotalCount()){
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"该sku:"+reqDto.getSkuId()+" 总共"+seriesNftInfoBo.getNftTotalCount()+"个NFT已经发行完毕,没有剩余库存!");
}
nftOrderBindBo = GalaxyNftOrderBindBo.getNew();
nftOrderBindBo.setNftOrderPayId(reqDto.getNftOrderPayId());
nftOrderBindBo.setSeriesId(seriesNftInfoBo.getSeriesId());
nftOrderBindBo.setSeriesCode(seriesNftInfoBo.getSeriesCode());
nftOrderBindBo.setNftIdIndex(Integer.valueOf(String.valueOf(nftIdNo)));
nftOrderBindBo.setRouterType(reqDto.getRouterType());
String nowTimeStr = DateUtil.Formatter.yyyyMMddHHmmss.format(LocalDateTime.now());
nftOrderBindBo.setCreatedAt(nowTimeStr);
dataUtils.setGalaxyNftOrderBindBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBindBo);
}
seriesBeginIndex = nftOrderBindBo.getNftIdIndex();
/**
* 如果已经发行成功
*/
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.PROCESSING.getCode())){
if(StringUtil.isNotEmpty(nftOrderBo.getNftPublishTaskId())){
publishTaskId = nftOrderBo.getNftPublishTaskId();
}
}else if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.INIT.getCode())){
//发行
Xuper004PublishAssetReqDto xuper004PublishAssetReqDto = Xuper004PublishAssetReqDto.getNew();
// 定义返回结果对象
Xuper004PublishAssetRespDto xuper004PublishAssetRespDto = null;
long assetId = Long.parseLong(seriesNftInfoBo.getSeriesId());
try {
xuper004PublishAssetReqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
xuper004PublishAssetReqDto.setAssetId(assetId);
XuperResponseDto<Xuper004PublishAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper004PublishAsset(xuper004PublishAssetReqDto);
if(xuperResponseDto.isSuccess()){
xuper004PublishAssetRespDto = xuperResponseDto.getParseData(Xuper004PublishAssetRespDto.class);
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("xuper004PublishAsset resp : "+ JsonUtils.toJson(xuper004PublishAssetRespDto));
if (Integer.parseInt(ErrorCode.SUCCESS.getCode()) == xuper004PublishAssetRespDto.errNo){
publishTaskId = String.valueOf(assetId);
nftOrderBo.setNftPublishTaskId(publishTaskId);
}
}
if (StringUtil.isNotEmpty(publishTaskId)){
try{
nftPublishChainTimestamp = DateUtil.getNowSeconds();
nftPublishStatus = Integer.parseInt(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode());
nftPublishTradeHash = publishTaskId;
//赋值返回参数
nftId = seriesId.concat("_").concat(seriesBeginIndex.toString());
nftOrderBo.setNftId(nftId);
log.info("发行NFT后返回给前端nftID:{}", nftId);
}catch (GalaxyNftPublishException e){
throw new GalaxyNftPublishException(e.getCode(),e.getMessage());
}catch(Exception e){
log.error(e.getMessage(),e);
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"nft035PublishResult_exception:"+e.getMessage());
}
}else{
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"nft034Publish_resp:taskId : "+publishTaskId);
}
}catch (GalaxyNftPublishException e) {
failDesc = e.getMessage();
}catch(Exception e){
failDesc = e.getMessage();
log.error(e.getMessage(),e);
}
if(StringUtil.isNotEmpty(failDesc)){
//记录发行异常信息
try{
//发行异常或者失败记录任务id
if(StringUtil.isNotNull(nftOrderBo)&&StringUtil.isNotEmpty(nftOrderBo.getNftPublishTaskId())){
nftOrderBo.setNftPublishStatus(GalaxyEnum.TaskStatusEnum.PROCESSING.getCode());
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//更新nft发行状态为处理中
dataUtils.updateNftOrderPublishInfo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}else{
//记录错误信息
GalaxyNftOrderFailLogVo nftOrderFailLogVo = galaxyBeanTransferBiz.buildNftOrderFailLogVo(GalaxyEnum.TradeTypeEnum.TRADE_PUBLISH,reqDto,GalaxyEnum.OrderDealWithStatusEnum.DATA_INIT,failDesc,null
,userInfoBo,seriesNftInfoBo,nftOrderBo);
dataUtils.setNftOrderFailLogVo(reqDto.getRouterType(),nftOrderFailLogVo);
}
}catch(Exception e){
log.error(reqDto.getNftOrderPayId()+"发行setNftOrderFailLogVo记录异常:"+e.getMessage(),e);
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
//更新订单缓存数据状态
if(StringUtil.isNotEmpty(nftOrderBo.getNftId())){
if(StringUtil.isNotNull(nftPublishChainTimestamp)){
//设置时间
String nftPublishChainTimestampStr = DateUtil.format(new Date(nftPublishChainTimestamp*1000),DateUtil.Formatter.yyyyMMddHHmmss);
nftOrderBo.setNftPublishChainTimestamp(nftPublishChainTimestampStr);
}
if(StringUtil.isNotNull(nftPublishStatus)){
//转换任务状态
String nftPublishStatusStr = GalaxyEnumBiz.getTaskStatusEnum(reqDto.getRouterType(),nftPublishStatus.toString()).getCode();
nftOrderBo.setNftPublishStatus(nftPublishStatusStr);
}
nftOrderBo.setNftPublishTradeHash(nftPublishTradeHash);
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//先更新nft发行数据
dataUtils.updateNftOrderPublishInfo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}
//第二步:执行购买逻辑
if(StringUtil.isNotEmpty(nftOrderBo.getNftId())){
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = xuperTradeCommonBiz.executeBuyBusiness(reqDto,userInfoBo,seriesNftInfoBo,nftOrderBo);
if(StringUtil.isNotNull(nftPublishAndBuyRespDto)&&StringUtil.isNotEmpty(nftPublishAndBuyRespDto.getNftId())){
return ResponseDto.success(nftPublishAndBuyRespDto);
}else{
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL.getCode(),GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
}
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
......
......@@ -36,7 +36,7 @@ public class GalaxyRouterStrategyXuperTradeImpl implements IGalaxyRouterStrategy
@Override
public ResponseDto<GalaxyNftBuyResultQueryRespDto> nftBuyResultQuery(GalaxyNftBuyResultQueryReqDto reqDto) {
return xuperTradeBiz.nftBuyResultQuery(reqDto);
return null;
}
@Override
......@@ -56,6 +56,6 @@ public class GalaxyRouterStrategyXuperTradeImpl implements IGalaxyRouterStrategy
@Override
public ResponseDto<GalaxyNftBuyRespDto> nftBuy(GalaxyNftBuyReqDto reqDto) {
return xuperTradeBiz.nftBuy(reqDto);
return null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment