ppt_english_group.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. package ppt
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_ETA_mobile_api/models/ppt_english"
  7. "hongze/hongze_ETA_mobile_api/models/system"
  8. "hongze/hongze_ETA_mobile_api/utils"
  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. PptxUrl: pptInfo.PptxUrl,
  410. ReportId: pptInfo.ReportId,
  411. ReportCode: pptInfo.ReportCode,
  412. }
  413. if pptV.ChildGroupPptId > 0 {
  414. tmp.IsSingleShare = 1
  415. }
  416. list = append(list, tmp)
  417. hasPpt[pptInfo.PptId] = struct{}{}
  418. }
  419. }
  420. }
  421. }
  422. }
  423. ret.List = list
  424. if groupId <= 0 {
  425. sort.Sort(ret)
  426. }
  427. ret.Total = len(list)
  428. return
  429. }
  430. // MoveGroupPptEnglish 移动ppt操作
  431. func MoveGroupPptEnglish(groupId, groupPptId, prevGroupPptId, nextGroupPptId int64, adminId int) (err error) {
  432. //查询当前映射是否存在
  433. //判断当前登录者是否有共享的权限oo
  434. groupPpt, err := ppt_english.GetPptMappingByGroupPptId(groupPptId, adminId)
  435. if err != nil {
  436. if err.Error() == utils.ErrNoRow() {
  437. err = errors.New("当前目录下的ppt不存在")
  438. return
  439. }
  440. err = errors.New("目录下的ppt查询出错:" + err.Error())
  441. return
  442. }
  443. var updateStr []string
  444. //如果更换了目录,默认当前排序值为0
  445. var currentSort, prevSort, nextSort int64
  446. //判断是否更换group
  447. if groupPpt.GroupId != groupId {
  448. _, err = ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
  449. if err != nil {
  450. if err.Error() == utils.ErrNoRow() {
  451. err = errors.New("目录不存在")
  452. return
  453. }
  454. err = errors.New("目录查询出错:" + err.Error())
  455. return
  456. }
  457. //判断是否需要解除当个ppt共享
  458. //解除共享操作
  459. err = CancelShareSingleGroupPptEnglish(groupPpt, adminId)
  460. if err != nil {
  461. err = errors.New(err.Error())
  462. return
  463. }
  464. groupPpt.GroupId = groupId
  465. updateStr = append(updateStr, "group_id")
  466. }
  467. currentSort = groupPpt.PptSort
  468. var prevGroupPpt *ppt_english.PptEnglishGroupMapping
  469. var nextGroupPpt *ppt_english.PptEnglishGroupMapping
  470. if prevGroupPptId > 0 {
  471. prevGroupPpt, err = ppt_english.GetPptMappingByGroupPptId(prevGroupPptId, adminId)
  472. if err != nil {
  473. if err.Error() == utils.ErrNoRow() {
  474. err = errors.New("目录下的ppt不存在")
  475. return
  476. }
  477. err = errors.New("目录下的ppt查询出错:" + err.Error())
  478. return
  479. }
  480. prevSort = prevGroupPpt.PptSort
  481. }
  482. if nextGroupPptId > 0 {
  483. nextGroupPpt, err = ppt_english.GetPptMappingByGroupPptId(nextGroupPptId, adminId)
  484. if err != nil {
  485. if err.Error() == utils.ErrNoRow() {
  486. err = errors.New("目录下的ppt不存在")
  487. return
  488. }
  489. err = errors.New("目录下的ppt查询出错:" + err.Error())
  490. return
  491. }
  492. nextSort = nextGroupPpt.PptSort
  493. }
  494. updateStr = append(updateStr, "ppt_sort")
  495. //移到两个排序值中间操作
  496. if prevSort >= currentSort {
  497. //往下移动
  498. err = ppt_english.MoveDownGroupPptBySort(groupId, prevSort, currentSort)
  499. if err != nil {
  500. err = errors.New("向下移动ppt出错:" + err.Error())
  501. return
  502. }
  503. groupPpt.PptSort = prevSort
  504. } else if nextSort <= currentSort && nextSort != 0 {
  505. //往上移动
  506. err = ppt_english.MoveUpGroupPptBySort(groupId, nextSort, currentSort)
  507. if err != nil {
  508. err = errors.New("向上移动ppt出错:" + err.Error())
  509. return
  510. }
  511. groupPpt.PptSort = nextSort
  512. }
  513. //更新当前排序
  514. err = groupPpt.Update(updateStr)
  515. if err != nil {
  516. err = errors.New("移动ppt出错:" + err.Error())
  517. return
  518. }
  519. return
  520. }
  521. // MoveEnglishGroup 移动目录
  522. func MoveEnglishGroup(groupId, prevGroupId, nextGroupId int64, adminId int) (err error) {
  523. //查询目录是否存在
  524. groupInfo, err := ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
  525. if err != nil {
  526. if err.Error() == utils.ErrNoRow() {
  527. err = errors.New("目录不存在")
  528. return
  529. }
  530. err = errors.New("目录查询出错:" + err.Error())
  531. return
  532. }
  533. //如果更换了目录,默认当前排序值为0
  534. var currentSort, prevSort, nextSort int64
  535. currentSort = groupInfo.GroupSort
  536. var prevGroup *ppt_english.PptEnglishGroup
  537. var nextGroup *ppt_english.PptEnglishGroup
  538. if prevGroupId > 0 {
  539. prevGroup, err = ppt_english.GetPptGroupByGroupIdAdminId(prevGroupId, adminId)
  540. if err != nil {
  541. if err.Error() == utils.ErrNoRow() {
  542. err = errors.New("目录不存在")
  543. return
  544. }
  545. err = errors.New("目录查询出错:" + err.Error())
  546. return
  547. }
  548. prevSort = prevGroup.GroupSort
  549. }
  550. if nextGroupId > 0 {
  551. nextGroup, err = ppt_english.GetPptGroupByGroupIdAdminId(nextGroupId, adminId)
  552. if err != nil {
  553. if err.Error() == utils.ErrNoRow() {
  554. err = errors.New("目录不存在")
  555. return
  556. }
  557. err = errors.New("目录查询出错:" + err.Error())
  558. return
  559. }
  560. nextSort = nextGroup.GroupSort
  561. }
  562. //移到两个排序值中间操作
  563. if prevSort >= currentSort {
  564. //往下移动
  565. err = ppt_english.MoveDownGroupBySort(prevSort, currentSort)
  566. if err != nil {
  567. err = errors.New("向下移动ppt出错:" + err.Error())
  568. return
  569. }
  570. groupInfo.GroupSort = prevSort
  571. } else if nextSort <= currentSort && nextSort != 0 {
  572. //往上移动
  573. err = ppt_english.MoveUpGroupBySort(nextSort, currentSort)
  574. if err != nil {
  575. err = errors.New("向上移动ppt出错:" + err.Error())
  576. return
  577. }
  578. groupInfo.GroupSort = nextSort
  579. }
  580. //更新当前排序
  581. err = groupInfo.Update([]string{"group_sort"})
  582. if err != nil {
  583. err = errors.New("移动目录出错:" + err.Error())
  584. return
  585. }
  586. return
  587. }
  588. // CancelShareSingleGroupPptEnglish 解除单个共享的ppt
  589. func CancelShareSingleGroupPptEnglish(groupPpt *ppt_english.PptEnglishGroupMapping, adminId int) (err error) {
  590. if groupPpt.ChildGroupPptId <= 0 {
  591. return
  592. }
  593. //如果已经是共享状态,
  594. //判断当前登录者是否有取消共享的权限
  595. childGroupPpt, tErr := ppt_english.GetPptMappingByGroupPptId(groupPpt.ChildGroupPptId, adminId)
  596. if tErr != nil {
  597. if tErr.Error() != utils.ErrNoRow() {
  598. err = errors.New("目录下的ppt查询出错:" + tErr.Error())
  599. return
  600. }
  601. }
  602. if childGroupPpt != nil {
  603. //删除共享目录和ppt的映射关系
  604. err = ppt_english.DeletePptGroupMapping(childGroupPpt.GroupPptId, adminId)
  605. if err != nil {
  606. err = errors.New("删除共享目录下的ppt失败:" + err.Error())
  607. return
  608. }
  609. //删除共享出去的公共目录
  610. err = ppt_english.DeletePptGroup(childGroupPpt.GroupId)
  611. if err != nil {
  612. err = errors.New("删除共享目录失败:" + err.Error())
  613. return
  614. }
  615. }
  616. //更新共享状态为未共享,
  617. //更新共享标识
  618. groupPpt.ChildGroupPptId = 0
  619. err = groupPpt.Update([]string{"child_group_ppt_id"})
  620. if err != nil {
  621. err = errors.New("更新共享标识失败" + err.Error())
  622. return
  623. }
  624. return
  625. }
  626. // DeleteGroupPptEnglish 删除ppt
  627. func DeleteGroupPptEnglish(PptId int) (err error) {
  628. //查询该ppt的所有单个共享出去的目录信息
  629. groupPpts, err := ppt_english.GetGroupPptByPptId(PptId)
  630. if err != nil {
  631. err = errors.New("查询目录里的ppt失败" + err.Error())
  632. return
  633. }
  634. if len(groupPpts) <= 0 {
  635. return
  636. }
  637. //整理出需要删除的groupId
  638. groupPptMap := make(map[int64]*ppt_english.PptEnglishGroupMapping)
  639. for _, v := range groupPpts {
  640. groupPptMap[v.GroupPptId] = v
  641. }
  642. var delGroupIds string
  643. for _, v := range groupPpts {
  644. if v.ChildGroupPptId > 0 {
  645. if childGroup, ok := groupPptMap[v.ChildGroupPptId]; ok {
  646. delGroupIds += strconv.Itoa(int(childGroup.GroupId)) + ","
  647. }
  648. }
  649. }
  650. if delGroupIds != "" {
  651. delGroupIds = "(" + strings.Trim(delGroupIds, ",") + ")"
  652. err = ppt_english.DeletePptGroupByGroupIds(delGroupIds)
  653. if err != nil {
  654. err = errors.New("删除单个共享目录失败" + err.Error())
  655. return
  656. }
  657. }
  658. //再统一删除目录里相关的ppt
  659. err = ppt_english.DeletePptGroupMappingByPptId(PptId)
  660. if err != nil {
  661. err = errors.New("删除目录里的ppt失败" + err.Error())
  662. return
  663. }
  664. return
  665. }
  666. // CopyPptEnglish 复制单个ppt,并移动到新的目录下面
  667. func CopyPptEnglish(pptId int, groupId int64, adminId int, adminRealName string) (resp ppt_english.RespGroupPptNameListItem, err error) {
  668. //查询ppt详情
  669. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  670. if err != nil {
  671. if err.Error() == utils.ErrNoRow() {
  672. err = errors.New("ppt 不存在")
  673. return
  674. }
  675. err = errors.New("查询ppt失败" + err.Error())
  676. return
  677. }
  678. // 查询目录是否存在
  679. _, err = ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
  680. if err != nil {
  681. if err.Error() == utils.ErrNoRow() {
  682. err = errors.New("目录不存在")
  683. return
  684. }
  685. err = errors.New("目录查询出错:" + err.Error())
  686. return
  687. }
  688. pptNames, err := ppt_english.GetAllPptTitle()
  689. if err != nil {
  690. err = errors.New("查询ppt标题出错:" + err.Error())
  691. return
  692. }
  693. //复制ppt,更新作者为当前账号,并返回新的pptID
  694. var newPptList []*ppt_english.PptEnglish
  695. newPpt := &ppt_english.PptEnglish{
  696. TemplateType: pptInfo.TemplateType,
  697. BackgroundImg: pptInfo.BackgroundImg,
  698. Title: generateCopyName(pptInfo.Title, 1, pptNames),
  699. ReportType: pptInfo.ReportType,
  700. PptDate: pptInfo.PptDate,
  701. Content: pptInfo.Content,
  702. CreateTime: time.Now(),
  703. ModifyTime: time.Now(),
  704. AdminId: adminId,
  705. AdminRealName: adminRealName,
  706. }
  707. newPptList = append(newPptList, newPpt)
  708. err = ppt_english.AddPptEnglishMulti(newPptList)
  709. if err != nil {
  710. err = errors.New("复制目录里的ppt出错:" + err.Error())
  711. return
  712. }
  713. var newMappings []*ppt_english.PptEnglishGroupMapping
  714. newGroupPpt := &ppt_english.PptEnglishGroupMapping{
  715. GroupId: groupId,
  716. PptId: int64(newPpt.PptId),
  717. CreateTime: time.Now(),
  718. ModifyTime: time.Now(),
  719. AdminId: adminId,
  720. AdminRealName: adminRealName,
  721. }
  722. newMappings = append(newMappings, newGroupPpt)
  723. err = ppt_english.AddPptGroupMappingMulti(newMappings)
  724. if err != nil {
  725. err = errors.New("复制目录里的ppt出错:" + err.Error())
  726. return
  727. }
  728. //批量更新排序字段
  729. err = ppt_english.UpdatePptGroupMappingSortMulti([]int64{newGroupPpt.GroupPptId})
  730. if err != nil {
  731. err = errors.New("更新排序标识出错:" + err.Error())
  732. return
  733. }
  734. var pptPage int
  735. if newPpt.Content != "" {
  736. contents := make([]PageContent, 0)
  737. if e := json.Unmarshal([]byte(newPpt.Content), &contents); e != nil {
  738. err = errors.New(fmt.Sprintf("%d,解析PPT内容页数失败: %s", newPpt.PptId, e.Error()))
  739. return
  740. }
  741. pptPage = len(contents)
  742. }
  743. resp = ppt_english.RespGroupPptNameListItem{
  744. GroupPptId: newGroupPpt.GroupPptId,
  745. PptId: int64(newPpt.PptId),
  746. Title: newPpt.Title,
  747. AdminId: newPpt.AdminId,
  748. AdminRealName: newPpt.AdminRealName,
  749. PptCreateTime: newPpt.CreateTime.Format(utils.FormatDateTime),
  750. PptPage: pptPage,
  751. }
  752. return
  753. }
  754. // generateCopyNameEnglish 生成复制的目录名称
  755. func generateCopyNameEnglish(originName string, count int, nameList []string) (newName string) {
  756. newName = originName + "(" + strconv.Itoa(count) + ")"
  757. for _, v := range nameList {
  758. if v == newName {
  759. count++
  760. newName = generateCopyName(originName, count, nameList)
  761. return
  762. }
  763. }
  764. return
  765. }
  766. // SearchGroupPptEnglish 根据ppt标题搜索ppt
  767. func SearchGroupPptEnglish(keyWord string) (ret ppt_english.RespSearchGroupPptList, err error) {
  768. //组装group ppt
  769. list := make([]*ppt_english.RespSearchGroupPptListItem, 0)
  770. ret.List = list
  771. reqKeyword := "%" + keyWord + "%"
  772. condition := " and title like ? "
  773. var pars []interface{}
  774. pars = append(pars, reqKeyword)
  775. pptList, err := ppt_english.GetPptEnglishByCondition(condition, pars)
  776. if err != nil {
  777. err = errors.New("查询ppt列表出错:" + err.Error())
  778. return
  779. }
  780. if len(pptList) == 0 {
  781. return
  782. }
  783. pptIds := make([]string, 0)
  784. pptMap := make(map[int]*ppt_english.PptEnglish)
  785. for _, v := range pptList {
  786. pptIds = append(pptIds, strconv.Itoa(v.PptId))
  787. pptMap[v.PptId] = v
  788. }
  789. groupPptList, err := ppt_english.GetPublicGroupPptByPptIds(pptIds)
  790. if err != nil {
  791. err = errors.New("查询目录里的ppt列表出错:" + err.Error())
  792. return
  793. }
  794. for _, v := range groupPptList {
  795. tmp := new(ppt_english.RespSearchGroupPptListItem)
  796. tmp.GroupPptId = v.GroupPptId
  797. tmp.PptId = v.PptId
  798. if i, ok := pptMap[int(v.PptId)]; ok {
  799. tmp.Title = i.Title
  800. }
  801. list = append(list, tmp)
  802. }
  803. ret.List = list
  804. return
  805. }
  806. func GetEnglishGroupsByAdminId(adminId int) (ret ppt_english.RespGroupList, err error) {
  807. myPptList := make([]*ppt_english.RespGroupPptNameListItem, 0)
  808. otherPptList := make([]*ppt_english.RespGroupPptNameListItem, 0)
  809. grantList := []ppt_english.RespGroupListItem{
  810. {
  811. GroupId: 1,
  812. GroupName: "我共享的",
  813. PptList: myPptList,
  814. },
  815. {
  816. GroupId: 2,
  817. GroupName: "收到共享",
  818. PptList: otherPptList,
  819. },
  820. }
  821. ret.PublicList = make([]*ppt_english.RespGroupListItem, 0)
  822. ret.PrivateList = make([]*ppt_english.RespGroupListItem, 0)
  823. ret.GrantList = grantList
  824. pptMap := make(map[int]*ppt_english.PptEnglish)
  825. groupMap := make(map[int64][]*ppt_english.RespGroupPptNameListItem)
  826. groupHasNewPptMap := make(map[int64]struct{})
  827. pptIds := make([]int, 0)
  828. // 获取我的ppt分组
  829. privateGroups, err := ppt_english.GetPrivatePptGroupsByAdminId(adminId)
  830. if err != nil {
  831. err = errors.New("私有目录查询出错:" + err.Error())
  832. return
  833. }
  834. groupIds := make([]int64, 0)
  835. for _, v := range privateGroups {
  836. groupIds = append(groupIds, v.GroupId)
  837. }
  838. var pptMappings []*ppt_english.PptEnglishGroupMapping
  839. // 如果没有分组,那么直接返回
  840. if len(groupIds) > 0 {
  841. // 遍历分组并拼接
  842. for _, v := range privateGroups {
  843. tmp := new(ppt_english.RespGroupListItem)
  844. tmp.GroupId = v.GroupId
  845. tmp.GroupName = v.GroupName
  846. tmp.IsShare = v.IsShare
  847. tmp.AdminId = v.AdminId
  848. ret.PrivateList = append(ret.PrivateList, tmp)
  849. }
  850. // 通过分组id获取相关的ppt信息,主要是为了获取所有的ppt_id字段
  851. pptMappings, err = ppt_english.GetPptMappingListByGroupIds(groupIds)
  852. if err != nil {
  853. err = errors.New("查询目录里的ppt出错:" + err.Error())
  854. return
  855. }
  856. for _, v := range pptMappings {
  857. pptIds = append(pptIds, int(v.PptId))
  858. }
  859. }
  860. adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
  861. adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
  862. // grantList 已经分配权限的ppt
  863. grantPptList, err := ppt_english.GetAllGrantList(adminId)
  864. for _, v := range grantPptList {
  865. pptIds = append(pptIds, v.PptId)
  866. if _, ok := adminIdMap[v.AdminId]; !ok {
  867. adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
  868. adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  869. }
  870. }
  871. if len(pptIds) > 0 {
  872. // 通过ppt_id列表字段获取所有的ppt信息
  873. pptList, tmpErr := ppt_english.GetPptEnglishByIds(pptIds)
  874. if tmpErr != nil {
  875. err = errors.New("查询ppt详情出错:" + err.Error())
  876. return
  877. }
  878. for _, v := range pptList {
  879. pptMap[v.PptId] = v
  880. }
  881. }
  882. // 私有的Ppt列表
  883. {
  884. //组装group ppt
  885. for _, v := range pptMappings {
  886. i, ok := pptMap[int(v.PptId)]
  887. if !ok { //找不到ppt,还干个啥,直接退出当前循环啊
  888. continue
  889. }
  890. pptPage := 0
  891. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  892. if i.Content != "" {
  893. contents := make([]PageContent, 0)
  894. if e := json.Unmarshal([]byte(i.Content), &contents); e != nil {
  895. err = errors.New(fmt.Sprintf("%d,解析PPT内容页数失败: %s", i.PptId, e.Error()))
  896. return
  897. }
  898. pptPage = len(contents)
  899. }
  900. tmp := &ppt_english.RespGroupPptNameListItem{
  901. AdminId: v.AdminId,
  902. GroupPptId: v.GroupPptId,
  903. PptId: v.PptId,
  904. AdminRealName: v.AdminRealName,
  905. Title: i.Title,
  906. IsSingleShare: i.IsShare,
  907. PptxUrl: i.PptxUrl,
  908. ReportId: i.ReportId,
  909. ReportCode: i.ReportCode,
  910. PptCreateTime: i.CreateTime.Format(utils.FormatDateTime),
  911. PptPage: pptPage,
  912. }
  913. if tmp.PptVersion == 2 {
  914. groupHasNewPptMap[v.GroupId] = struct{}{}
  915. }
  916. groupMap[v.GroupId] = append(groupMap[v.GroupId], tmp)
  917. }
  918. for k, v := range ret.PrivateList {
  919. if pptL, ok := groupMap[v.GroupId]; ok {
  920. ret.PrivateList[k].PptList = pptL
  921. if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
  922. ret.PrivateList[k].OnlyOld = true
  923. }
  924. }
  925. }
  926. }
  927. publicAdminIdList := make([]int, 0)
  928. publicPptListMap := make(map[int][]*ppt_english.RespGroupPptNameListItem)
  929. // 获取公开分享的ppt
  930. sharePptList, err := ppt_english.GetSharePptEnglish()
  931. for _, v := range sharePptList {
  932. publicPptList, ok := publicPptListMap[v.AdminId]
  933. if !ok {
  934. publicPptList = make([]*ppt_english.RespGroupPptNameListItem, 0)
  935. publicAdminIdList = append(publicAdminIdList, v.AdminId)
  936. // 需要查询的创建人信息
  937. if _, ok := adminIdMap[v.AdminId]; !ok {
  938. adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
  939. adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
  940. }
  941. }
  942. contents := make([]PageContent, 0)
  943. if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
  944. err = errors.New("解析PPT内容页数失败: " + e.Error())
  945. return
  946. }
  947. pptPage := len(contents)
  948. tmpV := &ppt_english.RespGroupPptNameListItem{
  949. GroupPptId: int64(v.PptId),
  950. PptId: int64(v.PptId),
  951. Title: v.Title,
  952. AdminId: v.AdminId,
  953. AdminRealName: v.AdminRealName,
  954. IsSingleShare: v.IsShare,
  955. PptxUrl: v.PptxUrl,
  956. ReportId: v.ReportId,
  957. ReportCode: v.ReportCode,
  958. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  959. PptPage: pptPage,
  960. }
  961. publicPptList = append(publicPptList, tmpV)
  962. publicPptListMap[v.AdminId] = publicPptList
  963. }
  964. // 创建人信息
  965. systemAdminMap := make(map[int]*system.Admin)
  966. systemAdminList, err := system.GetAdminListByIdList(adminIdList)
  967. if err != nil {
  968. return
  969. }
  970. for _, v := range systemAdminList {
  971. systemAdminMap[v.AdminId] = v
  972. }
  973. // 公开分享的用户列表
  974. {
  975. for _, v := range publicAdminIdList {
  976. systemAdmin, ok := systemAdminMap[v]
  977. if !ok {
  978. continue
  979. }
  980. // ppt 列表信息
  981. respGroupPptNameListItemList, ok := publicPptListMap[v]
  982. if !ok {
  983. respGroupPptNameListItemList = make([]*ppt_english.RespGroupPptNameListItem, 0)
  984. }
  985. // ppt 分组信息
  986. tmpRespGroupListItem := &ppt_english.RespGroupListItem{
  987. GroupId: int64(systemAdmin.AdminId),
  988. GroupName: systemAdmin.RealName + "的PPT",
  989. AdminId: systemAdmin.AdminId,
  990. IsShare: 1,
  991. OnlyOld: false,
  992. PptList: respGroupPptNameListItemList,
  993. }
  994. ret.PublicList = append(ret.PublicList, tmpRespGroupListItem)
  995. }
  996. }
  997. myGrantPPtIdMap := make(map[int]int) //我分配的ppt的id集合
  998. // 共享Ppt
  999. {
  1000. for _, v := range grantPptList {
  1001. pptPage := 0
  1002. // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
  1003. if v.Content != "" {
  1004. contents := make([]PageContent, 0)
  1005. if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
  1006. err = errors.New("解析PPT内容页数失败: " + e.Error())
  1007. return
  1008. }
  1009. }
  1010. title := v.Title
  1011. if adminInfo, ok := systemAdminMap[v.AdminId]; ok {
  1012. title = adminInfo.RealName + "———" + title
  1013. }
  1014. tmp := &ppt_english.RespGroupPptNameListItem{
  1015. AdminId: v.AdminId,
  1016. //GroupPptId: v.GroupPptId,
  1017. PptId: int64(v.PptId),
  1018. AdminRealName: v.AdminRealName,
  1019. Title: title,
  1020. PptVersion: v.PptVersion,
  1021. IsSingleShare: v.IsShare,
  1022. PptxUrl: v.PptxUrl,
  1023. ReportId: v.ReportId,
  1024. ReportCode: v.ReportCode,
  1025. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1026. PptPage: pptPage,
  1027. }
  1028. if v.AdminId == adminId {
  1029. tmp.IsGrant = 1
  1030. myPptList = append(myPptList, tmp)
  1031. myGrantPPtIdMap[v.PptId] = v.PptId
  1032. } else {
  1033. tmp.IsReceived = 1
  1034. otherPptList = append(otherPptList, tmp)
  1035. }
  1036. }
  1037. grantList[0].PptList = myPptList
  1038. grantList[1].PptList = otherPptList
  1039. ret.GrantList = grantList
  1040. }
  1041. // 处理公共ppt里面的关于自个的ppt是否有配置权限的字段数据变更
  1042. for k, publicList := range ret.PublicList {
  1043. for kk, pptInfo := range publicList.PptList {
  1044. // 是否有过权限配置
  1045. if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
  1046. pptInfo.IsGrant = 1
  1047. }
  1048. publicList.PptList[kk] = pptInfo
  1049. }
  1050. ret.PublicList[k] = publicList
  1051. }
  1052. for k, privateList := range ret.PrivateList {
  1053. for kk, pptInfo := range privateList.PptList {
  1054. // 是否有过权限配置
  1055. if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
  1056. pptInfo.IsGrant = 1
  1057. }
  1058. privateList.PptList[kk] = pptInfo
  1059. }
  1060. ret.PrivateList[k] = privateList
  1061. }
  1062. return
  1063. //则过滤空文件夹
  1064. //公共ppt
  1065. pubList := make([]*ppt_english.RespGroupListItem, 0)
  1066. for _, v := range ret.PublicList {
  1067. if len(v.PptList) > 0 {
  1068. pubList = append(pubList, v)
  1069. }
  1070. }
  1071. ret.PublicList = pubList
  1072. // 私有ppt
  1073. priList := make([]*ppt_english.RespGroupListItem, 0)
  1074. for _, v := range ret.PrivateList {
  1075. if len(v.PptList) > 0 {
  1076. priList = append(priList, v)
  1077. }
  1078. }
  1079. ret.PrivateList = priList
  1080. return
  1081. }
  1082. // ShareSingleGroupPptEnglishEnglish 共享单个ppt/取消共享单个ppt,返回共享状态
  1083. // @Author roc
  1084. // @Time 2022-08-29 15:22:20
  1085. func ShareSingleGroupPptEnglish(pptId int, adminId int) (pptInfo *ppt_english.PptEnglish, err error) {
  1086. //判断当前登录者是否有共享的权限
  1087. pptInfo, err = ppt_english.GetPptEnglishById(pptId)
  1088. if err != nil {
  1089. if err.Error() == utils.ErrNoRow() {
  1090. err = errors.New("当前目录下的ppt不存在")
  1091. return
  1092. }
  1093. err = errors.New("目录下的ppt查询出错:" + err.Error())
  1094. return
  1095. }
  1096. if pptInfo.AdminId != adminId {
  1097. err = errors.New("该Ppt不是本人创建")
  1098. return
  1099. }
  1100. //判断当前的共享状态
  1101. if pptInfo.IsShare > 0 {
  1102. pptInfo.IsShare = 0
  1103. err = pptInfo.Update([]string{"IsShare"})
  1104. if err != nil {
  1105. err = errors.New(err.Error())
  1106. return
  1107. }
  1108. } else {
  1109. pptInfo.IsShare = 1
  1110. err = pptInfo.Update([]string{"IsShare"})
  1111. if err != nil {
  1112. err = errors.New(err.Error())
  1113. return
  1114. }
  1115. }
  1116. return
  1117. }
  1118. func GetMyPptEnglishList(adminId int, keyword string) (ret ppt_english.RespGroupPptList, err error) {
  1119. list := make([]*ppt_english.RespGroupPptListItem, 0)
  1120. ret.List = list
  1121. var condition string
  1122. var pars []interface{}
  1123. condition += ` AND admin_id=? `
  1124. pars = append(pars, adminId)
  1125. if keyword != `` {
  1126. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1127. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  1128. }
  1129. pptList, err := ppt_english.GetAllPptEnglishList(condition, pars)
  1130. if len(pptList) <= 0 {
  1131. return
  1132. }
  1133. for _, v := range pptList {
  1134. tmpV := &ppt_english.RespGroupPptListItem{
  1135. GroupPptId: int64(v.PptId),
  1136. PptId: int64(v.PptId),
  1137. TemplateType: v.TemplateType,
  1138. BackgroundImg: v.BackgroundImg,
  1139. Title: v.Title,
  1140. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1141. AdminId: v.AdminId,
  1142. AdminRealName: v.AdminRealName,
  1143. IsSingleShare: v.IsShare,
  1144. PptxUrl: v.PptxUrl,
  1145. ReportId: v.ReportId,
  1146. ReportCode: v.ReportCode,
  1147. }
  1148. list = append(list, tmpV)
  1149. }
  1150. ret.List = list
  1151. ret.Total = len(list)
  1152. return
  1153. }
  1154. // GetSharePptList 公共目录下的ppt列表
  1155. // @Author roc
  1156. // @Time 2022-08-29 16:27:59
  1157. func GetSharePptEnglishList(adminId int, keyword string, isPrivate bool) (ret ppt_english.RespGroupPptList, err error) {
  1158. list := make([]*ppt_english.RespGroupPptListItem, 0)
  1159. ret.List = list
  1160. var condition string
  1161. var pars []interface{}
  1162. // 公开的ppt
  1163. condition += ` AND is_share=? `
  1164. if isPrivate {
  1165. pars = append(pars, 0)
  1166. } else {
  1167. pars = append(pars, 1)
  1168. }
  1169. if adminId > 0 {
  1170. condition += ` AND admin_id=? `
  1171. pars = append(pars, adminId)
  1172. }
  1173. if keyword != `` {
  1174. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  1175. pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
  1176. }
  1177. pptList, err := ppt_english.GetAllPptEnglishList(condition, pars)
  1178. if len(pptList) <= 0 {
  1179. return
  1180. }
  1181. for _, v := range pptList {
  1182. tmpV := &ppt_english.RespGroupPptListItem{
  1183. GroupPptId: int64(v.PptId),
  1184. PptId: int64(v.PptId),
  1185. TemplateType: v.TemplateType,
  1186. BackgroundImg: v.BackgroundImg,
  1187. Title: v.Title,
  1188. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1189. AdminId: v.AdminId,
  1190. AdminRealName: v.AdminRealName,
  1191. IsSingleShare: v.IsShare,
  1192. PptxUrl: v.PptxUrl,
  1193. ReportId: v.ReportId,
  1194. ReportCode: v.ReportCode,
  1195. }
  1196. list = append(list, tmpV)
  1197. }
  1198. ret.List = list
  1199. ret.Total = len(list)
  1200. return
  1201. }
  1202. // GetGrantPptList 公共目录下的ppt列表
  1203. // @Author roc
  1204. // @Time 2022-09-05 15:50:25
  1205. func GetGrantPptEnglishList(adminId int, keyword, sourceType string) (ret ppt_english.RespGroupPptList, err error) {
  1206. list := make([]*ppt_english.RespGroupPptListItem, 0)
  1207. ret.List = list
  1208. var condition string
  1209. var pars []interface{}
  1210. switch sourceType {
  1211. case "my":
  1212. condition += ` AND a.admin_id = ? `
  1213. pars = append(pars, adminId)
  1214. case "other":
  1215. condition += ` AND a.admin_id != ? AND (b.department_id = 1 OR b.grant_admin_id = ?) `
  1216. pars = append(pars, adminId, adminId)
  1217. default:
  1218. err = errors.New("无效的来源")
  1219. return
  1220. }
  1221. if keyword != `` {
  1222. condition += ` AND a.title LIKE ? `
  1223. pars = append(pars, "%"+keyword+"%")
  1224. }
  1225. pptList, err := ppt_english.GetGrantList(condition, pars)
  1226. if err != nil {
  1227. return
  1228. }
  1229. if len(pptList) <= 0 {
  1230. return
  1231. }
  1232. for _, v := range pptList {
  1233. tmpV := &ppt_english.RespGroupPptListItem{
  1234. GroupPptId: int64(v.PptId),
  1235. PptId: int64(v.PptId),
  1236. TemplateType: v.TemplateType,
  1237. BackgroundImg: v.BackgroundImg,
  1238. Title: v.Title,
  1239. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1240. AdminId: v.AdminId,
  1241. AdminRealName: v.AdminRealName,
  1242. PptVersion: v.PptVersion,
  1243. IsSingleShare: v.IsShare,
  1244. PptxUrl: v.PptxUrl,
  1245. ReportId: v.ReportId,
  1246. ReportCode: v.ReportCode,
  1247. }
  1248. list = append(list, tmpV)
  1249. }
  1250. ret.List = list
  1251. ret.Total = len(list)
  1252. return
  1253. }
  1254. // GetEnglishCopyUsableTitle 根据原标题获取复制/转换可用的标题
  1255. func GetEnglishCopyUsableTitle(title string) (newTitle string, err error) {
  1256. if title == "" {
  1257. return
  1258. }
  1259. // 标题列表
  1260. titles, e := ppt_english.GetPPTTitleList()
  1261. if e != nil {
  1262. err = errors.New("获取英文PPT标题列表失败, Err: " + e.Error())
  1263. return
  1264. }
  1265. if !utils.InArrayByStr(titles, title) {
  1266. newTitle = title
  1267. return
  1268. }
  1269. // 新标题
  1270. titleFormat := title + "(%d)"
  1271. for i := 1; i < 999; i++ {
  1272. newTitle = fmt.Sprintf(titleFormat, i)
  1273. if !utils.InArrayByStr(titles, newTitle) {
  1274. return
  1275. }
  1276. }
  1277. return
  1278. }
  1279. // GetEnglishPptList 公共ppt和我的ppt
  1280. // @Author xi
  1281. // @Time 2022-08-29 16:27:59
  1282. func GetEnglishPptList(adminId int, keyword string) (ret ppt_english.RespGroupPptList, err error) {
  1283. list := make([]*ppt_english.RespGroupPptListItem, 0)
  1284. ret.List = list
  1285. var condition string
  1286. var pars []interface{}
  1287. condition += ` AND (admin_id=? OR is_share=1) `
  1288. pars = append(pars, adminId)
  1289. if keyword != `` {
  1290. condition += ` AND (title LIKE ? ) `
  1291. pars = append(pars, "%"+keyword+"%")
  1292. }
  1293. pptList, err := ppt_english.GetAllPptEnglishList(condition, pars)
  1294. if len(pptList) <= 0 {
  1295. return
  1296. }
  1297. for _, v := range pptList {
  1298. tmpV := &ppt_english.RespGroupPptListItem{
  1299. GroupPptId: int64(v.PptId),
  1300. PptId: int64(v.PptId),
  1301. TemplateType: v.TemplateType,
  1302. BackgroundImg: v.BackgroundImg,
  1303. Title: v.Title,
  1304. PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1305. AdminId: v.AdminId,
  1306. AdminRealName: v.AdminRealName,
  1307. IsSingleShare: v.IsShare,
  1308. PptxUrl: v.PptxUrl,
  1309. ReportId: v.ReportId,
  1310. ReportCode: v.ReportCode,
  1311. }
  1312. list = append(list, tmpV)
  1313. }
  1314. if keyword != `` {
  1315. for _, v := range list {
  1316. if strings.Contains(v.Title, keyword) {
  1317. index := strings.Index(v.Title,keyword)
  1318. newTitle := v.Title[:index] + "<span class=\"color-light\">"+ keyword +"</span>"+ v.Title[index+len(keyword):]
  1319. v.Title = newTitle
  1320. }
  1321. }
  1322. }
  1323. ret.List = list
  1324. ret.Total = len(list)
  1325. return
  1326. }