feat(count): 新增笔记和用户计数相关数据结构和服务
- 新增笔记收藏表(NoteCollectionDO)及相关Mapper和服务实现 - 新增笔记计数表(NoteCountDO)及相关Mapper和服务实现 - 新增笔记点赞表(NoteLikeDO)及相关Mapper和服务实现 - 新增用户计数表(UserCountDO)及相关Mapper和服务实现 - 配置RedisTemplate以支持JSON格式序列化 - 引入RocketMQ依赖并配置自动装配 - 在count模块中添加Redis和RocketMQ相关配置类
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.hanserwei.hannote.count.biz.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
// 设置 RedisTemplate 的连接工厂
|
||||
redisTemplate.setConnectionFactory(connectionFactory);
|
||||
|
||||
// 使用 StringRedisSerializer 来序列化和反序列化 redis 的 key 值,确保 key 是可读的字符串
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
|
||||
// 使用 Jackson2JsonRedisSerializer 来序列化和反序列化 redis 的 value 值, 确保存储的是 JSON 格式
|
||||
Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
|
||||
redisTemplate.setValueSerializer(serializer);
|
||||
redisTemplate.setHashValueSerializer(serializer);
|
||||
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.hanserwei.hannote.count.biz.config;
|
||||
|
||||
import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration
|
||||
@Import(RocketMQAutoConfiguration.class)
|
||||
public class RocketMQConfig {
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.hanserwei.hannote.count.biz.domain.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 笔记计数表
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName(value = "t_note_count")
|
||||
public class NoteCountDO {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 笔记ID
|
||||
*/
|
||||
@TableField(value = "note_id")
|
||||
private Long noteId;
|
||||
|
||||
/**
|
||||
* 获得点赞总数
|
||||
*/
|
||||
@TableField(value = "like_total")
|
||||
private Long likeTotal;
|
||||
|
||||
/**
|
||||
* 获得收藏总数
|
||||
*/
|
||||
@TableField(value = "collect_total")
|
||||
private Long collectTotal;
|
||||
|
||||
/**
|
||||
* 被评论总数
|
||||
*/
|
||||
@TableField(value = "comment_total")
|
||||
private Long commentTotal;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.hanserwei.hannote.count.biz.domain.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 笔记计数表
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName(value = "t_note_count")
|
||||
public class TNoteCount {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 笔记ID
|
||||
*/
|
||||
@TableField(value = "note_id")
|
||||
private Long noteId;
|
||||
|
||||
/**
|
||||
* 获得点赞总数
|
||||
*/
|
||||
@TableField(value = "like_total")
|
||||
private Long likeTotal;
|
||||
|
||||
/**
|
||||
* 获得收藏总数
|
||||
*/
|
||||
@TableField(value = "collect_total")
|
||||
private Long collectTotal;
|
||||
|
||||
/**
|
||||
* 被评论总数
|
||||
*/
|
||||
@TableField(value = "comment_total")
|
||||
private Long commentTotal;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.hanserwei.hannote.count.biz.domain.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 用户计数表
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName(value = "t_user_count")
|
||||
public class UserCountDO {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableField(value = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 粉丝总数
|
||||
*/
|
||||
@TableField(value = "fans_total")
|
||||
private Long fansTotal;
|
||||
|
||||
/**
|
||||
* 关注总数
|
||||
*/
|
||||
@TableField(value = "following_total")
|
||||
private Long followingTotal;
|
||||
|
||||
/**
|
||||
* 发布笔记总数
|
||||
*/
|
||||
@TableField(value = "note_total")
|
||||
private Long noteTotal;
|
||||
|
||||
/**
|
||||
* 获得点赞总数
|
||||
*/
|
||||
@TableField(value = "like_total")
|
||||
private Long likeTotal;
|
||||
|
||||
/**
|
||||
* 获得收藏总数
|
||||
*/
|
||||
@TableField(value = "collect_total")
|
||||
private Long collectTotal;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hanserwei.hannote.count.biz.domain.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.hanserwei.hannote.count.biz.domain.dataobject.NoteCountDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface NoteCountDOMapper extends BaseMapper<NoteCountDO> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.hanserwei.hannote.count.biz.domain.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.hanserwei.hannote.count.biz.domain.dataobject.UserCountDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserCountDOMapper extends BaseMapper<UserCountDO> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.hanserwei.hannote.count.biz.service;
|
||||
|
||||
import com.hanserwei.hannote.count.biz.domain.dataobject.NoteCountDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
public interface NoteCountDOService extends IService<NoteCountDO>{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.hanserwei.hannote.count.biz.service;
|
||||
|
||||
import com.hanserwei.hannote.count.biz.domain.dataobject.UserCountDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
public interface UserCountDOService extends IService<UserCountDO>{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.hanserwei.hannote.count.biz.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.hanserwei.hannote.count.biz.domain.dataobject.NoteCountDO;
|
||||
import com.hanserwei.hannote.count.biz.domain.mapper.NoteCountDOMapper;
|
||||
import com.hanserwei.hannote.count.biz.service.NoteCountDOService;
|
||||
@Service
|
||||
public class NoteCountDOServiceImpl extends ServiceImpl<NoteCountDOMapper, NoteCountDO> implements NoteCountDOService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.hanserwei.hannote.count.biz.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.hanserwei.hannote.count.biz.domain.mapper.UserCountDOMapper;
|
||||
import com.hanserwei.hannote.count.biz.domain.dataobject.UserCountDO;
|
||||
import com.hanserwei.hannote.count.biz.service.UserCountDOService;
|
||||
@Service
|
||||
public class UserCountDOServiceImpl extends ServiceImpl<UserCountDOMapper, UserCountDO> implements UserCountDOService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hanserwei.hannote.count.biz.domain.mapper.NoteCountDOMapper">
|
||||
<resultMap id="BaseResultMap" type="com.hanserwei.hannote.count.biz.domain.dataobject.NoteCountDO">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table t_note_count-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="note_id" jdbcType="BIGINT" property="noteId" />
|
||||
<result column="like_total" jdbcType="BIGINT" property="likeTotal" />
|
||||
<result column="collect_total" jdbcType="BIGINT" property="collectTotal" />
|
||||
<result column="comment_total" jdbcType="BIGINT" property="commentTotal" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, note_id, like_total, collect_total, comment_total
|
||||
</sql>
|
||||
</mapper>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hanserwei.hannote.count.biz.domain.mapper.UserCountDOMapper">
|
||||
<resultMap id="BaseResultMap" type="com.hanserwei.hannote.count.biz.domain.dataobject.UserCountDO">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table t_user_count-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId" />
|
||||
<result column="fans_total" jdbcType="BIGINT" property="fansTotal" />
|
||||
<result column="following_total" jdbcType="BIGINT" property="followingTotal" />
|
||||
<result column="note_total" jdbcType="BIGINT" property="noteTotal" />
|
||||
<result column="like_total" jdbcType="BIGINT" property="likeTotal" />
|
||||
<result column="collect_total" jdbcType="BIGINT" property="collectTotal" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, user_id, fans_total, following_total, note_total, like_total, collect_total
|
||||
</sql>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user