excel_info.go 4.6 KB

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