ppt_v2_group.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "time"
  6. )
  7. type PptV2Group struct {
  8. GroupId int64 `gorm:"column:group_id;primaryKey;autoIncrement" description:"ppt目录ID"`
  9. GroupName string `gorm:"column:group_name" description:"目录名称"`
  10. AdminId int `gorm:"column:admin_id" description:"目录创建者账号ID"`
  11. IsShare int8 `gorm:"column:is_share" description:"是否共享,0私有,1共享"`
  12. GroupSort int64 `gorm:"column:group_sort" description:"目录排序标识"`
  13. IsShareAdd int8 `gorm:"column:is_share_add" description:"是否是通过单个ppt共享生成的目录,0不是,1-是"`
  14. CreateTime time.Time `gorm:"column:create_time;autoCreateTime" description:"创建时间"`
  15. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  16. ShareTime time.Time `gorm:"column:share_time" description:"分享时间"`
  17. }
  18. func GetPrivatePptGroups(adminId int) (list []*PptV2Group, err error) {
  19. sql := "select * from ppt_v2_group where admin_id=? order by group_sort asc, group_id asc"
  20. err = global.DmSQL["rddp"].Raw(sql, adminId).Find(&list).Error
  21. return
  22. }
  23. func GetPrivatePptGroupsByAdminId(adminId int) (list []*PptV2Group, err error) {
  24. sql := "select * from ppt_v2_group where admin_id=? AND is_share_add=0 order by group_sort asc, group_id asc"
  25. err = global.DmSQL["rddp"].Raw(sql, adminId).Find(&list).Error
  26. return
  27. }
  28. func GetPublicPptGroups() (list []*PptV2Group, err error) {
  29. sql := "select * from ppt_v2_group where is_share=1 order by share_time asc, group_id asc"
  30. err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error
  31. return
  32. }
  33. func GetPptGroupByName(groupName string, adminId int) (item *PptV2Group, err error) {
  34. sql := "select * from ppt_v2_group where admin_id=? and group_name=?"
  35. err = global.DmSQL["rddp"].Raw(sql, adminId, groupName).Find(&item).Error
  36. return
  37. }
  38. func GetPptGroupByGroupIdAdminId(groupId int64, adminId int) (item *PptV2Group, err error) {
  39. sql := "select * from ppt_v2_group where admin_id=? and group_id=?"
  40. err = global.DmSQL["rddp"].Raw(sql, adminId, groupId).First(&item).Error
  41. return
  42. }
  43. func GetPptGroupByGroupId(groupId int64) (item *PptV2Group, err error) {
  44. sql := "select * from ppt_v2_group where group_id=?"
  45. err = global.DmSQL["rddp"].Raw(sql, groupId).First(&item).Error
  46. return
  47. }
  48. func AddPptGroup(item *PptV2Group) (lastId int64, err error) {
  49. err = global.DmSQL["rddp"].Create(item).Error
  50. lastId = item.GroupId
  51. return
  52. }
  53. func DeletePptGroup(groupId int64) (err error) {
  54. sql := `DELETE FROM ppt_v2_group WHERE group_id=? `
  55. err = global.DmSQL["rddp"].Exec(sql, groupId).Error
  56. return
  57. }
  58. func DeletePptGroupByGroupIds(groupIds string) (err error) {
  59. sql := `DELETE FROM ppt_v2_group WHERE group_id in ` + groupIds
  60. err = global.DmSQL["rddp"].Exec(sql).Error
  61. return
  62. }
  63. func (item *PptV2Group) Update(cols []string) (err error) {
  64. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  65. return
  66. }
  67. func MoveUpGroupBySort(nextSort, currentSort int64) (err error) {
  68. sql := `update ppt_v2_group set group_sort = group_sort + 1 where group_sort >= ? and group_sort< ?`
  69. err = global.DmSQL["rddp"].Exec(sql, nextSort, currentSort).Error
  70. return
  71. }
  72. func MoveDownGroupBySort(prevSort, currentSort int64) (err error) {
  73. sql := `update ppt_v2_group set group_sort = group_sort - 1 where group_sort <= ? and group_sort> ? `
  74. err = global.DmSQL["rddp"].Exec(sql, prevSort, currentSort).Error
  75. return
  76. }
  77. func GetPptGroupNamesByAdminId(adminId int) (names []string, err error) {
  78. sql := "select group_name from ppt_v2_group where admin_id = ?"
  79. err = global.DmSQL["rddp"].Raw(sql, adminId).Scan(&names).Error
  80. return
  81. }
  82. func GetPptGroupIdAndGroupNameByAdminId(adminId int) (list []*RespPptGroupName, err error) {
  83. sql := "select group_id, group_name from ppt_v2_group where admin_id = ? and is_share_add != 1 order by group_sort asc, group_id asc"
  84. err = global.DmSQL["rddp"].Raw(sql, adminId).Find(&list).Error
  85. return
  86. }
  87. func AddPptGroupMulti(list []*PptV2Group) (err error) {
  88. err = global.DmSQL["rddp"].CreateInBatches(list, utils.MultiAddNum).Error
  89. return
  90. }
  91. func UpdatePptGroupSortMulti(groupIds []int64) (err error) {
  92. tx := global.DmSQL["rddp"].Begin()
  93. for _, v := range groupIds {
  94. err = tx.Exec("UPDATE ppt_v2_group SET group_sort = group_id WHERE group_id = ?", v).Error
  95. if err != nil {
  96. tx.Rollback()
  97. return
  98. }
  99. }
  100. tx.Commit()
  101. return
  102. }
  103. type ReqAddPptGroup struct {
  104. GroupName string `description:"目录名称"`
  105. }
  106. type RespAddPptGroup struct {
  107. GroupId int64 `description:"目录id"`
  108. }
  109. type ReqPptGroup struct {
  110. GroupId int64 `description:"目录id"`
  111. }
  112. type ReqRenamePptGroup struct {
  113. GroupId int64 `description:"目录id"`
  114. GroupName string `description:"目录名称"`
  115. }
  116. type RespPptGroupShare struct {
  117. GroupId int64 `description:"目录id"`
  118. IsShare int8 `description:"是否共享,0私有,1共享"`
  119. }
  120. type RespGroupList struct {
  121. PublicList []*RespGroupListItem
  122. PrivateList []*RespGroupListItem
  123. GrantList []RespGroupListItem
  124. }
  125. type RespGroupListItem struct {
  126. GroupId int64 `description:"目录id"`
  127. GroupName string `description:"目录名称"`
  128. AdminId int `description:"目录创建者账号ID"`
  129. IsShare int8 `description:"是否共享,0私有,1共享"`
  130. OnlyOld bool `description:"是否只包含ppt旧版本的目录,只包含旧版的ppt:true,否则 false"`
  131. PptList []*RespGroupPptNameListItem
  132. }
  133. type RespGroupPptNameListItem struct {
  134. GroupPptId int64 `description:"目录和ppt绑定序号"`
  135. PptId int64 `description:"ppt ID"`
  136. Title string `description:"标题"`
  137. AdminId int `description:"移动ppt到该目录的系统用户id"`
  138. AdminRealName string `description:"系统用户名称"`
  139. PptVersion int8 `description:"是否ppt的旧版本;1:旧的,2:新的"`
  140. IsSingleShare int8 `description:"是否是单个共享ppt,0未单个共享,1共享"`
  141. PptxUrl string `description:"pptx下载地址"`
  142. ReportId int `description:"关联的报告ID"`
  143. ReportCode string `description:"关联的报告code"`
  144. PptCreateTime string `description:"ppt创建时间"`
  145. PptModifyTime string `description:"ppt修改时间"`
  146. PublishTime string `description:"发布时间"`
  147. PptPage int `description:"PPT总页数"`
  148. IsReceived int8 `description:"是否收到的共享,0:不是,1:是"`
  149. IsGrant int8 `description:"是否分配了权限,0:不是,1:是"`
  150. TitleSetting string `description:"PPT标题设置"`
  151. }
  152. type RespGroupPptListItem struct {
  153. GroupPptId int64 `description:"目录和ppt绑定序号"`
  154. PptId int64 `description:"ppt ID"`
  155. TemplateType int `description:"模版类型"`
  156. BackgroundImg string `description:"背景图片"`
  157. Title string `description:"标题"`
  158. PptCreateTime string `description:"ppt创建时间"`
  159. PptModifyTime string `description:"ppt修改时间"`
  160. AdminId int `description:"移动ppt到该目录的系统用户id"`
  161. AdminRealName string `description:"系统用户名称"`
  162. PptVersion int8 `description:"是否ppt的旧版本;1:旧的,2:新的"`
  163. IsSingleShare int8 `description:"是否是单个共享ppt,0未单个共享,1共享"`
  164. PptxUrl string `description:"pptx下载地址"`
  165. PptPage int `description:"PPT总页数"`
  166. ReportId int `description:"关联的报告ID"`
  167. ReportCode string `description:"关联的报告code"`
  168. PublishTime string `description:"发布时间"`
  169. Editor PPTEditingCache `description:"编辑人信息"`
  170. }
  171. func (p RespGroupPptList) Len() int {
  172. return len(p.List)
  173. }
  174. func (p RespGroupPptList) Less(i, j int) bool {
  175. if p.List[i].PptCreateTime < p.List[j].PptCreateTime {
  176. return false
  177. }
  178. return true
  179. }
  180. func (p RespGroupPptList) Swap(i, j int) {
  181. p.List[i], p.List[j] = p.List[j], p.List[i]
  182. }
  183. type ReqPptShare struct {
  184. GroupPptId int64 `description:"目录和ppt绑定序号"`
  185. }
  186. type RespPptShare struct {
  187. GroupPptId int64 `description:"目录和ppt绑定自增序号"`
  188. IsSingleShare int8 `description:"是否是单个共享ppt,0未单个共享,1共享"`
  189. }
  190. type RespGroupPptList struct {
  191. List []*RespGroupPptListItem
  192. Total int `description:"ppt总数"`
  193. }
  194. type ReqMoveGroupPpt struct {
  195. GroupId int64 `description:"目标目录id"`
  196. GroupPptId int64 `description:"当前被移动的目录里的ppt绑定序号"`
  197. PrevGroupPptId int64 `description:"上一个目录里的ppt绑定序号,ppt最终在目录中置顶,则传0值"`
  198. NextGroupPptId int64 `description:"下一个目录里的ppt绑定序号,ppt最终在目录末尾,则传0值"`
  199. }
  200. type ReqMoveGroup struct {
  201. GroupId int64 `description:"目标目录id"`
  202. PrevGroupId int64 `description:"上一个目录Id,置顶,则传0值"`
  203. NextGroupId int64 `description:"下一个目录Id,放到末尾,则传0值"`
  204. }
  205. type ReqCopyPpt struct {
  206. GroupId int64 `description:"目录id"`
  207. PptId int `description:"PptId" `
  208. }
  209. type RespPptGroupNameList struct {
  210. List []*RespPptGroupName
  211. }
  212. type RespPptGroupName struct {
  213. GroupId int64 `gorm:"column:group_id` // `description:"目录id"`
  214. GroupName string `gorm:"column:group_name"` //`description:"目录名称"`
  215. }
  216. type RespSearchGroupPptList struct {
  217. List []*RespSearchGroupPptListItem
  218. }
  219. type RespSearchGroupPptListItem struct {
  220. GroupPptId int64 `description:"目录和ppt绑定序号"`
  221. PptId int64 `description:"ppt ID"`
  222. Title string `description:"标题"`
  223. }
  224. type ReqPptShareV2 struct {
  225. PptId int `description:"pptId"`
  226. }
  227. type RespPptShareV2 struct {
  228. PptId int `description:"目录和ppt绑定自增序号"`
  229. IsShare int8 `description:"是否是单个共享ppt,0未单个共享,1共享"`
  230. }