Commit fa572885 authored by tangtuo's avatar tangtuo

新增查询我的nft接口

修改上传加密文件
parent 9334d266
...@@ -37,7 +37,7 @@ public class Nft extends BaseEntity { ...@@ -37,7 +37,7 @@ public class Nft extends BaseEntity {
private String synopsis; private String synopsis;
@ApiModelProperty("文件名") @ApiModelProperty("文件名")
private String fileName; private String fileName;
@ApiModelProperty("文件地址--用户选择不存档的情况下为空") @ApiModelProperty("文件地址--用户选择不存档的情况下为空")
private String fileUrl; private String fileUrl;
...@@ -57,6 +57,9 @@ public class Nft extends BaseEntity { ...@@ -57,6 +57,9 @@ public class Nft extends BaseEntity {
@ApiModelProperty("nft哈希") @ApiModelProperty("nft哈希")
private String nftHash; private String nftHash;
@ApiModelProperty("nft token")
private String tokenId;
@ApiModelProperty("nft发行时间") @ApiModelProperty("nft发行时间")
private Date publishTime; private Date publishTime;
......
...@@ -17,7 +17,7 @@ public interface NftService extends IService<Nft> { ...@@ -17,7 +17,7 @@ public interface NftService extends IService<Nft> {
* @param nft * @param nft
* @return * @return
*/ */
String publish(Nft nft); Nft publish(Nft nft);
/** /**
* 查看nft列表 * 查看nft列表
...@@ -38,18 +38,18 @@ public interface NftService extends IService<Nft> { ...@@ -38,18 +38,18 @@ public interface NftService extends IService<Nft> {
Boolean collection(Integer id); Boolean collection(Integer id);
/** /**
* 获取收藏页的nft对象 * 查询用户的收藏列表
* *
* @param id
* @return * @return
*/ */
CollectionNftVo getCollectionVoById(Integer id); List<CollectionNftVo> getCollectionList();
/** /**
* 查询用户的收藏列表 * 查询我的nft列表
* *
* @param categoryId * @param categoryId
* @param userId
* @return * @return
*/ */
List<CollectionNftVo> getCollectionList(Integer categoryId); List<Nft> listCurrent(Integer categoryId, Integer userId);
} }
...@@ -6,16 +6,24 @@ import cn.hutool.core.collection.CollectionUtil; ...@@ -6,16 +6,24 @@ import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.entity.Nft; 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.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
import com.fzm.common.mapper.NftMapper; import com.fzm.common.mapper.NftMapper;
import com.fzm.common.service.NftService; import com.fzm.common.service.NftService;
import com.fzm.common.service.UserService;
import com.fzm.common.utils.JsonUtil; import com.fzm.common.utils.JsonUtil;
import com.fzm.common.utils.RedisUtil; import com.fzm.common.utils.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -34,13 +42,30 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -34,13 +42,30 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
RedisUtil redisUtil; RedisUtil redisUtil;
@Resource @Resource
private UserService userService;
@Resource
private NftMapper nftMapper; private NftMapper nftMapper;
@Value("${chain.para.contract-name}")
private String contractName;
@Override @Override
public String publish(Nft nft) { public Nft publish(Nft nft) {
User user = userService.getById(StpUtil.getLoginIdAsInt());
// 获取用户的私钥
String wallet = user.getWallet();
String privkey = paraChainClient.walletDumpPrivkey(wallet);
String txHash = paraChainClient.evmPublishNFT1155(contractName, wallet, privkey, 1, true);
if (StringUtils.isBlank(txHash) || !txHash.contains("-")) {
throw GlobalException.newException(ResultCode.FAILED, "nft发行失败");
}
String[] split = txHash.split("-");
nft.setNftHash(split[0]);
nft.setTokenId(split[1]);
nft.setPublishTime(new Date());
save(nft); save(nft);
//return paraChainClient.evmPublishNFT1155(); return getById(nft.getId());
return null;
} }
@Override @Override
...@@ -59,24 +84,27 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -59,24 +84,27 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
} }
} }
@Override
public CollectionNftVo getCollectionVoById(Integer id) {
return new CollectionNftVo(getById(id));
}
@Override @Override
public List<CollectionNftVo> getCollectionList(Integer categoryId) { public List<CollectionNftVo> getCollectionList() {
String key = RedisConstant.COLLECTION_USER_PREFIX + StpUtil.getLoginIdAsInt(); String key = RedisConstant.COLLECTION_USER_PREFIX + StpUtil.getLoginIdAsInt();
Set<String> set = redisUtil.setMembers(key); Set<String> set = redisUtil.setMembers(key);
if (CollectionUtil.isEmpty(set)) { if (CollectionUtil.isEmpty(set)) {
return new ArrayList<>(); return new ArrayList<>();
} }
List<Integer> ids = set.stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList()); List<Integer> ids = set.stream().map(Integer::valueOf).collect(Collectors.toList());
List<Nft> nfts = nftMapper.selectBatchIds(ids); List<Nft> nfts = nftMapper.selectBatchIds(ids);
List<CollectionNftVo> list = nfts.stream().map(CollectionNftVo::new).collect(Collectors.toList()); return nfts.stream().map(CollectionNftVo::new).collect(Collectors.toList());
}
@Override
public List<Nft> listCurrent(Integer categoryId, Integer userId) {
QueryWrapper<Nft> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", SystemConstant.BOOLEAN_DATA_TRUE).eq("user_id", userId);
if (categoryId != null) { if (categoryId != null) {
list = list.stream().filter(nft -> categoryId.equals(nft.getCategoryId())).collect(Collectors.toList()); queryWrapper.eq("category_id", categoryId);
} }
return list; queryWrapper.orderByDesc("is_top", "publish_time");
return nftMapper.selectList(queryWrapper);
} }
} }
...@@ -32,25 +32,43 @@ public class OssUtil { ...@@ -32,25 +32,43 @@ public class OssUtil {
* @param file * @param file
* @return * @return
*/ */
public String putSimpleObject(MultipartFile file) throws IOException { public String putObject(MultipartFile file, String bucket) throws IOException {
String endpoint = ossProperties.getEndPoint(); String endpoint = ossProperties.getEndPoint();
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。 // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
String accessKeyId = ossProperties.getAppKey(); String accessKeyId = ossProperties.getAppKey();
String accessKeySecret = ossProperties.getAppSecret(); String accessKeySecret = ossProperties.getAppSecret();
String bucketName = ossProperties.getSimpleBucket();
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如20210629/a8703bcf7d354ea2bbb5ccdf76b7405f/123.jpg。 // <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如20210629/a8703bcf7d354ea2bbb5ccdf76b7405f/123.jpg。
String objectName = String.format("%s/%s/%s", DateUtil.format(new Date(), "yyyyMMdd"), IdUtil.simpleUUID(), file.getOriginalFilename()); String objectName = String.format("%s/%s/%s", DateUtil.format(new Date(), "yyyyMMdd"), IdUtil.simpleUUID(), file.getOriginalFilename());
// 创建OSSClient实例。 // 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
ossClient.putObject(bucket, objectName, file.getInputStream());
// 上传文件到指定的存储空间(bucketName)并将其保存为指定的文件名称(objectName)。
String content = "Hello OSS";
ossClient.putObject(bucketName, objectName, file.getInputStream());
// 关闭OSSClient。 // 关闭OSSClient。
ossClient.shutdown(); ossClient.shutdown();
return String.format("https://%s.%s/%s", bucketName, endpoint, objectName); return String.format("https://%s.%s/%s", bucket, endpoint, objectName);
}
/**
* 文件普通存储
*
* @param file
* @return
* @throws IOException
*/
public String putSimpleObject(MultipartFile file) throws IOException {
return putObject(file, ossProperties.getSimpleBucket());
}
/**
* 文件加密存储
*
* @param file
* @return
* @throws IOException
*/
public String putEncryptObject(MultipartFile file) throws IOException {
return putObject(file, ossProperties.getEncryptBucket());
} }
public void createEncryptBucket() { public void createEncryptBucket() {
...@@ -75,20 +93,12 @@ public class OssUtil { ...@@ -75,20 +93,12 @@ public class OssUtil {
ossClient.createBucket(ossProperties.getEncryptBucket()); ossClient.createBucket(ossProperties.getEncryptBucket());
} }
public String putEncryptObject(MultipartFile file) {
String endpoint = ossProperties.getEndPoint();
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
String accessKeyId = ossProperties.getAppKey();
String accessKeySecret = ossProperties.getAppSecret();
String bucketName = ossProperties.getSimpleBucket();
// <yourObjectName>上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如20210629/a8703bcf7d354ea2bbb5ccdf76b7405f/123.jpg。
String objectName = String.format("%s/%s/%s", DateUtil.format(new Date(), "yyyyMMdd"), IdUtil.simpleUUID(), file.getOriginalFilename());
return String.format("https://%s.%s/%s", bucketName, endpoint, objectName);
}
/**
* 下载文件
*
* @param file
*/
public void downloadFile(String file) { public void downloadFile(String file) {
String endpoint = ossProperties.getEndPoint(); String endpoint = ossProperties.getEndPoint();
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。 // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
......
...@@ -37,11 +37,8 @@ public class CollectionController { ...@@ -37,11 +37,8 @@ public class CollectionController {
@SaCheckLogin @SaCheckLogin
@GetMapping("/list") @GetMapping("/list")
@ApiOperation(value = "获取用户的收藏列表") @ApiOperation(value = "获取用户的收藏列表")
private ResponseModel<Map<String, Object>> list(@ApiParam(value = "类目id,查询全部的话传null") @RequestParam Integer categoryId) { private ResponseModel<List<CollectionNftVo>> list() {
List<CollectionNftVo> list = nftService.getCollectionList(categoryId); List<CollectionNftVo> list = nftService.getCollectionList();
HashMap<String, Object> result = new HashMap<>(4); return ResponseModel.success(list);
result.put("list", list);
result.put("size", list.size());
return ResponseModel.success(result);
} }
} }
...@@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil; ...@@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil;
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.User; import com.fzm.common.entity.User;
import com.fzm.common.entity.vo.CollectionNftVo;
import com.fzm.common.entity.vo.NftVo; import com.fzm.common.entity.vo.NftVo;
import com.fzm.common.enums.ResultCode; import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException; import com.fzm.common.exception.GlobalException;
...@@ -19,7 +20,11 @@ import org.springframework.web.bind.annotation.*; ...@@ -19,7 +20,11 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author tangtuo * @author tangtuo
...@@ -43,16 +48,16 @@ public class NftController { ...@@ -43,16 +48,16 @@ public class NftController {
@SaCheckLogin @SaCheckLogin
@PostMapping("/publish") @PostMapping("/publish")
@ApiOperation(value = "nft发行") @ApiOperation(value = "nft发行")
public ResponseModel publish(@ApiParam(value = "类目id", required = true) Integer categoryId, public ResponseModel<Nft> publish(@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,
@ApiParam(value = "简介", required = true) String synopsis, @ApiParam(value = "简介", required = true) String synopsis,
@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,
@ApiParam(value = "nft编号", required = true) String nftId) { @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)) {
...@@ -69,9 +74,9 @@ public class NftController { ...@@ -69,9 +74,9 @@ public class NftController {
.setTheme(theme) .setTheme(theme)
.setSynopsis(synopsis) .setSynopsis(synopsis)
.setFileHash(fileHash) .setFileHash(fileHash)
.setNftId(nftId); .setNftId(nftId)
String nftHash = nftService.publish(nft); .setIsArchives(isArchives);
return ResponseModel.success(nftHash); return ResponseModel.success(nftService.publish(nft));
} }
@GetMapping("/list") @GetMapping("/list")
...@@ -99,4 +104,16 @@ public class NftController { ...@@ -99,4 +104,16 @@ public class NftController {
return ResponseModel.success(new NftVo(nft, user)); return ResponseModel.success(new NftVo(nft, user));
} }
@SaCheckLogin
@GetMapping("/list/current")
@ApiOperation(value = "获取我的nft列表")
public ResponseModel<Map<String, Object>> listCurrent(@ApiParam(value = "类目id,查询全部的时候传null") @RequestParam(required = false) Integer categoryId) {
List<Nft> list = nftService.listCurrent(categoryId, StpUtil.getLoginIdAsInt());
List<CollectionNftVo> nftVoList = list.stream().map(CollectionNftVo::new).collect(Collectors.toList());
HashMap<String, Object> result = new HashMap<>(4);
result.put("list", nftVoList);
result.put("size", nftVoList.size());
return ResponseModel.success(result);
}
} }
...@@ -62,13 +62,13 @@ public class UserController { ...@@ -62,13 +62,13 @@ public class UserController {
} }
@GetMapping(value = "/isRegister/{username}") @GetMapping(value = "/isRegister/{username}")
@ApiOperation(value = "/判断用户是否已注册过") @ApiOperation(value = "判断用户是否已注册过")
public ResponseModel<Boolean> isRegister(@PathVariable String username) { public ResponseModel<Boolean> isRegister(@PathVariable String username) {
return ResponseModel.success(userService.loadUserByUsername(username) != null); return ResponseModel.success(userService.loadUserByUsername(username) != null);
} }
@GetMapping(value = "/isSetPassword/{username}") @GetMapping(value = "/isSetPassword/{username}")
@ApiOperation(value = "/判断用户是否已设置密码") @ApiOperation(value = "判断用户是否已设置密码")
public ResponseModel<Boolean> isSetPassword(@PathVariable String username) { public ResponseModel<Boolean> isSetPassword(@PathVariable String username) {
User user = userService.loadUserByUsername(username); User user = userService.loadUserByUsername(username);
return ResponseModel.success(user != null && StringUtils.isNotBlank(user.getPassword())); return ResponseModel.success(user != null && StringUtils.isNotBlank(user.getPassword()));
......
...@@ -104,3 +104,13 @@ chain: ...@@ -104,3 +104,13 @@ chain:
title: user.p.joying. title: user.p.joying.
admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ
admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7 admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7
contract-name: user.evm.0xd996a3a866c577596df260844a045a068ec5accd8d71ccaa3d578c9617ec5490
contract-address: 1iDWTHZQxPES4hLveZRcwJH6AMaMfZfZZ
aliyun:
oss:
app-key: LTAI5tHGn7cVJdEtihTFLSeB
app-secret: XYmfBSbLaZoblGXZwIXkbhfBD7a1eg
end-point: oss-cn-hangzhou.aliyuncs.com
simple-bucket: test-nft
encrypt-bucket: test-nft-2
...@@ -87,6 +87,14 @@ swagger: ...@@ -87,6 +87,14 @@ swagger:
name: tangtuo name: tangtuo
email: ttuo@33.com email: ttuo@33.com
aliyun:
oss:
app-key: LTAI5tHGn7cVJdEtihTFLSeB
app-secret: XYmfBSbLaZoblGXZwIXkbhfBD7a1eg
end-point: oss-cn-hangzhou.aliyuncs.com
simple-bucket: test-nft
encrypt-bucket: test-nft-2
sms: sms:
app-key: Yiru app-key: Yiru
app-secret: mx5oaR^RY8!(ziHn app-secret: mx5oaR^RY8!(ziHn
...@@ -104,3 +112,5 @@ chain: ...@@ -104,3 +112,5 @@ chain:
title: user.p.joying. title: user.p.joying.
admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ
admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7 admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7
contract-name: user.evm.0xd996a3a866c577596df260844a045a068ec5accd8d71ccaa3d578c9617ec5490
contract-address: 1iDWTHZQxPES4hLveZRcwJH6AMaMfZfZZ
...@@ -11,10 +11,10 @@ import java.io.File; ...@@ -11,10 +11,10 @@ import java.io.File;
public class FileTest { public class FileTest {
public static void main(String[] args) { public static void main(String[] args) {
File file = new File("C:\\Users\\tangtuo\\Desktop\\唐拓个人简历.docx"); File file = new File("C:\\Users\\tangtuo\\Pictures\\微信图片_20210208094951.jpg");
String s = SecureUtil.md5(file); String s = SecureUtil.md5(file);
System.out.println(s); System.out.println(s);
System.out.println("c3043a1f6ab8a5e07130ffae51b3de6f".equals(s));
} }
} }
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