refactor(common): 统一通用常量与日志时间格式
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.bruce.common.config;
|
||||
|
||||
import com.bruce.common.constant.CommonConsts;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -11,6 +12,6 @@ import org.springframework.stereotype.Component;
|
||||
@ConfigurationProperties(prefix = "common.attachment")
|
||||
public class AttachmentProperties {
|
||||
|
||||
private String basePath = "data/attachments";
|
||||
private String basePath = CommonConsts.DEFAULT_ATTACHMENT_BASE_PATH;
|
||||
|
||||
}
|
||||
|
||||
21
src/main/java/com/bruce/common/constant/CommonConsts.java
Normal file
21
src/main/java/com/bruce/common/constant/CommonConsts.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.bruce.common.constant;
|
||||
|
||||
public final class CommonConsts {
|
||||
|
||||
public static final String DATE_FORMAT_LONG_STR = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static final String DATE_FORMAT_MILLIS_STR = "yyyy-MM-dd HH:mm:ss.SSS";
|
||||
|
||||
public static final String TIME_ZONE_GMT8 = "GMT+8";
|
||||
|
||||
public static final String DEFAULT_ATTACHMENT_BASE_PATH = "data/attachments";
|
||||
|
||||
public static final String STORAGE_TYPE_LOCAL = "LOCAL";
|
||||
|
||||
public static final String REQUEST_RESULT_SUCCESS_CODE = "0";
|
||||
|
||||
public static final String REQUEST_RESULT_FAIL_CODE = "-1";
|
||||
|
||||
private CommonConsts() {
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.Version;
|
||||
import com.bruce.common.constant.CommonConsts;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -24,7 +25,7 @@ public class BaseEntity {
|
||||
private String createBy;
|
||||
|
||||
@Schema(description = "创建时间", example = "2026-05-18 20:00:00")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = CommonConsts.DATE_FORMAT_LONG_STR, timezone = CommonConsts.TIME_ZONE_GMT8)
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@@ -33,7 +34,7 @@ public class BaseEntity {
|
||||
private String updateBy;
|
||||
|
||||
@Schema(description = "更新时间", example = "2026-05-18 20:00:00")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = CommonConsts.DATE_FORMAT_LONG_STR, timezone = CommonConsts.TIME_ZONE_GMT8)
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bruce.common.domain.model;
|
||||
|
||||
import com.bruce.common.constant.CommonConsts;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -10,9 +11,9 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public class RequestResult<T> {
|
||||
|
||||
public static final String FAIL_CODE = "-1";
|
||||
public static final String FAIL_CODE = CommonConsts.REQUEST_RESULT_FAIL_CODE;
|
||||
|
||||
public static final String SUCCESS_CODE = "0";
|
||||
public static final String SUCCESS_CODE = CommonConsts.REQUEST_RESULT_SUCCESS_CODE;
|
||||
|
||||
@Schema(description = "错误消息")
|
||||
private String message;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bruce.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bruce.common.config.AttachmentProperties;
|
||||
import com.bruce.common.constant.CommonConsts;
|
||||
import com.bruce.common.domain.entity.SysAttachment;
|
||||
import com.bruce.common.dto.request.SysAttachmentUploadRequest;
|
||||
import com.bruce.common.mapper.SysAttachmentMapper;
|
||||
@@ -22,8 +23,6 @@ import java.util.UUID;
|
||||
@Service
|
||||
public class SysAttachmentServiceImpl extends ServiceImpl<SysAttachmentMapper, SysAttachment> implements ISysAttachmentService {
|
||||
|
||||
private static final String STORAGE_TYPE_LOCAL = "LOCAL";
|
||||
|
||||
@Autowired
|
||||
private AttachmentProperties attachmentProperties;
|
||||
|
||||
@@ -64,7 +63,7 @@ public class SysAttachmentServiceImpl extends ServiceImpl<SysAttachmentMapper, S
|
||||
attachment.setFileSuffix(suffix);
|
||||
attachment.setContentType(file.getContentType());
|
||||
attachment.setFileSize(file.getSize());
|
||||
attachment.setStorageType(STORAGE_TYPE_LOCAL);
|
||||
attachment.setStorageType(CommonConsts.STORAGE_TYPE_LOCAL);
|
||||
attachment.setFilePath(dateDirectory + "/" + storedFileName);
|
||||
attachment.setFileUrl(null);
|
||||
attachment.setVersion(1);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.bruce.rag.dto.response;
|
||||
|
||||
import com.bruce.common.constant.CommonConsts;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -33,9 +35,11 @@ public class RagStoreResponse {
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = CommonConsts.DATE_FORMAT_LONG_STR, timezone = CommonConsts.TIME_ZONE_GMT8)
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@JsonFormat(pattern = CommonConsts.DATE_FORMAT_LONG_STR, timezone = CommonConsts.TIME_ZONE_GMT8)
|
||||
private Date updateTime;
|
||||
|
||||
public static RagStoreResponse fromEntity(RagStore entity) {
|
||||
|
||||
Reference in New Issue
Block a user