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

Commit 66476459 authored by anjiabin's avatar anjiabin

实现zxtnft购买功能

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