ppt_v2_group.go 11 KB

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