提交
This commit is contained in:
@@ -199,8 +199,13 @@ func AttachmentFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
// 中文文件名走 RFC 5987;下载(dl=1)才强制 attachment,否则内联预览
|
||||
disp := "inline"
|
||||
// 中文文件名走 RFC 5987;图片/PDF 内联预览,其他类型强制下载;
|
||||
// 显式 dl=1 一律强制下载(对齐 WMS /uploads/ 行为)。
|
||||
ext := strings.ToLower(filepath.Ext(abs))
|
||||
disp := "attachment"
|
||||
if isInlineExt(ext) {
|
||||
disp = "inline"
|
||||
}
|
||||
if r.URL.Query().Get("dl") == "1" {
|
||||
disp = "attachment"
|
||||
}
|
||||
@@ -219,6 +224,27 @@ func AttachmentDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.BadRequest(w, "参数错误:id 必填")
|
||||
return
|
||||
}
|
||||
// 删除保护(对齐 WMS):关键工艺文件 / 保留期内检验件禁止删除,避免质量/工艺记录丢失。
|
||||
rec, gerr := logic.New(svcCtx).GetAttachment(r.Context(), req.Id)
|
||||
if gerr != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
switch rec.FileType {
|
||||
case FileTypeProcessPDF, FileTypeProcessCard:
|
||||
httpx.Fail(w, 3315, "工艺流程 / 流程卡为关键工艺文件,禁止删除")
|
||||
return
|
||||
case FileTypeInspectionPhoto, FileTypeInspectionPDF:
|
||||
years := svcCtx.Config.Upload.LocalRetentionYears
|
||||
if years <= 0 {
|
||||
years = 1
|
||||
}
|
||||
cutYear := time.Now().Year() - years
|
||||
if rec.CreatedAt.Year() >= cutYear {
|
||||
httpx.Fail(w, 3315, fmt.Sprintf("检验记录在质量追溯保留期(%d 年)内,禁止删除", years))
|
||||
return
|
||||
}
|
||||
}
|
||||
att, err := logic.New(svcCtx).DeleteAttachment(r.Context(), req.Id, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3313, "删除附件失败:"+err.Error())
|
||||
|
||||
Reference in New Issue
Block a user