12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817 |
- package ppt
- import (
- "encoding/json"
- "errors"
- "eta/eta_api/models"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- type PageContent struct {
- //Id int `json:"id"`
- Key int `json:"key"`
- ModelId int `json:"modelId"`
- Title string `json:"title"`
- Elements []PageContentElements `json:"elements"`
- }
- type PageContentElements struct {
- Type string `json:"type"`
- Position int `json:"position"`
- Content string `json:"content"`
- RichContent string `json:"richContent"`
- ChartId string `json:"chartId"`
- Src string `json:"src"`
- }
- // GetGroupsByAdminId 查询ppt目录列表
- func GetGroupsByAdminId(IsNewPpt, adminId int) (ret models.RespGroupList, err error) {
- publicGroups, err := models.GetPublicPptGroups()
- if err != nil {
- err = errors.New("公共目录查询出错:" + err.Error())
- return
- }
- privateGroups, err := models.GetPrivatePptGroups(adminId)
- if err != nil {
- err = errors.New("私有目录查询出错:" + err.Error())
- return
- }
- groupIds := make([]int64, 0)
- for _, v := range publicGroups {
- groupIds = append(groupIds, v.GroupId)
- }
- for _, v := range privateGroups {
- groupIds = append(groupIds, v.GroupId)
- }
- ret.PublicList = make([]*models.RespGroupListItem, 0)
- ret.PrivateList = make([]*models.RespGroupListItem, 0)
- if len(groupIds) == 0 {
- return
- }
- //整理目录数据
- for _, v := range publicGroups {
- tmp := new(models.RespGroupListItem)
- tmp.GroupId = v.GroupId
- tmp.GroupName = v.GroupName
- tmp.IsShare = v.IsShare
- tmp.AdminId = v.AdminId
- ret.PublicList = append(ret.PublicList, tmp)
- }
- for _, v := range privateGroups {
- if v.IsShareAdd == 1 {
- continue
- } else {
- tmp := new(models.RespGroupListItem)
- tmp.GroupId = v.GroupId
- tmp.GroupName = v.GroupName
- tmp.IsShare = v.IsShare
- tmp.AdminId = v.AdminId
- ret.PrivateList = append(ret.PrivateList, tmp)
- }
- }
- pptMappings, err := models.GetPptMappingListByGroupIds(groupIds)
- if err != nil {
- err = errors.New("查询目录里的ppt出错:" + err.Error())
- return
- }
- pptMap := make(map[int]*models.PptV2)
- groupMap := make(map[int64][]*models.RespGroupPptNameListItem)
- groupHasNewPptMap := make(map[int64]struct{})
- pptIds := make([]int, 0)
- for _, v := range pptMappings {
- pptIds = append(pptIds, int(v.PptId))
- }
- if len(pptIds) == 0 {
- // 返回所有空目录
- return
- }
- pptList, err := models.GetPptV2ByIds(pptIds)
- if err != nil {
- err = errors.New("查询ppt详情出错:" + err.Error())
- return
- }
- for _, v := range pptList {
- pptMap[v.PptId] = v
- }
- //组装group ppt
- for _, v := range pptMappings {
- tmp := new(models.RespGroupPptNameListItem)
- tmp.AdminId = v.AdminId
- tmp.GroupPptId = v.GroupPptId
- tmp.PptId = v.PptId
- if v.ChildGroupPptId > 0 {
- tmp.IsSingleShare = 1
- }
- if i, ok := pptMap[int(v.PptId)]; ok {
- // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
- if i.Content != "" {
- contents := make([]PageContent, 0)
- if e := json.Unmarshal([]byte(i.Content), &contents); e != nil {
- err = errors.New("解析PPT内容页数失败: " + e.Error())
- return
- }
- tmp.PptPage = len(contents)
- }
- tmp.Title = i.Title
- tmp.PptVersion = i.PptVersion
- tmp.PptxUrl = i.PptxUrl
- tmp.ReportId = i.ReportId
- tmp.ReportCode = i.ReportCode
- tmp.PptCreateTime = i.CreateTime.Format(utils.FormatDateTime)
- }
- tmp.AdminRealName = v.AdminRealName
- if tmp.PptVersion == 2 {
- groupHasNewPptMap[v.GroupId] = struct{}{}
- } else {
- if IsNewPpt == 1 { //如果只展示新版的ppt,则忽略旧版ppt
- continue
- }
- }
- groupMap[v.GroupId] = append(groupMap[v.GroupId], tmp)
- }
- for k, v := range ret.PublicList {
- if pptL, ok := groupMap[v.GroupId]; ok {
- ret.PublicList[k].PptList = pptL
- if _, ok1 := groupHasNewPptMap[v.GroupId]; !ok1 && len(pptL) > 0 {
- ret.PublicList[k].OnlyOld = true
- }
- }
- }
- 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
- }
- }
- }
- if IsNewPpt == 1 { //如果只展示新版ppt,则过滤空文件夹
- pubList := make([]*models.RespGroupListItem, 0)
- for _, v := range ret.PublicList {
- if len(v.PptList) > 0 {
- pubList = append(pubList, v)
- }
- }
- ret.PublicList = pubList
- priList := make([]*models.RespGroupListItem, 0)
- for _, v := range ret.PrivateList {
- if len(v.PptList) > 0 {
- priList = append(priList, v)
- }
- }
- ret.PrivateList = priList
- }
- return
- }
- // AddGroup 新增ppt目录
- func AddGroup(groupName string, adminId int, isShare int8, isSharedAdd int8) (newId int64, err error) {
- item, err := models.GetPptGroupByName(groupName, adminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- if item != nil {
- err = errors.New("目录名称已存在,不可重复添加")
- return
- }
- groupInfo := &models.PptV2Group{
- GroupName: groupName,
- AdminId: adminId,
- IsShare: isShare,
- IsShareAdd: isSharedAdd,
- }
- if isShare == 1 {
- groupInfo.ShareTime = time.Now()
- }
- newId, err = models.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
- }
- // AddGroupPptMapping 新增ppt和目录映射关系
- func AddGroupPptMapping(pptId int64, groupId int64, adminId int, adminRealName string) (newId int64, err error) {
- _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- bindInfo := &models.PptV2GroupMapping{
- GroupId: groupId,
- PptId: pptId,
- AdminId: adminId,
- AdminRealName: adminRealName,
- }
- newId, err = models.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
- }
- // DelGroup 删除ppt 目录
- func DelGroup(groupId int64, adminId int) (err error) {
- _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //查询是否有映射存在
- count, err := models.GetPptMappingCountByGroupId(groupId)
- if err != nil {
- err = errors.New("查询目录里的ppt个数出错:" + err.Error())
- return
- }
- if count > 0 {
- err = errors.New("该目录下有关联PPT,不允许删除")
- return
- }
- err = models.DeletePptGroup(groupId)
- if err != nil {
- err = errors.New("删除失败:" + err.Error())
- return
- }
- return
- }
- // ShareGroup 共享/取消共享目录
- func ShareGroup(groupId int64, adminId int) (respShare models.RespPptGroupShare, err error) {
- // 查询目录是否存在
- groupInfo, err := models.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
- }
- // CopyGroup 复制目录
- func CopyGroup(groupId int64, adminId int, adminRealName string) (err error) {
- //查询目录是否存在
- groupInfo, err := models.GetPptGroupByGroupId(groupId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //新增公共目录。目录名称在原来的基础上带上复制序号
- groupNames, err := models.GetPptGroupNamesByAdminId(adminId)
- if err != nil {
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- newGroupName := generateCopyName(groupInfo.GroupName, 1, groupNames)
- newGroupId, err := AddGroup(newGroupName, adminId, 0, 0)
- if err != nil {
- err = errors.New("复制目录出错:" + err.Error())
- return
- }
- //查询该目录下面是否存在ppt,如果存在则批量复制ppt到新目录下
- mappingList, err := models.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 := models.GetPptV2ByIds(pptIds)
- if err != nil {
- err = errors.New("查询ppt列表出错:" + err.Error())
- return
- }
- pptNames, err := models.GetAllPptTitle()
- if err != nil {
- err = errors.New("查询ppt标题出错:" + err.Error())
- return
- }
- //批量复制ppt,更新作者为当前账号,并返回新的pptID
- newPptList := make([]*models.PptV2, 0)
- for _, v := range pptList {
- if v.PptVersion != 2 { //只复制新版的ppt,旧版本的ppt忽略
- continue
- }
- tmp := &models.PptV2{
- TemplateType: v.TemplateType,
- BackgroundImg: v.BackgroundImg,
- Title: generateCopyName(v.Title, 1, pptNames),
- ReportType: v.ReportType,
- PptDate: v.PptDate,
- Content: v.Content,
- CoverContent: v.CoverContent,
- PptUrl: v.PptUrl,
- PptxUrl: v.PptxUrl,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- PptVersion: v.PptVersion,
- TitleSetting: v.TitleSetting,
- }
- newPptList = append(newPptList, tmp)
- }
- if len(newPptList) > 0 {
- err = models.AddPptV2Multi(newPptList)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- newMappings := make([]*models.PptV2GroupMapping, 0)
- for _, v := range newPptList {
- tmp := &models.PptV2GroupMapping{
- GroupId: newGroupId,
- PptId: int64(v.PptId),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- }
- newMappings = append(newMappings, tmp)
- }
- err = models.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 = models.UpdatePptGroupMappingSortMulti(newGroupPptIds)
- if err != nil {
- err = errors.New("更新排序标识出错:" + err.Error())
- return
- }
- }
- return
- }
- // RenameGroupName 目录重命名
- func RenameGroupName(groupId int64, groupName string, adminId int) (err error) {
- groupInfo, err := models.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 := models.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
- }
- // ShareSingleGroupPpt 共享单个ppt/取消共享单个ppt,返回共享状态
- func ShareSingleGroupPpt(groupPptId int64, adminId int, adminRealName string) (ret models.RespPptShare, err error) {
- //判断当前登录者是否有共享的权限
- groupPpt, err := models.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 := models.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 = CancelShareSingleGroupPpt(groupPpt, adminId)
- if err != nil {
- err = errors.New(err.Error())
- return
- }
- ret.IsSingleShare = 0
- } else {
- //如果是未共享状态,则共享该ppt,类似复制流程,并更新共享标识
- //新增公共目录。目录名称在原来的基础上带上复制序号
- groupNames, tErr := models.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
- }
- // GetGroupPptList 公共目录下的ppt列表或者单个目录里的ppt列表
- func GetGroupPptList(groupId int64, adminId int) (ret models.RespGroupPptList, err error) {
- var groupPptList []*models.PptV2GroupMapping
- var groups []*models.PptV2Group
- list := make([]*models.RespGroupPptListItem, 0)
- ret.List = list
- if groupId > 0 {
- //只查询组内的ppt列表
- //查询目录是否存在
- groupInfo, tErr := models.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 = models.GetPptMappingListByGroupId(groupId)
- if tErr != nil {
- err = errors.New("目录里的ppt查询出错:" + tErr.Error())
- return
- }
- } else {
- // 获取我的所有的ppt
- ret, err = GetMyPptList(adminId, ``)
- return
- ////查询所有公共目录下的ppt列表
- //var tErr error
- //groups, tErr = models.GetPublicPptGroups()
- //if tErr != nil {
- // err = errors.New("目录查询出错:" + tErr.Error())
- // return
- //}
- ////查询这些目录下的所有ppt
- //groupIds := make([]int64, 0)
- //for _, v := range groups {
- // groupIds = append(groupIds, v.GroupId)
- //}
- //
- //groupPptList, tErr = models.GetPptMappingListByGroupIds(groupIds)
- //if tErr != nil {
- // err = errors.New("目录里的ppt查询出错:" + tErr.Error())
- // return
- //}
- }
- if len(groupPptList) <= 0 {
- return
- }
- pptMap := make(map[int]*models.PptV2)
- groupMap := make(map[int64][]*models.PptV2GroupMapping)
- 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 := models.GetPptV2ByIds(pptIds)
- if err != nil {
- err = errors.New("查询ppt详情出错:" + err.Error())
- return
- }
- for _, v := range pptList {
- if v.PptPage == 0 && v.Content != "" {
- 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 := &models.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,
- PptVersion: pptInfo.PptVersion,
- 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
- }
- // MoveGroupPpt 移动ppt操作
- func MoveGroupPpt(groupId, groupPptId, prevGroupPptId, nextGroupPptId int64, adminId int) (err error) {
- //查询当前映射是否存在
- //判断当前登录者是否有共享的权限oo
- groupPpt, err := models.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 = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- //判断是否需要解除当个ppt共享
- //解除共享操作
- err = CancelShareSingleGroupPpt(groupPpt, adminId)
- if err != nil {
- err = errors.New(err.Error())
- return
- }
- groupPpt.GroupId = groupId
- updateStr = append(updateStr, "group_id")
- }
- currentSort = groupPpt.PptSort
- var prevGroupPpt *models.PptV2GroupMapping
- var nextGroupPpt *models.PptV2GroupMapping
- if prevGroupPptId > 0 {
- prevGroupPpt, err = models.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 = models.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 = models.MoveDownGroupPptBySort(groupId, prevSort, currentSort)
- if err != nil {
- err = errors.New("向下移动ppt出错:" + err.Error())
- return
- }
- groupPpt.PptSort = prevSort
- } else if nextSort <= currentSort && nextSort != 0 {
- //往上移动
- err = models.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
- }
- // MoveGroup 移动目录
- func MoveGroup(groupId, prevGroupId, nextGroupId int64, adminId int) (err error) {
- //查询目录是否存在
- groupInfo, err := models.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 *models.PptV2Group
- var nextGroup *models.PptV2Group
- if prevGroupId > 0 {
- prevGroup, err = models.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 = models.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 = models.MoveDownGroupBySort(prevSort, currentSort)
- if err != nil {
- err = errors.New("向下移动ppt出错:" + err.Error())
- return
- }
- groupInfo.GroupSort = prevSort
- } else if nextSort <= currentSort && nextSort != 0 {
- //往上移动
- err = models.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
- }
- // CancelShareSingleGroupPpt 解除单个共享的ppt
- func CancelShareSingleGroupPpt(groupPpt *models.PptV2GroupMapping, adminId int) (err error) {
- if groupPpt.ChildGroupPptId <= 0 {
- return
- }
- //如果已经是共享状态,
- //判断当前登录者是否有取消共享的权限
- childGroupPpt, tErr := models.GetPptMappingByGroupPptId(groupPpt.ChildGroupPptId, adminId)
- if tErr != nil {
- if tErr.Error() != utils.ErrNoRow() {
- err = errors.New("目录下的ppt查询出错:" + tErr.Error())
- return
- }
- }
- if childGroupPpt != nil {
- //删除共享目录和ppt的映射关系
- err = models.DeletePptGroupMapping(childGroupPpt.GroupPptId, adminId)
- if err != nil {
- err = errors.New("删除共享目录下的ppt失败:" + err.Error())
- return
- }
- //删除共享出去的公共目录
- err = models.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
- }
- // DeleteGroupPpt 删除ppt
- func DeleteGroupPpt(PptId int) (err error) {
- //查询该ppt的所有单个共享出去的目录信息
- groupPpts, err := models.GetGroupPptByPptId(PptId)
- if err != nil {
- err = errors.New("查询目录里的ppt失败" + err.Error())
- return
- }
- if len(groupPpts) <= 0 {
- return
- }
- //整理出需要删除的groupId
- groupPptMap := make(map[int64]*models.PptV2GroupMapping)
- 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 = models.DeletePptGroupByGroupIds(delGroupIds)
- if err != nil {
- err = errors.New("删除单个共享目录失败" + err.Error())
- return
- }
- }
- //再统一删除目录里相关的ppt
- err = models.DeletePptGroupMappingByPptId(PptId)
- if err != nil {
- err = errors.New("删除目录里的ppt失败" + err.Error())
- return
- }
- return
- }
- // CopyPpt 复制单个ppt,并移动到新的目录下面
- func CopyPpt(pptId int, groupId int64, adminId int, adminRealName string) (resp models.RespGroupPptNameListItem, err error) {
- //查询ppt详情
- pptInfo, err := models.GetPptV2ById(pptId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("ppt 不存在")
- return
- }
- err = errors.New("查询ppt失败" + err.Error())
- return
- }
- if pptInfo.PptVersion == 1 {
- err = errors.New("旧版本的ppt不允许复制")
- return
- }
- // 查询目录是否存在
- _, err = models.GetPptGroupByGroupIdAdminId(groupId, adminId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("目录不存在")
- return
- }
- err = errors.New("目录查询出错:" + err.Error())
- return
- }
- pptNames, err := models.GetAllPptTitle()
- if err != nil {
- err = errors.New("查询ppt标题出错:" + err.Error())
- return
- }
- //复制ppt,更新作者为当前账号,并返回新的pptID
- var newPptList []*models.PptV2
- newPpt := &models.PptV2{
- TemplateType: pptInfo.TemplateType,
- BackgroundImg: pptInfo.BackgroundImg,
- Title: generateCopyName(pptInfo.Title, 1, pptNames),
- ReportType: pptInfo.ReportType,
- PptDate: pptInfo.PptDate,
- Content: pptInfo.Content,
- CoverContent: pptInfo.CoverContent,
- PptUrl: pptInfo.PptUrl,
- PptxUrl: pptInfo.PptxUrl,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- PptVersion: pptInfo.PptVersion,
- TitleSetting: pptInfo.TitleSetting,
- }
- newPptList = append(newPptList, newPpt)
- err = models.AddPptV2Multi(newPptList)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- var newMappings []*models.PptV2GroupMapping
- newGroupPpt := &models.PptV2GroupMapping{
- GroupId: groupId,
- PptId: int64(newPpt.PptId),
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- AdminId: adminId,
- AdminRealName: adminRealName,
- }
- newMappings = append(newMappings, newGroupPpt)
- err = models.AddPptGroupMappingMulti(newMappings)
- if err != nil {
- err = errors.New("复制目录里的ppt出错:" + err.Error())
- return
- }
- //批量更新排序字段
- err = models.UpdatePptGroupMappingSortMulti([]int64{newGroupPpt.GroupPptId})
- if err != nil {
- err = errors.New("更新排序标识出错:" + err.Error())
- return
- }
- pptPage := 0
- // 因之前并没有存储PPT页数字段,所以此处读取PPT内容的长度
- 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 = models.RespGroupPptNameListItem{
- GroupPptId: newGroupPpt.GroupPptId,
- PptId: int64(newPpt.PptId),
- Title: newPpt.Title,
- AdminId: newPpt.AdminId,
- AdminRealName: newPpt.AdminRealName,
- PptVersion: newPpt.PptVersion,
- PptxUrl: newPpt.PptxUrl,
- ReportId: newPpt.ReportId,
- ReportCode: newPpt.ReportCode,
- PptCreateTime: newPpt.CreateTime.Format(utils.FormatDateTime),
- PptPage: pptPage,
- TitleSetting: newPpt.TitleSetting,
- }
- return
- }
- // generateCopyName 生成复制的目录名称
- func generateCopyName(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
- }
- // SearchGroupPpt 根据ppt标题搜索ppt
- func SearchGroupPpt(keyWord string) (ret models.RespSearchGroupPptList, err error) {
- //组装group ppt
- list := make([]*models.RespSearchGroupPptListItem, 0)
- ret.List = list
- reqKeyword := "%" + keyWord + "%"
- condition := " and title like ? "
- var pars []interface{}
- pars = append(pars, reqKeyword)
- pptList, err := models.GetPptV2ByCondition(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]*models.PptV2)
- for _, v := range pptList {
- pptIds = append(pptIds, strconv.Itoa(v.PptId))
- pptMap[v.PptId] = v
- }
- groupPptList, err := models.GetPublicGroupPptByPptIds(pptIds)
- if err != nil {
- err = errors.New("查询目录里的ppt列表出错:" + err.Error())
- return
- }
- for _, v := range groupPptList {
- tmp := new(models.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
- }
- // InitPptGroup 初始化目录分组
- func InitPptGroup() (err error) {
- //查询所有的ppt
- now := time.Now()
- pptList, err := models.GetPptV2ByCondition("", []interface{}{})
- if err != nil {
- errors.New("查询所有的ppt出错" + err.Error())
- return
- }
- pptAdminMap := make(map[int]string, 0)
- adminPptListMap := make(map[int][]*models.PptV2)
- oldPptAdminMap := make(map[int]string, 0)
- oldAdminPptListMap := make(map[int][]*models.PptV2)
- //查询所有的ppt作者
- for _, v := range pptList {
- if v.PptVersion == 2 {
- if _, ok := pptAdminMap[v.AdminId]; !ok {
- pptAdminMap[v.AdminId] = v.AdminRealName
- }
- adminPptListMap[v.AdminId] = append(adminPptListMap[v.AdminId], v)
- } else {
- if _, ok := oldPptAdminMap[v.AdminId]; !ok {
- oldPptAdminMap[v.AdminId] = v.AdminRealName
- }
- oldAdminPptListMap[v.AdminId] = append(oldAdminPptListMap[v.AdminId], v)
- }
- }
- //批量生成历史目录,共享目录
- newOldGroupList := make([]*models.PptV2Group, 0)
- //批量生成目录,共享目录
- newGroupList := make([]*models.PptV2Group, 0)
- if len(pptAdminMap) > 0 {
- for k, v := range pptAdminMap {
- tmp := &models.PptV2Group{
- GroupName: v + "的PPT",
- AdminId: k,
- IsShare: 1,
- CreateTime: now,
- ModifyTime: now,
- ShareTime: now,
- }
- newGroupList = append(newGroupList, tmp)
- }
- //批量把对应的ppt放到目录当中
- err = models.AddPptGroupMulti(newGroupList)
- if err != nil {
- err = errors.New("创建目录出错:" + err.Error())
- return
- }
- }
- if len(oldPptAdminMap) > 0 {
- for k, v := range oldPptAdminMap {
- tmp := &models.PptV2Group{
- GroupName: v + "的历史PPT",
- AdminId: k,
- IsShare: 1,
- CreateTime: now,
- ModifyTime: now,
- ShareTime: now,
- }
- newOldGroupList = append(newOldGroupList, tmp)
- }
- //批量把对应的ppt放到目录当中
- err = models.AddPptGroupMulti(newOldGroupList)
- if err != nil {
- err = errors.New("创建目录出错:" + err.Error())
- return
- }
- }
- //批量更新排序字段
- var newGroupIds []int64
- var newMappings []*models.PptV2GroupMapping
- for _, v := range newGroupList {
- newGroupIds = append(newGroupIds, v.GroupId)
- if ppts, ok := adminPptListMap[v.AdminId]; ok {
- for _, p := range ppts {
- tmp := &models.PptV2GroupMapping{
- GroupId: v.GroupId,
- PptId: int64(p.PptId),
- CreateTime: now,
- ModifyTime: now,
- AdminId: p.AdminId,
- AdminRealName: p.AdminRealName,
- }
- newMappings = append(newMappings, tmp)
- }
- }
- }
- for _, v := range newOldGroupList {
- newGroupIds = append(newGroupIds, v.GroupId)
- if oldPpts, ok1 := oldAdminPptListMap[v.AdminId]; ok1 {
- for _, p := range oldPpts {
- tmp := &models.PptV2GroupMapping{
- GroupId: v.GroupId,
- PptId: int64(p.PptId),
- CreateTime: now,
- ModifyTime: now,
- AdminId: p.AdminId,
- AdminRealName: p.AdminRealName,
- }
- newMappings = append(newMappings, tmp)
- }
- }
- }
- err = models.UpdatePptGroupSortMulti(newGroupIds)
- if err != nil {
- err = errors.New("更新目录排序标识出错:" + err.Error())
- return
- }
- err = models.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 = models.UpdatePptGroupMappingSortMulti(newGroupPptIds)
- if err != nil {
- err = errors.New("更新排序标识出错:" + err.Error())
- return
- }
- return
- }
- // GetGroupsByAdminIdV2 查询ppt目录列表
- // @Author roc
- // @Time 2022-08-29 15:22:20
- func GetGroupsByAdminIdV2(IsNewPpt, adminId int, lang string) (ret models.RespGroupList, err error) {
- myPptList := make([]*models.RespGroupPptNameListItem, 0)
- otherPptList := make([]*models.RespGroupPptNameListItem, 0)
- grantList := []models.RespGroupListItem{}
- if lang == utils.EnLangVersion {
- grantList = append(grantList, []models.RespGroupListItem{
- {
- GroupId: 1,
- GroupName: "My shared",
- PptList: myPptList,
- },
- {
- GroupId: 2,
- GroupName: "Received shared",
- PptList: otherPptList,
- },
- }...)
- } else {
- grantList = append(grantList, []models.RespGroupListItem{
- {
- GroupId: 1,
- GroupName: "我共享的",
- PptList: myPptList,
- },
- {
- GroupId: 2,
- GroupName: "收到共享",
- PptList: otherPptList,
- },
- }...)
- }
- ret.PublicList = make([]*models.RespGroupListItem, 0)
- ret.PrivateList = make([]*models.RespGroupListItem, 0)
- ret.GrantList = grantList
- pptMap := make(map[int]*models.PptV2)
- groupMap := make(map[int64][]*models.RespGroupPptNameListItem)
- groupHasNewPptMap := make(map[int64]struct{})
- pptIds := make([]int, 0)
- // 获取我的ppt分组
- privateGroups, err := models.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 []*models.PptV2GroupMapping
- // 如果没有分组,那么直接返回
- if len(groupIds) > 0 {
- // 遍历分组并拼接
- for _, v := range privateGroups {
- tmp := new(models.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 = models.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 := models.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 := models.GetPptV2ByIds(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
- }
- if IsNewPpt == 1 && i.PptVersion != 2 { //都说了只要新版ppt,你一个不是新版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 := &models.RespGroupPptNameListItem{
- AdminId: v.AdminId,
- GroupPptId: v.GroupPptId,
- PptId: v.PptId,
- AdminRealName: v.AdminRealName,
- Title: i.Title,
- PptVersion: i.PptVersion,
- 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][]*models.RespGroupPptNameListItem)
- // 获取公开分享的ppt
- sharePptList, err := models.GetSharePptV2(IsNewPpt)
- for _, v := range sharePptList {
- publicPptList, ok := publicPptListMap[v.AdminId]
- if !ok {
- publicPptList = make([]*models.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 := &models.RespGroupPptNameListItem{
- GroupPptId: int64(v.PptId),
- PptId: int64(v.PptId),
- Title: v.Title,
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- 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,
- }
- 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([]*models.RespGroupPptNameListItem, 0)
- }
- // ppt 分组信息
- tmpRespGroupListItem := &models.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 := &models.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,
- }
- //如果只展示新版ppt,则过滤旧版的Ppt
- if IsNewPpt == 1 && v.PptVersion == 1 {
- continue
- }
- 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
- }
- //如果只展示新版ppt,则过滤空文件夹
- if IsNewPpt == 1 {
- //公共ppt
- pubList := make([]*models.RespGroupListItem, 0)
- for _, v := range ret.PublicList {
- if len(v.PptList) > 0 {
- pubList = append(pubList, v)
- }
- }
- ret.PublicList = pubList
- // 私有ppt
- priList := make([]*models.RespGroupListItem, 0)
- for _, v := range ret.PrivateList {
- if len(v.PptList) > 0 {
- priList = append(priList, v)
- }
- }
- ret.PrivateList = priList
- }
- return
- }
- // ShareSingleGroupPptV2 共享单个ppt/取消共享单个ppt,返回共享状态
- // @Author roc
- // @Time 2022-08-29 15:22:20
- func ShareSingleGroupPptV2(pptId int, adminId int) (pptInfo *models.PptV2, err error) {
- //判断当前登录者是否有共享的权限
- pptInfo, err = models.GetPptV2ById(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
- }
- // GetMyPptList 我的ppt列表
- // @Author roc
- // @Time 2022-09-05 17:26:21
- func GetMyPptList(adminId int, keyword string) (ret models.RespGroupPptList, err error) {
- list := make([]*models.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 := models.GetAllPptV2List(condition, pars)
- if len(pptList) <= 0 {
- return
- }
- var pptContent []services.PPTContent
- for _, v := range pptList {
- if v.PptPage == 0 && v.Content != "" {
- err = json.Unmarshal([]byte(v.Content), &pptContent)
- if err != nil {
- return
- }
- v.PptPage = len(pptContent)
- }
- tmpV := &models.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
- }
- // GetSharePptList 公共目录下的ppt列表
- // @Author roc
- // @Time 2022-08-29 16:27:59
- func GetSharePptList(adminId int, keyword string, isPrivate bool) (ret models.RespGroupPptList, err error) {
- list := make([]*models.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 := models.GetAllPptV2List(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 := &models.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
- }
- // GetGrantPptList 公共目录下的ppt列表
- // @Author roc
- // @Time 2022-09-05 15:50:25
- func GetGrantPptList(adminId int, keyword, sourceType string) (ret models.RespGroupPptList, err error) {
- list := make([]*models.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 := models.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 := &models.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
- }
- // SearchPptList PPT搜索(我的/公开PPT)
- func SearchPptList(adminId int, keyword string) (ret models.RespGroupPptList, err error) {
- list := make([]*models.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 := models.GetAllPptV2List(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 := &models.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,
- PptVersion: v.PptVersion,
- 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
- }
|