ppt_v2_group_mapping.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. )
  6. // ppt目录和ppt 映射表
  7. type PptV2GroupMapping struct {
  8. GroupPptId int64 `orm:"column(group_ppt_id);pk;auto" description:"自增序号"`
  9. GroupId int64 `description:"ppt目录ID"`
  10. PptSort int64 `description:"Ppt的排序"`
  11. PptId int64 `description:"ppt ID"`
  12. CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  13. ModifyTime time.Time `orm:"auto_now;type(datetime)" description:"修改时间"`
  14. AdminId int `description:"移动ppt到该目录的系统用户id"`
  15. AdminRealName string `description:"系统用户名称"`
  16. ChildGroupPptId int64 `description:"设置共享后的新映射ID"`
  17. IsMoved bool `description:"true表示改PPT被人为移动过"`
  18. }
  19. // AddPptGroupMapping 新增目录和ppt的映射关系
  20. func AddPptGroupMapping(item *PptV2GroupMapping) (lastId int64, err error) {
  21. o := orm.NewOrmUsingDB("rddp")
  22. lastId, err = o.Insert(item)
  23. return
  24. }
  25. // GetPptMappingCountByGroupId 查询目录下,ppt的个数
  26. func GetPptMappingCountByGroupId(groupId int64) (total int64, err error) {
  27. o := orm.NewOrmUsingDB("rddp")
  28. sql := `select count(*) from ppt_v2_group_mapping where group_id=?`
  29. err = o.Raw(sql, groupId).QueryRow(&total)
  30. return
  31. }
  32. // GetPptMappingListByGroupId 查询目录下,ppt列表
  33. func GetPptMappingListByGroupId(groupId int64) (list []*PptV2GroupMapping, err error) {
  34. o := orm.NewOrmUsingDB("rddp")
  35. sql := `select group_ppt_id, group_id, ppt_id, ppt_sort, admin_id, admin_real_name, create_time from ppt_v2_group_mapping where group_id=? order by ppt_sort asc, group_ppt_id asc `
  36. _, err = o.Raw(sql, groupId).QueryRows(&list)
  37. return
  38. }
  39. // GetPptMappingListByGroupIds 根据分组ID查找
  40. func GetPptMappingListByGroupIds(groupIds []int64) (list []*PptV2GroupMapping, err error) {
  41. _, err = orm.NewOrmUsingDB("rddp").
  42. QueryTable("ppt_v2_group_mapping").
  43. Filter("group_id__in", groupIds).
  44. OrderBy("-ppt_sort", "group_ppt_id").
  45. All(&list)
  46. return
  47. }
  48. // GetPptMappingByGroupPptId 查询根据映射ID,查询单个映射关系
  49. func GetPptMappingByGroupPptId(groupPptId int64, adminId int) (item *PptV2GroupMapping, err error) {
  50. o := orm.NewOrmUsingDB("rddp")
  51. sql := `select * from ppt_v2_group_mapping where group_ppt_id=? and admin_id=?`
  52. err = o.Raw(sql, groupPptId, adminId).QueryRow(&item)
  53. return
  54. }
  55. // GetPptMappingByGroupPptId 查询根据映射ID,查询单个映射关系数量
  56. func GetPptMappingByGroupPptCountId(groupPptId int64, adminId int) (count int, err error) {
  57. o := orm.NewOrmUsingDB("rddp")
  58. sql := `select COUNT(*) AS count from ppt_v2_group_mapping where group_ppt_id=? and admin_id=?`
  59. err = o.Raw(sql, groupPptId, adminId).QueryRow(&count)
  60. return
  61. }
  62. // GetPptMappingByPptId 查询根据ppt_Id, 查询当映单个映射关系
  63. func GetPptMappingByPptId(pptId int64) (item *PptV2GroupMapping, err error) {
  64. o := orm.NewOrmUsingDB("rddp")
  65. sql := ` select * from ppt_v2_group_mapping where ppt_id=? `
  66. err = o.Raw(sql, pptId).QueryRow(&item)
  67. return
  68. }
  69. // Update 更新ppt目录映射的基本信息
  70. func (item *PptV2GroupMapping) Update(cols []string) (err error) {
  71. o := orm.NewOrmUsingDB("rddp")
  72. _, err = o.Update(item, cols...)
  73. return
  74. }
  75. // AddPptGroupMappingMulti 批量新增ppt和目录的映射关系
  76. func AddPptGroupMappingMulti(list []*PptV2GroupMapping) (err error) {
  77. o := orm.NewOrmUsingDB("rddp")
  78. _, err = o.InsertMulti(1, list)
  79. return
  80. }
  81. // UpdatePptGroupMappingSortMulti 批量更新初始排序标识
  82. func UpdatePptGroupMappingSortMulti(groupPptIds []int64) (err error) {
  83. o := orm.NewOrmUsingDB("rddp")
  84. p, err := o.Raw("UPDATE ppt_v2_group_mapping SET ppt_sort = group_ppt_id WHERE group_ppt_id = ?").Prepare()
  85. if err != nil {
  86. return
  87. }
  88. defer func() {
  89. _ = p.Close() // 别忘记关闭 statement
  90. }()
  91. for _, v := range groupPptIds {
  92. _, err = p.Exec(v)
  93. if err != nil {
  94. return
  95. }
  96. }
  97. return
  98. }
  99. // DeletePptGroupMapping 删除ppt目录
  100. func DeletePptGroupMapping(groupId int64, adminId int) (err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. sql := `DELETE FROM ppt_v2_group_mapping WHERE group_ppt_id=? and admin_id=? `
  103. _, err = o.Raw(sql, groupId, adminId).Exec()
  104. return
  105. }
  106. // DeletePptGroupMappingByPptId 删除ppt目录
  107. func DeletePptGroupMappingByPptId(pptId int) (err error) {
  108. o := orm.NewOrmUsingDB("rddp")
  109. sql := `DELETE FROM ppt_v2_group_mapping WHERE ppt_id=?`
  110. _, err = o.Raw(sql, pptId).Exec()
  111. return
  112. }
  113. // MoveUpGroupPptBySort 往上移动ppt
  114. func MoveUpGroupPptBySort(groupId, nextSort, currentSort int64) (err error) {
  115. o := orm.NewOrmUsingDB("rddp")
  116. sql := `update ppt_v2_group_mapping set ppt_sort = ppt_sort + 1 where group_id=? and ppt_sort >= ? and ppt_sort< ?`
  117. _, err = o.Raw(sql, groupId, nextSort, currentSort).Exec()
  118. return
  119. }
  120. // MoveDownGroupPptBySort 往下移动ppt
  121. func MoveDownGroupPptBySort(groupId, prevSort, currentSort int64) (err error) {
  122. o := orm.NewOrmUsingDB("rddp")
  123. sql := `update ppt_v2_group_mapping set ppt_sort = ppt_sort - 1 where group_id=? and ppt_sort <= ? and ppt_sort> ? `
  124. _, err = o.Raw(sql, groupId, prevSort, currentSort).Exec()
  125. return
  126. }
  127. // GetGroupPptByPptId 根据pptID 查找各个目录下的ppt
  128. func GetGroupPptByPptId(pptId int) (list []*PptV2GroupMapping, err error) {
  129. o := orm.NewOrmUsingDB("rddp")
  130. sql := `select * from ppt_v2_group_mapping where ppt_id=?`
  131. _, err = o.Raw(sql, pptId).QueryRows(&list)
  132. return
  133. }
  134. // GetPublicGroupPptByPptIds 根据pptid查询公共目录下的ppt
  135. func GetPublicGroupPptByPptIds(pptIds []string) (list []*PptV2GroupMapping, err error) {
  136. qb, _ := orm.NewQueryBuilder("mysql")
  137. // 构建查询对象
  138. qb.Select("p.*").
  139. From("ppt_v2_group as g").
  140. InnerJoin("ppt_v2_group_mapping as p").On("g.group_id = p.group_id").
  141. Where("g.is_share = 1 and p.ppt_id").In(pptIds...).
  142. OrderBy("g.share_time asc, p.ppt_sort asc")
  143. // 导出 SQL 语句
  144. sql := qb.String()
  145. // 执行 SQL 语句
  146. o := orm.NewOrmUsingDB("rddp")
  147. _, err = o.Raw(sql).QueryRows(&list)
  148. return
  149. }