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

Commit 66476459 authored by anjiabin's avatar anjiabin

实现zxtnft购买功能

parent a5f2e117
......@@ -11,8 +11,9 @@ package com.liquidnet.service.galaxy.constant;
*/
public class GalaxyConstant {
public static final String REDIS_KET_GALAXY_USER="galaxy:user:";
public static final String REDIS_KET_GALAXY_ART_SERIES="galaxy:series:";
public static final String SERIES_STORE_NAME="NOW_ZXL_NFT_PIC";// 系列存储目录名称
public static final String REDIS_KET_GALAXY_SERIES="galaxy:series:";
public static final String SERIES_NAME_PREFIX="NOW_ZXL_";// 系列存储目录名称和系列声明
public enum RouterTypeEnum{
ZXINCHAIN("zxinchain","至信链"),
......@@ -31,6 +32,26 @@ public class GalaxyConstant {
}
}
/**
* 路由业务枚举
*/
public enum SeriesClaimStatusEnum{
PROCESSING("processing","系列声明中"),
SUCCESS ("success","系列声明成功"),
FAIL ("fail","系列声明失败");
private String code;
private String message;
SeriesClaimStatusEnum(String code, String message) {
this.code = code;
this.message = message;
}
public String getCode() {
return code;
}
}
/**
* 路由业务枚举
*/
......
......@@ -16,10 +16,24 @@ import java.io.Serializable;
*/
@Data
public class GalaxySeriesInfoBo implements Serializable,Cloneable {
/**
* 本地系列唯一标识id
*/
private String skuId;
/**
* 系列名称
*/
private String seriesName;
/**
* 区块链上系列ID
*/
private String seriesId;
private Long totalCount;
private Long crtCount;
private String nftUrl;
private String publishStatus;
@Override
public String toString(){
......
......@@ -23,7 +23,23 @@ public class GalaxyNftUploadReqDto extends GalaxyBaseReqDto implements Serializa
private String imageUrl;
@ApiModelProperty(position = 2, required = true, value = "商品唯一规格ID")
private String skuID;
private String skuId;
/**
* 系列一共有多少个,0表示没有限制
*/
@ApiModelProperty(position = 2, required = true, value = "商品唯一规格ID")
private Long totalCount;
/**
* 系列封面url,不超过1024个字符
*/
@ApiModelProperty(position = 2, required = true, value = "商品唯一规格ID")
private String coverUrl;
/**
* 系列描述信息,不超过500个字符
*/
@ApiModelProperty(position = 2, required = true, value = "商品唯一规格ID")
private String desc;
@Override
......
......@@ -15,7 +15,10 @@ import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.galaxy.constant.GalaxyConstant;
import com.liquidnet.service.galaxy.dto.bo.GalaxySeriesInfoBo;
import com.liquidnet.service.galaxy.dto.param.*;
import com.liquidnet.service.galaxy.utils.DataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -52,6 +55,9 @@ public class ZxinArtworkBiz {
@Autowired
private ZxlnftConfig zxlnftConfig;
@Autowired
private DataUtils dataUtils;
@Value("${liquidnet.galaxy.temp-file-path:/Users/anjiabin/mdsky_gitlab/galaxy/tempFilePath}")
private String tempFilePath;
......@@ -71,9 +77,11 @@ public class ZxinArtworkBiz {
public ResponseDto<GalaxyNftUploadRespDto> nftUpload(GalaxyNftUploadReqDto reqDto) {
String imageUrl = reqDto.getImageUrl();
String seriesName = "NOW_ZXL_NFT_PIC_skuId002"; //系列名字 skuId
String filePath = "/Users/anjiabin/Downloads/myFileTemp/zxl_image_test_001.jpg";
String fileName = IDGenerator.getZxlNftImageCosCode() +".jpg";
//上传系列名只用来目录区分
String seriesName = GalaxyConstant.SERIES_NAME_PREFIX + reqDto.getSkuId(); //素材存储目录
String filePath = null;
String imageType = imageUrl.substring(imageUrl.lastIndexOf("."),imageUrl.length());
String fileName = IDGenerator.getZxlNftImageCosCode() + imageType;
//通过图片url地址上传
File cosFile = this.inputStreamToFile(reqDto.getImageUrl(),fileName);
......@@ -85,14 +93,6 @@ public class ZxinArtworkBiz {
String fullFilePath = null; //需要保存,返回给调用者
String seriesId = null;
// 1.4.1调用图片内容检测接口
Nft008QueryImageModerationReqDto nft008ReqDto = Nft008QueryImageModerationReqDto.getNew();
nft008ReqDto.setImageUrl(imageUrl);
ZxlnftResponseDto<Nft008QueryImageModerationRespDto> nft008RespDto = zxlnftSdkUtil.nft008QueryImageModeration(nft008ReqDto);
if(!nft008RespDto.getData().getSuggestion().equals(ZxlnftEnum.SuggestionEnum.PASS.getCode())){
throw new ZxlNftException(ZxlErrorEnum.IMAGE_CHECK_ERROR.getCode(),ZxlErrorEnum.IMAGE_CHECK_ERROR.getMsg());
}
// 1.4.2调用生成素材上传临时密钥接口
Nft022UploadSecretReqDto nft022ReqDto = Nft022UploadSecretReqDto.getNew();
nft022ReqDto.setSeriesName(seriesName);
......@@ -127,6 +127,8 @@ public class ZxinArtworkBiz {
log.info("完整的素材访问fullFilePath url:{}",fullFilePath);
//进行系列声明
GalaxyNftUploadRespDto galaxyNftUploadRespDto = GalaxyNftUploadRespDto.getNew();
galaxyNftUploadRespDto.setMaterialAccessUrl(fullFilePath);
return ResponseDto.success(galaxyNftUploadRespDto);
......@@ -140,61 +142,85 @@ public class ZxinArtworkBiz {
}
public ResponseDto<GalaxyArtSeriesClaimRespDto> seriesClaim(GalaxyArtSeriesClaimReqDto reqDto) {
String skuId = reqDto.getSkuId();
String seriesName = GalaxyConstant.SERIES_NAME_PREFIX.concat(skuId);
String nftUrl = reqDto.getCoverUrl();
Long totalCound = reqDto.getTotalCount();
String desc = reqDto.getDesc();
//返回参数
String seriesId = null;
String taskId = null;
/**
* 进行系列声明
*/
// Nft030SeriesClaimReqDto nft030ReqDto = Nft030SeriesClaimReqDto.getNew();
// nft030ReqDto.setPubKey(zxlnftConfig.getNftPlatformPubKey());
// nft030ReqDto.setSeriesName(seriesName);
// //无限制系列 设置为0
// nft030ReqDto.setTotalCount(0l);
// nft030ReqDto.setOperateId(IDGenerator.get32UUID());
// //系列封面
// nft030ReqDto.setCoverUrl("https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg");
// nft030ReqDto.setDesc("系列描述信息不超过500字符");
// nft030ReqDto.setMaxPublishCount(0);
// nft030ReqDto.setSeriesBeginFromZero(false);
// ZxlnftResponseDto<Nft030SeriesClaimRespDto> nft30RespDto = zxlnftSdkUtil.nft030SeriesClaim(reqDto);
//
// //{"taskId":"49d1cccc-e62c-40bc-923c-bfac31325351_nft-series-claim_1"}
// if(nft30RespDto.isSuccess()){
// //系列声明结果查询
// Nft031SeriesClaimResultReqDto nft031ReqDto = Nft031SeriesClaimResultReqDto.getNew();
// //第零个系列 无限制系列
// nft031ReqDto.setTaskId(nft30RespDto.getData().getTaskId());
//
// int count = 0;
// while(StringUtil.isEmpty(seriesId)){
// //休眠1秒钟,等待执行结果
// try {
// Thread.sleep(1000l);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// count++;
// log.info("=======执行第{}次查询,taskId:{}",count,nft031ReqDto.getTaskId());
// ZxlnftResponseDto<Nft031SeriesClaimResultRespDto> nft031RespDtoTemp = zxlnftSdkUtil.nft031SeriesClaimResult(nft031ReqDto);
// if(nft031RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
// seriesId = nft031RespDtoTemp.getData().getSeriesId();
// break;
// }else if(nft031RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
// log.info("任务执行失败!taskId:{}",nft031ReqDto.getTaskId());
// break;
// }
//
// if(count==6){
// log.info("=======查询共6次,跳出循环!taskId:{}",nft031ReqDto.getTaskId());
// break;
// }
// }
//
// log.info("系列声明结果查询 seriesId :{}",seriesId);
// }
Nft030SeriesClaimReqDto nft030ReqDto = Nft030SeriesClaimReqDto.getNew();
nft030ReqDto.setPubKey(zxlnftConfig.getNftPlatformPubKey());
nft030ReqDto.setSeriesName(seriesName);
//无限制系列 设置为0
nft030ReqDto.setTotalCount(totalCound);
nft030ReqDto.setOperateId(IDGenerator.get32UUID());
//系列封面
nft030ReqDto.setCoverUrl(nftUrl);
nft030ReqDto.setDesc(desc);
nft030ReqDto.setMaxPublishCount(0);
nft030ReqDto.setSeriesBeginFromZero(false);
ZxlnftResponseDto<Nft030SeriesClaimRespDto> nft30RespDto = zxlnftSdkUtil.nft030SeriesClaim(nft030ReqDto);
//{"taskId":"49d1cccc-e62c-40bc-923c-bfac31325351_nft-series-claim_1"}
if(nft30RespDto.isSuccess()){
//系列声明结果查询
Nft031SeriesClaimResultReqDto nft031ReqDto = Nft031SeriesClaimResultReqDto.getNew();
//第零个系列 无限制系列
taskId = nft30RespDto.getData().getTaskId();
nft031ReqDto.setTaskId(taskId);
int count = 0;
while(StringUtil.isEmpty(seriesId)){
//休眠1秒钟,等待执行结果
try {
Thread.sleep(1000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
log.info("=======执行第{}次查询,taskId:{}",count,nft031ReqDto.getTaskId());
ZxlnftResponseDto<Nft031SeriesClaimResultRespDto> nft031RespDtoTemp = zxlnftSdkUtil.nft031SeriesClaimResult(nft031ReqDto);
if(nft031RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode())){
seriesId = nft031RespDtoTemp.getData().getSeriesId();
break;
}else if(nft031RespDtoTemp.getData().getTaskStatus().toString().equals(ZxlnftEnum.TaskStatusEnum.TASK_FAIL.getCode())){
log.info("任务执行失败!taskId:{}",nft031ReqDto.getTaskId());
break;
}
if(count==6){
log.info("=======查询共6次,跳出循环!taskId:{}",nft031ReqDto.getTaskId());
break;
}
}
log.info("系列声明结果查询 seriesId :{}",seriesId);
}
GalaxySeriesInfoBo seriesInfoBo = GalaxySeriesInfoBo.getNew();
//构造缓存数据
if(seriesInfoBo==null){
seriesInfoBo = GalaxySeriesInfoBo.getNew();
seriesInfoBo.setSkuId(skuId);
seriesInfoBo.setSeriesName(seriesName);
seriesInfoBo.setSeriesId(seriesId);
seriesInfoBo.setTotalCount(totalCound);
seriesInfoBo.setCrtCount(0l);
seriesInfoBo.setPublishStatus(GalaxyConstant.SeriesClaimStatusEnum.PROCESSING.getCode());
seriesInfoBo.setNftUrl(nftUrl);
dataUtils.setSeriesInfoBo(reqDto.getRouteType(),reqDto.getSkuId(),seriesInfoBo);
}
return null;
}
/**
* 大美 通过URL上传
*
......
......@@ -39,12 +39,12 @@ public class DataUtils {
}
}
public void setSeriesInfoBo(String routeType,String userId, GalaxyUserInfoBo userInfoBo) {
redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_USER.concat(routeType).concat(":") + userId,userInfoBo,keyExpireTime);
public void setSeriesInfoBo(String routeType,String skuId, GalaxySeriesInfoBo seriesInfoBo) {
redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_SERIES.concat(routeType).concat(":") + skuId,seriesInfoBo,keyExpireTime);
}
public GalaxySeriesInfoBo getSeriesInfoBo(String routeType, String skuId) {
Object obj = redisUtil.get(GalaxyConstant.REDIS_KET_GALAXY_ART_SERIES.concat(routeType).concat(":") + skuId);
Object obj = redisUtil.get(GalaxyConstant.REDIS_KET_GALAXY_SERIES.concat(routeType).concat(":") + skuId);
if(obj!=null){
return (GalaxySeriesInfoBo) obj;
}else {
......@@ -52,7 +52,7 @@ public class DataUtils {
if (seriesInfoBo == null) {
return null;
}
redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_ART_SERIES.concat(routeType).concat(":") + skuId, seriesInfoBo);
redisUtil.set(GalaxyConstant.REDIS_KET_GALAXY_SERIES.concat(routeType).concat(":") + skuId, seriesInfoBo);
return seriesInfoBo;
}
}
......
......@@ -26,6 +26,13 @@ public class TestZxlnftBiz {
@Autowired
private ZxlnftBiz zxlnftBiz;
@Test
public void getImageType(){
String url = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
String imageType = url.substring(url.lastIndexOf("."),url.length());
System.out.println(imageType);
}
@Test
public void buildHeader(){
MultiValueMap<String, String> commonHeader = new LinkedMultiValueMap();
......
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