123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mobile/models"
- "eta/eta_mobile/services"
- "eta/eta_mobile/services/alarm_msg"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/beego/beego/v2/server/web"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- "os"
- "path"
- "strconv"
- "strings"
- "time"
- )
- // ReportController 报告
- type ReportController struct {
- BaseAuthController
- }
- // ReportUploadCommonController 报告上传
- type ReportUploadCommonController struct {
- web.Controller
- }
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间)"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param Frequency query string true "频度"
- // @Param ClassifyNameFirst query string true "一级分类名称"
- // @Param ClassifyNameSecond query string true "二级分类名称"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Success 200 {object} models.ReportListResp
- // @router /list [get]
- func (this *ReportController) ListReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- timeType := this.GetString("TimeType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- frequency := this.GetString("Frequency")
- classifyNameFirst := this.GetString("ClassifyNameFirst")
- classifyNameSecond := this.GetString("ClassifyNameSecond")
- state, _ := this.GetInt("State")
- keyWord := this.GetString("KeyWord")
- companyType := this.GetString("CompanyType")
- msgIsSend, _ := this.GetInt("MsgIsSend")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- if timeType == "" {
- timeType = "publish_time"
- }
- if timeType != "publish_time" && timeType != "modify_time" {
- br.Msg = "请选择正确的时间"
- br.ErrMsg = "请选择正确的时间"
- return
- }
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (title LIKE '%` + keyWord + `%' OR admin_real_name LIKE '%` + keyWord + `%' ) `
- }
- if startDate != "" {
- condition += ` AND ` + timeType + ` >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND ` + timeType + ` <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- if classifyNameFirst != "" {
- condition += ` AND classify_name_first = ? `
- pars = append(pars, classifyNameFirst)
- }
- if classifyNameSecond != "" {
- condition += ` AND classify_name_second = ? `
- pars = append(pars, classifyNameSecond)
- }
- if state > 0 {
- condition += ` AND state = ? `
- pars = append(pars, state)
- }
- // 消息是否已推送 1-未推送; 2-已推送
- if msgIsSend == 1 {
- condition += ` AND (msg_is_send = 0 OR ths_msg_is_send = 0) `
- }
- if msgIsSend == 2 {
- condition += ` AND msg_is_send = 1 AND ths_msg_is_send = 1 `
- }
- total, err := models.GetReportListCount(condition, pars, companyType)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err := models.GetReportList(condition, pars, companyType, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listLen := len(list)
- if listLen > 0 {
- reportIdArr := make([]string, 0)
- syncReportIdArr := make([]string, 0) // 同步过来的报告IDs
- for i := 0; i < listLen; i++ {
- reportIdArr = append(reportIdArr, strconv.Itoa(list[i].Id))
- if list[i].OldReportId > 0 {
- syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
- }
- }
- reportIds := strings.Join(reportIdArr, ",")
- syncReportIds := strings.Join(syncReportIdArr, ",")
- // 查询同步过来的报告对应的老报告PV+UV
- pvMap := make(map[int]int, 0)
- uvMap := make(map[int]int, 0)
- if syncReportIds != "" {
- puvList, e := models.GetPUVByResearchReportIds(syncReportIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
- return
- }
- puvLen := len(puvList)
- for i := 0; i < puvLen; i++ {
- pvMap[puvList[i].ResearchReportId] = puvList[i].Pv
- uvMap[puvList[i].ResearchReportId] = puvList[i].Uv
- }
- }
- // 晨周报音频列表
- videoList, err := models.GetReportChapterVideoListByReportIds(reportIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告音频文件失败,Err:" + err.Error()
- return
- }
- for i := 0; i < listLen; i++ {
- list[i].Content = html.UnescapeString(list[i].Content)
- list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
- // 除周报外其余报告均可推送客群
- list[i].NeedThsMsg = 1
- //if list[i].HasChapter == 1 && list[i].ChapterType == utils.REPORT_TYPE_WEEK {
- // list[i].NeedThsMsg = 0
- //}
- chapterList := make([]*models.ReportChapterVideoList, 0)
- for ii := 0; ii < len(videoList); ii++ {
- if list[i].Id == videoList[ii].ReportId {
- chapterList = append(chapterList, videoList[ii])
- }
- }
- list[i].ChapterVideoList = chapterList
- list[i].Pv += pvMap[list[i].OldReportId]
- list[i].Uv += uvMap[list[i].OldReportId]
- }
- }
- for _, item := range list {
- /*key := fmt.Sprint(`crm:report:edit:`, item.Id)
- opUserId, _ := utils.Rc.RedisInt(key)
- //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
- if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
- item.CanEdit = true
- } else {
- adminInfo, errAdmin := system.GetSysUserById(opUserId)
- if errAdmin != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
- return
- }
- item.Editor = adminInfo.RealName
- }*/
- if item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
- item.CanEdit = true
- } else {
- markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName)
- if err != nil {
- br.Msg = "查询标记状态失败"
- br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
- return
- }
- if markStatus.Status == 0 {
- item.CanEdit = true
- } else {
- item.Editor = markStatus.Editor
- }
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.ReportListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 发布报告接口
- // @Description 发布报告
- // @Param request body models.PublishReq true "type json string"
- // @Success 200 Ret=200 发布成功
- // @router /publish [post]
- func (this *ReportController) PublishReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PublishReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportIds := req.ReportIds
- if reportIds == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- reportArr := strings.Split(reportIds, ",")
- tips := ""
- for _, v := range reportArr {
- vint, err := strconv.Atoi(v)
- if err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,Err:" + err.Error()
- return
- }
- report, err := models.GetReportById(vint)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- var publishTime time.Time
- if report.MsgIsSend == 1 && report.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
- publishTime, _ = time.ParseInLocation(utils.FormatDateTime, report.PublishTime, time.Local)
- } else {
- publishTime = time.Now()
- }
- var tmpErr error
- if report.HasChapter == 1 && (report.ChapterType == utils.REPORT_TYPE_DAY || report.ChapterType == utils.REPORT_TYPE_WEEK) {
- // 发布晨周报
- if tips, tmpErr = services.PublishDayWeekReport(vint); tmpErr != nil {
- br.Msg = "报告发布失败"
- br.ErrMsg = "晨周报发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
- return
- }
- } else {
- if report.Content == "" {
- br.Msg = "报告内容为空,不可发布"
- br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
- return
- }
- if tmpErr = models.PublishReportById(report.Id, publishTime); tmpErr != nil {
- br.Msg = "报告发布失败"
- br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
- return
- }
- go func() {
- // 生成音频
- if report.VideoUrl == "" {
- _ = services.CreateVideo(report)
- }
- //// 推送找钢网
- //if utils.RunMode == "release" && (report.ClassifyNameSecond == "知白守黑日评" || report.ClassifyNameSecond == "股债日评") {
- // _ = services.ZhaoGangSend(report)
- //}
- // 更新报告Es
- _ = services.UpdateReportEs(report.Id, 2)
- }()
- }
- }
- // 发布晨周报部分章节未发布的提示
- if tips != "" {
- br.Data = tips
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- }
- // @Title 取消发布报告接口
- // @Description 取消发布报告
- // @Param request body models.PublishCancelReq true "type json string"
- // @Success 200 Ret=200 取消发布成功
- // @router /publish/cancle [post]
- func (this *ReportController) PublishCancleReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PublishCancelReq
- 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
- }
- publishTimeNullFlag := true
- reportInfo, err := models.GetReportById(req.ReportIds)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if reportInfo.MsgIsSend == 1 {
- publishTimeNullFlag = false
- }
- err = models.PublishCancleReport(req.ReportIds, publishTimeNullFlag)
- if err != nil {
- br.Msg = "取消发布失败"
- br.ErrMsg = "取消发布失败,Err:" + err.Error()
- return
- }
- // 更新ES禁用
- {
- go services.UpdateReportEs(req.ReportIds, 1)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "取消发布成功"
- }
- // @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 = "删除成功"
- }
- // @Title 新增报告接口
- // @Description 新增报告
- // @Param request body models.AddReq true "type json string"
- // @Success 200 {object} models.AddResp
- // @router /add [post]
- func (this *ReportController) Add() {
- 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.AddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var contentSub string
- if req.Content != "" {
- 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)
- }
- }
- maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
- if err != nil {
- br.Msg = "期数获取失败!"
- br.ErrMsg = "期数获取失败,Err:" + err.Error()
- return
- }
- item := new(models.Report)
- item.AddType = req.AddType
- item.ClassifyIdFirst = req.ClassifyIdFirst
- item.ClassifyNameFirst = req.ClassifyNameFirst
- item.ClassifyIdSecond = req.ClassifyIdSecond
- item.ClassifyNameSecond = req.ClassifyNameSecond
- item.Title = req.Title
- item.Abstract = req.Abstract
- item.Author = req.Author
- item.Frequency = req.Frequency
- item.State = req.State
- item.Content = html.EscapeString(req.Content)
- item.Stage = maxStage + 1
- item.ContentSub = html.EscapeString(contentSub)
- item.CreateTime = req.CreateTime
- item.ModifyTime = time.Now()
- item.ReportVersion = req.ReportVersion
- item.AdminId = sysUser.AdminId
- item.AdminRealName = sysUser.RealName
- newReportId, err := models.AddReport(item)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- //处理权限
- {
- permissionItems, err := models.GetPermission(req.ClassifyNameSecond)
- if err != nil {
- go alarm_msg.SendAlarmMsg("获取权限失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "获取权限失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- for _, v := range permissionItems {
- err = models.AddChartPermissionChapterMapping(v.ChartPermissionId, newReportId)
- if err != nil {
- go alarm_msg.SendAlarmMsg("新增权限失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "新增权限失败,Err:"+err.Error()+strconv.FormatInt(newReportId, 10), utils.EmailSendToUsers)
- }
- }
- }
- reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
- //修改唯一编码
- {
- go models.ModifyReportCode(newReportId, reportCode)
- }
- resp := new(models.AddResp)
- resp.ReportId = newReportId
- resp.ReportCode = reportCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // @Title 编辑报告接口
- // @Description 编辑报告
- // @Param request body models.EditReq true "type json string"
- // @Success 200 {object} models.EditResp
- // @router /edit [post]
- func (this *ReportController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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 != "" {
- 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)
- }
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- //更新标记key
- markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
- 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, _ := models.GetReportById(int(req.ReportId))
- if report != nil {
- 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
- }
- }
- item := new(models.Report)
- item.ClassifyIdFirst = req.ClassifyIdFirst
- item.ClassifyNameFirst = req.ClassifyNameFirst
- item.ClassifyIdSecond = req.ClassifyIdSecond
- item.ClassifyNameSecond = req.ClassifyNameSecond
- item.Title = req.Title
- item.Abstract = req.Abstract
- item.Author = req.Author
- item.Frequency = req.Frequency
- item.State = req.State
- item.Stage = stage
- item.Content = html.EscapeString(req.Content)
- item.ContentSub = html.EscapeString(contentSub)
- item.CreateTime = req.CreateTime
- err = models.EditReport(item, req.ReportId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- //处理权限
- {
- err = models.RemoveChartPermissionChapterMapping(req.ReportId)
- if err != nil {
- go alarm_msg.SendAlarmMsg("修改删除报告权限失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "修改删除报告权限失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- permissionItems, err := models.GetPermission(req.ClassifyNameSecond)
- if err != nil {
- go alarm_msg.SendAlarmMsg("获取权限失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "获取权限失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- for _, v := range permissionItems {
- err = models.AddChartPermissionChapterMapping(v.ChartPermissionId, req.ReportId)
- if err != nil {
- go alarm_msg.SendAlarmMsg("新增权限失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "新增权限失败,Err:"+err.Error()+strconv.FormatInt(req.ReportId, 10), utils.EmailSendToUsers)
- }
- }
- }
- 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
- }
- // @Title 获取报告详情接口
- // @Description 获取报告详情
- // @Param request body models.ReportDetailReq true "type json string"
- // @Success 200 {object} models.Report
- // @router /detail [get]
- func (this *ReportController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- /*var req models.ReportDetailReq
- 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 = "参数错误"
- return
- }*/
- reportId, err := this.GetInt("ReportId")
- if err != nil {
- br.Msg = "获取参数失败!"
- br.ErrMsg = "获取参数失败,Err:" + err.Error()
- return
- }
- if reportId <= 0 {
- br.Msg = "参数错误"
- return
- }
- item, err := models.GetReportById(reportId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- chapterList := make([]*models.ReportChapter, 0)
- if item.HasChapter == 1 && (item.ChapterType == utils.REPORT_TYPE_DAY || item.ChapterType == utils.REPORT_TYPE_WEEK) {
- // 获取章节内容
- tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
- return
- }
- if len(tmpChapterList) > 0 {
- // 获取更新规则
- researchType := tmpChapterList[0].ReportType
- chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
- if tmpErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
- return
- }
- // 调整章节更新
- nowTime := time.Now().Local()
- for _, item := range tmpChapterList {
- stop := false
- for _, rule := range chapterTypeList {
- if rule.ReportChapterTypeId == item.TypeId {
- //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
- // 如果被永久暂停更新了
- if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
- stop = true
- } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
- startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
- if timeErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
- return
- }
- endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
- if timeErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
- return
- }
- // 暂停更新
- if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
- stop = true
- }
- break
- }
- }
- }
- if !stop {
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- chapterList = append(chapterList, item)
- }
- }
- }
- item.Abstract = item.Title
- }
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- resp := &models.ReportDetailView{
- ReportDetail: item,
- ChapterList: chapterList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @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
- }
- ext := path.Ext(h.Filename)
- dateDir := time.Now().Format("20060102")
- uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
- err = os.MkdirAll(uploadDir, 777)
- 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, err := services.UploadAliyun(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
- }
- // @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
- }
- // 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, "%"+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
- }
- // @Title 保存草稿
- // @Description 保存草稿
- // @Param request body models.SaveReportContent true "type json string"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /saveReportContent [post]
- func (this *ReportController) SaveReportContent() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- 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.SaveReportContent
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportId := req.ReportId
- noChangeFlag := req.NoChange
- fmt.Println("reportId:", reportId)
- if reportId > 0 {
- markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- }
- if reportId > 0 && noChangeFlag != 1 {
- fmt.Println("line 617")
- content := req.Content
- if content == "" {
- content = this.GetString("Content")
- }
- if content != "" {
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- content = contentClean
- contentSub, err := services.GetReportContentSub(content)
- if err != nil {
- go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- content = html.EscapeString(content)
- contentSub = html.EscapeString(contentSub)
- err = models.EditReportContent(reportId, content, contentSub)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- go models.AddReportSaveLog(reportId, this.SysUser.AdminId, content, contentSub, this.SysUser.AdminName)
- }
- }
- resp := new(models.SaveReportContentResp)
- resp.ReportId = reportId
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功成功"
- br.Data = resp
- }
- // @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
- }
- ext := path.Ext(h.Filename)
- dateDir := time.Now().Format("20060102")
- uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
- err = os.MkdirAll(uploadDir, 777)
- if err != nil {
- return
- }
- randStr := utils.GetRandStringNoSpecialChar(28)
- fileName := randStr + ext
- fpath := uploadDir + "/" + fileName
- defer f.Close() //关闭上传文件
- err = this.SaveToFile("file", fpath)
- if err != nil {
- return
- }
- //上传到阿里云
- resourceUrl, err := services.UploadAliyun(fileName, fpath)
- if err != nil {
- 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 {
- return
- }
- resp := new(models.ResourceResp)
- resp.Id = newId
- resp.ResourceUrl = resourceUrl
- this.Data["json"] = map[string]string{"link": resourceUrl}
- this.ServeJSON()
- }
- // @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
- }
- 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
- }
- // @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
- }
- 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 = "保存成功"
- }
- // @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
- }
- // 获取章节列表
- 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, 0)
- for i := 0; i < len(typeList); i++ {
- typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
- }
- resp := make([]*models.ReportChapterResp, 0)
- if len(chapterList) > 0 {
- // 获取更新规则
- researchType := chapterList[0].ReportType
- chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
- if tmpErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
- return
- }
- // 调整章节更新
- nowTime := time.Now().Local()
- for _, item := range chapterList {
- stop := false
- for _, rule := range chapterTypeList {
- if rule.ReportChapterTypeId == item.TypeId {
- //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
- // 如果被永久暂停更新了
- if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
- stop = true
- } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
- startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
- if timeErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
- return
- }
- endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
- if timeErr != nil {
- br.Msg = "获取更新规则失败"
- br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
- return
- }
- // 暂停更新
- if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
- stop = true
- }
- break
- }
- }
- }
- if !stop {
- resp = append(resp, &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),
- })
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // @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
- }
- 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
- }
- // @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
- }
- chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "获取章节信息失败"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- if chapterInfo != nil {
- chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
- chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = chapterInfo
- }
- // @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.Title == "" {
- // br.Msg = "请输入标题"
- // return
- //}
- if req.Content == "" {
- br.Msg = "请输入内容"
- return
- }
- if req.AddType == 0 {
- br.Msg = "请选择新增方式"
- return
- }
- reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
- if err != nil {
- br.Msg = "报告章节信息有误"
- br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
- return
- }
- reqTickerList := req.TickerList
- newContent := req.Content
- // 更新章节及指标
- contentSub := ""
- if req.Content != "" {
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- req.Content = contentClean
- contentSub, err = services.GetReportContentSub(req.Content)
- if err != nil {
- br.Msg = "内容分段解析失败"
- br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
- return
- }
- }
- if req.Content == "" {
- req.Content = newContent
- }
- reportChapterInfo.Title = req.Title
- reportChapterInfo.AddType = req.AddType
- reportChapterInfo.Author = req.Author
- reportChapterInfo.Content = html.EscapeString(req.Content)
- reportChapterInfo.ContentSub = html.EscapeString(contentSub)
- reportChapterInfo.IsEdit = 1
- reportChapterInfo.CreateTime = req.CreateTime
- reportChapterInfo.VideoUrl = req.VideoUrl
- reportChapterInfo.VideoName = req.VideoName
- reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
- reportChapterInfo.VideoSize = req.VideoSize
- reportChapterInfo.VideoKind = 1
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
- if req.VideoUrl != "" {
- updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
- }
- // 晨报更新指标
- tickerList := make([]*models.ReportChapterTicker, 0)
- if reportChapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
- nowTime := time.Now()
- for i := 0; i < len(reqTickerList); i++ {
- tickerList = append(tickerList, &models.ReportChapterTicker{
- ReportChapterId: reportChapterInfo.ReportChapterId,
- Sort: reqTickerList[i].Sort,
- Ticker: reqTickerList[i].Ticker,
- CreateTime: nowTime,
- UpdateTime: nowTime,
- })
- }
- }
- err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 备份关键数据
- 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 = "保存成功"
- }
- // @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
- }
- // @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
- }
- // 更新章节标签
- 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 = "保存成功"
- }
- // @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
- }
- 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
- }
- // @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
- //}
- // @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
- }
- 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
- }
- // @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
- }
- if req.Title == "" {
- br.Msg = "请输入标题"
- return
- }
- if req.Content == "" {
- br.Msg = "请输入内容"
- return
- }
- if req.AddType == 0 {
- br.Msg = "请选择新增方式"
- return
- }
- reqTickerList := req.TickerList
- chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
- if err != nil {
- br.Msg = "章节信息有误"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- reportInfo, err := models.GetReportById(chapterInfo.ReportId)
- if err != nil {
- br.Msg = "查询报告有误"
- br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
- return
- }
- // 获取规则配置
- 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
- }
- updateCols := make([]string, 0)
- updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "PublishState", "PublishTime")
- nowTime := time.Now()
- var publishTime time.Time
- if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
- publishTime, _ = time.ParseInLocation(utils.FormatDateTime, reportInfo.PublishTime, time.Local)
- } else {
- publishTime = time.Now()
- }
- if req.VideoUrl != "" {
- chapterInfo.VideoUrl = req.VideoUrl
- chapterInfo.VideoName = req.VideoName
- chapterInfo.VideoSize = req.VideoSize
- chapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
- chapterInfo.VideoKind = 1
- updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
- } else {
- if chapterInfo.VideoUrl == "" {
- // 生成video
- videoUrl, videoName, videoSize, videoPlaySeconds, err := services.CreateReportVideo(req.Title, req.Content, publishTime.Format(utils.FormatDateTime))
- if err != nil {
- br.Msg = "生成video失败"
- br.ErrMsg = "生成video失败, Err: " + err.Error()
- return
- }
- chapterInfo.VideoUrl = videoUrl
- chapterInfo.VideoName = videoName
- chapterInfo.VideoSize = videoSize
- chapterInfo.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
- chapterInfo.VideoKind = 2
- updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
- }
- }
- // 更新章节信息
- contentSub := ""
- if req.Content != "" {
- 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
- }
- }
- chapterInfo.Title = req.Title
- chapterInfo.AddType = req.AddType
- chapterInfo.Author = req.Author
- chapterInfo.Content = html.EscapeString(req.Content)
- chapterInfo.ContentSub = html.EscapeString(contentSub)
- chapterInfo.IsEdit = 1
- chapterInfo.CreateTime = req.CreateTime
- chapterInfo.PublishState = 2
- chapterInfo.PublishTime = publishTime
- // 晨报更新指标
- tickerList := make([]*models.ReportChapterTicker, 0)
- if chapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
- for i := 0; i < len(reqTickerList); i++ {
- tickerList = append(tickerList, &models.ReportChapterTicker{
- ReportChapterId: chapterInfo.ReportChapterId,
- Sort: reqTickerList[i].Sort,
- Ticker: reqTickerList[i].Ticker,
- CreateTime: nowTime,
- UpdateTime: nowTime,
- })
- }
- }
- if err = models.UpdateChapterAndTicker(chapterInfo, updateCols, tickerList); err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
- return
- }
- // 更新章节ES
- {
- go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
- }
- // 同时发布报告
- if req.PublishReport == 1 {
- if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
- br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
- br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @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
- }
- 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
- }
- tips, err := services.PublishDayWeekReport(reportId)
- if err != nil {
- br.Msg = "发布失败"
- br.ErrMsg = "发布晨/周报失败, Err: " + err.Error()
- return
- }
- // 部分章节未发布的提示信息
- if tips != "" {
- br.Data = tips
- }
- 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 = "操作成功"
- }
- // 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
- }
- 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, sysUser.AdminId, req.Status, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- msg := "标记成功"
- br.Ret = 200
- br.Success = true
- br.Msg = msg
- br.Data = data
- }
- // @Title 模板消息/客群消息推送接口
- // @Description 模板消息/客群消息推送接口
- // @Param request body models.SendTemplateMsgReq true "type json string"
- // @Success 200 Ret=200 推送成功
- // @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)
- }()
- }
- report, e := models.GetReportById(req.ReportId)
- if e != nil {
- br.Msg = "报告不存在或已被删除, 请刷新页面"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- if report.MsgIsSend == 1 && report.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 report.MsgIsSend == 0 {
- go func() {
- fmt.Println("推送模板消息:", req.ReportId)
- _ = services.SendMiniProgramReportWxMsg(req.ReportId)
- }()
- }
- // 推送客群消息
- if report.ThsMsgIsSend == 0 {
- //go func() {
- // 周报无客群消息
- // 2023-3-19 15:19:24 现在开始周报又要推送了
- //if report.HasChapter == 1 && report.ChapterType == utils.REPORT_TYPE_WEEK {
- // return
- //}
- //_ = services.SendReportMiniToThs(report)
- //}()
- }
- // 更新推送消息状态
- if err = models.ModifyReportMsgIsSendV2(req.ReportId); err != nil {
- br.Msg = "推送失败"
- br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "推送成功"
- br.IsAddLog = true
- }
- // GetStopDayWeekReportChapterTypeList
- // @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
- }
- var typeNameArr []string
- 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
- }
- // PrePublishReport
- // @Title 设置定时发布接口
- // @Description 设置定时发布接口
- // @Param request body models.PrePublishReq true "type json string"
- // @Success 200 Ret=200 发布成功
- // @router /pre_publish [post]
- func (this *ReportController) PrePublishReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PrePublishReq
- 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 = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- if req.PrePublishTime == "" {
- br.Msg = "发布时间不能为空"
- return
- }
- if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
- br.Msg = "参数错误"
- br.ErrMsg = "是否发送模版消息标识错误"
- return
- }
- prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
- if err != nil {
- br.Msg = "发布时间格式错误"
- br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
- return
- }
- if prePublishTime.Before(time.Now()) {
- br.Msg = "发布时间不允许选择过去时间"
- return
- }
- if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
- br.Msg = "发布时间距离当前时间太近了"
- return
- }
- report, err := models.GetReportById(reportId)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- if report.HasChapter == 1 && (report.ChapterType == utils.REPORT_TYPE_DAY || report.ChapterType == utils.REPORT_TYPE_WEEK) {
- br.Msg = "晨报周报不支持定时发布"
- return
- }
- if report.Content == "" {
- br.Msg = "报告内容为空,不可发布"
- br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
- return
- }
- if report.State == 2 {
- br.Msg = "报告已发布,不可设置定时发布"
- return
- }
- var tmpErr error
- if tmpErr = models.SetPrePublishReportById(report.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
- br.Msg = "设置定时发布失败"
- br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "定时发布成功"
- }
|