ppt_v2_grant.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package models
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. // PptV2Grant Ppt授权表
  8. type PptV2Grant struct {
  9. GrantId int64 `gorm:"column:grant_id;primaryKey" description:"自增序号"`
  10. PptId int64 `description:"ppt ID"`
  11. DepartmentId int64 `description:"授权部门id"`
  12. GrantAdminId int64 `description:"授权部门id"`
  13. CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  14. }
  15. // GetPPtGrantInfo 获取已经有权限的ppt列表
  16. func GetPPtGrantInfo(pptId int) (list []*PptV2Grant, err error) {
  17. o := global.DbMap[utils.DbNameReport]
  18. sql := `SELECT * FROM ppt_v2_grant WHERE ppt_id=? `
  19. err = o.Raw(sql, pptId).Find(&list).Error
  20. return
  21. }
  22. // GrantInfoResp ppt权限配置返回数据
  23. type GrantInfoResp struct {
  24. PptId int `description:"PptId" `
  25. GrantType int `description:"分配类型;1:全部ficc研究员;2:指定成员"`
  26. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  27. }
  28. // GrantPptReq 分配ppt权限
  29. type GrantPptReq struct {
  30. PptId int `description:"PptId" `
  31. GrantType int `description:"分配类型;1:全部ficc研究员;2:指定成员"`
  32. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  33. }
  34. // MultiAddPptV2Grant 批量添加授权记录
  35. func MultiAddPptV2Grant(pptId int, list []*PptV2Grant) (err error) {
  36. to := global.DbMap[utils.DbNameReport].Begin()
  37. defer func() {
  38. if err != nil {
  39. _ = to.Rollback()
  40. } else {
  41. _ = to.Commit()
  42. }
  43. }()
  44. sql := "DELETE from ppt_v2_grant where ppt_id=?"
  45. err = to.Exec(sql, pptId).Error
  46. if err != nil {
  47. return
  48. }
  49. // 新增授权记录
  50. if len(list) > 0 {
  51. tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
  52. if tmpErr != nil {
  53. err = tmpErr
  54. return
  55. }
  56. }
  57. return
  58. }
  59. // DeletePptV2Grant 移除授权记录
  60. func DeletePptV2Grant(pptId int) (err error) {
  61. o := global.DbMap[utils.DbNameReport]
  62. sql := "DELETE from ppt_v2_grant where ppt_id=?"
  63. err = o.Exec(sql, pptId).Error
  64. return
  65. }
  66. // PptV2InfoGrantItem Ppt信息记录(包含授权信息)
  67. type PptV2InfoGrantItem struct {
  68. PptId int `gorm:"column:ppt_id;primaryKey" description:"ppt的Id"`
  69. TemplateType int `description:"模版类型"`
  70. BackgroundImg string `description:"背景图片"`
  71. Title string `description:"标题"`
  72. ReportType string `description:"报告类型"`
  73. PptDate string `description:"选择日期"`
  74. Content string `description:"ppt内容"`
  75. PptUrl string `description:"ppt下载地址"`
  76. PptxUrl string `description:"pptx下载地址"`
  77. CreateTime time.Time `description:"创建时间"`
  78. ModifyTime time.Time `description:"修改时间"`
  79. AdminId int `description:"系统用户id"`
  80. AdminRealName string `description:"系统用户名称"`
  81. PptVersion int8 `description:"是否ppt的旧版本;1:旧的,2:新的"`
  82. ReportId int `description:"关联的报告ID"`
  83. ReportCode string `description:"关联的报告code"`
  84. IsShare int8 `description:"是否分享,0:不分享,1:分享"`
  85. PublishTime time.Time `description:"发布时间"`
  86. PptPage int `description:"PPT页数"`
  87. //GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"`
  88. //PptId int64 `description:"ppt ID"`
  89. //DepartmentId int64 `description:"授权部门id"`
  90. //GrantAdminId int64 `description:"授权部门id"`
  91. //CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  92. }
  93. // GetAllGrantList 获取已经有权限的ppt列表
  94. func GetAllGrantList(sysUserId int) (list []*PptV2InfoGrantItem, err error) {
  95. o := global.DbMap[utils.DbNameReport]
  96. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  97. WHERE a.admin_id=? OR b.department_id=1 OR b.grant_admin_id=? GROUP BY a.ppt_id`
  98. err = o.Raw(sql, sysUserId, sysUserId).Find(&list).Error
  99. return
  100. }
  101. // GetGrantList 获取我共享出去/别人共享给我的的ppt列表
  102. func GetGrantList(condition string, pars []interface{}) (list []*PptV2InfoGrantItem, err error) {
  103. o := global.DbMap[utils.DbNameReport]
  104. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  105. WHERE 1=1 `
  106. sql += condition
  107. sql += ` GROUP BY a.ppt_id ORDER BY a.modify_time DESC `
  108. err = o.Raw(sql, pars...).Find(&list).Error
  109. return
  110. }
  111. // GetPPtGrantConf 根据ppt_id和操作人获取ppt权限配置
  112. func GetPPtGrantConf(pptId, sysUserId int) (item *PptV2InfoGrantItem, err error) {
  113. o := global.DbMap[utils.DbNameReport]
  114. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  115. WHERE a.ppt_id=? AND (b.department_id=1 OR b.grant_admin_id=?) GROUP BY a.ppt_id`
  116. err = o.Raw(sql, pptId, sysUserId).First(&item).Error
  117. return
  118. }