ppt_group.go 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  1. package ppt
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/services"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "github.com/shopspring/decimal"
  11. "sort"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type PageContent struct {
  17. //Id int `json:"id"`
  18. Key int `json:"key"`
  19. ModelId int `json:"modelId"`
  20. Title string `json:"title"`
  21. Elements []PageContentElements `json:"elements"`
  22. }
  23. type PageContentElements struct {
  24. Type string `json:"type"`
  25. Position int `json:"position"`
  26. Content string `json:"content"`
  27. RichContent string `json:"richContent"`
  28. ChartId string `json:"chartId"`
  29. Src string `json:"src"`
  30. }
  31. // GetGroupsByAdminId 查询ppt目录列表
  32. func GetGroupsByAdminId(IsNewPpt, adminId int) (ret models.RespGroupList, err error) {
  33. publicGroups, err := models.GetPublicPptGroups()
  34. if err != nil {
  35. err = errors.New("公共目录查询出错:" + err.Error())
  36. return
  37. }
  38. privateGroups, err := models.GetPrivatePptGroups(adminId)
  39. if err != nil {
  40. err = errors.New("私有目录查询出错:" + err.Error())
  41. return
  42. }
  43. groupIds := make([]int64, 0)
  44. for _, v := range publicGroups {
  45. groupIds = append(groupIds, v.GroupId)
  46. }
  47. for _, v := range privateGroups {
  48. groupIds = append(groupIds, v.GroupId)
  49. }
  50. ret.PublicList = make([]*models.RespGroupListItem, 0)
  51. ret.PrivateList = make([]*models.RespGroupListItem, 0)
  52. if len(groupIds) == 0 {
  53. return
  54. }
  55. //整理目录数据
  56. for _, v := range publicGroups {
  57. tmp := new(models.RespGroupListItem)
  58. tmp.GroupId = v.GroupId
  59. tmp.GroupName = v.GroupName
  60. tmp.IsShare = v.IsShare
  61. tmp.AdminId = v.AdminId
  62. ret.PublicList = append(ret.PublicList, tmp)
  63. }
  64. for _, v := range privateGroups {
  65. if v.IsShareAdd == 1 {
  66. continue
  67. } else {
  68. tmp := new(models.RespGroupListItem)
  69. tmp.GroupId = v.GroupId
  70. tmp.GroupName = v.GroupName
  71. tmp.IsShare = v.IsShare
  72. tmp.AdminId = v.AdminId
  73. ret.PrivateList = append(ret.PrivateList, tmp)
  74. }
  75. }
  76. pptMappings, err := models.GetPptMappingListByGroupIds(groupIds)
  77. if err != nil {
  78. err = errors.New("查询目录里的ppt出错:" + err.Error())
  79. return
  80. }
  81. pptMap := make(map[int]*models.PptV2)
  82. groupMap := make(map[int64][]*models.RespGroupPptNameListItem)
  83. groupHasNewPptMap := make(map[int64]struct{})
  84. pptIds := make([]int, 0)
  85. for _, v := range pptMappings {
  86. pptIds = append(pptIds, int(v.PptId))
  87. }
  88. if len(pptIds) == 0 {
  89. // 返回所有空目录
  90. return
  91. }
  92. pptList, err := models.GetPptV2ByIds(pptIds)
  93. if err != nil {
  94. err = errors.New("查询ppt详情出错:" + err.Error())
  95. return
  96. }
  97. for _, v := range pptList {
  98. pptMap[v.PptId] = v
  99. }
  100. //组装group ppt
  101. for _, v := range pptMappings {
  102. tmp := new(models.RespGroupPptNameListItem)
  103. tmp.AdminId = v.AdminId
  104. tmp.GroupPptId = v.GroupPptId
  105. tmp.PptId = v.PptId
  106. if v.ChildGroupPptId > 0 {
  107. tmp.IsSingleShare = 1
  108. }
  109. if i, ok := pptMap[int(v.PptId)]; ok {
  110. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  111. if i.Content != "" {
  112. contents := make([]PageContent, 0)
  113. if e := json.Unmarshal([]byte(i.Content), &contents); e != nil {
  114. err = errors.New("解析PPT内容页数失败: " + e.Error())
  115. return
  116. }
  117. tmp.PptPage = len(contents)
  118. }
  119. tmp.Title = i.Title
  120. tmp.PptVersion = i.PptVersion
  121. tmp.PptxUrl = i.PptxUrl
  122. tmp.ReportId = i.ReportId
  123. tmp.ReportCode = i.ReportCode
  124. tmp.PptCreateTime = i.CreateTime.Format(utils.FormatDateTime)
  125. }
  126. tmp.AdminRealName = v.AdminRealName
  127. if tmp.PptVersion == 2 {
  128. groupHasNewPptMap[v.GroupId] = struct{}{}
  129. } else {
  130. if IsNewPpt == 1 { //如果只展示新版的ppt,则忽略旧版ppt
  131. continue
  132. }
  133. }
  134. groupMap[v.GroupId] = append(groupMap[v.GroupId], tmp)
  135. }
  136. for k, v := range ret.PublicList {
  137. if pptL, ok := groupMap[v.GroupId]; ok {
  138. ret.PublicList[k].PptList = pptL
  139. if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
  140. ret.PublicList[k].OnlyOld = true
  141. }
  142. }
  143. }
  144. for k, v := range ret.PrivateList {
  145. if pptL, ok := groupMap[v.GroupId]; ok {
  146. ret.PrivateList[k].PptList = pptL
  147. if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
  148. ret.PrivateList[k].OnlyOld = true
  149. }
  150. }
  151. }
  152. if IsNewPpt == 1 { //如果只展示新版ppt,则过滤空文件夹
  153. pubList := make([]*models.RespGroupListItem, 0)
  154. for _, v := range ret.PublicList {
  155. if len(v.PptList) > 0 {
  156. pubList = append(pubList, v)
  157. }
  158. }
  159. ret.PublicList = pubList
  160. priList := make([]*models.RespGroupListItem, 0)
  161. for _, v := range ret.PrivateList {
  162. if len(v.PptList) > 0 {
  163. priList = append(priList, v)
  164. }
  165. }
  166. ret.PrivateList = priList
  167. }
  168. return
  169. }
  170. // AddGroup 新增ppt目录
  171. func AddGroup(groupName string, adminId int, isShare int8, isSharedAdd int8) (newId int64, err error) {
  172. item, err := models.GetPptGroupByName(groupName, adminId)
  173. if err != nil && !utils.IsErrNoRow(err) {
  174. err = errors.New("目录查询出错:" + err.Error())
  175. return
  176. }
  177. if item != nil && item.GroupId > 0 {
  178. err = errors.New("目录名称已存在,不可重复添加")
  179. return
  180. }
  181. groupInfo := &models.PptV2Group{
  182. GroupName: groupName,
  183. AdminId: adminId,
  184. IsShare: isShare,
  185. IsShareAdd: isSharedAdd,
  186. CreateTime: time.Now(),
  187. ModifyTime: time.Now(),
  188. }
  189. if isShare == 1 {
  190. groupInfo.ShareTime = time.Now()
  191. }
  192. newId, err = models.AddPptGroup(groupInfo)
  193. if err != nil {
  194. err = errors.New("新增失败,Err:" + err.Error())
  195. return
  196. }
  197. groupInfo.GroupSort = newId
  198. groupInfo.GroupId = newId
  199. // 更新排序标识
  200. err = groupInfo.Update([]string{"group_sort"})
  201. if err != nil {
  202. err = errors.New("更新排序失败:" + err.Error())
  203. return
  204. }
  205. return
  206. }
  207. // AddGroupPptMapping 新增ppt和目录映射关系
  208. func AddGroupPptMapping(pptId int64, groupId int64, adminId int, adminRealName string) (newId int64, err error) {
  209. _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  210. if err != nil {
  211. if utils.IsErrNoRow(err) {
  212. err = errors.New("目录不存在")
  213. return
  214. }
  215. err = errors.New("目录查询出错:" + err.Error())
  216. return
  217. }
  218. // 获取当前目录下最大的排序
  219. pptSort, err := models.GetMaxSortByGroupId(groupId)
  220. if err != nil {
  221. err = errors.New("查询最大排序出错:" + err.Error())
  222. return
  223. }
  224. newSort, _ := decimal.NewFromFloat(pptSort).Add(decimal.NewFromInt(1)).Float64()
  225. bindInfo := &models.PptV2GroupMapping{
  226. GroupId: groupId,
  227. PptId: pptId,
  228. AdminId: adminId,
  229. AdminRealName: adminRealName,
  230. CreateTime: time.Now(),
  231. ModifyTime: time.Now(),
  232. PptSort: newSort,
  233. }
  234. newId, err = models.AddPptGroupMapping(bindInfo)
  235. if err != nil {
  236. err = errors.New("绑定目录失败:" + err.Error())
  237. return
  238. }
  239. bindInfo.GroupPptId = newId
  240. //bindInfo.PptSort = newId
  241. //err = bindInfo.Update([]string{"ppt_sort"})
  242. //if err != nil {
  243. // err = errors.New("更新排序失败:" + err.Error())
  244. // return
  245. //}
  246. return
  247. }
  248. // DelGroup 删除ppt 目录
  249. func DelGroup(groupId int64, adminId int) (err error) {
  250. _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  251. if err != nil {
  252. if utils.IsErrNoRow(err) {
  253. err = errors.New("目录不存在")
  254. return
  255. }
  256. err = errors.New("目录查询出错:" + err.Error())
  257. return
  258. }
  259. //查询是否有映射存在
  260. count, err := models.GetPptMappingCountByGroupId(groupId)
  261. if err != nil {
  262. err = errors.New("查询目录里的ppt个数出错:" + err.Error())
  263. return
  264. }
  265. if count > 0 {
  266. err = errors.New("该目录下有关联PPT,不允许删除")
  267. return
  268. }
  269. err = models.DeletePptGroup(groupId)
  270. if err != nil {
  271. err = errors.New("删除失败:" + err.Error())
  272. return
  273. }
  274. return
  275. }
  276. // ShareGroup 共享/取消共享目录
  277. func ShareGroup(groupId int64, adminId int) (respShare models.RespPptGroupShare, err error) {
  278. // 查询目录是否存在
  279. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  280. if err != nil {
  281. if utils.IsErrNoRow(err) {
  282. err = errors.New("目录不存在")
  283. return
  284. }
  285. err = errors.New("目录查询出错:" + err.Error())
  286. return
  287. }
  288. // 判断是共享操作还是取消共享操作
  289. if groupInfo.IsShare == 1 {
  290. //取消共享
  291. groupInfo.IsShare = 0
  292. //groupInfo.ModifyTime = time.Now()
  293. err = groupInfo.Update([]string{"is_share"})
  294. if err != nil {
  295. err = errors.New("取消共享出错:" + err.Error())
  296. return
  297. }
  298. } else {
  299. //设置共享
  300. groupInfo.IsShare = 1
  301. groupInfo.ShareTime = time.Now()
  302. err = groupInfo.Update([]string{"is_share", "share_time"})
  303. if err != nil {
  304. err = errors.New("设置共享出错:" + err.Error())
  305. return
  306. }
  307. respShare.IsShare = 1
  308. }
  309. respShare.GroupId = groupId
  310. return
  311. }
  312. // CopyGroup 复制目录
  313. func CopyGroup(groupId int64, adminId int, adminRealName string) (err error) {
  314. //查询目录是否存在
  315. groupInfo, err := models.GetPptGroupByGroupId(groupId)
  316. if err != nil {
  317. if utils.IsErrNoRow(err) {
  318. err = errors.New("目录不存在")
  319. return
  320. }
  321. err = errors.New("目录查询出错:" + err.Error())
  322. return
  323. }
  324. //新增公共目录。目录名称在原来的基础上带上复制序号
  325. groupNames, err := models.GetPptGroupNamesByAdminId(adminId)
  326. if err != nil {
  327. err = errors.New("目录查询出错:" + err.Error())
  328. return
  329. }
  330. newGroupName := generateCopyName(groupInfo.GroupName, 1, groupNames)
  331. newGroupId, err := AddGroup(newGroupName, adminId, 0, 0)
  332. if err != nil {
  333. err = errors.New("复制目录出错:" + err.Error())
  334. return
  335. }
  336. //查询该目录下面是否存在ppt,如果存在则批量复制ppt到新目录下
  337. mappingList, err := models.GetPptMappingListByGroupId(groupId)
  338. if err != nil {
  339. err = errors.New("查询目录里的ppt列表出错:" + err.Error())
  340. return
  341. }
  342. if len(mappingList) <= 0 {
  343. return
  344. }
  345. pptIds := make([]int, 0)
  346. for _, v := range mappingList {
  347. pptIds = append(pptIds, int(v.PptId))
  348. }
  349. //批量查询ppt详情
  350. pptList, err := models.GetPptV2ByIds(pptIds)
  351. if err != nil {
  352. err = errors.New("查询ppt列表出错:" + err.Error())
  353. return
  354. }
  355. pptNames, err := models.GetAllPptTitle()
  356. if err != nil {
  357. err = errors.New("查询ppt标题出错:" + err.Error())
  358. return
  359. }
  360. //批量复制ppt,更新作者为当前账号,并返回新的pptID
  361. newPptList := make([]*models.PptV2, 0)
  362. for _, v := range pptList {
  363. if v.PptVersion != 2 { //只复制新版的ppt,旧版本的ppt忽略
  364. continue
  365. }
  366. tmp := &models.PptV2{
  367. TemplateType: v.TemplateType,
  368. BackgroundImg: v.BackgroundImg,
  369. Title: generateCopyName(v.Title, 1, pptNames),
  370. ReportType: v.ReportType,
  371. PptDate: v.PptDate,
  372. Content: v.Content,
  373. CoverContent: v.CoverContent,
  374. PptUrl: v.PptUrl,
  375. PptxUrl: v.PptxUrl,
  376. CreateTime: time.Now(),
  377. ModifyTime: time.Now(),
  378. AdminId: adminId,
  379. AdminRealName: adminRealName,
  380. PptVersion: v.PptVersion,
  381. TitleSetting: v.TitleSetting,
  382. }
  383. newPptList = append(newPptList, tmp)
  384. }
  385. if len(newPptList) > 0 {
  386. err = models.AddPptV2Multi(newPptList)
  387. if err != nil {
  388. err = errors.New("复制目录里的ppt出错:" + err.Error())
  389. return
  390. }
  391. newMappings := make([]*models.PptV2GroupMapping, 0)
  392. for i, v := range newPptList {
  393. tmp := &models.PptV2GroupMapping{
  394. GroupId: newGroupId,
  395. PptId: int64(v.PptId),
  396. CreateTime: time.Now(),
  397. ModifyTime: time.Now(),
  398. AdminId: adminId,
  399. AdminRealName: adminRealName,
  400. PptSort: float64(i + 1),
  401. }
  402. newMappings = append(newMappings, tmp)
  403. }
  404. err = models.AddPptGroupMappingMulti(newMappings)
  405. if err != nil {
  406. err = errors.New("复制目录里的ppt出错:" + err.Error())
  407. return
  408. }
  409. //批量更新排序字段
  410. //var newGroupPptIds []int64
  411. //for _, v := range newMappings {
  412. // newGroupPptIds = append(newGroupPptIds, v.GroupPptId)
  413. //}
  414. //err = models.UpdatePptGroupMappingSortMulti(newGroupPptIds)
  415. //if err != nil {
  416. // err = errors.New("更新排序标识出错:" + err.Error())
  417. // return
  418. //}
  419. }
  420. return
  421. }
  422. // RenameGroupName 目录重命名
  423. func RenameGroupName(groupId int64, groupName string, adminId int) (err error) {
  424. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  425. if err != nil {
  426. if utils.IsErrNoRow(err) {
  427. err = errors.New("目录不存在")
  428. return
  429. }
  430. err = errors.New("目录查询出错:" + err.Error())
  431. return
  432. }
  433. if groupInfo.GroupName == groupName {
  434. err = errors.New("与原名字一致,无需修改")
  435. return
  436. }
  437. item, err := models.GetPptGroupByName(groupName, adminId)
  438. if err != nil && !utils.IsErrNoRow(err) {
  439. err = errors.New("目录查询出错:" + err.Error())
  440. return
  441. }
  442. if item != nil && item.GroupId > 0 {
  443. err = errors.New("目录名称已存在,不可重复添加")
  444. return
  445. }
  446. //更新新名字
  447. groupInfo.GroupName = groupName
  448. err = groupInfo.Update([]string{"group_name"})
  449. if err != nil {
  450. err = errors.New("目录重命名失败" + err.Error())
  451. return
  452. }
  453. return
  454. }
  455. // ShareSingleGroupPpt 共享单个ppt/取消共享单个ppt,返回共享状态
  456. func ShareSingleGroupPpt(groupPptId int64, adminId int, adminRealName string) (ret models.RespPptShare, err error) {
  457. //判断当前登录者是否有共享的权限
  458. groupPpt, err := models.GetPptMappingByGroupPptId(groupPptId, adminId)
  459. if err != nil {
  460. if utils.IsErrNoRow(err) {
  461. err = errors.New("当前目录下的ppt不存在")
  462. return
  463. }
  464. err = errors.New("目录下的ppt查询出错:" + err.Error())
  465. return
  466. }
  467. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupPpt.GroupId, adminId)
  468. if err != nil {
  469. if utils.IsErrNoRow(err) {
  470. err = errors.New("目录不存在")
  471. return
  472. }
  473. err = errors.New("目录查询出错:" + err.Error())
  474. return
  475. }
  476. //判断当前的共享状态
  477. if groupPpt.ChildGroupPptId > 0 {
  478. err = CancelShareSingleGroupPpt(groupPpt, adminId)
  479. if err != nil {
  480. err = errors.New(err.Error())
  481. return
  482. }
  483. ret.IsSingleShare = 0
  484. } else {
  485. //如果是未共享状态,则共享该ppt,类似复制流程,并更新共享标识
  486. //新增公共目录。目录名称在原来的基础上带上复制序号
  487. groupNames, tErr := models.GetPptGroupNamesByAdminId(adminId)
  488. if tErr != nil {
  489. err = errors.New("目录查询出错:" + tErr.Error())
  490. return
  491. }
  492. newGroupName := generateCopyName(groupInfo.GroupName, 1, groupNames)
  493. newGroupId, tErr := AddGroup(newGroupName, adminId, 1, 1)
  494. if tErr != nil {
  495. err = errors.New(tErr.Error())
  496. return
  497. }
  498. //新增公共的目录和ppt之间的映射关系
  499. newGroupPptId, tErr := AddGroupPptMapping(groupPpt.PptId, newGroupId, adminId, adminRealName)
  500. if tErr != nil {
  501. err = errors.New(tErr.Error())
  502. return
  503. }
  504. //更新共享标识
  505. groupPpt.ChildGroupPptId = newGroupPptId
  506. err = groupPpt.Update([]string{"child_group_ppt_id"})
  507. if err != nil {
  508. err = errors.New("更新共享标识失败" + err.Error())
  509. return
  510. }
  511. ret.IsSingleShare = 1
  512. }
  513. ret.GroupPptId = groupPptId
  514. return
  515. }
  516. // GetGroupPptList 公共目录下的ppt列表或者单个目录里的ppt列表
  517. func GetGroupPptList(groupId int64, adminId int) (ret models.RespGroupPptList, err error) {
  518. var groupPptList []*models.PptV2GroupMapping
  519. var groups []*models.PptV2Group
  520. list := make([]*models.RespGroupPptListItem, 0)
  521. ret.List = list
  522. if groupId > 0 {
  523. //只查询组内的ppt列表
  524. //查询目录是否存在
  525. groupInfo, tErr := models.GetPptGroupByGroupId(groupId)
  526. if tErr != nil {
  527. if utils.IsErrNoRow(tErr) {
  528. err = errors.New("目录不存在")
  529. return
  530. }
  531. err = errors.New("目录查询出错:" + tErr.Error())
  532. return
  533. }
  534. groups = append(groups, groupInfo)
  535. groupPptList, tErr = models.GetPptMappingListByGroupId(groupId)
  536. if tErr != nil {
  537. err = errors.New("目录里的ppt查询出错:" + tErr.Error())
  538. return
  539. }
  540. } else {
  541. // 获取我的所有的ppt
  542. ret, err = GetMyPptList(adminId, ``)
  543. return
  544. ////查询所有公共目录下的ppt列表
  545. //var tErr error
  546. //groups, tErr = models.GetPublicPptGroups()
  547. //if tErr != nil {
  548. // err = errors.New("目录查询出错:" + tErr.Error())
  549. // return
  550. //}
  551. ////查询这些目录下的所有ppt
  552. //groupIds := make([]int64, 0)
  553. //for _, v := range groups {
  554. // groupIds = append(groupIds, v.GroupId)
  555. //}
  556. //
  557. //groupPptList, tErr = models.GetPptMappingListByGroupIds(groupIds)
  558. //if tErr != nil {
  559. // err = errors.New("目录里的ppt查询出错:" + tErr.Error())
  560. // return
  561. //}
  562. }
  563. if len(groupPptList) <= 0 {
  564. return
  565. }
  566. pptMap := make(map[int]*models.PptV2)
  567. groupMap := make(map[int64][]*models.PptV2GroupMapping)
  568. pptIds := make([]int, 0)
  569. for _, v := range groupPptList {
  570. pptIds = append(pptIds, int(v.PptId))
  571. groupMap[v.GroupId] = append(groupMap[v.GroupId], v)
  572. }
  573. if len(pptIds) == 0 {
  574. // 返回所有空目录
  575. return
  576. }
  577. pptList, err := models.GetPptV2ByIds(pptIds)
  578. if err != nil {
  579. err = errors.New("查询ppt详情出错:" + err.Error())
  580. return
  581. }
  582. for _, v := range pptList {
  583. if v.PptPage == 0 && v.Content != "" {
  584. var pptContent []services.PPTContent
  585. err = json.Unmarshal([]byte(v.Content), &pptContent)
  586. if err != nil {
  587. err = errors.New("解析ppt内容出错" + err.Error())
  588. return
  589. }
  590. v.PptPage = len(pptContent)
  591. }
  592. pptMap[v.PptId] = v
  593. }
  594. //按照排序顺序,依次放入ppt
  595. hasPpt := make(map[int]struct{})
  596. for _, v := range groups {
  597. if mapList, ok := groupMap[v.GroupId]; ok {
  598. if len(mapList) > 0 {
  599. for _, pptV := range mapList {
  600. pptInfo, ok1 := pptMap[int(pptV.PptId)]
  601. _, ok2 := hasPpt[int(pptV.PptId)]
  602. if ok1 && !ok2 {
  603. tmp := &models.RespGroupPptListItem{
  604. GroupPptId: pptV.GroupPptId,
  605. PptId: pptV.PptId,
  606. TemplateType: pptInfo.TemplateType,
  607. BackgroundImg: pptInfo.BackgroundImg,
  608. Title: pptInfo.Title,
  609. AdminId: pptV.AdminId,
  610. AdminRealName: pptV.AdminRealName,
  611. IsSingleShare: 0,
  612. PptCreateTime: pptInfo.CreateTime.Format(utils.FormatDateTime),
  613. PptModifyTime: pptInfo.ModifyTime.Format(utils.FormatDateTime),
  614. PptxUrl: pptInfo.PptxUrl,
  615. PptVersion: pptInfo.PptVersion,
  616. ReportId: pptInfo.ReportId,
  617. ReportCode: pptInfo.ReportCode,
  618. PublishTime: utils.DealDateTimeZero(pptInfo.PublishTime, utils.FormatDateTime),
  619. PptPage: pptInfo.PptPage,
  620. }
  621. if pptV.ChildGroupPptId > 0 {
  622. tmp.IsSingleShare = 1
  623. }
  624. list = append(list, tmp)
  625. hasPpt[pptInfo.PptId] = struct{}{}
  626. }
  627. }
  628. }
  629. }
  630. }
  631. ret.List = list
  632. if groupId <= 0 {
  633. sort.Sort(ret)
  634. }
  635. ret.Total = len(list)
  636. return
  637. }
  638. // MoveGroupPpt 移动ppt操作
  639. //func MoveGroupPpt(groupId, groupPptId, prevGroupPptId, nextGroupPptId int64, adminId int) (err error) {
  640. // //查询当前映射是否存在
  641. // //判断当前登录者是否有共享的权限oo
  642. // groupPpt, err := models.GetPptMappingByGroupPptId(groupPptId, adminId)
  643. // if err != nil {
  644. // if utils.IsErrNoRow(err) {
  645. // err = errors.New("当前目录下的ppt不存在")
  646. // return
  647. // }
  648. // err = errors.New("目录下的ppt查询出错:" + err.Error())
  649. // return
  650. // }
  651. // var updateStr []string
  652. // //如果更换了目录,默认当前排序值为0
  653. // var currentSort, prevSort, nextSort int64
  654. // //判断是否更换group
  655. // if groupPpt.GroupId != groupId {
  656. // _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  657. // if err != nil {
  658. // if utils.IsErrNoRow(err) {
  659. // err = errors.New("目录不存在")
  660. // return
  661. // }
  662. // err = errors.New("目录查询出错:" + err.Error())
  663. // return
  664. // }
  665. // //判断是否需要解除当个ppt共享
  666. // //解除共享操作
  667. // err = CancelShareSingleGroupPpt(groupPpt, adminId)
  668. // if err != nil {
  669. // err = errors.New(err.Error())
  670. // return
  671. // }
  672. // groupPpt.GroupId = groupId
  673. // updateStr = append(updateStr, "group_id")
  674. // }
  675. // currentSort = groupPpt.PptSort
  676. //
  677. // var prevGroupPpt *models.PptV2GroupMapping
  678. // var nextGroupPpt *models.PptV2GroupMapping
  679. // if prevGroupPptId > 0 {
  680. // prevGroupPpt, err = models.GetPptMappingByGroupPptId(prevGroupPptId, adminId)
  681. // if err != nil {
  682. // if utils.IsErrNoRow(err) {
  683. // err = errors.New("目录下的ppt不存在")
  684. // return
  685. // }
  686. // err = errors.New("目录下的ppt查询出错:" + err.Error())
  687. // return
  688. // }
  689. // prevSort = prevGroupPpt.PptSort
  690. // }
  691. //
  692. // if nextGroupPptId > 0 {
  693. // nextGroupPpt, err = models.GetPptMappingByGroupPptId(nextGroupPptId, adminId)
  694. // if err != nil {
  695. // if utils.IsErrNoRow(err) {
  696. // err = errors.New("目录下的ppt不存在")
  697. // return
  698. // }
  699. // err = errors.New("目录下的ppt查询出错:" + err.Error())
  700. // return
  701. // }
  702. // nextSort = nextGroupPpt.PptSort
  703. // }
  704. //
  705. // updateStr = append(updateStr, "ppt_sort")
  706. //
  707. // //移到两个排序值中间操作
  708. // if prevSort >= currentSort {
  709. // //往下移动
  710. // err = models.MoveDownGroupPptBySort(groupId, prevSort, currentSort)
  711. // if err != nil {
  712. // err = errors.New("向下移动ppt出错:" + err.Error())
  713. // return
  714. // }
  715. // groupPpt.PptSort = prevSort
  716. // } else if nextSort <= currentSort && nextSort != 0 {
  717. // //往上移动
  718. // err = models.MoveUpGroupPptBySort(groupId, nextSort, currentSort)
  719. // if err != nil {
  720. // err = errors.New("向上移动ppt出错:" + err.Error())
  721. // return
  722. // }
  723. // groupPpt.PptSort = nextSort
  724. // }
  725. // //更新当前排序
  726. // err = groupPpt.Update(updateStr)
  727. // if err != nil {
  728. // err = errors.New("移动ppt出错:" + err.Error())
  729. // return
  730. // }
  731. // return
  732. //}
  733. func MoveGroupPpt(groupId, groupPptId, prevGroupPptId, nextGroupPptId int64, adminId int) (err error) {
  734. //查询当前映射是否存在
  735. //判断当前登录者是否有共享的权限oo
  736. groupPpt, err := models.GetPptMappingByGroupPptId(groupPptId, adminId)
  737. if err != nil {
  738. if utils.IsErrNoRow(err) {
  739. err = errors.New("当前目录下的ppt不存在")
  740. return
  741. }
  742. err = errors.New("目录下的ppt查询出错:" + err.Error())
  743. return
  744. }
  745. var updateStr []string
  746. //判断是否更换group
  747. if groupPpt.GroupId != groupId {
  748. _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  749. if err != nil {
  750. if utils.IsErrNoRow(err) {
  751. err = errors.New("目录不存在")
  752. return
  753. }
  754. err = errors.New("目录查询出错:" + err.Error())
  755. return
  756. }
  757. //判断是否需要解除当个ppt共享
  758. //解除共享操作
  759. err = CancelShareSingleGroupPpt(groupPpt, adminId)
  760. if err != nil {
  761. err = errors.New(err.Error())
  762. return
  763. }
  764. groupPpt.GroupId = groupId
  765. updateStr = append(updateStr, "group_id")
  766. }
  767. var prevGroupPpt *models.PptV2GroupMapping
  768. var nextGroupPpt *models.PptV2GroupMapping
  769. if prevGroupPptId > 0 {
  770. prevGroupPpt, err = models.GetPptMappingByGroupPptId(prevGroupPptId, adminId)
  771. if err != nil {
  772. if utils.IsErrNoRow(err) {
  773. err = errors.New("目录下的ppt不存在")
  774. return
  775. }
  776. err = errors.New("目录下的ppt查询出错:" + err.Error())
  777. return
  778. }
  779. }
  780. if nextGroupPptId > 0 {
  781. nextGroupPpt, err = models.GetPptMappingByGroupPptId(nextGroupPptId, adminId)
  782. if err != nil {
  783. if utils.IsErrNoRow(err) {
  784. err = errors.New("目录下的ppt不存在")
  785. return
  786. }
  787. err = errors.New("目录下的ppt查询出错:" + err.Error())
  788. return
  789. }
  790. }
  791. pptSort := groupPpt.PptSort
  792. if prevGroupPpt != nil && prevGroupPpt.PptId > 0 && nextGroupPpt != nil && nextGroupPpt.PptId > 0 { // 两个之间
  793. pptSort, _ = decimal.NewFromFloat(prevGroupPpt.PptSort).Add(decimal.NewFromFloat(nextGroupPpt.PptSort)).Div(decimal.NewFromInt(2)).Float64()
  794. } else if prevGroupPpt != nil && prevGroupPpt.PptId > 0 {
  795. // 最下面
  796. maxSort, tmpErr := models.GetMinSortByGroupId(prevGroupPpt.GroupId)
  797. if tmpErr != nil {
  798. err = errors.New("获取最小排序失败:" + tmpErr.Error())
  799. return
  800. }
  801. pptSort, _ = decimal.NewFromFloat(maxSort).Sub(decimal.NewFromInt(1)).Float64()
  802. } else if nextGroupPpt != nil && nextGroupPpt.PptId > 0 {
  803. // 最上面
  804. minSort, tmpErr := models.GetMaxSortByGroupId(nextGroupPpt.GroupId)
  805. if tmpErr != nil {
  806. err = errors.New("获取最小排序失败:" + tmpErr.Error())
  807. return
  808. }
  809. pptSort, _ = decimal.NewFromFloat(minSort).Add(decimal.NewFromInt(1)).Float64()
  810. }
  811. groupPpt.PptSort = pptSort
  812. updateStr = append(updateStr, "ppt_sort")
  813. //更新当前排序
  814. err = groupPpt.Update(updateStr)
  815. if err != nil {
  816. err = errors.New("移动ppt出错:" + err.Error())
  817. return
  818. }
  819. return
  820. }
  821. // MoveGroup 移动目录
  822. func MoveGroup(groupId, prevGroupId, nextGroupId int64, adminId int) (err error) {
  823. //查询目录是否存在
  824. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  825. if err != nil {
  826. if utils.IsErrNoRow(err) {
  827. err = errors.New("目录不存在")
  828. return
  829. }
  830. err = errors.New("目录查询出错:" + err.Error())
  831. return
  832. }
  833. //如果更换了目录,默认当前排序值为0
  834. var currentSort, prevSort, nextSort int64
  835. currentSort = groupInfo.GroupSort
  836. var prevGroup *models.PptV2Group
  837. var nextGroup *models.PptV2Group
  838. if prevGroupId > 0 {
  839. prevGroup, err = models.GetPptGroupByGroupIdAdminId(prevGroupId, adminId)
  840. if err != nil {
  841. if utils.IsErrNoRow(err) {
  842. err = errors.New("目录不存在")
  843. return
  844. }
  845. err = errors.New("目录查询出错:" + err.Error())
  846. return
  847. }
  848. prevSort = prevGroup.GroupSort
  849. }
  850. if nextGroupId > 0 {
  851. nextGroup, err = models.GetPptGroupByGroupIdAdminId(nextGroupId, adminId)
  852. if err != nil {
  853. if utils.IsErrNoRow(err) {
  854. err = errors.New("目录不存在")
  855. return
  856. }
  857. err = errors.New("目录查询出错:" + err.Error())
  858. return
  859. }
  860. nextSort = nextGroup.GroupSort
  861. }
  862. //移到两个排序值中间操作
  863. if prevSort >= currentSort {
  864. //往下移动
  865. err = models.MoveDownGroupBySort(prevSort, currentSort)
  866. if err != nil {
  867. err = errors.New("向下移动ppt出错:" + err.Error())
  868. return
  869. }
  870. groupInfo.GroupSort = prevSort
  871. } else if nextSort <= currentSort && nextSort != 0 {
  872. //往上移动
  873. err = models.MoveUpGroupBySort(nextSort, currentSort)
  874. if err != nil {
  875. err = errors.New("向上移动ppt出错:" + err.Error())
  876. return
  877. }
  878. groupInfo.GroupSort = nextSort
  879. }
  880. //更新当前排序
  881. err = groupInfo.Update([]string{"group_sort"})
  882. if err != nil {
  883. err = errors.New("移动目录出错:" + err.Error())
  884. return
  885. }
  886. return
  887. }
  888. // CancelShareSingleGroupPpt 解除单个共享的ppt
  889. func CancelShareSingleGroupPpt(groupPpt *models.PptV2GroupMapping, adminId int) (err error) {
  890. if groupPpt.ChildGroupPptId <= 0 {
  891. return
  892. }
  893. //如果已经是共享状态,
  894. //判断当前登录者是否有取消共享的权限
  895. childGroupPpt, tErr := models.GetPptMappingByGroupPptId(groupPpt.ChildGroupPptId, adminId)
  896. if tErr != nil {
  897. if !utils.IsErrNoRow(tErr) {
  898. err = errors.New("目录下的ppt查询出错:" + tErr.Error())
  899. return
  900. }
  901. }
  902. if childGroupPpt != nil {
  903. //删除共享目录和ppt的映射关系
  904. err = models.DeletePptGroupMapping(childGroupPpt.GroupPptId, adminId)
  905. if err != nil {
  906. err = errors.New("删除共享目录下的ppt失败:" + err.Error())
  907. return
  908. }
  909. //删除共享出去的公共目录
  910. err = models.DeletePptGroup(childGroupPpt.GroupId)
  911. if err != nil {
  912. err = errors.New("删除共享目录失败:" + err.Error())
  913. return
  914. }
  915. }
  916. //更新共享状态为未共享,
  917. //更新共享标识
  918. groupPpt.ChildGroupPptId = 0
  919. err = groupPpt.Update([]string{"child_group_ppt_id"})
  920. if err != nil {
  921. err = errors.New("更新共享标识失败" + err.Error())
  922. return
  923. }
  924. return
  925. }
  926. // DeleteGroupPpt 删除ppt
  927. func DeleteGroupPpt(PptId int) (err error) {
  928. //查询该ppt的所有单个共享出去的目录信息
  929. groupPpts, err := models.GetGroupPptByPptId(PptId)
  930. if err != nil {
  931. err = errors.New("查询目录里的ppt失败" + err.Error())
  932. return
  933. }
  934. if len(groupPpts) <= 0 {
  935. return
  936. }
  937. //整理出需要删除的groupId
  938. groupPptMap := make(map[int64]*models.PptV2GroupMapping)
  939. for _, v := range groupPpts {
  940. groupPptMap[v.GroupPptId] = v
  941. }
  942. var delGroupIds string
  943. for _, v := range groupPpts {
  944. if v.ChildGroupPptId > 0 {
  945. if childGroup, ok := groupPptMap[v.ChildGroupPptId]; ok {
  946. delGroupIds += strconv.Itoa(int(childGroup.GroupId)) + ","
  947. }
  948. }
  949. }
  950. if delGroupIds != "" {
  951. delGroupIds = "(" + strings.Trim(delGroupIds, ",") + ")"
  952. err = models.DeletePptGroupByGroupIds(delGroupIds)
  953. if err != nil {
  954. err = errors.New("删除单个共享目录失败" + err.Error())
  955. return
  956. }
  957. }
  958. //再统一删除目录里相关的ppt
  959. err = models.DeletePptGroupMappingByPptId(PptId)
  960. if err != nil {
  961. err = errors.New("删除目录里的ppt失败" + err.Error())
  962. return
  963. }
  964. return
  965. }
  966. // CopyPpt 复制单个ppt,并移动到新的目录下面
  967. func CopyPpt(pptId int, groupId int64, adminId int, adminRealName string) (resp models.RespGroupPptNameListItem, err error) {
  968. //查询ppt详情
  969. pptInfo, err := models.GetPptV2ById(pptId)
  970. if err != nil {
  971. if utils.IsErrNoRow(err) {
  972. err = errors.New("ppt 不存在")
  973. return
  974. }
  975. err = errors.New("查询ppt失败" + err.Error())
  976. return
  977. }
  978. if pptInfo.PptVersion == 1 {
  979. err = errors.New("旧版本的ppt不允许复制")
  980. return
  981. }
  982. // 查询目录是否存在
  983. _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  984. if err != nil {
  985. if utils.IsErrNoRow(err) {
  986. err = errors.New("目录不存在")
  987. return
  988. }
  989. err = errors.New("目录查询出错:" + err.Error())
  990. return
  991. }
  992. pptNames, err := models.GetAllPptTitle()
  993. if err != nil {
  994. err = errors.New("查询ppt标题出错:" + err.Error())
  995. return
  996. }
  997. //复制ppt,更新作者为当前账号,并返回新的pptID
  998. var newPptList []*models.PptV2
  999. newPpt := &models.PptV2{
  1000. TemplateType: pptInfo.TemplateType,
  1001. BackgroundImg: pptInfo.BackgroundImg,
  1002. Title: generateCopyName(pptInfo.Title, 1, pptNames),
  1003. ReportType: pptInfo.ReportType,
  1004. PptDate: pptInfo.PptDate,
  1005. Content: pptInfo.Content,
  1006. CoverContent: pptInfo.CoverContent,
  1007. PptUrl: pptInfo.PptUrl,
  1008. PptxUrl: pptInfo.PptxUrl,
  1009. CreateTime: time.Now(),
  1010. ModifyTime: time.Now(),
  1011. AdminId: adminId,
  1012. AdminRealName: adminRealName,
  1013. PptVersion: pptInfo.PptVersion,
  1014. TitleSetting: pptInfo.TitleSetting,
  1015. }
  1016. newPptList = append(newPptList, newPpt)
  1017. err = models.AddPptV2Multi(newPptList)
  1018. if err != nil {
  1019. err = errors.New("复制目录里的ppt出错:" + err.Error())
  1020. return
  1021. }
  1022. // 获取当前目录下最大的排序
  1023. pptSort, err := models.GetMaxSortByGroupId(groupId)
  1024. if err != nil {
  1025. err = errors.New("查询最大排序出错:" + err.Error())
  1026. return
  1027. }
  1028. newSort, _ := decimal.NewFromFloat(pptSort).Add(decimal.NewFromInt(1)).Float64()
  1029. var newMappings []*models.PptV2GroupMapping
  1030. newGroupPpt := &models.PptV2GroupMapping{
  1031. GroupId: groupId,
  1032. PptId: int64(newPpt.PptId),
  1033. CreateTime: time.Now(),
  1034. ModifyTime: time.Now(),
  1035. AdminId: adminId,
  1036. AdminRealName: adminRealName,
  1037. PptSort: newSort,
  1038. }
  1039. newMappings = append(newMappings, newGroupPpt)
  1040. err = models.AddPptGroupMappingMulti(newMappings)
  1041. if err != nil {
  1042. err = errors.New("复制目录里的ppt出错:" + err.Error())
  1043. return
  1044. }
  1045. //批量更新排序字段
  1046. //err = models.UpdatePptGroupMappingSortMulti([]int64{newGroupPpt.GroupPptId})
  1047. //if err != nil {
  1048. // err = errors.New("更新排序标识出错:" + err.Error())
  1049. // return
  1050. //}
  1051. pptPage := 0
  1052. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  1053. if newPpt.Content != "" {
  1054. contents := make([]PageContent, 0)
  1055. if e := json.Unmarshal([]byte(newPpt.Content), &contents); e != nil {
  1056. err = errors.New(fmt.Sprintf("%d,解析PPT内容页数失败: %s", newPpt.PptId, e.Error()))
  1057. return
  1058. }
  1059. pptPage = len(contents)
  1060. }
  1061. resp = models.RespGroupPptNameListItem{
  1062. GroupPptId: newGroupPpt.GroupPptId,
  1063. PptId: int64(newPpt.PptId),
  1064. Title: newPpt.Title,
  1065. AdminId: newPpt.AdminId,
  1066. AdminRealName: newPpt.AdminRealName,
  1067. PptVersion: newPpt.PptVersion,
  1068. PptxUrl: newPpt.PptxUrl,
  1069. ReportId: newPpt.ReportId,
  1070. ReportCode: newPpt.ReportCode,
  1071. PptCreateTime: newPpt.CreateTime.Format(utils.FormatDateTime),
  1072. PptPage: pptPage,
  1073. TitleSetting: newPpt.TitleSetting,
  1074. }
  1075. return
  1076. }
  1077. // generateCopyName 生成复制的目录名称
  1078. func generateCopyName(originName string, count int, nameList []string) (newName string) {
  1079. newName = originName + "(" + strconv.Itoa(count) + ")"
  1080. for _, v := range nameList {
  1081. if v == newName {
  1082. count++
  1083. newName = generateCopyName(originName, count, nameList)
  1084. return
  1085. }
  1086. }
  1087. return
  1088. }
  1089. // SearchGroupPpt 根据ppt标题搜索ppt
  1090. func SearchGroupPpt(keyWord string) (ret models.RespSearchGroupPptList, err error) {
  1091. //组装group ppt
  1092. list := make([]*models.RespSearchGroupPptListItem, 0)
  1093. ret.List = list
  1094. reqKeyword := "%" + keyWord + "%"
  1095. condition := " and title like ? "
  1096. var pars []interface{}
  1097. pars = append(pars, reqKeyword)
  1098. pptList, err := models.GetPptV2ByCondition(condition, pars)
  1099. if err != nil {
  1100. err = errors.New("查询ppt列表出错:" + err.Error())
  1101. return
  1102. }
  1103. if len(pptList) == 0 {
  1104. return
  1105. }
  1106. pptIds := make([]string, 0)
  1107. pptMap := make(map[int]*models.PptV2)
  1108. for _, v := range pptList {
  1109. pptIds = append(pptIds, strconv.Itoa(v.PptId))
  1110. pptMap[v.PptId] = v
  1111. }
  1112. groupPptList, err := models.GetPublicGroupPptByPptIds(pptIds)
  1113. if err != nil {
  1114. err = errors.New("查询目录里的ppt列表出错:" + err.Error())
  1115. return
  1116. }
  1117. for _, v := range groupPptList {
  1118. tmp := new(models.RespSearchGroupPptListItem)
  1119. tmp.GroupPptId = v.GroupPptId
  1120. tmp.PptId = v.PptId
  1121. if i, ok := pptMap[int(v.PptId)]; ok {
  1122. tmp.Title = i.Title
  1123. }
  1124. list = append(list, tmp)
  1125. }
  1126. ret.List = list
  1127. return
  1128. }
  1129. // GetGroupsByAdminIdV2 查询ppt目录列表
  1130. // @Author roc
  1131. // @Time 2022-08-29 15:22:20
  1132. func GetGroupsByAdminIdV2(IsNewPpt, adminId int, lang string) (ret models.RespGroupList, err error) {
  1133. myPptList := make([]*models.RespGroupPptNameListItem, 0)
  1134. otherPptList := make([]*models.RespGroupPptNameListItem, 0)
  1135. grantList := []models.RespGroupListItem{}
  1136. if lang == utils.EnLangVersion {
  1137. grantList = append(grantList, []models.RespGroupListItem{
  1138. {
  1139. GroupId: 1,
  1140. GroupName: "My shared",
  1141. PptList: myPptList,
  1142. },
  1143. {
  1144. GroupId: 2,
  1145. GroupName: "Received shared",
  1146. PptList: otherPptList,
  1147. },
  1148. }...)
  1149. } else {
  1150. grantList = append(grantList, []models.RespGroupListItem{
  1151. {
  1152. GroupId: 1,
  1153. GroupName: "我共享的",
  1154. PptList: myPptList,
  1155. },
  1156. {
  1157. GroupId: 2,
  1158. GroupName: "收到共享",
  1159. PptList: otherPptList,
  1160. },
  1161. }...)
  1162. }
  1163. ret.PublicList = make([]*models.RespGroupListItem, 0)
  1164. ret.PrivateList = make([]*models.RespGroupListItem, 0)
  1165. ret.GrantList = grantList
  1166. pptMap := make(map[int]*models.PptV2)
  1167. groupMap := make(map[int64][]*models.RespGroupPptNameListItem)
  1168. groupHasNewPptMap := make(map[int64]struct{})
  1169. pptIds := make([]int, 0)
  1170. // 获取我的ppt分组
  1171. privateGroups, err := models.GetPrivatePptGroupsByAdminId(adminId)
  1172. if err != nil {
  1173. err = errors.New("私有目录查询出错:" + err.Error())
  1174. return
  1175. }
  1176. groupIds := make([]int64, 0)
  1177. for _, v := range privateGroups {
  1178. groupIds = append(groupIds, v.GroupId)
  1179. }
  1180. var pptMappings []*models.PptV2GroupMapping
  1181. // 如果没有分组,那么直接返回
  1182. if len(groupIds) > 0 {
  1183. // 遍历分组并拼接
  1184. for _, v := range privateGroups {
  1185. tmp := new(models.RespGroupListItem)
  1186. tmp.GroupId = v.GroupId
  1187. tmp.GroupName = v.GroupName
  1188. tmp.IsShare = v.IsShare
  1189. tmp.AdminId = v.AdminId
  1190. ret.PrivateList = append(ret.PrivateList, tmp)
  1191. }
  1192. // 通过分组id获取相关的ppt信息,主要是为了获取所有的ppt_id字段
  1193. pptMappings, err = models.GetPptMappingListByGroupIds(groupIds)
  1194. if err != nil {
  1195. err = errors.New("查询目录里的ppt出错:" + err.Error())
  1196. return
  1197. }
  1198. for _, v := range pptMappings {
  1199. pptIds = append(pptIds, int(v.PptId))
  1200. }
  1201. }
  1202. adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
  1203. adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
  1204. // grantList 已经分配权限的ppt
  1205. grantPptList, err := models.GetAllGrantList(adminId)
  1206. for _, v := range grantPptList {
  1207. pptIds = append(pptIds, v.PptId)
  1208. if _, ok := adminIdMap[v.AdminId]; !ok {
  1209. adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
  1210. adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  1211. }
  1212. }
  1213. if len(pptIds) > 0 {
  1214. // 通过ppt_id列表字段获取所有的ppt信息
  1215. pptList, tmpErr := models.GetPptV2ByIds(pptIds)
  1216. if tmpErr != nil {
  1217. err = errors.New("查询ppt详情出错:" + err.Error())
  1218. return
  1219. }
  1220. for _, v := range pptList {
  1221. pptMap[v.PptId] = v
  1222. }
  1223. }
  1224. // 私有的Ppt列表
  1225. {
  1226. //组装group ppt
  1227. for _, v := range pptMappings {
  1228. i, ok := pptMap[int(v.PptId)]
  1229. if !ok { //找不到ppt,还干个啥,直接退出当前循环啊
  1230. continue
  1231. }
  1232. if IsNewPpt == 1 && i.PptVersion != 2 { //都说了只要新版ppt,你一个不是新版ppt的,凑啥热闹,靠边站去,直接退出当前循环啊
  1233. continue
  1234. }
  1235. pptPage := 0
  1236. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  1237. if i.Content != "" {
  1238. contents := make([]PageContent, 0)
  1239. if e := json.Unmarshal([]byte(i.Content), &contents); e != nil {
  1240. err = errors.New(fmt.Sprintf("%d,解析PPT内容页数失败: %s", i.PptId, e.Error()))
  1241. return
  1242. }
  1243. pptPage = len(contents)
  1244. }
  1245. tmp := &models.RespGroupPptNameListItem{
  1246. AdminId: v.AdminId,
  1247. GroupPptId: v.GroupPptId,
  1248. PptId: v.PptId,
  1249. AdminRealName: v.AdminRealName,
  1250. Title: i.Title,
  1251. PptVersion: i.PptVersion,
  1252. IsSingleShare: i.IsShare,
  1253. PptxUrl: i.PptxUrl,
  1254. ReportId: i.ReportId,
  1255. ReportCode: i.ReportCode,
  1256. PptCreateTime: i.CreateTime.Format(utils.FormatDateTime),
  1257. PptModifyTime: i.ModifyTime.Format(utils.FormatDateTime),
  1258. PublishTime: utils.DealDateTimeZero(i.PublishTime, utils.FormatDateTime),
  1259. PptPage: pptPage,
  1260. }
  1261. if tmp.PptVersion == 2 {
  1262. groupHasNewPptMap[v.GroupId] = struct{}{}
  1263. }
  1264. groupMap[v.GroupId] = append(groupMap[v.GroupId], tmp)
  1265. }
  1266. for k, v := range ret.PrivateList {
  1267. if pptL, ok := groupMap[v.GroupId]; ok {
  1268. ret.PrivateList[k].PptList = pptL
  1269. if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
  1270. ret.PrivateList[k].OnlyOld = true
  1271. }
  1272. }
  1273. }
  1274. }
  1275. publicAdminIdList := make([]int, 0)
  1276. publicPptListMap := make(map[int][]*models.RespGroupPptNameListItem)
  1277. // 获取公开分享的ppt
  1278. sharePptList, err := models.GetSharePptV2(IsNewPpt)
  1279. for _, v := range sharePptList {
  1280. publicPptList, ok := publicPptListMap[v.AdminId]
  1281. if !ok {
  1282. publicPptList = make([]*models.RespGroupPptNameListItem, 0)
  1283. publicAdminIdList = append(publicAdminIdList, v.AdminId)
  1284. // 需要查询的创建人信息
  1285. if _, ok := adminIdMap[v.AdminId]; !ok {
  1286. adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
  1287. adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  1288. }
  1289. }
  1290. contents := make([]PageContent, 0)
  1291. if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
  1292. err = errors.New("解析PPT内容页数失败: " + e.Error())
  1293. return
  1294. }
  1295. pptPage := len(contents)
  1296. tmpV := &models.RespGroupPptNameListItem{
  1297. GroupPptId: int64(v.PptId),
  1298. PptId: int64(v.PptId),
  1299. Title: v.Title,
  1300. AdminId: v.AdminId,
  1301. AdminRealName: v.AdminRealName,
  1302. PptVersion: v.PptVersion,
  1303. IsSingleShare: v.IsShare,
  1304. PptxUrl: v.PptxUrl,
  1305. ReportId: v.ReportId,
  1306. ReportCode: v.ReportCode,
  1307. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1308. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1309. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1310. PptPage: pptPage,
  1311. }
  1312. publicPptList = append(publicPptList, tmpV)
  1313. publicPptListMap[v.AdminId] = publicPptList
  1314. }
  1315. // 创建人信息
  1316. systemAdminMap := make(map[int]*system.Admin)
  1317. systemAdminList, err := system.GetAdminListByIdList(adminIdList)
  1318. if err != nil {
  1319. return
  1320. }
  1321. for _, v := range systemAdminList {
  1322. systemAdminMap[v.AdminId] = v
  1323. }
  1324. // 公开分享的用户列表
  1325. {
  1326. for _, v := range publicAdminIdList {
  1327. systemAdmin, ok := systemAdminMap[v]
  1328. if !ok {
  1329. continue
  1330. }
  1331. // ppt 列表信息
  1332. respGroupPptNameListItemList, ok := publicPptListMap[v]
  1333. if !ok {
  1334. respGroupPptNameListItemList = make([]*models.RespGroupPptNameListItem, 0)
  1335. }
  1336. // ppt 分组信息
  1337. tmpRespGroupListItem := &models.RespGroupListItem{
  1338. GroupId: int64(systemAdmin.AdminId),
  1339. GroupName: systemAdmin.RealName + "的PPT",
  1340. AdminId: systemAdmin.AdminId,
  1341. IsShare: 1,
  1342. OnlyOld: false,
  1343. PptList: respGroupPptNameListItemList,
  1344. }
  1345. ret.PublicList = append(ret.PublicList, tmpRespGroupListItem)
  1346. }
  1347. }
  1348. myGrantPPtIdMap := make(map[int]int) //我分配的ppt的id集合
  1349. // 共享Ppt
  1350. {
  1351. for _, v := range grantPptList {
  1352. pptPage := 0
  1353. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  1354. if v.Content != "" {
  1355. contents := make([]PageContent, 0)
  1356. if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
  1357. err = errors.New("解析PPT内容页数失败: " + e.Error())
  1358. return
  1359. }
  1360. }
  1361. title := v.Title
  1362. if adminInfo, ok := systemAdminMap[v.AdminId]; ok {
  1363. title = adminInfo.RealName + "———" + title
  1364. }
  1365. tmp := &models.RespGroupPptNameListItem{
  1366. AdminId: v.AdminId,
  1367. //GroupPptId: v.GroupPptId,
  1368. PptId: int64(v.PptId),
  1369. AdminRealName: v.AdminRealName,
  1370. Title: title,
  1371. PptVersion: v.PptVersion,
  1372. IsSingleShare: v.IsShare,
  1373. PptxUrl: v.PptxUrl,
  1374. ReportId: v.ReportId,
  1375. ReportCode: v.ReportCode,
  1376. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1377. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1378. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1379. PptPage: pptPage,
  1380. }
  1381. //如果只展示新版ppt,则过滤旧版的Ppt
  1382. if IsNewPpt == 1 && v.PptVersion == 1 {
  1383. continue
  1384. }
  1385. if v.AdminId == adminId {
  1386. tmp.IsGrant = 1
  1387. myPptList = append(myPptList, tmp)
  1388. myGrantPPtIdMap[v.PptId] = v.PptId
  1389. } else {
  1390. tmp.IsReceived = 1
  1391. otherPptList = append(otherPptList, tmp)
  1392. }
  1393. }
  1394. grantList[0].PptList = myPptList
  1395. grantList[1].PptList = otherPptList
  1396. ret.GrantList = grantList
  1397. }
  1398. // 处理公共ppt里面的关于自个的ppt是否有配置权限的字段数据变更
  1399. for k, publicList := range ret.PublicList {
  1400. for kk, pptInfo := range publicList.PptList {
  1401. // 是否有过权限配置
  1402. if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
  1403. pptInfo.IsGrant = 1
  1404. }
  1405. publicList.PptList[kk] = pptInfo
  1406. }
  1407. ret.PublicList[k] = publicList
  1408. }
  1409. for k, privateList := range ret.PrivateList {
  1410. for kk, pptInfo := range privateList.PptList {
  1411. // 是否有过权限配置
  1412. if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
  1413. pptInfo.IsGrant = 1
  1414. }
  1415. privateList.PptList[kk] = pptInfo
  1416. }
  1417. ret.PrivateList[k] = privateList
  1418. }
  1419. //如果只展示新版ppt,则过滤空文件夹
  1420. if IsNewPpt == 1 {
  1421. //公共ppt
  1422. pubList := make([]*models.RespGroupListItem, 0)
  1423. for _, v := range ret.PublicList {
  1424. if len(v.PptList) > 0 {
  1425. pubList = append(pubList, v)
  1426. }
  1427. }
  1428. ret.PublicList = pubList
  1429. // 私有ppt
  1430. priList := make([]*models.RespGroupListItem, 0)
  1431. for _, v := range ret.PrivateList {
  1432. if len(v.PptList) > 0 {
  1433. priList = append(priList, v)
  1434. }
  1435. }
  1436. ret.PrivateList = priList
  1437. }
  1438. return
  1439. }
  1440. // ShareSingleGroupPptV2 共享单个ppt/取消共享单个ppt,返回共享状态
  1441. // @Author roc
  1442. // @Time 2022-08-29 15:22:20
  1443. func ShareSingleGroupPptV2(pptId int, adminId int) (pptInfo *models.PptV2, err error) {
  1444. //判断当前登录者是否有共享的权限
  1445. pptInfo, err = models.GetPptV2ById(pptId)
  1446. if err != nil {
  1447. if utils.IsErrNoRow(err) {
  1448. err = errors.New("当前目录下的ppt不存在")
  1449. return
  1450. }
  1451. err = errors.New("目录下的ppt查询出错:" + err.Error())
  1452. return
  1453. }
  1454. if pptInfo.AdminId != adminId {
  1455. err = errors.New("该Ppt不是本人创建")
  1456. return
  1457. }
  1458. //判断当前的共享状态
  1459. if pptInfo.IsShare > 0 {
  1460. pptInfo.IsShare = 0
  1461. err = pptInfo.Update([]string{"IsShare"})
  1462. if err != nil {
  1463. err = errors.New(err.Error())
  1464. return
  1465. }
  1466. } else {
  1467. pptInfo.IsShare = 1
  1468. err = pptInfo.Update([]string{"IsShare"})
  1469. if err != nil {
  1470. err = errors.New(err.Error())
  1471. return
  1472. }
  1473. }
  1474. return
  1475. }
  1476. // GetMyPptList 我的ppt列表
  1477. // @Author roc
  1478. // @Time 2022-09-05 17:26:21
  1479. func GetMyPptList(adminId int, keyword string) (ret models.RespGroupPptList, err error) {
  1480. list := make([]*models.RespGroupPptListItem, 0)
  1481. ret.List = list
  1482. var condition string
  1483. var pars []interface{}
  1484. condition += ` AND admin_id=? `
  1485. pars = append(pars, adminId)
  1486. if keyword != `` {
  1487. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1488. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1489. }
  1490. pptList, err := models.GetAllPptV2List(condition, pars)
  1491. if len(pptList) <= 0 {
  1492. return
  1493. }
  1494. var pptContent []services.PPTContent
  1495. for _, v := range pptList {
  1496. if v.PptPage == 0 && v.Content != "" {
  1497. err = json.Unmarshal([]byte(v.Content), &pptContent)
  1498. if err != nil {
  1499. return
  1500. }
  1501. v.PptPage = len(pptContent)
  1502. }
  1503. tmpV := &models.RespGroupPptListItem{
  1504. GroupPptId: int64(v.PptId),
  1505. PptId: int64(v.PptId),
  1506. TemplateType: v.TemplateType,
  1507. BackgroundImg: v.BackgroundImg,
  1508. Title: v.Title,
  1509. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1510. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1511. AdminId: v.AdminId,
  1512. AdminRealName: v.AdminRealName,
  1513. PptVersion: v.PptVersion,
  1514. IsSingleShare: v.IsShare,
  1515. PptxUrl: v.PptxUrl,
  1516. ReportId: v.ReportId,
  1517. ReportCode: v.ReportCode,
  1518. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1519. PptPage: v.PptPage,
  1520. }
  1521. list = append(list, tmpV)
  1522. }
  1523. ret.List = list
  1524. ret.Total = len(list)
  1525. return
  1526. }
  1527. // GetSharePptList 公共目录下的ppt列表
  1528. // @Author roc
  1529. // @Time 2022-08-29 16:27:59
  1530. func GetSharePptList(adminId int, keyword string, isPrivate bool) (ret models.RespGroupPptList, err error) {
  1531. list := make([]*models.RespGroupPptListItem, 0)
  1532. ret.List = list
  1533. var condition string
  1534. var pars []interface{}
  1535. // 公开的ppt
  1536. condition += ` AND is_share=? `
  1537. if isPrivate {
  1538. pars = append(pars, 0)
  1539. } else {
  1540. pars = append(pars, 1)
  1541. }
  1542. if adminId > 0 {
  1543. condition += ` AND admin_id=? `
  1544. pars = append(pars, adminId)
  1545. }
  1546. if keyword != `` {
  1547. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1548. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1549. }
  1550. pptList, err := models.GetAllPptV2List(condition, pars)
  1551. if len(pptList) <= 0 {
  1552. return
  1553. }
  1554. var pptContent []services.PPTContent
  1555. for _, v := range pptList {
  1556. if v.PptPage == 0 {
  1557. err = json.Unmarshal([]byte(v.Content), &pptContent)
  1558. if err != nil {
  1559. return
  1560. }
  1561. v.PptPage = len(pptContent)
  1562. }
  1563. tmpV := &models.RespGroupPptListItem{
  1564. GroupPptId: int64(v.PptId),
  1565. PptId: int64(v.PptId),
  1566. TemplateType: v.TemplateType,
  1567. BackgroundImg: v.BackgroundImg,
  1568. Title: v.Title,
  1569. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1570. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1571. AdminId: v.AdminId,
  1572. AdminRealName: v.AdminRealName,
  1573. PptVersion: v.PptVersion,
  1574. IsSingleShare: v.IsShare,
  1575. PptxUrl: v.PptxUrl,
  1576. ReportId: v.ReportId,
  1577. ReportCode: v.ReportCode,
  1578. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1579. PptPage: v.PptPage,
  1580. }
  1581. list = append(list, tmpV)
  1582. }
  1583. ret.List = list
  1584. ret.Total = len(list)
  1585. return
  1586. }
  1587. // GetGrantPptList 公共目录下的ppt列表
  1588. // @Author roc
  1589. // @Time 2022-09-05 15:50:25
  1590. func GetGrantPptList(adminId int, keyword, sourceType string) (ret models.RespGroupPptList, err error) {
  1591. list := make([]*models.RespGroupPptListItem, 0)
  1592. ret.List = list
  1593. var condition string
  1594. var pars []interface{}
  1595. switch sourceType {
  1596. case "my":
  1597. condition += ` AND a.admin_id = ? `
  1598. pars = append(pars, adminId)
  1599. case "other":
  1600. condition += ` AND a.admin_id != ? AND (b.department_id = 1 OR b.grant_admin_id = ?) `
  1601. pars = append(pars, adminId, adminId)
  1602. default:
  1603. err = errors.New("无效的来源")
  1604. return
  1605. }
  1606. if keyword != `` {
  1607. condition += ` AND a.title LIKE ? `
  1608. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  1609. }
  1610. pptList, err := models.GetGrantList(condition, pars)
  1611. if err != nil {
  1612. return
  1613. }
  1614. if len(pptList) <= 0 {
  1615. return
  1616. }
  1617. var pptContent []services.PPTContent
  1618. for _, v := range pptList {
  1619. if v.PptPage == 0 {
  1620. err = json.Unmarshal([]byte(v.Content), &pptContent)
  1621. if err != nil {
  1622. return
  1623. }
  1624. v.PptPage = len(pptContent)
  1625. }
  1626. tmpV := &models.RespGroupPptListItem{
  1627. GroupPptId: int64(v.PptId),
  1628. PptId: int64(v.PptId),
  1629. TemplateType: v.TemplateType,
  1630. BackgroundImg: v.BackgroundImg,
  1631. Title: v.Title,
  1632. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1633. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1634. AdminId: v.AdminId,
  1635. AdminRealName: v.AdminRealName,
  1636. PptVersion: v.PptVersion,
  1637. IsSingleShare: v.IsShare,
  1638. PptxUrl: v.PptxUrl,
  1639. ReportId: v.ReportId,
  1640. ReportCode: v.ReportCode,
  1641. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1642. PptPage: v.PptPage,
  1643. }
  1644. list = append(list, tmpV)
  1645. }
  1646. ret.List = list
  1647. ret.Total = len(list)
  1648. return
  1649. }
  1650. // SearchPptList PPT搜索(我的/公开PPT)
  1651. func SearchPptList(adminId int, keyword string) (ret models.RespGroupPptList, err error) {
  1652. list := make([]*models.RespGroupPptListItem, 0)
  1653. ret.List = list
  1654. var condition string
  1655. var pars []interface{}
  1656. // 公开的PPT或是我的非公开PPT
  1657. condition += ` AND (is_share = 1 OR (admin_id = ? AND is_share = 0)) `
  1658. pars = append(pars, adminId)
  1659. if keyword != `` {
  1660. kw := fmt.Sprint("%", keyword, "%")
  1661. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1662. pars = append(pars, kw, kw)
  1663. }
  1664. pptList, err := models.GetAllPptV2List(condition, pars)
  1665. if len(pptList) <= 0 {
  1666. return
  1667. }
  1668. var pptContent []services.PPTContent
  1669. for _, v := range pptList {
  1670. if v.PptPage == 0 {
  1671. err = json.Unmarshal([]byte(v.Content), &pptContent)
  1672. if err != nil {
  1673. return
  1674. }
  1675. v.PptPage = len(pptContent)
  1676. }
  1677. tmpV := &models.RespGroupPptListItem{
  1678. GroupPptId: int64(v.PptId),
  1679. PptId: int64(v.PptId),
  1680. TemplateType: v.TemplateType,
  1681. BackgroundImg: v.BackgroundImg,
  1682. Title: v.Title,
  1683. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1684. AdminId: v.AdminId,
  1685. AdminRealName: v.AdminRealName,
  1686. PptVersion: v.PptVersion,
  1687. IsSingleShare: v.IsShare,
  1688. PptxUrl: v.PptxUrl,
  1689. ReportId: v.ReportId,
  1690. ReportCode: v.ReportCode,
  1691. PptPage: v.PptPage,
  1692. }
  1693. list = append(list, tmpV)
  1694. }
  1695. ret.List = list
  1696. ret.Total = len(list)
  1697. return
  1698. }