feat(document): 添加附件变更控制字段并优化文档上传逻辑

- 新增 fileChanged 字段用于控制附件信息更新
- 移除控制器中的时间戳和上传人设置逻辑
- 在更新操作中添加条件判断避免误更新附件信息
- 实现 refreshUploadInfo 方法统一处理上传信息
- 优化数据库映射文件中的条件更新逻辑
- 集成 SecurityUtils 和 DateUtils 工具类
- 完善附件路径为空时的清理机制
master
zangch@mesnac.com 6 days ago
parent 013d1fa34f
commit d1c57e379d

@ -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));
}

@ -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())

@ -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);
}
}

@ -103,10 +103,10 @@
<if test="productCode != null">"product_code" = #{productCode},</if>
<if test="productName != null">"product_name" = #{productName},</if>
<if test="versionNo != null">"version_no" = #{versionNo},</if>
<if test="documentPath != null">"document_path" = #{documentPath},</if>
<if test="documentSize != null">"document_size" = #{documentSize},</if>
<if test="uploader != null">"uploader" = #{uploader},</if>
<if test="uploadTime != null">"upload_time" = #{uploadTime},</if>
<if test="documentPath != null or fileChanged == true">"document_path" = #{documentPath},</if>
<if test="documentSize != null or fileChanged == true">"document_size" = #{documentSize},</if>
<if test="uploader != null or fileChanged == true">"uploader" = #{uploader},</if>
<if test="uploadTime != null or fileChanged == true">"upload_time" = #{uploadTime},</if>
<if test="effectiveDate != null">"effective_date" = #{effectiveDate},</if>
<if test="expiryDate != null">"expiry_date" = #{expiryDate},</if>
<if test="status != null">"status" = #{status},</if>

Loading…
Cancel
Save