12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/report"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/services/data"
- "eta/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
- }
- // 操作权限校验
- hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
- if !hasAuth {
- br.Msg = msg
- br.ErrMsg = errMsg
- br.IsSendEmail = isSendEmail
- return
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- if reportChapterInfo.PublishState == 2 {
- br.Msg = "该报告章节已发布,不允许编辑"
- br.ErrMsg = "该报告章节已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 报告的最后编辑人
- reportInfo.LastModifyAdminId = sysUser.AdminId
- reportInfo.LastModifyAdminName = sysUser.RealName
- reportInfo.ModifyTime = time.Now()
- updateCols := make([]string, 0)
- 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
- updateCols = append(updateCols, "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
- updateCols = append(updateCols, "CreateTime")
- }
- reportChapterInfo.LastModifyAdminId = sysUser.AdminId
- reportChapterInfo.LastModifyAdminName = sysUser.RealName
- reportChapterInfo.ContentModifyTime = time.Now()
- reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- updateCols = append(updateCols, "Author", "Content", "ContentSub", "IsEdit", "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
- }
- // 操作权限校验
- hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
- if !hasAuth {
- br.Msg = msg
- br.ErrMsg = errMsg
- br.IsSendEmail = isSendEmail
- 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.CheckReportAuthByReportId(sysUser, 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, 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.CheckReportAuthByReportId(sysUser, 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
- }
- // 操作权限校验
- hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, chapterInfo, false, this.Lang)
- if !hasAuth {
- br.Msg = msg
- br.ErrMsg = errMsg
- br.IsSendEmail = isSendEmail
- 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, 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, reportInfo.IsPublicPublish)
- }
- // 同时发布报告
- //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
- }
- // 操作权限校验
- hasAuth, msg, errMsg, isSendEmail := checkOpPermission(sysUser, reportInfo, reportChapterInfo, true, this.Lang)
- if !hasAuth {
- br.Msg = msg
- br.ErrMsg = errMsg
- br.IsSendEmail = isSendEmail
- 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 = "保存成功"
- }
- // CancelPublishReportChapter
- // @Title 取消发布章节
- // @Description 取消发布章节
- // @Param request body models.PublishReportChapterReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /chapter/publish/cancel [post]
- func (this *ReportController) CancelPublishReportChapter() {
- 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
- }
- // 章节发布状态校验
- if chapterInfo.PublishState == 1 {
- br.Msg = "该章节未发布,不能重复撤销"
- br.ErrMsg = "该章节未发布,不能重复撤销"
- br.IsSendEmail = false
- 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
- }
- // 更新章节信息
- chapterInfo.PublishState = 1
- chapterInfo.PublishTime = time.Time{}
- chapterInfo.LastModifyAdminId = this.SysUser.AdminId
- chapterInfo.LastModifyAdminName = this.SysUser.RealName
- chapterInfo.ModifyTime = time.Now()
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
- err = chapterInfo.UpdateChapter(updateCols)
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 更新章节ES
- {
- go services.UpdateReportChapterEs(chapterInfo.ReportChapterId, reportInfo.IsPublicPublish)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "撤销成功"
- }
- // checkOpPermission
- // @Description: 操作权限校验
- // @author: Roc
- // @datetime 2024-11-12 09:58:34
- // @param sysUser *system.Admin
- // @param reportInfo *models.Report
- // @param reportChapterInfo *models.ReportChapter
- // @param isMarkStatus bool
- // @param lang string
- // @return hasAuth bool
- // @return msg string
- // @return errMsg string
- // @return isSendEmail bool
- func checkOpPermission(sysUser *system.Admin, reportInfo *models.Report, reportChapterInfo *models.ReportChapter, isMarkStatus bool, lang string) (hasAuth bool, msg, errMsg string, isSendEmail bool) {
- isSendEmail = true
- // 权限校验
- isAuth, err := services.CheckChapterAuthByReportChapterInfo(sysUser, reportInfo.AdminId, reportChapterInfo)
- if err != nil {
- msg = "获取报告权限失败"
- errMsg = "获取报告权限失败,Err:" + err.Error()
- return
- }
- if !isAuth {
- msg = "没有权限"
- errMsg = "没有权限"
- isSendEmail = false
- return
- }
- // 如果不是创建人,那么就要去查看是否授权
- //if reportInfo.AdminId != sysUser.AdminId && !utils.IsAdminRole(sysUser.RoleTypeCode) {
- // // 授权用户权限校验
- // chapterGrantObj := report.ReportChapterGrant{}
- // _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
- // if tmpErr != nil {
- // if tmpErr.Error() == utils.ErrNoRow() {
- // msg = "没有权限"
- // errMsg = "没有权限"
- // isSendEmail = false
- // return
- // }
- // msg = "获取章节id授权用户失败"
- // errMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
- // return
- // }
- //}
- // 标记更新中
- if isMarkStatus {
- markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, lang)
- if err != nil {
- msg = err.Error()
- errMsg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- msg = markStatus.Msg
- errMsg = markStatus.Msg
- isSendEmail = false
- return
- }
- }
- // 有权限
- hasAuth = true
- return
- }
|