ppt_english_group_mapping.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package ppt_english
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_api/global"
  5. "eta/eta_api/utils"
  6. "time"
  7. )
  8. // ppt目录和ppt 映射表
  9. type PptEnglishGroupMapping struct {
  10. GroupPptId int64 `orm:"column(group_ppt_id);pk" gorm:"primaryKey" description:"自增序号"`
  11. GroupId int64 `description:"ppt目录ID"`
  12. PptSort float64 `description:"Ppt的排序"`
  13. PptId int64 `description:"ppt ID"`
  14. CreateTime time.Time `orm:"auto_now_add;type(datetime)" description:"创建时间"`
  15. ModifyTime time.Time `orm:"auto_now;type(datetime)" description:"修改时间"`
  16. AdminId int `description:"移动ppt到该目录的系统用户id"`
  17. AdminRealName string `description:"系统用户名称"`
  18. ChildGroupPptId int64 `description:"设置共享后的新映射ID"`
  19. IsMoved bool `description:"true表示改PPT被人为移动过"`
  20. }
  21. // AddPptGroupMapping 新增目录和ppt的映射关系
  22. func AddPptGroupMapping(item *PptEnglishGroupMapping) (lastId int64, err error) {
  23. o := global.DbMap[utils.DbNameReport]
  24. err = o.Create(item).Error
  25. if err != nil {
  26. return
  27. }
  28. lastId = item.GroupPptId
  29. return
  30. }
  31. // GetPptMappingCountByGroupId 查询目录下,ppt的个数
  32. func GetPptMappingCountByGroupId(groupId int64) (total int64, err error) {
  33. o := global.DbMap[utils.DbNameReport]
  34. sql := `select count(*) from ppt_english_group_mapping where group_id=?`
  35. err = o.Raw(sql, groupId).Scan(&total).Error
  36. return
  37. }
  38. // GetPptMappingListByGroupId 查询目录下,ppt列表
  39. func GetPptMappingListByGroupId(groupId int64) (list []*PptEnglishGroupMapping, err error) {
  40. o := global.DbMap[utils.DbNameReport]
  41. 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 `
  42. err = o.Raw(sql, groupId).Find(&list).Error
  43. return
  44. }
  45. // GetPptMappingListByGroupIds 根据分组ID查找
  46. func GetPptMappingListByGroupIds(groupIds []int64) (list []*PptEnglishGroupMapping, err error) {
  47. o := global.DbMap[utils.DbNameReport] /*.
  48. QueryTable("ppt_english_group_mapping").
  49. Filter("group_id__in", groupIds).
  50. OrderBy("-ppt_sort", "group_ppt_id").
  51. All(&list)*/
  52. sql := `select * from ppt_english_group_mapping where group_id in ` + utils.GetOrmInReplace(len(groupIds)) + ` order by ppt_sort desc, group_ppt_id asc`
  53. err = o.Raw(sql, groupIds).Find(&list).Error
  54. return
  55. }
  56. // GetPptMappingByPptId 查询目录下, pptId对应的目录映射关系
  57. func GetPptMappingByPptId(pptId int64) (item *PptEnglishGroupMapping, err error) {
  58. o := global.DbMap[utils.DbNameReport]
  59. sql := ` select * from ppt_english_group_mapping where ppt_id=? `
  60. err = o.Raw(sql, pptId).First(&item).Error
  61. return
  62. }
  63. // GetPptMappingListByGroupIdDesc 查询目录下,ppt列表, 降序排列
  64. func GetPptMappingListByGroupIdDesc(groupId int64) (list []*PptEnglishGroupMapping, err error) {
  65. o := global.DbMap[utils.DbNameReport]
  66. 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 desc, group_ppt_id desc `
  67. err = o.Raw(sql, groupId).Find(&list).Error
  68. return
  69. }
  70. // GetPptMappingByGroupPptId 查询根据映射ID,查询单个映射关系
  71. func GetPptMappingByGroupPptId(groupPptId int64, adminId int) (item *PptEnglishGroupMapping, err error) {
  72. o := global.DbMap[utils.DbNameReport]
  73. sql := `select * from ppt_english_group_mapping where group_ppt_id=? and admin_id=?`
  74. err = o.Raw(sql, groupPptId, adminId).First(&item).Error
  75. return
  76. }
  77. // GetPptMappingByGroupPptId 查询根据映射ID,查询单个映射关系数量
  78. func GetPptMappingCountByGroupPptId(groupPptId int64, adminId int) (count int, err error) {
  79. o := global.DbMap[utils.DbNameReport]
  80. sql := `select COUNT(*) AS count from ppt_english_group_mapping where group_ppt_id=? and admin_id=?`
  81. err = o.Raw(sql, groupPptId, adminId).Scan(&count).Error
  82. return
  83. }
  84. // Update 更新ppt目录映射的基本信息
  85. func (item *PptEnglishGroupMapping) Update(cols []string) (err error) {
  86. o := global.DbMap[utils.DbNameReport]
  87. err = o.Select(cols).Updates(item).Error
  88. return
  89. }
  90. // AddPptGroupMappingMulti 批量新增ppt和目录的映射关系
  91. func AddPptGroupMappingMulti(list []*PptEnglishGroupMapping) (err error) {
  92. o := global.DbMap[utils.DbNameReport]
  93. err = o.CreateInBatches(list, utils.MultiAddNum).Error
  94. return
  95. }
  96. // UpdatePptGroupMappingSortMulti 批量更新初始排序标识
  97. func UpdatePptGroupMappingSortMulti(groupPptIds []int64) (err error) {
  98. o := global.DbMap[utils.DbNameReport]
  99. sql := "UPDATE ppt_english_group_mapping SET ppt_sort = group_ppt_id WHERE group_ppt_id = ?"
  100. for _, v := range groupPptIds {
  101. err = o.Exec(sql, v).Error
  102. if err != nil {
  103. return
  104. }
  105. }
  106. return
  107. }
  108. // DeletePptGroupMapping 删除ppt目录
  109. func DeletePptGroupMapping(groupId int64, adminId int) (err error) {
  110. o := global.DbMap[utils.DbNameReport]
  111. sql := `DELETE FROM ppt_english_group_mapping WHERE group_ppt_id=? and admin_id=? `
  112. err = o.Exec(sql, groupId, adminId).Error
  113. return
  114. }
  115. // DeletePptGroupMappingByPptId 删除ppt目录
  116. func DeletePptGroupMappingByPptId(pptId int) (err error) {
  117. o := global.DbMap[utils.DbNameReport]
  118. sql := `DELETE FROM ppt_english_group_mapping WHERE ppt_id=?`
  119. err = o.Exec(sql, pptId).Error
  120. return
  121. }
  122. // MoveUpGroupPptBySort 往上移动ppt
  123. func MoveUpGroupPptBySort(groupId, nextSort, currentSort int64) (err error) {
  124. o := global.DbMap[utils.DbNameReport]
  125. sql := `update ppt_english_group_mapping set ppt_sort = ppt_sort + 1 where group_id=? and ppt_sort >= ? and ppt_sort< ?`
  126. err = o.Exec(sql, groupId, nextSort, currentSort).Error
  127. return
  128. }
  129. // MoveDownGroupPptBySort 往下移动ppt
  130. func MoveDownGroupPptBySort(groupId, prevSort, currentSort int64) (err error) {
  131. o := global.DbMap[utils.DbNameReport]
  132. sql := `update ppt_english_group_mapping set ppt_sort = ppt_sort - 1 where group_id=? and ppt_sort <= ? and ppt_sort> ? `
  133. err = o.Exec(sql, groupId, prevSort, currentSort).Error
  134. return
  135. }
  136. // GetGroupPptByPptId 根据pptID 查找各个目录下的ppt
  137. func GetGroupPptByPptId(pptId int) (list []*PptEnglishGroupMapping, err error) {
  138. o := global.DbMap[utils.DbNameReport]
  139. sql := `select * from ppt_english_group_mapping where ppt_id=?`
  140. err = o.Raw(sql, pptId).Find(&list).Error
  141. return
  142. }
  143. // GetPublicGroupPptByPptIds 根据pptid查询公共目录下的ppt
  144. func GetPublicGroupPptByPptIds(pptIds []string) (list []*PptEnglishGroupMapping, err error) {
  145. sql := `select p.* from ppt_english_group as g inner join ppt_english_group_mapping as p on g.group_id = p.group_id where g.is_share = 1 and p.ppt_id in ` + utils.GetOrmInReplace(len(pptIds)) + ` order by g.share_time asc, p.ppt_sort asc`
  146. // 执行 SQL 语句
  147. o := global.DbMap[utils.DbNameReport]
  148. err = o.Raw(sql).Find(&list).Error
  149. return
  150. }
  151. // GetMaxSortByGroupId
  152. // @Description: 根据分组id获取最大排序
  153. // @author: Roc
  154. // @datetime 2025-03-07 18:22:56
  155. // @param groupPptId int64
  156. // @return pptSort float64
  157. // @return err error
  158. func GetMaxSortByEnglishGroupId(groupPptId int64) (pptSort float64, err error) {
  159. o := global.DbMap[utils.DbNameReport]
  160. sql := `select MAX(ppt_sort) AS count from ppt_english_group_mapping where group_id=?`
  161. var sortNull sql2.NullFloat64
  162. err = o.Raw(sql, groupPptId).Scan(&sortNull).Error
  163. if err != nil {
  164. return
  165. }
  166. if sortNull.Valid {
  167. pptSort = sortNull.Float64
  168. }
  169. return
  170. }
  171. // GetMinSortByGroupId
  172. // @Description: 根据分组id获取最大排序
  173. // @author: Roc
  174. // @datetime 2025-03-07 18:22:56
  175. // @param groupPptId int64
  176. // @return pptSort float64
  177. // @return err error
  178. func GetMinSortByEnglishGroupId(groupPptId int64) (pptSort float64, err error) {
  179. o := global.DbMap[utils.DbNameReport]
  180. sql := `select MIN(ppt_sort) AS count from ppt_english_group_mapping where group_id=?`
  181. var sortNull sql2.NullFloat64
  182. err = o.Raw(sql, groupPptId).Scan(&sortNull).Error
  183. if err != nil {
  184. return
  185. }
  186. if sortNull.Valid {
  187. pptSort = sortNull.Float64
  188. }
  189. return
  190. }