ppt_english_grant.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package ppt_english
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // PptEnglishGrant Ppt授权表
  7. type PptEnglishGrant 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 []*PptEnglishGrant, err error) {
  16. o := orm.NewOrmUsingDB("rddp")
  17. sql := `SELECT * FROM ppt_english_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. // MultiAddPptEnglishGrant 批量添加授权记录
  34. func MultiAddPptEnglishGrant(pptId int, list []*PptEnglishGrant) (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_english_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. // DeletePptEnglishGrant 移除授权记录
  63. func DeletePptEnglishGrant(pptId int) (err error) {
  64. o := orm.NewOrmUsingDB("rddp")
  65. sql := "DELETE from ppt_english_grant where ppt_id=?"
  66. _, err = o.Raw(sql, pptId).Exec()
  67. return
  68. }
  69. // PptEnglishInfoGrantItem Ppt信息记录(包含授权信息)
  70. type PptEnglishInfoGrantItem 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. PptPage int `description:"PPT总页数"`
  90. //GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"`
  91. //PptId int64 `description:"ppt ID"`
  92. //DepartmentId int64 `description:"授权部门id"`
  93. //GrantAdminId int64 `description:"授权部门id"`
  94. //CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  95. }
  96. // GetAllGrantList 获取已经有权限的ppt列表
  97. func GetAllGrantList(sysUserId int) (list []*PptEnglishInfoGrantItem, err error) {
  98. o := orm.NewOrmUsingDB("rddp")
  99. sql := `SELECT a.* FROM ppt_english a JOIN ppt_english_grant b on a.ppt_id=b.ppt_id
  100. WHERE a.admin_id=? OR b.department_id=1 OR b.grant_admin_id=? GROUP BY a.ppt_id`
  101. _, err = o.Raw(sql, sysUserId, sysUserId).QueryRows(&list)
  102. return
  103. }
  104. // GetGrantList 获取我共享出去/别人共享给我的的ppt列表
  105. func GetGrantList(condition string, pars []interface{}) (list []*PptEnglishInfoGrantItem, err error) {
  106. o := orm.NewOrmUsingDB("rddp")
  107. sql := `SELECT a.* FROM ppt_english a JOIN ppt_english_grant b on a.ppt_id=b.ppt_id
  108. WHERE 1=1 `
  109. sql += condition
  110. sql += ` GROUP BY a.ppt_id ORDER BY a.modify_time DESC `
  111. _, err = o.Raw(sql, pars).QueryRows(&list)
  112. return
  113. }
  114. // GetPPtGrantConf 根据ppt_id和操作人获取ppt权限配置
  115. func GetPPtGrantConf(pptId, sysUserId int) (item *PptEnglishInfoGrantItem, err error) {
  116. o := orm.NewOrmUsingDB("rddp")
  117. sql := `SELECT a.* FROM ppt_english a JOIN ppt_english_grant b on a.ppt_id=b.ppt_id
  118. WHERE a.ppt_id=? AND (b.department_id=1 OR b.grant_admin_id=?) GROUP BY a.ppt_id`
  119. err = o.Raw(sql, pptId, sysUserId).QueryRow(&item)
  120. return
  121. }