1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/report"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "html"
- "strconv"
- "time"
- )
- // EditDayWeekChapter
- // @Title 编辑晨周报章节内容
- // @Description 编辑晨周报章节内容
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /addChapter [post]
- func (this *ReportController) AddDayWeekChapter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.AddReportChapterReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportId <= 0 {
- br.Msg = "报告ID有误"
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportById(req.ReportId)
- if err != nil {
- br.Msg = "报告信息有误"
- br.ErrMsg = "报告信息有误, Err: " + err.Error()
- return
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- return
- }
- newContent := req.Content
- // 更新章节及指标
- contentSub := ""
- if req.Content != "" {
- e := utils.ContentXssCheck(req.Content)
- if e != nil {
- br.Msg = "存在非法标签"
- br.ErrMsg = "存在非法标签, Err: " + e.Error()
- return
- }
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- req.Content = contentClean
- contentSub, err = services.GetReportContentSub(req.Content)
- if err != nil {
- br.Msg = "内容分段解析失败"
- br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
- return
- }
- }
- if req.Content == "" {
- req.Content = newContent
- }
- reportChapterInfo := new(models.ReportChapter)
- reportChapterInfo.ReportId = reportInfo.Id
- reportChapterInfo.ClassifyIdFirst = reportInfo.ClassifyIdFirst
- reportChapterInfo.ClassifyNameFirst = reportInfo.ClassifyNameFirst
- reportChapterInfo.Title = req.Title
- reportChapterInfo.AddType = 1
- reportChapterInfo.Author = req.Author
- reportChapterInfo.Content = html.EscapeString(req.Content)
- reportChapterInfo.ContentSub = html.EscapeString(contentSub)
- reportChapterInfo.IsEdit = 1
- reportChapterInfo.CreateTime = req.CreateTime
- reportChapterInfo.VideoKind = 1
- reportChapterInfo.ClassifyIdSecond = reportInfo.ClassifyIdSecond
- reportChapterInfo.ClassifyNameSecond = reportInfo.ClassifyNameSecond
- reportChapterInfo.ClassifyIdThird = reportInfo.ClassifyIdThird
- reportChapterInfo.ClassifyNameThird = reportInfo.ClassifyNameThird
- reportChapterInfo.LastModifyAdminId = sysUser.AdminId
- reportChapterInfo.LastModifyAdminName = sysUser.RealName
- reportChapterInfo.ContentModifyTime = time.Now()
- reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- reportChapterInfo.CanvasColor = req.CanvasColor
- reportChapterInfo.HeadResourceId = req.HeadResourceId
- reportChapterInfo.EndResourceId = req.EndResourceId
- err = reportChapterInfo.Add()
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 备份关键数据
- chapters := make([]*models.ReportChapter, 0)
- chapters = append(chapters, reportChapterInfo)
- go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // EditDayWeekChapter
- // @Title 编辑晨周报章节内容
- // @Description 编辑晨周报章节内容
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /editDayWeekChapter [post]
- func (this *ReportController) EditDayWeekChapter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.EditReportChapterReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportChapterId := req.ReportChapterId
- if reportChapterId <= 0 {
- br.Msg = "报告章节ID有误"
- return
- }
- if req.Content == "" {
- br.Msg = "请输入内容"
- return
- }
- // 获取章节详情
- reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "报告章节信息有误"
- br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
- if err != nil {
- br.Msg = "报告信息有误"
- br.ErrMsg = "报告信息有误, Err: " + err.Error()
- return
- }
- // 操作权限校验
- {
- // 如果不是创建人,那么就要去查看是否授权
- if reportInfo.AdminId != sysUser.AdminId {
- // 授权用户权限校验
- chapterGrantObj := report.ReportChapterGrant{}
- _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
- if tmpErr != nil {
- if tmpErr.Error() == utils.ErrNoRow() {
- br.Msg = "没有权限"
- br.ErrMsg = "没有权限"
- br.IsSendEmail = false
- return
- }
- br.Msg = "获取章节id授权用户失败"
- br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
- return
- }
- }
- // 标记更新中
- {
- markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- br.IsSendEmail = false
- return
- }
- }
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- return
- }
- reqTickerList := req.TickerList
- // 更新章节及指标
- contentSub := ""
- if req.Content != "" {
- e := utils.ContentXssCheck(req.Content)
- if e != nil {
- br.Msg = "存在非法标签"
- br.ErrMsg = "存在非法标签, Err: " + e.Error()
- return
- }
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- req.Content = contentClean
- contentSub, err = services.GetReportContentSub(req.Content)
- if err != nil {
- br.Msg = "内容分段解析失败"
- br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
- return
- }
- }
- reportChapterInfo.Title = req.Title
- //reportChapterInfo.AddType = req.AddType
- reportChapterInfo.Author = req.Author
- reportChapterInfo.Content = html.EscapeString(req.Content)
- reportChapterInfo.ContentSub = html.EscapeString(contentSub)
- reportChapterInfo.IsEdit = 1
- reportChapterInfo.CreateTime = req.CreateTime
- reportChapterInfo.VideoUrl = req.VideoUrl
- reportChapterInfo.VideoName = req.VideoName
- reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
- reportChapterInfo.VideoSize = req.VideoSize
- reportChapterInfo.VideoKind = 1
- reportChapterInfo.LastModifyAdminId = sysUser.AdminId
- reportChapterInfo.LastModifyAdminName = sysUser.RealName
- reportChapterInfo.ContentModifyTime = time.Now()
- reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- reportChapterInfo.CanvasColor = req.CanvasColor
- reportChapterInfo.HeadResourceId = req.HeadResourceId
- reportChapterInfo.EndResourceId = req.EndResourceId
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
- if req.VideoUrl != "" {
- updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
- }
- updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct", "CanvasColor", "HeadResourceId", "EndResourceId")
- // 章节报告更新指标
- tickerList := make([]*models.ReportChapterTicker, 0)
- if len(reqTickerList) > 0 {
- nowTime := time.Now()
- for i := 0; i < len(reqTickerList); i++ {
- tickerList = append(tickerList, &models.ReportChapterTicker{
- ReportChapterId: reportChapterInfo.ReportChapterId,
- Sort: reqTickerList[i].Sort,
- Ticker: reqTickerList[i].Ticker,
- CreateTime: nowTime,
- UpdateTime: nowTime,
- })
- }
- }
- err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 标记更新中
- {
- markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- }
- // 备份关键数据
- chapters := make([]*models.ReportChapter, 0)
- chapters = append(chapters, reportChapterInfo)
- go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // DelChapter
- // @Title 编辑晨周报章节内容
- // @Description 编辑晨周报章节内容
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /chapter/del [post]
- //func (this *ReportController) DelChapter() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- //
- // sysUser := this.SysUser
- // if sysUser == nil {
- // br.Msg = "请登录"
- // br.ErrMsg = "请登录,SysUser Is Empty"
- // br.Ret = 408
- // return
- // }
- //
- // var req models.DelReportChapterReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // reportChapterId := req.ReportChapterId
- // if reportChapterId <= 0 {
- // br.Msg = "报告章节ID有误"
- // return
- // }
- // if req.Content == "" {
- // br.Msg = "请输入内容"
- // return
- // }
- //
- // // 获取章节详情
- // reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- // if err != nil {
- // br.Msg = "报告章节信息有误"
- // br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
- // return
- // }
- //
- // // 获取报告详情
- // reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
- // if err != nil {
- // br.Msg = "报告信息有误"
- // br.ErrMsg = "报告信息有误, Err: " + err.Error()
- // return
- // }
- //
- // // 操作权限校验
- // {
- // // 如果不是创建人,那么就要去查看是否授权
- // if reportInfo.AdminId != sysUser.AdminId {
- // // 授权用户权限校验
- // chapterGrantObj := report.ReportChapterGrant{}
- // _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
- // if tmpErr != nil {
- // if tmpErr.Error() == utils.ErrNoRow() {
- // br.Msg = "没有权限"
- // br.ErrMsg = "没有权限"
- // br.IsSendEmail = false
- // return
- // }
- // br.Msg = "获取章节id授权用户失败"
- // br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
- // return
- // }
- // }
- //
- // // 标记更新中
- // {
- // markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- // if err != nil {
- // br.Msg = err.Error()
- // return
- // }
- // if markStatus.Status == 1 {
- // br.Msg = markStatus.Msg
- // br.IsSendEmail = false
- // return
- // }
- // }
- // }
- //
- // if reportInfo.State == 2 {
- // br.Msg = "该报告已发布,不允许编辑"
- // br.ErrMsg = "该报告已发布,不允许编辑"
- // return
- // }
- //
- // reqTickerList := req.TickerList
- // // 更新章节及指标
- // contentSub := ""
- // if req.Content != "" {
- // e := utils.ContentXssCheck(req.Content)
- // if e != nil {
- // br.Msg = "存在非法标签"
- // br.ErrMsg = "存在非法标签, Err: " + e.Error()
- // return
- // }
- // contentClean, e := services.FilterReportContentBr(req.Content)
- // if e != nil {
- // br.Msg = "内容去除前后空格失败"
- // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- // return
- // }
- // req.Content = contentClean
- //
- // contentSub, err = services.GetReportContentSub(req.Content)
- // if err != nil {
- // br.Msg = "内容分段解析失败"
- // br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
- // return
- // }
- // }
- //
- // reportChapterInfo.Title = req.Title
- // //reportChapterInfo.AddType = req.AddType
- // reportChapterInfo.Author = req.Author
- // reportChapterInfo.Content = html.EscapeString(req.Content)
- // reportChapterInfo.ContentSub = html.EscapeString(contentSub)
- // reportChapterInfo.IsEdit = 1
- // reportChapterInfo.CreateTime = req.CreateTime
- // reportChapterInfo.VideoUrl = req.VideoUrl
- // reportChapterInfo.VideoName = req.VideoName
- // reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
- // reportChapterInfo.VideoSize = req.VideoSize
- // reportChapterInfo.VideoKind = 1
- //
- // reportChapterInfo.LastModifyAdminId = sysUser.AdminId
- // reportChapterInfo.LastModifyAdminName = sysUser.RealName
- // reportChapterInfo.ContentModifyTime = time.Now()
- // reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- // reportChapterInfo.CanvasColor = req.CanvasColor
- // reportChapterInfo.HeadResourceId = req.HeadResourceId
- // reportChapterInfo.EndResourceId = req.EndResourceId
- //
- // updateCols := make([]string, 0)
- // updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
- // if req.VideoUrl != "" {
- // updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
- // }
- //
- // updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct", "CanvasColor", "HeadResourceId", "EndResourceId")
- //
- // // 章节报告更新指标
- // tickerList := make([]*models.ReportChapterTicker, 0)
- // if len(reqTickerList) > 0 {
- // nowTime := time.Now()
- // for i := 0; i < len(reqTickerList); i++ {
- // tickerList = append(tickerList, &models.ReportChapterTicker{
- // ReportChapterId: reportChapterInfo.ReportChapterId,
- // Sort: reqTickerList[i].Sort,
- // Ticker: reqTickerList[i].Ticker,
- // CreateTime: nowTime,
- // UpdateTime: nowTime,
- // })
- // }
- // }
- // err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- // return
- // }
- //
- // // 标记更新中
- // {
- // markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- // if err != nil {
- // br.Msg = err.Error()
- // return
- // }
- // if markStatus.Status == 1 {
- // br.Msg = markStatus.Msg
- // return
- // }
- // }
- //
- // // 备份关键数据
- // chapters := make([]*models.ReportChapter, 0)
- // chapters = append(chapters, reportChapterInfo)
- // go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
- //
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "保存成功"
- //}
- // EditChapterBaseInfoAndPermission
- // @Title 修改报告章节的基础信息、授权用户权限、品种权限
- // @Description 修改报告章节的基础信息、授权用户权限、品种权限
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /chapter/base_info/edit [post]
- func (this *ReportController) EditChapterBaseInfoAndPermission() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.EditReportChapterBaseInfoAndPermissionReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportChapterId := req.ReportChapterId
- if reportChapterId <= 0 {
- br.Msg = "报告章节ID有误"
- return
- }
- // 获取章节详情
- reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "报告章节信息有误"
- br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
- if err != nil {
- br.Msg = "报告信息有误"
- br.ErrMsg = "报告信息有误, Err: " + err.Error()
- return
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- return
- }
- err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // GetReportChapterList
- // @Title 获取报告章节列表
- // @Description 获取报告章节列表
- // @Param ReportId query string true "报告ID"
- // @Success 200 {object} company.CompanyListResp
- // @router /getReportChapterList [get]
- func (this *ReportController) GetReportChapterList() {
- // TODO 授权用户校验
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reqReportId := this.GetString("ReportId")
- reportId, _ := strconv.Atoi(reqReportId)
- if reportId <= 0 {
- br.Msg = "报告ID有误"
- return
- }
- // 获取章节列表
- chapterList, err := models.GetChapterListByReportId(reportId)
- if err != nil {
- br.Msg = "获取章节列表失败"
- br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
- return
- }
- typeList, err := models.GetReportChapterTypeList()
- if err != nil {
- br.Msg = "获取章节类型列表失败"
- br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
- return
- }
- typeIdImg := make(map[int]string)
- for i := 0; i < len(typeList); i++ {
- typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
- }
- resp := make([]models.ReportChapterResp, 0)
- if len(chapterList) > 0 {
- chapterIdList := make([]int, 0)
- // 章节id授权用户列表map
- chapterIdGrandListMap := make(map[int][]int)
- // 章节id关联品种id列表map
- chapterIdPermissionListMap := make(map[int][]int)
- for _, v := range chapterList {
- chapterIdList = append(chapterIdList, v.ReportChapterId)
- }
- // 处理章节id授权用户列表
- {
- chapterGrantObj := report.ReportChapterGrant{}
- chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range chapterGrantList {
- tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
- if !ok {
- tmpChapterIdGrandList = make([]int, 0)
- }
- chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
- }
- }
- // 处理章节id关联品种id列表
- {
- obj := report.ReportChapterPermissionMapping{}
- chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
- if tmpErr != nil {
- br.Msg = "获取章节id关联品种列表失败"
- br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range chapterPermissionList {
- tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
- if !ok {
- tmpChapterIdPermissionList = make([]int, 0)
- }
- chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
- }
- }
- // TODO 获取更新规则
- researchType := chapterList[0].ReportType
- chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
- if tmpErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
- return
- }
- // 调整章节更新
- nowTime := time.Now().Local()
- for _, item := range chapterList {
- stop := false
- for _, rule := range chapterTypeList {
- if rule.ReportChapterTypeId == item.TypeId {
- //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
- // 如果被永久暂停更新了
- if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
- stop = true
- } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
- startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
- if timeErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
- return
- }
- endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
- if timeErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
- return
- }
- // 暂停更新
- if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
- stop = true
- }
- break
- }
- }
- }
- if !stop {
- // 授权的用户列表
- tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
- if !ok {
- tmpChapterIdGrandList = make([]int, 0)
- }
- // 关联的品种列表
- tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
- if !ok {
- tmpChapterIdPermissionList = make([]int, 0)
- }
- tmpChapterItem := models.ReportChapterResp{
- ReportChapterId: item.ReportChapterId,
- ReportId: item.ReportId,
- ReportType: item.ReportType,
- TypeId: item.TypeId,
- TypeName: item.TypeName,
- TypeEditImg: typeIdImg[item.TypeId],
- Title: item.Title,
- IsEdit: item.IsEdit,
- Trend: item.Trend,
- Sort: item.Sort,
- PublishState: item.PublishState,
- VideoUrl: item.VideoUrl,
- VideoName: item.VideoName,
- VideoPlaySeconds: item.VideoPlaySeconds,
- VideoSize: item.VideoSize,
- VideoKind: item.VideoKind,
- ModifyTime: item.ModifyTime.Format(utils.FormatDate),
- GrandAdminIdList: tmpChapterIdGrandList,
- PermissionIdList: tmpChapterIdPermissionList,
- }
- markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markStatus.Status == 0 {
- tmpChapterItem.CanEdit = true
- } else {
- tmpChapterItem.Editor = markStatus.Editor
- }
- resp = append(resp, tmpChapterItem)
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetDayWeekChapter
- // @Title 获取晨周报章节信息
- // @Description 获取晨周报章节信息
- // @Param ReportChapterId query int true "报告章节ID"
- // @Success 200 Ret=200 保存成功
- // @router /getDayWeekChapter [get]
- func (this *ReportController) GetDayWeekChapter() {
- // TODO 授权用户校验
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reportChapterId, _ := this.GetInt("ReportChapterId")
- if reportChapterId <= 0 {
- br.Msg = "参数有误"
- return
- }
- chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "获取章节信息失败"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- if chapterInfo != nil {
- chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
- chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
- chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
- }
- // 授权用户列表map
- chapterGrantIdList := make([]int, 0)
- // 关联品种id列表map
- chapterPermissionIdList := make([]int, 0)
- // 处理章节id授权用户列表
- {
- chapterGrantObj := report.ReportChapterGrant{}
- chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterInfo.ReportChapterId)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range chapterGrantList {
- chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
- }
- }
- // 处理章节id关联品种id列表
- {
- obj := report.ReportChapterPermissionMapping{}
- chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterInfo.ReportChapterId)
- if tmpErr != nil {
- br.Msg = "获取章节id关联品种列表失败"
- br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range chapterPermissionList {
- chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
- }
- }
- resp := models.ReportChapterItem{
- ReportChapter: *chapterInfo,
- GrandAdminIdList: chapterGrantIdList,
- PermissionIdList: chapterPermissionIdList,
- }
- // 获取当前编辑状态
- {
- markStatus, err := services.UpdateReportEditMark(chapterInfo.ReportId, chapterInfo.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markStatus.Status == 0 {
- resp.CanEdit = true
- } else {
- resp.Editor = markStatus.Editor
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // ChapterMove
- // @Title 移动章节类型
- // @Description 移动章节类型
- // @Param request body models.PermissionMoveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /chapter/move [post]
- func (this *ReportController) ChapterMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.ReportChapterMoveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- if req.ReportChapterId == 0 {
- br.Msg = "请选择要移动的章节"
- return
- }
- e, msg := services.MoveReportChapter(&req)
- if e != nil {
- br.Msg = msg
- br.ErrMsg = "移动品种失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // EditChapterTrendTag
- // @Title 编辑章节趋势标签
- // @Description 编辑章节趋势标签
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /editChapterTrendTag [post]
- func (this *ReportController) EditChapterTrendTag() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.EditChapterTrendTagReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportChapterId <= 0 {
- br.Msg = "章节ID有误"
- return
- }
- if req.Trend == "" {
- br.Msg = "请输入标签"
- return
- }
- chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
- if err != nil {
- br.Msg = "获取章节信息失败"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
- if err != nil {
- br.Msg = "报告信息有误"
- br.ErrMsg = "报告信息有误, Err: " + err.Error()
- return
- }
- // 操作权限校验
- {
- // 如果不是创建人,那么就要去查看是否授权
- if reportInfo.AdminId != sysUser.AdminId {
- // 授权用户权限校验
- chapterGrantObj := report.ReportChapterGrant{}
- _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(chapterInfo.ReportChapterId, sysUser.AdminId)
- if tmpErr != nil {
- if tmpErr.Error() == utils.ErrNoRow() {
- br.Msg = "没有权限"
- br.ErrMsg = "没有权限"
- br.IsSendEmail = false
- return
- }
- br.Msg = "获取章节id授权用户失败"
- br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
- return
- }
- }
- }
- // 更新章节标签
- chapterInfo.Trend = req.Trend
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Trend")
- if err = chapterInfo.UpdateChapter(updateCols); err != nil {
- br.Msg = "更新标签失败"
- br.ErrMsg = "更新标签失败, Err: " + err.Error()
- return
- }
- // 添加关键词
- if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
- br.Msg = "添加标签关键词失败"
- br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // GetSunCode 获取太阳码
- // @Title 公共模块
- // @Description 获取分享海报
- // @Param request body models.SunCodeReq true "type json string"
- // @Success 200 {object} string "获取成功"
- // @failure 400 {string} string "获取失败"
- // @router /getSunCode [post]
- func (this *ReportController) GetSunCode() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.SunCodeReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var sunCodeUrl string
- //先查,查不到再去生成上传
- item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "查询太阳码失败!"
- br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
- return
- }
- if item != nil {
- sunCodeUrl = item.SuncodeUrl
- }
- if sunCodeUrl == "" {
- sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
- if err != nil {
- br.Msg = "生成太阳码失败!"
- br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
- return
- }
- }
- br.Data = sunCodeUrl
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|