mirror of
https://github.com/201206030/novel-cloud.git
synced 2025-06-27 23:16:39 +00:00
refactor: 基于 novel 项目 & Spring Cloud 2022 & Spring Cloud Alibaba 2022 重构
This commit is contained in:
36
novel-author/novel-author-service/pom.xml
Normal file
36
novel-author/novel-author-service/pom.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>novel-author</artifactId>
|
||||
<groupId>io.github.xxyopen</groupId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>novel-author-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.github.xxyopen</groupId>
|
||||
<artifactId>novel-author-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.xxyopen</groupId>
|
||||
<artifactId>novel-book-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.xxyopen</groupId>
|
||||
<artifactId>novel-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
package io.github.xxyopen.novel.author;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {"io.github.xxyopen.novel"})
|
||||
@MapperScan("io.github.xxyopen.novel.author.dao.mapper")
|
||||
@EnableCaching
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = {"io.github.xxyopen.novel.book.feign"})
|
||||
public class NovelAuthorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NovelAuthorApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package io.github.xxyopen.novel.author.config;
|
||||
|
||||
import io.github.xxyopen.novel.author.dto.AuthorInfoDto;
|
||||
import io.github.xxyopen.novel.author.manager.cache.AuthorInfoCacheManager;
|
||||
import io.github.xxyopen.novel.common.auth.JwtUtils;
|
||||
import io.github.xxyopen.novel.common.auth.UserHolder;
|
||||
import io.github.xxyopen.novel.common.constant.ErrorCodeEnum;
|
||||
import io.github.xxyopen.novel.common.constant.SystemConfigConsts;
|
||||
import io.github.xxyopen.novel.config.exception.BusinessException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 认证授权 拦截器:为了注入其它的 Spring beans,需要通过 @Component 注解将该拦截器注册到 Spring 上下文
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/18
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AuthInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final AuthorInfoCacheManager authorInfoCacheManager;
|
||||
|
||||
/**
|
||||
* handle 执行前调用
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
// 获取登录 JWT
|
||||
String token = request.getHeader(SystemConfigConsts.HTTP_AUTH_HEADER_NAME);
|
||||
|
||||
// 开始认证
|
||||
if (!StringUtils.hasText(token)) {
|
||||
// token 为空
|
||||
throw new BusinessException(ErrorCodeEnum.USER_LOGIN_EXPIRED);
|
||||
}
|
||||
Long userId = JwtUtils.parseToken(token, SystemConfigConsts.NOVEL_FRONT_KEY);
|
||||
if (Objects.isNull(userId)) {
|
||||
// token 解析失败
|
||||
throw new BusinessException(ErrorCodeEnum.USER_LOGIN_EXPIRED);
|
||||
}
|
||||
// 作家权限认证
|
||||
AuthorInfoDto authorInfo = authorInfoCacheManager.getAuthor(userId);
|
||||
if (Objects.isNull(authorInfo)) {
|
||||
// 作家账号不存在,无权访问作家专区
|
||||
throw new BusinessException(ErrorCodeEnum.USER_UN_AUTH);
|
||||
}
|
||||
|
||||
// 设置作家ID到当前线程
|
||||
UserHolder.setAuthorId(authorInfo.getId());
|
||||
// 设置 userId 到当前线程
|
||||
UserHolder.setUserId(userId);
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* handler 执行后调用,出现异常不调用
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
ModelAndView modelAndView) throws Exception {
|
||||
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
|
||||
}
|
||||
|
||||
/**
|
||||
* DispatcherServlet 完全处理完请求后调用,出现异常照常调用
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
// 清理当前线程保存的用户数据
|
||||
UserHolder.clear();
|
||||
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package io.github.xxyopen.novel.author.config;
|
||||
|
||||
import io.github.xxyopen.novel.common.constant.ApiRouterConsts;
|
||||
import io.github.xxyopen.novel.config.interceptor.TokenParseInterceptor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Spring Web Mvc 相关配置不要加 @EnableWebMvc 注解,否则会导致 jackson 的全局配置失效。因为 @EnableWebMvc 注解会导致 WebMvcAutoConfiguration 自动配置失效
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/18
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
private final AuthInterceptor authInterceptor;
|
||||
|
||||
private final TokenParseInterceptor tokenParseInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
// 权限认证拦截
|
||||
registry.addInterceptor(authInterceptor)
|
||||
// 拦截作家后台相关请求接口
|
||||
.addPathPatterns(
|
||||
ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/**")
|
||||
// 放行注册相关请求接口
|
||||
.excludePathPatterns(ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/register",
|
||||
ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/status")
|
||||
.order(2);
|
||||
|
||||
// Token 解析
|
||||
registry.addInterceptor(tokenParseInterceptor)
|
||||
.addPathPatterns(
|
||||
ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/register", ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/status")
|
||||
.order(3);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package io.github.xxyopen.novel.author.controller.author;
|
||||
|
||||
import io.github.xxyopen.novel.author.dto.req.AuthorRegisterReqDto;
|
||||
import io.github.xxyopen.novel.author.manager.feign.BookFeignManager;
|
||||
import io.github.xxyopen.novel.author.service.AuthorService;
|
||||
import io.github.xxyopen.novel.book.dto.req.BookAddReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.req.BookPageReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.req.ChapterAddReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.req.ChapterPageReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.resp.BookChapterRespDto;
|
||||
import io.github.xxyopen.novel.book.dto.resp.BookInfoRespDto;
|
||||
import io.github.xxyopen.novel.common.auth.UserHolder;
|
||||
import io.github.xxyopen.novel.common.constant.ApiRouterConsts;
|
||||
import io.github.xxyopen.novel.common.constant.SystemConfigConsts;
|
||||
import io.github.xxyopen.novel.common.req.PageReqDto;
|
||||
import io.github.xxyopen.novel.common.resp.PageRespDto;
|
||||
import io.github.xxyopen.novel.common.resp.RestResp;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 作家后台-作家模块 API 控制器
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/23
|
||||
*/
|
||||
@Tag(name = "AuthorController", description = "作家后台-作者模块")
|
||||
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
|
||||
@RestController
|
||||
@RequestMapping(ApiRouterConsts.API_AUTHOR_URL_PREFIX)
|
||||
@RequiredArgsConstructor
|
||||
public class AuthorController {
|
||||
|
||||
private final AuthorService authorService;
|
||||
|
||||
private final BookFeignManager bookFeignManager;
|
||||
|
||||
/**
|
||||
* 作家注册接口
|
||||
*/
|
||||
@Operation(summary = "作家注册接口")
|
||||
@PostMapping("register")
|
||||
public RestResp<Void> register(@Valid @RequestBody AuthorRegisterReqDto dto) {
|
||||
dto.setUserId(UserHolder.getUserId());
|
||||
return authorService.register(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询作家状态接口
|
||||
*/
|
||||
@Operation(summary = "作家状态查询接口")
|
||||
@GetMapping("status")
|
||||
public RestResp<Integer> getStatus() {
|
||||
return authorService.getStatus(UserHolder.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说发布接口
|
||||
*/
|
||||
@Operation(summary = "小说发布接口")
|
||||
@PostMapping("book")
|
||||
public RestResp<Void> publishBook(@Valid @RequestBody BookAddReqDto dto) {
|
||||
return bookFeignManager.publishBook(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说发布列表查询接口
|
||||
*/
|
||||
@Operation(summary = "小说发布列表查询接口")
|
||||
@GetMapping("books")
|
||||
public RestResp<PageRespDto<BookInfoRespDto>> listBooks(@ParameterObject BookPageReqDto dto) {
|
||||
dto.setAuthorId(UserHolder.getAuthorId());
|
||||
return bookFeignManager.listPublishBooks(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说章节发布接口
|
||||
*/
|
||||
@Operation(summary = "小说章节发布接口")
|
||||
@PostMapping("book/chapter/{bookId}")
|
||||
public RestResp<Void> publishBookChapter(
|
||||
@Parameter(description = "小说ID") @PathVariable("bookId") Long bookId,
|
||||
@Valid @RequestBody ChapterAddReqDto dto) {
|
||||
dto.setAuthorId(UserHolder.getAuthorId());
|
||||
dto.setBookId(bookId);
|
||||
return bookFeignManager.publishBookChapter(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说章节发布列表查询接口
|
||||
*/
|
||||
@Operation(summary = "小说章节发布列表查询接口")
|
||||
@GetMapping("book/chapters/{bookId}")
|
||||
public RestResp<PageRespDto<BookChapterRespDto>> listBookChapters(
|
||||
@Parameter(description = "小说ID") @PathVariable("bookId") Long bookId,
|
||||
@ParameterObject PageReqDto dto) {
|
||||
ChapterPageReqDto chapterPageReqReqDto = new ChapterPageReqDto();
|
||||
chapterPageReqReqDto.setBookId(bookId);
|
||||
chapterPageReqReqDto.setPageNum(dto.getPageNum());
|
||||
chapterPageReqReqDto.setPageSize(dto.getPageSize());
|
||||
return bookFeignManager.listPublishBookChapters(chapterPageReqReqDto);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package io.github.xxyopen.novel.author.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 作家邀请码
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
@TableName("author_code")
|
||||
public class AuthorCode implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 邀请码
|
||||
*/
|
||||
private String inviteCode;
|
||||
|
||||
/**
|
||||
* 有效时间
|
||||
*/
|
||||
private LocalDateTime validityTime;
|
||||
|
||||
/**
|
||||
* 是否使用过;0-未使用 1-使用过
|
||||
*/
|
||||
private Integer isUsed;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getInviteCode() {
|
||||
return inviteCode;
|
||||
}
|
||||
|
||||
public void setInviteCode(String inviteCode) {
|
||||
this.inviteCode = inviteCode;
|
||||
}
|
||||
|
||||
public LocalDateTime getValidityTime() {
|
||||
return validityTime;
|
||||
}
|
||||
|
||||
public void setValidityTime(LocalDateTime validityTime) {
|
||||
this.validityTime = validityTime;
|
||||
}
|
||||
|
||||
public Integer getIsUsed() {
|
||||
return isUsed;
|
||||
}
|
||||
|
||||
public void setIsUsed(Integer isUsed) {
|
||||
this.isUsed = isUsed;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthorCode{" +
|
||||
"id=" + id +
|
||||
", inviteCode=" + inviteCode +
|
||||
", validityTime=" + validityTime +
|
||||
", isUsed=" + isUsed +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -0,0 +1,185 @@
|
||||
package io.github.xxyopen.novel.author.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 稿费收入统计
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
@TableName("author_income")
|
||||
public class AuthorIncome implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 作家ID
|
||||
*/
|
||||
private Long authorId;
|
||||
|
||||
/**
|
||||
* 小说ID
|
||||
*/
|
||||
private Long bookId;
|
||||
|
||||
/**
|
||||
* 收入月份
|
||||
*/
|
||||
private LocalDate incomeMonth;
|
||||
|
||||
/**
|
||||
* 税前收入;单位:分
|
||||
*/
|
||||
private Integer preTaxIncome;
|
||||
|
||||
/**
|
||||
* 税后收入;单位:分
|
||||
*/
|
||||
private Integer afterTaxIncome;
|
||||
|
||||
/**
|
||||
* 支付状态;0-待支付 1-已支付
|
||||
*/
|
||||
private Integer payStatus;
|
||||
|
||||
/**
|
||||
* 稿费确认状态;0-待确认 1-已确认
|
||||
*/
|
||||
private Integer confirmStatus;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
private String detail;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getAuthorId() {
|
||||
return authorId;
|
||||
}
|
||||
|
||||
public void setAuthorId(Long authorId) {
|
||||
this.authorId = authorId;
|
||||
}
|
||||
|
||||
public Long getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(Long bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public LocalDate getIncomeMonth() {
|
||||
return incomeMonth;
|
||||
}
|
||||
|
||||
public void setIncomeMonth(LocalDate incomeMonth) {
|
||||
this.incomeMonth = incomeMonth;
|
||||
}
|
||||
|
||||
public Integer getPreTaxIncome() {
|
||||
return preTaxIncome;
|
||||
}
|
||||
|
||||
public void setPreTaxIncome(Integer preTaxIncome) {
|
||||
this.preTaxIncome = preTaxIncome;
|
||||
}
|
||||
|
||||
public Integer getAfterTaxIncome() {
|
||||
return afterTaxIncome;
|
||||
}
|
||||
|
||||
public void setAfterTaxIncome(Integer afterTaxIncome) {
|
||||
this.afterTaxIncome = afterTaxIncome;
|
||||
}
|
||||
|
||||
public Integer getPayStatus() {
|
||||
return payStatus;
|
||||
}
|
||||
|
||||
public void setPayStatus(Integer payStatus) {
|
||||
this.payStatus = payStatus;
|
||||
}
|
||||
|
||||
public Integer getConfirmStatus() {
|
||||
return confirmStatus;
|
||||
}
|
||||
|
||||
public void setConfirmStatus(Integer confirmStatus) {
|
||||
this.confirmStatus = confirmStatus;
|
||||
}
|
||||
|
||||
public String getDetail() {
|
||||
return detail;
|
||||
}
|
||||
|
||||
public void setDetail(String detail) {
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthorIncome{" +
|
||||
"id=" + id +
|
||||
", authorId=" + authorId +
|
||||
", bookId=" + bookId +
|
||||
", incomeMonth=" + incomeMonth +
|
||||
", preTaxIncome=" + preTaxIncome +
|
||||
", afterTaxIncome=" + afterTaxIncome +
|
||||
", payStatus=" + payStatus +
|
||||
", confirmStatus=" + confirmStatus +
|
||||
", detail=" + detail +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package io.github.xxyopen.novel.author.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 稿费收入明细统计
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
@TableName("author_income_detail")
|
||||
public class AuthorIncomeDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 作家ID
|
||||
*/
|
||||
private Long authorId;
|
||||
|
||||
/**
|
||||
* 小说ID;0表示全部作品
|
||||
*/
|
||||
private Long bookId;
|
||||
|
||||
/**
|
||||
* 收入日期
|
||||
*/
|
||||
private LocalDate incomeDate;
|
||||
|
||||
/**
|
||||
* 订阅总额
|
||||
*/
|
||||
private Integer incomeAccount;
|
||||
|
||||
/**
|
||||
* 订阅次数
|
||||
*/
|
||||
private Integer incomeCount;
|
||||
|
||||
/**
|
||||
* 订阅人数
|
||||
*/
|
||||
private Integer incomeNumber;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getAuthorId() {
|
||||
return authorId;
|
||||
}
|
||||
|
||||
public void setAuthorId(Long authorId) {
|
||||
this.authorId = authorId;
|
||||
}
|
||||
|
||||
public Long getBookId() {
|
||||
return bookId;
|
||||
}
|
||||
|
||||
public void setBookId(Long bookId) {
|
||||
this.bookId = bookId;
|
||||
}
|
||||
|
||||
public LocalDate getIncomeDate() {
|
||||
return incomeDate;
|
||||
}
|
||||
|
||||
public void setIncomeDate(LocalDate incomeDate) {
|
||||
this.incomeDate = incomeDate;
|
||||
}
|
||||
|
||||
public Integer getIncomeAccount() {
|
||||
return incomeAccount;
|
||||
}
|
||||
|
||||
public void setIncomeAccount(Integer incomeAccount) {
|
||||
this.incomeAccount = incomeAccount;
|
||||
}
|
||||
|
||||
public Integer getIncomeCount() {
|
||||
return incomeCount;
|
||||
}
|
||||
|
||||
public void setIncomeCount(Integer incomeCount) {
|
||||
this.incomeCount = incomeCount;
|
||||
}
|
||||
|
||||
public Integer getIncomeNumber() {
|
||||
return incomeNumber;
|
||||
}
|
||||
|
||||
public void setIncomeNumber(Integer incomeNumber) {
|
||||
this.incomeNumber = incomeNumber;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthorIncomeDetail{" +
|
||||
"id=" + id +
|
||||
", authorId=" + authorId +
|
||||
", bookId=" + bookId +
|
||||
", incomeDate=" + incomeDate +
|
||||
", incomeAccount=" + incomeAccount +
|
||||
", incomeCount=" + incomeCount +
|
||||
", incomeNumber=" + incomeNumber +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
package io.github.xxyopen.novel.author.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 作者信息
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
@TableName("author_info")
|
||||
public class AuthorInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 邀请码
|
||||
*/
|
||||
private String inviteCode;
|
||||
|
||||
/**
|
||||
* 笔名
|
||||
*/
|
||||
private String penName;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String telPhone;
|
||||
|
||||
/**
|
||||
* QQ或微信账号
|
||||
*/
|
||||
private String chatAccount;
|
||||
|
||||
/**
|
||||
* 电子邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 作品方向;0-男频 1-女频
|
||||
*/
|
||||
private Integer workDirection;
|
||||
|
||||
/**
|
||||
* 0:正常;1-封禁
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getInviteCode() {
|
||||
return inviteCode;
|
||||
}
|
||||
|
||||
public void setInviteCode(String inviteCode) {
|
||||
this.inviteCode = inviteCode;
|
||||
}
|
||||
|
||||
public String getPenName() {
|
||||
return penName;
|
||||
}
|
||||
|
||||
public void setPenName(String penName) {
|
||||
this.penName = penName;
|
||||
}
|
||||
|
||||
public String getTelPhone() {
|
||||
return telPhone;
|
||||
}
|
||||
|
||||
public void setTelPhone(String telPhone) {
|
||||
this.telPhone = telPhone;
|
||||
}
|
||||
|
||||
public String getChatAccount() {
|
||||
return chatAccount;
|
||||
}
|
||||
|
||||
public void setChatAccount(String chatAccount) {
|
||||
this.chatAccount = chatAccount;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Integer getWorkDirection() {
|
||||
return workDirection;
|
||||
}
|
||||
|
||||
public void setWorkDirection(Integer workDirection) {
|
||||
this.workDirection = workDirection;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthorInfo{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", inviteCode=" + inviteCode +
|
||||
", penName=" + penName +
|
||||
", telPhone=" + telPhone +
|
||||
", chatAccount=" + chatAccount +
|
||||
", email=" + email +
|
||||
", workDirection=" + workDirection +
|
||||
", status=" + status +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.github.xxyopen.novel.author.dao.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import io.github.xxyopen.novel.author.dao.entity.AuthorCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 作家邀请码 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
public interface AuthorCodeMapper extends BaseMapper<AuthorCode> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.github.xxyopen.novel.author.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import io.github.xxyopen.novel.author.dao.entity.AuthorIncomeDetail;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 稿费收入明细统计 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
public interface AuthorIncomeDetailMapper extends BaseMapper<AuthorIncomeDetail> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.github.xxyopen.novel.author.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import io.github.xxyopen.novel.author.dao.entity.AuthorIncome;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 稿费收入统计 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
public interface AuthorIncomeMapper extends BaseMapper<AuthorIncome> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package io.github.xxyopen.novel.author.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import io.github.xxyopen.novel.author.dao.entity.AuthorInfo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 作者信息 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/05/11
|
||||
*/
|
||||
public interface AuthorInfoMapper extends BaseMapper<AuthorInfo> {
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package io.github.xxyopen.novel.author.manager.cache;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.github.xxyopen.novel.author.dao.entity.AuthorInfo;
|
||||
import io.github.xxyopen.novel.author.dao.mapper.AuthorInfoMapper;
|
||||
import io.github.xxyopen.novel.author.dto.AuthorInfoDto;
|
||||
import io.github.xxyopen.novel.common.constant.CacheConsts;
|
||||
import io.github.xxyopen.novel.common.constant.DatabaseConsts;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 作家信息 缓存管理类
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/12
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AuthorInfoCacheManager {
|
||||
|
||||
private final AuthorInfoMapper authorInfoMapper;
|
||||
|
||||
/**
|
||||
* 查询作家信息,并放入缓存中
|
||||
*/
|
||||
@Cacheable(cacheManager = CacheConsts.REDIS_CACHE_MANAGER,
|
||||
value = CacheConsts.AUTHOR_INFO_CACHE_NAME, unless = "#result == null")
|
||||
public AuthorInfoDto getAuthor(Long userId) {
|
||||
QueryWrapper<AuthorInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper
|
||||
.eq(DatabaseConsts.AuthorInfoTable.COLUMN_USER_ID, userId)
|
||||
.last(DatabaseConsts.SqlEnum.LIMIT_1.getSql());
|
||||
AuthorInfo authorInfo = authorInfoMapper.selectOne(queryWrapper);
|
||||
if (Objects.isNull(authorInfo)) {
|
||||
return null;
|
||||
}
|
||||
return AuthorInfoDto.builder()
|
||||
.id(authorInfo.getId())
|
||||
.penName(authorInfo.getPenName())
|
||||
.status(authorInfo.getStatus()).build();
|
||||
}
|
||||
|
||||
@CacheEvict(cacheManager = CacheConsts.REDIS_CACHE_MANAGER,
|
||||
value = CacheConsts.AUTHOR_INFO_CACHE_NAME)
|
||||
public void evictAuthorCache() {
|
||||
// 调用此方法自动清除作家信息的缓存
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package io.github.xxyopen.novel.author.manager.feign;
|
||||
|
||||
import io.github.xxyopen.novel.author.dto.AuthorInfoDto;
|
||||
import io.github.xxyopen.novel.author.manager.cache.AuthorInfoCacheManager;
|
||||
import io.github.xxyopen.novel.book.dto.req.BookAddReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.req.BookPageReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.req.ChapterAddReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.req.ChapterPageReqDto;
|
||||
import io.github.xxyopen.novel.book.dto.resp.BookChapterRespDto;
|
||||
import io.github.xxyopen.novel.book.dto.resp.BookEsRespDto;
|
||||
import io.github.xxyopen.novel.book.dto.resp.BookInfoRespDto;
|
||||
import io.github.xxyopen.novel.book.feign.BookFeign;
|
||||
import io.github.xxyopen.novel.common.auth.UserHolder;
|
||||
import io.github.xxyopen.novel.common.constant.ErrorCodeEnum;
|
||||
import io.github.xxyopen.novel.common.req.PageReqDto;
|
||||
import io.github.xxyopen.novel.common.resp.PageRespDto;
|
||||
import io.github.xxyopen.novel.common.resp.RestResp;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 小说微服务调用 Feign 客户端管理
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2023/3/29
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class BookFeignManager {
|
||||
|
||||
private final BookFeign bookFeign;
|
||||
|
||||
private final AuthorInfoCacheManager authorInfoCacheManager;
|
||||
|
||||
public RestResp<Void> publishBook(BookAddReqDto dto) {
|
||||
AuthorInfoDto author = authorInfoCacheManager.getAuthor(UserHolder.getUserId());
|
||||
dto.setAuthorId(author.getId());
|
||||
dto.setPenName(author.getPenName());
|
||||
return bookFeign.publishBook(dto);
|
||||
}
|
||||
|
||||
public RestResp<PageRespDto<BookInfoRespDto>> listPublishBooks(BookPageReqDto dto) {
|
||||
authorInfoCacheManager.getAuthor(UserHolder.getUserId());
|
||||
return bookFeign.listPublishBooks(dto);
|
||||
}
|
||||
|
||||
public RestResp<Void> publishBookChapter(ChapterAddReqDto dto) {
|
||||
return bookFeign.publishBookChapter(dto);
|
||||
}
|
||||
|
||||
public RestResp<PageRespDto<BookChapterRespDto>> listPublishBookChapters(ChapterPageReqDto dto) {
|
||||
return bookFeign.listPublishBookChapters(dto);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.github.xxyopen.novel.author.service;
|
||||
|
||||
|
||||
import io.github.xxyopen.novel.author.dto.req.AuthorRegisterReqDto;
|
||||
import io.github.xxyopen.novel.common.resp.RestResp;
|
||||
|
||||
/**
|
||||
* 作家模块 业务服务类
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/23
|
||||
*/
|
||||
public interface AuthorService {
|
||||
|
||||
/**
|
||||
* 作家注册
|
||||
*
|
||||
* @param dto 注册参数
|
||||
* @return void
|
||||
*/
|
||||
RestResp<Void> register(AuthorRegisterReqDto dto);
|
||||
|
||||
/**
|
||||
* 查询作家状态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 作家状态
|
||||
*/
|
||||
RestResp<Integer> getStatus(Long userId);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package io.github.xxyopen.novel.author.service.impl;
|
||||
|
||||
import io.github.xxyopen.novel.author.dao.entity.AuthorInfo;
|
||||
import io.github.xxyopen.novel.author.dao.mapper.AuthorInfoMapper;
|
||||
import io.github.xxyopen.novel.author.dto.AuthorInfoDto;
|
||||
import io.github.xxyopen.novel.author.dto.req.AuthorRegisterReqDto;
|
||||
import io.github.xxyopen.novel.author.manager.cache.AuthorInfoCacheManager;
|
||||
import io.github.xxyopen.novel.author.service.AuthorService;
|
||||
import io.github.xxyopen.novel.common.resp.RestResp;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 作家模块 服务实现类
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/23
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class AuthorServiceImpl implements AuthorService {
|
||||
|
||||
private final AuthorInfoCacheManager authorInfoCacheManager;
|
||||
|
||||
private final AuthorInfoMapper authorInfoMapper;
|
||||
|
||||
@Override
|
||||
public RestResp<Void> register(AuthorRegisterReqDto dto) {
|
||||
// 校验该用户是否已注册为作家
|
||||
AuthorInfoDto author = authorInfoCacheManager.getAuthor(dto.getUserId());
|
||||
if (Objects.nonNull(author)) {
|
||||
// 该用户已经是作家,直接返回
|
||||
return RestResp.ok();
|
||||
}
|
||||
// 保存作家注册信息
|
||||
AuthorInfo authorInfo = new AuthorInfo();
|
||||
authorInfo.setUserId(dto.getUserId());
|
||||
authorInfo.setChatAccount(dto.getChatAccount());
|
||||
authorInfo.setEmail(dto.getEmail());
|
||||
authorInfo.setInviteCode("0");
|
||||
authorInfo.setTelPhone(dto.getTelPhone());
|
||||
authorInfo.setPenName(dto.getPenName());
|
||||
authorInfo.setWorkDirection(dto.getWorkDirection());
|
||||
authorInfo.setCreateTime(LocalDateTime.now());
|
||||
authorInfo.setUpdateTime(LocalDateTime.now());
|
||||
authorInfoMapper.insert(authorInfo);
|
||||
// 清除作家缓存
|
||||
authorInfoCacheManager.evictAuthorCache();
|
||||
return RestResp.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResp<Integer> getStatus(Long userId) {
|
||||
AuthorInfoDto author = authorInfoCacheManager.getAuthor(userId);
|
||||
return Objects.isNull(author) ? RestResp.ok(null) : RestResp.ok(author.getStatus());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
server:
|
||||
port: 9010
|
||||
spring:
|
||||
profiles:
|
||||
include: common
|
||||
active: dev
|
||||
|
||||
management:
|
||||
# 端点启用配置
|
||||
endpoint:
|
||||
logfile:
|
||||
# 启用返回日志文件内容的端点
|
||||
enabled: true
|
||||
# 外部日志文件路径
|
||||
external-file: logs/novel-author-service.log
|
@ -0,0 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: novel-author-service
|
||||
profiles:
|
||||
include: common
|
||||
|
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||
<conversionRule conversionWord="wex"
|
||||
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
|
||||
<conversionRule conversionWord="wEx"
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||
<!-- 彩色日志格式 -->
|
||||
<property name="CONSOLE_LOG_PATTERN"
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
|
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,%i索引【从数字0开始递增】,,, -->
|
||||
<!-- appender是configuration的子节点,是负责写日志的组件。 -->
|
||||
<!-- ConsoleAppender:把日志输出到控制台 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是demo.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过1KB时,对当前日志进行分割 重命名 -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
|
||||
<File>logs/novel-author-service.log</File>
|
||||
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
||||
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||
<!-- 文件名:logs/demo.2017-12-05.0.log -->
|
||||
<fileNamePattern>logs/debug.%d.%i.log</fileNamePattern>
|
||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
||||
<maxHistory>30</maxHistory>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成1KB看效果 -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<!-- pattern节点,用来设置日志的输入格式 -->
|
||||
<pattern>
|
||||
%d %p (%file:%line\)- %m%n
|
||||
</pattern>
|
||||
<!-- 记录日志的编码:此处设置字符集 - -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
<springProfile name="dev">
|
||||
<!-- ROOT 日志级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||
<logger name="io.github.xxyopen" level="DEBUG" additivity="false">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</logger>
|
||||
</springProfile>
|
||||
|
||||
<springProfile name="prod">
|
||||
<!-- ROOT 日志级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||
<logger name="io.github.xxyopen" level="ERROR" additivity="false">
|
||||
<appender-ref ref="FILE"/>
|
||||
</logger>
|
||||
</springProfile>
|
||||
</configuration>
|
Reference in New Issue
Block a user