bi_dashboard.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models/bi_dashboard"
  5. "eta/eta_api/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // UpdateBiDashboardEditing 更新看板编辑状态
  10. func UpdateBiDashboardEditing(boardId, status, userId int, userName string) (ret bi_dashboard.BiDashboardEditingCache, err error) {
  11. if boardId <= 0 {
  12. return
  13. }
  14. cacheKey := ""
  15. cacheKey = fmt.Sprint(utils.CACHE_BI_DASHBOARD_EDITING, boardId)
  16. // 完成编辑
  17. if status == 2 {
  18. _ = utils.Rc.Delete(cacheKey)
  19. return
  20. }
  21. // 读取缓存中的结果
  22. var editor bi_dashboard.BiDashboardEditingCache
  23. strCache, _ := utils.Rc.RedisString(cacheKey)
  24. fmt.Println(strCache)
  25. if strCache != "" {
  26. e := json.Unmarshal([]byte(strCache), &editor)
  27. if e != nil {
  28. err = fmt.Errorf("解析缓存内容失败: %s", e.Error())
  29. return
  30. }
  31. }
  32. // 标记编辑中
  33. if status == 1 {
  34. // 无人编辑, 写入缓存
  35. if !editor.IsEditing {
  36. ret.IsEditing = true
  37. ret.AdminId = userId
  38. ret.Editor = userName
  39. ret.Tips = fmt.Sprintf("当前%s正在编辑看板", userName)
  40. b, _ := json.Marshal(ret)
  41. utils.Rc.SetNX(cacheKey, string(b), 3*time.Minute)
  42. return
  43. }
  44. // 有人编辑
  45. if editor.IsEditing {
  46. // 编辑用户与当前用户不一致, 返回编辑用户, 一致则更新缓存
  47. if userId == editor.AdminId {
  48. b, _ := json.Marshal(editor)
  49. utils.Rc.Do("SETEX", cacheKey, int64(180), string(b))
  50. }
  51. ret = editor
  52. return
  53. }
  54. } else {
  55. // 默认查询
  56. ret = editor
  57. }
  58. return
  59. }