ppt_grant.go 1.5 KB

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