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

Commit 4ca2db0b authored by anjiabin's avatar anjiabin

优化相关策略实现

parent ed9c2d28
...@@ -21,7 +21,9 @@ public enum GalaxyErrorEnum { ...@@ -21,7 +21,9 @@ public enum GalaxyErrorEnum {
SERIES_CLAIM_SUCCESSED("NFT0010009","系列已声明成功,不允许重复声明!"), SERIES_CLAIM_SUCCESSED("NFT0010009","系列已声明成功,不允许重复声明!"),
SERIES_CLAIM_NOT_EXIST("NFT0010010","系列声明初始化信息不存在,请检查是否已上传对应素材!"), SERIES_CLAIM_NOT_EXIST("NFT0010010","系列声明初始化信息不存在,请检查是否已上传对应素材!"),
PUBLISH_ORDER_NOT_EXIST("NFT0010011","NFT购买订单不存在!"), PUBLISH_ORDER_NOT_EXIST("NFT0010011","NFT购买订单不存在!"),
NFT_BUY_TASK_NOT_EXIST("NFT0010012","NFT购买执行任务不存在"); NFT_BUY_TASK_NOT_EXIST("NFT0010012","NFT购买执行任务不存在"),
NFT_BUY_TASK_HAVE_EXIST("NFT0010013","NFT购买执行任务已存在,不可以重复购买!"),
NFT_BUY_FAIL("NFT0010014","NFT购买失败,nftId不存在!");
private String code; private String code;
private String message; private String message;
......
package com.liquidnet.service.galaxy.dto.bo; package com.liquidnet.service.galaxy.dto.bo;
import com.liquidnet.commons.lang.util.BASE64Util;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException;
/** /**
* @author AnJiabin <anjiabin@zhengzai.tv> * @author AnJiabin <anjiabin@zhengzai.tv>
...@@ -29,6 +31,26 @@ public class GalaxyUserInfoBo implements Serializable,Cloneable{ ...@@ -29,6 +31,26 @@ public class GalaxyUserInfoBo implements Serializable,Cloneable{
private String routerType; private String routerType;
private String blockChainAddress; private String blockChainAddress;
public String getUserPubKey() {
String pubKey = null;
try {
pubKey = BASE64Util.decode(userPubKey);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return pubKey;
}
public String getUserPriKey() {
String priKey = null;
try {
priKey = BASE64Util.decode(userPriKey);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return priKey;
}
@Override @Override
public String toString(){ public String toString(){
return JsonUtils.toJson(this); return JsonUtils.toJson(this);
......
package com.liquidnet.service.galaxy.router.zxin.biz; 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.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig; import com.liquidnet.common.third.zxlnft.config.ZxlnftConfig;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum; import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
...@@ -53,14 +54,18 @@ public class ZxinTradeBiz { ...@@ -53,14 +54,18 @@ public class ZxinTradeBiz {
private DataUtils dataUtils; private DataUtils dataUtils;
public ResponseDto<GalaxyNftBuyRespDto> nftBuy(GalaxyNftBuyReqDto nftBuyReqDto){ public ResponseDto<GalaxyNftBuyRespDto> nftBuy(GalaxyNftBuyReqDto nftBuyReqDto){
//获取订单信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getNftOrderPayId());
if(StringUtil.isNotNull(nftOrderBo)&&StringUtil.isNotEmpty(nftOrderBo.getNftBuyTaskId())){
return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_TASK_HAVE_EXIST.getCode(), GalaxyErrorEnum.NFT_BUY_TASK_HAVE_EXIST.getMessage());
}
//获取用户信息 //获取用户信息
GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getUserId()); GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getUserId());
//获取sku信息 //获取sku信息
GalaxySeriesInfoBo seriesInfoBo = dataUtils.getSeriesInfoBo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getSkuId()); GalaxySeriesInfoBo seriesInfoBo = dataUtils.getSeriesInfoBo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getSkuId());
//获取nftOrder信息
GalaxyNftOrderBo nftOrderBo = dataUtils.getNftOrderBo(nftBuyReqDto.getRouterType(),nftBuyReqDto.getNftOrderPayId());
//返回参数nftId //返回参数nftId
String nftId = null; String nftId = null;
...@@ -70,14 +75,21 @@ public class ZxinTradeBiz { ...@@ -70,14 +75,21 @@ public class ZxinTradeBiz {
if(StringUtil.isNotEmpty(nftId)){ if(StringUtil.isNotEmpty(nftId)){
//执行购买逻辑 //执行购买逻辑
GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusiness(nftId,userInfoBo,seriesInfoBo); GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusiness(nftBuyReqDto.getRouterType(),nftId,userInfoBo,seriesInfoBo,nftOrderBo);
return ResponseDto.success(nftBuyRespDto); return ResponseDto.success(nftBuyRespDto);
}else{ }else{
return ResponseDto.failure(GalaxyErrorEnum.PUBLISH_BUY_FAIL.getCode(), GalaxyErrorEnum.PUBLISH_BUY_FAIL.getMessage()); return ResponseDto.failure(GalaxyErrorEnum.NFT_BUY_FAIL.getCode(), GalaxyErrorEnum.NFT_BUY_FAIL.getMessage());
} }
} }
public ResponseDto<GalaxyNftPublishAndBuyRespDto> nftPublishAndBuy(GalaxyNftPublishAndBuyReqDto reqDto) { 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()); GalaxyUserInfoBo userInfoBo = dataUtils.getGalaxyUserInfo(reqDto.getRouterType(),reqDto.getUserId());
...@@ -208,7 +220,7 @@ public class ZxinTradeBiz { ...@@ -208,7 +220,7 @@ public class ZxinTradeBiz {
if(StringUtil.isNotEmpty(nftId)){ if(StringUtil.isNotEmpty(nftId)){
//执行购买逻辑 //执行购买逻辑
GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew(); GalaxyNftPublishAndBuyRespDto nftPublishAndBuyRespDto = GalaxyNftPublishAndBuyRespDto.getNew();
GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusiness(nftId,userInfoBo,seriesInfoBo); GalaxyNftBuyRespDto nftBuyRespDto = this.nftBuyBusiness(reqDto.getRouterType(),nftId,userInfoBo,seriesInfoBo,nftOrderBo);
BeanUtil.copy(nftBuyRespDto,nftPublishAndBuyRespDto); BeanUtil.copy(nftBuyRespDto,nftPublishAndBuyRespDto);
return ResponseDto.success(nftPublishAndBuyRespDto); return ResponseDto.success(nftPublishAndBuyRespDto);
}else{ }else{
...@@ -263,7 +275,7 @@ public class ZxinTradeBiz { ...@@ -263,7 +275,7 @@ public class ZxinTradeBiz {
return ResponseDto.success(resultQueryRespDto); return ResponseDto.success(resultQueryRespDto);
} }
private GalaxyNftBuyRespDto nftBuyBusiness(String nftId,GalaxyUserInfoBo userInfoBo, GalaxySeriesInfoBo seriesInfoBo){ private GalaxyNftBuyRespDto nftBuyBusiness(String routerType,String nftId,GalaxyUserInfoBo userInfoBo, GalaxySeriesInfoBo seriesInfoBo,GalaxyNftOrderBo nftOrderBo){
// 3.2.2调用购买NFT接口 // 3.2.2调用购买NFT接口
Nft043BuyReqDto nft043BuyReqDto = Nft043BuyReqDto.getNew(); Nft043BuyReqDto nft043BuyReqDto = Nft043BuyReqDto.getNew();
nft043BuyReqDto.setNftId(nftId); nft043BuyReqDto.setNftId(nftId);
...@@ -288,47 +300,22 @@ public class ZxinTradeBiz { ...@@ -288,47 +300,22 @@ public class ZxinTradeBiz {
String signature = zxlnftBiz.createSign(userInfoBo.getUserPriKey(),signMetaData); String signature = zxlnftBiz.createSign(userInfoBo.getUserPriKey(),signMetaData);
nft043BuyReqDto.setSignature(signature); nft043BuyReqDto.setSignature(signature);
String nftBuyTaskId = null;
ZxlnftResponseDto<Nft043BuyRespDto> nft043RespDto = zxlnftSdkUtil.nft043Buy(nft043BuyReqDto); ZxlnftResponseDto<Nft043BuyRespDto> nft043RespDto = zxlnftSdkUtil.nft043Buy(nft043BuyReqDto);
if(nft043RespDto.isSuccess()){ if(nft043RespDto.isSuccess()){
//3.2.4查询NFT购买结果 nftBuyTaskId = nft043RespDto.getData().getTaskId();
Nft044BuyResultReqDto nft044ReqDto = Nft044BuyResultReqDto.getNew(); }else{
nft044ReqDto.setTaskId(nft043RespDto.getData().getTaskId()); throw new LiquidnetServiceException(nft043RespDto.getCode(),nft043RespDto.getMessage());
long timeStart = System.currentTimeMillis();
ZxlnftResponseDto<Nft044BuyResultRespDto> nft044RespDto = zxlnftSdkUtil.nft044BuyResult(nft044ReqDto);
if(nft044RespDto.isSuccess()){
int count = 1;
String payTaskId = null;
while(payTaskId == null){
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
log.info("=======执行第{}次查询,taskId:{}",1,nft044ReqDto.getTaskId());
ZxlnftResponseDto<Nft044BuyResultRespDto> nft044RespDtoTemp = zxlnftSdkUtil.nft044BuyResult(nft044ReqDto);
if(nft044RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
payTaskId = nft044RespDtoTemp.getData().getPayTaskId();
}else if(nft044RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
log.info("任务执行失败!taskId:{}",nft044ReqDto.getTaskId());
return null;
}
if(count==6){
log.info("=======查询共6次,跳出循环!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);
}
}
} }
return null;
//更新缓存数据状态
nftOrderBo.setNftBuyPayTaskId(nftBuyTaskId);
dataUtils.updateNftOrderBuyTaskId(routerType,nftOrderBo.getNftOrderPayId(),nftOrderBo);
GalaxyNftBuyRespDto nftBuyRespDto = GalaxyNftBuyRespDto.getNew();
nftBuyRespDto.setUserId(userInfoBo.getUserId());
nftBuyRespDto.setNftId(null);
return nftBuyRespDto;
} }
/** /**
......
...@@ -122,4 +122,16 @@ public class DataUtils { ...@@ -122,4 +122,16 @@ public class DataUtils {
log.info("updateNftOrderInfo result:{}",result.toString()); log.info("updateNftOrderInfo result:{}",result.toString());
} }
public void updateNftOrderBuyTaskId(String routeType,String nftOrderPayId,GalaxyNftOrderBo nftOrderBo) {
redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_TRADE.concat(routeType).concat(":") + nftOrderPayId,nftOrderBo,keyExpireTime);
Query query = Query.query(Criteria.where("nftOrderPayId").is(nftOrderPayId));
Update update = Update.fromDocument(Document.parse(JsonUtils.toJson(nftOrderBo)));
update.set("nftBuyTaskId", nftOrderBo.getNftBuyTaskId());
String nowTimeStr = DateUtil.Formatter.yyyyMMddHHmmss.format(LocalDateTime.now());
update.set("updatedAt",nowTimeStr);
UpdateResult result = mongoTemplate.updateFirst(query,update, GalaxyNftOrderBo.class,GalaxyNftOrderBo.class.getSimpleName());
log.info("updateNftOrderInfo result:{}",result.toString());
}
} }
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