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

Commit 77a1e8fa authored by anjiabin's avatar anjiabin

实现xuper相关艺术品上传

parent ac94ca6a
......@@ -39,6 +39,11 @@ public class GalaxySeriesNftUploadBo implements Serializable,Cloneable {
*/
private String displayUrl;
/**
* nft介质hash值
*/
private String nftHashStr;
/**
* 创建时间
*/
......
package com.liquidnet.service.galaxy;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.ArrayList;
import java.util.List;
public class MybatisPlusCodeGenerator {
/**
* @param moduleRootPath 项目模块根路径 到 /src 之前 ex:E:\projects\trlabs-bus-v1\trlabs-bus-service\trlabs-common\trlabs-mybatis
* @param dsc 数据源
* @param parentName 相当于业务模块名 com.liquidnet.service.adam 全限定类名
* @param tableNames 表名
*/
public static void doGenerator(String moduleRootPath,
DataSourceConfig dsc,
String parentName,
String[] tableNames) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置BankMybatisPlusCodeGenerator
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(moduleRootPath + "/src/main/java");
gc.setAuthor("liquidnet");
gc.setOpen(false);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent(parentName);
mpg.setPackageInfo(pc);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
// 如果模板引擎是 freemarker
String templatePath = "/templates/mapper.xml.ftl";
// 自定义输出配置
List<FileOutConfig> focList = new ArrayList<>();
// 自定义配置会被优先输出
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return moduleRootPath + "/src/main/resources/com/liquidnet/service/galaxy/mapper/" + pc.getModuleName()
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setInclude(tableNames);
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
public static void main(String[] args) {
DataSourceConfig dsc = new DataSourceConfig();
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUrl("jdbc:mysql://39.107.71.112:3308/dev_ln_scene?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=CST");
dsc.setUsername("root");
dsc.setPassword("Zhengzai@rd2U#");
String resourcePath = "/Users/anjiabin/Downloads/tmp";
String directory = "com.liquidnet.service.galaxy";
String[] dbTableArray = new String[]{"galaxy_user_info", "galaxy_series_info", "galaxy_series_nft_info","galaxy_nft_order_info", "galaxy_nft_trade_info","galaxy_nft_order_fail_log"};
doGenerator(resourcePath, dsc, directory, dbTableArray);
}
}
package com.liquidnet.service.galaxy.router.xuper.biz;
import com.baidu.xuper.crypto.Hash;
import com.baidu.xasset.auth.Crypto;
import com.baidu.xasset.client.base.Base;
import com.baidu.xuper.api.Account;
import com.liquidnet.common.third.xuper.config.XuperConfig;
import com.liquidnet.common.third.xuper.constant.XuperEnum;
import com.liquidnet.common.third.xuper.dto.*;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.xuper.util.XuperSdkUtil;
import com.liquidnet.common.third.zxlnft.biz.ZxlnftBiz;
import com.liquidnet.common.third.zxlnft.constant.ZxlnftEnum;
import com.liquidnet.common.third.zxlnft.exception.ZxlNftException;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
......@@ -45,8 +45,6 @@ import java.time.LocalDateTime;
@Slf4j
@Component
public class XuperArtworkBiz {
@Autowired
private ZxlnftBiz zxlnftBiz;
@Autowired
private XuperSdkUtil xuperSdkUtil;
......@@ -95,7 +93,7 @@ public class XuperArtworkBiz {
galaxyNftUploadRespDto.setOriginalNftUrl(reqDto.getOriginalNftUrl());
galaxyNftUploadRespDto.setDisplayUrl(this.getFullFilePath(seriesName,originalDisplayUrl));
galaxyNftUploadRespDto.setOriginalDisplayUrl(reqDto.getOriginalDisplayUrl());
} catch(ZxlNftException e){
} catch(XupterException e){
log.error(e.getMessage());
return ResponseDto.failure(e.getCode(),e.getMessage());
}catch (Exception e) {
......@@ -160,13 +158,17 @@ public class XuperArtworkBiz {
String nftUrl = reqDto.getNftUrl();
//该文件只为了生成hash值
String originalNftUrl = seriesNftUploadBo.getOriginalNftUrl();
String nftHashStr = this.getNftHashByNftUrl(originalNftUrl);
//设置nft的hash值
seriesNftUploadBo.setNftHashStr(nftHashStr);
String displlayUrl = reqDto.getDisplayUrl();
try {
xuper002CreateAssetReqDto.setMnemonic(xuperConfig.getNftPlatformMnemonic());
//资产碎片数量,小于1和大于200000代表不做库存限制
xuper002CreateAssetReqDto.setAmount(totalCount.intValue());
//藏品显示售卖价格,单位为分
xuper002CreateAssetReqDto.setPrice(Long.parseLong(reqDto.getSellCount()));
xuper002CreateAssetReqDto.setPrice(new BigDecimal(reqDto.getSellCount()).multiply(BigDecimal.valueOf(100l)).longValue());
//资产分类。1:艺术品 2:收藏品 3:门票 4:酒店
xuper002CreateAssetReqDto.setAssetCate(Integer.valueOf(XuperEnum.assetTypeEnum.COLLECTION.getCode()));
//资产名称,小于30个字节
......@@ -188,7 +190,7 @@ public class XuperArtworkBiz {
//(可选)业务侧用户标记,必要时请安全处理后设置
xuper002CreateAssetReqDto.setUserId(0l);
//(可选)要存证的资产文件sm3散列值,如有多个文件逐个计算hash值后合并计算最终hash值
xuper002CreateAssetReqDto.setFileHash(this.getNftHashByNftUrl(originalNftUrl));
xuper002CreateAssetReqDto.setFileHash(nftHashStr);
//执行数字资产创建
XuperResponseDto<Xuper002CreateAssetRespDto> xuperResponseDto = xuperSdkUtil.xuper002CreateAsset(xuper002CreateAssetReqDto);
......@@ -207,9 +209,10 @@ public class XuperArtworkBiz {
String taskId = null;
seriesClaimRespDto = GalaxyArtSeriesClaimRespDto.getNew();
if(xuper002CreateAssetRespDto.errNo==0){
if(StringUtil.isNotNull(xuper002CreateAssetRespDto)&&xuper002CreateAssetRespDto.errNo==0){
//第零个系列 无限制系列
taskId = String.valueOf(xuper002CreateAssetRespDto.getAssetId());
seriesId = String.valueOf(xuper002CreateAssetRespDto.getAssetId());
//构造缓存数据
if(StringUtil.isNull(seriesInfoBo)){
//
......@@ -222,6 +225,8 @@ public class XuperArtworkBiz {
//等一个系列支持多个藏品后需要从请求参数获取
seriesInfoBo.setSeriesName(seriesName);
seriesInfoBo.setSeriesCode(seriesCode);
seriesInfoBo.setSeriesId(seriesId);
seriesInfoBo.setSeriesClaimTaskId(taskId);
dataUtils.setSeriesInfoBo(reqDto.getRouterType(),seriesCode,seriesInfoBo);
//构造系列nft信息
......@@ -230,7 +235,7 @@ public class XuperArtworkBiz {
if(StringUtil.isEmpty(seriesNftInfoBo.getNftHash())){
log.error("生成nftHash error skuId:{} nftUrl is :{} ",seriesNftInfoBo.getSkuId(),seriesNftInfoBo.getNftUrl());
throw new ZxlNftException(GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getCode(),GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getMessage());
throw new XupterException(GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getCode(),GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getMessage());
}
}
}else{
......@@ -243,7 +248,7 @@ public class XuperArtworkBiz {
seriesClaimRespDto.setSeriesId(seriesId);
seriesClaimRespDto.setSeriesName(seriesName);
}catch(ZxlNftException e){
}catch(XupterException e){
sysFailDesc = e.getMessage();
log.error(e.getMessage(),e);
}catch(Exception e){
......@@ -270,8 +275,13 @@ public class XuperArtworkBiz {
//如果nftUrl介质hash为空,则重新生成
if(StringUtil.isEmpty(seriesNftInfoBo.getNftHash())){
//更新系列对应的系列nft状态
seriesNftInfoBo.setNftHash(zxlnftBiz.getHashString(seriesNftInfoBo.getNftUrl()));
//根据skuId获取原始上传信息
GalaxySeriesNftUploadBo seriesNftUploadBo = dataUtils.getSeriesNftUploadBo(reqDto.getRouterType(),reqDto.getSkuId());
if(StringUtil.isNull(seriesNftUploadBo)){
return ResponseDto.failure(GalaxyErrorEnum.SERIES_CLAIM_NOT_EXIST.getCode(),GalaxyErrorEnum.SERIES_CLAIM_NOT_EXIST.getMessage());
}
String originalNftUrl = seriesNftUploadBo.getOriginalNftUrl();
seriesNftInfoBo.setNftHash(this.getNftHashByNftUrl(originalNftUrl));
dataUtils.updateSeriesNftStatus(reqDto.getRouterType(),reqDto.getSkuId(),seriesNftInfoBo);
}
......@@ -281,7 +291,7 @@ public class XuperArtworkBiz {
return ResponseDto.failure(GalaxyErrorEnum.SERIES_NOT_EXIST.getCode(), GalaxyErrorEnum.SERIES_NOT_EXIST.getMessage());
}
if(seriesInfoBo.getSeriesClaimStatus().equalsIgnoreCase(GalaxyEnum.SeriesClaimStatusEnum.SUCCESS.getCode())){
GalaxyArtSeriesClaimResultQueryRespDto resultQueryRespDto = this.buildGalaxyArtSeriesClaimResultQueryRespDto(reqDto,seriesInfoBo,ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode());
GalaxyArtSeriesClaimResultQueryRespDto resultQueryRespDto = this.buildGalaxyArtSeriesClaimResultQueryRespDto(reqDto,seriesInfoBo, ZxlnftEnum.TaskStatusEnum.TASK_SUCCESS.getCode());
return ResponseDto.success(resultQueryRespDto);
}
......@@ -421,7 +431,13 @@ public class XuperArtworkBiz {
} catch (IOException e) {
e.printStackTrace();
}
nftHashStr = new String(Hash.doubleSha256(fileByte));
try {
Account account = xuperSdkUtil.getAccount(xuperConfig.getNftPlatformMnemonic());
nftHashStr = Crypto.xassetSignECDSA(account,fileByte);
} catch (Exception var25) {
Base.logger.warning("account esdsa sign failed" + var25);
throw new XupterException(GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getCode(),GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getMessage());
}
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
......@@ -481,7 +497,7 @@ public class XuperArtworkBiz {
seriesNftInfoBo.setNftFlag(reqDto.getNftFlag());
BigDecimal sellCount = new BigDecimal(reqDto.getSellCount()).multiply(BigDecimal.valueOf(100l)); //积分
seriesNftInfoBo.setSellCount(sellCount);
seriesNftInfoBo.setNftHash(zxlnftBiz.getHashString(reqDto.getNftUrl()));
seriesNftInfoBo.setNftHash(seriesNftUploadBo.getNftHashStr());
seriesNftInfoBo.setRouterType(reqDto.getRouterType());
seriesNftInfoBo.setCreatedAt(LocalDateTime.now());
return seriesNftInfoBo;
......
package com.liquidnet.service.goblin.test.xuper;
import com.baidu.xasset.auth.Crypto;
import com.baidu.xasset.client.base.Base;
import com.baidu.xuper.api.Account;
import com.liquidnet.common.third.xuper.config.XuperConfig;
import com.liquidnet.common.third.xuper.exception.XupterException;
import com.liquidnet.common.third.xuper.util.XuperSdkUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.galaxy.biz.GalaxyCommonBiz;
import com.liquidnet.service.galaxy.constant.GalaxyErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.io.IOException;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestUrlHash
* @Package com.liquidnet.service.goblin.test.xuper
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/6/29 16:10
*/
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class TestUrlHash {
@Autowired
private GalaxyCommonBiz galaxyCommonBiz;
@Autowired
private XuperSdkUtil xuperSdkUtil;
@Autowired
private XuperConfig xuperConfig;
@Test
public void testGetNftHashByNftUrl(){
String url = "https://zhixinliantest-1302317679.cos.ap-guangzhou.myqcloud.com/nft/4e40d5f6f65aa8ec9bc33ab424e0167e68783bbe95d4d265086314d749808eef/ZXLNFTIMAGE202202241512003609141721.jpg";
log.info("hash === {} ",this.getNftHashByNftUrl(url));
}
private String getNftHashByNftUrl(String originalUrl){
//原始介质文件hash值
String nftHashStr = null;
try {
String filePath = null;
String imageType = null;
if(originalUrl.lastIndexOf("?")!=-1){
String tempUrl = originalUrl.substring(0,originalUrl.lastIndexOf("?"));
imageType = tempUrl.substring(tempUrl.lastIndexOf("."),tempUrl.length());
}else{
imageType = originalUrl.substring(originalUrl.lastIndexOf("."),originalUrl.length());
}
String fileName = IDGenerator.getXuperNftImageCosCode() + imageType;
//通过图片url地址上传
File cosFile = galaxyCommonBiz.inputStreamToFile(originalUrl,fileName);
filePath = cosFile.getPath();
log.info("cosFile.getPath() :{}",cosFile.getPath());//Users/anjiabin/data/galaxy/tempFilePath/XUPERNFTIMAGE202206291056041871343690.jpg
log.info("cosFile.getAbsoluteFile() :{}",cosFile.getAbsoluteFile());///Users/anjiabin/mdsky_gitlab/liquidnet-bus-v1/Users/anjiabin/data/galaxy/tempFilePath/XUPERNFTIMAGE202206291056041871343690.jpg
byte[] fileByte = new byte[0];
try {
fileByte = galaxyCommonBiz.toByteArray(new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
try {
Account account = xuperSdkUtil.getAccount(xuperConfig.getNftPlatformMnemonic());
nftHashStr = Crypto.xassetSignECDSA(account,fileByte);
} catch (Exception var25) {
Base.logger.warning("account esdsa sign failed" + var25);
throw new XupterException(GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getCode(),GalaxyErrorEnum.SERIES_NFT_HASH_CREATE_FAIL.getMessage());
}
// nftHashStr = new String(Hash.doubleSha256(fileByte));
}catch (XupterException e) {
log.error("biz error msg "+e.getMessage(),e);
}catch (Exception e) {
log.error("sys error msg "+e.getMessage(),e);
}
log.info("getNftHashByNftUrl url:{} ,hashStr:{}",originalUrl,nftHashStr);
return nftHashStr;
}
}
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