ppt_english_group_mapping.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package ppt_english
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ppt目录和ppt 映射表
  7. type PptEnglishGroupMapping 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. }
  18. // AddPptGroupMapping 新增目录和ppt的映射关系
  19. func AddPptGroupMapping(item *PptEnglishGroupMapping) (lastId int64, err error) {
  20. o := orm.NewOrmUsingDB("rddp")
  21. lastId, err = o.Insert(item)
  22. return
  23. }
  24. // GetPptMappingCountByGroupId 查询目录下,ppt的个数
  25. func GetPptMappingCountByGroupId(groupId int64) (total int64, err error) {
  26. o := orm.NewOrmUsingDB("rddp")
  27. sql := `select count(*) from ppt_english_group_mapping where group_id=?`
  28. err = o.Raw(sql, groupId).QueryRow(&total)
  29. return
  30. }
  31. // GetPptMappingListByGroupId 查询目录下,ppt列表
  32. func GetPptMappingListByGroupId(groupId int64) (list []*PptEnglishGroupMapping, err error) {
  33. o := orm.NewOrmUsingDB("rddp")
  34. sql := `select group_ppt_id, group_id, ppt_id, ppt_sort, admin_id, admin_real_name, create_time from ppt_english_group_mapping where group_id=? order by ppt_sort asc, group_ppt_id asc `
  35. _, err = o.Raw(sql, groupId).QueryRows(&list)
  36. return
  37. }
  38. // GetPptMappingListByGroupIds 根据分组ID查找
  39. func GetPptMappingListByGroupIds(groupIds []int64) (list []*PptEnglishGroupMapping, err error) {
  40. _, err = orm.NewOrmUsingDB("rddp").
  41. QueryTable("ppt_english_group_mapping").
  42. Filter("group_id__in", groupIds).
  43. OrderBy("-ppt_sort", "group_ppt_id").
  44. All(&list)
  45. return
  46. }
  47. // GetPptMappingByGroupPptId 查询根据映射ID,查询单个映射关系
  48. func GetPptMappingByGroupPptId(groupPptId int64, adminId int) (item *PptEnglishGroupMapping, err error) {
  49. o := orm.NewOrmUsingDB("rddp")
  50. sql := `select * from ppt_english_group_mapping where group_ppt_id=? and admin_id=?`
  51. err = o.Raw(sql, groupPptId, adminId).QueryRow(&item)
  52. return
  53. }
  54. // Update 更新ppt目录映射的基本信息
  55. func (item *PptEnglishGroupMapping) Update(cols []string) (err error) {
  56. o := orm.NewOrmUsingDB("rddp")
  57. _, err = o.Update(item, cols...)
  58. return
  59. }
  60. // AddPptGroupMappingMulti 批量新增ppt和目录的映射关系
  61. func AddPptGroupMappingMulti(list []*PptEnglishGroupMapping) (err error) {
  62. o := orm.NewOrmUsingDB("rddp")
  63. _, err = o.InsertMulti(1, list)
  64. return
  65. }
  66. // UpdatePptGroupMappingSortMulti 批量更新初始排序标识
  67. func UpdatePptGroupMappingSortMulti(groupPptIds []int64) (err error) {
  68. o := orm.NewOrmUsingDB("rddp")
  69. p, err := o.Raw("UPDATE ppt_english_group_mapping SET ppt_sort = group_ppt_id WHERE group_ppt_id = ?").Prepare()
  70. if err != nil {
  71. return
  72. }
  73. defer func() {
  74. _ = p.Close() // 别忘记关闭 statement
  75. }()
  76. for _, v := range groupPptIds {
  77. _, err = p.Exec(v)
  78. if err != nil {
  79. return
  80. }
  81. }
  82. return
  83. }
  84. // DeletePptGroupMapping 删除ppt目录
  85. func DeletePptGroupMapping(groupId int64, adminId int) (err error) {
  86. o := orm.NewOrmUsingDB("rddp")
  87. sql := `DELETE FROM ppt_english_group_mapping WHERE group_ppt_id=? and admin_id=? `
  88. _, err = o.Raw(sql, groupId, adminId).Exec()
  89. return
  90. }
  91. // DeletePptGroupMappingByPptId 删除ppt目录
  92. func DeletePptGroupMappingByPptId(pptId int) (err error) {
  93. o := orm.NewOrmUsingDB("rddp")
  94. sql := `DELETE FROM ppt_english_group_mapping WHERE ppt_id=?`
  95. _, err = o.Raw(sql, pptId).Exec()
  96. return
  97. }
  98. // MoveUpGroupPptBySort 往上移动ppt
  99. func MoveUpGroupPptBySort(groupId, nextSort, currentSort int64) (err error) {
  100. o := orm.NewOrmUsingDB("rddp")
  101. sql := `update ppt_english_group_mapping set ppt_sort = ppt_sort + 1 where group_id=? and ppt_sort >= ? and ppt_sort< ?`
  102. _, err = o.Raw(sql, groupId, nextSort, currentSort).Exec()
  103. return
  104. }
  105. // MoveDownGroupPptBySort 往下移动ppt
  106. func MoveDownGroupPptBySort(groupId, prevSort, currentSort int64) (err error) {
  107. o := orm.NewOrmUsingDB("rddp")
  108. sql := `update ppt_english_group_mapping set ppt_sort = ppt_sort - 1 where group_id=? and ppt_sort <= ? and ppt_sort> ? `
  109. _, err = o.Raw(sql, groupId, prevSort, currentSort).Exec()
  110. return
  111. }
  112. // GetGroupPptByPptId 根据pptID 查找各个目录下的ppt
  113. func GetGroupPptByPptId(pptId int) (list []*PptEnglishGroupMapping, err error) {
  114. o := orm.NewOrmUsingDB("rddp")
  115. sql := `select * from ppt_english_group_mapping where ppt_id=?`
  116. _, err = o.Raw(sql, pptId).QueryRows(&list)
  117. return
  118. }
  119. // GetPublicGroupPptByPptIds 根据pptid查询公共目录下的ppt
  120. func GetPublicGroupPptByPptIds(pptIds []string) (list []*PptEnglishGroupMapping, err error) {
  121. qb, _ := orm.NewQueryBuilder("mysql")
  122. // 构建查询对象
  123. qb.Select("p.*").
  124. From("ppt_english_group as g").
  125. InnerJoin("ppt_english_group_mapping as p").On("g.group_id = p.group_id").
  126. Where("g.is_share = 1 and p.ppt_id").In(pptIds...).
  127. OrderBy("g.share_time asc, p.ppt_sort asc")
  128. // 导出 SQL 语句
  129. sql := qb.String()
  130. // 执行 SQL 语句
  131. o := orm.NewOrmUsingDB("rddp")
  132. _, err = o.Raw(sql).QueryRows(&list)
  133. return
  134. }