excel_info.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. excel3 "eta/eta_mobile/models/data_manage/excel"
  6. "eta/eta_mobile/models/system"
  7. "eta/eta_mobile/services/data/data_manage_permission"
  8. "eta/eta_mobile/utils"
  9. "fmt"
  10. "time"
  11. )
  12. // UpdateExcelEditMark 更新表格当前更新状态
  13. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  14. func UpdateExcelEditMark(excelInfoId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {
  15. //更新标记key
  16. key := fmt.Sprint(`crm:excel:edit:`, excelInfoId)
  17. opUserId, e := utils.Rc.RedisInt(key)
  18. var opUser models.MarkReportItem
  19. if e != nil {
  20. opUserInfoStr, tErr := utils.Rc.RedisString(key)
  21. if tErr == nil {
  22. tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
  23. if tErr == nil {
  24. opUserId = opUser.AdminId
  25. }
  26. }
  27. }
  28. if opUserId > 0 && opUserId != nowUserId {
  29. editor := opUser.Editor
  30. if editor == "" {
  31. //查询账号的用户姓名
  32. otherInfo, e := system.GetSysAdminById(opUserId)
  33. if e != nil {
  34. err = fmt.Errorf("查询其他编辑者信息失败")
  35. return
  36. }
  37. editor = otherInfo.RealName
  38. }
  39. ret.Status = 1
  40. ret.Msg = fmt.Sprintf("当前%s正在编辑中", editor)
  41. ret.Editor = editor
  42. return
  43. }
  44. if status == 1 {
  45. nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName}
  46. bt, e := json.Marshal(nowUser)
  47. if e != nil {
  48. err = fmt.Errorf("格式化编辑者信息失败")
  49. return
  50. }
  51. if opUserId > 0 {
  52. utils.Rc.Do("SETEX", key, int64(300), string(bt)) //3分钟缓存
  53. } else {
  54. utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存
  55. }
  56. } else if status == 0 {
  57. //清除编辑缓存
  58. _ = utils.Rc.Delete(key)
  59. }
  60. return
  61. }
  62. // GetBalanceExcelIdsByAdminId 获取用户有权限的平衡表excelIds
  63. func GetBalanceExcelIdsByAdminId(adminId int, condition string, pars []interface{}, permissionEdbIdList, permissionClassifyIdList []int) (authIds []int, err error) {
  64. //找到当前协作人相关的表格ID
  65. obj := new(excel3.ExcelWorker)
  66. existList, err := obj.GetBySysUserId(adminId)
  67. if err != nil {
  68. //br.Msg = "获取表格协作人失败!"
  69. //br.ErrMsg = "获取表格协作人失败,Err:" + err.Error()
  70. return
  71. }
  72. var excelIds []int
  73. newCondition := condition
  74. newPars := pars
  75. if len(existList) > 0 {
  76. for _, v := range existList {
  77. excelIds = append(excelIds, v.ExcelInfoId)
  78. }
  79. newCondition += fmt.Sprintf(` AND ( excel_info_id IN (%s) or sys_user_id = ?)`, utils.GetOrmInReplace(len(excelIds)))
  80. newPars = append(newPars, excelIds, adminId)
  81. } else {
  82. newCondition += ` AND sys_user_id = ? `
  83. newPars = append(newPars, adminId)
  84. }
  85. //获取表格信息
  86. tmpList, e := excel3.GetNoContentExcelListByConditionNoPage(newCondition, newPars)
  87. if e != nil && e.Error() != utils.ErrNoRow() {
  88. //br.Success = true
  89. //br.Msg = "获取表格信息失败"
  90. //br.ErrMsg = "获取表格信息失败,Err:" + e.Error()
  91. return
  92. }
  93. classifyIdListTmp := make([]int, 0)
  94. for _, v := range tmpList {
  95. classifyIdListTmp = append(classifyIdListTmp, v.ExcelClassifyId)
  96. }
  97. classifyMap := make(map[int]*excel3.ExcelClassify)
  98. // 分类信息
  99. if len(classifyIdListTmp) > 0 {
  100. classifyListTmp, e := excel3.GetClassifyByIdList(classifyIdListTmp)
  101. if e != nil {
  102. //br.Msg = "获取表格分类信息失败"
  103. //br.ErrMsg = "获取表格分类列表数据失败,Err:" + e.Error()
  104. return
  105. }
  106. for _, v := range classifyListTmp {
  107. classifyMap[v.ExcelClassifyId] = v
  108. }
  109. }
  110. excelIds = make([]int, 0)
  111. for _, v := range tmpList {
  112. // 数据权限
  113. if classifyInfo, ok := classifyMap[v.ExcelClassifyId]; ok {
  114. v.HaveOperaAuth = data_manage_permission.CheckExcelPermissionByPermissionIdList(v.IsJoinPermission, classifyInfo.IsJoinPermission, v.ExcelInfoId, v.ExcelClassifyId, permissionEdbIdList, permissionClassifyIdList)
  115. if v.HaveOperaAuth {
  116. excelIds = append(excelIds, v.ExcelInfoId)
  117. }
  118. }
  119. }
  120. authIds = excelIds
  121. return
  122. }