ppt_group.go 48 KB

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