ppt_v2_grant.go 5.4 KB

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