excel_info.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/system"
  6. "eta/eta_mobile/utils"
  7. "fmt"
  8. "time"
  9. )
  10. // UpdateExcelEditMark 更新表格当前更新状态
  11. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  12. func UpdateExcelEditMark(excelInfoId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {
  13. //更新标记key
  14. key := fmt.Sprint(`crm:excel:edit:`, excelInfoId)
  15. opUserId, e := utils.Rc.RedisInt(key)
  16. var opUser models.MarkReportItem
  17. if e != nil {
  18. opUserInfoStr, tErr := utils.Rc.RedisString(key)
  19. if tErr == nil {
  20. tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
  21. if tErr == nil {
  22. opUserId = opUser.AdminId
  23. }
  24. }
  25. }
  26. if opUserId > 0 && opUserId != nowUserId {
  27. editor := opUser.Editor
  28. if editor == "" {
  29. //查询账号的用户姓名
  30. otherInfo, e := system.GetSysAdminById(opUserId)
  31. if e != nil {
  32. err = fmt.Errorf("查询其他编辑者信息失败")
  33. return
  34. }
  35. editor = otherInfo.RealName
  36. }
  37. ret.Status = 1
  38. ret.Msg = fmt.Sprintf("当前%s正在编辑中", editor)
  39. ret.Editor = editor
  40. return
  41. }
  42. if status == 1 {
  43. nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName}
  44. bt, e := json.Marshal(nowUser)
  45. if e != nil {
  46. err = fmt.Errorf("格式化编辑者信息失败")
  47. return
  48. }
  49. if opUserId > 0 {
  50. utils.Rc.Do("SETEX", key, int64(300), string(bt)) //3分钟缓存
  51. } else {
  52. utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存
  53. }
  54. } else if status == 0 {
  55. //清除编辑缓存
  56. _ = utils.Rc.Delete(key)
  57. }
  58. return
  59. }