From d1c57e379d8272a787bf0234c42b72ce751d17f7 Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Thu, 12 Mar 2026 16:13:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(document):=20=E6=B7=BB=E5=8A=A0=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E5=8F=98=E6=9B=B4=E6=8E=A7=E5=88=B6=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=96=87=E6=A1=A3=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 fileChanged 字段用于控制附件信息更新 - 移除控制器中的时间戳和上传人设置逻辑 - 在更新操作中添加条件判断避免误更新附件信息 - 实现 refreshUploadInfo 方法统一处理上传信息 - 优化数据库映射文件中的条件更新逻辑 - 集成 SecurityUtils 和 DateUtils 工具类 - 完善附件路径为空时的清理机制 --- .../StandardDocumentController.java | 5 ---- .../aucma/base/domain/StandardDocument.java | 12 +++++++++ .../impl/StandardDocumentServiceImpl.java | 27 +++++++++++++++++++ .../mapper/base/StandardDocumentMapper.xml | 8 +++--- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/aucma-base/src/main/java/com/aucma/base/controller/StandardDocumentController.java b/aucma-base/src/main/java/com/aucma/base/controller/StandardDocumentController.java index 260d25a..ce50f9c 100644 --- a/aucma-base/src/main/java/com/aucma/base/controller/StandardDocumentController.java +++ b/aucma-base/src/main/java/com/aucma/base/controller/StandardDocumentController.java @@ -3,7 +3,6 @@ package com.aucma.base.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; -import com.aucma.common.utils.DateUtils; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -56,9 +55,6 @@ public class StandardDocumentController extends BaseController { @Log(title = "标准文档" , businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody StandardDocument standardDocument) { - standardDocument.setUploader(getUsername()); - standardDocument.setUploadTime(DateUtils.getNowDate()); - standardDocument.setCreatedTime(DateUtils.getNowDate()); return toAjax(standardDocumentService.insertStandardDocument(standardDocument)); } @@ -66,7 +62,6 @@ public class StandardDocumentController extends BaseController { @Log(title = "标准文档" , businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody StandardDocument standardDocument) { - standardDocument.setUpdatedTime(DateUtils.getNowDate()); return toAjax(standardDocumentService.updateStandardDocument(standardDocument)); } diff --git a/aucma-base/src/main/java/com/aucma/base/domain/StandardDocument.java b/aucma-base/src/main/java/com/aucma/base/domain/StandardDocument.java index e2eac75..83bd044 100644 --- a/aucma-base/src/main/java/com/aucma/base/domain/StandardDocument.java +++ b/aucma-base/src/main/java/com/aucma/base/domain/StandardDocument.java @@ -37,6 +37,9 @@ public class StandardDocument extends BaseEntity { @Excel(name = "文档大小") private Long documentSize; + /** 附件是否被前端显式变更,仅用于更新时控制空值落库 */ + private Boolean fileChanged; + @Excel(name = "上传人") private String uploader; @@ -138,6 +141,14 @@ public class StandardDocument extends BaseEntity { this.documentSize = documentSize; } + public Boolean getFileChanged() { + return fileChanged; + } + + public void setFileChanged(Boolean fileChanged) { + this.fileChanged = fileChanged; + } + public String getUploader() { return uploader; } @@ -214,6 +225,7 @@ public class StandardDocument extends BaseEntity { .append("versionNo", getVersionNo()) .append("documentPath", getDocumentPath()) .append("documentSize", getDocumentSize()) + .append("fileChanged", getFileChanged()) .append("uploader", getUploader()) .append("uploadTime", getUploadTime()) .append("effectiveDate", getEffectiveDate()) diff --git a/aucma-base/src/main/java/com/aucma/base/service/impl/StandardDocumentServiceImpl.java b/aucma-base/src/main/java/com/aucma/base/service/impl/StandardDocumentServiceImpl.java index 4032186..c42f5d5 100644 --- a/aucma-base/src/main/java/com/aucma/base/service/impl/StandardDocumentServiceImpl.java +++ b/aucma-base/src/main/java/com/aucma/base/service/impl/StandardDocumentServiceImpl.java @@ -1,8 +1,14 @@ package com.aucma.base.service.impl; +import java.util.Date; import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import com.aucma.common.utils.DateUtils; +import com.aucma.common.utils.SecurityUtils; +import com.aucma.common.utils.StringUtils; import com.aucma.base.mapper.StandardDocumentMapper; import com.aucma.base.domain.StandardDocument; import com.aucma.base.service.IStandardDocumentService; @@ -24,11 +30,20 @@ public class StandardDocumentServiceImpl implements IStandardDocumentService { @Override public int insertStandardDocument(StandardDocument standardDocument) { + Date now = DateUtils.getNowDate(); + standardDocument.setCreatedTime(now); + refreshUploadInfo(standardDocument, now); return standardDocumentMapper.insertStandardDocument(standardDocument); } @Override public int updateStandardDocument(StandardDocument standardDocument) { + Date now = DateUtils.getNowDate(); + standardDocument.setUpdatedTime(now); + if (Boolean.TRUE.equals(standardDocument.getFileChanged())) { + // 只有前端明确声明附件变更时,才刷新或清空上传元数据,避免普通字段编辑误伤附件信息。 + refreshUploadInfo(standardDocument, now); + } return standardDocumentMapper.updateStandardDocument(standardDocument); } @@ -41,4 +56,16 @@ public class StandardDocumentServiceImpl implements IStandardDocumentService { public int deleteStandardDocumentByObjId(Long objId) { return standardDocumentMapper.deleteStandardDocumentByObjId(objId); } + + private void refreshUploadInfo(StandardDocument standardDocument, Date operateTime) { + if (StringUtils.isNotBlank(standardDocument.getDocumentPath())) { + // 上传人与上传时间必须和当前实际附件保持一致,后续版本追溯才有意义。 + standardDocument.setUploader(SecurityUtils.getUsername()); + standardDocument.setUploadTime(operateTime); + return; + } + standardDocument.setUploader(null); + standardDocument.setUploadTime(null); + standardDocument.setDocumentSize(null); + } } diff --git a/aucma-base/src/main/resources/mapper/base/StandardDocumentMapper.xml b/aucma-base/src/main/resources/mapper/base/StandardDocumentMapper.xml index b091c30..631961f 100644 --- a/aucma-base/src/main/resources/mapper/base/StandardDocumentMapper.xml +++ b/aucma-base/src/main/resources/mapper/base/StandardDocumentMapper.xml @@ -103,10 +103,10 @@ "product_code" = #{productCode}, "product_name" = #{productName}, "version_no" = #{versionNo}, - "document_path" = #{documentPath}, - "document_size" = #{documentSize}, - "uploader" = #{uploader}, - "upload_time" = #{uploadTime}, + "document_path" = #{documentPath}, + "document_size" = #{documentSize}, + "uploader" = #{uploader}, + "upload_time" = #{uploadTime}, "effective_date" = #{effectiveDate}, "expiry_date" = #{expiryDate}, "status" = #{status},