ppt_v2_group_mapping.go 5.9 KB

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