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

Commit 05685b45 authored by anjiabin's avatar anjiabin

nft修改购买逻辑

parent 6c2c48ae
......@@ -257,6 +257,42 @@ public class GalaxyEnum {
}
}
/**
* 订单处理状态
*/
public enum OrderDealWithStatusEnum{
DATA_INIT("0","数据初始化"),
SUCCESS("1","已处理成功"),
FAIL("2","处理失败"),
NOT_DEAL_WITH("3","不做处理");
private String code;
private String message;
OrderDealWithStatusEnum(String code, String message) {
this.code = code;
this.message = message;
}
public OrderDealWithStatusEnum getEnumByCode(String code){
OrderDealWithStatusEnum[] arry = OrderDealWithStatusEnum.values();
for (int i = 0; i < arry.length; i++) {
if (arry[i].getCode().equals(code)) {
return arry[i];
}
}
return null;
}
public String getCode() {
return code;
}
public String getMessage(){
return message;
}
}
public static void main(String[] args) {
Integer aaa = 1;
......
......@@ -24,7 +24,12 @@ public enum GalaxyErrorEnum {
PUBLISH_ORDER_NOT_EXIST("NFT0010011","NFT购买订单不存在!"),
NFT_BUY_TASK_NOT_EXIST("NFT0010012","NFT购买执行任务不存在"),
NFT_BUY_TASK_HAVE_EXIST("NFT0010013","NFT购买执行任务已存在,不可以重复购买!"),
NFT_BUY_FAIL("NFT0010014","NFT购买失败,nftId不存在!");
NFT_BUY_FAIL("NFT0010014","NFT购买失败,nftId不存在!"),
NFT_BUY_FAIL_USER_NOT_EXIST("NFT0010015","NFT购买失败,用户信息不存在!"),
NFT_BUY_FAIL_SERIES_NFT_NOT_EXIST("NFT0010016","NFT购买失败,系列NFT信息不存在!"),
NFT_PUBLISH_ERROR("NFT0010017","NFT发行异常!"),
NFT_BUY_ERROR("NFT0010018","NFT购买异常!");
private String code;
private String message;
......
package com.liquidnet.service.galaxy.exception;
import lombok.Data;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: 自定义异常类
* @class: ZxlNftException
* @Package com.liquidnet.common.third.zxlnft.exception
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/2/21 13:44
*/
@Data
public class GalaxyNftBuyException extends RuntimeException{
private static final long serialVersionUID = -3916918823313768482L;
private String code;
private String message;
public GalaxyNftBuyException(String code, String message) {
super(message);
this.code = code;
this.message = message;
}
public GalaxyNftBuyException(String code, String message, Throwable t) {
super(message, t);
this.code = code;
this.message = message;
}
}
......@@ -15,18 +15,18 @@ import lombok.Data;
public class GalaxyNftException extends RuntimeException{
private static final long serialVersionUID = -3916918823313768482L;
private String code;
private String msg;
private String message;
public GalaxyNftException(String code, String msg) {
super(msg);
public GalaxyNftException(String code, String message) {
super(message);
this.code = code;
this.msg = msg;
this.message = message;
}
public GalaxyNftException(String code, String msg, Throwable t) {
super(msg, t);
public GalaxyNftException(String code, String message, Throwable t) {
super(message, t);
this.code = code;
this.msg = msg;
this.message = message;
}
}
package com.liquidnet.service.galaxy.exception;
import lombok.Data;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: 自定义异常类
* @class: ZxlNftException
* @Package com.liquidnet.common.third.zxlnft.exception
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/2/21 13:44
*/
@Data
public class GalaxyNftPublishException extends RuntimeException{
private static final long serialVersionUID = -3916918823313768482L;
private String code;
private String message;
public GalaxyNftPublishException(String code, String message) {
super(message);
this.code = code;
this.message = message;
}
public GalaxyNftPublishException(String code, String message, Throwable t) {
super(message, t);
this.code = code;
this.message = message;
}
}
......@@ -34,13 +34,14 @@ public class ZxlnftSdkUtil {
private ZxlnftBiz zxlnftBiz;
public ZxlnftResponseDto<Nft001RegisterVerifyCodeRespDto> nft001RegisterVerifyCode(Nft001RegisterVerifyCodeReqDto reqDto){
Nft001RegisterVerifyCodeRespDto respDto = Nft001RegisterVerifyCodeRespDto.getNew();
/**
* 构造请求
*/
Nft001RegisterVerifyCodeReq req = Nft001RegisterVerifyCodeReq.getNew();
BeanUtil.copy(reqDto,req);
Nft001RegisterVerifyCodeRespDto respDto = Nft001RegisterVerifyCodeRespDto.getNew();
try{
Nft001RegisterVerifyCodeResp resp = zxlnftSdkService.nft001RegisterVerifyCode(req);
BeanUtil.copy(resp,respDto);
......@@ -68,23 +69,23 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft003RegisterPersonPlatformRespDto> nft003RegisterPersonPlatform(Nft003RegisterPersonPlatformReqDto reqDto){
/**
* 构造请求
*/
Nft003RegisterPersonPlatformReq req = Nft003RegisterPersonPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(personName_mobile_idCard)
*/
String signMetaData = req.getPersonName()
.concat("_").concat(req.getMobile())
.concat("_").concat(req.getIdCard());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft003RegisterPersonPlatformRespDto respDto = Nft003RegisterPersonPlatformRespDto.getNew();
try{
/**
* 构造请求
*/
Nft003RegisterPersonPlatformReq req = Nft003RegisterPersonPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(personName_mobile_idCard)
*/
String signMetaData = req.getPersonName()
.concat("_").concat(req.getMobile())
.concat("_").concat(req.getIdCard());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft003RegisterPersonPlatformResp resp = zxlnftSdkService.nft003RegisterPersonPlatform(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -111,23 +112,23 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft005BusinessLicenseUploadPlatformRespDto> nft005BusinessLicenseUploadPlatform(Nft005BusinessLicenseUploadPlatformReqDto reqDto){
/**
* 构造请求
*/
Nft005BusinessLicenseUploadPlatformReq req = Nft005BusinessLicenseUploadPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformIdentification(zxlnftConfig.getPlatformIdentification());
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(platformIdentification)
*/
String signMetaData = req.getPlatformIdentification();
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft005BusinessLicenseUploadPlatformRespDto respDto = Nft005BusinessLicenseUploadPlatformRespDto.getNew();
try{
/**
* 构造请求
*/
Nft005BusinessLicenseUploadPlatformReq req = Nft005BusinessLicenseUploadPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformIdentification(zxlnftConfig.getPlatformIdentification());
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(platformIdentification)
*/
String signMetaData = req.getPlatformIdentification();
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft005BusinessLicenseUploadPlatformResp resp = zxlnftSdkService.nft005BusinessLicenseUploadPlatform(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -154,23 +155,23 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft007OfficialLetterUploadPlatformRespDto> nft007OfficialLetterUploadPlatform(Nft007OfficialLetterUploadPlatformReqDto reqDto){
/**
* 构造请求
*/
Nft007OfficialLetterUploadPlatformReq req = Nft007OfficialLetterUploadPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformIdentification(zxlnftConfig.getPlatformIdentification());
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(platformIdentification)
*/
String signMetaData = req.getPlatformIdentification();
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft007OfficialLetterUploadPlatformRespDto respDto = Nft007OfficialLetterUploadPlatformRespDto.getNew();
try{
/**
* 构造请求
*/
Nft007OfficialLetterUploadPlatformReq req = Nft007OfficialLetterUploadPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformIdentification(zxlnftConfig.getPlatformIdentification());
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(platformIdentification)
*/
String signMetaData = req.getPlatformIdentification();
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft007OfficialLetterUploadPlatformResp resp = zxlnftSdkService.nft007OfficialLetterUploadPlatform(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -214,27 +215,27 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft010RegisterCompanyPlatformRespDto> nft010RegisterCompanyPlatform(Nft010RegisterCompanyPlatformReqDto reqDto){
/**
* 构造请求
*/
Nft010RegisterCompanyPlatformReq req = Nft010RegisterCompanyPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(epName_creditCode_representativeName_contact_mobile_idcard)
*/
String signMetaData = req.getEpName()
.concat("_").concat(req.getCreditCode())
.concat("_").concat(req.getRepresentativeName())
.concat("_").concat(req.getContact())
.concat("_").concat(req.getMobile())
.concat("_").concat(req.getIdcard());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft010RegisterCompanyPlatformRespDto respDto = Nft010RegisterCompanyPlatformRespDto.getNew();
try{
/**
* 构造请求
*/
Nft010RegisterCompanyPlatformReq req = Nft010RegisterCompanyPlatformReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(epName_creditCode_representativeName_contact_mobile_idcard)
*/
String signMetaData = req.getEpName()
.concat("_").concat(req.getCreditCode())
.concat("_").concat(req.getRepresentativeName())
.concat("_").concat(req.getContact())
.concat("_").concat(req.getMobile())
.concat("_").concat(req.getIdcard());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft010RegisterCompanyPlatformResp resp = zxlnftSdkService.nft010RegisterCompanyPlatform(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -295,22 +296,22 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft014IdentityBindSubmitByTrustedRespDto> nft014IdentityBindSubmitByTrusted(Nft014IdentityBindSubmitByTrustedReqDto reqDto){
/**
* 构造请求
*/
Nft014IdentityBindSubmitByTrustedReq req = Nft014IdentityBindSubmitByTrustedReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(epName_creditCode_representativeName_contact_mobile_idcard)
*/
String signMetaData = req.getUserSignData();
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft014IdentityBindSubmitByTrustedRespDto respDto = Nft014IdentityBindSubmitByTrustedRespDto.getNew();
try{
/**
* 构造请求
*/
Nft014IdentityBindSubmitByTrustedReq req = Nft014IdentityBindSubmitByTrustedReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台签名信息:sign(epName_creditCode_representativeName_contact_mobile_idcard)
*/
String signMetaData = req.getUserSignData();
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft014IdentityBindSubmitByTrustedResp resp = zxlnftSdkService.nft014IdentityBindSubmitByTrusted(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -439,23 +440,24 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft022UploadSecretRespDto> nft022UploadSecret(Nft022UploadSecretReqDto reqDto){
/**
* 构造请求
*/
Nft022UploadSecretReq req = Nft022UploadSecretReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPubKey(zxlnftConfig.getNftPlatformPubKey());
//系列为空
String pubData = req.getTimestamp() + "_" + req.getUserPubKey();
//系列不为空
if(StringUtil.isNotEmpty(req.getSeriesName())){
pubData = req.getTimestamp() + "_" + req.getSeriesName() + "_" + req.getUserPubKey();
}
req.setPubSignedData(zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),pubData));
Nft022UploadSecretRespDto respDto = Nft022UploadSecretRespDto.getNew();
try{
/**
* 构造请求
*/
Nft022UploadSecretReq req = Nft022UploadSecretReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPubKey(zxlnftConfig.getNftPlatformPubKey());
//系列为空
String pubData = req.getTimestamp() + "_" + req.getUserPubKey();
//系列不为空
if(StringUtil.isNotEmpty(req.getSeriesName())){
pubData = req.getTimestamp() + "_" + req.getSeriesName() + "_" + req.getUserPubKey();
}
req.setPubSignedData(zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),pubData));
Nft022UploadSecretResp resp = zxlnftSdkService.nft022UploadSecret(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -465,26 +467,26 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft023PointApplyRespDto> nft023PointApply(Nft023PointApplyReqDto reqDto){
/**
* 构造请求
*/
Nft023PointApplyReq req = Nft023PointApplyReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台方的私钥签名,签名对象和signature对象一致,签名对象是(platformPubKey_applyerAddr_接口名_count_operateId) 接口名=apply_point
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getApplyerAddr())
.concat("_").concat("apply_point")
.concat("_").concat(req.getCount().toString())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignature(signature);
Nft023PointApplyRespDto respDto = Nft023PointApplyRespDto.getNew();
try{
/**
* 构造请求
*/
Nft023PointApplyReq req = Nft023PointApplyReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 平台方的私钥签名,签名对象和signature对象一致,签名对象是(platformPubKey_applyerAddr_接口名_count_operateId) 接口名=apply_point
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getApplyerAddr())
.concat("_").concat("apply_point")
.concat("_").concat(req.getCount().toString())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignature(signature);
Nft023PointApplyResp resp = zxlnftSdkService.nft023PointApply(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -494,17 +496,17 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft024PointApplyResultRespDto> nft024PointApplyResult(Nft024PointApplyResultReqDto reqDto){
/**
* 构造请求
*/
Nft024PointApplyResultReq req = Nft024PointApplyResultReq.getNew();
BeanUtil.copy(reqDto,req);
//设置平台公钥
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
Nft024PointApplyResultRespDto respDto = Nft024PointApplyResultRespDto.getNew();
try{
/**
* 构造请求
*/
Nft024PointApplyResultReq req = Nft024PointApplyResultReq.getNew();
BeanUtil.copy(reqDto,req);
//设置平台公钥
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
Nft024PointApplyResultResp resp = zxlnftSdkService.nft024PointApplyResult(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -602,52 +604,50 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft030SeriesClaimRespDto> nft030SeriesClaim(Nft030SeriesClaimReqDto reqDto){
/**
* 构造请求
*/
Nft030SeriesClaimReq req = Nft030SeriesClaimReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 系列声明人的私钥签名,签名对象是(platformPubKey_pubKey_接口名_seriesName_totalCount_coverUrl_desc_maxPublishCount
* _seriesBeginFromZero_operateId) 接口名:series_claim
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getPubKey())
.concat("_").concat("series_claim")
.concat("_").concat(req.getSeriesName())
.concat("_").concat(req.getTotalCount().toString())
.concat("_").concat(req.getCoverUrl())
.concat("_").concat(req.getDesc())
.concat("_").concat(req.getMaxPublishCount().toString())
.concat("_").concat(req.getSeriesBeginFromZero().toString())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setSignature(signature);
/**
* 平台方的私钥签名,签名对象是(platformPubKey_pubKey_接口名_seriesName_totalCount_coverUrl_desc_maxPublishCount
* _seriesBeginFromZero_operateId) 接口名:series_claim
*/
String platformSignMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getPubKey())
.concat("_").concat("series_claim")
.concat("_").concat(req.getSeriesName())
.concat("_").concat(req.getTotalCount().toString())
.concat("_").concat(req.getCoverUrl())
.concat("_").concat(req.getDesc())
.concat("_").concat(req.getMaxPublishCount().toString())
.concat("_").concat(req.getSeriesBeginFromZero().toString())
.concat("_").concat(req.getOperateId());
String platformSignature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),platformSignMetaData);
req.setPlatformSignature(platformSignature);
Nft030SeriesClaimRespDto respDto = Nft030SeriesClaimRespDto.getNew();
try{
/**
* 构造请求
*/
Nft030SeriesClaimReq req = Nft030SeriesClaimReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 系列声明人的私钥签名,签名对象是(platformPubKey_pubKey_接口名_seriesName_totalCount_coverUrl_desc_maxPublishCount
* _seriesBeginFromZero_operateId) 接口名:series_claim
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getPubKey())
.concat("_").concat("series_claim")
.concat("_").concat(req.getSeriesName())
.concat("_").concat(req.getTotalCount().toString())
.concat("_").concat(req.getCoverUrl())
.concat("_").concat(req.getDesc())
.concat("_").concat(req.getMaxPublishCount().toString())
.concat("_").concat(req.getSeriesBeginFromZero().toString())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setSignature(signature);
/**
* 平台方的私钥签名,签名对象是(platformPubKey_pubKey_接口名_seriesName_totalCount_coverUrl_desc_maxPublishCount
* _seriesBeginFromZero_operateId) 接口名:series_claim
*/
String platformSignMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getPubKey())
.concat("_").concat("series_claim")
.concat("_").concat(req.getSeriesName())
.concat("_").concat(req.getTotalCount().toString())
.concat("_").concat(req.getCoverUrl())
.concat("_").concat(req.getDesc())
.concat("_").concat(req.getMaxPublishCount().toString())
.concat("_").concat(req.getSeriesBeginFromZero().toString())
.concat("_").concat(req.getOperateId());
String platformSignature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),platformSignMetaData);
req.setPlatformSignature(platformSignature);
Nft030SeriesClaimResp resp = zxlnftSdkService.nft030SeriesClaim(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -710,42 +710,42 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft034PublishRespDto> nft034Publish(Nft034PublishReqDto reqDto){
Nft034PublishReq req = Nft034PublishReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPubKey(zxlnftConfig.getNftPlatformPubKey());
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
req.setHash(zxlnftBiz.getHashString(req.getUrl()));
/**
* 发行人的私钥签名,签名对象是(platformPubKey_pubKey_接口名_author_name_url_displayUrl_hash_desc_flag_publishCount_seriesId_seriesBeginIndex
* _sellStatus_sellCount_metaData_operateId)
* 接口名:publish_nft
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getPubKey())
.concat("_").concat("publish_nft")
.concat("_").concat(req.getAuthor())
.concat("_").concat(req.getName())
.concat("_").concat(req.getUrl())
.concat("_").concat(req.getDisplayUrl())
.concat("_").concat(req.getHash())
.concat("_").concat(req.getDesc())
.concat("_").concat(req.getFlag()==null?"":req.getFlag())
.concat("_").concat(req.getPublishCount().toString())
.concat("_").concat(req.getSeriesId()==null?"":req.getSeriesId())
.concat("_").concat(req.getSeriesBeginIndex().toString())
.concat("_").concat(req.getSellStatus().toString())
.concat("_").concat(req.getSellCount()==null?Long.toString(0): req.getSellCount().toString())
.concat("_").concat(req.getMetaData()==null?"":req.getMetaData())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setSignature(signature);
String platformSignature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignature(platformSignature);
Nft034PublishRespDto respDto = Nft034PublishRespDto.getNew();
try{
Nft034PublishReq req = Nft034PublishReq.getNew();
BeanUtil.copy(reqDto,req);
req.setPubKey(zxlnftConfig.getNftPlatformPubKey());
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
req.setHash(zxlnftBiz.getHashString(req.getUrl()));
/**
* 发行人的私钥签名,签名对象是(platformPubKey_pubKey_接口名_author_name_url_displayUrl_hash_desc_flag_publishCount_seriesId_seriesBeginIndex
* _sellStatus_sellCount_metaData_operateId)
* 接口名:publish_nft
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getPubKey())
.concat("_").concat("publish_nft")
.concat("_").concat(req.getAuthor())
.concat("_").concat(req.getName())
.concat("_").concat(req.getUrl())
.concat("_").concat(req.getDisplayUrl())
.concat("_").concat(req.getHash())
.concat("_").concat(req.getDesc())
.concat("_").concat(req.getFlag()==null?"":req.getFlag())
.concat("_").concat(req.getPublishCount().toString())
.concat("_").concat(req.getSeriesId()==null?"":req.getSeriesId())
.concat("_").concat(req.getSeriesBeginIndex().toString())
.concat("_").concat(req.getSellStatus().toString())
.concat("_").concat(req.getSellCount()==null?Long.toString(0): req.getSellCount().toString())
.concat("_").concat(req.getMetaData()==null?"":req.getMetaData())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setSignature(signature);
String platformSignature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignature(platformSignature);
Nft034PublishResp resp = zxlnftSdkService.nft034Publish(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -893,32 +893,31 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft043BuyRespDto> nft043Buy(Nft043BuyReqDto reqDto){
/**
* 构造请求
*/
Nft043BuyReq req = Nft043BuyReq.getNew();
BeanUtil.copy(reqDto,req);
//设置平台公钥
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 接收人的私钥签名,签名对象是(platformPubKey_receiverPubKey_pointReceiverAddr_applyScore_接口名_nftId_offerCount_operateId)
* 接口名:buy_nft
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getReceiverPubKey())
.concat("_").concat(req.getPointReceiverAddr())
.concat("_").concat(req.getApplyScore().toString())
.concat("_").concat("buy_nft")
.concat("_").concat(req.getNftId())
.concat("_").concat(req.getOfferCount().toString())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignature(signature);
Nft043BuyRespDto respDto = Nft043BuyRespDto.getNew();
try{
/**
* 构造请求
*/
Nft043BuyReq req = Nft043BuyReq.getNew();
BeanUtil.copy(reqDto,req);
//设置平台公钥
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 接收人的私钥签名,签名对象是(platformPubKey_receiverPubKey_pointReceiverAddr_applyScore_接口名_nftId_offerCount_operateId)
* 接口名:buy_nft
*/
String signMetaData = req.getPlatformPubKey()
.concat("_").concat(req.getReceiverPubKey())
.concat("_").concat(req.getPointReceiverAddr())
.concat("_").concat(req.getApplyScore().toString())
.concat("_").concat("buy_nft")
.concat("_").concat(req.getNftId())
.concat("_").concat(req.getOfferCount().toString())
.concat("_").concat(req.getOperateId());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignature(signature);
Nft043BuyResp resp = zxlnftSdkService.nft043Buy(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......@@ -1104,25 +1103,25 @@ public class ZxlnftSdkUtil {
}
public ZxlnftResponseDto<Nft054QueryUserAddressBelongToUserRespDto> nft054QueryUserAddressBelongToUser(Nft054QueryUserAddressBelongToUserReqDto reqDto){
/**
* 构造请求
*/
Nft054QueryUserAddressBelongToUserReq req = Nft054QueryUserAddressBelongToUserReq.getNew();
BeanUtil.copy(reqDto,req);
//设置平台公钥
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 接收人的私钥签名,签名对象是(platformPubKey_receiverPubKey_pointReceiverAddr_applyScore_接口名_nftId_offerCount_operateId)
* 接口名:buy_nft
*/
String signMetaData = req.getAddress1()
.concat("_").concat(req.getAddress2());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft054QueryUserAddressBelongToUserRespDto respDto = Nft054QueryUserAddressBelongToUserRespDto.getNew();
try{
/**
* 构造请求
*/
Nft054QueryUserAddressBelongToUserReq req = Nft054QueryUserAddressBelongToUserReq.getNew();
BeanUtil.copy(reqDto,req);
//设置平台公钥
req.setPlatformPubKey(zxlnftConfig.getNftPlatformPubKey());
/**
* 接收人的私钥签名,签名对象是(platformPubKey_receiverPubKey_pointReceiverAddr_applyScore_接口名_nftId_offerCount_operateId)
* 接口名:buy_nft
*/
String signMetaData = req.getAddress1()
.concat("_").concat(req.getAddress2());
String signature = zxlnftBiz.createSign(zxlnftConfig.getNftPlatformPriKey(),signMetaData);
req.setPlatformSignData(signature);
Nft054QueryUserAddressBelongToUserResp resp = zxlnftSdkService.nft054QueryUserAddressBelongToUser(req);
BeanUtil.copy(resp,respDto);
}catch(ZxlNftException e){
......
package com.liquidnet.service.consumer.kylin.service.processor;
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.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.consumer.kylin.utils.DataUtils;
import com.liquidnet.service.galaxy.biz.GalaxyBeanTransferBiz;
import com.liquidnet.service.galaxy.biz.GalaxyEnumBiz;
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.GalaxyNftBuyRespDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishAndBuyReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishAndBuyRespDto;
import com.liquidnet.service.galaxy.exception.GalaxyNftException;
import com.liquidnet.service.galaxy.router.zxin.biz.ZxinTradeCommonBiz;
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;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
......@@ -40,320 +21,14 @@ import java.util.Date;
@Component
public class ConsumerGalaxyJsonNftPublishAndBuyProcessor {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
@Autowired
private ZxlnftBiz zxlnftBiz;
@Autowired
private ZxlnftConfig zxlnftConfig;
@Autowired
private DataUtils dataUtils;
@Autowired
private GalaxyBeanTransferBiz galaxyBeanTransferBiz;
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
try{
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNotNull(nftOrderBo)){
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());
if(StringUtil.isNull(seriesNftInfoBo)){
return ResponseDto.failure(GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getCode(), GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getMessage());
}
//初始化订单数据
if(nftOrderBo==null){
nftOrderBo = galaxyBeanTransferBiz.buildNftOrderBo(reqDto.getNftOrderPayId(),userInfoBo,seriesNftInfoBo);
dataUtils.setNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}
/**
* 获取订单和nft绑定信息
*/
GalaxyNftOrderBindBo nftOrderBindBo = dataUtils.getGalaxyNftOrderBindBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNull(nftOrderBindBo)){
//获取发行索引
long nftIdNo = dataUtils.incrNftIdNo(reqDto.getRouterType(),reqDto.getSkuId());
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);
}
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 = nftOrderBindBo.getNftIdIndex();
//发行金额
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;
// //查询系列信息(暂时不通过系列查询获取发行序列号)
// 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()) {
publishTaskId = nft034RespDto.getData().getTaskId();
//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)) {
//休眠1秒钟,等待执行结果
try {
Thread.sleep(2000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
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();
}else if(nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.PROCESSING.getCode())){
log.info("任务执行中!taskId:{}", nft035ReqDto.getTaskId());
nftPublishStatus = nft035RespDtoTemp.getData().getTaskStatus();
}
if (count == 5) {
log.info("=======查询共5次,跳出循环!taskId:{}", nft035ReqDto.getTaskId());
break;
}
}
//赋值返回参数
nftId = nftIdBegin;
log.info("发行NFT后返回给前端nftID:{}", nftIdBegin);
log.info("总共执行了{}次查询 总耗时:{} MS", count, (System.currentTimeMillis() - timeStart));
}
//更新订单缓存数据状态
nftOrderBo.setNftId(nftId);
nftOrderBo.setNftPublishTaskId(publishTaskId);
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(nftId)){
//执行购买逻辑
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusinessSync(reqDto.getRouterType(),nftId,userInfoBo,seriesNftInfoBo,nftOrderBo);
BeanUtil.copy(nftBuyRespDto,nftPublishAndBuyRespDto);
return ResponseDto.success(nftPublishAndBuyRespDto);
}
}catch(GalaxyNftException e){
String rsMsg = e.getMessage();
log.error("购买失败",e);
}catch(Exception e){
log.error("发行上链异常!",e);
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
private ZxinTradeCommonBiz zxinTradeCommonBiz;
/**
* 保持线程循环查询
* @param nftId
* @param userInfoBo
* @param seriesNftInfoBo
* 执行购买处理
* @param reqDto
* @return
*/
private GalaxyNftBuyRespDto nftBuyBusinessSync(String routerType,String nftId,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo,GalaxyNftOrderBo nftOrderBo){
//定义返回参数
String nftBuyTaskId = null;
Long nftBuyChainTimestamp = null;
Integer nftBuyStatus = null;
String nftBuyTradeHash = null;
String nftBuyPayTaskId = null;
// 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(userInfoBo.getBlockChainAddress());
nft043BuyReqDto.setOfferCount(seriesNftInfoBo.getSellCount().longValue());
nft043BuyReqDto.setOperateId(IDGenerator.get32UUID());
/**
* 接收人的私钥签名,签名对象是(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();
}
nft043BuyReqDto.setSignature(signature);
ZxlnftResponseDto<Nft043BuyRespDto> nft043RespDto = zxlnftSdkUtil.nft043Buy(nft043BuyReqDto);
if(nft043RespDto.isSuccess()){
nftBuyTaskId = nft043RespDto.getData().getTaskId();
//3.2.4查询NFT购买结果
Nft044BuyResultReqDto nft044ReqDto = Nft044BuyResultReqDto.getNew();
nft044ReqDto.setTaskId(nftBuyTaskId);
long timeStart = System.currentTimeMillis();
int count = 0;
while(nftBuyPayTaskId == null){
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
log.info("=======执行第{}次查询,taskId:{}",count,nft044ReqDto.getTaskId());
ZxlnftResponseDto<Nft044BuyResultRespDto> nft044RespDto = zxlnftSdkUtil.nft044BuyResult(nft044ReqDto);
if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
nftBuyPayTaskId = nft044RespDto.getData().getPayTaskId();
nftBuyChainTimestamp = nft044RespDto.getData().getChainTimestamp();
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
nftBuyTradeHash = nft044RespDto.getData().getTxHash();
}else if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
log.info("任务执行失败!taskId:{}",nft044ReqDto.getTaskId());
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
}else if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.PROCESSING.getCode())){
log.info("任务执行中!taskId:{}",nft044ReqDto.getTaskId());
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
}
if(count==5){
log.info("=======查询共5次,跳出循环!taskId:{}",nft044ReqDto.getTaskId());
break;
}
}
log.info("总共执行了多少次查询:{} 总耗时:{}",count,System.currentTimeMillis() - timeStart);
// if(StringUtil.isNotEmpty(payTaskId)){
// //3.2.5查询NFT购买支付结果
// Nft045BuyPayResultReqDto nft045ReqDto = Nft045BuyPayResultReqDto.getNew();
// nft045ReqDto.setTaskId(payTaskId);
// ZxlnftResponseDto<Nft045BuyPayResultRespDto> nft045RespDto = zxlnftSdkUtil.nft045BuyPayResult(nft045ReqDto);
// }
//更新订单缓存数据状态
nftOrderBo.setNftBuyTaskId(nftBuyTaskId);
if(StringUtil.isNotNull(nftBuyChainTimestamp)){
//设置时间
String nftBuyChainTimestampStr = DateUtil.format(new Date(nftBuyChainTimestamp*1000),DateUtil.Formatter.yyyyMMddHHmmss);
nftOrderBo.setNftBuyChainTimestamp(nftBuyChainTimestampStr);
}
if(StringUtil.isNotNull(nftBuyStatus)){
//转换任务状态
String nftBuyStatusStr = GalaxyEnumBiz.getTaskStatusEnum(routerType,nftBuyStatus.toString()).getCode();
nftOrderBo.setNftBuyStatus(nftBuyStatusStr);
}
nftOrderBo.setNftBuyTradeHash(nftBuyTradeHash);
nftOrderBo.setNftBuyPayTaskId(nftBuyPayTaskId);
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//先更新nft发行数据
dataUtils.updateNftOrderBuyInfo(routerType,nftOrderBo.getNftOrderPayId(),nftOrderBo);
}
GalaxyNftBuyRespDto nftBuyRespDto = GalaxyNftBuyRespDto.getNew();
nftBuyRespDto.setUserId(userInfoBo.getUserId());
nftBuyRespDto.setNftId(nftId);
return nftBuyRespDto;
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
return zxinTradeCommonBiz.nftPublishAndBuy(reqDto);
}
}
package com.liquidnet.service.consumer.kylin.utils;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.galaxy.utils.AbstractDataUtils;
import com.liquidnet.service.galaxy.utils.QueueUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class DataUtils extends AbstractDataUtils {
@Autowired
private RedisUtil redisUtil;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private QueueUtil queueUtil;
private long keyExpireTime = 3600*24*30;
@Override
public RedisUtil getRedisUtil() {
return redisUtil;
}
@Override
public MongoTemplate getMongoTemplate() {
return mongoTemplate;
}
@Override
public com.liquidnet.service.galaxy.utils.QueueUtil getQueueUtil() {
return queueUtil;
}
}
package com.liquidnet.service.galaxy.biz;
import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
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.GalaxyNftPublishAndBuyReqDto;
import com.liquidnet.service.galaxy.dto.vo.mongo.GalaxyNftOrderFailLogVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -54,4 +57,42 @@ public class GalaxyBeanTransferBiz {
nftOrderBo.setUpdatedAt(null);
return nftOrderBo;
}
/**
*
* @param reqDto
* @param userInfoBo
* @param seriesNftInfoBo
* @return
*/
public GalaxyNftOrderFailLogVo buildNftOrderFailLogVo(GalaxyEnum.TradeTypeEnum tradeTypeEnum,GalaxyNftPublishAndBuyReqDto reqDto
,GalaxyEnum.OrderDealWithStatusEnum orderDealWithStatus,String failDesc,String failDescSecond,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo, GalaxyNftOrderBo nftOrderBo){
GalaxyNftOrderFailLogVo nftOrderFailLogVo = GalaxyNftOrderFailLogVo.getNew();
nftOrderFailLogVo.setNftOrderPayId(reqDto.getNftOrderPayId());
if(StringUtil.isNotNull(seriesNftInfoBo)){
nftOrderFailLogVo.setUserId(seriesNftInfoBo.getSkuId());
nftOrderFailLogVo.setNftName(seriesNftInfoBo.getNftName());
nftOrderFailLogVo.setSeriesName(seriesNftInfoBo.getSeriesName());
nftOrderFailLogVo.setSeriesId(seriesNftInfoBo.getSeriesId());
nftOrderFailLogVo.setSeriesCode(seriesNftInfoBo.getSeriesCode());
}
if(StringUtil.isNotNull(nftOrderBo)){
nftOrderFailLogVo.setNftId(nftOrderBo.getNftId());
if(tradeTypeEnum.getCode().equalsIgnoreCase(GalaxyEnum.TradeTypeEnum.TRADE_PUBLISH.getCode())){
nftOrderFailLogVo.setTaskId(nftOrderBo.getNftPublishTaskId());
}else if(tradeTypeEnum.getCode().equalsIgnoreCase(GalaxyEnum.TradeTypeEnum.TRADE_BUY.getCode())){
nftOrderFailLogVo.setTaskId(nftOrderBo.getNftBuyTaskId());
}
}
nftOrderFailLogVo.setFailReasonDesc(failDesc);
nftOrderFailLogVo.setFailReasonDescSecond(failDescSecond);
nftOrderFailLogVo.setDealWithStatus(orderDealWithStatus.getCode());
nftOrderFailLogVo.setTradeType(tradeTypeEnum.getCode());
nftOrderFailLogVo.setRouterType(reqDto.getRouterType());
nftOrderFailLogVo.setCreatedAt(LocalDateTime.now());
nftOrderFailLogVo.setUpdatedAt(null);
return nftOrderFailLogVo;
}
}
package com.liquidnet.service.galaxy.router.zxin.biz;
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.util.ZxlnftSdkUtil;
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.GalaxyNftBuyRespDto;
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;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: ZxinTradeBiz
* @Package com.liquidnet.service.galaxy.router.zxin.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2022/3/15 13:08
*/
@Slf4j
@Component
public class ZxinTradeCommonBiz {
@Autowired
private ZxlnftSdkUtil zxlnftSdkUtil;
@Autowired
private ZxlnftBiz zxlnftBiz;
@Autowired
private ZxlnftConfig zxlnftConfig;
@Autowired
private GalaxyDataUtils dataUtils;
@Autowired
private GalaxyBeanTransferBiz galaxyBeanTransferBiz;
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
//获取用户信息
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId());
if(StringUtil.isNull(userInfoBo)){
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)){
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(StringUtil.isNotNull(nftOrderBo)){
/**
* 如果已经发行购买成功
*/
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())
&&nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL_ALREADY_EXIST.getCode(), GalaxyErrorEnum.PUBLISH_FAIL_ALREADY_EXIST.getMessage());
}
if(nftOrderBo.getNftPublishStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.TASK_SUCCESS.getCode())
&&nftOrderBo.getNftBuyStatus().equalsIgnoreCase(GalaxyEnum.TaskStatusEnum.INIT.getCode())){
//再次发起购买
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = this.executeBuyBusiness(reqDto,userInfoBo,seriesNftInfoBo,nftOrderBo);
return ResponseDto.success(nftPublishAndBuyRespDto);
}
}
//初始化订单数据
if(nftOrderBo==null){
nftOrderBo = galaxyBeanTransferBiz.buildNftOrderBo(reqDto.getNftOrderPayId(),userInfoBo,seriesNftInfoBo);
dataUtils.setNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}
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());
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));
// }
//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()) {
try{
publishTaskId = nft034RespDto.getData().getTaskId();
nftOrderBo.setNftPublishTaskId(publishTaskId);
//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)) {
//休眠1秒钟,等待执行结果
try {
Thread.sleep(2000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
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(), "ERR_1:"+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 == 5) {
// log.info("=======查询共5次,跳出循环!taskId:{}", nft035ReqDto.getTaskId());
// break;
// }
}
//赋值返回参数
nftId = nftIdBegin;
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(),"ERR_2:"+e.getMessage());
}
}else{
//发行失败
throw new GalaxyNftPublishException(GalaxyErrorEnum.NFT_PUBLISH_ERROR.getCode(),"ERR_3:"+nft034RespDto.getMessage());
}
}catch (GalaxyNftPublishException e) {
failDesc = e.getMessage();
}catch(Exception e){
failDesc = e.getMessage();
log.error(e.getMessage(),e);
}
if(StringUtil.isNotEmpty(failDesc)){
//记录发行异常信息
try{
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);
}
}
//更新订单缓存数据状态
nftOrderBo.setNftId(nftId);
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(nftId)){
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = this.executeBuyBusiness(reqDto,userInfoBo,seriesNftInfoBo,nftOrderBo);
return ResponseDto.success(nftPublishAndBuyRespDto);
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
private GalaxyNftPublishAndBuyRespDto executeBuyBusiness(GalaxyNftPublishAndBuyReqDto reqDto,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo,GalaxyNftOrderBo nftOrderBo){
String buyFailDesc = null;
//执行购买逻辑
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
try{
GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusinessSync(reqDto.getRouterType(),nftOrderBo.getNftId(),userInfoBo,seriesNftInfoBo,nftOrderBo);
BeanUtil.copy(nftBuyRespDto,nftPublishAndBuyRespDto);
}catch (GalaxyNftBuyException e){
buyFailDesc = e.getMessage();
}catch(Exception e){
buyFailDesc = e.getMessage();
log.error(e.getMessage(),e);
}
if(StringUtil.isNotEmpty(buyFailDesc)){
//记录购买异常信息
try{
GalaxyNftOrderFailLogVo nftOrderFailLogVo = galaxyBeanTransferBiz.buildNftOrderFailLogVo(GalaxyEnum.TradeTypeEnum.TRADE_BUY,reqDto,GalaxyEnum.OrderDealWithStatusEnum.DATA_INIT,buyFailDesc,null
,userInfoBo,seriesNftInfoBo,nftOrderBo);
dataUtils.setNftOrderFailLogVo(reqDto.getRouterType(),nftOrderFailLogVo);
}catch(Exception e){
log.error(reqDto.getNftOrderPayId()+"购买setNftOrderFailLogVo记录异常:"+e.getMessage(),e);
}
}
return nftPublishAndBuyRespDto;
}
/**
* 保持线程循环查询
* @param nftId
* @param userInfoBo
* @param seriesNftInfoBo
* @return
*/
private GalaxyNftBuyRespDto nftBuyBusinessSync(String routerType,String nftId,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo,GalaxyNftOrderBo nftOrderBo){
//定义返回参数
String nftBuyTaskId = null;
Long nftBuyChainTimestamp = null;
Integer nftBuyStatus = null;
String nftBuyTradeHash = null;
String nftBuyPayTaskId = null;
// 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(userInfoBo.getBlockChainAddress());
nft043BuyReqDto.setOfferCount(seriesNftInfoBo.getSellCount().longValue());
nft043BuyReqDto.setOperateId(IDGenerator.get32UUID());
/**
* 接收人的私钥签名,签名对象是(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();
}
nft043BuyReqDto.setSignature(signature);
ZxlnftResponseDto<Nft043BuyRespDto> nft043RespDto = zxlnftSdkUtil.nft043Buy(nft043BuyReqDto);
if(nft043RespDto.isSuccess()){
try{
nftBuyTaskId = nft043RespDto.getData().getTaskId();
nftOrderBo.setNftBuyTaskId(nftBuyTaskId);
//3.2.4查询NFT购买结果
Nft044BuyResultReqDto nft044ReqDto = Nft044BuyResultReqDto.getNew();
nft044ReqDto.setTaskId(nftBuyTaskId);
long timeStart = System.currentTimeMillis();
int count = 0;
while(nftBuyPayTaskId == null){
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
log.info("=======执行第{}次查询,taskId:{}",count,nft044ReqDto.getTaskId());
ZxlnftResponseDto<Nft044BuyResultRespDto> nft044RespDto = zxlnftSdkUtil.nft044BuyResult(nft044ReqDto);
if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
nftBuyPayTaskId = nft044RespDto.getData().getPayTaskId();
nftBuyChainTimestamp = nft044RespDto.getData().getChainTimestamp();
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
nftBuyTradeHash = nft044RespDto.getData().getTxHash();
}else if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
log.info("任务执行失败!taskId:{}",nft044ReqDto.getTaskId());
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
//购买失败
throw new GalaxyNftBuyException(GalaxyErrorEnum.NFT_BUY_FAIL.getCode(), "ERR_1:"+GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
}else if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.PROCESSING.getCode())){
log.info("任务执行中!taskId:{}",nft044ReqDto.getTaskId());
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
}
// if(count==5){
// log.info("=======查询共5次,跳出循环!taskId:{}",nft044ReqDto.getTaskId());
// break;
// }
}
log.info("总共执行了多少次查询:{} 总耗时:{}",count,System.currentTimeMillis() - timeStart);
// if(StringUtil.isNotEmpty(payTaskId)){
// //3.2.5查询NFT购买支付结果
// Nft045BuyPayResultReqDto nft045ReqDto = Nft045BuyPayResultReqDto.getNew();
// nft045ReqDto.setTaskId(payTaskId);
// ZxlnftResponseDto<Nft045BuyPayResultRespDto> nft045RespDto = zxlnftSdkUtil.nft045BuyPayResult(nft045ReqDto);
// }
}catch (GalaxyNftBuyException e){
throw new GalaxyNftBuyException(e.getCode(),e.getMessage());
}catch(Exception e){
log.error(e.getMessage(),e);
//发行失败
throw new GalaxyNftBuyException(GalaxyErrorEnum.NFT_BUY_ERROR.getCode(),"ERR_2:"+e.getMessage());
}
//更新订单缓存数据状态
if(StringUtil.isNotNull(nftBuyChainTimestamp)){
//设置时间
String nftBuyChainTimestampStr = DateUtil.format(new Date(nftBuyChainTimestamp*1000),DateUtil.Formatter.yyyyMMddHHmmss);
nftOrderBo.setNftBuyChainTimestamp(nftBuyChainTimestampStr);
}
if(StringUtil.isNotNull(nftBuyStatus)){
//转换任务状态
String nftBuyStatusStr = GalaxyEnumBiz.getTaskStatusEnum(routerType,nftBuyStatus.toString()).getCode();
nftOrderBo.setNftBuyStatus(nftBuyStatusStr);
}
nftOrderBo.setNftBuyTradeHash(nftBuyTradeHash);
nftOrderBo.setNftBuyPayTaskId(nftBuyPayTaskId);
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//先更新nft发行数据
dataUtils.updateNftOrderBuyInfo(routerType,nftOrderBo.getNftOrderPayId(),nftOrderBo);
}else{
//购买失败
throw new GalaxyNftBuyException(GalaxyErrorEnum.NFT_BUY_ERROR.getCode(),"ERR_3:"+nft043RespDto.getMessage());
}
GalaxyNftBuyRespDto nftBuyRespDto = GalaxyNftBuyRespDto.getNew();
nftBuyRespDto.setUserId(userInfoBo.getUserId());
nftBuyRespDto.setNftId(nftId);
return nftBuyRespDto;
}
}
......@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class DataUtils extends AbstractDataUtils{
public class GalaxyDataUtils extends AbstractDataUtils{
@Autowired
private RedisUtil redisUtil;
......
......@@ -6,6 +6,7 @@ db.createCollection("GalaxySeriesNftInfoVo");
db.createCollection("GalaxySeriesNftUploadVo");
db.createCollection("GalaxyNftOrderVo");
db.createCollection("GalaxyNftOrderBindVo");
db.createCollection("GalaxyNftOrderFailLogVo");
db.createCollection("GalaxyNftTradeVo");
......@@ -16,6 +17,7 @@ db.GalaxySeriesNftInfoVo.createIndex({skuId:"hashed"});
db.GalaxySeriesNftUploadVo.createIndex({skuId:"hashed"});
db.GalaxyNftOrderVo.createIndex({nftOrderPayId:"hashed"});
db.GalaxyNftOrderBindVo.createIndex({nftOrderPayId:"hashed"});
db.GalaxyNftOrderFailLogVo.createIndex({nftOrderPayId:"hashed"});
db.GalaxyNftTradeVo.createIndex({nftId:"hashed"});
#创建分片
......
......@@ -139,7 +139,7 @@ create table galaxy_nft_order_fail_log
fail_reason_desc_second varchar(20) COMMENT '失败原因2',
trade_type varchar(3) COMMENT '交易类别 1发行 2购买 3转移 4设置价格 5设置状态',
router_type varchar(20) NOT NULL COMMENT '路由类型(zxinchain、eth、antchain)',
deal_with_status varchar(3) COMMENT '处理状态 1未处理 2已处理 3再次失败 4不做处理',
deal_with_status varchar(3) COMMENT '处理状态 0数据初始化 1已处理成功 2处理失败 3不做处理',
created_at timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updated_at timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`mid`)
......
......@@ -24,7 +24,7 @@ import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftInfoBo;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesNftUploadBo;
import com.liquidnet.service.galaxy.dto.param.*;
import com.liquidnet.service.galaxy.utils.DataUtils;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -59,7 +59,7 @@ public class ZxinArtworkBiz {
private ZxlnftConfig zxlnftConfig;
@Autowired
private DataUtils dataUtils;
private GalaxyDataUtils dataUtils;
@Autowired
private GalaxyCommonBiz galaxyCommonBiz;
......
......@@ -20,7 +20,7 @@ import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishRespDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishResultQueryReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyNftPublishResultQueryRespDto;
import com.liquidnet.service.galaxy.utils.DataUtils;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -45,7 +45,7 @@ public class ZxinPublishBiz {
private ZxlnftSdkUtil zxlnftSdkUtil;
@Autowired
private DataUtils dataUtils;
private GalaxyDataUtils dataUtils;
@Autowired
private GalaxyBeanTransferBiz galaxyBeanTransferBiz;
......
......@@ -3,7 +3,6 @@ package com.liquidnet.service.galaxy.router.zxin.biz;
import com.liquidnet.common.exception.LiquidnetServiceException;
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.util.ZxlnftSdkUtil;
import com.liquidnet.commons.lang.util.*;
......@@ -12,18 +11,16 @@ 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.utils.DataUtils;
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.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -50,7 +47,7 @@ public class ZxinTradeBiz {
private ZxlnftConfig zxlnftConfig;
@Autowired
private DataUtils dataUtils;
private GalaxyDataUtils dataUtils;
@Autowired
private GalaxyBeanTransferBiz galaxyBeanTransferBiz;
......@@ -58,6 +55,9 @@ public class ZxinTradeBiz {
@Autowired
private ZxinPublishBiz zxinPublishBiz;
@Autowired
private ZxinTradeCommonBiz zxinTradeCommonBiz;
public ResponseDto<GalaxyNftBuyRespDto> nftBuy(GalaxyNftBuyReqDto nftBuyReqDto){
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getNftOrderPayId());
......@@ -87,183 +87,6 @@ public class ZxinTradeBiz {
}
}
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNotNull(nftOrderBo)){
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());
if(StringUtil.isNull(seriesNftInfoBo)){
return ResponseDto.failure(GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getCode(), GalaxyErrorEnum.SERIES_NFT_INFO_NOT_EXIST.getMessage());
}
//初始化订单数据
if(nftOrderBo==null){
nftOrderBo = galaxyBeanTransferBiz.buildNftOrderBo(reqDto.getNftOrderPayId(),userInfoBo,seriesNftInfoBo);
dataUtils.setNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId(),nftOrderBo);
}
/**
* 获取订单和nft绑定信息
*/
GalaxyNftOrderBindBo nftOrderBindBo = dataUtils.getGalaxyNftOrderBindBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
if(StringUtil.isNull(nftOrderBindBo)){
//获取发行索引
long nftIdNo = dataUtils.incrNftIdNo(reqDto.getRouterType(),reqDto.getSkuId());
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);
}
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 = nftOrderBindBo.getNftIdIndex();
//发行金额
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;
// //查询系列信息(暂时不通过系列查询获取发行序列号)
// 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()) {
publishTaskId = nft034RespDto.getData().getTaskId();
//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)) {
//休眠1秒钟,等待执行结果
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
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();
}else if(nft035RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.PROCESSING.getCode())){
log.info("任务执行中!taskId:{}", nft035ReqDto.getTaskId());
nftPublishStatus = nft035RespDtoTemp.getData().getTaskStatus();
}
if (count == 5) {
log.info("=======查询共5次,跳出循环!taskId:{}", nft035ReqDto.getTaskId());
break;
}
}
//赋值返回参数
nftId = nftIdBegin;
log.info("发行NFT后返回给前端nftID:{}", nftIdBegin);
log.info("总共执行了{}次查询 总耗时:{} MS", count, (System.currentTimeMillis() - timeStart));
}
//更新订单缓存数据状态
nftOrderBo.setNftId(nftId);
nftOrderBo.setNftPublishTaskId(publishTaskId);
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(nftId)){
//执行购买逻辑
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusinessSync(reqDto.getRouterType(),nftId,userInfoBo,seriesNftInfoBo,nftOrderBo);
BeanUtil.copy(nftBuyRespDto,nftPublishAndBuyRespDto);
return ResponseDto.success(nftPublishAndBuyRespDto);
}
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_FAIL.getMessage());
}
public ResponseDto<GalaxyNftBuyResultQueryRespDto> nftBuyResultQuery(GalaxyNftBuyResultQueryReqDto reqDto) {
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(reqDto.getRouterType(),reqDto.getNftOrderPayId());
......@@ -437,121 +260,11 @@ public class ZxinTradeBiz {
}
/**
* 保持线程循环查询
* @param nftId
* @param userInfoBo
* @param seriesNftInfoBo
* 发行和购买
* @param reqDto
* @return
*/
private GalaxyNftBuyRespDto nftBuyBusinessSync(String routerType,String nftId,GalaxyUserInfoBo userInfoBo, GalaxySeriesNftInfoBo seriesNftInfoBo,GalaxyNftOrderBo nftOrderBo){
//定义返回参数
String nftBuyTaskId = null;
Long nftBuyChainTimestamp = null;
Integer nftBuyStatus = null;
String nftBuyTradeHash = null;
String nftBuyPayTaskId = null;
// 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(userInfoBo.getBlockChainAddress());
nft043BuyReqDto.setOfferCount(seriesNftInfoBo.getSellCount().longValue());
nft043BuyReqDto.setOperateId(IDGenerator.get32UUID());
/**
* 接收人的私钥签名,签名对象是(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();
}
nft043BuyReqDto.setSignature(signature);
ZxlnftResponseDto<Nft043BuyRespDto> nft043RespDto = zxlnftSdkUtil.nft043Buy(nft043BuyReqDto);
if(nft043RespDto.isSuccess()){
nftBuyTaskId = nft043RespDto.getData().getTaskId();
//3.2.4查询NFT购买结果
Nft044BuyResultReqDto nft044ReqDto = Nft044BuyResultReqDto.getNew();
nft044ReqDto.setTaskId(nftBuyTaskId);
long timeStart = System.currentTimeMillis();
int count = 0;
while(nftBuyPayTaskId == null){
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
log.info("=======执行第{}次查询,taskId:{}",count,nft044ReqDto.getTaskId());
ZxlnftResponseDto<Nft044BuyResultRespDto> nft044RespDto = zxlnftSdkUtil.nft044BuyResult(nft044ReqDto);
if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
nftBuyPayTaskId = nft044RespDto.getData().getPayTaskId();
nftBuyChainTimestamp = nft044RespDto.getData().getChainTimestamp();
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
nftBuyTradeHash = nft044RespDto.getData().getTxHash();
}else if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
log.info("任务执行失败!taskId:{}",nft044ReqDto.getTaskId());
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
}else if(nft044RespDto.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.PROCESSING.getCode())){
log.info("任务执行中!taskId:{}",nft044ReqDto.getTaskId());
nftBuyStatus = nft044RespDto.getData().getTaskStatus();
}
if(count==5){
log.info("=======查询共5次,跳出循环!taskId:{}",nft044ReqDto.getTaskId());
break;
}
}
log.info("总共执行了多少次查询:{} 总耗时:{}",count,System.currentTimeMillis() - timeStart);
// if(StringUtil.isNotEmpty(payTaskId)){
// //3.2.5查询NFT购买支付结果
// Nft045BuyPayResultReqDto nft045ReqDto = Nft045BuyPayResultReqDto.getNew();
// nft045ReqDto.setTaskId(payTaskId);
// ZxlnftResponseDto<Nft045BuyPayResultRespDto> nft045RespDto = zxlnftSdkUtil.nft045BuyPayResult(nft045ReqDto);
// }
//更新订单缓存数据状态
nftOrderBo.setNftBuyTaskId(nftBuyTaskId);
if(StringUtil.isNotNull(nftBuyChainTimestamp)){
//设置时间
String nftBuyChainTimestampStr = DateUtil.format(new Date(nftBuyChainTimestamp*1000),DateUtil.Formatter.yyyyMMddHHmmss);
nftOrderBo.setNftBuyChainTimestamp(nftBuyChainTimestampStr);
}
if(StringUtil.isNotNull(nftBuyStatus)){
//转换任务状态
String nftBuyStatusStr = GalaxyEnumBiz.getTaskStatusEnum(routerType,nftBuyStatus.toString()).getCode();
nftOrderBo.setNftBuyStatus(nftBuyStatusStr);
}
nftOrderBo.setNftBuyTradeHash(nftBuyTradeHash);
nftOrderBo.setNftBuyPayTaskId(nftBuyPayTaskId);
nftOrderBo.setUpdatedAt(LocalDateTime.now());
//先更新nft发行数据
dataUtils.updateNftOrderBuyInfo(routerType,nftOrderBo.getNftOrderPayId(),nftOrderBo);
}
GalaxyNftBuyRespDto nftBuyRespDto = GalaxyNftBuyRespDto.getNew();
nftBuyRespDto.setUserId(userInfoBo.getUserId());
nftBuyRespDto.setNftId(nftId);
return nftBuyRespDto;
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
return zxinTradeCommonBiz.nftPublishAndBuy(reqDto);
}
}
......@@ -21,7 +21,7 @@ import com.liquidnet.service.galaxy.dto.param.GalaxyUserBindStatusQueryReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserBindStatusQueryRespDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterReqDto;
import com.liquidnet.service.galaxy.dto.param.GalaxyUserRegisterRespDto;
import com.liquidnet.service.galaxy.utils.DataUtils;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -51,7 +51,7 @@ public class ZxinUserBiz {
private ZxlnftBiz zxlnftBiz;
@Autowired
private DataUtils dataUtils;
private GalaxyDataUtils dataUtils;
public ResponseDto<GalaxyUserRegisterRespDto> userRegister(GalaxyUserRegisterReqDto reqDto) {
String userId = reqDto.getUserId();
......
package com.liquidnet.service.galaxy.router.zxin.service;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
import com.liquidnet.service.galaxy.dto.param.*;
import com.liquidnet.service.galaxy.router.strategy.IGalaxyRouterStrategyTrade;
......@@ -34,9 +32,10 @@ public class GalaxyRouterStrategyZxlTradeImpl implements IGalaxyRouterStrategyTr
@Override
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) {
queueUtil.sendMsgByRedis(MQConst.GalaxyQueue.JSON_NFT_PUBLISH_AND_BUY.getKey(), JsonUtils.toJson(reqDto));
return ResponseDto.success();
// return zxinTradeBiz.nftPublishAndBuy(reqDto);
//测试发送队列
// queueUtil.sendMsgByRedis(MQConst.GalaxyQueue.JSON_NFT_PUBLISH_AND_BUY.getKey(), JsonUtils.toJson(reqDto));
// return ResponseDto.success();
return zxinTradeBiz.nftPublishAndBuy(reqDto);
}
@Override
......
......@@ -6,7 +6,8 @@ liquidnet:
username: user
password: user123
eureka:
host: 39.107.71.112:7001
# host: 39.107.71.112:7001
host: 127.0.0.1:7001
# end-dev-这里是配置信息基本值
spring:
......
......@@ -4,7 +4,7 @@ import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.constant.GalaxyEnum;
import com.liquidnet.service.galaxy.dto.bo.GalaxyUserInfoBo;
import com.liquidnet.service.galaxy.utils.DataUtils;
import com.liquidnet.service.galaxy.utils.GalaxyDataUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -34,7 +34,7 @@ public class TestRedisUtil {
private long keyExpireTime = 3600*24*30;
@Autowired
private DataUtils dataUtils;
private GalaxyDataUtils dataUtils;
@Test
......
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