1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480 |
- package ppt
- import (
- "encoding/json"
- "errors"
- "eta/eta_api/models/ppt_english"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- // AddEnglishGroup 新增ppt目录
- func AddEnglishGroup(groupName string, adminId int, isShare int8, isSharedAdd int8) (newId int64, err error) {
- item, err := ppt_english.GetPptGroupByName(groupName, adminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- if item != nil {
- err = errors.New("目录名称已存在,不可重复添加")
- return
- }
- groupInfo := &ppt_english.PptEnglishGroup{
- GroupName: groupName,
- AdminId: adminId,
- IsShare: isShare,
- IsShareAdd: isSharedAdd,
- }
- if isShare == 1 {
- groupInfo.ShareTime = time.Now()
- }
- newId, err = ppt_english.AddPptGroup(groupInfo)
- if err != nil {
- err = errors.New("新增失败,Err:" + err.Error())
- return
- }
- groupInfo.GroupSort = newId
- groupInfo.GroupId = newId
- // 更新排序标识
- err = groupInfo.Update([]string{"group_sort"})
- if err != nil {
- err = errors.New("更新排序失败:" + err.Error())
- return
- }
- return
- }
- // AddGroupPptEnglishMapping 新增ppt和目录映射关系
- func AddGroupPptEnglishMapping(pptId int64, groupId int64, adminId int, adminRealName string) (newId int64, err error) {
- _, err = ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- bindInfo := &ppt_english.PptEnglishGroupMapping{
- GroupId: groupId,
- PptId: pptId,
- AdminId: adminId,
- AdminRealName: adminRealName,
- }
- newId, err = ppt_english.AddPptGroupMapping(bindInfo)
- if err != nil {
- err = errors.New("绑定目录失败:" + err.Error())
- return
- }
- bindInfo.GroupPptId = newId
- bindInfo.PptSort = newId
- err = bindInfo.Update([]string{"ppt_sort"})
- if err != nil {
- err = errors.New("更新排序失败:" + err.Error())
- return
- }
- return
- }
- // DelEnglishGroup 删除ppt 目录
- func DelEnglishGroup(groupId int64, adminId int) (err error) {
- _, err = ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //查询是否有映射存在
- count, err := ppt_english.GetPptMappingCountByGroupId(groupId)
- if err != nil {
- err = errors.New("查询目录里的ppt个数出错:" + err.Error())
- return
- }
- if count > 0 {
- err = errors.New("该目录下有关联PPT,不允许删除")
- return
- }
- err = ppt_english.DeletePptGroup(groupId)
- if err != nil {
- err = errors.New("删除失败:" + err.Error())
- return
- }
- return
- }
- // ShareEnglishGroup 共享/取消共享目录
- func ShareEnglishGroup(groupId int64, adminId int) (respShare ppt_english.RespPptGroupShare, err error) {
- // 查询目录是否存在
- groupInfo, err := ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- // 判断是共享操作还是取消共享操作
- if groupInfo.IsShare == 1 {
- //取消共享
- groupInfo.IsShare = 0
- //groupInfo.ModifyTime = time.Now()
- err = groupInfo.Update([]string{"is_share"})
- if err != nil {
- err = errors.New("取消共享出错:" + err.Error())
- return
- }
- } else {
- //设置共享
- groupInfo.IsShare = 1
- groupInfo.ShareTime = time.Now()
- err = groupInfo.Update([]string{"is_share", "share_time"})
- if err != nil {
- err = errors.New("设置共享出错:" + err.Error())
- return
- }
- respShare.IsShare = 1
- }
- respShare.GroupId = groupId
- return
- }
- // CopyEnglishGroup 复制目录
- func CopyEnglishGroup(groupId int64, adminId int, adminRealName string) (err error) {
- //查询目录是否存在
- groupInfo, err := ppt_english.GetPptGroupByGroupId(groupId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //新增公共目录。目录名称在原来的基础上带上复制序号
- groupNames, err := ppt_english.GetPptGroupNamesByAdminId(adminId)
- if err != nil {
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- newGroupName := generateCopyName(groupInfo.GroupName, 1, groupNames)
- newGroupId, err := AddEnglishGroup(newGroupName, adminId, 0, 0)
- if err != nil {
- err = errors.New("复制目录出错:" + err.Error())
- return
- }
- //查询该目录下面是否存在ppt,如果存在则批量复制ppt到新目录下
- mappingList, err := ppt_english.GetPptMappingListByGroupId(groupId)
- if err != nil {
- err = errors.New("查询目录里的ppt列表出错:" + err.Error())
- return
- }
- if len(mappingList) <= 0 {
- return
- }
- pptIds := make([]int, 0)
- for _, v := range mappingList {
- pptIds = append(pptIds, int(v.PptId))
- }
- //批量查询ppt详情
- pptList, err := ppt_english.GetPptEnglishByIds(pptIds)
- if err != nil {
- err = errors.New("查询ppt列表出错:" + err.Error())
- return
- }
- pptNames, err := ppt_english.GetAllPptTitle()
- if err != nil {
- err = errors.New("查询ppt标题出错:" + err.Error())
- return
- }
- //批量复制ppt,更新作者为当前账号,并返回新的pptID
- newPptList := make([]*ppt_english.PptEnglish, 0)
- for _, v := range pptList {
- tmp := &ppt_english.PptEnglish{
- TemplateType: v.TemplateType,
- BackgroundImg: v.BackgroundImg,
- Title: generateCopyName(v.Title, 1, pptNames),
- ReportType: v.ReportType,
- PptDate: v.PptDate,
- Content: v.Content,
- CoverContent: v.CoverContent,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- TitleSetting: v.TitleSetting,
- }
- newPptList = append(newPptList, tmp)
- }
- if len(newPptList) > 0 {
- err = ppt_english.AddPptEnglishMulti(newPptList)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- newMappings := make([]*ppt_english.PptEnglishGroupMapping, 0)
- for _, v := range newPptList {
- tmp := &ppt_english.PptEnglishGroupMapping{
- GroupId: newGroupId,
- PptId: int64(v.PptId),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- }
- newMappings = append(newMappings, tmp)
- }
- err = ppt_english.AddPptGroupMappingMulti(newMappings)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- //批量更新排序字段
- var newGroupPptIds []int64
- for _, v := range newMappings {
- newGroupPptIds = append(newGroupPptIds, v.GroupPptId)
- }
- err = ppt_english.UpdatePptGroupMappingSortMulti(newGroupPptIds)
- if err != nil {
- err = errors.New("更新排序标识出错:" + err.Error())
- return
- }
- }
- return
- }
- // RenameEnglishGroupName 目录重命名
- func RenameEnglishGroupName(groupId int64, groupName string, adminId int) (err error) {
- groupInfo, err := ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- if groupInfo.GroupName == groupName {
- err = errors.New("与原名字一致,无需修改")
- return
- }
- item, err := ppt_english.GetPptGroupByName(groupName, adminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- if item != nil {
- err = errors.New("目录名称已存在,不可重复添加")
- return
- }
- //更新新名字
- groupInfo.GroupName = groupName
- err = groupInfo.Update([]string{"group_name"})
- if err != nil {
- err = errors.New("目录重命名失败" + err.Error())
- return
- }
- return
- }
- // ShareSingleEnglishGroupPpt 共享单个ppt/取消共享单个ppt,返回共享状态
- func ShareSingleEnglishGroupPpt(groupPptId int64, adminId int, adminRealName string) (ret ppt_english.RespPptShare, err error) {
- //判断当前登录者是否有共享的权限
- groupPpt, err := ppt_english.GetPptMappingByGroupPptId(groupPptId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("当前目录下的ppt不存在")
- return
- }
- err = errors.New("目录下的ppt查询出错:" + err.Error())
- return
- }
- groupInfo, err := ppt_english.GetPptGroupByGroupIdAdminId(groupPpt.GroupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //判断当前的共享状态
- if groupPpt.ChildGroupPptId > 0 {
- err = CancelShareSingleGroupPptEnglish(groupPpt, adminId)
- if err != nil {
- err = errors.New(err.Error())
- return
- }
- ret.IsSingleShare = 0
- } else {
- //如果是未共享状态,则共享该ppt,类似复制流程,并更新共享标识
- //新增公共目录。目录名称在原来的基础上带上复制序号
- groupNames, tErr := ppt_english.GetPptGroupNamesByAdminId(adminId)
- if tErr != nil {
- err = errors.New("目录查询出错:" + tErr.Error())
- return
- }
- newGroupName := generateCopyName(groupInfo.GroupName, 1, groupNames)
- newGroupId, tErr := AddGroup(newGroupName, adminId, 1, 1)
- if tErr != nil {
- err = errors.New(tErr.Error())
- return
- }
- //新增公共的目录和ppt之间的映射关系
- newGroupPptId, tErr := AddGroupPptMapping(groupPpt.PptId, newGroupId, adminId, adminRealName)
- if tErr != nil {
- err = errors.New(tErr.Error())
- return
- }
- //更新共享标识
- groupPpt.ChildGroupPptId = newGroupPptId
- err = groupPpt.Update([]string{"child_group_ppt_id"})
- if err != nil {
- err = errors.New("更新共享标识失败" + err.Error())
- return
- }
- ret.IsSingleShare = 1
- }
- ret.GroupPptId = groupPptId
- return
- }
- // GetGroupPptEnglishList 公共目录下的ppt列表或者单个目录里的ppt列表
- func GetGroupPptEnglishList(groupId int64, adminId int) (ret ppt_english.RespGroupPptList, err error) {
- var groupPptList []*ppt_english.PptEnglishGroupMapping
- var groups []*ppt_english.PptEnglishGroup
- list := make([]*ppt_english.RespGroupPptListItem, 0)
- ret.List = list
- if groupId > 0 {
- //只查询组内的ppt列表
- //查询目录是否存在
- groupInfo, tErr := ppt_english.GetPptGroupByGroupId(groupId)
- if tErr != nil {
- if tErr.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + tErr.Error())
- return
- }
- groups = append(groups, groupInfo)
- groupPptList, tErr = ppt_english.GetPptMappingListByGroupIdDesc(groupId)
- if tErr != nil {
- err = errors.New("目录里的ppt查询出错:" + tErr.Error())
- return
- }
- } else {
- // 获取我的所有的ppt
- ret, err = GetMyPptEnglishList(adminId, ``)
- return
- }
- if len(groupPptList) <= 0 {
- return
- }
- pptMap := make(map[int]*ppt_english.PptEnglish)
- groupMap := make(map[int64][]*ppt_english.PptEnglishGroupMapping)
- pptIds := make([]int, 0)
- for _, v := range groupPptList {
- pptIds = append(pptIds, int(v.PptId))
- groupMap[v.GroupId] = append(groupMap[v.GroupId], v)
- }
- if len(pptIds) == 0 {
- // 返回所有空目录
- return
- }
- pptList, err := ppt_english.GetPptEnglishByIds(pptIds)
- if err != nil {
- err = errors.New("查询ppt详情出错:" + err.Error())
- return
- }
- for _, v := range pptList {
- // 解决部分历史ppt数据不存在TotalPages的情况
- if v.PptPage == 0 {
- var pptContent []services.PPTContent
- err = json.Unmarshal([]byte(v.Content), &pptContent)
- if err != nil {
- err = errors.New("解析ppt内容出错" + err.Error())
- return
- }
- v.PptPage = len(pptContent)
- }
- pptMap[v.PptId] = v
- }
- //按照排序顺序,依次放入ppt
- hasPpt := make(map[int]struct{})
- for _, v := range groups {
- if mapList, ok := groupMap[v.GroupId]; ok {
- if len(mapList) > 0 {
- for _, pptV := range mapList {
- pptInfo, ok1 := pptMap[int(pptV.PptId)]
- _, ok2 := hasPpt[int(pptV.PptId)]
- if ok1 && !ok2 {
- tmp := &ppt_english.RespGroupPptListItem{
- GroupPptId: pptV.GroupPptId,
- PptId: pptV.PptId,
- TemplateType: pptInfo.TemplateType,
- BackgroundImg: pptInfo.BackgroundImg,
- Title: pptInfo.Title,
- AdminId: pptV.AdminId,
- AdminRealName: pptV.AdminRealName,
- IsSingleShare: 0,
- PptCreateTime: pptInfo.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: pptInfo.ModifyTime.Format(utils.FormatDateTime),
- PptxUrl: pptInfo.PptxUrl,
- ReportId: pptInfo.ReportId,
- ReportCode: pptInfo.ReportCode,
- PublishTime: utils.DealDateTimeZero(pptInfo.PublishTime, utils.FormatDateTime),
- PptPage: pptInfo.PptPage,
- }
- if pptV.ChildGroupPptId > 0 {
- tmp.IsSingleShare = 1
- }
- list = append(list, tmp)
- hasPpt[pptInfo.PptId] = struct{}{}
- }
- }
- }
- }
- }
- ret.List = list
- if groupId <= 0 {
- sort.Sort(ret)
- }
- ret.Total = len(list)
- return
- }
- // MoveGroupPptEnglish 移动ppt操作
- func MoveGroupPptEnglish(groupId, groupPptId, prevGroupPptId, nextGroupPptId int64, adminId int) (err error) {
- //查询当前映射是否存在
- //判断当前登录者是否有共享的权限oo
- groupPpt, err := ppt_english.GetPptMappingByGroupPptId(groupPptId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("当前目录下的ppt不存在")
- return
- }
- err = errors.New("目录下的ppt查询出错:" + err.Error())
- return
- }
- var updateStr []string
- //如果更换了目录,默认当前排序值为0
- var currentSort, prevSort, nextSort int64
- //判断是否更换group
- if groupPpt.GroupId != groupId {
- _, err = ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //判断是否需要解除当个ppt共享
- //解除共享操作
- err = CancelShareSingleGroupPptEnglish(groupPpt, adminId)
- if err != nil {
- err = errors.New(err.Error())
- return
- }
- groupPpt.GroupId = groupId
- updateStr = append(updateStr, "group_id")
- }
- currentSort = groupPpt.PptSort
- var prevGroupPpt *ppt_english.PptEnglishGroupMapping
- var nextGroupPpt *ppt_english.PptEnglishGroupMapping
- if prevGroupPptId > 0 {
- prevGroupPpt, err = ppt_english.GetPptMappingByGroupPptId(prevGroupPptId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录下的ppt不存在")
- return
- }
- err = errors.New("目录下的ppt查询出错:" + err.Error())
- return
- }
- prevSort = prevGroupPpt.PptSort
- }
- if nextGroupPptId > 0 {
- nextGroupPpt, err = ppt_english.GetPptMappingByGroupPptId(nextGroupPptId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录下的ppt不存在")
- return
- }
- err = errors.New("目录下的ppt查询出错:" + err.Error())
- return
- }
- nextSort = nextGroupPpt.PptSort
- }
- updateStr = append(updateStr, "ppt_sort")
- //移到两个排序值中间操作
- if prevSort >= currentSort {
- //往下移动
- err = ppt_english.MoveDownGroupPptBySort(groupId, prevSort, currentSort)
- if err != nil {
- err = errors.New("向下移动ppt出错:" + err.Error())
- return
- }
- groupPpt.PptSort = prevSort
- } else if nextSort <= currentSort && nextSort != 0 {
- //往上移动
- err = ppt_english.MoveUpGroupPptBySort(groupId, nextSort, currentSort)
- if err != nil {
- err = errors.New("向上移动ppt出错:" + err.Error())
- return
- }
- groupPpt.PptSort = nextSort
- }
- //更新当前排序
- err = groupPpt.Update(updateStr)
- if err != nil {
- err = errors.New("移动ppt出错:" + err.Error())
- return
- }
- return
- }
- // MoveEnglishGroup 移动目录
- func MoveEnglishGroup(groupId, prevGroupId, nextGroupId int64, adminId int) (err error) {
- //查询目录是否存在
- groupInfo, err := ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //如果更换了目录,默认当前排序值为0
- var currentSort, prevSort, nextSort int64
- currentSort = groupInfo.GroupSort
- var prevGroup *ppt_english.PptEnglishGroup
- var nextGroup *ppt_english.PptEnglishGroup
- if prevGroupId > 0 {
- prevGroup, err = ppt_english.GetPptGroupByGroupIdAdminId(prevGroupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- prevSort = prevGroup.GroupSort
- }
- if nextGroupId > 0 {
- nextGroup, err = ppt_english.GetPptGroupByGroupIdAdminId(nextGroupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- nextSort = nextGroup.GroupSort
- }
- //移到两个排序值中间操作
- if prevSort >= currentSort {
- //往下移动
- err = ppt_english.MoveDownGroupBySort(prevSort, currentSort)
- if err != nil {
- err = errors.New("向下移动ppt出错:" + err.Error())
- return
- }
- groupInfo.GroupSort = prevSort
- } else if nextSort <= currentSort && nextSort != 0 {
- //往上移动
- err = ppt_english.MoveUpGroupBySort(nextSort, currentSort)
- if err != nil {
- err = errors.New("向上移动ppt出错:" + err.Error())
- return
- }
- groupInfo.GroupSort = nextSort
- }
- //更新当前排序
- err = groupInfo.Update([]string{"group_sort"})
- if err != nil {
- err = errors.New("移动目录出错:" + err.Error())
- return
- }
- return
- }
- // CancelShareSingleGroupPptEnglish 解除单个共享的ppt
- func CancelShareSingleGroupPptEnglish(groupPpt *ppt_english.PptEnglishGroupMapping, adminId int) (err error) {
- if groupPpt.ChildGroupPptId <= 0 {
- return
- }
- //如果已经是共享状态,
- //判断当前登录者是否有取消共享的权限
- childGroupPpt, tErr := ppt_english.GetPptMappingByGroupPptId(groupPpt.ChildGroupPptId, adminId)
- if tErr != nil {
- if tErr.Error() != utils.ErrNoRow() {
- err = errors.New("目录下的ppt查询出错:" + tErr.Error())
- return
- }
- }
- if childGroupPpt != nil {
- //删除共享目录和ppt的映射关系
- err = ppt_english.DeletePptGroupMapping(childGroupPpt.GroupPptId, adminId)
- if err != nil {
- err = errors.New("删除共享目录下的ppt失败:" + err.Error())
- return
- }
- //删除共享出去的公共目录
- err = ppt_english.DeletePptGroup(childGroupPpt.GroupId)
- if err != nil {
- err = errors.New("删除共享目录失败:" + err.Error())
- return
- }
- }
- //更新共享状态为未共享,
- //更新共享标识
- groupPpt.ChildGroupPptId = 0
- err = groupPpt.Update([]string{"child_group_ppt_id"})
- if err != nil {
- err = errors.New("更新共享标识失败" + err.Error())
- return
- }
- return
- }
- // DeleteGroupPptEnglish 删除ppt
- func DeleteGroupPptEnglish(PptId int) (err error) {
- //查询该ppt的所有单个共享出去的目录信息
- groupPpts, err := ppt_english.GetGroupPptByPptId(PptId)
- if err != nil {
- err = errors.New("查询目录里的ppt失败" + err.Error())
- return
- }
- if len(groupPpts) <= 0 {
- return
- }
- //整理出需要删除的groupId
- groupPptMap := make(map[int64]*ppt_english.PptEnglishGroupMapping)
- for _, v := range groupPpts {
- groupPptMap[v.GroupPptId] = v
- }
- var delGroupIds string
- for _, v := range groupPpts {
- if v.ChildGroupPptId > 0 {
- if childGroup, ok := groupPptMap[v.ChildGroupPptId]; ok {
- delGroupIds += strconv.Itoa(int(childGroup.GroupId)) + ","
- }
- }
- }
- if delGroupIds != "" {
- delGroupIds = "(" + strings.Trim(delGroupIds, ",") + ")"
- err = ppt_english.DeletePptGroupByGroupIds(delGroupIds)
- if err != nil {
- err = errors.New("删除单个共享目录失败" + err.Error())
- return
- }
- }
- //再统一删除目录里相关的ppt
- err = ppt_english.DeletePptGroupMappingByPptId(PptId)
- if err != nil {
- err = errors.New("删除目录里的ppt失败" + err.Error())
- return
- }
- return
- }
- // CopyPptEnglish 复制单个ppt,并移动到新的目录下面
- func CopyPptEnglish(pptId int, groupId int64, adminId int, adminRealName string) (resp ppt_english.RespGroupPptNameListItem, err error) {
- //查询ppt详情
- pptInfo, err := ppt_english.GetPptEnglishById(pptId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("ppt 不存在")
- return
- }
- err = errors.New("查询ppt失败" + err.Error())
- return
- }
- // 查询目录是否存在
- _, err = ppt_english.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- pptNames, err := ppt_english.GetAllPptTitle()
- if err != nil {
- err = errors.New("查询ppt标题出错:" + err.Error())
- return
- }
- //复制ppt,更新作者为当前账号,并返回新的pptID
- var newPptList []*ppt_english.PptEnglish
- newPpt := &ppt_english.PptEnglish{
- TemplateType: pptInfo.TemplateType,
- BackgroundImg: pptInfo.BackgroundImg,
- Title: generateCopyName(pptInfo.Title, 1, pptNames),
- ReportType: pptInfo.ReportType,
- PptDate: pptInfo.PptDate,
- Content: pptInfo.Content,
- CoverContent: pptInfo.CoverContent,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- TitleSetting: pptInfo.TitleSetting,
- }
- newPptList = append(newPptList, newPpt)
- err = ppt_english.AddPptEnglishMulti(newPptList)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- var newMappings []*ppt_english.PptEnglishGroupMapping
- newGroupPpt := &ppt_english.PptEnglishGroupMapping{
- GroupId: groupId,
- PptId: int64(newPpt.PptId),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- }
- newMappings = append(newMappings, newGroupPpt)
- err = ppt_english.AddPptGroupMappingMulti(newMappings)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- //批量更新排序字段
- err = ppt_english.UpdatePptGroupMappingSortMulti([]int64{newGroupPpt.GroupPptId})
- if err != nil {
- err = errors.New("更新排序标识出错:" + err.Error())
- return
- }
- var pptPage int
- if newPpt.Content != "" {
- contents := make([]PageContent, 0)
- if e := json.Unmarshal([]byte(newPpt.Content), &contents); e != nil {
- err = errors.New(fmt.Sprintf("%d,解析PPT内容页数失败: %s", newPpt.PptId, e.Error()))
- return
- }
- pptPage = len(contents)
- }
- resp = ppt_english.RespGroupPptNameListItem{
- GroupPptId: newGroupPpt.GroupPptId,
- PptId: int64(newPpt.PptId),
- Title: newPpt.Title,
- AdminId: newPpt.AdminId,
- AdminRealName: newPpt.AdminRealName,
- PptCreateTime: newPpt.CreateTime.Format(utils.FormatDateTime),
- PptPage: pptPage,
- TitleSetting: newPpt.TitleSetting,
- }
- return
- }
- // generateCopyNameEnglish 生成复制的目录名称
- func generateCopyNameEnglish(originName string, count int, nameList []string) (newName string) {
- newName = originName + "(" + strconv.Itoa(count) + ")"
- for _, v := range nameList {
- if v == newName {
- count++
- newName = generateCopyName(originName, count, nameList)
- return
- }
- }
- return
- }
- // SearchGroupPptEnglish 根据ppt标题搜索ppt
- func SearchGroupPptEnglish(keyWord string) (ret ppt_english.RespSearchGroupPptList, err error) {
- //组装group ppt
- list := make([]*ppt_english.RespSearchGroupPptListItem, 0)
- ret.List = list
- condition := " and title like ? "
- var pars []interface{}
- pars = append(pars, utils.GetLikeKeyword(keyWord))
- pptList, err := ppt_english.GetPptEnglishByCondition(condition, pars)
- if err != nil {
- err = errors.New("查询ppt列表出错:" + err.Error())
- return
- }
- if len(pptList) == 0 {
- return
- }
- pptIds := make([]string, 0)
- pptMap := make(map[int]*ppt_english.PptEnglish)
- for _, v := range pptList {
- pptIds = append(pptIds, strconv.Itoa(v.PptId))
- pptMap[v.PptId] = v
- }
- groupPptList, err := ppt_english.GetPublicGroupPptByPptIds(pptIds)
- if err != nil {
- err = errors.New("查询目录里的ppt列表出错:" + err.Error())
- return
- }
- for _, v := range groupPptList {
- tmp := new(ppt_english.RespSearchGroupPptListItem)
- tmp.GroupPptId = v.GroupPptId
- tmp.PptId = v.PptId
- if i, ok := pptMap[int(v.PptId)]; ok {
- tmp.Title = i.Title
- }
- list = append(list, tmp)
- }
- ret.List = list
- return
- }
- func GetEnglishGroupsByAdminId(adminId int) (ret ppt_english.RespGroupList, err error) {
- myPptList := make([]*ppt_english.RespGroupPptNameListItem, 0)
- otherPptList := make([]*ppt_english.RespGroupPptNameListItem, 0)
- grantList := []ppt_english.RespGroupListItem{
- {
- GroupId: 1,
- GroupName: "我共享的",
- PptList: myPptList,
- },
- {
- GroupId: 2,
- GroupName: "收到共享",
- PptList: otherPptList,
- },
- }
- ret.PublicList = make([]*ppt_english.RespGroupListItem, 0)
- ret.PrivateList = make([]*ppt_english.RespGroupListItem, 0)
- ret.GrantList = grantList
- pptMap := make(map[int]*ppt_english.PptEnglish)
- groupMap := make(map[int64][]*ppt_english.RespGroupPptNameListItem)
- groupHasNewPptMap := make(map[int64]struct{})
- pptIds := make([]int, 0)
- // 获取我的ppt分组
- privateGroups, err := ppt_english.GetPrivatePptGroupsByAdminId(adminId)
- if err != nil {
- err = errors.New("私有目录查询出错:" + err.Error())
- return
- }
- groupIds := make([]int64, 0)
- for _, v := range privateGroups {
- groupIds = append(groupIds, v.GroupId)
- }
- var pptMappings []*ppt_english.PptEnglishGroupMapping
- // 如果没有分组,那么直接返回
- if len(groupIds) > 0 {
- // 遍历分组并拼接
- for _, v := range privateGroups {
- tmp := new(ppt_english.RespGroupListItem)
- tmp.GroupId = v.GroupId
- tmp.GroupName = v.GroupName
- tmp.IsShare = v.IsShare
- tmp.AdminId = v.AdminId
- ret.PrivateList = append(ret.PrivateList, tmp)
- }
- // 通过分组id获取相关的ppt信息,主要是为了获取所有的ppt_id字段
- pptMappings, err = ppt_english.GetPptMappingListByGroupIds(groupIds)
- if err != nil {
- err = errors.New("查询目录里的ppt出错:" + err.Error())
- return
- }
- for _, v := range pptMappings {
- pptIds = append(pptIds, int(v.PptId))
- }
- }
- adminIdList := make([]int, 0) //需要查询的创建人admin_id列表集合
- adminIdMap := make(map[int]int) //需要查询的创建人admin_id集合,用来去重的,避免重复id
- // grantList 已经分配权限的ppt
- grantPptList, err := ppt_english.GetAllGrantList(adminId)
- for _, v := range grantPptList {
- pptIds = append(pptIds, v.PptId)
- if _, ok := adminIdMap[v.AdminId]; !ok {
- adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
- adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
- }
- }
- if len(pptIds) > 0 {
- // 通过ppt_id列表字段获取所有的ppt信息
- pptList, tmpErr := ppt_english.GetPptEnglishByIds(pptIds)
- if tmpErr != nil {
- err = errors.New("查询ppt详情出错:" + err.Error())
- return
- }
- for _, v := range pptList {
- pptMap[v.PptId] = v
- }
- }
- // 私有的Ppt列表
- {
- //组装group ppt
- for _, v := range pptMappings {
- i, ok := pptMap[int(v.PptId)]
- if !ok { //找不到ppt,还干个啥,直接退出当前循环啊
- continue
- }
- pptPage := 0
- // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
- if i.Content != "" {
- contents := make([]PageContent, 0)
- if e := json.Unmarshal([]byte(i.Content), &contents); e != nil {
- err = errors.New(fmt.Sprintf("%d,解析PPT内容页数失败: %s", i.PptId, e.Error()))
- return
- }
- pptPage = len(contents)
- }
- tmp := &ppt_english.RespGroupPptNameListItem{
- AdminId: v.AdminId,
- GroupPptId: v.GroupPptId,
- PptId: v.PptId,
- AdminRealName: v.AdminRealName,
- Title: i.Title,
- IsSingleShare: i.IsShare,
- PptxUrl: i.PptxUrl,
- ReportId: i.ReportId,
- ReportCode: i.ReportCode,
- PptCreateTime: i.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: i.ModifyTime.Format(utils.FormatDateTime),
- PublishTime: utils.DealDateTimeZero(i.PublishTime, utils.FormatDateTime),
- PptPage: pptPage,
- }
- if tmp.PptVersion == 2 {
- groupHasNewPptMap[v.GroupId] = struct{}{}
- }
- groupMap[v.GroupId] = append(groupMap[v.GroupId], tmp)
- }
- for k, v := range ret.PrivateList {
- if pptL, ok := groupMap[v.GroupId]; ok {
- ret.PrivateList[k].PptList = pptL
- if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
- ret.PrivateList[k].OnlyOld = true
- }
- }
- }
- }
- publicAdminIdList := make([]int, 0)
- publicPptListMap := make(map[int][]*ppt_english.RespGroupPptNameListItem)
- // 获取公开分享的ppt
- sharePptList, err := ppt_english.GetSharePptEnglish()
- for _, v := range sharePptList {
- publicPptList, ok := publicPptListMap[v.AdminId]
- if !ok {
- publicPptList = make([]*ppt_english.RespGroupPptNameListItem, 0)
- publicAdminIdList = append(publicAdminIdList, v.AdminId)
- // 需要查询的创建人信息
- if _, ok := adminIdMap[v.AdminId]; !ok {
- adminIdList = append(adminIdList, v.AdminId) //需要查询的创建人admin_id列表集合
- adminIdMap[v.AdminId] = v.AdminId //需要查询的创建人admin_id集合,用来去重的,避免重复id
- }
- }
- contents := make([]PageContent, 0)
- if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
- err = errors.New("解析PPT内容页数失败: " + e.Error())
- return
- }
- pptPage := len(contents)
- tmpV := &ppt_english.RespGroupPptNameListItem{
- GroupPptId: int64(v.PptId),
- PptId: int64(v.PptId),
- Title: v.Title,
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- IsSingleShare: v.IsShare,
- PptxUrl: v.PptxUrl,
- ReportId: v.ReportId,
- ReportCode: v.ReportCode,
- PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
- PptPage: pptPage,
- }
- publicPptList = append(publicPptList, tmpV)
- publicPptListMap[v.AdminId] = publicPptList
- }
- // 创建人信息
- systemAdminMap := make(map[int]*system.Admin)
- systemAdminList, err := system.GetAdminListByIdList(adminIdList)
- if err != nil {
- return
- }
- for _, v := range systemAdminList {
- systemAdminMap[v.AdminId] = v
- }
- // 公开分享的用户列表
- {
- for _, v := range publicAdminIdList {
- systemAdmin, ok := systemAdminMap[v]
- if !ok {
- continue
- }
- // ppt 列表信息
- respGroupPptNameListItemList, ok := publicPptListMap[v]
- if !ok {
- respGroupPptNameListItemList = make([]*ppt_english.RespGroupPptNameListItem, 0)
- }
- // ppt 分组信息
- tmpRespGroupListItem := &ppt_english.RespGroupListItem{
- GroupId: int64(systemAdmin.AdminId),
- GroupName: systemAdmin.RealName + "的PPT",
- AdminId: systemAdmin.AdminId,
- IsShare: 1,
- OnlyOld: false,
- PptList: respGroupPptNameListItemList,
- }
- ret.PublicList = append(ret.PublicList, tmpRespGroupListItem)
- }
- }
- myGrantPPtIdMap := make(map[int]int) //我分配的ppt的id集合
- // 共享Ppt
- {
- for _, v := range grantPptList {
- pptPage := 0
- // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
- if v.Content != "" {
- contents := make([]PageContent, 0)
- if e := json.Unmarshal([]byte(v.Content), &contents); e != nil {
- err = errors.New("解析PPT内容页数失败: " + e.Error())
- return
- }
- }
- title := v.Title
- if adminInfo, ok := systemAdminMap[v.AdminId]; ok {
- title = adminInfo.RealName + "———" + title
- }
- tmp := &ppt_english.RespGroupPptNameListItem{
- AdminId: v.AdminId,
- //GroupPptId: v.GroupPptId,
- PptId: int64(v.PptId),
- AdminRealName: v.AdminRealName,
- Title: title,
- PptVersion: v.PptVersion,
- IsSingleShare: v.IsShare,
- PptxUrl: v.PptxUrl,
- ReportId: v.ReportId,
- ReportCode: v.ReportCode,
- PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
- PptPage: pptPage,
- }
- if v.AdminId == adminId {
- tmp.IsGrant = 1
- myPptList = append(myPptList, tmp)
- myGrantPPtIdMap[v.PptId] = v.PptId
- } else {
- tmp.IsReceived = 1
- otherPptList = append(otherPptList, tmp)
- }
- }
- grantList[0].PptList = myPptList
- grantList[1].PptList = otherPptList
- ret.GrantList = grantList
- }
- // 处理公共ppt里面的关于自个的ppt是否有配置权限的字段数据变更
- for k, publicList := range ret.PublicList {
- for kk, pptInfo := range publicList.PptList {
- // 是否有过权限配置
- if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
- pptInfo.IsGrant = 1
- }
- publicList.PptList[kk] = pptInfo
- }
- ret.PublicList[k] = publicList
- }
- for k, privateList := range ret.PrivateList {
- for kk, pptInfo := range privateList.PptList {
- // 是否有过权限配置
- if _, ok := myGrantPPtIdMap[int(pptInfo.PptId)]; ok {
- pptInfo.IsGrant = 1
- }
- privateList.PptList[kk] = pptInfo
- }
- ret.PrivateList[k] = privateList
- }
- return
- //则过滤空文件夹
- //公共ppt
- pubList := make([]*ppt_english.RespGroupListItem, 0)
- for _, v := range ret.PublicList {
- if len(v.PptList) > 0 {
- pubList = append(pubList, v)
- }
- }
- ret.PublicList = pubList
- // 私有ppt
- priList := make([]*ppt_english.RespGroupListItem, 0)
- for _, v := range ret.PrivateList {
- if len(v.PptList) > 0 {
- priList = append(priList, v)
- }
- }
- ret.PrivateList = priList
- return
- }
- // ShareSingleGroupPptEnglishEnglish 共享单个ppt/取消共享单个ppt,返回共享状态
- // @Author roc
- // @Time 2022-08-29 15:22:20
- func ShareSingleGroupPptEnglish(pptId int, adminId int) (pptInfo *ppt_english.PptEnglish, err error) {
- //判断当前登录者是否有共享的权限
- pptInfo, err = ppt_english.GetPptEnglishById(pptId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("当前目录下的ppt不存在")
- return
- }
- err = errors.New("目录下的ppt查询出错:" + err.Error())
- return
- }
- if pptInfo.AdminId != adminId {
- err = errors.New("该Ppt不是本人创建")
- return
- }
- //判断当前的共享状态
- if pptInfo.IsShare > 0 {
- pptInfo.IsShare = 0
- err = pptInfo.Update([]string{"IsShare"})
- if err != nil {
- err = errors.New(err.Error())
- return
- }
- } else {
- pptInfo.IsShare = 1
- err = pptInfo.Update([]string{"IsShare"})
- if err != nil {
- err = errors.New(err.Error())
- return
- }
- }
- return
- }
- func GetMyPptEnglishList(adminId int, keyword string) (ret ppt_english.RespGroupPptList, err error) {
- list := make([]*ppt_english.RespGroupPptListItem, 0)
- ret.List = list
- var condition string
- var pars []interface{}
- condition += ` AND admin_id=? `
- pars = append(pars, adminId)
- if keyword != `` {
- condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- pptList, err := ppt_english.GetAllPptEnglishList(condition, pars)
- if len(pptList) <= 0 {
- return
- }
- var pptContent []services.PPTContent
- for _, v := range pptList {
- if v.PptPage == 0 {
- err = json.Unmarshal([]byte(v.Content), &pptContent)
- if err != nil {
- return
- }
- v.PptPage = len(pptContent)
- }
- tmpV := &ppt_english.RespGroupPptListItem{
- GroupPptId: int64(v.PptId),
- PptId: int64(v.PptId),
- TemplateType: v.TemplateType,
- BackgroundImg: v.BackgroundImg,
- Title: v.Title,
- PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- IsSingleShare: v.IsShare,
- PptxUrl: v.PptxUrl,
- ReportId: v.ReportId,
- ReportCode: v.ReportCode,
- PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
- PptPage: v.PptPage,
- }
- list = append(list, tmpV)
- }
- ret.List = list
- ret.Total = len(list)
- return
- }
- // GetSharePptList 公共目录下的ppt列表
- // @Author roc
- // @Time 2022-08-29 16:27:59
- func GetSharePptEnglishList(adminId int, keyword string, isPrivate bool) (ret ppt_english.RespGroupPptList, err error) {
- list := make([]*ppt_english.RespGroupPptListItem, 0)
- ret.List = list
- var condition string
- var pars []interface{}
- // 公开的ppt
- condition += ` AND is_share=? `
- if isPrivate {
- pars = append(pars, 0)
- } else {
- pars = append(pars, 1)
- }
- if adminId > 0 {
- condition += ` AND admin_id=? `
- pars = append(pars, adminId)
- }
- if keyword != `` {
- condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- pptList, err := ppt_english.GetAllPptEnglishList(condition, pars)
- if len(pptList) <= 0 {
- return
- }
- var pptContent []services.PPTContent
- for _, v := range pptList {
- if v.PptPage == 0 {
- err = json.Unmarshal([]byte(v.Content), &pptContent)
- if err != nil {
- return
- }
- v.PptPage = len(pptContent)
- }
- tmpV := &ppt_english.RespGroupPptListItem{
- GroupPptId: int64(v.PptId),
- PptId: int64(v.PptId),
- TemplateType: v.TemplateType,
- BackgroundImg: v.BackgroundImg,
- Title: v.Title,
- PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- IsSingleShare: v.IsShare,
- PptxUrl: v.PptxUrl,
- ReportId: v.ReportId,
- ReportCode: v.ReportCode,
- PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
- PptPage: v.PptPage,
- }
- list = append(list, tmpV)
- }
- ret.List = list
- ret.Total = len(list)
- return
- }
- // GetGrantPptList 公共目录下的ppt列表
- // @Author roc
- // @Time 2022-09-05 15:50:25
- func GetGrantPptEnglishList(adminId int, keyword, sourceType string) (ret ppt_english.RespGroupPptList, err error) {
- list := make([]*ppt_english.RespGroupPptListItem, 0)
- ret.List = list
- var condition string
- var pars []interface{}
- switch sourceType {
- case "my":
- condition += ` AND a.admin_id = ? `
- pars = append(pars, adminId)
- case "other":
- condition += ` AND a.admin_id != ? AND (b.department_id = 1 OR b.grant_admin_id = ?) `
- pars = append(pars, adminId, adminId)
- default:
- err = errors.New("无效的来源")
- return
- }
- if keyword != `` {
- condition += ` AND a.title LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyword, 1)
- }
- pptList, err := ppt_english.GetGrantList(condition, pars)
- if err != nil {
- return
- }
- if len(pptList) <= 0 {
- return
- }
- var pptContent []services.PPTContent
- for _, v := range pptList {
- if v.PptPage == 0 {
- err = json.Unmarshal([]byte(v.Content), &pptContent)
- if err != nil {
- return
- }
- v.PptPage = len(pptContent)
- }
- tmpV := &ppt_english.RespGroupPptListItem{
- GroupPptId: int64(v.PptId),
- PptId: int64(v.PptId),
- TemplateType: v.TemplateType,
- BackgroundImg: v.BackgroundImg,
- Title: v.Title,
- PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
- PptModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- PptVersion: v.PptVersion,
- IsSingleShare: v.IsShare,
- PptxUrl: v.PptxUrl,
- ReportId: v.ReportId,
- ReportCode: v.ReportCode,
- PublishTime: utils.DealDateTimeZero(v.PublishTime, utils.FormatDateTime),
- PptPage: v.PptPage,
- }
- list = append(list, tmpV)
- }
- ret.List = list
- ret.Total = len(list)
- return
- }
- // GetEnglishCopyUsableTitle 根据原标题获取复制/转换可用的标题
- func GetEnglishCopyUsableTitle(title string) (newTitle string, err error) {
- if title == "" {
- return
- }
- // 标题列表
- titles, e := ppt_english.GetPPTTitleList()
- if e != nil {
- err = errors.New("获取英文PPT标题列表失败, Err: " + e.Error())
- return
- }
- if !utils.InArrayByStr(titles, title) {
- newTitle = title
- return
- }
- // 新标题
- titleFormat := title + "(%d)"
- for i := 1; i < 999; i++ {
- newTitle = fmt.Sprintf(titleFormat, i)
- if !utils.InArrayByStr(titles, newTitle) {
- return
- }
- }
- return
- }
- // SearchEnglishPptList PPT搜索(我的/公开PPT)
- func SearchEnglishPptList(adminId int, keyword string) (ret ppt_english.RespGroupPptList, err error) {
- list := make([]*ppt_english.RespGroupPptListItem, 0)
- ret.List = list
- var condition string
- var pars []interface{}
- // 公开的PPT或是我的非公开PPT
- condition += ` AND (is_share = 1 OR (admin_id = ? AND is_share = 0)) `
- pars = append(pars, adminId)
- if keyword != `` {
- kw := fmt.Sprint("%", keyword, "%")
- condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
- pars = append(pars, kw, kw)
- }
- pptList, err := ppt_english.GetAllPptEnglishList(condition, pars)
- if len(pptList) <= 0 {
- return
- }
- var pptContent []services.PPTContent
- for _, v := range pptList {
- if v.PptPage == 0 {
- err = json.Unmarshal([]byte(v.Content), &pptContent)
- if err != nil {
- return
- }
- v.PptPage = len(pptContent)
- }
- tmpV := &ppt_english.RespGroupPptListItem{
- GroupPptId: int64(v.PptId),
- PptId: int64(v.PptId),
- TemplateType: v.TemplateType,
- BackgroundImg: v.BackgroundImg,
- Title: v.Title,
- PptCreateTime: v.CreateTime.Format(utils.FormatDateTime),
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- IsSingleShare: v.IsShare,
- PptxUrl: v.PptxUrl,
- ReportId: v.ReportId,
- ReportCode: v.ReportCode,
- PptPage: v.PptPage,
- }
- list = append(list, tmpV)
- }
- ret.List = list
- ret.Total = len(list)
- return
- }
|