ppt_english_group.go 42 KB

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