ppt_grant.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package ppt
  2. import (
  3. "errors"
  4. "eta/eta_mobile/models"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. // GrantPpt 授权ppt
  10. func GrantPpt(pptId, grantType int, grantAdminIdStr string, sysUserId int) (err error, errMsg string) {
  11. list := make([]*models.PptV2Grant, 0)
  12. switch grantType {
  13. case 1:
  14. departmentId := 1 //ficc研究员部门
  15. tmpV := &models.PptV2Grant{
  16. //GrantId: 0,
  17. PptId: int64(pptId),
  18. DepartmentId: int64(departmentId),
  19. GrantAdminId: 0,
  20. CreateTime: time.Now(),
  21. }
  22. list = append(list, tmpV)
  23. case 2:
  24. if grantAdminIdStr == `` {
  25. errMsg = `请选择用户`
  26. return
  27. }
  28. grantAdminIdStrList := strings.Split(grantAdminIdStr, ",")
  29. lenGrantAdminIdStrList := len(grantAdminIdStrList) //指定用户的人数
  30. for _, v := range grantAdminIdStrList {
  31. grantAdminId, tmpErr := strconv.Atoi(v)
  32. if tmpErr != nil {
  33. errMsg = `数据异常`
  34. err = errors.New("用户转int失败," + tmpErr.Error())
  35. return
  36. }
  37. //如果只选择了自己作为指定的人,那么就提示他报错。如果多人,那么就过滤自己
  38. if grantAdminId == sysUserId {
  39. if lenGrantAdminIdStrList == 1 {
  40. errMsg = `不允许选择本人作为共享用户`
  41. return
  42. }
  43. continue
  44. }
  45. tmpV := &models.PptV2Grant{
  46. //GrantId: 0,
  47. PptId: int64(pptId),
  48. //DepartmentId: int64(departmentId),
  49. GrantAdminId: int64(grantAdminId),
  50. CreateTime: time.Now(),
  51. }
  52. list = append(list, tmpV)
  53. }
  54. }
  55. if len(list) <= 0 {
  56. errMsg = `请选择用户`
  57. return
  58. }
  59. err = models.MultiAddPptV2Grant(pptId, list)
  60. if err != nil {
  61. errMsg = "设置失败"
  62. }
  63. return
  64. }
  65. // DeleteGrantPpt 移除授权ppt
  66. func DeleteGrantPpt(pptId int) (err error, errMsg string) {
  67. err = models.DeletePptV2Grant(pptId)
  68. if err != nil {
  69. errMsg = "取消失败"
  70. }
  71. return
  72. }