Commit d65ecdb6 authored by tangtuo's avatar tangtuo

纪念版nft相关接口编写

parent 087afef8
package com.fzm.common.entity.vo;
import cn.hutool.core.date.DateUtil;
import com.fzm.common.entity.CommemorateNft;
import com.fzm.common.entity.Nft;
import com.fzm.common.entity.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author tangtuo
* @date 2021/7/1 10:35
*/
@Data
public class CommemorateNftVo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("发行人")
private String publisher;
@ApiModelProperty("头像")
private String avatar;
@ApiModelProperty("钱包地址")
private String publishAddress;
@ApiModelProperty("发行个数")
private Integer publishCount;
@ApiModelProperty("已领取个数")
private Integer receiveCount;
@ApiModelProperty("发行时间")
private Date publishTime;
@ApiModelProperty("简介")
private String synopsis;
@ApiModelProperty("nft哈希")
private String nftHash;
@ApiModelProperty("0-当前用户已领取 1-纪念版nft还未领取完 2-纪念版nft已领取完")
private Integer status;
public CommemorateNftVo(CommemorateNft nft, User user) {
this.id = nft.getId();
this.name = nft.getName();
this.avatar = user.getAvatar();
this.publishAddress = nft.getPublishAddress();
this.publishCount = nft.getCount();
this.publisher = user.getNickname();
this.nftHash = nft.getNftHash();
this.publishTime = nft.getPublishTime();
this.synopsis = nft.getSynopsis();
}
}
......@@ -52,7 +52,7 @@ public class NftCertificateVo {
this.id = nft.getId();
this.publisher = user.getNickname();
this.publishTime = nft.getPublishTime();
this.wallet=user.getWallet();
this.wallet=nft.getPublishAddress();
this.qrCode = qrCode;
this.examineStatus = 0;
this.copyrightStatus = 0;
......
......@@ -61,7 +61,6 @@ public interface UserService extends IService<User> {
UserStatisticVo getStatistic();
/**
*
* @param telephone
* @param nickname
* @param authType
......@@ -70,4 +69,12 @@ public interface UserService extends IService<User> {
* @return
*/
List<UserListVo> list(String telephone, String nickname, Integer authType, String start, String end);
/**
* 根据钱包地址查询用户信息
*
* @param publishAddress
* @return
*/
User getUserByWallet(String publishAddress);
}
......@@ -193,6 +193,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
}
@Override
public User getUserByWallet(String publishAddress) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("wallet", publishAddress);
return getOne(queryWrapper);
}
@Override
public List<UserListVo> list(String telephone, String nickname, Integer authType, String start, String end) {
DateTime startDate = null;
DateTime endDate = null;
......
......@@ -2,19 +2,25 @@ package com.fzm.portal.controller;
import cn.hutool.crypto.SecureUtil;
import com.fzm.common.annotation.Authentication;
import com.fzm.common.constant.RedisConstant;
import com.fzm.common.entity.CommemorateNft;
import com.fzm.common.entity.Label;
import com.fzm.common.entity.User;
import com.fzm.common.entity.vo.CommemorateNftVo;
import com.fzm.common.enums.ResultCode;
import com.fzm.common.exception.GlobalException;
import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.CommemorateNftService;
import com.fzm.common.service.LabelService;
import com.fzm.common.service.UserService;
import com.fzm.common.utils.JwtUtil;
import com.fzm.common.utils.OssUtil;
import com.fzm.common.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.redisson.api.RSemaphore;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -37,6 +43,15 @@ public class CommemorateNftController {
@Resource
private OssUtil ossUtil;
@Resource
private UserService userService;
@Resource
private RedissonClient redisson;
@Resource
private RedisUtil redisUtil;
@Authentication
@PostMapping("/publish")
@ApiOperation(value = "发行纪念版nft", notes = "返回发行成功的数量")
......@@ -66,6 +81,40 @@ public class CommemorateNftController {
@ApiOperation(value = "领取纪念版nft")
public ResponseModel<Boolean> receive(@RequestParam Integer id) {
Boolean result = commemorateNftService.receive(id);
return ResponseModel.success();
return ResponseModel.success(result);
}
@Authentication
@GetMapping("/get/{id}")
@ApiOperation(value = "纪念版nft详情页")
public ResponseModel<CommemorateNftVo> getById(@PathVariable Integer id, @RequestHeader String Authorization) {
CommemorateNft nft = commemorateNftService.getById(id);
if (nft == null) {
throw GlobalException.newException(ResultCode.DATA_ERROR, "此纪念版nft已下架");
}
User user = userService.getById(nft.getUserId());
CommemorateNftVo commemorateNftVo = new CommemorateNftVo(nft, user);
RSemaphore semaphore = redisson.getSemaphore(RedisConstant.COMMEMORATE_NFT_PREFIX + id);
int permits = semaphore.availablePermits();
commemorateNftVo.setReceiveCount(nft.getCount() - permits);
Boolean receive = redisUtil.sIsMember(RedisConstant.COMMEMORATE_NFT_MEMBERS_PREFIX + id, JwtUtil.getUserIdFromToken(Authorization).toString());
// 当前用户已领取
if (receive) {
commemorateNftVo.setStatus(0);
} else {
// 未领取完毕
if (commemorateNftVo.getPublishCount() > commemorateNftVo.getReceiveCount()) {
commemorateNftVo.setStatus(1);
} else {
commemorateNftVo.setStatus(2);
}
}
return ResponseModel.success(commemorateNftVo);
}
@GetMapping("/list")
@ApiOperation(value = "首页banner页(纪念版nft列表)")
public ResponseModel<List<CommemorateNft>> list() {
return ResponseModel.success(commemorateNftService.list());
}
}
......@@ -172,7 +172,7 @@ public class NftController {
if (!nft.getUserId().equals(userId)) {
throw GlobalException.newException(ResultCode.FORBIDDEN, "您无权查看别人的nft证书");
}
User user = userService.getById(userId);
User user = userService.getUserByWallet(nft.getPublishAddress());
String qrCode = QRCodeUtil.encode(PATH, null, false);
NftCertificateVo vo = new NftCertificateVo(nft, user, qrCode);
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