Commit 9334d266 authored by tangtuo's avatar tangtuo

新增收藏功能的接口

parent 326bfa82
...@@ -7,12 +7,13 @@ package com.fzm.common.constant; ...@@ -7,12 +7,13 @@ package com.fzm.common.constant;
public class RedisConstant { public class RedisConstant {
/** /**
* 后台管理用户的token的key值前缀 * 用户收藏的key前缀
*/ */
public static final String ADMIN_USER_TOKEN_PREFIX = "admin:user:token:"; public static final String COLLECTION_USER_PREFIX = "collection:user:";
/**
* 门户用户的token的key值前缀
*/
public static final String PORTAL_USER_TOKEN_PREFIX = "portal:user:token:";
} }
package com.fzm.common.entity.vo;
import com.fzm.common.entity.Nft;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author tangtuo
* @date 2021/7/1 17:54
*/
@Data
public class CollectionNftVo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("类目id")
private Integer categoryId;
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("主题,多个用逗号,隔开")
private String theme;
@ApiModelProperty("nft编号")
private String nftId;
public CollectionNftVo(Nft nft) {
this.id = nft.getId();
this.theme = nft.getTheme();
this.nftId = nft.getNftId();
this.categoryId = nft.getCategoryId();
this.name = nft.getName();
}
}
...@@ -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.vo.CollectionNftVo;
import java.util.List; import java.util.List;
...@@ -10,7 +11,45 @@ import java.util.List; ...@@ -10,7 +11,45 @@ import java.util.List;
* @date 2021/6/30 15:55 * @date 2021/6/30 15:55
*/ */
public interface NftService extends IService<Nft> { public interface NftService extends IService<Nft> {
/**
* 发行nft
*
* @param nft
* @return
*/
String publish(Nft nft); String publish(Nft nft);
/**
* 查看nft列表
*
* @param pageNum
* @param pageSize
* @param categoryId
* @return
*/
List<Nft> list(Integer pageNum, Integer pageSize, Integer categoryId); List<Nft> list(Integer pageNum, Integer pageSize, Integer categoryId);
/**
* 收藏nft
*
* @param id nft主键
* @return
*/
Boolean collection(Integer id);
/**
* 获取收藏页的nft对象
*
* @param id
* @return
*/
CollectionNftVo getCollectionVoById(Integer id);
/**
* 查询用户的收藏列表
*
* @param categoryId
* @return
*/
List<CollectionNftVo> getCollectionList(Integer categoryId);
} }
package com.fzm.common.service.impl; package com.fzm.common.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.fzm.chain.simplesdk.client.ParaChainClient; import cn.fzm.chain.simplesdk.client.ParaChainClient;
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.entity.Nft; import com.fzm.common.entity.Nft;
import com.fzm.common.entity.vo.CollectionNftVo;
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.utils.JsonUtil;
import com.fzm.common.utils.RedisUtil;
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.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* @author tangtuo * @author tangtuo
...@@ -22,6 +31,9 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -22,6 +31,9 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
private ParaChainClient paraChainClient; private ParaChainClient paraChainClient;
@Resource @Resource
RedisUtil redisUtil;
@Resource
private NftMapper nftMapper; private NftMapper nftMapper;
@Override @Override
...@@ -33,6 +45,38 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -33,6 +45,38 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
@Override @Override
public List<Nft> list(Integer pageNum, Integer pageSize, Integer categoryId) { public List<Nft> list(Integer pageNum, Integer pageSize, Integer categoryId) {
return nftMapper.list(pageNum,pageSize,categoryId); return nftMapper.list(pageNum, pageSize, categoryId);
}
@Override
public Boolean collection(Integer id) {
String key = RedisConstant.COLLECTION_USER_PREFIX + StpUtil.getLoginIdAsInt();
// 如果用户收藏的nft已经存在列表里,那么就是取消收藏
if (redisUtil.sIsMember(key, id.toString())) {
return redisUtil.sRemove(key, id.toString()) == 1;
} else {
return redisUtil.sAdd(key, id.toString()) == 1;
}
}
@Override
public CollectionNftVo getCollectionVoById(Integer id) {
return new CollectionNftVo(getById(id));
}
@Override
public List<CollectionNftVo> getCollectionList(Integer categoryId) {
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<Nft> nfts = nftMapper.selectBatchIds(ids);
List<CollectionNftVo> list = nfts.stream().map(CollectionNftVo::new).collect(Collectors.toList());
if (categoryId != null) {
list = list.stream().filter(nft -> categoryId.equals(nft.getCategoryId())).collect(Collectors.toList());
}
return list;
} }
} }
package com.fzm.portal.controller; package com.fzm.portal.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.fzm.common.entity.vo.CollectionNftVo;
import com.fzm.common.model.ResponseModel; import com.fzm.common.model.ResponseModel;
import com.fzm.common.service.NftService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author tangtuo * @author tangtuo
...@@ -11,11 +20,28 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -11,11 +20,28 @@ import org.springframework.web.bind.annotation.RestController;
*/ */
@RestController @RestController
@RequestMapping(value = "/collection") @RequestMapping(value = "/collection")
@Api(tags = "门户用户管理") @Api(tags = "收藏")
public class CollectionController { public class CollectionController {
@Resource
private NftService nftService;
/*public ResponseModel add(){ @SaCheckLogin
@PostMapping("/add")
@ApiOperation(value = "收藏 | 取消收藏", notes = "用户如果已经收藏了当前作品的话就是取消收藏,反之就是收藏")
public ResponseModel add(@ApiParam(value = "nft的主键") @RequestParam Integer id) {
Boolean result = nftService.collection(id);
return ResponseModel.success(result);
}
}*/ @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);
}
} }
server: server:
port: 8001 port: 8001
spring: spring:
application:
name: joying-portal
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
datasource: datasource:
url: jdbc:mysql://localhost:3306/fzm_joying?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 url: jdbc:mysql://172.16.101.135:3306/fzm_joying?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
username: root username: root
password: 123456 password: 123456
platform: mysql platform: mysql
...@@ -72,7 +70,6 @@ spring: ...@@ -72,7 +70,6 @@ spring:
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
is-concurrent: false is-concurrent: false
swagger: swagger:
title: 乐映影视 title: 乐映影视
description: 乐映影视门户系统RESTFUL API description: 乐映影视门户系统RESTFUL API
...@@ -107,12 +104,3 @@ chain: ...@@ -107,12 +104,3 @@ chain:
title: user.p.joying. title: user.p.joying.
admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ admin: 16naUoLwjNUgMhGVRmL3xTVpCso2DJp8JZ
admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7 admin-key: 8cd19e9bf39055f95e3e33cc1e08b9f9fc2e9be48a5b3a4d401e64041c97aec7
aliyun:
oss:
app-key: LTAI5tHGn7cVJdEtihTFLSeB
app-secret: XYmfBSbLaZoblGXZwIXkbhfBD7a1eg
end-point: oss-cn-hangzhou.aliyuncs.com
simple-bucket: test-nft
encrypt-bucket: test-nft-2
spring: spring:
profiles: profiles:
active: dev active: local
application: application:
name: joying-portal name: joying-portal
......
package com.fzm.portal; package com.fzm.portal;
import cn.fzm.chain.simplesdk.client.ParaChainClient; import cn.fzm.chain.simplesdk.client.ParaChainClient;
import com.fzm.common.utils.JsonUtil;
import com.fzm.common.utils.RedisUtil; import com.fzm.common.utils.RedisUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
@SpringBootTest @SpringBootTest
class LyPortalApplicationTests { class LyPortalApplicationTests {
...@@ -18,12 +22,15 @@ class LyPortalApplicationTests { ...@@ -18,12 +22,15 @@ class LyPortalApplicationTests {
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@Resource @Resource
StringRedisTemplate stringRedisTemplate;
@Resource
ParaChainClient paraClient; ParaChainClient paraClient;
@Test @Test
void contextLoads() { void contextLoads() {
String s = paraClient.walletCreateAccount("1"); System.out.println(redisUtil.setMembers("user:collect:2"));
System.out.println(s); System.out.println(redisUtil.sSize("user:collect:2"));
} }
} }
SET NAMES utf8mb4;
SET
FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `tb_auth_enterprise`;
CREATE TABLE `tb_auth_enterprise`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL COMMENT '用户id',
`enterprise_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '企业名称',
`uscc` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '统一社会信用代码',
`legal_person_name` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '法人姓名',
`legal_person_card_num` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '法人证件号码',
`mobile` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '法人代表手机号码',
`public_account` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '对公账户',
`bank_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '开户银行',
`bank_branch` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '开户支行',
`create_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (0),
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `idx_userid`(`user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '企业认证信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for tb_auth_person
-- ----------------------------
DROP TABLE IF EXISTS `tb_auth_person`;
CREATE TABLE `tb_auth_person`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NULL DEFAULT NULL COMMENT '用户id',
`name` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '姓名',
`id_card` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '身份证号码',
`card_picture_front` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '身份证正面照片(人脸面)',
`card_picture_back` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '身份证反面照片(国徽面)',
`create_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (0),
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `idx_userid`(`user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '个人认证信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for tb_category
-- ----------------------------
DROP TABLE IF EXISTS `tb_category`;
CREATE TABLE `tb_category`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
`english_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
`create_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (0),
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '首页类目表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for tb_nft
-- ----------------------------
DROP TABLE IF EXISTS `tb_nft`;
CREATE TABLE `tb_nft`
(
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL COMMENT '类目id',
`user_id` int(11) NOT NULL COMMENT '用户id',
`name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '名称',
`author` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '作者',
`theme` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '题材',
`synopsis` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '简介',
`file_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '文件名',
`file_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '文件地址--用户选择不存档的情况下为空',
`file_hash` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '文件上链hash',
`is_archives` tinyint(1) NOT NULL COMMENT '平台存档 0-不存档 1-加密存档',
`is_grant` tinyint(1) NOT NULL COMMENT '授权阅读 0-不需要授权 1-需要授权',
`nft_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'nft编号',
`nft_hash` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'nft哈希',
`publish_time` datetime(0) NULL DEFAULT NULL COMMENT 'nft发行时间',
`is_top` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否置顶 0-否 1-是',
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0: 下架 1:上架',
`create_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (0),
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for tb_user
-- ----------------------------
DROP TABLE IF EXISTS `tb_user`;
CREATE TABLE `tb_user`
(
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`telephone` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机号',
`email` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
`password` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '密码',
`wallet` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '钱包地址',
`nickname` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '昵称',
`signature` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '个性签名',
`avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '头像',
`auth_type` tinyint(1) NULL DEFAULT NULL COMMENT '认证类型 0-个人认证 1-企业认证',
`auth_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '实名认证状态 0-未认证 1-认证成功 2-认证失败 3-认证中',
`create_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (0),
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `idx_telephone`(`telephone`) USING BTREE,
UNIQUE INDEX `idx_email`(`email`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '门户用户表' ROW_FORMAT = Dynamic;
SET
FOREIGN_KEY_CHECKS = 1;
\ No newline at end of file
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