系统管理员点击同步时同步半年历史数据
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"stock-user-system/internal/middleware"
|
||||
"stock-user-system/internal/models"
|
||||
"stock-user-system/internal/services"
|
||||
|
||||
@@ -146,8 +147,21 @@ func (h *StockHandler) SyncStatus(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TriggerSync 手动触发同步(管理员)。
|
||||
// 系统管理员点击时同步近半年历史数据,其他管理员只同步当天。
|
||||
func (h *StockHandler) TriggerSync(c *gin.Context) {
|
||||
count, err := h.Svc.Sync(c.Request.Context(), "manual")
|
||||
user, ok := middleware.GetCurrentUser(c)
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": "未登录"})
|
||||
return
|
||||
}
|
||||
|
||||
var count int
|
||||
var err error
|
||||
if user.Role == models.RoleSystemAdmin {
|
||||
count, err = h.Svc.SyncHistory(c.Request.Context(), "manual", 6)
|
||||
} else {
|
||||
count, err = h.Svc.Sync(c.Request.Context(), "manual")
|
||||
}
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user