ppt_v2_grant.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. //o := orm.NewOrmUsingDB("rddp")
  18. sql := `SELECT * FROM ppt_v2_grant WHERE ppt_id=? `
  19. //_, err = o.Raw(sql, pptId).QueryRows(&list)
  20. err = global.DmSQL["rddp"].Raw(sql, pptId).Find(&list).Error
  21. return
  22. }
  23. // GrantInfoResp ppt权限配置返回数据
  24. type GrantInfoResp struct {
  25. PptId int `description:"PptId" `
  26. GrantType int `description:"分配类型;1:全部ficc研究员;2:指定成员"`
  27. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  28. }
  29. // GrantPptReq 分配ppt权限
  30. type GrantPptReq struct {
  31. PptId int `description:"PptId" `
  32. GrantType int `description:"分配类型;1:全部ficc研究员;2:指定成员"`
  33. AdminIdStr string `description:"指定成员id,多个成员用英文,隔开"`
  34. }
  35. // MultiAddPptV2Grant 批量添加授权记录
  36. func MultiAddPptV2Grant(pptId int, list []*PptV2Grant) (err error) {
  37. //o := orm.NewOrmUsingDB("rddp")
  38. //to, err := o.Begin()
  39. to := global.DmSQL["rddp"].Begin()
  40. if err != nil {
  41. return
  42. }
  43. defer func() {
  44. if err != nil {
  45. _ = to.Rollback()
  46. } else {
  47. _ = to.Commit()
  48. }
  49. }()
  50. sql := "DELETE from ppt_v2_grant where ppt_id=?"
  51. //_, err = to.Raw(sql, pptId).Exec()
  52. err = to.Exec(sql, pptId).Error
  53. if err != nil {
  54. return
  55. }
  56. // 新增授权记录
  57. if len(list) > 0 {
  58. //_, tmpErr := to.InsertMulti(len(list), list)
  59. tmpErr := to.CreateInBatches(list, utils.MultiAddNum).Error
  60. if tmpErr != nil {
  61. err = tmpErr
  62. return
  63. }
  64. }
  65. return
  66. }
  67. // DeletePptV2Grant 移除授权记录
  68. func DeletePptV2Grant(pptId int) (err error) {
  69. //o := orm.NewOrmUsingDB("rddp")
  70. sql := "DELETE from ppt_v2_grant where ppt_id=?"
  71. //_, err = o.Raw(sql, pptId).Exec()
  72. err = global.DmSQL["rddp"].Exec(sql, pptId).Error
  73. return
  74. }
  75. // PptV2InfoGrantItem Ppt信息记录(包含授权信息)
  76. //
  77. // type PptV2InfoGrantItem struct {
  78. // PptId int `orm:"column(ppt_id);pk;auto" description:"ppt的Id"`
  79. // TemplateType int `description:"模版类型"`
  80. // BackgroundImg string `description:"背景图片"`
  81. // Title string `description:"标题"`
  82. // ReportType string `description:"报告类型"`
  83. // PptDate string `description:"选择日期"`
  84. // Content string `description:"ppt内容"`
  85. // PptUrl string `description:"ppt下载地址"`
  86. // PptxUrl string `description:"pptx下载地址"`
  87. // CreateTime time.Time `description:"创建时间"`
  88. // ModifyTime time.Time `description:"修改时间"`
  89. // AdminId int `description:"系统用户id"`
  90. // AdminRealName string `description:"系统用户名称"`
  91. // PptVersion int8 `description:"是否ppt的旧版本;1:旧的,2:新的"`
  92. // ReportId int `description:"关联的报告ID"`
  93. // ReportCode string `description:"关联的报告code"`
  94. // IsShare int8 `description:"是否分享,0:不分享,1:分享"`
  95. // PublishTime time.Time `description:"发布时间"`
  96. // PptPage int `description:"PPT页数"`
  97. //
  98. // //GrantId int64 `orm:"column(grant_id);pk;auto" description:"自增序号"`
  99. // //PptId int64 `description:"ppt ID"`
  100. // //DepartmentId int64 `description:"授权部门id"`
  101. // //GrantAdminId int64 `description:"授权部门id"`
  102. // //CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  103. // }
  104. type PptV2InfoGrantItem struct {
  105. PptId int `gorm:"column:ppt_id;primaryKey;autoIncrement" description:"ppt的Id"`
  106. TemplateType int `gorm:"column:template_type" description:"模版类型"`
  107. BackgroundImg string `gorm:"column:background_img" description:"背景图片"`
  108. Title string `gorm:"column:title" description:"标题"`
  109. ReportType string `gorm:"column:report_type" description:"报告类型"`
  110. PptDate string `gorm:"column:ppt_date" description:"选择日期"`
  111. Content string `gorm:"column:content" description:"ppt内容"`
  112. PptUrl string `gorm:"column:ppt_url" description:"ppt下载地址"`
  113. PptxUrl string `gorm:"column:pptx_url" description:"pptx下载地址"`
  114. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  115. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  116. AdminId int `gorm:"column:admin_id" description:"系统用户id"`
  117. AdminRealName string `gorm:"column:admin_real_name" description:"系统用户名称"`
  118. PptVersion int8 `gorm:"column:ppt_version" description:"是否ppt的旧版本;1:旧的,2:新的"`
  119. ReportId int `gorm:"column:report_id" description:"关联的报告ID"`
  120. ReportCode string `gorm:"column:report_code" description:"关联的报告code"`
  121. IsShare int8 `gorm:"column:is_share" description:"是否分享,0:不分享,1:分享"`
  122. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  123. PptPage int `gorm:"column:ppt_page" description:"PPT页数"`
  124. }
  125. // GetAllGrantList 获取已经有权限的ppt列表
  126. func GetAllGrantList(sysUserId int) (list []*PptV2InfoGrantItem, err error) {
  127. //o := orm.NewOrmUsingDB("rddp")
  128. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  129. WHERE a.admin_id=? OR b.department_id=1 OR b.grant_admin_id=? GROUP BY a.ppt_id`
  130. //_, err = o.Raw(sql, sysUserId, sysUserId).QueryRows(&list)
  131. err = global.DmSQL["rddp"].Raw(sql, sysUserId, sysUserId).Find(&list).Error
  132. return
  133. }
  134. // GetGrantList 获取我共享出去/别人共享给我的的ppt列表
  135. func GetGrantList(condition string, pars []interface{}) (list []*PptV2InfoGrantItem, err error) {
  136. //o := orm.NewOrmUsingDB("rddp")
  137. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  138. WHERE 1=1 `
  139. sql += condition
  140. sql += ` GROUP BY a.ppt_id ORDER BY a.modify_time DESC `
  141. //_, err = o.Raw(sql, pars).QueryRows(&list)
  142. err = global.DmSQL["rddp"].Raw(sql, pars).Find(&list).Error
  143. return
  144. }
  145. // GetPPtGrantConf 根据ppt_id和操作人获取ppt权限配置
  146. func GetPPtGrantConf(pptId, sysUserId int) (item *PptV2InfoGrantItem, err error) {
  147. //o := orm.NewOrmUsingDB("rddp")
  148. sql := `SELECT a.* FROM ppt_v2 a JOIN ppt_v2_grant b on a.ppt_id=b.ppt_id
  149. WHERE a.ppt_id=? AND (b.department_id=1 OR b.grant_admin_id=?) GROUP BY a.ppt_id`
  150. //err = o.Raw(sql, pptId, sysUserId).QueryRow(&item)
  151. err = global.DmSQL["rddp"].Raw(sql, pptId, sysUserId).First(&item).Error
  152. return
  153. }