Commit 675d9604 authored by tangtuo's avatar tangtuo

修改nft上链逻辑

新增查询所有主题接口
parent f5a76b3d
package com.fzm.common.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* @author tangtuo
* @date 2021/7/8 16:26
*/
@Data
@TableName("tb_label")
public class Label {
@TableId(type = IdType.AUTO)
private Integer id;
private String name;
}
package com.fzm.common.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* @author tangtuo
* @date 2021/7/8 16:04
*/
@Data
public class NftDto {
@NotNull(message = "nft主键不能为空")
@ApiModelProperty("nft主键")
private Integer id;
@NotBlank(message = "nft哈希不能为空")
@ApiModelProperty("nft哈希")
private String fileHash;
@NotBlank(message = "nft编号不能为空")
@ApiModelProperty("nft编号")
private String nftId;
@NotBlank(message = "发行人地址不能为空")
@ApiModelProperty("发行人地址")
private String wallet;
}
package com.fzm.common.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Label;
import org.apache.ibatis.annotations.Mapper;
/**
* @author tangtuo
* @date 2021/7/1 14:35
*/
@Mapper
public interface LabelMapper extends BaseMapper<Label> {
}
package com.fzm.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Label;
/**
* @author tangtuo
* @date 2021/7/1 14:35
*/
public interface LabelService extends IService<Label> {
}
...@@ -2,6 +2,7 @@ package com.fzm.common.service; ...@@ -2,6 +2,7 @@ package com.fzm.common.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.fzm.common.entity.Nft; import com.fzm.common.entity.Nft;
import com.fzm.common.entity.NftDto;
import com.fzm.common.entity.vo.CollectionNftVo; import com.fzm.common.entity.vo.CollectionNftVo;
import com.fzm.common.entity.vo.NftListVo; import com.fzm.common.entity.vo.NftListVo;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -14,12 +15,12 @@ import java.util.List; ...@@ -14,12 +15,12 @@ import java.util.List;
*/ */
public interface NftService extends IService<Nft> { public interface NftService extends IService<Nft> {
/** /**
* 发行nft * 保存nft基本信息
* *
* @param nft * @param nft
* @return * @return
*/ */
Nft publish(Nft nft); NftDto saveNft(Nft nft);
/** /**
* 查看nft列表 * 查看nft列表
...@@ -117,4 +118,12 @@ public interface NftService extends IService<Nft> { ...@@ -117,4 +118,12 @@ public interface NftService extends IService<Nft> {
* @param id * @param id
*/ */
void download(Integer id); void download(Integer id);
/**
* 发行nft
*
* @param nftDto
* @return
*/
Boolean publish(NftDto nftDto);
} }
package com.fzm.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Label;
import com.fzm.common.mapper.CategoryMapper;
import com.fzm.common.mapper.LabelMapper;
import com.fzm.common.service.CategoryService;
import com.fzm.common.service.LabelService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author tangtuo
* @date 2021/7/1 14:36
*/
@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements LabelService {
}
...@@ -10,10 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -10,10 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.common.constant.RedisConstant; import com.fzm.common.constant.RedisConstant;
import com.fzm.common.constant.SystemConstant; import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.BaseEntity; import com.fzm.common.entity.*;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.User;
import com.fzm.common.entity.vo.CollectionNftVo; import com.fzm.common.entity.vo.CollectionNftVo;
import com.fzm.common.entity.vo.NftListVo; import com.fzm.common.entity.vo.NftListVo;
import com.fzm.common.enums.ResultCode; import com.fzm.common.enums.ResultCode;
...@@ -68,26 +65,41 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -68,26 +65,41 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
private String contractName; private String contractName;
@Override @Override
public Nft publish(Nft nft) { public NftDto saveNft(Nft nft) {
User user = userService.getById(StpUtil.getLoginIdAsInt()); User user = userService.getById(StpUtil.getLoginIdAsInt());
// 如果用户是第一次发行作品,把用户的isPublish修改成1 // 如果用户是第一次发行作品,把用户的isPublish修改成1
if (SystemConstant.BOOLEAN_DATA_FALSE.equals(user.getIsPublish())) { if (SystemConstant.BOOLEAN_DATA_FALSE.equals(user.getIsPublish())) {
User u = new User().setId(user.getId()).setIsPublish(SystemConstant.BOOLEAN_DATA_TRUE); User u = new User().setId(user.getId()).setIsPublish(SystemConstant.BOOLEAN_DATA_TRUE);
userService.updateById(u); userService.updateById(u);
} }
save(nft);
NftDto nftDto = new NftDto();
// 获取用户的钱包地址 // 获取用户的钱包地址
String wallet = user.getWallet(); String wallet = user.getWallet();
nftDto.setNftId(generateNftId(nft.getCategoryId()));
nftDto.setWallet(wallet);
nftDto.setId(nft.getId());
nftDto.setFileHash(nft.getFileHash());
return nftDto;
/*
*/
}
@Override
public Boolean publish(NftDto nftDto) {
// 获取用户的私钥 // 获取用户的私钥
String privkey = paraChainClient.walletDumpPrivkey(wallet); User user = userService.getById(StpUtil.getLoginIdAsInt());
String wallet = user.getWallet();
String privkey = paraChainClient.walletDumpPrivkey(user.getWallet());
String txHash = paraChainClient.evmPublishNFT1155(contractName, wallet, privkey, 1, true); String txHash = paraChainClient.evmPublishNFT1155(contractName, wallet, privkey, 1, true);
if (StringUtils.isBlank(txHash) || !txHash.contains("-")) { if (StringUtils.isBlank(txHash) || !txHash.contains("-")) {
throw GlobalException.newException(ResultCode.FAILED, "nft发行失败"); throw GlobalException.newException(ResultCode.FAILED, "nft发行失败");
} }
String[] split = txHash.split("-"); String[] split = txHash.split("-");
long tokenId = Long.parseLong(split[1]); long tokenId = Long.parseLong(split[1]);
nft.setNftHash(split[0]); Nft nft = getById(nftDto.getId());
nft.setTokenId(tokenId);
nft.setPublishTime(new Date());
// 构建上链信息 // 构建上链信息
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("author", nft.getAuthor()); map.put("author", nft.getAuthor());
...@@ -99,8 +111,11 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -99,8 +111,11 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
if (StringUtils.isBlank(tradeHash)) { if (StringUtils.isBlank(tradeHash)) {
throw GlobalException.newException(ResultCode.FAILED, "nft发行失败"); throw GlobalException.newException(ResultCode.FAILED, "nft发行失败");
} }
save(nft); nft.setNftHash(split[0]);
return getById(nft.getId()); nft.setTokenId(tokenId);
nft.setPublishTime(new Date());
nft.setNftId(nftDto.getNftId());
return updateById(nft);
} }
@Override @Override
......
package com.fzm.portal.controller;
import com.fzm.common.entity.Category;
import com.fzm.common.entity.Label;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.CategoryService;
import com.fzm.common.service.LabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @author tangtuo
* @date 2021/7/1 14:37
*/
@RestController
@RequestMapping(value = "/label")
@Api(tags = "主题管理")
public class LabelController {
@Resource
private LabelService labelService;
@GetMapping("/list")
@ApiOperation(value = "查询所有主题信息")
public ResponseModel<List<Label>> list() {
return ResponseModel.success(labelService.list());
}
}
...@@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil; ...@@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.fzm.common.constant.SystemConstant; import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.Nft; import com.fzm.common.entity.Nft;
import com.fzm.common.entity.NftDto;
import com.fzm.common.entity.User; import com.fzm.common.entity.User;
import com.fzm.common.entity.vo.CollectionNftVo; import com.fzm.common.entity.vo.CollectionNftVo;
import com.fzm.common.entity.vo.NftCertificateVo; import com.fzm.common.entity.vo.NftCertificateVo;
...@@ -20,6 +21,7 @@ import com.fzm.common.utils.QRCodeUtil; ...@@ -20,6 +21,7 @@ import com.fzm.common.utils.QRCodeUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -55,13 +57,13 @@ public class NftController { ...@@ -55,13 +57,13 @@ public class NftController {
* 存证二维码跳转地址 * 存证二维码跳转地址
* todo 修改成动态前端路由 * todo 修改成动态前端路由
*/ */
private static final String path = "https://chain.33.cn/document/60"; private static final String PATH = "https://chain.33.cn/document/60";
@SaCheckLogin @SaCheckLogin
@PostMapping("/publish") @PostMapping("/save")
@ApiOperation(value = "nft发行") @ApiOperation(value = "nft基本信息保存(基本信息和加密上链两个步骤)")
public ResponseModel<Nft> publish(@ApiParam(value = "类目id", required = true) Integer categoryId, public ResponseModel<NftDto> save(@ApiParam(value = "类目id", required = true) Integer categoryId,
@ApiParam(value = "名称", required = true) String name, @ApiParam(value = "名称", required = true) String name,
@ApiParam(value = "作者", required = true) String author, @ApiParam(value = "作者", required = true) String author,
@ApiParam(value = "主题", required = true) String theme, @ApiParam(value = "主题", required = true) String theme,
...@@ -69,8 +71,7 @@ public class NftController { ...@@ -69,8 +71,7 @@ public class NftController {
@ApiParam(value = "文件", required = false) MultipartFile file, @ApiParam(value = "文件", required = false) MultipartFile file,
@ApiParam(value = "文件hash", required = true) String fileHash, @ApiParam(value = "文件hash", required = true) String fileHash,
@ApiParam(value = "平台存档 0-不存档 1-加密存档", required = true) Integer isArchives, @ApiParam(value = "平台存档 0-不存档 1-加密存档", required = true) Integer isArchives,
@ApiParam(value = "授权阅读 0-不需要授权 1-需要授权", required = false) Integer isGrant, @ApiParam(value = "授权阅读 0-不需要授权 1-需要授权", required = false) Integer isGrant) throws IOException {
@ApiParam(value = "nft编号", required = true) String nftId) throws IOException {
Nft nft = new Nft(); Nft nft = new Nft();
// 当平台存档选择加密存档时,文件必传 // 当平台存档选择加密存档时,文件必传
if (SystemConstant.BOOLEAN_DATA_TRUE.equals(isArchives)) { if (SystemConstant.BOOLEAN_DATA_TRUE.equals(isArchives)) {
...@@ -91,9 +92,17 @@ public class NftController { ...@@ -91,9 +92,17 @@ public class NftController {
.setTheme(theme) .setTheme(theme)
.setSynopsis(synopsis) .setSynopsis(synopsis)
.setFileHash(fileHash) .setFileHash(fileHash)
.setNftId(nftId)
.setIsArchives(isArchives); .setIsArchives(isArchives);
return ResponseModel.success(nftService.publish(nft)); return ResponseModel.success(nftService.saveNft(nft));
}
@SaCheckLogin
@PostMapping("/publish")
@ApiOperation("发行nft")
public ResponseModel<Boolean> publish(@Validated @RequestBody NftDto nftDto) {
Boolean result = nftService.publish(nftDto);
return ResponseModel.success(result);
} }
@GetMapping("/list") @GetMapping("/list")
...@@ -165,7 +174,7 @@ public class NftController { ...@@ -165,7 +174,7 @@ public class NftController {
throw GlobalException.newException(ResultCode.FORBIDDEN, "您无权查看别人的nft证书"); throw GlobalException.newException(ResultCode.FORBIDDEN, "您无权查看别人的nft证书");
} }
User user = userService.getById(userId); User user = userService.getById(userId);
String qrCode = QRCodeUtil.encode(path, null, false); String qrCode = QRCodeUtil.encode(PATH, null, false);
NftCertificateVo vo = new NftCertificateVo(nft, user, qrCode); NftCertificateVo vo = new NftCertificateVo(nft, user, qrCode);
return ResponseModel.success(vo); return ResponseModel.success(vo);
} }
......
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