diff --git a/.gitignore b/.gitignore index 0f2da04..8b40d82 100755 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ build/ /han-note-kv/han-note-kv-biz/src/main/resources/application-dev.yml /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 diff --git a/.idea/encodings.xml b/.idea/encodings.xml index dbc0060..d4b0457 100755 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -17,6 +17,12 @@ + + + + + + diff --git a/han-note-auth/src/main/java/com/hanserwei/hannote/auth/HanNoteAuthApplication.java b/han-note-auth/src/main/java/com/hanserwei/hannote/auth/HannoteAuthApplication.java similarity index 78% rename from han-note-auth/src/main/java/com/hanserwei/hannote/auth/HanNoteAuthApplication.java rename to han-note-auth/src/main/java/com/hanserwei/hannote/auth/HannoteAuthApplication.java index 65c7b9a..d7400f5 100755 --- a/han-note-auth/src/main/java/com/hanserwei/hannote/auth/HanNoteAuthApplication.java +++ b/han-note-auth/src/main/java/com/hanserwei/hannote/auth/HannoteAuthApplication.java @@ -6,10 +6,10 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableFeignClients(basePackages = "com.hanserwei.hannote") -public class HanNoteAuthApplication { +public class HannoteAuthApplication { public static void main(String[] args) { - SpringApplication.run(HanNoteAuthApplication.class, args); + SpringApplication.run(HannoteAuthApplication.class, args); } } diff --git a/han-note-auth/src/main/resources/application.yml b/han-note-auth/src/main/resources/application.yml index 6ea4bd3..b848c13 100755 --- a/han-note-auth/src/main/resources/application.yml +++ b/han-note-auth/src/main/resources/application.yml @@ -3,12 +3,6 @@ spring: name: han-note-auth profiles: active: dev # 默认激活 dev 本地开发环境 - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver # 指定数据库驱动类 - # 数据库连接信息 - url: ${spring.datasource.url} - username: ${spring.datasource.username} # 数据库用户名 - password: ${spring.datasource.password} # 数据库密码 data: redis: database: 5 # Redis 数据库索引(默认为 0) diff --git a/han-note-note/han-note-note-api/pom.xml b/han-note-note/han-note-note-api/pom.xml new file mode 100644 index 0000000..19bad48 --- /dev/null +++ b/han-note-note/han-note-note-api/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + + com.hanserwei + han-note-note + ${revision} + + + + jar + + han-note-api + ${project.artifactId} + RPC层, 供其他服务调用 + + + + com.hanserwei + hanserwei-common + + + diff --git a/han-note-note/han-note-note-biz/pom.xml b/han-note-note/han-note-note-biz/pom.xml new file mode 100644 index 0000000..1b8aa87 --- /dev/null +++ b/han-note-note/han-note-note-biz/pom.xml @@ -0,0 +1,105 @@ + + 4.0.0 + + + com.hanserwei + han-note-note + ${revision} + + + + jar + + han-note-note-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 + + + + + com.baomidou + mybatis-plus-spring-boot3-starter + + + + + com.mysql + mysql-connector-j + + + + + com.alibaba + druid-spring-boot-3-starter + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + org.apache.commons + commons-pool2 + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/HannoteNoteBizApplication.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/HannoteNoteBizApplication.java new file mode 100644 index 0000000..6087c23 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/HannoteNoteBizApplication.java @@ -0,0 +1,11 @@ +package com.hanserwei.hannote.note.biz; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HannoteNoteBizApplication { + public static void main(String[] args) { + SpringApplication.run(HannoteNoteBizApplication.class, args); + } +} diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/config/RedisTemplateConfig.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/config/RedisTemplateConfig.java new file mode 100644 index 0000000..001d97c --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/config/RedisTemplateConfig.java @@ -0,0 +1,31 @@ +package com.hanserwei.hannote.note.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-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/ChannelDO.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/ChannelDO.java new file mode 100644 index 0000000..2f459d5 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/ChannelDO.java @@ -0,0 +1,49 @@ +package com.hanserwei.hannote.note.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 java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 频道表 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "t_channel") +public class ChannelDO { + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 频道名称 + */ + @TableField(value = "`name`") + private String name; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + private Date createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time") + private Date updateTime; + + /** + * 逻辑删除(0:未删除 1:已删除) + */ + @TableField(value = "is_deleted") + private Boolean isDeleted; +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/ChannelTopicRelDO.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/ChannelTopicRelDO.java new file mode 100644 index 0000000..b311fbc --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/ChannelTopicRelDO.java @@ -0,0 +1,49 @@ +package com.hanserwei.hannote.note.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 java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 频道-话题关联表 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "t_channel_topic_rel") +public class ChannelTopicRelDO { + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 频道ID + */ + @TableField(value = "channel_id") + private Long channelId; + + /** + * 话题ID + */ + @TableField(value = "topic_id") + private Long topicId; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + private Date createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time") + private Date updateTime; +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/NoteDO.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/NoteDO.java new file mode 100644 index 0000000..a46c3a4 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/NoteDO.java @@ -0,0 +1,103 @@ +package com.hanserwei.hannote.note.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 java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 笔记表 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "t_note") +public class NoteDO { + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 标题 + */ + @TableField(value = "title") + private String title; + + /** + * 内容是否为空(0:不为空 1:空) + */ + @TableField(value = "is_content_empty") + private Boolean isContentEmpty; + + /** + * 发布者ID + */ + @TableField(value = "creator_id") + private Long creatorId; + + /** + * 话题ID + */ + @TableField(value = "topic_id") + private Long topicId; + + /** + * 话题名称 + */ + @TableField(value = "topic_name") + private String topicName; + + /** + * 是否置顶(0:未置顶 1:置顶) + */ + @TableField(value = "is_top") + private Boolean isTop; + + /** + * 类型(0:图文 1:视频) + */ + @TableField(value = "`type`") + private Byte type; + + /** + * 笔记图片链接(逗号隔开) + */ + @TableField(value = "img_uris") + private String imgUris; + + /** + * 视频链接 + */ + @TableField(value = "video_uri") + private String videoUri; + + /** + * 可见范围(0:公开,所有人可见 1:仅对自己可见) + */ + @TableField(value = "visible") + private Byte visible; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + private Date createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time") + private Date updateTime; + + /** + * 状态(0:待审核 1:正常展示 2:被删除(逻辑删除) 3:被下架) + */ + @TableField(value = "`status`") + private Byte status; +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/TopicDO.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/TopicDO.java new file mode 100644 index 0000000..00635eb --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/dataobject/TopicDO.java @@ -0,0 +1,49 @@ +package com.hanserwei.hannote.note.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 java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 话题表 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "t_topic") +public class TopicDO { + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 话题名称 + */ + @TableField(value = "`name`") + private String name; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + private Date createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time") + private Date updateTime; + + /** + * 逻辑删除(0:未删除 1:已删除) + */ + @TableField(value = "is_deleted") + private Boolean isDeleted; +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/ChannelDOMapper.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/ChannelDOMapper.java new file mode 100644 index 0000000..bb4d210 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/ChannelDOMapper.java @@ -0,0 +1,7 @@ +package com.hanserwei.hannote.note.biz.domain.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hanserwei.hannote.note.biz.domain.dataobject.ChannelDO; + +public interface ChannelDOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/ChannelTopicRelDOMapper.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/ChannelTopicRelDOMapper.java new file mode 100644 index 0000000..2f26c5e --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/ChannelTopicRelDOMapper.java @@ -0,0 +1,7 @@ +package com.hanserwei.hannote.note.biz.domain.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hanserwei.hannote.note.biz.domain.dataobject.ChannelTopicRelDO; + +public interface ChannelTopicRelDOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/NoteDOMapper.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/NoteDOMapper.java new file mode 100644 index 0000000..f4b1df1 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/NoteDOMapper.java @@ -0,0 +1,7 @@ +package com.hanserwei.hannote.note.biz.domain.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hanserwei.hannote.note.biz.domain.dataobject.NoteDO; + +public interface NoteDOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/TopicDOMapper.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/TopicDOMapper.java new file mode 100644 index 0000000..6592009 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/domain/mapper/TopicDOMapper.java @@ -0,0 +1,7 @@ +package com.hanserwei.hannote.note.biz.domain.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hanserwei.hannote.note.biz.domain.dataobject.TopicDO; + +public interface TopicDOMapper extends BaseMapper { +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteStatusEnum.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteStatusEnum.java new file mode 100644 index 0000000..19e8855 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteStatusEnum.java @@ -0,0 +1,18 @@ +package com.hanserwei.hannote.note.biz.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum NoteStatusEnum { + + BE_EXAMINE(0), // 待审核 + NORMAL(1), // 正常展示 + DELETED(2), // 被删除 + DOWNED(3), // 被下架 + ; + + private final Integer code; + +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteTypeEnum.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteTypeEnum.java new file mode 100644 index 0000000..727dcaa --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteTypeEnum.java @@ -0,0 +1,48 @@ +package com.hanserwei.hannote.note.biz.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Objects; + +@Getter +@AllArgsConstructor +public enum NoteTypeEnum { + + IMAGE_TEXT(0, "图文"), + VIDEO(1, "视频"); + + private final Integer code; + private final String description; + + /** + * 类型是否有效 + * + * @param code 类型 code + * @return 是否有效 + */ + public static boolean isValid(Integer code) { + for (NoteTypeEnum noteTypeEnum : NoteTypeEnum.values()) { + if (Objects.equals(code, noteTypeEnum.getCode())) { + return true; + } + } + return false; + } + + /** + * 根据类型 code 获取对应的枚举 + * + * @param code 类型 code + * @return 对应的枚举 + */ + public static NoteTypeEnum valueOf(Integer code) { + for (NoteTypeEnum noteTypeEnum : NoteTypeEnum.values()) { + if (Objects.equals(code, noteTypeEnum.getCode())) { + return noteTypeEnum; + } + } + return null; + } + +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteVisibleEnum.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteVisibleEnum.java new file mode 100644 index 0000000..46c232d --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/NoteVisibleEnum.java @@ -0,0 +1,15 @@ +package com.hanserwei.hannote.note.biz.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum NoteVisibleEnum { + + PUBLIC(0), // 公开,所有人可见 + PRIVATE(1); // 仅自己可见 + + private final Integer code; + +} diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java new file mode 100644 index 0000000..093916d --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java @@ -0,0 +1,23 @@ +package com.hanserwei.hannote.note.biz.enums; + +import com.hanserwei.framework.common.exception.BaseExceptionInterface; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ResponseCodeEnum implements BaseExceptionInterface { + + // ----------- 通用异常状态码 ----------- + SYSTEM_ERROR("NOTE-10000", "出错啦,后台小哥正在努力修复中..."), + PARAM_NOT_VALID("NOTE-10001", "参数错误"), + + // ----------- 业务异常状态码 ----------- + ; + + // 异常码 + private final String errorCode; + // 错误信息 + private final String errorMsg; + +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/exception/GlobalExceptionHandler.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..090c3db --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/exception/GlobalExceptionHandler.java @@ -0,0 +1,103 @@ +package com.hanserwei.hannote.note.biz.exception; + +import com.hanserwei.framework.common.exception.ApiException; +import com.hanserwei.framework.common.response.Response; +import com.hanserwei.hannote.note.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-note/han-note-note-biz/src/main/resources/application.yml b/han-note-note/han-note-note-biz/src/main/resources/application.yml new file mode 100644 index 0000000..2d05f08 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/resources/application.yml @@ -0,0 +1,17 @@ +server: + port: 8086 # 项目启动的端口 + +spring: + profiles: + active: dev # 默认激活 dev 本地开发环境 + servlet: + multipart: + max-file-size: 20MB # 单个文件最大大小 + max-request-size: 100MB # 单次请求最大大小(包含多个文件) +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-note/han-note-note-biz/src/main/resources/bootstrap.yml b/han-note-note/han-note-note-biz/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..c88a1c3 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/resources/bootstrap.yml @@ -0,0 +1,12 @@ +spring: + application: + name: han-note-note # 应用名称 + 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-note/han-note-note-biz/src/main/resources/logback-spring.xml b/han-note-note/han-note-note-biz/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..11ccd3a --- /dev/null +++ b/han-note-note/han-note-note-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-note/han-note-note-biz/src/main/resources/mapperxml/ChannelDOMapper.xml b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/ChannelDOMapper.xml new file mode 100644 index 0000000..f76829f --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/ChannelDOMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + id, `name`, create_time, update_time, is_deleted + + \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/resources/mapperxml/ChannelTopicRelDOMapper.xml b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/ChannelTopicRelDOMapper.xml new file mode 100644 index 0000000..dd82c7f --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/ChannelTopicRelDOMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + id, channel_id, topic_id, create_time, update_time + + \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/resources/mapperxml/NoteDOMapper.xml b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/NoteDOMapper.xml new file mode 100644 index 0000000..a03020b --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/NoteDOMapper.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + id, title, is_content_empty, creator_id, topic_id, topic_name, is_top, `type`, img_uris, + video_uri, visible, create_time, update_time, `status` + + \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/resources/mapperxml/TopicDOMapper.xml b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/TopicDOMapper.xml new file mode 100644 index 0000000..ebfd7c0 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/resources/mapperxml/TopicDOMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + id, `name`, create_time, update_time, is_deleted + + \ No newline at end of file diff --git a/han-note-note/pom.xml b/han-note-note/pom.xml new file mode 100644 index 0000000..4867672 --- /dev/null +++ b/han-note-note/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + + com.hanserwei + han-note + ${revision} + + + + pom + + + + han-note-note-api + + + han-note-note + + ${project.artifactId} + + 笔记服务 + diff --git a/pom.xml b/pom.xml index 16d94b8..33a239d 100755 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,8 @@ han-note-user han-note-kv han-note-distributed-id-generator + han-note-note + han-note-note/han-note-note-biz diff --git a/sql/createTable.sql b/sql/createTable.sql index 806d452..4c8e2c3 100644 --- a/sql/createTable.sql +++ b/sql/createTable.sql @@ -84,3 +84,66 @@ CREATE TABLE `t_role_permission_rel` COLLATE = utf8mb4_unicode_ci COMMENT ='用户权限表'; +-- 表:t_channel +CREATE TABLE `t_channel` +( + `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 '更新时间', + `is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0:未删除 1:已删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='频道表'; + +-- 表:t_topic +CREATE TABLE `t_topic` +( + `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 '更新时间', + `is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0:未删除 1:已删除)', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='话题表'; + +-- 表:t_channel_topic_rel +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 '更新时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='频道-话题关联表'; + +-- 表:t_note +CREATE TABLE `t_note` +( + `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', + `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:视频)', + `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:仅对自己可见)', + `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:被下架)', + PRIMARY KEY (`id`) USING BTREE, + KEY `idx_creator_id` (`creator_id`), + KEY `idx_topic_id` (`topic_id`), + KEY `idx_status` (`status`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='笔记表'; \ No newline at end of file