chore: 清理冗余注释,保留字段/业务含义注释
This commit is contained in:
@@ -17,3 +17,31 @@
|
|||||||
- 删除表:创建新迁移脚本,使用 `DROP TABLE IF EXISTS`
|
- 删除表:创建新迁移脚本,使用 `DROP TABLE IF EXISTS`
|
||||||
- 修改表结构:使用 `ALTER TABLE` 语句
|
- 修改表结构:使用 `ALTER TABLE` 语句
|
||||||
- 新增表:创建新迁移脚本,使用 `CREATE TABLE`
|
- 新增表:创建新迁移脚本,使用 `CREATE TABLE`
|
||||||
|
|
||||||
|
## 框架机制
|
||||||
|
|
||||||
|
### 行级数据隔离(多租户拦截器)
|
||||||
|
|
||||||
|
- **配置类:** `MybatisPlusConfig` 注册 `TenantLineInnerInterceptor`
|
||||||
|
- **租户字段:** `created_by`(每个业务表的创建人字段)
|
||||||
|
- **租户值来源:** `StpUtil.getLoginIdAsString()`(当前登录用户)
|
||||||
|
- **自动注入:** 所有 SELECT/UPDATE/DELETE 语句自动追加 `WHERE created_by = #{当前用户}`
|
||||||
|
- **归属校验:** 查询单条记录时拦截器自动校验 `created_by`,非本人数据直接返回空
|
||||||
|
- **排除表:** `user`、`flyway_schema_history`、`databasechangelog`、`databasechangeloglock`
|
||||||
|
|
||||||
|
### 自动填充(MetaObjectHandler)
|
||||||
|
|
||||||
|
- **created_by / updated_by:** 插入/更新时自动填充为当前登录用户
|
||||||
|
- **created_time / updated_time:** 插入/更新时自动填充当前时间
|
||||||
|
|
||||||
|
### 认证鉴权(Sa-Token)
|
||||||
|
|
||||||
|
- **会话管理:** 基于 `StpUtil` 的登录/登出/会话查询
|
||||||
|
- **权限校验:** `@SaCheckPermission` 注解式权限控制
|
||||||
|
- **未登录处理:** 全局异常处理器捕获 `NotLoginException` 返回 401
|
||||||
|
|
||||||
|
## 编码规范
|
||||||
|
|
||||||
|
### 数据访问层
|
||||||
|
- **优先使用纯 MyBatis-Plus Java API**(`Wrappers.<T>lambdaQuery()`、`selectList`、`selectById` 等),避免手写 XML SQL
|
||||||
|
- 复杂查询通过 `Wrappers` 链式构建条件,必要时使用 `.apply()` 拼接原生 SQL 片段
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
---
|
||||||
|
name: comment-cleanup
|
||||||
|
description: 提交代码前优化 Java 注释,移除冗余描述性注释,保留功能性注释和业务上下文注释。
|
||||||
|
metadata:
|
||||||
|
short-description: 清理 Java 代码中的冗余注释
|
||||||
|
---
|
||||||
|
|
||||||
|
# Comment Cleanup
|
||||||
|
|
||||||
|
在代码提交前,扫描变更的 Java 文件,清理冗余注释,保留有价值的注释。
|
||||||
|
|
||||||
|
## 触发条件
|
||||||
|
|
||||||
|
用户要求清理注释、优化注释、提交前检查注释时使用。
|
||||||
|
|
||||||
|
## 工作流程
|
||||||
|
|
||||||
|
1. 定位待清理的 Java 文件(通常是 `git diff` 中变更的文件)
|
||||||
|
2. 逐文件扫描注释,按规则分类处理
|
||||||
|
3. 执行清理(删除或改造)
|
||||||
|
4. 输出清理报告
|
||||||
|
|
||||||
|
## 注释分类规则
|
||||||
|
|
||||||
|
### 移除:类型 A — 代码语义重复注释
|
||||||
|
|
||||||
|
代码本身已经清晰表达意图时,删除多余的行内注释。
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ❌ 移除:代码已经说清楚了
|
||||||
|
// 转换报告
|
||||||
|
List<ReviewFeedItem> reportItems = reports.stream().map(r -> toFeedItem(r)).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// ❌ 移除:合并逻辑一眼就能看出
|
||||||
|
// 合并并按创建时间倒序
|
||||||
|
return Stream.concat(reportItems.stream(), fragmentItems.stream())
|
||||||
|
.sorted(Comparator.comparing(ReviewFeedItem::getCreatedTime).reversed())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// ❌ 移除:查询目的从变量名已可知
|
||||||
|
// 先查该任务下的所有 sessionNum
|
||||||
|
List<String> sessionNums = studySessionsMapper.selectList(...)
|
||||||
|
```
|
||||||
|
|
||||||
|
**判断标准:** 如果删掉注释后,一个熟悉 Java/Spring 的开发者看代码没有任何困惑,就该移除。
|
||||||
|
|
||||||
|
**例外:** 方法级的 Javadoc(`/** ... */`)即使与代码重复,也保留,因为它服务于 IDE 提示和文档生成。
|
||||||
|
|
||||||
|
### 移除:类型 B — 框架机制注释
|
||||||
|
|
||||||
|
框架隐式行为(拦截器、MetaObjectHandler、AOP 等)的说明不在代码中重复标注,而是在 `AGENTS.md` 的"框架机制"章节集中描述。代码中的此类注释一律移除。
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ❌ 移除:框架机制已在 AGENTS.md 中说明
|
||||||
|
// created_by 条件由 TenantLineInnerInterceptor 自动注入
|
||||||
|
List<StudyReportsEntity> reports = studyReportsMapper.selectList(...)
|
||||||
|
|
||||||
|
// ❌ 移除
|
||||||
|
// 拦截器自动校验归属
|
||||||
|
return Optional.ofNullable(studyReportsMapper.selectById(id)) ...
|
||||||
|
|
||||||
|
// ❌ 移除
|
||||||
|
// created_by 由 MetaObjectHandler 自动填充
|
||||||
|
studySessionsServiceImpl.save(...)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 移除:类型 D — 空注释 / 无信息量注释
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ❌ 空 Javadoc
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableField(value = "created_time")
|
||||||
|
private LocalDateTime createdTime;
|
||||||
|
|
||||||
|
// ❌ 纯标注作者(无版本/日期等有价值信息时)
|
||||||
|
/**
|
||||||
|
* @author guo
|
||||||
|
*/
|
||||||
|
public class GlobalExceptionHandler { ... }
|
||||||
|
|
||||||
|
// ❌ 重复 HTTP 状态码(CommonResult.error 已隐含 400)
|
||||||
|
//code:400
|
||||||
|
return CommonResult.error(ex.getMessage());
|
||||||
|
```
|
||||||
|
|
||||||
|
### 保留:类型 C — 字段/类 Javadoc
|
||||||
|
|
||||||
|
字段 Javadoc 描述数据含义,类 Javadoc 描述模块职能。
|
||||||
|
|
||||||
|
**字段 Javadoc:** 保留,说明字段的业务含义。
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ✅ 保留:字段含义对理解数据模型有帮助
|
||||||
|
/**
|
||||||
|
* 账号-登录用
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_name")
|
||||||
|
private String userName;
|
||||||
|
```
|
||||||
|
|
||||||
|
**类 Javadoc:** 保留,但只描述类的职能,不包含实现技术细节。
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ❌ 移除:实现技术属于实现细节,不属于类描述
|
||||||
|
/** 复习模块 Service 实现(纯 MyBatis-Plus Java API) */
|
||||||
|
|
||||||
|
// ✅ 保留:只描述职能
|
||||||
|
/** 复习模块 Service 实现 */
|
||||||
|
```
|
||||||
|
|
||||||
|
### 改造:类型 E — 枚举注释
|
||||||
|
|
||||||
|
枚举中的中文含义注释应迁移到枚举类的专用字段中,而非用注释标注。
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ❌ 改造前:用注释标注含义
|
||||||
|
public enum Strategy {
|
||||||
|
// 创建组
|
||||||
|
CREATE("C"),
|
||||||
|
// 更新组
|
||||||
|
UPDATE("U");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ 改造后:用字段存储含义
|
||||||
|
public enum Strategy {
|
||||||
|
CREATE("C", "创建组"),
|
||||||
|
UPDATE("U", "更新组");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
Strategy(String code, String label) {
|
||||||
|
this.code = code;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() { return code; }
|
||||||
|
public String getLabel() { return label; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果枚举已有 `label`/`desc` 等字段,则直接删除注释。
|
||||||
|
|
||||||
|
**常量注释保留不变:**
|
||||||
|
```java
|
||||||
|
// ✅ 常量注释保留
|
||||||
|
// 最大重试次数
|
||||||
|
private static final int MAX_RETRY = 3;
|
||||||
|
```
|
||||||
|
|
||||||
|
### 保留:类型 F — TODO / FIXME 注释
|
||||||
|
|
||||||
|
```java
|
||||||
|
// ✅ 保留
|
||||||
|
//todo 参数传递未加密
|
||||||
|
```
|
||||||
|
|
||||||
|
## 执行命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 获取变更的 Java 文件
|
||||||
|
git diff --cached --name-only --diff-filter=ACMR -- '*.java'
|
||||||
|
|
||||||
|
# 对每个文件逐行扫描,按上述规则处理
|
||||||
|
```
|
||||||
|
|
||||||
|
## 输出格式
|
||||||
|
|
||||||
|
清理完成后,输出简要报告:
|
||||||
|
|
||||||
|
```
|
||||||
|
✅ 清理完成,共处理 N 个文件:
|
||||||
|
- 移除冗余注释 X 处
|
||||||
|
- 改造枚举注释 Y 处(需人工确认新增字段)
|
||||||
|
- 保留注释 Z 处(字段Javadoc/TODO)
|
||||||
|
```
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
schema_version: v1
|
||||||
|
interface:
|
||||||
|
display_name: Java 注释清理
|
||||||
|
short_description: 清理 Java 代码中的冗余注释,保留功能性注释
|
||||||
|
default_prompt: |
|
||||||
|
使用 $comment-cleanup 扫描变更的 Java 文件,移除冗余的描述性注释,保留框架机制注释、字段 Javadoc 和 TODO 注释。
|
||||||
@@ -15,41 +15,33 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guo
|
|
||||||
*/
|
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler({ErrorParameterException.class})
|
@ExceptionHandler({ErrorParameterException.class})
|
||||||
public CommonResult errorParameterException(ErrorParameterException ex) {
|
public CommonResult errorParameterException(ErrorParameterException ex) {
|
||||||
//code:400
|
|
||||||
return CommonResult.error(ex.getMessage());
|
return CommonResult.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler({NotFindEntitiesException.class})
|
@ExceptionHandler({NotFindEntitiesException.class})
|
||||||
public CommonResult notFindEntitiesException(NotFindEntitiesException ex) {
|
public CommonResult notFindEntitiesException(NotFindEntitiesException ex) {
|
||||||
//code:400
|
|
||||||
return CommonResult.error(ex.getMessage());
|
return CommonResult.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler({AppException.class})
|
@ExceptionHandler({AppException.class})
|
||||||
public CommonResult AppException(AppException ex) {
|
public CommonResult AppException(AppException ex) {
|
||||||
//code:500
|
|
||||||
return CommonResult.serverError(ex.getMessage());
|
return CommonResult.serverError(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
public CommonResult MyMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
|
public CommonResult MyMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
|
||||||
BindingResult bindingResult = ex.getBindingResult();
|
BindingResult bindingResult = ex.getBindingResult();
|
||||||
//code:400
|
|
||||||
return CommonResult.error(bindingResult.getFieldError().getDefaultMessage());
|
return CommonResult.error(bindingResult.getFieldError().getDefaultMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(NotLoginException.class)
|
@ExceptionHandler(NotLoginException.class)
|
||||||
public CommonResult handleNotLogin(NotLoginException e, HttpServletRequest req, HttpServletResponse res) {
|
public CommonResult handleNotLogin(NotLoginException e, HttpServletRequest req, HttpServletResponse res) {
|
||||||
//code:401
|
|
||||||
res.setStatus(HttpStatus.UNAUTHORIZED.value());
|
res.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||||
return new CommonResult<>(HttpStatus.UNAUTHORIZED.value(), "未登录,请重新登录", null);
|
return new CommonResult<>(HttpStatus.UNAUTHORIZED.value(), "未登录,请重新登录", null);
|
||||||
}
|
}
|
||||||
@@ -57,7 +49,6 @@ public class GlobalExceptionHandler {
|
|||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public CommonResult Exception(Exception ex) {
|
public CommonResult Exception(Exception ex) {
|
||||||
log.error("系统异常", ex);
|
log.error("系统异常", ex);
|
||||||
//code:400
|
|
||||||
return CommonResult.error(ex.getMessage());
|
return CommonResult.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import jakarta.validation.groups.Default;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局数据验证分组
|
* 全局数据验证分组
|
||||||
* GlobalValidationGroup -> OpenGroups ->ops
|
|
||||||
* @author guo
|
|
||||||
*/
|
*/
|
||||||
public interface Ops {
|
public interface Ops {
|
||||||
// 创建组
|
// 创建组
|
||||||
interface CreateG extends Default {}
|
interface CreateG extends Default {
|
||||||
|
}
|
||||||
|
|
||||||
// 更新组
|
// 更新组
|
||||||
interface UpdateG {}
|
interface UpdateG {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,21 +10,16 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guo
|
|
||||||
*/
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class JacksonConfig {
|
public class JacksonConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||||
ObjectMapper mapper = builder.build();
|
ObjectMapper mapper = builder.build();
|
||||||
|
|
||||||
// 注册自定义序列化器
|
|
||||||
SimpleModule module = new SimpleModule();
|
SimpleModule module = new SimpleModule();
|
||||||
module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
|
module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
|
||||||
mapper.registerModule(module);
|
mapper.registerModule(module);
|
||||||
|
|
||||||
// 关闭序列化为时间戳(使用字符串格式)
|
|
||||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
|
|
||||||
return mapper;
|
return mapper;
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Administrator
|
|
||||||
*/
|
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
@Configuration
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -24,11 +21,9 @@ public class WebMvcDevConfig implements WebMvcConfigurer {
|
|||||||
|
|
||||||
private final CorsProperties corsProperties;
|
private final CorsProperties corsProperties;
|
||||||
|
|
||||||
// 注册拦截器
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> {
|
registry.addInterceptor(new SaInterceptor(handle -> {
|
||||||
// OPTIONS 请求直接放行
|
|
||||||
if ("OPTIONS".equalsIgnoreCase(SaHolder.getRequest().getMethod())) {
|
if ("OPTIONS".equalsIgnoreCase(SaHolder.getRequest().getMethod())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,8 @@ public class WebMvcProdConfig implements WebMvcConfigurer {
|
|||||||
.allowCredentials(true);
|
.allowCredentials(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册拦截器
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
|
|
||||||
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
.excludePathPatterns("/login");
|
.excludePathPatterns("/login");
|
||||||
|
|||||||
-3
@@ -9,8 +9,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
|
public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
|
||||||
|
|
||||||
// 修改为ISO 8601格式,末尾带Z,表示UTC时区
|
|
||||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
|
|
||||||
public LocalDateTimeSerializer() {
|
public LocalDateTimeSerializer() {
|
||||||
@@ -22,7 +20,6 @@ public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
gen.writeNull();
|
gen.writeNull();
|
||||||
} else {
|
} else {
|
||||||
// 这里假设LocalDateTime是UTC时间,直接格式化并加Z
|
|
||||||
String formattedDate = value.format(formatter);
|
String formattedDate = value.format(formatter);
|
||||||
gen.writeString(formattedDate);
|
gen.writeString(formattedDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guo
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ package com.guo.learningprogresstracker.dto;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author guo
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public class TaskInfo {
|
public class TaskInfo {
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
|
|||||||
public void pausedStudySession(LocalDateTime endTime){
|
public void pausedStudySession(LocalDateTime endTime){
|
||||||
if (this.getSessionState().equals(StudySessionStateEnum.PAUSED.name())) {
|
if (this.getSessionState().equals(StudySessionStateEnum.PAUSED.name())) {
|
||||||
log.warn("不应出现的情况:暂停了一个状态为【{}】的学习会话({})", this.getSessionState(), this.getSessionNum());
|
log.warn("不应出现的情况:暂停了一个状态为【{}】的学习会话({})", this.getSessionState(), this.getSessionNum());
|
||||||
//
|
|
||||||
} else {
|
} else {
|
||||||
this.setEndTime(ObjectUtils.isEmpty(endTime) ? LocalDateTime.now() : endTime);
|
this.setEndTime(ObjectUtils.isEmpty(endTime) ? LocalDateTime.now() : endTime);
|
||||||
this.setActualTime(Duration.between(this.startTime, this.endTime).toSeconds());
|
this.setActualTime(Duration.between(this.startTime, this.endTime).toSeconds());
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 复习模块 Service 实现(纯 MyBatis-Plus Java API)
|
* 复习模块 Service 实现
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -33,7 +33,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ReviewFeedItem> getReviewFeed(int limit) {
|
public List<ReviewFeedItem> getReviewFeed(int limit) {
|
||||||
// created_by 条件由 TenantLineInnerInterceptor 自动注入
|
|
||||||
List<StudyReportsEntity> reports = studyReportsMapper.selectList(
|
List<StudyReportsEntity> reports = studyReportsMapper.selectList(
|
||||||
Wrappers.<StudyReportsEntity>lambdaQuery()
|
Wrappers.<StudyReportsEntity>lambdaQuery()
|
||||||
.orderByDesc(StudyReportsEntity::getCreatedTime)
|
.orderByDesc(StudyReportsEntity::getCreatedTime)
|
||||||
@@ -49,7 +48,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ReviewFeedItem> getTaskReview(String taskNum) {
|
public List<ReviewFeedItem> getTaskReview(String taskNum) {
|
||||||
// 先查该任务下的所有 sessionNum
|
|
||||||
List<String> sessionNums = studySessionsMapper.selectList(
|
List<String> sessionNums = studySessionsMapper.selectList(
|
||||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||||
@@ -77,14 +75,12 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StudyReportsEntity getReportDetail(int id) throws NotFindEntitiesException {
|
public StudyReportsEntity getReportDetail(int id) throws NotFindEntitiesException {
|
||||||
// 拦截器自动校验归属
|
|
||||||
return Optional.ofNullable(studyReportsMapper.selectById(id))
|
return Optional.ofNullable(studyReportsMapper.selectById(id))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("学习报告[" + id + "]不存在"));
|
.orElseThrow(() -> new NotFindEntitiesException("学习报告[" + id + "]不存在"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StudyReportFragmentsEntity getFragmentDetail(int id) throws NotFindEntitiesException {
|
public StudyReportFragmentsEntity getFragmentDetail(int id) throws NotFindEntitiesException {
|
||||||
// 拦截器自动校验归属
|
|
||||||
return Optional.ofNullable(studyReportFragmentsMapper.selectById(id))
|
return Optional.ofNullable(studyReportFragmentsMapper.selectById(id))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("学习残片[" + id + "]不存在"));
|
.orElseThrow(() -> new NotFindEntitiesException("学习残片[" + id + "]不存在"));
|
||||||
}
|
}
|
||||||
@@ -94,7 +90,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
*/
|
*/
|
||||||
private List<ReviewFeedItem> mergeAndConvert(List<StudyReportsEntity> reports,
|
private List<ReviewFeedItem> mergeAndConvert(List<StudyReportsEntity> reports,
|
||||||
List<StudyReportFragmentsEntity> fragments) {
|
List<StudyReportFragmentsEntity> fragments) {
|
||||||
// 收集所有 sessionNum,批量查询 session 和 task
|
|
||||||
Set<String> allSessionNums = Stream.concat(
|
Set<String> allSessionNums = Stream.concat(
|
||||||
reports.stream().map(StudyReportsEntity::getSessionNum),
|
reports.stream().map(StudyReportsEntity::getSessionNum),
|
||||||
fragments.stream().map(StudyReportFragmentsEntity::getSessionNum)
|
fragments.stream().map(StudyReportFragmentsEntity::getSessionNum)
|
||||||
@@ -104,7 +99,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 批量查询 sessions,构建 sessionNum -> taskNum 映射
|
|
||||||
Map<String, String> sessionToTaskMap = studySessionsMapper.selectList(
|
Map<String, String> sessionToTaskMap = studySessionsMapper.selectList(
|
||||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||||
.in(StudySessionsEntity::getSessionNum, allSessionNums)
|
.in(StudySessionsEntity::getSessionNum, allSessionNums)
|
||||||
@@ -115,7 +109,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
StudySessionsEntity::getTaskNum,
|
StudySessionsEntity::getTaskNum,
|
||||||
(a, b) -> a));
|
(a, b) -> a));
|
||||||
|
|
||||||
// 批量查询 tasks,构建 taskNum -> taskName 映射
|
|
||||||
Set<String> taskNums = new HashSet<>(sessionToTaskMap.values());
|
Set<String> taskNums = new HashSet<>(sessionToTaskMap.values());
|
||||||
Map<String, String> taskNameMap = tasksMapper.selectList(
|
Map<String, String> taskNameMap = tasksMapper.selectList(
|
||||||
Wrappers.<TaskEntity>lambdaQuery()
|
Wrappers.<TaskEntity>lambdaQuery()
|
||||||
@@ -127,7 +120,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
TaskEntity::getTaskName,
|
TaskEntity::getTaskName,
|
||||||
(a, b) -> a));
|
(a, b) -> a));
|
||||||
|
|
||||||
// 转换报告
|
|
||||||
List<ReviewFeedItem> reportItems = reports.stream().map(r -> {
|
List<ReviewFeedItem> reportItems = reports.stream().map(r -> {
|
||||||
ReviewFeedItem item = new ReviewFeedItem();
|
ReviewFeedItem item = new ReviewFeedItem();
|
||||||
item.setId(r.getId());
|
item.setId(r.getId());
|
||||||
@@ -141,7 +133,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
return item;
|
return item;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
// 转换残片
|
|
||||||
List<ReviewFeedItem> fragmentItems = fragments.stream().map(f -> {
|
List<ReviewFeedItem> fragmentItems = fragments.stream().map(f -> {
|
||||||
ReviewFeedItem item = new ReviewFeedItem();
|
ReviewFeedItem item = new ReviewFeedItem();
|
||||||
item.setId(f.getId());
|
item.setId(f.getId());
|
||||||
@@ -155,7 +146,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
return item;
|
return item;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
// 合并并按创建时间倒序
|
|
||||||
return Stream.concat(reportItems.stream(), fragmentItems.stream())
|
return Stream.concat(reportItems.stream(), fragmentItems.stream())
|
||||||
.sorted(Comparator.comparing(ReviewFeedItem::getCreatedTime,
|
.sorted(Comparator.comparing(ReviewFeedItem::getCreatedTime,
|
||||||
Comparator.nullsLast(Comparator.reverseOrder())))
|
Comparator.nullsLast(Comparator.reverseOrder())))
|
||||||
|
|||||||
+2
-6
@@ -14,10 +14,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guo
|
* 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service实现
|
||||||
* @description 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service实现
|
*/
|
||||||
* @createDate 2024-06-09 15:28:48
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
||||||
@@ -28,14 +26,12 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
|
|||||||
@Override
|
@Override
|
||||||
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
|
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
|
||||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||||
// 拦截器自动注入 created_by 条件,会话归属校验已内置
|
|
||||||
StudySessionsEntity session = studySessionsMapper.selectOne(
|
StudySessionsEntity session = studySessionsMapper.selectOne(
|
||||||
Wrappers.lambdaQuery(StudySessionsEntity.class)
|
Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, entity.getSessionNum()));
|
.eq(StudySessionsEntity::getSessionNum, entity.getSessionNum()));
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
throw new NotFindEntitiesException(String.format("未能找到学习会话sessionNum[%s]", entity.getSessionNum()));
|
throw new NotFindEntitiesException(String.format("未能找到学习会话sessionNum[%s]", entity.getSessionNum()));
|
||||||
}
|
}
|
||||||
// created_by 由 MetaObjectHandler 在 insert 时自动填充
|
|
||||||
this.save(entity);
|
this.save(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -27,9 +27,7 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guo
|
* 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service实现
|
||||||
* @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service实现
|
|
||||||
* @createDate 2024-06-09 15:28:48
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -45,7 +43,6 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
private final StudyReportsMapper studyReportsMapper;
|
private final StudyReportsMapper studyReportsMapper;
|
||||||
|
|
||||||
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException, ServiceException {
|
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException, ServiceException {
|
||||||
// 拦截器已自动注入 created_by 条件,只有当前用户的 task 才能查到
|
|
||||||
TaskEntity taskEntity = tasksServiceImpl.getOneOpt(
|
TaskEntity taskEntity = tasksServiceImpl.getOneOpt(
|
||||||
Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在", taskNum)));
|
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在", taskNum)));
|
||||||
@@ -82,7 +79,6 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException, ServiceException {
|
public void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException, ServiceException {
|
||||||
// 拦截器自动校验归属,查不到即说明无权访问
|
|
||||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
||||||
@@ -98,13 +94,11 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endedStudySession(String sessionNum, String content) throws ErrorParameterException {
|
public void endedStudySession(String sessionNum, String content) throws ErrorParameterException {
|
||||||
// 拦截器自动校验归属
|
|
||||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
||||||
studySessionsEntity.endedStudySession();
|
studySessionsEntity.endedStudySession();
|
||||||
this.updateById(studySessionsEntity);
|
this.updateById(studySessionsEntity);
|
||||||
// 创建学习报告(created_by 由 MetaObjectHandler 自动填充)
|
|
||||||
StudyReportsEntity studyReportsEntity = new StudyReportsEntity();
|
StudyReportsEntity studyReportsEntity = new StudyReportsEntity();
|
||||||
studyReportsEntity.setSessionNum(sessionNum);
|
studyReportsEntity.setSessionNum(sessionNum);
|
||||||
studyReportsEntity.setContent(content);
|
studyReportsEntity.setContent(content);
|
||||||
@@ -113,7 +107,6 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
|
public StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
|
||||||
// 拦截器自动注入 created_by,task 归属校验已内置
|
|
||||||
TaskEntity task = tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class)
|
TaskEntity task = tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class)
|
||||||
.eq(TaskEntity::getTaskNum, taskNum))
|
.eq(TaskEntity::getTaskNum, taskNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在"));
|
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在"));
|
||||||
@@ -124,7 +117,6 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<String> getAllFragments(String sessionNum) throws ErrorParameterException {
|
public ArrayList<String> getAllFragments(String sessionNum) throws ErrorParameterException {
|
||||||
// 拦截器自动校验归属
|
|
||||||
if (this.exists(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
if (this.exists(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))) {
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))) {
|
||||||
return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||||
@@ -137,7 +129,6 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void continueStudySession(String sessionNum) throws ErrorParameterException, ServiceException {
|
public void continueStudySession(String sessionNum) throws ErrorParameterException, ServiceException {
|
||||||
// 拦截器自动校验归属
|
|
||||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
||||||
@@ -153,7 +144,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 sessionNum 获取学习会话(归属由拦截器自动校验)
|
* 通过 sessionNum 获取学习会话
|
||||||
*/
|
*/
|
||||||
public StudySessionResponse getStudySessionBySessionNum(String sessionNum) throws ErrorParameterException {
|
public StudySessionResponse getStudySessionBySessionNum(String sessionNum) throws ErrorParameterException {
|
||||||
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guo
|
* 针对表【tasks(存储学习任务的基本信息,包括优先级的多维度计算)】的数据库操作Service实现
|
||||||
* @description 针对表【tasks(存储学习任务的基本信息,包括优先级的多维度计算)】的数据库操作Service实现
|
*/
|
||||||
* @createDate 2024-06-09 15:28:48
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -34,7 +32,6 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<TaskInfo> taskList(Integer pageNum, Integer pageSize) {
|
public Page<TaskInfo> taskList(Integer pageNum, Integer pageSize) {
|
||||||
// 拦截器自动注入 created_by 条件,只返回当前用户的任务
|
|
||||||
Page<TaskEntity> page = tasksMapper.selectPage(new Page<TaskEntity>(pageNum, pageSize),
|
Page<TaskEntity> page = tasksMapper.selectPage(new Page<TaskEntity>(pageNum, pageSize),
|
||||||
Wrappers.lambdaQuery(TaskEntity.class)
|
Wrappers.lambdaQuery(TaskEntity.class)
|
||||||
.orderByDesc(TaskEntity::getCalculatedPriority));
|
.orderByDesc(TaskEntity::getCalculatedPriority));
|
||||||
@@ -46,7 +43,6 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
public String addTask(TaskRequest taskRequest) throws ErrorParameterException {
|
public String addTask(TaskRequest taskRequest) throws ErrorParameterException {
|
||||||
TaskEntity task = TaskConvert.MAPPER.taskRequestToTaskEntity(taskRequest);
|
TaskEntity task = TaskConvert.MAPPER.taskRequestToTaskEntity(taskRequest);
|
||||||
|
|
||||||
// 拦截器自动注入 created_by,重复校验仅限当前用户
|
|
||||||
if (this.exists(Wrappers.lambdaQuery(TaskEntity.class)
|
if (this.exists(Wrappers.lambdaQuery(TaskEntity.class)
|
||||||
.eq(TaskEntity::getTaskName, task.getTaskName()))) {
|
.eq(TaskEntity::getTaskName, task.getTaskName()))) {
|
||||||
throw new ErrorParameterException(String.format("任务名[%s]重复", task.getTaskName()));
|
throw new ErrorParameterException(String.format("任务名[%s]重复", task.getTaskName()));
|
||||||
@@ -61,14 +57,12 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TaskInfoResponse getTask(String taskId) {
|
public TaskInfoResponse getTask(String taskId) {
|
||||||
// 拦截器自动校验归属,查到的一定是当前用户的任务
|
|
||||||
TaskEntity taskEntity = this.getById(taskId);
|
TaskEntity taskEntity = this.getById(taskId);
|
||||||
return TaskConvert.MAPPER.taskEntityToTaskInfoResponse(taskEntity);
|
return TaskConvert.MAPPER.taskEntityToTaskInfoResponse(taskEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTask(String taskId, TaskRequest updatedTask) {
|
public void updateTask(String taskId, TaskRequest updatedTask) {
|
||||||
// getById 已被拦截器保护,其他用户的任务查不到
|
|
||||||
TaskEntity existingTask = this.getById(taskId);
|
TaskEntity existingTask = this.getById(taskId);
|
||||||
if (existingTask == null) {
|
if (existingTask == null) {
|
||||||
throw new IllegalArgumentException("任务不存在: " + taskId);
|
throw new IllegalArgumentException("任务不存在: " + taskId);
|
||||||
@@ -86,7 +80,6 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteTask(String taskId) {
|
public void deleteTask(String taskId) {
|
||||||
// getById 已被拦截器保护,其他用户的任务查不到
|
|
||||||
TaskEntity existingTask = this.getById(taskId);
|
TaskEntity existingTask = this.getById(taskId);
|
||||||
if (existingTask == null) {
|
if (existingTask == null) {
|
||||||
throw new IllegalArgumentException("任务不存在: " + taskId);
|
throw new IllegalArgumentException("任务不存在: " + taskId);
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.guo.learningprogresstracker.dto.PriorityDto;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 加权优先级计算工具
|
* 加权优先级计算工具
|
||||||
*
|
|
||||||
* @author guo
|
|
||||||
*/
|
*/
|
||||||
public class CalculatedPriorityTool {
|
public class CalculatedPriorityTool {
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,11 @@ import java.util.Date;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于生成编码的工具
|
* 用于生成编码的工具
|
||||||
*
|
|
||||||
* @author guo
|
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GenerateNumTool {
|
public class GenerateNumTool {
|
||||||
private static int getNextSequence() {
|
private static int getNextSequence() {
|
||||||
// 获取当前时间的毫秒级时间戳
|
|
||||||
long timestamp = System.currentTimeMillis();
|
long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
// 使用时间戳的最后6位作为序列号
|
|
||||||
return (int) (timestamp % 1_000_000);
|
return (int) (timestamp % 1_000_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,22 +24,14 @@ public class GenerateNumTool {
|
|||||||
*/
|
*/
|
||||||
public static String generateNum(String prefix, String separator) {
|
public static String generateNum(String prefix, String separator) {
|
||||||
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||||
|
|
||||||
// 唯一的后缀
|
|
||||||
int sequence = getNextSequence();
|
int sequence = getNextSequence();
|
||||||
|
|
||||||
// 返回完整的 taskNum
|
|
||||||
return prefix + separator + currentDate + separator + sequence;
|
return prefix + separator + currentDate + separator + sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String generateNum(String prefix) {
|
public static String generateNum(String prefix) {
|
||||||
String separator = "-";
|
String separator = "-";
|
||||||
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||||
|
|
||||||
// 唯一的后缀
|
|
||||||
int sequence = getNextSequence();
|
int sequence = getNextSequence();
|
||||||
|
|
||||||
// 返回完整的 taskNum
|
|
||||||
return prefix + separator + currentDate + separator + sequence;
|
return prefix + separator + currentDate + separator + sequence;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user