feat: 大屏新增虚拟工位滚动栏与多订单轮播,附件表增加删除原因及彻底清除留痕字段
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/attachment"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
|
||||
@@ -34,13 +35,17 @@ type attachmentRow struct {
|
||||
FileSize int `json:"fileSize"`
|
||||
FileExt string `json:"fileExt"`
|
||||
MimeType string `json:"mimeType"`
|
||||
Uploader string `json:"uploader"`
|
||||
Archived bool `json:"archived"`
|
||||
Deleted bool `json:"deleted"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
URL string `json:"url"`
|
||||
PreviewURL string `json:"previewUrl"`
|
||||
Uploader string `json:"uploader"`
|
||||
Archived bool `json:"archived"`
|
||||
Deleted bool `json:"deleted"`
|
||||
DeletedAt int64 `json:"deletedAt"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedReason string `json:"deletedReason"`
|
||||
PurgedAt int64 `json:"purgedAt"`
|
||||
PurgedBy string `json:"purgedBy"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
URL string `json:"url"`
|
||||
PreviewURL string `json:"previewUrl"`
|
||||
}
|
||||
|
||||
func toAttachmentRow(a *ent.Attachment) *attachmentRow {
|
||||
@@ -50,7 +55,9 @@ func toAttachmentRow(a *ent.Attachment) *attachmentRow {
|
||||
ID: a.ID, BizType: a.BizType, BizID: a.BizId, FileType: a.FileType,
|
||||
FileName: a.FileName, FilePath: a.FilePath, FileSize: a.FileSize,
|
||||
FileExt: a.FileExt, MimeType: a.MimeType, Uploader: a.Uploader,
|
||||
Archived: a.Archived, Deleted: a.Deleted, DeletedBy: a.DeletedBy,
|
||||
Archived: a.Archived, Deleted: a.Deleted, DeletedAt: a.DeletedAt,
|
||||
DeletedBy: a.DeletedBy, DeletedReason: a.DeletedReason,
|
||||
PurgedAt: a.PurgedAt, PurgedBy: a.PurgedBy,
|
||||
CreatedAt: a.CreatedAt.Unix(),
|
||||
URL: "/api/v1/attachment/file/" + strconv.Itoa(a.ID) + "?dl=1",
|
||||
PreviewURL: previewURL(a.FilePath),
|
||||
@@ -170,9 +177,35 @@ func AttachmentCenterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
for _, a := range list {
|
||||
rows = append(rows, toAttachmentRow(a))
|
||||
}
|
||||
// 视角死角提示:未勾选含已删除时,告知当前筛选下有多少已删除附件被隐藏
|
||||
hiddenDeleted := 0
|
||||
if q.Get("includeDeleted") != "true" {
|
||||
hq := svcCtx.EntClient.Attachment.Query().Where(attachment.DeletedEQ(true))
|
||||
if v := strings.TrimSpace(q.Get("fileType")); v != "" {
|
||||
hq = hq.Where(attachment.FileTypeEQ(strings.ToUpper(v)))
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("bizType")); v != "" {
|
||||
hq = hq.Where(attachment.BizTypeEQ(v))
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("bizId")); v != "" {
|
||||
hq = hq.Where(attachment.BizIdEQ(v))
|
||||
}
|
||||
if v := strings.TrimSpace(q.Get("fileName")); v != "" {
|
||||
hq = hq.Where(attachment.FileNameContainsFold(v))
|
||||
}
|
||||
if !start.IsZero() {
|
||||
hq = hq.Where(attachment.CreatedAtGTE(start))
|
||||
}
|
||||
if !end.IsZero() {
|
||||
hq = hq.Where(attachment.CreatedAtLTE(end))
|
||||
}
|
||||
if n, e := hq.Count(r.Context()); e == nil {
|
||||
hiddenDeleted = n
|
||||
}
|
||||
}
|
||||
httpx.Ok(w, map[string]any{
|
||||
"total": total, "list": rows, "page": page, "pageSize": pageSize,
|
||||
"disk": diskStatus(svcCtx),
|
||||
"hiddenDeleted": hiddenDeleted, "disk": diskStatus(svcCtx),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -214,47 +247,7 @@ func AttachmentFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// AttachmentDeleteHandler POST /attachment/delete {id} 逻辑删除(库内标记,物理文件交由归档任务处理)
|
||||
func AttachmentDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Id int `json:"id"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.Id <= 0 {
|
||||
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())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "attachment.delete", "", operator(r, ""), "attachment", att.BizId,
|
||||
"删除附件 "+att.FileName, nil)
|
||||
httpx.OkMessage(w, "删除成功", nil)
|
||||
}
|
||||
}
|
||||
// AttachmentDeleteHandler 重构版在 attachment_lifecycle.go(删除前预检 + 引用校验 + 保护期 + 实名留痕)
|
||||
|
||||
// AttachmentDiskStatusHandler GET /attachment/disk-status 磁盘剩余空间状态
|
||||
func AttachmentDiskStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
Reference in New Issue
Block a user