excel_info.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. excelModel "eta/eta_api/models/data_manage/excel"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "time"
  10. )
  11. // UpdateExcelEditMark 更新表格当前更新状态
  12. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  13. func UpdateExcelEditMark(excelInfoId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {
  14. //更新标记key
  15. key := fmt.Sprint(`crm:excel:edit:`, excelInfoId)
  16. opUserId, e := utils.Rc.RedisInt(key)
  17. var opUser models.MarkReportItem
  18. if e != nil {
  19. opUserInfoStr, tErr := utils.Rc.RedisString(key)
  20. if tErr == nil {
  21. tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
  22. if tErr == nil {
  23. opUserId = opUser.AdminId
  24. }
  25. }
  26. }
  27. if opUserId > 0 && opUserId != nowUserId {
  28. editor := opUser.Editor
  29. if editor == "" {
  30. //查询账号的用户姓名
  31. otherInfo, e := system.GetSysAdminById(opUserId)
  32. if e != nil {
  33. err = fmt.Errorf("查询其他编辑者信息失败")
  34. return
  35. }
  36. editor = otherInfo.RealName
  37. }
  38. ret.Status = 1
  39. ret.Msg = fmt.Sprintf("当前%s正在编辑中", editor)
  40. ret.Editor = editor
  41. return
  42. }
  43. if status == 1 {
  44. nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName}
  45. bt, e := json.Marshal(nowUser)
  46. if e != nil {
  47. err = fmt.Errorf("格式化编辑者信息失败")
  48. return
  49. }
  50. if opUserId > 0 {
  51. utils.Rc.Do("SETEX", key, int64(300), string(bt)) //3分钟缓存
  52. } else {
  53. utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存
  54. }
  55. } else if status == 0 {
  56. //清除编辑缓存
  57. _ = utils.Rc.Delete(key)
  58. }
  59. return
  60. }
  61. // GetTradeAnalysisTableOpButton 获取持仓分析表格的操作权限
  62. func GetTradeAnalysisTableOpButton(belongUserId, sysUserId int, roleTypeCode string, haveOperaAuth bool) (button excelModel.ExcelInfoDetailButton) {
  63. // 这部分没有加到数据权限里,这里先注释掉
  64. //if !haveOperaAuth {
  65. // return
  66. //}
  67. // 非管理员角色查看其他用户创建的表格,可刷新、另存为、下载表格;
  68. button.RefreshButton = true
  69. button.CopyButton = true
  70. button.DownloadButton = true
  71. // 创建人、管理员有权限编辑和删除
  72. if belongUserId == sysUserId || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  73. button.OpButton = true
  74. button.DeleteButton = true
  75. }
  76. return
  77. }