ppt_v2_grant.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // PptV2Grant Ppt授权表
  7. type PptV2Grant struct {
  8. GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"`
  9. PptId int64 `description:"ppt ID"`
  10. DepartmentId int64 `description:"授权部门id"`
  11. GrantAdminId int64 `description:"授权部门id"`
  12. CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  13. }
  14. // GetPPtGrantInfo 获取已经有权限的ppt列表
  15. func GetPPtGrantInfo(pptId int) (list []*PptV2Grant, err error) {
  16. o := orm.NewOrmUsingDB("rddp")
  17. sql := `SELECT * FROM ppt_v2_grant WHERE ppt_id=? `
  18. _, err = o.Raw(sql, pptId).QueryRows(&list)
  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. o := orm.NewOrmUsingDB("rddp")
  36. to, err := o.Begin()
  37. if err != nil {
  38. return
  39. }
  40. defer func() {
  41. if err != nil {
  42. _ = to.Rollback()
  43. } else {
  44. _ = to.Commit()
  45. }
  46. }()
  47. sql := "DELETE from ppt_v2_grant where ppt_id=?"
  48. _, err = to.Raw(sql, pptId).Exec()
  49. if err != nil {
  50. return
  51. }
  52. // 新增授权记录
  53. if len(list) > 0 {
  54. _, tmpErr := to.InsertMulti(len(list), list)
  55. if tmpErr != nil {
  56. err = tmpErr
  57. return
  58. }
  59. }
  60. return
  61. }
  62. // DeletePptV2Grant 移除授权记录
  63. func DeletePptV2Grant(pptId int) (err error) {
  64. o := orm.NewOrmUsingDB("rddp")
  65. sql := "DELETE from ppt_v2_grant where ppt_id=?"
  66. _, err = o.Raw(sql, pptId).Exec()
  67. return
  68. }
  69. // PptV2InfoGrantItem Ppt信息记录(包含授权信息)
  70. type PptV2InfoGrantItem struct {
  71. PptId int `orm:"column(ppt_id);pk;auto" description:"ppt的Id"`
  72. TemplateType int `description:"模版类型"`
  73. BackgroundImg string `description:"背景图片"`
  74. Title string `description:"标题"`
  75. ReportType string `description:"报告类型"`
  76. PptDate string `description:"选择日期"`
  77. Content string `description:"ppt内容"`
  78. PptUrl string `description:"ppt下载地址"`
  79. PptxUrl string `description:"pptx下载地址"`
  80. CreateTime time.Time `description:"创建时间"`
  81. ModifyTime time.Time `description:"修改时间"`
  82. AdminId int `description:"系统用户id"`
  83. AdminRealName string `description:"系统用户名称"`
  84. PptVersion int8 `description:"是否ppt的旧版本;1:旧的,2:新的"`
  85. ReportId int `description:"关联的报告ID"`
  86. ReportCode string `description:"关联的报告code"`
  87. IsShare int8 `description:"是否分享,0:不分享,1:分享"`
  88. PublishTime time.Time `description:"发布时间"`
  89. //GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"`
  90. //PptId int64 `description:"ppt ID"`
  91. //DepartmentId int64 `description:"授权部门id"`
  92. //GrantAdminId int64 `description:"授权部门id"`
  93. //CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  94. }
  95. // GetAllGrantList 获取已经有权限的ppt列表
  96. func GetAllGrantList(sysUserId int) (list []*PptV2InfoGrantItem, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  99. WHERE a.admin_id=? OR b.department_id=1 OR b.grant_admin_id=? GROUP BY a.ppt_id`
  100. _, err = o.Raw(sql, sysUserId, sysUserId).QueryRows(&list)
  101. return
  102. }
  103. // GetGrantList 获取我共享出去/别人共享给我的的ppt列表
  104. func GetGrantList(condition string, pars []interface{}) (list []*PptV2InfoGrantItem, err error) {
  105. o := orm.NewOrmUsingDB("rddp")
  106. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  107. WHERE 1=1 `
  108. sql += condition
  109. sql += ` GROUP BY a.ppt_id ORDER BY a.modify_time DESC `
  110. _, err = o.Raw(sql, pars).QueryRows(&list)
  111. return
  112. }
  113. // GetPPtGrantConf 根据ppt_id和操作人获取ppt权限配置
  114. func GetPPtGrantConf(pptId, sysUserId int) (item *PptV2InfoGrantItem, err error) {
  115. o := orm.NewOrmUsingDB("rddp")
  116. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  117. WHERE a.ppt_id=? AND (b.department_id=1 OR b.grant_admin_id=?) GROUP BY a.ppt_id`
  118. err = o.Raw(sql, pptId, sysUserId).QueryRow(&item)
  119. return
  120. }