Commit fa572885 authored by tangtuo's avatar tangtuo

新增查询我的nft接口

修改上传加密文件
parent 9334d266
......@@ -37,7 +37,7 @@ public class Nft extends BaseEntity {
private String synopsis;
@ApiModelProperty("文件名")
private String fileName;
private String fileName;
@ApiModelProperty("文件地址--用户选择不存档的情况下为空")
private String fileUrl;
......@@ -57,6 +57,9 @@ public class Nft extends BaseEntity {
@ApiModelProperty("nft哈希")
private String nftHash;
@ApiModelProperty("nft token")
private String tokenId;
@ApiModelProperty("nft发行时间")
private Date publishTime;
......
......@@ -17,7 +17,7 @@ public interface NftService extends IService<Nft> {
* @param nft
* @return
*/
String publish(Nft nft);
Nft publish(Nft nft);
/**
* 查看nft列表
......@@ -38,18 +38,18 @@ public interface NftService extends IService<Nft> {
Boolean collection(Integer id);
/**
* 获取收藏页的nft对象
* 查询用户的收藏列表
*
* @param id
* @return
*/
CollectionNftVo getCollectionVoById(Integer id);
List<CollectionNftVo> getCollectionList();
/**
* 查询用户的收藏列表
* 查询我的nft列表
*
* @param categoryId
* @param userId
* @return
*/
List<CollectionNftVo> getCollectionList(Integer categoryId);
List<Nft> listCurrent(Integer categoryId, Integer userId);
}
......@@ -6,16 +6,24 @@ import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.common.constant.RedisConstant;
import com.fzm.common.constant.SystemConstant;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.User;
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.service.NftService;
import com.fzm.common.service.UserService;
import com.fzm.common.utils.JsonUtil;
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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -34,13 +42,30 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
RedisUtil redisUtil;
@Resource
private UserService userService;
@Resource
private NftMapper nftMapper;
@Value("${chain.para.contract-name}")
private String contractName;
@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);
//return paraChainClient.evmPublishNFT1155();
return null;
return getById(nft.getId());
}
@Override
......@@ -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
public List<CollectionNftVo> getCollectionList(Integer categoryId) {
public List<CollectionNftVo> getCollectionList() {
String key = RedisConstant.COLLECTION_USER_PREFIX + StpUtil.getLoginIdAsInt();
Set<String> set = redisUtil.setMembers(key);
if (CollectionUtil.isEmpty(set)) {
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<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) {
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 {
* @param file
* @return
*/
public String putSimpleObject(MultipartFile file) throws IOException {
public String putObject(MultipartFile file, String bucket) throws IOException {
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());
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// 上传文件到指定的存储空间(bucketName)并将其保存为指定的文件名称(objectName)。
String content = "Hello OSS";
ossClient.putObject(bucketName, objectName, file.getInputStream());
ossClient.putObject(bucket, objectName, file.getInputStream());
// 关闭OSSClient。
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() {
......@@ -75,20 +93,12 @@ public class OssUtil {
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) {
String endpoint = ossProperties.getEndPoint();
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
......
......@@ -37,11 +37,8 @@ public class CollectionController {
@SaCheckLogin
@GetMapping("/list")
@ApiOperation(value = "获取用户的收藏列表")
private ResponseModel<Map<String, Object>> list(@ApiParam(value = "类目id,查询全部的话传null") @RequestParam Integer categoryId) {
List<CollectionNftVo> list = nftService.getCollectionList(categoryId);
HashMap<String, Object> result = new HashMap<>(4);
result.put("list", list);
result.put("size", list.size());
return ResponseModel.success(result);
private ResponseModel<List<CollectionNftVo>> list() {
List<CollectionNftVo> list = nftService.getCollectionList();
return ResponseModel.success(list);
}
}
......@@ -5,6 +5,7 @@ import cn.dev33.satoken.stp.StpUtil;
import com.fzm.common.constant.SystemConstant;
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.NftVo;
import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
......@@ -19,7 +20,11 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author tangtuo
......@@ -43,16 +48,16 @@ public class NftController {
@SaCheckLogin
@PostMapping("/publish")
@ApiOperation(value = "nft发行")
public ResponseModel publish(@ApiParam(value = "类目id", required = true) Integer categoryId,
@ApiParam(value = "名称", required = true) String name,
@ApiParam(value = "作者", required = true) String author,
@ApiParam(value = "主题", required = true) String theme,
@ApiParam(value = "简介", required = true) String synopsis,
@ApiParam(value = "文件", required = false) MultipartFile file,
@ApiParam(value = "文件hash", required = true) String fileHash,
@ApiParam(value = "平台存档 0-不存档 1-加密存档", required = true) Integer isArchives,
@ApiParam(value = "授权阅读 0-不需要授权 1-需要授权", required = false) Integer isGrant,
@ApiParam(value = "nft编号", required = true) String nftId) {
public ResponseModel<Nft> publish(@ApiParam(value = "类目id", required = true) Integer categoryId,
@ApiParam(value = "名称", required = true) String name,
@ApiParam(value = "作者", required = true) String author,
@ApiParam(value = "主题", required = true) String theme,
@ApiParam(value = "简介", required = true) String synopsis,
@ApiParam(value = "文件", required = false) MultipartFile file,
@ApiParam(value = "文件hash", required = true) String fileHash,
@ApiParam(value = "平台存档 0-不存档 1-加密存档", required = true) Integer isArchives,
@ApiParam(value = "授权阅读 0-不需要授权 1-需要授权", required = false) Integer isGrant,
@ApiParam(value = "nft编号", required = true) String nftId) throws IOException {
Nft nft = new Nft();
// 当平台存档选择加密存档时,文件必传
if (SystemConstant.BOOLEAN_DATA_TRUE.equals(isArchives)) {
......@@ -69,9 +74,9 @@ public class NftController {
.setTheme(theme)
.setSynopsis(synopsis)
.setFileHash(fileHash)
.setNftId(nftId);
String nftHash = nftService.publish(nft);
return ResponseModel.success(nftHash);
.setNftId(nftId)
.setIsArchives(isArchives);
return ResponseModel.success(nftService.publish(nft));
}
@GetMapping("/list")
......@@ -99,4 +104,16 @@ public class NftController {
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 {
}
@GetMapping(value = "/isRegister/{username}")
@ApiOperation(value = "/判断用户是否已注册过")
@ApiOperation(value = "判断用户是否已注册过")
public ResponseModel<Boolean> isRegister(@PathVariable String username) {
return ResponseModel.success(userService.loadUserByUsername(username) != null);
}
@GetMapping(value = "/isSetPassword/{username}")
@ApiOperation(value = "/判断用户是否已设置密码")
@ApiOperation(value = "判断用户是否已设置密码")
public ResponseModel<Boolean> isSetPassword(@PathVariable String username) {
User user = userService.loadUserByUsername(username);
return ResponseModel.success(user != null && StringUtils.isNotBlank(user.getPassword()));
......
......@@ -104,3 +104,13 @@ chain:
title: user.p.joying.
admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ
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:
name: tangtuo
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:
app-key: Yiru
app-secret: mx5oaR^RY8!(ziHn
......@@ -104,3 +112,5 @@ chain:
title: user.p.joying.
admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ
admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7
contract-name: user.evm.0xd996a3a866c577596df260844a045a068ec5accd8d71ccaa3d578c9617ec5490
contract-address: 1iDWTHZQxPES4hLveZRcwJH6AMaMfZfZZ
......@@ -11,10 +11,10 @@ import java.io.File;
public class FileTest {
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);
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