1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/report_approve"
- "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/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "html"
- "os"
- "path"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // ReportController 报告
- type ReportController struct {
- BaseAuthController
- }
- // ReportCommonController 报告
- type ReportCommonController struct {
- BaseCommonController
- }
- // ReportUploadCommonController 报告上传
- type ReportUploadCommonController struct {
- web.Controller
- }
- // ListReport
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_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" && timeType != "approve_time" {
- br.Msg = "请选择正确的时间"
- br.ErrMsg = "请选择正确的时间"
- return
- }
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
- }
- 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 len(syncReportIdArr) > 0 {
- puvList, e := models.GetPUVByResearchReportIds(syncReportIdArr)
- 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(reportIdArr)
- 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
- }
- // PublishReport
- // @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
- }
- refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
- if !refreshResult {
- br.Msg = "图表刷新未完成,请稍后操作"
- br.ErrMsg = "图表刷新未完成,请稍后操作"
- br.IsSendEmail = false
- 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
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, report.ClassifyIdFirst, report.ClassifyIdSecond, models.ReportOperatePublish)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- if state == models.ReportStatePublished {
- // 发布报告
- 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)
- }()
- } else {
- // 从无审批切换为有审批, 状态重置
- if e = models.ResetReportById(report.Id, state); tmpErr != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("重置报告状态失败, Err: %s, ReportId: %d", e.Error(), report.Id)
- return
- }
- }
- recordItem := &models.ReportStateRecord{
- ReportId: vint,
- ReportType: 1,
- State: state,
- AdminId: this.SysUser.AdminId,
- AdminName: this.SysUser.AdminName,
- CreateTime: time.Now(),
- }
- go func() {
- _, _ = models.AddReportStateRecord(recordItem)
- }()
- // 生成报告pdf和长图
- if req.ReportUrl != "" {
- go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 1)
- }
- }
- }
- // 发布晨周报部分章节未发布的提示
- if tips != "" {
- br.Data = tips
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- }
- // PublishCancleReport
- // @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
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, models.ReportOperateCancelPublish)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag)
- if err != nil {
- br.Msg = "取消发布失败"
- br.ErrMsg = "取消发布失败,Err:" + err.Error()
- return
- }
- // 更新ES禁用
- {
- go services.UpdateReportEs(req.ReportIds, 1)
- }
- //// 获取审批流设置
- //confKey := "approval_flow"
- //confTmp, e := company.GetConfigDetailByCode(confKey)
- //if e != nil {
- // br.Msg = "获取审批流配置失败"
- // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
- // return
- //}
- //if confTmp.ConfigValue == "1" || confTmp.ConfigValue == "2" || confTmp.ConfigValue == "3" {
- // br.Msg = "撤销成功"
- //} else {
- // br.Msg = "取消发布成功"
- //}
- recordItem := &models.ReportStateRecord{
- ReportId: req.ReportIds,
- ReportType: 1,
- State: state,
- AdminId: this.SysUser.AdminId,
- AdminName: this.SysUser.AdminName,
- CreateTime: time.Now(),
- }
- go func() {
- _, _ = models.AddReportStateRecord(recordItem)
- }()
- br.Ret = 200
- br.Success = true
- }
- // 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 = "删除成功"
- }
- // Add
- // @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
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, req.ClassifyIdFirst, req.ClassifyIdSecond, models.ReportOperateAdd)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.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 = 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
- }
- reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
- //修改唯一编码
- {
- go models.ModifyReportCode(newReportId, reportCode)
- }
- //处理权限
- //if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
- go func() {
- permissionItems, e := models.GetPermission(req.ClassifyNameSecond)
- if e != nil {
- alarm_msg.SendAlarmMsg("获取权限失败,Err:"+e.Error(), 3)
- return
- }
- for _, v := range permissionItems {
- e = models.AddChartPermissionChapterMapping(v.ChartPermissionId, newReportId)
- if e != nil {
- alarm_msg.SendAlarmMsg("新增权限失败,Err:"+e.Error(), 3)
- return
- }
- }
- // 同步crm权限
- _ = services.EditReportPermissionSync(newReportId, req.ClassifyNameSecond)
- }()
- //}
- recordItem := &models.ReportStateRecord{
- ReportId: int(newReportId),
- ReportType: 1,
- State: 1,
- AdminId: this.SysUser.AdminId,
- AdminName: this.SysUser.AdminName,
- CreateTime: time.Now(),
- }
- go func() {
- _, _ = models.AddReportStateRecord(recordItem)
- }()
- resp := new(models.AddResp)
- resp.ReportId = newReportId
- resp.ReportCode = reportCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // Edit
- // @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()
- }()
- 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 != "" {
- 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)
- 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.GetReportById(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)
- 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 = report.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
- }
- //处理权限
- //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.ClassifyNameSecond)
- 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.ClassifyNameSecond)
- }()
- //}
- 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
- }
- // Detail
- // @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 {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除"
- return
- }
- 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
- }
- // 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
- }
- 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
- }
- // SaveReportContent
- // @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 {
- reportInfo, _ := models.GetReportById(int(req.ReportId))
- if reportInfo != nil && reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- return
- }
- 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
- }
- // 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
- }
- 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
- defer f.Close() //关闭上传文件
- err = this.SaveToFile("file", fpath)
- if err != nil {
- return
- }
- resourceUrl := ``
- //上传到阿里云 和 minio
- //if utils.ObjectStorageClient == "minio" {
- // resourceUrl, err = services.UploadImgToMinIo(fileName, fpath)
- // if err != nil {
- // return
- // }
- //} else {
- // resourceUrl, err = services.UploadAliyunV2(fileName, fpath)
- // if err != nil {
- // return
- // }
- //}
- 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
- }
- 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()
- }
- // 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
- // }
- // // 周报无客群
- // if report.HasChapter == 1 && report.ChapterType == utils.REPORT_TYPE_WEEK {
- // br.Msg = "周报无需推送客群消息"
- // return
- // }
- // err = services.SendReportMiniToThs(report)
- // if err != nil {
- // br.Msg = "消息已推送,请勿重复操作"
- // br.ErrMsg = "模板消息已推送,请勿重复操作2, Err: " + err.Error()
- // 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 = "保存成功"
- }
- // GetReportChapterList
- // @Title 获取报告章节列表
- // @Description 获取报告章节列表
- // @Param ReportId query string true "报告ID"
- // @Success 200 {object} company.CompanyListResp
- // @router /getReportChapterList [get]
- func (this *ReportController) GetReportChapterList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- 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
- }
- // 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
- }
- // GetDayWeekChapter
- // @Title 获取晨周报章节信息
- // @Description 获取晨周报章节信息
- // @Param ReportChapterId query int true "报告章节ID"
- // @Success 200 Ret=200 保存成功
- // @router /getDayWeekChapter [get]
- func (this *ReportController) GetDayWeekChapter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reportChapterId, _ := this.GetInt("ReportChapterId")
- if reportChapterId <= 0 {
- br.Msg = "参数有误"
- return
- }
- 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
- }
- // EditDayWeekChapter
- // @Title 编辑晨周报章节内容
- // @Description 编辑晨周报章节内容
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /editDayWeekChapter [post]
- func (this *ReportController) EditDayWeekChapter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.EditReportChapterReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- reportChapterId := req.ReportChapterId
- if reportChapterId <= 0 {
- br.Msg = "报告章节ID有误"
- return
- }
- //if req.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
- }
- // 获取报告详情
- reportInfo, err := models.GetReportById(reportChapterInfo.ReportId)
- if err != nil {
- br.Msg = "报告信息有误"
- br.ErrMsg = "报告信息有误, Err: " + err.Error()
- return
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- 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 = "保存成功"
- }
- // 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
- }
- // EditChapterTrendTag
- // @Title 编辑章节趋势标签
- // @Description 编辑章节趋势标签
- // @Param request body models.EditReportChapterReq true "type json string"
- // @Success 200 Ret=200 保存成功
- // @router /editChapterTrendTag [post]
- func (this *ReportController) EditChapterTrendTag() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.EditChapterTrendTagReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportChapterId <= 0 {
- br.Msg = "章节ID有误"
- return
- }
- if req.Trend == "" {
- br.Msg = "请输入标签"
- return
- }
- chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
- if err != nil {
- br.Msg = "获取章节信息失败"
- br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
- return
- }
- // 更新章节标签
- 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 = "保存成功"
- }
- // 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
- }
- // PublishDayWeekReportChapter
- // @Title 发布晨周报章节
- // @Description 发布晨周报章节
- // @Param request body models.PublishReportChapterReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /publishDayWeekReportChapter [post]
- func (this *ReportController) PublishDayWeekReportChapter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- 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.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
- }
- if reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- return
- }
- // 图表刷新状态
- refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
- if !refreshResult {
- br.Msg = "图表刷新未完成,请稍后操作"
- br.ErrMsg = "图表刷新未完成,请稍后操作"
- br.IsSendEmail = false
- 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")
- var needHandleVideo bool // 是否需要处理音频文件
- 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")
- // 手动上传的音频需要处理音频文件
- needHandleVideo = true
- } 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
- }
- }
- // 处理报告中的音频文件分贝
- if needHandleVideo {
- go services.HandleVideoDecibel(chapterInfo)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // 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 := 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
- }
- 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.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
- }
- 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, 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
- }
- // SendMsg
- // @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 utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- 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
- }
- // 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
- }
- 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
- }
- // 校验是否开启了审批流
- opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, report.ClassifyIdFirst, report.ClassifyIdSecond)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- if opening {
- 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
- }
- // 生成报告pdf和长图
- if report.HasChapter != 1 && report.ChapterType != utils.REPORT_TYPE_DAY && report.ChapterType != utils.REPORT_TYPE_WEEK && req.ReportUrl != "" {
- go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 1)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "定时发布成功"
- }
- // SubmitApprove
- // @Title 提交审批
- // @Description 提交审批接口
- // @Param request body models.ReportSubmitApproveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /approve/submit [post]
- func (this *ReportController) SubmitApprove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- return
- }
- var req models.ReportSubmitApproveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- reportId := req.ReportId
- if reportId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
- return
- }
- reportOb := new(models.Report)
- reportItem, e := reportOb.GetItemById(reportId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- // 校验当前审批配置, 返回下一个状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, models.ReportOperateSubmitApprove)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
- return
- }
- // 下一个状态不为待审批时, 仅更新状态
- if state != models.ReportStateWaitApprove {
- reportItem.State = state
- e = reportItem.UpdateReport([]string{"State"})
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- // 提交审批
- approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "提交审批失败, Err: " + e.Error()
- return
- }
- reportItem.ApproveId = approveId
- reportItem.State = models.ReportStateWaitApprove
- reportItem.ModifyTime = time.Now().Local()
- e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // CancelApprove
- // @Title 撤销审批
- // @Description 撤销审批
- // @Param request body models.ReportCancelApproveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /approve/cancel [post]
- func (this *ReportController) CancelApprove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- return
- }
- var req models.ReportCancelApproveReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- reportId := req.ReportId
- if reportId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
- return
- }
- reportOb := new(models.Report)
- reportItem, e := reportOb.GetItemById(reportId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- // 校验当前审批配置, 返回下一个状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, models.ReportOperateCancelApprove)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
- return
- }
- // 下一个状态不为待提交时, 仅更新状态
- if state != models.ReportStateWaitSubmit {
- reportItem.State = state
- e = reportItem.UpdateReport([]string{"State"})
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- return
- }
- //if reportItem.ApproveId <= 0 {
- // br.Msg = "报告审批不存在"
- // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
- // return
- //}
- // 撤销审批
- e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "撤销审批失败, Err: " + e.Error()
- return
- }
- //reportItem.ApproveId = 0
- //reportItem.State = models.ReportStateWaitSubmit
- //reportItem.ModifyTime = time.Now().Local()
- //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
- //if e != nil {
- // br.Msg = "操作失败"
- // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
- // return
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|