12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mobile/models"
- "eta/eta_mobile/services"
- "eta/eta_mobile/services/alarm_msg"
- "eta/eta_mobile/services/data"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/beego/beego/v2/server/web"
- "github.com/h2non/filetype"
- "github.com/tealeg/xlsx"
- "html"
- "io"
- "os"
- "path"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // ReportController 报告
- type ReportController struct {
- BaseAuthController
- }
- // ReportCommonController 报告
- type ReportCommonController struct {
- BaseCommonController
- }
- // ReportUploadCommonController 报告上传
- type ReportUploadCommonController struct {
- web.Controller
- }
- // Delete
- // @Title 删除报告接口
- // @Description 删除报告
- // @Param request body models.DeleteReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /delete [post]
- func (this *ReportController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportIds <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- if err := services.DeleteReportAndChapter(req.ReportIds); err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除报告失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- //func (this *ReportController) Edit() {
- // 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.EditReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // if req.Content == "" {
- // br.Msg = "报告内容不能为空"
- // return
- // }
- // var contentSub string
- // if req.Content != "" {
- // e := utils.ContentXssCheck(req.Content)
- // if e != nil {
- // br.Msg = "存在非法标签"
- // br.ErrMsg = "存在非法标签, Err: " + e.Error()
- // return
- // }
- // content, e := services.FilterReportContentBr(req.Content)
- // if e != nil {
- // br.Msg = "内容去除前后空格失败"
- // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- // return
- // }
- // req.Content = content
- //
- // contentSub, err = services.GetReportContentSub(req.Content)
- // if err != nil {
- // go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
- // //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- // }
- // }
- //
- // //更新标记key
- // markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- // if err != nil {
- // br.Msg = err.Error()
- // return
- // }
- // if markStatus.Status == 1 {
- // br.Msg = markStatus.Msg
- // //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
- // return
- // }
- //
- // var stage int
- // report, e := models.GetReportByReportId(int(req.ReportId))
- // if e != nil {
- // if e.Error() == utils.ErrNoRow() {
- // br.Msg = "报告已被删除, 请刷新页面"
- // return
- // }
- // br.Msg = "操作失败"
- // br.ErrMsg = "获取报告失败, Err: " + e.Error()
- // return
- // }
- // if report.State == models.ReportStatePublished || report.State == models.ReportStatePass {
- // br.Msg = "该报告已发布,不允许编辑"
- // br.ErrMsg = "该报告已发布,不允许编辑"
- // return
- // }
- // if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
- // maxStage, _ := models.GetReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
- // maxStage = maxStage + 1
- // stage = maxStage
- // } else {
- // stage = report.Stage
- // }
- // //if req.State != report.State {
- // // recordItem := &models.ReportStateRecord{
- // // ReportId: int(req.ReportId),
- // // ReportType: 1,
- // // State: req.State,
- // // AdminId: this.SysUser.AdminId,
- // // AdminName: this.SysUser.AdminName,
- // // CreateTime: time.Now(),
- // // }
- // // go func() {
- // // _, _ = models.AddReportStateRecord(recordItem)
- // // }()
- // //}
- //
- // //item := new(models.Report)
- // report.ClassifyIdFirst = req.ClassifyIdFirst
- // report.ClassifyNameFirst = req.ClassifyNameFirst
- // report.ClassifyIdSecond = req.ClassifyIdSecond
- // report.ClassifyNameSecond = req.ClassifyNameSecond
- // report.ClassifyIdThird = req.ClassifyIdThird
- // report.ClassifyNameThird = req.ClassifyNameThird
- // report.Title = req.Title
- // report.Abstract = req.Abstract
- // report.Author = req.Author
- // report.Frequency = req.Frequency
- // //report.State = report.State // 编辑不变更状态
- // report.Stage = stage
- // report.Content = html.EscapeString(req.Content)
- // report.ContentSub = html.EscapeString(contentSub)
- // report.CreateTime = req.CreateTime
- // //report.CollaborateType = req.CollaborateType
- // //report.ReportLayout = req.ReportLayout
- // if req.IsPublicPublish <= 0 {
- // req.IsPublicPublish = 1
- // }
- // report.IsPublicPublish = req.IsPublicPublish
- // err = report.Update([]string{"ClassifyIdFirst", "ClassifyNameFirst", "ClassifyIdSecond", "ClassifyNameSecond", "ClassifyIdThird", "ClassifyNameThird", "Title", "Abstract", "Author", "Frequency", "Stage", "Content", "ContentSub", "CreateTime", "IsPublicPublish"})
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "保存失败,Err:" + err.Error()
- // return
- // }
- //
- // //处理权限
- // //if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
- // go func() {
- // e := models.RemoveChartPermissionChapterMapping(req.ReportId)
- // if e != nil {
- // alarm_msg.SendAlarmMsg("修改删除报告权限失败,Err:"+e.Error(), 3)
- // return
- // }
- // permissionItems, e := models.GetPermission(req.ClassifyIdSecond)
- // if e != nil {
- // alarm_msg.SendAlarmMsg("获取权限失败,Err:"+e.Error(), 3)
- // return
- // }
- // for _, v := range permissionItems {
- // e = models.AddChartPermissionChapterMapping(v.ChartPermissionId, req.ReportId)
- // if e != nil {
- // alarm_msg.SendAlarmMsg("新增权限失败,Err:"+e.Error(), 3)
- // return
- // }
- // }
- // // 同步crm权限
- // _ = services.EditReportPermissionSync(req.ReportId, req.ClassifyIdSecond)
- // }()
- // //}
- //
- // reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
- // resp := new(models.EditResp)
- // resp.ReportId = req.ReportId
- // resp.ReportCode = reportCode
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "保存成功"
- // br.Data = resp
- //}
- // Upload
- // @Title 图片上传
- // @Description 图片上传接口
- // @Param file query file true "文件"
- // @Success 200 新增成功
- // @router /upload [post]
- func (this *ReportController) Upload() {
- 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
- }
- fileData, e := io.ReadAll(f)
- if e != nil {
- br.Msg = "上传失败"
- br.ErrMsg = "读取文件失败, Err: " + e.Error()
- return
- }
- pass := filetype.IsImage(fileData)
- if !pass {
- 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.UploadImgToMinIo(fileName, fpath)
- // if err != nil {
- // br.Msg = "文件上传失败"
- // br.ErrMsg = "文件上传失败,Err:" + err.Error()
- // return
- // }
- //} else {
- // resourceUrl, err = services.UploadAliyunV2(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 = 1
- item.CreateTime = time.Now()
- newId, err := models.AddResource(item)
- if err != nil {
- br.Msg = "资源上传失败"
- br.ErrMsg = "资源上传失败,Err:" + err.Error()
- return
- }
- resp := new(models.ResourceResp)
- resp.Id = newId
- resp.ResourceUrl = resourceUrl
- br.Msg = "上传成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- // ClassifyIdDetail
- // @Title 根据分类获取最近一次报告详情接口
- // @Description 根据分类获取最近一次报告详情
- // @Param request body models.ClassifyIdDetailReq true "type json string"
- // @Success 200 {object} models.Report
- // @router /classifyIdDetail [get]
- func (this *ReportController) ClassifyIdDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //classify_id_first=34&classify_id_second=36
- /*var req models.ClassifyIdDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }*/
- classifyIdFirst, _ := this.GetInt("classify_id_first")
- if classifyIdFirst <= 0 {
- classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
- }
- classifyIdSecond, _ := this.GetInt("classify_id_second")
- if classifyIdSecond <= 0 {
- classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
- }
- item, err := models.GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if item != nil {
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // SendTemplateMsg
- // @Title 模板消息推送接口
- // @Description 模板消息推送
- // @Param request body models.SendTemplateMsgReq true "type json string"
- // @Success 200 Ret=200 推送成功
- // @router /sendTemplateMsg [post]
- func (this *ReportController) SendTemplateMsg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- var req models.SendTemplateMsgReq
- 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 = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- report, _ := models.GetReportById(req.ReportId)
- if report.MsgIsSend == 1 {
- br.Msg = "消息已推送,请勿重复操作"
- br.ErrMsg = "模板消息已推送,请勿重复操作"
- return
- }
- videoNameDate := `(` + time.Now().Format("0102") + `)`
- err = models.UpdateReportPublishTime(req.ReportId, videoNameDate)
- if err != nil {
- br.Msg = "修改报告发布时间失败"
- br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
- return
- }
- err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate)
- if err != nil {
- br.Msg = "修改章节发布时间失败"
- br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
- return
- }
- services.SendMiniProgramReportWxMsg(req.ReportId)
- err = models.ModifyReportMsgIsSend(req.ReportId)
- if err != nil {
- br.Msg = "发送失败"
- br.ErrMsg = "发送失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发送成功"
- br.IsAddLog = true
- }
- // Author
- // @Title 获取报告作者接口
- // @Description 获取报告作者
- // @Param AuthorType query int true "来源类型,1:中文,2:英文"
- // @Param StartDate query string true "开始时间"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /author [get]
- func (this *ReportController) Author() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyword := this.GetString("Keyword")
- var condition string
- var pars []interface{}
- condition += ` AND author_type = 1 AND enable = 1`
- if keyword != `` {
- condition += ` AND report_author like ? `
- pars = append(pars, utils.GetLikeKeyword(keyword))
- }
- _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
- if err != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := models.ReportAuthorResp{
- List: items,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // UploadImg
- // @Title 图片上传
- // @Description 图片上传接口
- // @Param File query file true "文件"
- // @Success 200 上传成功
- // @router /uploadImg [post]
- func (this *ReportUploadCommonController) UploadImg() {
- var err error
- defer func() {
- if err != nil {
- fmt.Println("文件上传失败:", err.Error())
- go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒", "URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- f, h, err := this.GetFile("file")
- if err != nil {
- return
- }
- defer f.Close() //关闭上传文件
- // 不依赖于文件扩展名检查文件格式
- fileData, e := io.ReadAll(f)
- if e != nil {
- err = fmt.Errorf("读取文件失败, Err: %s", e.Error())
- return
- }
- pass := filetype.IsImage(fileData)
- if !pass {
- kind, _ := filetype.Match(fileData)
- if kind.Extension != "pdf" {
- err = fmt.Errorf("文件格式有误")
- return
- }
- fmt.Printf("File type: %s. MIME: %s\n", kind.Extension, kind.MIME.Value)
- }
- 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 {
- return
- }
- randStr := utils.GetRandStringNoSpecialChar(28)
- fileName := randStr + ext
- fpath := uploadDir + "/" + fileName
- err = this.SaveToFile("file", fpath)
- if err != nil {
- return
- }
- defer func() {
- os.Remove(fpath)
- }()
- // 上传至对象存储
- resourceUrl := ``
- ossClient := services.NewOssClient()
- if ossClient == nil {
- err = fmt.Errorf("初始化OSS服务失败")
- return
- }
- resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
- if err != nil {
- err = fmt.Errorf("文件上传失败, Err: %s", err.Error())
- return
- }
- item := new(models.Resource)
- item.ResourceUrl = resourceUrl
- item.ResourceType = 1
- item.CreateTime = time.Now()
- newId, err := models.AddResource(item)
- if err != nil {
- return
- }
- resp := new(models.ResourceResp)
- resp.Id = newId
- resp.ResourceUrl = resourceUrl
- this.Data["json"] = map[string]string{"link": resourceUrl}
- this.ServeJSON()
- }
- // Export
- // @Title 研报浏览数据导出
- // @Description 研报浏览数据导出接口
- // @Param ReportIds query string true "报告id,多个报告用英文,隔开"
- // @Success 200 {object} company.CompanyListResp
- // @router /report_view_record/export [get]
- func (this *ReportController) Export() {
- 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
- }
- reportIds := this.GetString("ReportIds")
- if reportIds == "" {
- br.Msg = "请选择需要下载的报告"
- br.ErrMsg = "请选择需要下载的报告"
- return
- }
- //生成excel文件
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- //只有权益研究员,以及超管可以下载
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
- br.Msg = "没有下载权限"
- br.ErrMsg = "没有下载权限"
- return
- }
- //普通样式
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- //设置默认字体和文字大小
- xlsx.SetDefaultFont(12, "宋体")
- style.Alignment = alignment
- style.ApplyAlignment = true
- //标题样式
- titleStyle := xlsx.NewStyle()
- titleFont := xlsx.NewFont(20, "宋体")
- titleFont.Bold = true
- titleStyle.Font = *titleFont
- titleStyle.Alignment = alignment
- //titleStyle.ApplyAlignment = true
- //表头
- headerStyle := xlsx.NewStyle()
- headerFont := xlsx.NewFont(12, "宋体")
- headerFont.Bold = true
- headerStyle.Font = *headerFont
- headerStyle.Alignment = alignment
- headerStyle.ApplyAlignment = true
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- //记录已经命名了的表单名称
- sheetNameMap := make(map[string]int)
- reportSlice := strings.Split(reportIds, ",")
- for _, reportIdStr := range reportSlice {
- reportId, convErr := strconv.Atoi(reportIdStr)
- if convErr != nil {
- br.Msg = "报告传参异常"
- br.ErrMsg = "报告传参异常"
- return
- }
- report, reportErr := models.GetReportById(reportId)
- if reportErr != nil {
- br.Msg = "查询报告异常"
- br.ErrMsg = "查询报告异常:" + reportErr.Error()
- return
- }
- //查询浏览记录
- _, viewList, err := models.GetViewListByReportId(reportId)
- //fmt.Println(total)
- //fmt.Println(viewList)
- //fmt.Println(err)
- if err != nil {
- br.Msg = "查询报告浏览记录异常"
- br.ErrMsg = "查询报告浏览记录异常:" + err.Error()
- return
- }
- //导入报表
- //报表名称
- createTime, _ := time.Parse(utils.FormatDateTime, report.CreateTime)
- timeStr := createTime.Format("0102")
- reportName := report.Title + "(" + timeStr + ")"
- //表单名称
- sheetName := reportName
- //判断当前sheet表单map中是否已经存在该表单名称,如果存在,那么需要添加后缀,并给sheet表单map中赋值次数加1处理;不存在,那么还是使用当前名称,并给sheet表单map中赋值次数为1
- if n, ok := sheetNameMap[sheetName]; ok == true {
- n++
- sheetName = sheetName + "_" + strconv.Itoa(n)
- sheetNameMap[sheetName] = n
- } else {
- sheetNameMap[sheetName] = 1
- }
- sheel, err := xlsxFile.AddSheet(sheetName)
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //设置列宽
- sheel.SetColWidth(0, 0, 28)
- sheel.SetColWidth(1, 1, 18)
- sheel.SetColWidth(2, 2, 18)
- sheel.SetColWidth(3, 3, 18)
- sheel.SetColWidth(4, 4, 40)
- //标题行
- titleRow := sheel.AddRow()
- titleRow.SetHeight(40)
- //标题列
- titleCell := titleRow.AddCell()
- titleCell.HMerge = 4 //向右合并列数,不包括自身列
- //报表标题名称
- titleCell.SetValue(reportName)
- titleCell.SetStyle(titleStyle)
- //表头
- headerRow := sheel.AddRow()
- headerRow.SetHeight(18)
- timeHeaderCell := headerRow.AddCell()
- timeHeaderCell.SetValue("浏览时间")
- timeHeaderCell.SetStyle(headerStyle)
- nameHeaderCell := headerRow.AddCell()
- nameHeaderCell.SetValue("用户名称")
- nameHeaderCell.SetStyle(headerStyle)
- mobileHeaderCell := headerRow.AddCell()
- mobileHeaderCell.SetValue("手机号")
- mobileHeaderCell.SetStyle(headerStyle)
- emailHeaderCell := headerRow.AddCell()
- emailHeaderCell.SetValue("邮箱")
- emailHeaderCell.SetStyle(headerStyle)
- companyHeaderCell := headerRow.AddCell()
- companyHeaderCell.SetValue("所属企业客户名称")
- companyHeaderCell.SetStyle(headerStyle)
- for _, v := range viewList {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(18)
- timeCell := dataRow.AddCell()
- timeCell.SetString(v.CreateTime.Format(utils.FormatDateTime))
- timeCell.SetStyle(style)
- nameCell := dataRow.AddCell()
- nameCell.SetString(v.RealName)
- nameCell.SetStyle(style)
- mobileCell := dataRow.AddCell()
- mobileCell.SetString(v.Mobile)
- mobileCell.SetStyle(style)
- emailCell := dataRow.AddCell()
- emailCell.SetString(v.Email)
- emailCell.SetStyle(style)
- companyCell := dataRow.AddCell()
- companyCell.SetString(v.CompanyName)
- companyCell.SetStyle(style)
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "研报浏览记录" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // ThsSendTemplateMsg
- // @Title 客群消息推送接口
- // @Description 客群消息推送接口
- // @Param request body models.SendTemplateMsgReq true "type json string"
- // @Success 200 Ret=200 推送成功
- // @router /ths/sendTemplateMsg [post]
- func (this *ReportController) ThsSendTemplateMsg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.ThsSendTemplateMsgReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- for _, v := range req.ReportId {
- if v <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- //加锁,避免重复点击造成的多次推送
- {
- redisKey := fmt.Sprint("report:send:ths:", v)
- ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
- if !ok {
- br.Msg = "报告已推送客群,请勿重复推送"
- return
- }
- defer func() {
- utils.Rc.Delete(redisKey)
- }()
- }
- report, err := models.GetReportById(v)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "报告已经被删除,请刷新页面"
- br.ErrMsg = "报告已经被删除,请刷新页面,req:" + string(this.Ctx.Input.RequestBody)
- return
- }
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,req:" + string(this.Ctx.Input.RequestBody)
- return
- }
- if report.ThsMsgIsSend == 1 {
- br.Msg = "消息已推送,请勿重复操作"
- br.ErrMsg = "模板消息已推送,请勿重复操作1"
- return
- }
- err = models.ModifyReportThsMsgIsSend(report)
- if err != nil {
- br.Msg = "发送失败"
- br.ErrMsg = "发送失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发送成功"
- }
- // GetDayWeekReportChapterTypeList
- // @Title 获取晨报周报章节类型列表
- // @Description 获取晨报周报章节类型列表
- // @Param StopType query string true "停更类型 stop; disable;"
- // @Success 200 {object} models.ReportListResp
- // @router /getDayWeekReportChapterTypeList [get]
- func (this *ReportController) GetDayWeekReportChapterTypeList() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- var condition string
- var pars []interface{}
- // 停更类型
- stopType := this.GetString("StopType")
- switch stopType {
- case "", "stop":
- condition += ` AND enabled = ? `
- pars = append(pars, 1)
- case "disable":
- default:
- br.Msg = "停更类型异常"
- br.IsSendEmail = false
- return
- }
- dayList := make([]*models.ReportChapterType, 0)
- weekList := make([]*models.ReportChapterType, 0)
- // 晨报
- {
- tmpCondition := condition
- tmpPars := pars
- // 报告类型
- tmpCondition += ` AND research_type = ? `
- tmpPars = append(tmpPars, "day")
- list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
- if err != nil {
- br.Msg = "获取报告章节类型列表失败"
- br.ErrMsg = "获取报告章节类型列表失败, Err: " + err.Error()
- return
- }
- nowTime := time.Now()
- for _, v := range list {
- if v.IsSet == 1 {
- endTime, _ := time.Parse(utils.FormatDate, v.PauseEndTime)
- if nowTime.After(endTime.AddDate(0, 0, 1)) { //设置过期了已经
- v.IsSet = 0
- v.PauseStartTime = ``
- v.PauseEndTime = ``
- }
- }
- dayList = append(dayList, v)
- }
- }
- // 周报
- {
- tmpCondition := condition
- tmpPars := pars
- // 报告类型
- tmpCondition += ` AND research_type = ? `
- tmpPars = append(tmpPars, "week")
- list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
- if err != nil {
- br.Msg = "获取报告章节类型列表失败"
- br.ErrMsg = "获取报告章节类型列表失败, Err: " + err.Error()
- return
- }
- nowTime := time.Now()
- for _, v := range list {
- if v.IsSet == 1 {
- endTime, _ := time.Parse(utils.FormatDate, v.PauseEndTime)
- if nowTime.After(endTime.AddDate(0, 0, 1)) { //设置过期了已经
- v.IsSet = 0
- v.PauseStartTime = ``
- v.PauseEndTime = ``
- }
- }
- weekList = append(weekList, v)
- }
- }
- resp := models.UpdateReportChapterTypeResp{
- Day: dayList,
- Week: weekList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetDayWeekReportPauseTime
- // @Title 获取晨报周报的更新暂停时间
- // @Description 获取晨报周报的更新暂停时间
- // @Success 200 {object} models.ReportListResp
- // @router /getDayWeekReportPauseTime [get]
- func (this *ReportController) GetDayWeekReportPauseTime() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- list, err := models.GetDayWeekReportPauseTimeList()
- if err != nil {
- br.Msg = "获取晨报周报的更新暂停时间失败"
- br.ErrMsg = "获取晨报周报的更新暂停时间失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // SetDayWeekReportUpdateRule
- // @Title 设置晨报周报的更新规则
- // @Description 设置晨报周报的更新规则
- // @Param request body models.SetDayWeekReportUpdateRuleReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /setDayWeekReportUpdateRule [post]
- func (this *ReportController) SetDayWeekReportUpdateRule() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- var req models.SetDayWeekReportUpdateRuleReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- researchType := req.ResearchType
- if researchType == "" {
- br.Msg = "报告类型不能为空"
- return
- }
- // 设置章节类型的暂停时间
- if err := models.SetDayWeekReportUpdateRule(researchType, req.List); err != nil {
- br.Msg = "设置暂停时间失败"
- br.ErrMsg = "设置暂停时间失败, Err: " + err.Error()
- return
- }
- // 同步到crm数据库
- go func() {
- var syncReq services.ChapterTypeSyncReq
- _, _ = services.ReportChapterTypeSync(&syncReq)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // SetDayWeekReportEnableRule
- // @Title 设置晨报周报的永久暂停更新规则
- // @Description 设置晨报周报的永久暂停更新规则
- // @Param request body models.SetDayWeekReportEnableUpdateRuleReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /setDayWeekReportEnableUpdateRule [post]
- func (this *ReportController) SetDayWeekReportEnableRule() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- var req models.SetDayWeekReportEnableUpdateRuleReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- dayReportChapterTypeIdList := strings.Split(req.DayReportChapterTypeId, ",")
- weekReportChapterTypeIdList := strings.Split(req.WeekReportChapterTypeId, ",")
- //if len(reportChapterTypeIdList) <= 0 {
- // br.Msg = "报告类型选择异常"
- // br.IsSendEmail = false
- // return
- //}
- // 设置章节类型的禁用状态
- if err := models.SetDayWeekReportEnableUpdateRule(dayReportChapterTypeIdList, weekReportChapterTypeIdList); err != nil {
- br.Msg = "设置永久停更失败"
- br.ErrMsg = "设置永久停更失败, Err: " + err.Error()
- return
- }
- go func() {
- var syncReq services.ChapterTypeSyncReq
- _, _ = services.ReportChapterTypeSync(&syncReq)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // AddDayWeekReport
- // @Title 新增晨报周报
- // @Description 新增晨报周报
- // @Param request body models.SaveDayWeekReportReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /addDayWeekReport [post]
- //func (this *ReportController) AddDayWeekReport() {
- // 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
- // }
- // if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "操作成功"
- // return
- // }
- //
- // var req models.SaveDayWeekReportReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- //
- // reportType := req.ReportType
- // if reportType == "" {
- // br.Msg = "请选择报告类型"
- // return
- // }
- // if reportType != utils.REPORT_TYPE_DAY && reportType != utils.REPORT_TYPE_WEEK {
- // br.Msg = "报告类型有误"
- // return
- // }
- // if req.Title == "" {
- // br.Msg = "请输入报告标题"
- // return
- // }
- // if req.CreateTime == "" {
- // br.Msg = "请选择发布时间"
- // return
- // }
- //
- // // 报告
- // var frequency, classifyName string
- // var classifyId int
- // if reportType == utils.REPORT_TYPE_DAY {
- // frequency = "日度"
- // classify, err := models.GetClassifyByKeyword("晨报")
- // if err == nil {
- // classifyId = classify.Id
- // classifyName = "晨报"
- // }
- // } else if reportType == utils.REPORT_TYPE_WEEK {
- // frequency = "周度"
- // classify, err := models.GetClassifyByKeyword("周报")
- // if err == nil {
- // classifyId = classify.Id
- // classifyName = "周报"
- // }
- // } else {
- // br.Msg = "报告类型有误"
- // return
- // }
- //
- // // 获取晨周报期数
- // yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
- // maxStage, err := models.GetDayWeekReportStage(classifyId, yearStart)
- // if err != nil {
- // br.Msg = "获取报告期数失败"
- // br.ErrMsg = "获取报告期数失败,Err:" + err.Error()
- // return
- // }
- // stage := maxStage + 1
- //
- // item := new(models.Report)
- // item.AddType = 1
- // item.ClassifyIdFirst = classifyId
- // item.ClassifyNameFirst = classifyName
- // item.Title = req.Title
- // item.Author = req.Author
- // item.Frequency = frequency
- // item.State = 1
- // item.Stage = stage
- // item.CreateTime = req.CreateTime
- // item.ModifyTime = time.Now()
- // item.HasChapter = 1
- // item.ChapterType = reportType
- //
- // // 章节类型列表
- // typeList, err := models.GetReportChapterTypeListByResearchType(reportType)
- // if err != nil {
- // br.Msg = "获取报告章节类型列表失败"
- // br.ErrMsg = "获取报告章节类型列表失败,Err:" + err.Error()
- // return
- // }
- // var chapterList []*models.ReportChapter
- // // 晨报自动继承上一期内容
- // skip := false
- // if reportType == utils.REPORT_TYPE_DAY {
- // lastDayReport, err := models.GetLastPublishDayWeekReport(utils.REPORT_TYPE_DAY)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取上一期晨报失败"
- // br.ErrMsg = "获取上一期晨报失败,Err:" + err.Error()
- // return
- // }
- // if lastDayReport != nil {
- // // 继承上一篇章节内容
- // lastReportChapters, err := models.GetPublishedChapterListByReportId(lastDayReport.Id)
- // if err != nil {
- // br.Msg = "获取上一期晨报章节失败"
- // br.ErrMsg = "获取上一期晨报章节失败,Err:" + err.Error()
- // return
- // }
- // chapterMap := make(map[int]*models.ReportChapter)
- // for i := 0; i < len(lastReportChapters); i++ {
- // chapterMap[lastReportChapters[i].TypeId] = lastReportChapters[i]
- // }
- // for _, typeItem := range typeList {
- // v := chapterMap[typeItem.ReportChapterTypeId]
- // chapterItem := new(models.ReportChapter)
- // if v != nil {
- // chapterItem.AddType = 2
- // chapterItem.Title = v.Title
- // chapterItem.ReportType = reportType
- // chapterItem.ClassifyIdFirst = classifyId
- // chapterItem.ClassifyNameFirst = classifyName
- // chapterItem.TypeId = typeItem.ReportChapterTypeId
- // chapterItem.TypeName = typeItem.ReportChapterTypeName
- // chapterItem.Content = v.Content
- // chapterItem.ContentSub = v.ContentSub
- // chapterItem.Stage = stage
- // chapterItem.PublishState = 1
- // chapterItem.Sort = typeItem.Sort
- // chapterItem.CreateTime = req.CreateTime
- // chapterItem.ModifyTime = time.Now()
- // } else {
- // chapterItem.AddType = 1
- // chapterItem.ReportType = reportType
- // chapterItem.ClassifyIdFirst = classifyId
- // chapterItem.ClassifyNameFirst = classifyName
- // chapterItem.TypeId = typeItem.ReportChapterTypeId
- // chapterItem.TypeName = typeItem.ReportChapterTypeName
- // chapterItem.Stage = stage
- // chapterItem.PublishState = 1
- // chapterItem.Sort = typeItem.Sort
- // chapterItem.CreateTime = req.CreateTime
- // chapterItem.ModifyTime = time.Now()
- // }
- // chapterList = append(chapterList, chapterItem)
- // }
- // skip = true
- // }
- // }
- // if !skip {
- // // 空白章节
- // for _, typeItem := range typeList {
- // chapterItem := new(models.ReportChapter)
- // chapterItem.AddType = 1
- // chapterItem.ReportType = reportType
- // chapterItem.ClassifyIdFirst = classifyId
- // chapterItem.ClassifyNameFirst = classifyName
- // chapterItem.TypeId = typeItem.ReportChapterTypeId
- // chapterItem.TypeName = typeItem.ReportChapterTypeName
- // chapterItem.Stage = stage
- // chapterItem.PublishState = 1
- // chapterItem.Sort = typeItem.Sort
- // chapterItem.CreateTime = req.CreateTime
- // chapterItem.ModifyTime = time.Now()
- // chapterList = append(chapterList, chapterItem)
- // }
- // }
- //
- // // 新增报告及章节
- // var reportId int64
- // if reportId, err = models.AddReportAndChapter(item, chapterList); err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "新增报告及章节失败, Err: " + err.Error()
- // return
- // }
- // reportCode := utils.MD5(strconv.Itoa(int(reportId)))
- // // 修改唯一编码
- // {
- // go models.ModifyReportCode(reportId, reportCode)
- // }
- //
- // // 备份关键数据
- // go services.SaveReportLogs(item, chapterList, sysUser.AdminId, sysUser.RealName)
- //
- // resp := new(models.AddResp)
- // resp.ReportId = reportId
- // resp.ReportCode = reportCode
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "保存成功"
- // br.Data = resp
- //}
- // EditDayWeekReport
- // @Title 编辑晨周报
- // @Description 编辑晨周报
- // @Param request body models.SaveDayWeekReportReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /editDayWeekReport [post]
- func (this *ReportController) EditDayWeekReport() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- var req models.SaveDayWeekReportReq
- 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
- }
- if req.ReportType == "" {
- br.Msg = "请选择报告类型"
- return
- }
- if req.ReportType != utils.REPORT_TYPE_DAY && req.ReportType != utils.REPORT_TYPE_WEEK {
- br.Msg = "报告类型有误"
- return
- }
- if req.Title == "" {
- br.Msg = "请输入报告标题"
- return
- }
- if req.CreateTime == "" {
- br.Msg = "请选择发布时间"
- return
- }
- reportInfo, err := models.GetReportByReportId(req.ReportId)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
- return
- }
- if req.ReportType != reportInfo.ChapterType {
- br.Msg = "暂不允许修改晨周报类型"
- return
- }
- reportInfo.Title = req.Title
- reportInfo.CreateTime = req.CreateTime
- reportInfo.Author = req.Author
- err = models.EditReport(reportInfo, int64(req.ReportId))
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
- // GetLastDayWeekReportChapter
- // @Title 获取上一篇已发表的晨周报章节内容
- // @Description 获取上一篇已发表的晨周报章节内容
- // @Param TypeId query int true "品种ID"
- // @Param ReportType query string true "报告类型 day-晨报; week-周报; "
- // @Success 200 {object} company.CompanyListResp
- // @router /getLastDayWeekReportChapter [get]
- func (this *ReportController) GetLastDayWeekReportChapter() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- typeId, _ := this.GetInt("TypeId")
- reportType := this.GetString("ReportType")
- item, err := models.GetLastPublishedReportChapter(typeId, reportType)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上一篇晨周报失败, Err: " + err.Error()
- return
- }
- if item != nil {
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // GetChapterTrendTag
- // @Title 获取章节趋势标签列表
- // @Description 获取章节趋势标签列表
- // @Success 200 Ret=200 获取成功
- // @router /getChapterTrendTag [get]
- func (this *ReportController) GetChapterTrendTag() {
- 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
- }
- list, err := models.GetKeyWordListByFrom("trend")
- if err != nil {
- br.Msg = "获取章节趋势标签列表失败"
- br.ErrMsg = "获取章节趋势标签列表失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // GetDayReportTickerList
- // @Title 获取晨报数据指标列表
- // @Description 获取晨报数据指标列表
- // @Param ReportChapterId query int true "章节ID"
- // @Success 200 Ret=200 保存成功
- // @router /getDayReportTickerList [get]
- func (this *ReportController) GetDayReportTickerList() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- reportChapterId, _ := this.GetInt("ReportChapterId")
- if reportChapterId <= 0 {
- br.Msg = "章节ID有误"
- return
- }
- chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "获取章节信息失败"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- // 获取ticker列表
- tickerList, err := models.GetDailyBaseColumnList("", chapterInfo.TypeId)
- if err != nil {
- br.Msg = "获取指标列表失败"
- br.ErrMsg = "获取指标列表失败, Err: " + err.Error()
- return
- }
- // 获取章节ticker
- reportTicker, err := models.GetTickerListByReportChapterId(reportChapterId)
- if err != nil {
- br.Msg = "获取章节Ticker失败"
- br.ErrMsg = "获取章节Ticker失败, Err: " + err.Error()
- return
- }
- selectMap := make(map[string]int, 0)
- for i := 0; i < len(reportTicker); i++ {
- selectMap[reportTicker[i].Ticker] = 1
- }
- // 选中状态
- for _, item := range tickerList {
- if _, in := selectMap[item.BaseColumnTicker]; in {
- item.Selected = 1
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = tickerList
- }
- // GetDayWeekReportVideoList
- // @Title 获取晨周报音视频列表
- // @Description 获取晨周报音视频列表
- // @Param ReportId query int true "报告ID"
- // @Success 200 Ret=200 保存成功
- // @router /getDayWeekReportVideoList [get]
- func (this *ReportController) GetDayWeekReportVideoList() {
- 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 = "参数有误"
- return
- }
- list, err := models.GetReportChapterVideoList(reportId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告音频列表失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // IsLastDayWeekReportChapter
- // @Title 是否为晨周报本期最后一个发布的报告
- // @Description 是否为晨周报本期最后一个发布的报告
- // @Param ReportChapterId query int true "报告章节ID"
- // @Success 200 Ret=200 获取成功
- // @router /isLastDayWeekReportChapter [get]
- func (this *ReportController) IsLastDayWeekReportChapter() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- reportChapterId, _ := this.GetInt("ReportChapterId")
- if reportChapterId <= 0 {
- br.Msg = "参数有误"
- return
- }
- chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "章节信息有误"
- br.ErrMsg = "章节信息有误, Err: " + err.Error()
- return
- }
- // 获取已发布章节数及本期报告应发布数
- publishedNum, err := models.CountPublishedChapterNum(chapterInfo.ReportId)
- if err != nil {
- br.Msg = "获取已发布章节数失败"
- br.ErrMsg = "获取已发布章节数失败, Err: " + err.Error()
- return
- }
- enableTypeList, err := models.GetEnableReportChapterTypeList(chapterInfo.ReportType)
- if err != nil {
- br.Msg = "获取章节类型列表失败"
- br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
- return
- }
- var isLast bool
- enableNum := len(enableTypeList)
- publishedNum += 1
- if publishedNum == enableNum {
- isLast = true
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = isLast
- }
- // PublishDayWeekReport
- // @Title 发布晨周报
- // @Description 发布晨周报
- // @Param request body models.PublishDayWeekReportReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /publishDayWeekReport [post]
- func (this *ReportController) PublishDayWeekReport() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- var req models.PublishDayWeekReportReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportId := req.ReportId
- if reportId <= 0 {
- br.Msg = "参数有误"
- return
- }
- reportInfo, err := models.GetReportByReportId(reportId)
- if err != nil {
- br.Msg = "报告信息有误"
- br.ErrMsg = "报告信息有误, Err: " + err.Error()
- return
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布"
- return
- }
- // 图表刷新状态
- refreshResult := data.CheckBatchChartRefreshResult("report", reportId, 0)
- if !refreshResult {
- br.Msg = "图表刷新未完成,请稍后操作"
- br.ErrMsg = "图表刷新未完成,请稍后操作"
- br.IsSendEmail = false
- return
- }
- tips, err, errMsg := services.PublishChapterReport(reportInfo, "", sysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "发布晨/周报失败, Err: " + err.Error()
- return
- }
- // 部分章节未发布的提示信息
- if tips != "" {
- br.Data = tips
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // GetStopDayWeekReportChapterTypeList
- // @Title 获取暂停更新的晨报周报章节类型列表
- // @Description 获取暂停更新的晨报周报章节类型列表
- // @Success 200 {object} models.ReportListResp
- // @router /getStopDayWeekReportChapterTypeList [get]
- func (this *ReportController) GetStopDayWeekReportChapterTypeList() {
- 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
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- stopDay := make([]*models.ReportChapterType, 0)
- stopWeek := make([]*models.ReportChapterType, 0)
- disableDay := make([]*models.ReportChapterType, 0)
- disableWeek := make([]*models.ReportChapterType, 0)
- stopList, err := models.GetStopUpdateReportChapterTypeListByResearchType()
- if err != nil {
- br.Msg = "获取暂停更新报告章节类型列表失败"
- br.ErrMsg = "获取暂停更新报告章节类型列表失败, Err: " + err.Error()
- return
- }
- for _, v := range stopList {
- if v.ResearchType == "day" {
- stopDay = append(stopDay, v)
- } else {
- stopWeek = append(stopWeek, v)
- }
- }
- disableList, err := models.GetDisableUpdateReportChapterTypeListByResearchType()
- if err != nil {
- br.Msg = "获取停止更新报告章节类型列表失败"
- br.ErrMsg = "获取停止更新报告章节类型列表失败, Err: " + err.Error()
- return
- }
- for _, v := range disableList {
- if v.ResearchType == "day" {
- disableDay = append(disableDay, v)
- } else {
- disableWeek = append(disableWeek, v)
- }
- }
- resp := models.StopUpdateReportChapterTypeResp{
- StopDay: stopDay,
- StopWeek: stopWeek,
- DisableDay: disableDay,
- DisableWeek: disableWeek,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MarkEditStatus
- // @Title 标记报告编辑状态
- // @Description 标记报告编辑状态接口
- // @Param request body request.MarkEditEnReport true "type json string"
- // @Success 200 标记成功 ;202 标记成功
- // @router /mark [post]
- func (this *ReportController) MarkEditStatus() {
- 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.MarkEditReport
- 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
- }
- if req.Status < 0 {
- br.Msg = "标记状态异常"
- return
- }
- //更新标记key
- data, err := services.UpdateReportEditMark(req.ReportId, req.ReportChapterId, sysUser.AdminId, req.Status, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- msg := "标记成功"
- br.Ret = 200
- br.Success = true
- br.Msg = msg
- br.Data = data
- }
- // SendMsg
- // @Title 模板消息/客群消息推送接口
- // @Description 模板消息/客群消息推送接口
- // @Param request body models.SendTemplateMsgReq true "type json string"
- // @Success 200 {object} models.SendTemplateMsgResp
- // @router /sendMsg [post]
- func (this *ReportController) SendMsg() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.SendTemplateMsgReq
- 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 = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- // 加锁,避免重复点击造成的多次推送
- {
- redisKey := fmt.Sprint("report:send:ths:", req.ReportId)
- ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
- if !ok {
- br.Msg = "报告已推送, 请勿重复推送"
- return
- }
- defer func() {
- _ = utils.Rc.Delete(redisKey)
- }()
- }
- reportInfo, e := models.GetReportByReportId(req.ReportId)
- if e != nil {
- br.Msg = "报告不存在或已被删除, 请刷新页面"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- if reportInfo.MsgIsSend == 1 && reportInfo.ThsMsgIsSend == 1 {
- br.Msg = "消息已推送,请勿重复操作"
- br.ErrMsg = "消息已推送,请勿重复操作"
- return
- }
- // 更新报告发布时间
- videoNameDate := `(` + time.Now().Format("0102") + `)`
- if err = models.UpdateReportPublishTime(req.ReportId, videoNameDate); err != nil {
- br.Msg = "修改报告发布时间失败"
- br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
- return
- }
- if err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate); err != nil {
- br.Msg = "修改章节发布时间失败"
- br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
- return
- }
- // 可能存在历史数据两个只推了一个所以此处加个判断
- // 推送模板消息
- if reportInfo.MsgIsSend == 0 {
- go func() {
- fmt.Println("推送模板消息:", req.ReportId)
- _ = services.SendMiniProgramReportWxMsg(req.ReportId)
- }()
- }
- // 更新推送消息状态
- reportInfo.MsgIsSend = 1
- reportInfo.ThsMsgIsSend = 1
- reportInfo.MsgSendTime = time.Now()
- reportInfo.ModifyTime = time.Now()
- err = reportInfo.UpdateReport([]string{"MsgIsSend", "ThsMsgIsSend", "MsgSendTime", "ModifyTime"})
- if err != nil {
- br.Msg = "推送失败"
- br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "推送成功"
- br.IsAddLog = true
- br.Data = models.SendTemplateMsgResp{
- ReportId: reportInfo.Id,
- MsgSendTime: reportInfo.MsgSendTime.Format(utils.FormatDateTime),
- }
- }
- // CheckDayWeekReportChapterVideo
- // @Title 获取暂停更新的晨报周报章节类型列表
- // @Description 获取暂停更新的晨报周报章节类型列表
- // @Param ReportId query string true "报告ID"
- // @Success 200 {object} models.ReportListResp
- // @router /CheckDayWeekReportChapterVideo [get]
- func (this *ReportController) CheckDayWeekReportChapterVideo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reqReportId := this.GetString("ReportId")
- reportId, _ := strconv.Atoi(reqReportId)
- if reportId <= 0 {
- br.Msg = "报告ID有误"
- return
- }
- // 获取章节列表
- chapterList, err := models.GetChapterListByReportId(reportId)
- if err != nil {
- br.Msg = "获取章节列表失败"
- br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
- return
- }
- typeNameArr := make([]string, 0)
- for _, v := range chapterList {
- if v.VideoUrl == "" || (v.VideoUrl != "" && v.VideoKind == 2) {
- typeNameArr = append(typeNameArr, v.TypeName)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = typeNameArr
- }
|