ppt_group.go 49 KB

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