123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package services
- import (
- "encoding/json"
- "eta_gn/eta_api/models/bi_dashboard"
- "eta_gn/eta_api/utils"
- "fmt"
- "time"
- )
- func UpdateBiDashboardEditing(boardId, status, userId int, userName string) (ret bi_dashboard.BiDashboardEditingCache, err error) {
- if boardId <= 0 {
- return
- }
- cacheKey := ""
- cacheKey = fmt.Sprint(utils.CACHE_BI_DASHBOARD_EDITING, boardId)
- if status == 2 {
- _ = utils.Rc.Delete(cacheKey)
- return
- }
- var editor bi_dashboard.BiDashboardEditingCache
- strCache, _ := utils.Rc.RedisString(cacheKey)
- fmt.Println(strCache)
- if strCache != "" {
- e := json.Unmarshal([]byte(strCache), &editor)
- if e != nil {
- err = fmt.Errorf("解析缓存内容失败: %s", e.Error())
- return
- }
- }
- if status == 1 {
- if !editor.IsEditing {
- ret.IsEditing = true
- ret.AdminId = userId
- ret.Editor = userName
- ret.Tips = fmt.Sprintf("当前%s正在编辑看板", userName)
- b, _ := json.Marshal(ret)
- utils.Rc.SetNX(cacheKey, string(b), 3*time.Minute)
- return
- }
- if editor.IsEditing {
- if userId == editor.AdminId {
- b, _ := json.Marshal(editor)
- utils.Rc.Do("SETEX", cacheKey, int64(180), string(b))
- }
- ret = editor
- return
- }
- } else {
- ret = editor
- }
- return
- }
|