ppt_group.go 47 KB

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