ppt_english_grant.go 8.4 KB

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