bi_dashboard.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models/bi_dashboard"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "time"
  8. )
  9. func UpdateBiDashboardEditing(boardId, status, userId int, userName string) (ret bi_dashboard.BiDashboardEditingCache, err error) {
  10. if boardId <= 0 {
  11. return
  12. }
  13. cacheKey := ""
  14. cacheKey = fmt.Sprint(utils.CACHE_BI_DASHBOARD_EDITING, boardId)
  15. if status == 2 {
  16. _ = utils.Rc.Delete(cacheKey)
  17. return
  18. }
  19. var editor bi_dashboard.BiDashboardEditingCache
  20. strCache, _ := utils.Rc.RedisString(cacheKey)
  21. fmt.Println(strCache)
  22. if strCache != "" {
  23. e := json.Unmarshal([]byte(strCache), &editor)
  24. if e != nil {
  25. err = fmt.Errorf("解析缓存内容失败: %s", e.Error())
  26. return
  27. }
  28. }
  29. if status == 1 {
  30. if !editor.IsEditing {
  31. ret.IsEditing = true
  32. ret.AdminId = userId
  33. ret.Editor = userName
  34. ret.Tips = fmt.Sprintf("当前%s正在编辑看板", userName)
  35. b, _ := json.Marshal(ret)
  36. utils.Rc.SetNX(cacheKey, string(b), 3*time.Minute)
  37. return
  38. }
  39. if editor.IsEditing {
  40. if userId == editor.AdminId {
  41. b, _ := json.Marshal(editor)
  42. utils.Rc.Do("SETEX", cacheKey, int64(180), string(b))
  43. }
  44. ret = editor
  45. return
  46. }
  47. } else {
  48. ret = editor
  49. }
  50. return
  51. }