ppt_english_group.go 40 KB

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