GetSyncProgress 获取同步进度 @Summary Get sync progress @Description Get synchronization progress @Tags Synchronization @Accept json @Produce json @Security BearerAuth @Param from path int true "Source: 1=WeCom, 2=DingTalk" @Success 200 {object} model.CommonResponse{data=interface{}} "Operation succeeded"
(c *gin.Context)
| 93 | // @Failure 404 {object} model.CommonResponse "Enterprise not found" |
| 94 | // @Router /api/sync-progress/{from} [get] |
| 95 | func GetSyncProgress(c *gin.Context) { |
| 96 | fromStr := c.Param("from") |
| 97 | from, err := strconv.Atoi(fromStr) |
| 98 | if err != nil { |
| 99 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 100 | return |
| 101 | } |
| 102 | |
| 103 | // 验证 from 参数 |
| 104 | if from != model.DepartmentFromWecom && from != model.DepartmentFromDingtalk { |
| 105 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(fmt.Errorf("invalid from parameter: %d", from))) |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | var eid = config.GetEID(c) |
| 110 | |
| 111 | var progress interface{} |
| 112 | |
| 113 | switch from { |
| 114 | case model.DepartmentFromWecom: |
| 115 | wecomProgressManager := saas_wecom.GetWecomSyncProgressManager() |
| 116 | progress = wecomProgressManager.GetProgress(from, eid) |
| 117 | case model.DepartmentFromDingtalk: |
| 118 | dingtalkProgressManager := saas_dingtalk.GetDingtalkSyncProgressManager() |
| 119 | progress = dingtalkProgressManager.GetProgress(from, eid) |
| 120 | default: |
| 121 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(fmt.Errorf("unsupported from parameter: %d", from))) |
| 122 | return |
| 123 | } |
| 124 | |
| 125 | // 检查指针类型的nil值 |
| 126 | if progress == nil || (progress.(*saas_wecom.SyncProgress)) == nil { |
| 127 | // 默认返回同步失败状态 |
| 128 | defaultProgress := &saas_wecom.SyncProgress{ |
| 129 | From: from, |
| 130 | Eid: eid, |
| 131 | Progress: 0, |
| 132 | Status: "failed", |
| 133 | Message: "未找到同步进度记录", |
| 134 | StartTime: time.Now(), |
| 135 | EndTime: time.Now(), |
| 136 | } |
| 137 | c.JSON(http.StatusOK, model.Success.ToResponse(defaultProgress)) |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | c.JSON(http.StatusOK, model.Success.ToResponse(progress)) |
| 142 | } |
| 143 | |
| 144 | // GetAllSyncProgress 获取所有同步进度 |
| 145 | // @Summary Get all sync progress |
nothing calls this directly
no test coverage detected