ppt_english_group.go 39 KB

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