feat: complete workbench split admin routes

This commit is contained in:
richjohnrambo
2026-09-17 23:37:16 +08:00
parent 7099a33cde
commit 5c805c7b09
6 changed files with 334 additions and 26 deletions
+39 -18
View File
@@ -64,6 +64,8 @@ func (a *API) Register(mux *http.ServeMux) {
mux.HandleFunc("/internal/admin/workbench/apps", a.withInternalAdminAuth(a.adminWorkbenchApps))
mux.HandleFunc("/internal/admin/workbench/apps/disable", a.withInternalAdminAuth(a.adminWorkbenchAppDisable))
mux.HandleFunc("/internal/admin/workbench/apps/reorder", a.withInternalAdminAuth(a.adminWorkbenchAppsReorder))
mux.HandleFunc("/internal/admin/workbench/organization/departments", a.withInternalAdminAuth(a.adminOrganizationDepartments))
mux.HandleFunc("/internal/admin/workbench/organization/members", a.withInternalAdminAuth(a.adminOrganizationMembers))
mux.HandleFunc("/internal/admin/workbench/mailbox-config", a.withInternalAdminAuth(a.adminMailboxConfig))
mux.HandleFunc("/internal/admin/workbench/feedback-config", a.withInternalAdminAuth(a.adminFeedbackConfig))
}
@@ -698,11 +700,6 @@ func (a *API) dailyReportResource(w http.ResponseWriter, r *http.Request, p *aut
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "daily_report", "daily_report.draft.saved", report.ReportID,
[]int64{p.UserID}, "日报", report.ReportDate.Format("2006-01-02"),
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
writeSuccess(w, r, dailyReportPayload(*report))
case tail == "draft" && r.Method == http.MethodPut:
var body struct {
@@ -718,8 +715,8 @@ func (a *API) dailyReportResource(w http.ResponseWriter, r *http.Request, p *aut
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "daily_report", "daily_report.submitted", report.ReportID,
[]int64{p.UserID}, "日报已提交", report.ReportDate.Format("2006-01-02"),
if !a.publishWorkbenchEvent(w, r, p, "daily_report", "daily_report.draft.saved", report.ReportID,
[]int64{p.UserID}, "日报", report.ReportDate.Format("2006-01-02"),
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
@@ -736,6 +733,11 @@ func (a *API) dailyReportResource(w http.ResponseWriter, r *http.Request, p *aut
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "daily_report", "daily_report.submitted", report.ReportID,
[]int64{p.UserID}, "日报已提交", report.ReportDate.Format("2006-01-02"),
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
writeSuccess(w, r, dailyReportPayload(*report))
default:
methodNotAllowed(w, r)
@@ -747,7 +749,17 @@ func (a *API) dailyReportStatistics(w http.ResponseWriter, r *http.Request, p *a
methodNotAllowed(w, r)
return
}
writeSuccess(w, r, map[string]any{"expected_count": 0, "submitted_count": 0, "missing_count": 0, "scope": map[string]any{"department_id": r.URL.Query().Get("department_id")}})
date, err := parseDate(firstNonEmpty(r.URL.Query().Get("date"), time.Now().Format("2006-01-02")))
if err != nil {
writeError(w, r, http.StatusBadRequest, 30000, reasonMalformedRequest, "malformed request", map[string]any{"field": "date"})
return
}
stats, err := st.DailyReportStats(r.Context(), date, r.URL.Query().Get("department_id"))
if err != nil {
writeStoreError(w, r, err)
return
}
writeSuccess(w, r, reportStatsPayload(stats))
}
func (a *API) dailyReportReminders(w http.ResponseWriter, r *http.Request, p *auth.Principal, st *store.Store) {
@@ -819,11 +831,6 @@ func (a *API) monthlyReportResource(w http.ResponseWriter, r *http.Request, p *a
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "monthly_report", "monthly_report.draft.saved", report.ReportID,
[]int64{p.UserID}, "月报", report.Month,
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
writeSuccess(w, r, monthlyReportPayload(*report))
case tail == "draft" && r.Method == http.MethodPut:
var body struct {
@@ -840,8 +847,8 @@ func (a *API) monthlyReportResource(w http.ResponseWriter, r *http.Request, p *a
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "monthly_report", "monthly_report.submitted", report.ReportID,
[]int64{p.UserID}, "月报已提交", report.Month,
if !a.publishWorkbenchEvent(w, r, p, "monthly_report", "monthly_report.draft.saved", report.ReportID,
[]int64{p.UserID}, "月报", report.Month,
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
@@ -858,8 +865,8 @@ func (a *API) monthlyReportResource(w http.ResponseWriter, r *http.Request, p *a
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "monthly_report", "monthly_report.reopened", report.ReportID,
[]int64{p.UserID}, "月报已重开", report.Month,
if !a.publishWorkbenchEvent(w, r, p, "monthly_report", "monthly_report.submitted", report.ReportID,
[]int64{p.UserID}, "月报已提交", report.Month,
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
@@ -876,6 +883,11 @@ func (a *API) monthlyReportResource(w http.ResponseWriter, r *http.Request, p *a
writeStoreError(w, r, err)
return
}
if !a.publishWorkbenchEvent(w, r, p, "monthly_report", "monthly_report.reopened", report.ReportID,
[]int64{p.UserID}, "月报已重开", report.Month,
map[string]any{"report_id": report.ReportID, "version": report.Version, "status": report.Status}) {
return
}
writeSuccess(w, r, monthlyReportPayload(*report))
default:
methodNotAllowed(w, r)
@@ -887,7 +899,16 @@ func (a *API) monthlyReportStatistics(w http.ResponseWriter, r *http.Request, p
methodNotAllowed(w, r)
return
}
writeSuccess(w, r, map[string]any{"expected_count": 0, "submitted_count": 0, "missing_count": 0, "scope": map[string]any{"department_id": r.URL.Query().Get("department_id")}})
month := strings.TrimSpace(r.URL.Query().Get("month"))
if month == "" {
month = time.Now().Format("2006-01")
}
stats, err := st.MonthlyReportStats(r.Context(), month, r.URL.Query().Get("department_id"))
if err != nil {
writeStoreError(w, r, err)
return
}
writeSuccess(w, r, reportStatsPayload(stats))
}
func (a *API) mailboxConfig(w http.ResponseWriter, r *http.Request, p *auth.Principal, st *store.Store) {