package services import ( "context" "encoding/json" "eta/eta_forum_task/models" "eta/eta_forum_task/services/alarm_msg" "eta/eta_forum_task/services/eta_forum" "eta/eta_forum_task/utils" "fmt" "time" ) type AdminBatchSaveReq struct { List []*models.Admin } func AdminBatchSaveTask(cont context.Context) (err error) { deleteCache := true cacheKey := "eta_forum_task:EtaForumAdminUpdate" defer func() { if deleteCache { _ = utils.Rc.Delete(cacheKey) } if err != nil { go alarm_msg.SendAlarmMsg(utils.APP_NAME_CN+"同步管理员数据失败"+time.Now().Format("2006-01-02 15:04:05")+"
"+err.Error(), 3) } }() if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) { deleteCache = false err = fmt.Errorf("系统处理中,请稍后重试!") return } // 查询需要更新的图表信息总数 adminList, err := models.GetAllAdminList() if err != nil { return } if len(adminList) == 0 { return } // 更新管理员数据 //查询用户信息 var req AdminBatchSaveReq req.List = adminList reqJson, err := json.Marshal(req) if err != nil { err = fmt.Errorf("参数解析异常,Err:" + err.Error()) return } respItem, err := eta_forum.AdminBatchSaveLib(string(reqJson)) if err != nil { err = fmt.Errorf("上传管理员信息失败,Err:" + err.Error()) return } if respItem.Ret != 200 { err = fmt.Errorf("上传管理员信息失败,Err:%v,errMsg:%v", respItem.Msg, respItem.ErrMsg) return } fmt.Println("同步管理员数据完成, 同步管理员数据完成:", len(adminList), "条") return }