feat: 大屏改为纯流式自适应布局,新增KPI带与产线动态拓扑地图
This commit is contained in:
@@ -263,91 +263,4 @@ func AttachmentDiskStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// AttachmentArchiveHandler POST /attachment/archive {dryRun} 归档
|
||||
// 把「早于本地保留年数」的附件移动到 ArchiveDir 并标记 archived=true(保留索引可追溯)。
|
||||
// ArchiveDir 为空时只标记不移动;dryRun=true 时仅返回将被归档的数量。
|
||||
func AttachmentArchiveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
DryRun bool `json:"dryRun"`
|
||||
}
|
||||
_ = httpx.ParseJSON(r, &req)
|
||||
cfg := svcCtx.Config.Upload
|
||||
years := cfg.LocalRetentionYears
|
||||
if years <= 0 {
|
||||
years = 1
|
||||
}
|
||||
cutYear := time.Now().Year() - years // 早于该年份的附件可归档
|
||||
svc := logic.New(svcCtx)
|
||||
recs, err := svc.ListArchivableAttachments(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3314, err.Error())
|
||||
return
|
||||
}
|
||||
moved, marked, failed := 0, 0, 0
|
||||
for _, rec := range recs {
|
||||
if rec.CreatedAt.Year() > cutYear-1 {
|
||||
continue
|
||||
}
|
||||
if req.DryRun {
|
||||
marked++
|
||||
continue
|
||||
}
|
||||
if cfg.ArchiveDir != "" {
|
||||
src, ok1 := safeAbsPath(cfg.Dir, rec.FilePath)
|
||||
dst, ok2 := safeAbsPath(cfg.ArchiveDir, rec.FilePath)
|
||||
if !ok1 || !ok2 {
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
if err := os.Rename(src, dst); err != nil {
|
||||
if err2 := copyFile(src, dst); err2 != nil {
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
_ = os.Remove(src)
|
||||
}
|
||||
moved++
|
||||
}
|
||||
if err := svc.MarkArchived(r.Context(), rec.ID); err != nil {
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
marked++
|
||||
}
|
||||
if !req.DryRun {
|
||||
svcCtx.EventLog.Write(r.Context(), "attachment.archive", "", operator(r, ""), "attachment", "archive",
|
||||
fmt.Sprintf("附件归档:移动%d 标记%d 失败%d(早于 %d 年)", moved, marked, failed, cutYear),
|
||||
map[string]any{"moved": moved, "marked": marked, "failed": failed})
|
||||
}
|
||||
httpx.Ok(w, map[string]any{
|
||||
"moved": moved, "marked": marked, "failed": failed,
|
||||
"cutYear": cutYear, "archiveDir": cfg.ArchiveDir, "dryRun": req.DryRun,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// copyFile 兜底复制(跨盘符 Rename 失败时用)。
|
||||
func copyFile(src, dst string) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := out.ReadFrom(in); err != nil {
|
||||
_ = out.Close()
|
||||
return err
|
||||
}
|
||||
return out.Close()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/backup"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// BackupItemsHandler GET /api/v1/backup/items 可选数据项(质量 4 表不出现)
|
||||
func BackupItemsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
httpx.Ok(w, svcCtx.Backup.ListItems())
|
||||
}
|
||||
}
|
||||
|
||||
// BackupStartHandler POST /api/v1/backup/start 启动备份
|
||||
func BackupStartHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req backup.BackupRequest
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
req.Operator = operator(r, "")
|
||||
jobID, err := svcCtx.Backup.StartBackup(req)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2601, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"jobId": jobID})
|
||||
}
|
||||
}
|
||||
|
||||
// BackupProgressHandler GET /api/v1/backup/progress?jobId=
|
||||
func BackupProgressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
jobID := r.URL.Query().Get("jobId")
|
||||
p, ok := svcCtx.Backup.Progress(jobID)
|
||||
if !ok {
|
||||
httpx.Fail(w, 2602, "任务不存在")
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, p)
|
||||
}
|
||||
}
|
||||
|
||||
// CleanupCheckHandler POST /api/v1/cleanup/check 覆盖预检(部分/无覆盖拒绝)
|
||||
func CleanupCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Start int64 `json:"start"`
|
||||
End int64 `json:"end"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
cov, err := svcCtx.Backup.CheckCoverage(req.Start, req.End)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2603, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, cov)
|
||||
}
|
||||
}
|
||||
|
||||
// CleanupStartHandler POST /api/v1/cleanup/start 启动清理(物理删除)
|
||||
func CleanupStartHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req backup.CleanupRequest
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
req.Operator = operator(r, "")
|
||||
jobID, err := svcCtx.Backup.StartCleanup(req)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2604, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"jobId": jobID})
|
||||
}
|
||||
}
|
||||
|
||||
// CleanupProgressHandler GET /api/v1/cleanup/progress?jobId=
|
||||
func CleanupProgressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
jobID := r.URL.Query().Get("jobId")
|
||||
p, ok := svcCtx.Backup.Progress(jobID)
|
||||
if !ok {
|
||||
httpx.Fail(w, 2605, "任务不存在")
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, p)
|
||||
}
|
||||
}
|
||||
|
||||
// BackupDrivesHandler GET /api/v1/backup/drives 列出本机盘符(admin-only,用于服务端目录选择器)
|
||||
func BackupDrivesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
drives, err := backup.ListDrives()
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2606, "读取盘符失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, drives)
|
||||
}
|
||||
}
|
||||
|
||||
// BackupListDirHandler GET /api/v1/backup/listdir?path= 列出给定目录的一级子目录(admin-only)
|
||||
func BackupListDirHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
dirs, err := backup.ListDir(r.URL.Query().Get("path"))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2607, "读取目录失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, dirs)
|
||||
}
|
||||
}
|
||||
|
||||
// BackupReminderHandler GET /api/v1/backup/reminder 清理提醒(按 backup_record 最近 success + 提醒周期算超期)
|
||||
func BackupReminderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
days := logic.New(svcCtx).CfgInt(r.Context(), logic.CfgArchiveRemindDays, 7)
|
||||
res, err := svcCtx.Backup.Reminder(days)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2608, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
|
||||
// CleanupPreviewHandler POST /api/v1/cleanup/preview 清理预览(将删除行数/字节,不落盘)
|
||||
func CleanupPreviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Start int64 `json:"start"`
|
||||
End int64 `json:"end"`
|
||||
Items []string `json:"items"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if req.End <= req.Start {
|
||||
httpx.Fail(w, 2609, "时间窗不合法")
|
||||
return
|
||||
}
|
||||
if len(req.Items) == 0 {
|
||||
httpx.Fail(w, 2610, "请至少选择一个数据项")
|
||||
return
|
||||
}
|
||||
res, err := svcCtx.Backup.Preview(req.Start, req.End, req.Items)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2611, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
|
||||
// BackupRecordsHandler GET /api/v1/backup/records 备份/清理历史(分页 50/页)
|
||||
func BackupRecordsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
page, _ := strconv.Atoi(q.Get("page"))
|
||||
size, _ := strconv.Atoi(q.Get("size"))
|
||||
res, err := svcCtx.Backup.ListRecords(page, size, q.Get("status"), q.Get("scope"))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2612, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
@@ -47,10 +47,9 @@ var pathPermMap = map[string]string{
|
||||
//(produce.quality:process / produce.quality:final),此处不映射单一码,避免误拦/误放。
|
||||
// 检验员签字确认(需求B 第二签,巡检终端「待签任务」)
|
||||
"POST:/api/v1/signs/inspector": "sys.inspect:sign",
|
||||
// 附件中心(sys.attachment 菜单下):删除 / 归档清理属管理动作;
|
||||
// 附件中心(sys.attachment 菜单下):删除属管理动作;
|
||||
// 列表/预览/下载不设按钮门槛(有菜单权限即可查阅)
|
||||
"POST:/api/v1/attachment/delete": "sys.attachment:manage",
|
||||
"POST:/api/v1/attachment/archive": "sys.attachment:manage",
|
||||
"POST:/api/v1/attachment/delete": "sys.attachment:manage",
|
||||
// 账号管理(拆分自原 sys.rbac:user;sys.account 菜单下增/改/删)
|
||||
"POST:/api/v1/users": "sys.account:add",
|
||||
"PUT:/api/v1/users": "sys.account:edit",
|
||||
|
||||
@@ -336,6 +336,19 @@ func DashboardSnapshotInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFu
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardConfigInternalHandler 门口看板(项目A)启动配置:标题文字 + 语音播报开关。
|
||||
// 基础设置页(dashboard.board.title / dashboard.board.voice)维护,保存即生效;看板端轮询跟随。
|
||||
func DashboardConfigInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vo, err := logic.New(svcCtx).GetSettings(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2010, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"title": vo.DashboardTitle, "voiceOn": vo.DashboardVoice})
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardMaterialQueryHandler 看板物料追溯查询入口(C7):转发 WMS 物料档案 + 库存。
|
||||
func DashboardMaterialQueryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -37,6 +37,20 @@ func RegisterRoutes(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
{Method: http.MethodPost, Path: "/permissions", Handler: CreatePermissionHandler(serverCtx)},
|
||||
{Method: http.MethodPut, Path: "/permissions", Handler: UpdatePermissionHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/permissions/:id", Handler: DeletePermissionHandler(serverCtx)},
|
||||
|
||||
// 备份到外部存储(U盘/移动硬盘)+ 按时间窗物理清理
|
||||
{Method: http.MethodGet, Path: "/backup/items", Handler: BackupItemsHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/backup/start", Handler: BackupStartHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/backup/progress", Handler: BackupProgressHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/cleanup/check", Handler: CleanupCheckHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/cleanup/start", Handler: CleanupStartHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/cleanup/progress", Handler: CleanupProgressHandler(serverCtx)},
|
||||
// 数据归档增强:目录选择器 / 提醒 / 预览 / 历史
|
||||
{Method: http.MethodGet, Path: "/backup/drives", Handler: BackupDrivesHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/backup/listdir", Handler: BackupListDirHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/backup/reminder", Handler: BackupReminderHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/cleanup/preview", Handler: CleanupPreviewHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/backup/records", Handler: BackupRecordsHandler(serverCtx)},
|
||||
}
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares([]rest.Middleware{permissionGuard(serverCtx)}, jwtAdmin...),
|
||||
|
||||
@@ -44,6 +44,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/snapshot", Handler: internal(production.DashboardSnapshotInternalHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/config", Handler: internal(production.DashboardConfigInternalHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/material-query", Handler: internal(production.DashboardMaterialQueryHandler(serverCtx)),
|
||||
})
|
||||
@@ -343,7 +346,6 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodGet, Path: "/attachment/all", Handler: AttachmentCenterHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/attachment/file/:id", Handler: AttachmentFileHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/attachment/disk-status", Handler: DiskStatusHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/attachment/archive", Handler: AttachmentArchiveHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/attachment/delete", Handler: AttachmentDeleteHandler(serverCtx)},
|
||||
|
||||
// ---------- 工艺流程/工位(块3) ----------
|
||||
|
||||
Reference in New Issue
Block a user