ppt_group.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  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. PptUrl: v.PptUrl,
  360. PptxUrl: v.PptxUrl,
  361. CreateTime: time.Now(),
  362. ModifyTime: time.Now(),
  363. AdminId: adminId,
  364. AdminRealName: adminRealName,
  365. PptVersion: v.PptVersion,
  366. }
  367. newPptList = append(newPptList, tmp)
  368. }
  369. if len(newPptList) > 0 {
  370. err = models.AddPptV2Multi(newPptList)
  371. if err != nil {
  372. err = errors.New("复制目录里的ppt出错:" + err.Error())
  373. return
  374. }
  375. newMappings := make([]*models.PptV2GroupMapping, 0)
  376. for _, v := range newPptList {
  377. tmp := &models.PptV2GroupMapping{
  378. GroupId: newGroupId,
  379. PptId: int64(v.PptId),
  380. CreateTime: time.Now(),
  381. ModifyTime: time.Now(),
  382. AdminId: adminId,
  383. AdminRealName: adminRealName,
  384. }
  385. newMappings = append(newMappings, tmp)
  386. }
  387. err = models.AddPptGroupMappingMulti(newMappings)
  388. if err != nil {
  389. err = errors.New("复制目录里的ppt出错:" + err.Error())
  390. return
  391. }
  392. //批量更新排序字段
  393. var newGroupPptIds []int64
  394. for _, v := range newMappings {
  395. newGroupPptIds = append(newGroupPptIds, v.GroupPptId)
  396. }
  397. err = models.UpdatePptGroupMappingSortMulti(newGroupPptIds)
  398. if err != nil {
  399. err = errors.New("更新排序标识出错:" + err.Error())
  400. return
  401. }
  402. }
  403. return
  404. }
  405. // RenameGroupName 目录重命名
  406. func RenameGroupName(groupId int64, groupName string, adminId int) (err error) {
  407. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  408. if err != nil {
  409. if err.Error() == utils.ErrNoRow() {
  410. err = errors.New("目录不存在")
  411. return
  412. }
  413. err = errors.New("目录查询出错:" + err.Error())
  414. return
  415. }
  416. if groupInfo.GroupName == groupName {
  417. err = errors.New("与原名字一致,无需修改")
  418. return
  419. }
  420. item, err := models.GetPptGroupByName(groupName, adminId)
  421. if err != nil && err.Error() != utils.ErrNoRow() {
  422. err = errors.New("目录查询出错:" + err.Error())
  423. return
  424. }
  425. if item != nil {
  426. err = errors.New("目录名称已存在,不可重复添加")
  427. return
  428. }
  429. //更新新名字
  430. groupInfo.GroupName = groupName
  431. err = groupInfo.Update([]string{"group_name"})
  432. if err != nil {
  433. err = errors.New("目录重命名失败" + err.Error())
  434. return
  435. }
  436. return
  437. }
  438. // ShareSingleGroupPpt 共享单个ppt/取消共享单个ppt,返回共享状态
  439. func ShareSingleGroupPpt(groupPptId int64, adminId int, adminRealName string) (ret models.RespPptShare, err error) {
  440. //判断当前登录者是否有共享的权限
  441. groupPpt, err := models.GetPptMappingByGroupPptId(groupPptId, adminId)
  442. if err != nil {
  443. if err.Error() == utils.ErrNoRow() {
  444. err = errors.New("当前目录下的ppt不存在")
  445. return
  446. }
  447. err = errors.New("目录下的ppt查询出错:" + err.Error())
  448. return
  449. }
  450. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupPpt.GroupId, adminId)
  451. if err != nil {
  452. if err.Error() == utils.ErrNoRow() {
  453. err = errors.New("目录不存在")
  454. return
  455. }
  456. err = errors.New("目录查询出错:" + err.Error())
  457. return
  458. }
  459. //判断当前的共享状态
  460. if groupPpt.ChildGroupPptId > 0 {
  461. err = CancelShareSingleGroupPpt(groupPpt, adminId)
  462. if err != nil {
  463. err = errors.New(err.Error())
  464. return
  465. }
  466. ret.IsSingleShare = 0
  467. } else {
  468. //如果是未共享状态,则共享该ppt,类似复制流程,并更新共享标识
  469. //新增公共目录。目录名称在原来的基础上带上复制序号
  470. groupNames, tErr := models.GetPptGroupNamesByAdminId(adminId)
  471. if tErr != nil {
  472. err = errors.New("目录查询出错:" + tErr.Error())
  473. return
  474. }
  475. newGroupName := generateCopyName(groupInfo.GroupName, 1, groupNames)
  476. newGroupId, tErr := AddGroup(newGroupName, adminId, 1, 1)
  477. if tErr != nil {
  478. err = errors.New(tErr.Error())
  479. return
  480. }
  481. //新增公共的目录和ppt之间的映射关系
  482. newGroupPptId, tErr := AddGroupPptMapping(groupPpt.PptId, newGroupId, adminId, adminRealName)
  483. if tErr != nil {
  484. err = errors.New(tErr.Error())
  485. return
  486. }
  487. //更新共享标识
  488. groupPpt.ChildGroupPptId = newGroupPptId
  489. err = groupPpt.Update([]string{"child_group_ppt_id"})
  490. if err != nil {
  491. err = errors.New("更新共享标识失败" + err.Error())
  492. return
  493. }
  494. ret.IsSingleShare = 1
  495. }
  496. ret.GroupPptId = groupPptId
  497. return
  498. }
  499. // GetGroupPptList 公共目录下的ppt列表或者单个目录里的ppt列表
  500. func GetGroupPptList(groupId int64, adminId int) (ret models.RespGroupPptList, err error) {
  501. var groupPptList []*models.PptV2GroupMapping
  502. var groups []*models.PptV2Group
  503. list := make([]*models.RespGroupPptListItem, 0)
  504. ret.List = list
  505. if groupId > 0 {
  506. //只查询组内的ppt列表
  507. //查询目录是否存在
  508. groupInfo, tErr := models.GetPptGroupByGroupId(groupId)
  509. if tErr != nil {
  510. if tErr.Error() == utils.ErrNoRow() {
  511. err = errors.New("目录不存在")
  512. return
  513. }
  514. err = errors.New("目录查询出错:" + tErr.Error())
  515. return
  516. }
  517. groups = append(groups, groupInfo)
  518. groupPptList, tErr = models.GetPptMappingListByGroupId(groupId)
  519. if tErr != nil {
  520. err = errors.New("目录里的ppt查询出错:" + tErr.Error())
  521. return
  522. }
  523. } else {
  524. // 获取我的所有的ppt
  525. ret, err = GetMyPptList(adminId, ``)
  526. return
  527. ////查询所有公共目录下的ppt列表
  528. //var tErr error
  529. //groups, tErr = models.GetPublicPptGroups()
  530. //if tErr != nil {
  531. // err = errors.New("目录查询出错:" + tErr.Error())
  532. // return
  533. //}
  534. ////查询这些目录下的所有ppt
  535. //groupIds := make([]int64, 0)
  536. //for _, v := range groups {
  537. // groupIds = append(groupIds, v.GroupId)
  538. //}
  539. //
  540. //groupPptList, tErr = models.GetPptMappingListByGroupIds(groupIds)
  541. //if tErr != nil {
  542. // err = errors.New("目录里的ppt查询出错:" + tErr.Error())
  543. // return
  544. //}
  545. }
  546. if len(groupPptList) <= 0 {
  547. return
  548. }
  549. pptMap := make(map[int]*models.PptV2)
  550. groupMap := make(map[int64][]*models.PptV2GroupMapping)
  551. pptIds := make([]int, 0)
  552. for _, v := range groupPptList {
  553. pptIds = append(pptIds, int(v.PptId))
  554. groupMap[v.GroupId] = append(groupMap[v.GroupId], v)
  555. }
  556. if len(pptIds) == 0 {
  557. // 返回所有空目录
  558. return
  559. }
  560. pptList, err := models.GetPptV2ByIds(pptIds)
  561. if err != nil {
  562. err = errors.New("查询ppt详情出错:" + err.Error())
  563. return
  564. }
  565. for _, v := range pptList {
  566. pptMap[v.PptId] = v
  567. }
  568. //按照排序顺序,依次放入ppt
  569. hasPpt := make(map[int]struct{})
  570. for _, v := range groups {
  571. if mapList, ok := groupMap[v.GroupId]; ok {
  572. if len(mapList) > 0 {
  573. for _, pptV := range mapList {
  574. pptInfo, ok1 := pptMap[int(pptV.PptId)]
  575. _, ok2 := hasPpt[int(pptV.PptId)]
  576. if ok1 && !ok2 {
  577. tmp := &models.RespGroupPptListItem{
  578. GroupPptId: pptV.GroupPptId,
  579. PptId: pptV.PptId,
  580. TemplateType: pptInfo.TemplateType,
  581. BackgroundImg: pptInfo.BackgroundImg,
  582. Title: pptInfo.Title,
  583. AdminId: pptV.AdminId,
  584. AdminRealName: pptV.AdminRealName,
  585. IsSingleShare: 0,
  586. PptCreateTime: pptInfo.CreateTime.Format(utils.FormatDateTime),
  587. PptModifyTime: pptInfo.ModifyTime.Format(utils.FormatDateTime),
  588. PptxUrl: pptInfo.PptxUrl,
  589. PptVersion: pptInfo.PptVersion,
  590. ReportId: pptInfo.ReportId,
  591. ReportCode: pptInfo.ReportCode,
  592. PublishTime: utils.DealDateTimeZero(pptInfo.PublishTime, utils.FormatDateTime),
  593. }
  594. if pptV.ChildGroupPptId > 0 {
  595. tmp.IsSingleShare = 1
  596. }
  597. list = append(list, tmp)
  598. hasPpt[pptInfo.PptId] = struct{}{}
  599. }
  600. }
  601. }
  602. }
  603. }
  604. ret.List = list
  605. if groupId <= 0 {
  606. sort.Sort(ret)
  607. }
  608. ret.Total = len(list)
  609. return
  610. }
  611. // MoveGroupPpt 移动ppt操作
  612. func MoveGroupPpt(groupId, groupPptId, prevGroupPptId, nextGroupPptId int64, adminId int) (err error) {
  613. //查询当前映射是否存在
  614. //判断当前登录者是否有共享的权限oo
  615. groupPpt, err := models.GetPptMappingByGroupPptId(groupPptId, adminId)
  616. if err != nil {
  617. if err.Error() == utils.ErrNoRow() {
  618. err = errors.New("当前目录下的ppt不存在")
  619. return
  620. }
  621. err = errors.New("目录下的ppt查询出错:" + err.Error())
  622. return
  623. }
  624. var updateStr []string
  625. //如果更换了目录,默认当前排序值为0
  626. var currentSort, prevSort, nextSort int64
  627. //判断是否更换group
  628. if groupPpt.GroupId != groupId {
  629. _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  630. if err != nil {
  631. if err.Error() == utils.ErrNoRow() {
  632. err = errors.New("目录不存在")
  633. return
  634. }
  635. err = errors.New("目录查询出错:" + err.Error())
  636. return
  637. }
  638. //判断是否需要解除当个ppt共享
  639. //解除共享操作
  640. err = CancelShareSingleGroupPpt(groupPpt, adminId)
  641. if err != nil {
  642. err = errors.New(err.Error())
  643. return
  644. }
  645. groupPpt.GroupId = groupId
  646. updateStr = append(updateStr, "group_id")
  647. }
  648. currentSort = groupPpt.PptSort
  649. var prevGroupPpt *models.PptV2GroupMapping
  650. var nextGroupPpt *models.PptV2GroupMapping
  651. if prevGroupPptId > 0 {
  652. prevGroupPpt, err = models.GetPptMappingByGroupPptId(prevGroupPptId, adminId)
  653. if err != nil {
  654. if err.Error() == utils.ErrNoRow() {
  655. err = errors.New("目录下的ppt不存在")
  656. return
  657. }
  658. err = errors.New("目录下的ppt查询出错:" + err.Error())
  659. return
  660. }
  661. prevSort = prevGroupPpt.PptSort
  662. }
  663. if nextGroupPptId > 0 {
  664. nextGroupPpt, err = models.GetPptMappingByGroupPptId(nextGroupPptId, adminId)
  665. if err != nil {
  666. if err.Error() == utils.ErrNoRow() {
  667. err = errors.New("目录下的ppt不存在")
  668. return
  669. }
  670. err = errors.New("目录下的ppt查询出错:" + err.Error())
  671. return
  672. }
  673. nextSort = nextGroupPpt.PptSort
  674. }
  675. updateStr = append(updateStr, "ppt_sort")
  676. //移到两个排序值中间操作
  677. if prevSort >= currentSort {
  678. //往下移动
  679. err = models.MoveDownGroupPptBySort(groupId, prevSort, currentSort)
  680. if err != nil {
  681. err = errors.New("向下移动ppt出错:" + err.Error())
  682. return
  683. }
  684. groupPpt.PptSort = prevSort
  685. } else if nextSort <= currentSort && nextSort != 0 {
  686. //往上移动
  687. err = models.MoveUpGroupPptBySort(groupId, nextSort, currentSort)
  688. if err != nil {
  689. err = errors.New("向上移动ppt出错:" + err.Error())
  690. return
  691. }
  692. groupPpt.PptSort = nextSort
  693. }
  694. //更新当前排序
  695. err = groupPpt.Update(updateStr)
  696. if err != nil {
  697. err = errors.New("移动ppt出错:" + err.Error())
  698. return
  699. }
  700. return
  701. }
  702. // MoveGroup 移动目录
  703. func MoveGroup(groupId, prevGroupId, nextGroupId int64, adminId int) (err error) {
  704. //查询目录是否存在
  705. groupInfo, err := models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  706. if err != nil {
  707. if err.Error() == utils.ErrNoRow() {
  708. err = errors.New("目录不存在")
  709. return
  710. }
  711. err = errors.New("目录查询出错:" + err.Error())
  712. return
  713. }
  714. //如果更换了目录,默认当前排序值为0
  715. var currentSort, prevSort, nextSort int64
  716. currentSort = groupInfo.GroupSort
  717. var prevGroup *models.PptV2Group
  718. var nextGroup *models.PptV2Group
  719. if prevGroupId > 0 {
  720. prevGroup, err = models.GetPptGroupByGroupIdAdminId(prevGroupId, adminId)
  721. if err != nil {
  722. if err.Error() == utils.ErrNoRow() {
  723. err = errors.New("目录不存在")
  724. return
  725. }
  726. err = errors.New("目录查询出错:" + err.Error())
  727. return
  728. }
  729. prevSort = prevGroup.GroupSort
  730. }
  731. if nextGroupId > 0 {
  732. nextGroup, err = models.GetPptGroupByGroupIdAdminId(nextGroupId, adminId)
  733. if err != nil {
  734. if err.Error() == utils.ErrNoRow() {
  735. err = errors.New("目录不存在")
  736. return
  737. }
  738. err = errors.New("目录查询出错:" + err.Error())
  739. return
  740. }
  741. nextSort = nextGroup.GroupSort
  742. }
  743. //移到两个排序值中间操作
  744. if prevSort >= currentSort {
  745. //往下移动
  746. err = models.MoveDownGroupBySort(prevSort, currentSort)
  747. if err != nil {
  748. err = errors.New("向下移动ppt出错:" + err.Error())
  749. return
  750. }
  751. groupInfo.GroupSort = prevSort
  752. } else if nextSort <= currentSort && nextSort != 0 {
  753. //往上移动
  754. err = models.MoveUpGroupBySort(nextSort, currentSort)
  755. if err != nil {
  756. err = errors.New("向上移动ppt出错:" + err.Error())
  757. return
  758. }
  759. groupInfo.GroupSort = nextSort
  760. }
  761. //更新当前排序
  762. err = groupInfo.Update([]string{"group_sort"})
  763. if err != nil {
  764. err = errors.New("移动目录出错:" + err.Error())
  765. return
  766. }
  767. return
  768. }
  769. // CancelShareSingleGroupPpt 解除单个共享的ppt
  770. func CancelShareSingleGroupPpt(groupPpt *models.PptV2GroupMapping, adminId int) (err error) {
  771. if groupPpt.ChildGroupPptId <= 0 {
  772. return
  773. }
  774. //如果已经是共享状态,
  775. //判断当前登录者是否有取消共享的权限
  776. childGroupPpt, tErr := models.GetPptMappingByGroupPptId(groupPpt.ChildGroupPptId, adminId)
  777. if tErr != nil {
  778. if tErr.Error() != utils.ErrNoRow() {
  779. err = errors.New("目录下的ppt查询出错:" + tErr.Error())
  780. return
  781. }
  782. }
  783. if childGroupPpt != nil {
  784. //删除共享目录和ppt的映射关系
  785. err = models.DeletePptGroupMapping(childGroupPpt.GroupPptId, adminId)
  786. if err != nil {
  787. err = errors.New("删除共享目录下的ppt失败:" + err.Error())
  788. return
  789. }
  790. //删除共享出去的公共目录
  791. err = models.DeletePptGroup(childGroupPpt.GroupId)
  792. if err != nil {
  793. err = errors.New("删除共享目录失败:" + err.Error())
  794. return
  795. }
  796. }
  797. //更新共享状态为未共享,
  798. //更新共享标识
  799. groupPpt.ChildGroupPptId = 0
  800. err = groupPpt.Update([]string{"child_group_ppt_id"})
  801. if err != nil {
  802. err = errors.New("更新共享标识失败" + err.Error())
  803. return
  804. }
  805. return
  806. }
  807. // DeleteGroupPpt 删除ppt
  808. func DeleteGroupPpt(PptId int) (err error) {
  809. //查询该ppt的所有单个共享出去的目录信息
  810. groupPpts, err := models.GetGroupPptByPptId(PptId)
  811. if err != nil {
  812. err = errors.New("查询目录里的ppt失败" + err.Error())
  813. return
  814. }
  815. if len(groupPpts) <= 0 {
  816. return
  817. }
  818. //整理出需要删除的groupId
  819. groupPptMap := make(map[int64]*models.PptV2GroupMapping)
  820. for _, v := range groupPpts {
  821. groupPptMap[v.GroupPptId] = v
  822. }
  823. var delGroupIds string
  824. for _, v := range groupPpts {
  825. if v.ChildGroupPptId > 0 {
  826. if childGroup, ok := groupPptMap[v.ChildGroupPptId]; ok {
  827. delGroupIds += strconv.Itoa(int(childGroup.GroupId)) + ","
  828. }
  829. }
  830. }
  831. if delGroupIds != "" {
  832. delGroupIds = "(" + strings.Trim(delGroupIds, ",") + ")"
  833. err = models.DeletePptGroupByGroupIds(delGroupIds)
  834. if err != nil {
  835. err = errors.New("删除单个共享目录失败" + err.Error())
  836. return
  837. }
  838. }
  839. //再统一删除目录里相关的ppt
  840. err = models.DeletePptGroupMappingByPptId(PptId)
  841. if err != nil {
  842. err = errors.New("删除目录里的ppt失败" + err.Error())
  843. return
  844. }
  845. return
  846. }
  847. // CopyPpt 复制单个ppt,并移动到新的目录下面
  848. func CopyPpt(pptId int, groupId int64, adminId int, adminRealName string) (resp models.RespGroupPptNameListItem, err error) {
  849. //查询ppt详情
  850. pptInfo, err := models.GetPptV2ById(pptId)
  851. if err != nil {
  852. if err.Error() == utils.ErrNoRow() {
  853. err = errors.New("ppt 不存在")
  854. return
  855. }
  856. err = errors.New("查询ppt失败" + err.Error())
  857. return
  858. }
  859. if pptInfo.PptVersion == 1 {
  860. err = errors.New("旧版本的ppt不允许复制")
  861. return
  862. }
  863. // 查询目录是否存在
  864. _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
  865. if err != nil {
  866. if err.Error() == utils.ErrNoRow() {
  867. err = errors.New("目录不存在")
  868. return
  869. }
  870. err = errors.New("目录查询出错:" + err.Error())
  871. return
  872. }
  873. pptNames, err := models.GetAllPptTitle()
  874. if err != nil {
  875. err = errors.New("查询ppt标题出错:" + err.Error())
  876. return
  877. }
  878. //复制ppt,更新作者为当前账号,并返回新的pptID
  879. var newPptList []*models.PptV2
  880. newPpt := &models.PptV2{
  881. TemplateType: pptInfo.TemplateType,
  882. BackgroundImg: pptInfo.BackgroundImg,
  883. Title: generateCopyName(pptInfo.Title, 1, pptNames),
  884. ReportType: pptInfo.ReportType,
  885. PptDate: pptInfo.PptDate,
  886. Content: pptInfo.Content,
  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. PptModifyTime: i.ModifyTime.Format(utils.FormatDateTime),
  1238. PublishTime: utils.DealDateTimeZero(i.PublishTime, utils.FormatDateTime),
  1239. PptPage: pptPage,
  1240. }
  1241. if tmp.PptVersion == 2 {
  1242. groupHasNewPptMap[v.GroupId] = struct{}{}
  1243. }
  1244. groupMap[v.GroupId] = append(groupMap[v.GroupId], tmp)
  1245. }
  1246. for k, v := range ret.PrivateList {
  1247. if pptL, ok := groupMap[v.GroupId]; ok {
  1248. ret.PrivateList[k].PptList = pptL
  1249. if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
  1250. ret.PrivateList[k].OnlyOld = true
  1251. }
  1252. }
  1253. }
  1254. }
  1255. publicAdminIdList := make([]int, 0)
  1256. publicPptListMap := make(map[int][]*models.RespGroupPptNameListItem)
  1257. // 获取公开分享的ppt
  1258. sharePptList, err := models.GetSharePptV2(IsNewPpt)
  1259. for _, v := range sharePptList {
  1260. publicPptList, ok := publicPptListMap[v.AdminId]
  1261. if !ok {
  1262. publicPptList = make([]*models.RespGroupPptNameListItem, 0)
  1263. publicAdminIdList = append(publicAdminIdList, v.AdminId)
  1264. // 需要查询的创建人信息
  1265. if _, ok := adminIdMap[v.AdminId]; !ok {
  1266. adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
  1267. adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  1268. }
  1269. }
  1270. contents := make([]PageContent, 0)
  1271. if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
  1272. err = errors.New("解析PPT内容页数失败: " + e.Error())
  1273. return
  1274. }
  1275. pptPage := len(contents)
  1276. tmpV := &models.RespGroupPptNameListItem{
  1277. GroupPptId: int64(v.PptId),
  1278. PptId: int64(v.PptId),
  1279. Title: v.Title,
  1280. AdminId: v.AdminId,
  1281. AdminRealName: v.AdminRealName,
  1282. PptVersion: v.PptVersion,
  1283. IsSingleShare: v.IsShare,
  1284. PptxUrl: v.PptxUrl,
  1285. ReportId: v.ReportId,
  1286. ReportCode: v.ReportCode,
  1287. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1288. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1289. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1290. PptPage: pptPage,
  1291. }
  1292. publicPptList = append(publicPptList, tmpV)
  1293. publicPptListMap[v.AdminId] = publicPptList
  1294. }
  1295. // 创建人信息
  1296. systemAdminMap := make(map[int]*system.Admin)
  1297. systemAdminList, err := system.GetAdminListByIdList(adminIdList)
  1298. if err != nil {
  1299. return
  1300. }
  1301. for _, v := range systemAdminList {
  1302. systemAdminMap[v.AdminId] = v
  1303. }
  1304. // 公开分享的用户列表
  1305. {
  1306. for _, v := range publicAdminIdList {
  1307. systemAdmin, ok := systemAdminMap[v]
  1308. if !ok {
  1309. continue
  1310. }
  1311. // ppt 列表信息
  1312. respGroupPptNameListItemList, ok := publicPptListMap[v]
  1313. if !ok {
  1314. respGroupPptNameListItemList = make([]*models.RespGroupPptNameListItem, 0)
  1315. }
  1316. // ppt 分组信息
  1317. tmpRespGroupListItem := &models.RespGroupListItem{
  1318. GroupId: int64(systemAdmin.AdminId),
  1319. GroupName: systemAdmin.RealName + "的PPT",
  1320. AdminId: systemAdmin.AdminId,
  1321. IsShare: 1,
  1322. OnlyOld: false,
  1323. PptList: respGroupPptNameListItemList,
  1324. }
  1325. ret.PublicList = append(ret.PublicList, tmpRespGroupListItem)
  1326. }
  1327. }
  1328. myGrantPPtIdMap := make(map[int]int) //我分配的ppt的id集合
  1329. // 共享Ppt
  1330. {
  1331. for _, v := range grantPptList {
  1332. pptPage := 0
  1333. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  1334. if v.Content != "" {
  1335. contents := make([]PageContent, 0)
  1336. if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
  1337. err = errors.New("解析PPT内容页数失败: " + e.Error())
  1338. return
  1339. }
  1340. }
  1341. title := v.Title
  1342. if adminInfo, ok := systemAdminMap[v.AdminId]; ok {
  1343. title = adminInfo.RealName + "———" + title
  1344. }
  1345. tmp := &models.RespGroupPptNameListItem{
  1346. AdminId: v.AdminId,
  1347. //GroupPptId: v.GroupPptId,
  1348. PptId: int64(v.PptId),
  1349. AdminRealName: v.AdminRealName,
  1350. Title: title,
  1351. PptVersion: v.PptVersion,
  1352. IsSingleShare: v.IsShare,
  1353. PptxUrl: v.PptxUrl,
  1354. ReportId: v.ReportId,
  1355. ReportCode: v.ReportCode,
  1356. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1357. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1358. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1359. PptPage: pptPage,
  1360. }
  1361. //如果只展示新版ppt,则过滤旧版的Ppt
  1362. if IsNewPpt == 1 && v.PptVersion == 1 {
  1363. continue
  1364. }
  1365. if v.AdminId == adminId {
  1366. tmp.IsGrant = 1
  1367. myPptList = append(myPptList, tmp)
  1368. myGrantPPtIdMap[v.PptId] = v.PptId
  1369. } else {
  1370. tmp.IsReceived = 1
  1371. otherPptList = append(otherPptList, tmp)
  1372. }
  1373. }
  1374. grantList[0].PptList = myPptList
  1375. grantList[1].PptList = otherPptList
  1376. ret.GrantList = grantList
  1377. }
  1378. // 处理公共ppt里面的关于自个的ppt是否有配置权限的字段数据变更
  1379. for k, publicList := range ret.PublicList {
  1380. for kk, pptInfo := range publicList.PptList {
  1381. // 是否有过权限配置
  1382. if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
  1383. pptInfo.IsGrant = 1
  1384. }
  1385. publicList.PptList[kk] = pptInfo
  1386. }
  1387. ret.PublicList[k] = publicList
  1388. }
  1389. for k, privateList := range ret.PrivateList {
  1390. for kk, pptInfo := range privateList.PptList {
  1391. // 是否有过权限配置
  1392. if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
  1393. pptInfo.IsGrant = 1
  1394. }
  1395. privateList.PptList[kk] = pptInfo
  1396. }
  1397. ret.PrivateList[k] = privateList
  1398. }
  1399. //如果只展示新版ppt,则过滤空文件夹
  1400. if IsNewPpt == 1 {
  1401. //公共ppt
  1402. pubList := make([]*models.RespGroupListItem, 0)
  1403. for _, v := range ret.PublicList {
  1404. if len(v.PptList) > 0 {
  1405. pubList = append(pubList, v)
  1406. }
  1407. }
  1408. ret.PublicList = pubList
  1409. // 私有ppt
  1410. priList := make([]*models.RespGroupListItem, 0)
  1411. for _, v := range ret.PrivateList {
  1412. if len(v.PptList) > 0 {
  1413. priList = append(priList, v)
  1414. }
  1415. }
  1416. ret.PrivateList = priList
  1417. }
  1418. return
  1419. }
  1420. // ShareSingleGroupPptV2 共享单个ppt/取消共享单个ppt,返回共享状态
  1421. // @Author roc
  1422. // @Time 2022-08-29 15:22:20
  1423. func ShareSingleGroupPptV2(pptId int, adminId int) (pptInfo *models.PptV2, err error) {
  1424. //判断当前登录者是否有共享的权限
  1425. pptInfo, err = models.GetPptV2ById(pptId)
  1426. if err != nil {
  1427. if err.Error() == utils.ErrNoRow() {
  1428. err = errors.New("当前目录下的ppt不存在")
  1429. return
  1430. }
  1431. err = errors.New("目录下的ppt查询出错:" + err.Error())
  1432. return
  1433. }
  1434. if pptInfo.AdminId != adminId {
  1435. err = errors.New("该Ppt不是本人创建")
  1436. return
  1437. }
  1438. //判断当前的共享状态
  1439. if pptInfo.IsShare > 0 {
  1440. pptInfo.IsShare = 0
  1441. err = pptInfo.Update([]string{"IsShare"})
  1442. if err != nil {
  1443. err = errors.New(err.Error())
  1444. return
  1445. }
  1446. } else {
  1447. pptInfo.IsShare = 1
  1448. err = pptInfo.Update([]string{"IsShare"})
  1449. if err != nil {
  1450. err = errors.New(err.Error())
  1451. return
  1452. }
  1453. }
  1454. return
  1455. }
  1456. // GetMyPptList 我的ppt列表
  1457. // @Author roc
  1458. // @Time 2022-09-05 17:26:21
  1459. func GetMyPptList(adminId int, keyword string) (ret models.RespGroupPptList, err error) {
  1460. list := make([]*models.RespGroupPptListItem, 0)
  1461. ret.List = list
  1462. var condition string
  1463. var pars []interface{}
  1464. condition += ` AND admin_id=? `
  1465. pars = append(pars, adminId)
  1466. if keyword != `` {
  1467. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1468. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1469. }
  1470. pptList, err := models.GetAllPptV2List(condition, pars)
  1471. if len(pptList) <= 0 {
  1472. return
  1473. }
  1474. for _, v := range pptList {
  1475. tmpV := &models.RespGroupPptListItem{
  1476. GroupPptId: int64(v.PptId),
  1477. PptId: int64(v.PptId),
  1478. TemplateType: v.TemplateType,
  1479. BackgroundImg: v.BackgroundImg,
  1480. Title: v.Title,
  1481. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1482. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1483. AdminId: v.AdminId,
  1484. AdminRealName: v.AdminRealName,
  1485. PptVersion: v.PptVersion,
  1486. IsSingleShare: v.IsShare,
  1487. PptxUrl: v.PptxUrl,
  1488. ReportId: v.ReportId,
  1489. ReportCode: v.ReportCode,
  1490. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1491. }
  1492. list = append(list, tmpV)
  1493. }
  1494. ret.List = list
  1495. ret.Total = len(list)
  1496. return
  1497. }
  1498. // GetSharePptList 公共目录下的ppt列表
  1499. // @Author roc
  1500. // @Time 2022-08-29 16:27:59
  1501. func GetSharePptList(adminId int, keyword string, isPrivate bool) (ret models.RespGroupPptList, err error) {
  1502. list := make([]*models.RespGroupPptListItem, 0)
  1503. ret.List = list
  1504. var condition string
  1505. var pars []interface{}
  1506. // 公开的ppt
  1507. condition += ` AND is_share=? `
  1508. if isPrivate {
  1509. pars = append(pars, 0)
  1510. } else {
  1511. pars = append(pars, 1)
  1512. }
  1513. if adminId > 0 {
  1514. condition += ` AND admin_id=? `
  1515. pars = append(pars, adminId)
  1516. }
  1517. if keyword != `` {
  1518. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1519. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1520. }
  1521. pptList, err := models.GetAllPptV2List(condition, pars)
  1522. if len(pptList) <= 0 {
  1523. return
  1524. }
  1525. for _, v := range pptList {
  1526. tmpV := &models.RespGroupPptListItem{
  1527. GroupPptId: int64(v.PptId),
  1528. PptId: int64(v.PptId),
  1529. TemplateType: v.TemplateType,
  1530. BackgroundImg: v.BackgroundImg,
  1531. Title: v.Title,
  1532. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1533. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1534. AdminId: v.AdminId,
  1535. AdminRealName: v.AdminRealName,
  1536. PptVersion: v.PptVersion,
  1537. IsSingleShare: v.IsShare,
  1538. PptxUrl: v.PptxUrl,
  1539. ReportId: v.ReportId,
  1540. ReportCode: v.ReportCode,
  1541. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1542. }
  1543. list = append(list, tmpV)
  1544. }
  1545. ret.List = list
  1546. ret.Total = len(list)
  1547. return
  1548. }
  1549. // GetGrantPptList 公共目录下的ppt列表
  1550. // @Author roc
  1551. // @Time 2022-09-05 15:50:25
  1552. func GetGrantPptList(adminId int, keyword, sourceType string) (ret models.RespGroupPptList, err error) {
  1553. list := make([]*models.RespGroupPptListItem, 0)
  1554. ret.List = list
  1555. var condition string
  1556. var pars []interface{}
  1557. switch sourceType {
  1558. case "my":
  1559. condition += ` AND a.admin_id = ? `
  1560. pars = append(pars, adminId)
  1561. case "other":
  1562. condition += ` AND a.admin_id != ? AND (b.department_id = 1 OR b.grant_admin_id = ?) `
  1563. pars = append(pars, adminId, adminId)
  1564. default:
  1565. err = errors.New("无效的来源")
  1566. return
  1567. }
  1568. if keyword != `` {
  1569. condition += ` AND a.title LIKE ? `
  1570. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  1571. }
  1572. pptList, err := models.GetGrantList(condition, pars)
  1573. if err != nil {
  1574. return
  1575. }
  1576. if len(pptList) <= 0 {
  1577. return
  1578. }
  1579. for _, v := range pptList {
  1580. tmpV := &models.RespGroupPptListItem{
  1581. GroupPptId: int64(v.PptId),
  1582. PptId: int64(v.PptId),
  1583. TemplateType: v.TemplateType,
  1584. BackgroundImg: v.BackgroundImg,
  1585. Title: v.Title,
  1586. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1587. PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  1588. AdminId: v.AdminId,
  1589. AdminRealName: v.AdminRealName,
  1590. PptVersion: v.PptVersion,
  1591. IsSingleShare: v.IsShare,
  1592. PptxUrl: v.PptxUrl,
  1593. ReportId: v.ReportId,
  1594. ReportCode: v.ReportCode,
  1595. PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
  1596. }
  1597. list = append(list, tmpV)
  1598. }
  1599. ret.List = list
  1600. ret.Total = len(list)
  1601. return
  1602. }
  1603. // SearchPptList PPT搜索(我的/公开PPT)
  1604. func SearchPptList(adminId int, keyword string) (ret models.RespGroupPptList, err error) {
  1605. list := make([]*models.RespGroupPptListItem, 0)
  1606. ret.List = list
  1607. var condition string
  1608. var pars []interface{}
  1609. // 公开的PPT或是我的非公开PPT
  1610. condition += ` AND (is_share = 1 OR (admin_id = ? AND is_share = 0)) `
  1611. pars = append(pars, adminId)
  1612. if keyword != `` {
  1613. kw := fmt.Sprint("%", keyword, "%")
  1614. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1615. pars = append(pars, kw, kw)
  1616. }
  1617. pptList, err := models.GetAllPptV2List(condition, pars)
  1618. if len(pptList) <= 0 {
  1619. return
  1620. }
  1621. for _, v := range pptList {
  1622. tmpV := &models.RespGroupPptListItem{
  1623. GroupPptId: int64(v.PptId),
  1624. PptId: int64(v.PptId),
  1625. TemplateType: v.TemplateType,
  1626. BackgroundImg: v.BackgroundImg,
  1627. Title: v.Title,
  1628. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1629. AdminId: v.AdminId,
  1630. AdminRealName: v.AdminRealName,
  1631. PptVersion: v.PptVersion,
  1632. IsSingleShare: v.IsShare,
  1633. PptxUrl: v.PptxUrl,
  1634. ReportId: v.ReportId,
  1635. ReportCode: v.ReportCode,
  1636. }
  1637. list = append(list, tmpV)
  1638. }
  1639. ret.List = list
  1640. ret.Total = len(list)
  1641. return
  1642. }