ppt_v2_grant.go 5.8 KB

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