From 3ce029eccedc3985f1db96ad6bf53e77f4c02812 Mon Sep 17 00:00:00 2001 From: Hanserwei Date: Fri, 10 Oct 2025 19:38:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(user-relation):=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E7=94=A8=E6=88=B7=E5=85=B3=E7=B3=BB=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增用户关注和粉丝数据表结构及对应 DO、Mapper、Service 层代码 - 配置 RedisTemplate 以支持 JSON 格式的值序列化 - 添加全局异常处理器处理业务、参数校验等异常情况 - 完成模块基础配置文件(application.yml、bootstrap.yml)的初始化 - 在 SQL 脚本中新增 t_following 和 t_fans 表定义 - 更新 .gitignore、IDEA 编码设置以及 Maven 模块依赖关系 - 增加日志配置文件 logback-spring.xml 并区分环境输出方式 - 创建模块启动类 HannoteUserRelationBizApplication 并启用 MyBatis Mapper 扫描 --- .gitignore | 1 + .idea/encodings.xml | 6 + .../han-note-user-relation-api/pom.xml | 25 +++++ .../han-note-user-relation-biz/pom.xml | 103 ++++++++++++++++++ .../biz/config/RedisTemplateConfig.java | 31 ++++++ .../HannoteUserRelationBizApplication.java | 13 +++ .../biz/domain/dataobject/FansDO.java | 46 ++++++++ .../biz/domain/dataobject/FollowingDO.java | 46 ++++++++ .../biz/domain/mapper/FansDOMapper.java | 9 ++ .../biz/domain/mapper/FollowingDOMapper.java | 9 ++ .../relation/biz/enums/ResponseCodeEnum.java | 23 ++++ .../biz/exception/GlobalExceptionHandler.java | 103 ++++++++++++++++++ .../relation/biz/service/FansDOService.java | 8 ++ .../biz/service/FollowingDOService.java | 8 ++ .../biz/service/impl/FansDOServiceImpl.java | 13 +++ .../service/impl/FollowingDOServiceImpl.java | 13 +++ .../src/main/resources/application.yml | 31 ++++++ .../src/main/resources/bootstrap.yml | 12 ++ .../src/main/resources/logback-spring.xml | 58 ++++++++++ .../main/resources/mapperxml/FansDOMapper.xml | 16 +++ .../resources/mapperxml/FollowingDOMapper.xml | 16 +++ han-note-user-relation/pom.xml | 26 +++++ pom.xml | 1 + sql/createTable.sql | 49 +++++++-- 24 files changed, 655 insertions(+), 11 deletions(-) create mode 100644 han-note-user-relation/han-note-user-relation-api/pom.xml create mode 100644 han-note-user-relation/han-note-user-relation-biz/pom.xml create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/config/RedisTemplateConfig.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/HannoteUserRelationBizApplication.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FansDO.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FollowingDO.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FansDOMapper.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FollowingDOMapper.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/enums/ResponseCodeEnum.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/exception/GlobalExceptionHandler.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FansDOService.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FollowingDOService.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FansDOServiceImpl.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FollowingDOServiceImpl.java create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/resources/application.yml create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/resources/bootstrap.yml create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/resources/logback-spring.xml create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FansDOMapper.xml create mode 100644 han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FollowingDOMapper.xml create mode 100644 han-note-user-relation/pom.xml diff --git a/.gitignore b/.gitignore index 8b40d82..eb59f65 100755 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ build/ /han-note-kv/han-note-kv-biz/src/main/resources/application-prod.yml /han-note-kv/han-note-kv-biz/logs/ /han-note-note/han-note-note-biz/src/main/resources/application-dev.yml +/han-note-user-relation/han-note-user-relation-biz/src/main/resources/application-dev.yml diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 8c6bb9d..a79ed8e 100755 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -29,6 +29,12 @@ + + + + + + diff --git a/han-note-user-relation/han-note-user-relation-api/pom.xml b/han-note-user-relation/han-note-user-relation-api/pom.xml new file mode 100644 index 0000000..1afc88a --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-api/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + + + com.hanserwei + han-note-user-relation + ${revision} + + + + jar + + han-note-user-relation-api + ${project.artifactId} + RPC层, 供其他服务调用 + + + + com.hanserwei + hanserwei-common + + + + diff --git a/han-note-user-relation/han-note-user-relation-biz/pom.xml b/han-note-user-relation/han-note-user-relation-biz/pom.xml new file mode 100644 index 0000000..9631123 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + + + com.hanserwei + han-note-user-relation + ${revision} + + + + jar + + han-note-user-relation-biz + ${project.artifactId} + 用户关系服务业务模块 + + + + com.hanserwei + hanserwei-common + + + + + com.hanserwei + hanserwei-spring-boot-starter-biz-operationlog + + + + + com.hanserwei + hanserwei-spring-boot-starter-biz-context + + + + + com.hanserwei + hanserwei-spring-boot-starter-jackson + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.baomidou + mybatis-plus-spring-boot3-starter + + + + + com.mysql + mysql-connector-j + + + + + com.alibaba + druid-spring-boot-3-starter + + + + + org.apache.commons + commons-pool2 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/config/RedisTemplateConfig.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/config/RedisTemplateConfig.java new file mode 100644 index 0000000..6af3d21 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/config/RedisTemplateConfig.java @@ -0,0 +1,31 @@ +package com.hanserwei.hannote.user.relation.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 redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate redisTemplate = new RedisTemplate<>(); + // 设置 RedisTemplate 的连接工厂 + redisTemplate.setConnectionFactory(connectionFactory); + + // 使用 StringRedisSerializer 来序列化和反序列化 redis 的 key 值,确保 key 是可读的字符串 + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + + // 使用 Jackson2JsonRedisSerializer 来序列化和反序列化 redis 的 value 值, 确保存储的是 JSON 格式 + Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Object.class); + redisTemplate.setValueSerializer(serializer); + redisTemplate.setHashValueSerializer(serializer); + + redisTemplate.afterPropertiesSet(); + return redisTemplate; + } +} \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/HannoteUserRelationBizApplication.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/HannoteUserRelationBizApplication.java new file mode 100644 index 0000000..8ec07a9 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/HannoteUserRelationBizApplication.java @@ -0,0 +1,13 @@ +package com.hanserwei.hannote.user.relation.biz.domain; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScan("com.hanserwei.hannote.user.relation.biz.domain.mapper") +public class HannoteUserRelationBizApplication { + public static void main(String[] args) { + SpringApplication.run(HannoteUserRelationBizApplication.class, args); + } +} diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FansDO.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FansDO.java new file mode 100644 index 0000000..cf06df3 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FansDO.java @@ -0,0 +1,46 @@ +package com.hanserwei.hannote.user.relation.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; + +import java.time.LocalDateTime; + +/** + * 用户粉丝表 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "t_fans") +public class FansDO { + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 用户ID + */ + @TableField(value = "user_id") + private Long userId; + + /** + * 粉丝的用户ID + */ + @TableField(value = "fans_user_id") + private Long fansUserId; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FollowingDO.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FollowingDO.java new file mode 100644 index 0000000..b912112 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/dataobject/FollowingDO.java @@ -0,0 +1,46 @@ +package com.hanserwei.hannote.user.relation.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; + +import java.time.LocalDateTime; + +/** + * 用户关注表 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "t_following") +public class FollowingDO { + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 用户ID + */ + @TableField(value = "user_id") + private Long userId; + + /** + * 关注的用户ID + */ + @TableField(value = "following_user_id") + private Long followingUserId; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FansDOMapper.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FansDOMapper.java new file mode 100644 index 0000000..eef1ed9 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FansDOMapper.java @@ -0,0 +1,9 @@ +package com.hanserwei.hannote.user.relation.biz.domain.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hanserwei.hannote.user.relation.biz.domain.dataobject.FansDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface FansDOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FollowingDOMapper.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FollowingDOMapper.java new file mode 100644 index 0000000..eaed3ca --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/domain/mapper/FollowingDOMapper.java @@ -0,0 +1,9 @@ +package com.hanserwei.hannote.user.relation.biz.domain.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hanserwei.hannote.user.relation.biz.domain.dataobject.FollowingDO; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface FollowingDOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/enums/ResponseCodeEnum.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/enums/ResponseCodeEnum.java new file mode 100644 index 0000000..b66ad1b --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/enums/ResponseCodeEnum.java @@ -0,0 +1,23 @@ +package com.hanserwei.hannote.user.relation.biz.enums; + +import com.hanserwei.framework.common.exception.BaseExceptionInterface; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ResponseCodeEnum implements BaseExceptionInterface { + + // ----------- 通用异常状态码 ----------- + SYSTEM_ERROR("RELATION-10000", "出错啦,后台小哥正在努力修复中..."), + PARAM_NOT_VALID("RELATION-10001", "参数错误"), + + // ----------- 业务异常状态码 ----------- + ; + + // 异常码 + private final String errorCode; + // 错误信息 + private final String errorMsg; + +} \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/exception/GlobalExceptionHandler.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..b705ab3 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/exception/GlobalExceptionHandler.java @@ -0,0 +1,103 @@ +package com.hanserwei.hannote.user.relation.biz.exception; + +import com.hanserwei.framework.common.exception.ApiException; +import com.hanserwei.framework.common.response.Response; +import com.hanserwei.hannote.user.relation.biz.enums.ResponseCodeEnum; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.Optional; + +@SuppressWarnings("LoggingSimilarMessage") +@ControllerAdvice +@Slf4j +public class GlobalExceptionHandler { + + /** + * 捕获自定义业务异常 + * + * @return Response.fail(e) + */ + @ExceptionHandler({ApiException.class}) + @ResponseBody + public Response handleApiException(HttpServletRequest request, ApiException e) { + log.warn("{} request fail, errorCode: {}, errorMessage: {}", request.getRequestURI(), e.getErrorCode(), e.getErrorMsg()); + return Response.fail(e); + } + + /** + * 捕获参数校验异常 + * + * @return Response.fail(errorCode, errorMessage) + */ + @ExceptionHandler({MethodArgumentNotValidException.class}) + @ResponseBody + public Response handleMethodArgumentNotValidException(HttpServletRequest request, MethodArgumentNotValidException e) { + // 参数错误异常码 + String errorCode = ResponseCodeEnum.PARAM_NOT_VALID.getErrorCode(); + + // 获取 BindingResult + BindingResult bindingResult = e.getBindingResult(); + + StringBuilder sb = new StringBuilder(); + + // 获取校验不通过的字段,并组合错误信息,格式为: email 邮箱格式不正确, 当前值: '123124qq.com'; + Optional.of(bindingResult.getFieldErrors()).ifPresent(errors -> { + errors.forEach(error -> + sb.append(error.getField()) + .append(" ") + .append(error.getDefaultMessage()) + .append(", 当前值: '") + .append(error.getRejectedValue()) + .append("'; ") + + ); + }); + + // 错误信息 + String errorMessage = sb.toString(); + + log.warn("{} request error, errorCode: {}, errorMessage: {}", request.getRequestURI(), errorCode, errorMessage); + + return Response.fail(errorCode, errorMessage); + } + + /** + * 捕获 guava 参数校验异常 + * + * @return Response.fail(ResponseCodeEnum.PARAM_NOT_VALID) + */ + @ExceptionHandler({IllegalArgumentException.class}) + @ResponseBody + public Response handleIllegalArgumentException(HttpServletRequest request, IllegalArgumentException e) { + // 参数错误异常码 + String errorCode = ResponseCodeEnum.PARAM_NOT_VALID.getErrorCode(); + + // 错误信息 + String errorMessage = e.getMessage(); + + log.warn("{} request error, errorCode: {}, errorMessage: {}", request.getRequestURI(), errorCode, errorMessage); + + return Response.fail(errorCode, errorMessage); + } + + /** + * 其他类型异常 + * + * @param request 请求 + * @param e 异常 + * @return Response.fail(ResponseCodeEnum.SYSTEM_ERROR) + */ + @ExceptionHandler({Exception.class}) + @ResponseBody + public Response handleOtherException(HttpServletRequest request, Exception e) { + log.error("{} request error, ", request.getRequestURI(), e); + return Response.fail(ResponseCodeEnum.SYSTEM_ERROR); + } +} + diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FansDOService.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FansDOService.java new file mode 100644 index 0000000..c54aaa7 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FansDOService.java @@ -0,0 +1,8 @@ +package com.hanserwei.hannote.user.relation.biz.service; + +import com.hanserwei.hannote.user.relation.biz.domain.dataobject.FansDO; +import com.baomidou.mybatisplus.extension.service.IService; +public interface FansDOService extends IService{ + + +} diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FollowingDOService.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FollowingDOService.java new file mode 100644 index 0000000..9fa027f --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/FollowingDOService.java @@ -0,0 +1,8 @@ +package com.hanserwei.hannote.user.relation.biz.service; + +import com.hanserwei.hannote.user.relation.biz.domain.dataobject.FollowingDO; +import com.baomidou.mybatisplus.extension.service.IService; +public interface FollowingDOService extends IService{ + + +} diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FansDOServiceImpl.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FansDOServiceImpl.java new file mode 100644 index 0000000..8a33a69 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FansDOServiceImpl.java @@ -0,0 +1,13 @@ +package com.hanserwei.hannote.user.relation.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.user.relation.biz.domain.dataobject.FansDO; +import com.hanserwei.hannote.user.relation.biz.domain.mapper.FansDOMapper; +import com.hanserwei.hannote.user.relation.biz.service.FansDOService; +@Service +public class FansDOServiceImpl extends ServiceImpl implements FansDOService{ + +} diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FollowingDOServiceImpl.java b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FollowingDOServiceImpl.java new file mode 100644 index 0000000..d9b15df --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/java/com/hanserwei/hannote/user/relation/biz/service/impl/FollowingDOServiceImpl.java @@ -0,0 +1,13 @@ +package com.hanserwei.hannote.user.relation.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.user.relation.biz.domain.mapper.FollowingDOMapper; +import com.hanserwei.hannote.user.relation.biz.domain.dataobject.FollowingDO; +import com.hanserwei.hannote.user.relation.biz.service.FollowingDOService; +@Service +public class FollowingDOServiceImpl extends ServiceImpl implements FollowingDOService{ + +} diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/resources/application.yml b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/application.yml new file mode 100644 index 0000000..65a3924 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/application.yml @@ -0,0 +1,31 @@ +server: + port: 8089 # 项目启动的端口 + +spring: + profiles: + active: dev # 默认激活 dev 本地开发环境 + servlet: + multipart: + max-file-size: 20MB # 单个文件最大大小 + max-request-size: 100MB # 单次请求最大大小(包含多个文件) + data: + redis: + database: 5 # Redis 数据库索引(默认为 0) + host: 127.0.0.1 # Redis 服务器地址 + port: 6379 # Redis 服务器连接端口 + password: redis # Redis 服务器连接密码(默认为空) + timeout: 5s # 读超时时间 + connect-timeout: 5s # 链接超时时间 + lettuce: + pool: + max-active: 200 # 连接池最大连接数 + max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) + min-idle: 0 # 连接池中的最小空闲连接 + max-idle: 10 # 连接池中的最大空闲连接 +mybatis-plus: + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl + global-config: + banner: false + mapper-locations: classpath*:/mapperxml/*.xml \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/resources/bootstrap.yml b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..a0718f0 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/bootstrap.yml @@ -0,0 +1,12 @@ +spring: + application: + name: han-note-user-relation # 应用名称 + profiles: + active: dev # 默认激活 dev 本地开发环境 + cloud: + nacos: + discovery: + enabled: true # 启用服务发现 + group: DEFAULT_GROUP # 所属组 + namespace: han-note # 命名空间 + server-addr: 127.0.0.1:8848 # 指定 Nacos 配置中心的服务器地址 diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/resources/logback-spring.xml b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..4a0f51f --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/logback-spring.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + ${LOG_FILE}-%i.log + + 30 + + 10MB + + 0 + + false + + + ${LOG_PATTERN} + UTF-8 + + + + + + + 0 + + 256 + + + + + + + + + + + + + + + + + + + + + diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FansDOMapper.xml b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FansDOMapper.xml new file mode 100644 index 0000000..09a4712 --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FansDOMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + id, user_id, fans_user_id, create_time + + \ No newline at end of file diff --git a/han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FollowingDOMapper.xml b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FollowingDOMapper.xml new file mode 100644 index 0000000..b8f37ca --- /dev/null +++ b/han-note-user-relation/han-note-user-relation-biz/src/main/resources/mapperxml/FollowingDOMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + id, user_id, following_user_id, create_time + + \ No newline at end of file diff --git a/han-note-user-relation/pom.xml b/han-note-user-relation/pom.xml new file mode 100644 index 0000000..afbf6fd --- /dev/null +++ b/han-note-user-relation/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + + com.hanserwei + han-note + ${revision} + + + + pom + + + + han-note-user-relation-api + han-note-user-relation-biz + + + han-note-user-relation + + ${project.artifactId} + + 用户关系服务 + + diff --git a/pom.xml b/pom.xml index d0c6ea2..a9daa38 100755 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ han-note-distributed-id-generator han-note-note han-note-note/han-note-note-biz + han-note-user-relation diff --git a/sql/createTable.sql b/sql/createTable.sql index 394b510..1e6521e 100644 --- a/sql/createTable.sql +++ b/sql/createTable.sql @@ -87,7 +87,7 @@ CREATE TABLE `t_role_permission_rel` -- 表:t_channel CREATE TABLE `t_channel` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `name` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '频道名称', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', @@ -100,7 +100,7 @@ CREATE TABLE `t_channel` -- 表:t_topic CREATE TABLE `t_topic` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `name` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '话题名称', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', @@ -116,8 +116,8 @@ CREATE TABLE `t_channel_topic_rel` `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `channel_id` bigint unsigned NOT NULL COMMENT '频道ID', `topic_id` bigint unsigned NOT NULL COMMENT '话题ID', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 @@ -126,20 +126,20 @@ CREATE TABLE `t_channel_topic_rel` -- 表:t_note CREATE TABLE `t_note` ( - `id` bigint unsigned NOT NULL COMMENT '主键ID', + `id` bigint unsigned NOT NULL COMMENT '主键ID', `title` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '标题', `is_content_empty` bit(1) NOT NULL DEFAULT b'0' COMMENT '内容是否为空(0:不为空 1:空)', - `creator_id` bigint unsigned NOT NULL COMMENT '发布者ID', - `topic_id` bigint unsigned DEFAULT NULL COMMENT '话题ID', + `creator_id` bigint unsigned NOT NULL COMMENT '发布者ID', + `topic_id` bigint unsigned DEFAULT NULL COMMENT '话题ID', `topic_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '话题名称', `is_top` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否置顶(0:未置顶 1:置顶)', - `type` tinyint DEFAULT '0' COMMENT '类型(0:图文 1:视频)', + `type` tinyint DEFAULT '0' COMMENT '类型(0:图文 1:视频)', `img_uris` varchar(660) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '笔记图片链接(逗号隔开)', `video_uri` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '视频链接', - `visible` tinyint DEFAULT '0' COMMENT '可见范围(0:公开,所有人可见 1:仅对自己可见)', + `visible` tinyint DEFAULT '0' COMMENT '可见范围(0:公开,所有人可见 1:仅对自己可见)', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', - `status` tinyint NOT NULL DEFAULT '0' COMMENT '状态(0:待审核 1:正常展示 2:被删除(逻辑删除) 3:被下架)', + `status` tinyint NOT NULL DEFAULT '0' COMMENT '状态(0:待审核 1:正常展示 2:被删除(逻辑删除) 3:被下架)', PRIMARY KEY (`id`) USING BTREE, KEY `idx_creator_id` (`creator_id`), KEY `idx_topic_id` (`topic_id`), @@ -148,4 +148,31 @@ CREATE TABLE `t_note` DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT ='笔记表'; -ALTER table t_note add column `content_uuid` varchar(36) DEFAULT '' COMMENT '笔记内容UUID'; +ALTER table t_note + add column `content_uuid` varchar(36) DEFAULT '' COMMENT '笔记内容UUID'; + +CREATE TABLE `t_following` +( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `user_id` bigint unsigned NOT NULL COMMENT '用户ID', + `following_user_id` bigint unsigned NOT NULL COMMENT '关注的用户ID', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_user_id` (`user_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='用户关注表'; + +CREATE TABLE `t_fans` +( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `user_id` bigint unsigned NOT NULL COMMENT '用户ID', + `fans_user_id` bigint unsigned NOT NULL COMMENT '粉丝的用户ID', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_user_id` (`user_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='用户粉丝表'; + +