123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/report"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/utils"
- "html"
- "os"
- "path"
- "strconv"
- "strings"
- "time"
- )
- // AddChapter
- // @Title 新增晨周报章节内容
- // @Description 新增晨周报章节内容
- // @Param request body models.AddReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /chapter/add [post]
- func (this *ReportController) AddChapter() {
- 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
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == `` {
- br.Msg = "章节名称不能为空"
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportByReportId(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
- //}
- // 最小单元的分类
- var minClassifyId int
- var minClassifyName string
- if reportInfo.ClassifyIdThird > 0 {
- minClassifyId = reportInfo.ClassifyIdThird
- minClassifyName = reportInfo.ClassifyNameThird
- } else if reportInfo.ClassifyIdSecond > 0 {
- minClassifyId = reportInfo.ClassifyIdSecond
- minClassifyName = reportInfo.ClassifyNameSecond
- } else {
- minClassifyId = reportInfo.ClassifyIdFirst
- minClassifyName = reportInfo.ClassifyNameFirst
- }
- // 判断名称是否重复
- {
- var condition string
- var pars []interface{}
- condition += " AND report_id = ? AND title=? "
- pars = append(pars, req.ReportId, req.Title)
- count, err := models.GetCountReportChapterByCondition(condition, pars)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "章节名称不允许重复"
- br.ErrMsg = "章节名称不允许重复"
- br.IsSendEmail = false
- return
- }
- }
- reportChapterInfo := new(models.ReportChapter)
- reportChapterInfo.ReportId = reportInfo.Id
- reportChapterInfo.ClassifyIdFirst = minClassifyId
- reportChapterInfo.ClassifyNameFirst = minClassifyName
- reportChapterInfo.Title = req.Title
- reportChapterInfo.AddType = 1
- reportChapterInfo.PublishState = 1
- //reportChapterInfo.Author = req.Author
- //reportChapterInfo.Content = html.EscapeString(req.Content)
- //reportChapterInfo.ContentSub = html.EscapeString(contentSub)
- reportChapterInfo.IsEdit = 1
- //reportChapterInfo.CreateTime = req.CreateTime
- reportChapterInfo.CreateTime = reportInfo.CreateTime
- reportChapterInfo.ModifyTime = time.Now()
- reportChapterInfo.ReportCreateTime = time.Now()
- reportChapterInfo.VideoKind = 2
- reportChapterInfo.Stage = reportInfo.Stage
- 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, errMsg := services.AddChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, 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 = "保存成功"
- }
- // 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
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == `` {
- br.Msg = "章节名称不能为空"
- return
- }
- // 获取章节详情
- reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "报告章节信息有误"
- br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
- return
- }
- // 判断名称是否重复
- {
- var condition string
- var pars []interface{}
- condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
- pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
- count, err := models.GetCountReportChapterByCondition(condition, pars)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "章节名称不允许重复"
- br.ErrMsg = "章节名称不允许重复"
- br.IsSendEmail = false
- 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 = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 报告的最后编辑人
- reportInfo.LastModifyAdminId = sysUser.AdminId
- reportInfo.LastModifyAdminName = sysUser.RealName
- reportInfo.ModifyTime = time.Now()
- 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 = "保存成功"
- }
- // 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 = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 报告的最后编辑人
- reportInfo.LastModifyAdminId = sysUser.AdminId
- reportInfo.LastModifyAdminName = sysUser.RealName
- reportInfo.ModifyTime = time.Now()
- 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
- }
- }
- if req.Title != "" {
- 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.ModifyTime = time.Now()
- if req.CreateTime != `` {
- reportChapterInfo.CreateTime = req.CreateTime
- }
- reportChapterInfo.LastModifyAdminId = sysUser.AdminId
- reportChapterInfo.LastModifyAdminName = sysUser.RealName
- reportChapterInfo.ContentModifyTime = time.Now()
- reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "ModifyTime")
- updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct")
- // 章节报告更新指标
- 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(reportInfo, 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
- }
- // 获取章节详情
- 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 = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 删除章节
- err, errMsg := services.DelChapter(reportInfo, reportChapterInfo, sysUser)
- if err != nil {
- br.Msg = "删除失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- 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 = "删除成功"
- }
- // GetReportChapterList
- // @Title 获取报告章节列表
- // @Description 获取报告章节列表
- // @Param ReportId query string true "报告ID"
- // @Success 200 {object} company.CompanyListResp
- // @router /getReportChapterList [get]
- func (this *ReportController) GetReportChapterList() {
- 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
- }
- // 获取报告信息
- reportInfo, err := models.GetReportByReportId(reportId)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
- return
- }
- // 权限校验
- isAuth, err := services.CheckReportAuthByReportChapterInfo(sysUser.AdminId, reportInfo.AdminId, reportId)
- if err != nil {
- br.Msg = "获取报告权限失败"
- br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
- return
- }
- if !isAuth {
- br.Msg = "无操作权限"
- br.ErrMsg = "无操作权限"
- 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)
- }
- }
- // 章节类型的字段
- for _, item := range chapterList {
- // 授权的用户列表
- 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
- }
- // 报告章节的操作权限
- tmpChapterItem.IsAuth = services.CheckChapterAuthByAdminIdList(sysUser.AdminId, reportInfo.AdminId, tmpChapterIdGrandList)
- 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() {
- 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
- }
- chapterItem, err := models.GetReportChapterItemById(reportChapterId)
- if err != nil {
- br.Msg = "获取章节信息失败"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- // 获取报告详情
- reportInfo, err := models.GetReportById(chapterItem.ReportId)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
- return
- }
- // 权限校验
- isAuth, err := services.CheckReportAuthByReportChapterInfo(sysUser.AdminId, reportInfo.AdminId, reportInfo.Id)
- if err != nil {
- br.Msg = "获取报告权限失败"
- br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
- return
- }
- if !isAuth {
- br.Msg = "无操作权限"
- br.ErrMsg = "无操作权限"
- return
- }
- chapterItem.Content = html.UnescapeString(chapterItem.Content)
- chapterItem.ContentSub = html.UnescapeString(chapterItem.ContentSub)
- chapterItem.ContentStruct = html.UnescapeString(chapterItem.ContentStruct)
- // 授权用户列表map
- chapterGrantIdList := make([]int, 0)
- // 关联品种id列表map
- chapterPermissionIdList := make([]int, 0)
- // 处理章节id授权用户列表
- {
- chapterGrantObj := report.ReportChapterGrant{}
- chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterItem.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(chapterItem.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.ReportChapterItemResp{
- ReportChapterItem: *chapterItem,
- GrandAdminIdList: chapterGrantIdList,
- PermissionIdList: chapterPermissionIdList,
- }
- // 获取当前编辑状态
- {
- markStatus, err := services.UpdateReportEditMark(chapterItem.ReportId, chapterItem.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 = "操作成功"
- }
- // VoiceUpload
- // @Title 音频上传
- // @Description 音频上传接口
- // @Param file query file true "文件"
- // @Param ReportChapterId query int true "报告章节ID"
- // @Success Ret=200 上传成功
- // @router /chapter/voice/upload [post]
- func (this *ReportController) VoiceUpload() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- f, h, err := this.GetFile("file")
- if err != nil {
- br.Msg = "获取资源信息失败"
- br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
- return
- }
- // 报告章节id
- reportChapterId, err := this.GetInt("ReportChapterId", 0)
- if err != nil {
- br.Msg = "报告章节ID异常"
- br.ErrMsg = "报告章节ID异常,Err:" + err.Error()
- 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
- }
- // 权限校验
- isAuth, err := services.CheckChapterAuthByReportChapterInfo(this.SysUser.AdminId, reportInfo.AdminId, reportChapterInfo)
- if err != nil {
- br.Msg = "获取报告权限失败"
- br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
- return
- }
- if !isAuth {
- br.Msg = "无操作权限"
- br.ErrMsg = "无操作权限"
- return
- }
- ext := path.Ext(h.Filename)
- dateDir := time.Now().Format("20060102")
- uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
- err = os.MkdirAll(uploadDir, utils.DIR_MOD)
- if err != nil {
- br.Msg = "存储目录创建失败"
- br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- return
- }
- randStr := utils.GetRandStringNoSpecialChar(28)
- fileName := randStr + ext
- fPath := uploadDir + "/" + fileName
- defer f.Close() //关闭上传文件
- err = this.SaveToFile("file", fPath)
- if err != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- resourceUrl := ``
- //上传到阿里云 和 minio
- //if utils.ObjectStorageClient == "minio" {
- // resourceUrl, err = services.UploadAudioToMinIo(fileName, fPath)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- //} else {
- // resourceUrl, err = services.UploadAudioAliyun(fileName, fPath)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- //}
- ossClient := services.NewOssClient()
- if ossClient == nil {
- br.Msg = "上传失败"
- br.ErrMsg = "初始化OSS服务失败"
- return
- }
- resourceUrl, err = ossClient.UploadFile(fileName, fPath, "")
- if err != nil {
- br.Msg = "文件上传失败"
- br.ErrMsg = "文件上传失败,Err:" + err.Error()
- return
- }
- defer func() {
- os.Remove(fPath)
- }()
- item := new(models.Resource)
- item.ResourceUrl = resourceUrl
- item.ResourceType = 2
- item.CreateTime = time.Now()
- newId, err := models.AddResource(item)
- if err != nil {
- br.Msg = "资源上传失败"
- br.ErrMsg = "资源上传失败,Err:" + err.Error()
- return
- }
- //var playSeconds float64
- //playSeconds, err = mp3duration.Calculate(fPath)
- //if playSeconds <= 0 {
- // playSeconds, err = utils.GetVideoPlaySeconds(fPath)
- // if err != nil {
- // br.Msg = "获取音频时间失败"
- // br.ErrMsg = "获取音频时间失败,Err:" + err.Error()
- // return
- // }
- //}
- playSecondsStr, err := utils.GetDuration(fPath) //mp3duration.Calculate(fPath)
- if err != nil {
- utils.FileLog.Info("获取音频时间失败,Err:" + err.Error())
- }
- fileBody, err := os.ReadFile(fPath)
- videoSize := len(fileBody)
- sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
- sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
- {
- reportChapterCreateTime, err := time.Parse(utils.FormatDateTime, reportChapterInfo.CreateTime)
- if err != nil {
- br.Msg = "上传失败"
- br.ErrMsg = "上传失败,Err:" + err.Error()
- return
- }
- createTimeStr := reportChapterCreateTime.Format("0102")
- videoName := reportChapterInfo.Title + "(" + createTimeStr + ")"
- reportChapterInfo.VideoUrl = resourceUrl
- reportChapterInfo.VideoName = videoName
- reportChapterInfo.VideoPlaySeconds = playSecondsStr //fmt.Sprint(playSeconds)
- reportChapterInfo.VideoSize = sizeStr
- reportChapterInfo.VideoKind = 1
- reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
- reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
- reportInfo.VoiceGenerateType = 1
- reportChapterInfo.ModifyTime = time.Now()
- err = reportChapterInfo.UpdateChapter([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "VideoKind", "LastModifyAdminId", "LastModifyAdminName", "VoiceGenerateType", "ModifyTime"})
- if err != nil {
- br.Msg = "上传失败"
- br.ErrMsg = "修改报告章节的音频信息失败,Err:" + err.Error()
- return
- }
- // 修改报告的最近更新人信息
- reportInfo.LastModifyAdminId = this.SysUser.AdminId
- reportInfo.LastModifyAdminName = this.SysUser.RealName
- reportInfo.ModifyTime = time.Now()
- err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
- if err != nil {
- br.Msg = "上传失败"
- br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
- return
- }
- }
- // 处理报告中的音频文件分贝
- go services.HandleVideoDecibel(reportChapterInfo)
- resp := new(models.ResourceResp)
- resp.Id = newId
- resp.ResourceUrl = resourceUrl
- br.Msg = "上传成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- // PublishDayWeekReportChapter
- // @Title 发布章节
- // @Description 发布章节
- // @Param request body models.PublishReportChapterReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /publishDayWeekReportChapter [post]
- func (this *ReportController) PublishDayWeekReportChapter() {
- 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.PublishReportChapterReq
- 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 = "参数有误"
- 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.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 图表刷新状态
- refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
- if !refreshResult {
- br.Msg = "图表刷新未完成,请稍后操作"
- br.ErrMsg = "图表刷新未完成,请稍后操作"
- br.IsSendEmail = false
- return
- }
- // 如果是系统章节,那么需要校验下是否已经停更
- if chapterInfo.TypeId > 0 {
- // 获取规则配置
- reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
- if err != nil {
- br.Msg = "获取配置信息异常"
- br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
- return
- }
- if reportChapterTypeRule.Enabled == 0 {
- br.Msg = "该章节已永久停更"
- br.ErrMsg = "该章节已永久停更 "
- br.IsSendEmail = false
- return
- }
- }
- var publishTime time.Time
- if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime.IsZero() { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
- publishTime = reportInfo.PublishTime
- } else {
- publishTime = time.Now()
- }
- // 更新报告的最后编辑人
- reportInfo.LastModifyAdminId = sysUser.AdminId
- reportInfo.LastModifyAdminName = sysUser.RealName
- reportInfo.ModifyTime = time.Now()
- err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "报告最后编辑人保存失败, Err: " + err.Error()
- return
- }
- // 更新章节信息
- chapterInfo.IsEdit = 1
- chapterInfo.PublishState = 2
- chapterInfo.PublishTime = publishTime
- chapterInfo.LastModifyAdminId = this.SysUser.AdminId
- chapterInfo.LastModifyAdminName = this.SysUser.RealName
- chapterInfo.ModifyTime = time.Now()
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "IsEdit", "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
- err = chapterInfo.UpdateChapter(updateCols)
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 修改报告的最近更新人信息
- go func() {
- reportInfo.LastModifyAdminId = this.SysUser.AdminId
- reportInfo.LastModifyAdminName = this.SysUser.RealName
- reportInfo.ModifyTime = time.Now()
- err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
- if err != nil {
- br.Msg = "上传失败"
- br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
- return
- }
- }()
- // 生成音频
- go services.UpdateChaptersVideo([]int{chapterInfo.ReportChapterId})
- // 更新章节ES
- {
- go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
- }
- // 同时发布报告
- //if req.PublishReport == 1 {
- // if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
- // br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
- // br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
- // return
- // }
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // GetUnPublishReportChapterList
- // @Title 获取报告中未发布的章节数
- // @Description 获取报告中未发布的章节数
- // @Param ReportId query int true "报告ID"
- // @Success 200 Ret=200 获取成功
- // @router /chapter/un_publish/list [get]
- func (this *ReportController) GetUnPublishReportChapterList() {
- 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
- }
- reportId, _ := this.GetInt("ReportId")
- if reportId <= 0 {
- br.Msg = "参数有误"
- br.IsSendEmail = false
- return
- }
- reportInfo, err := models.GetReportById(reportId)
- if err != nil {
- br.Msg = "报告有误"
- br.ErrMsg = "报告有误, Err: " + err.Error()
- return
- }
- if reportInfo.HasChapter == 0 {
- br.Msg = "报告未包含章节"
- br.IsSendEmail = false
- return
- }
- // 获取未发布的章节列表
- unPublishedList, err := models.GetUnPublishedChapterList(reportInfo.Id)
- if err != nil {
- br.Msg = "获取未发布的章节数失败"
- br.ErrMsg = "获取未发布的章节数失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = unPublishedList
- }
- // EditChapterTitle
- // @Title 编辑章节标题
- // @Description 编辑章节标题
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /chapter/title/edit [post]
- func (this *ReportController) EditChapterTitle() {
- 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
- }
- req.Title = strings.TrimSpace(req.Title)
- if req.Title == `` {
- br.Msg = "章节名称不能为空"
- return
- }
- // 获取章节详情
- reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "报告章节信息有误"
- br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
- return
- }
- // 判断名称是否重复
- {
- var condition string
- var pars []interface{}
- condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
- pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
- count, err := models.GetCountReportChapterByCondition(condition, pars)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "判断章节名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "章节名称不允许重复"
- br.ErrMsg = "章节名称不允许重复"
- br.IsSendEmail = false
- 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 = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 报告的最后编辑人
- reportInfo.LastModifyAdminId = sysUser.AdminId
- reportInfo.LastModifyAdminName = sysUser.RealName
- reportInfo.ModifyTime = time.Now()
- reportChapterInfo.Title = req.Title
- reportChapterInfo.LastModifyAdminId = sysUser.AdminId
- reportChapterInfo.LastModifyAdminName = sysUser.RealName
- reportChapterInfo.ModifyTime = time.Now()
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Title", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
- // 更新报告的最近编辑人信息
- if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 更新章节
- if err = reportChapterInfo.UpdateChapter(updateCols); 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
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
|