12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/report"
- "eta/eta_api/models/report_approve"
- "eta/eta_api/models/smart_report"
- "eta/eta_api/models/system"
- "eta/eta_api/services"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/services/data"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- "io"
- "os"
- "strconv"
- "strings"
- "time"
- )
- // 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 ClassifyIdFirst query int true "一级分类id"
- // @Param ClassifyIdSecond query int true "二级分类id"
- // @Param ClassifyIdThird query int true "三级分类id"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param FilterReportType query string true "筛选报告类型,1:公共研报,2:共享研报,3:我的研报"
- // @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")
- classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
- classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
- classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
- state, _ := this.GetInt("State")
- keyWord := this.GetString("KeyWord")
- msgIsSend, _ := this.GetInt("MsgIsSend")
- filterReportType, _ := this.GetInt("FilterReportType", 1)
- 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 (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
- }
- if startDate != "" {
- condition += ` AND a.` + timeType + ` >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND a.` + timeType + ` <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND a.frequency = ? `
- pars = append(pars, frequency)
- }
- if classifyIdFirst > 0 {
- condition += ` AND a.classify_id_first = ? `
- pars = append(pars, classifyIdFirst)
- }
- if classifyIdSecond > 0 {
- condition += ` AND a.classify_id_second = ? `
- pars = append(pars, classifyIdSecond)
- }
- if classifyIdThird > 0 {
- condition += ` AND a.classify_id_third = ? `
- pars = append(pars, classifyIdThird)
- }
- if state > 0 {
- condition += ` AND a.state = ? `
- pars = append(pars, state)
- }
- // 消息是否已推送 1-未推送; 2-已推送
- if msgIsSend == 1 {
- condition += ` AND (a.msg_is_send = 0 OR a.ths_msg_is_send = 0) `
- }
- if msgIsSend == 2 {
- condition += ` AND a.msg_is_send = 1 AND a.ths_msg_is_send = 1 `
- }
- var err error
- var total int
- var list []*models.ReportList
- switch filterReportType {
- // 筛选报告类型,1:公共研报,2:共享研报,3:我的研报
- case 1:
- condition += ` AND a.is_public_publish = ? `
- pars = append(pars, 1)
- condition += ` AND a.state in (2,6) `
- case 3:
- condition += ` AND a.admin_id = ? `
- pars = append(pars, this.SysUser.AdminId)
- case 2:
- condition += ` AND (a.admin_id = ? or b.admin_id = ?) `
- pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId)
- }
- // 共享报告需要连表查询,所以需要单独写
- if filterReportType == 2 {
- total, err = models.GetReportListCountByGrant(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err = models.GetReportListByGrant(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- } else {
- total, err = models.GetReportListCountV1(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err = models.GetReportListV1(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- listLen := len(list)
- if listLen > 0 {
- pvMap := make(map[int]int)
- uvMap := make(map[int]int)
- reportIdArr := make([]int, 0)
- syncReportIdArr := make([]string, 0) // 同步过来的报告IDs
- oldAndNewReportIdMap := make(map[int]int) // 旧报告和新报告的id对应关系
- for i := 0; i < listLen; i++ {
- reportIdArr = append(reportIdArr, list[i].Id)
- if list[i].OldReportId > 0 && list[i].ReportLayout == 1 {
- syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
- oldAndNewReportIdMap[list[i].OldReportId] = list[i].Id
- }
- pvMap[list[i].Id] = list[i].Pv
- uvMap[list[i].Id] = list[i].Uv
- }
- // 当下报告的pv,uv
- if len(reportIdArr) > 0 {
- pvList, e := models.GetReportPvUvByReportIdList(reportIdArr)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
- return
- }
- for _, v := range pvList {
- pv := pvMap[v.ReportId]
- uv := uvMap[v.ReportId]
- pvMap[v.ReportId] = v.PvTotal + pv
- uvMap[v.ReportId] = v.UvTotal + uv
- }
- }
- //reportIds := strings.Join(reportIdArr, ",")
- //syncReportIds := strings.Join(syncReportIdArr, ",")
- // 查询同步过来的报告对应的老报告PV+UV
- 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++ {
- newReportId, ok := oldAndNewReportIdMap[puvList[i].ResearchReportId]
- if ok {
- pv := pvMap[newReportId]
- uv := uvMap[newReportId]
- pvMap[newReportId] = puvList[i].Pv + pv
- uvMap[newReportId] = puvList[i].Uv + 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].Id]
- list[i].Uv = uvMap[list[i].Id]
- }
- // 多人协作的协作报告,需要判断是否可编辑
- {
- grantObj := report.ReportGrant{}
- grantList, err := grantObj.GetGrantListByIdList(reportIdArr)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告授权失败,Err:" + err.Error()
- return
- }
- //grantMap := make(map[报告id]map[用户id]bool)
- grantMap := make(map[int]map[int]bool)
- for _, v := range grantList {
- grantUserMap, ok := grantMap[v.ReportId]
- if !ok {
- grantUserMap = make(map[int]bool)
- }
- grantUserMap[v.AdminId] = true
- grantMap[v.ReportId] = grantUserMap
- }
- for i, item := range list {
- if item.AdminId == this.SysUser.AdminId {
- list[i].HasAuth = true
- continue
- }
- // 查找授权
- var hasAuth bool
- grantUserMap, ok := grantMap[item.Id]
- // 如果报告根本没有授权用户,说明没有授权当前用户
- if !ok {
- continue
- }
- _, ok = grantUserMap[this.SysUser.AdminId]
- list[i].HasAuth = hasAuth
- // 如果报告关联用户找到,说明有授权当前用户
- if ok {
- list[i].HasAuth = true
- }
- }
- }
- }
- 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.HasChapter == 1 {
- item.CanEdit = true
- continue
- }
- markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
- 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
- }
- // 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
- }
- if req.Title == `` {
- br.Msg = "标题不能为空"
- br.ErrMsg = "标题不能为空"
- br.IsSendEmail = false
- return
- }
- if req.ClassifyIdFirst <= 0 {
- br.Msg = "分类必填"
- br.ErrMsg = "分类必填"
- br.IsSendEmail = false
- return
- }
- var contentSub string
- if req.Content != "" {
- e := utils.ContentXssCheck(req.Content)
- if e != nil {
- br.Msg = "存在非法标签"
- br.ErrMsg = "存在非法标签, Err: " + e.Error()
- return
- }
- content, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- req.Content = content
- contentSub, err = services.GetReportContentSub(req.Content)
- if err != nil {
- go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- // 报告期数
- maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird)
- if err != nil {
- br.Msg = "期数获取失败!"
- br.ErrMsg = "期数获取失败,Err:" + err.Error()
- return
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird, models.ReportOperateAdd)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- // 协作方式,1:个人,2:多人协作。默认:1
- if req.CollaborateType == 0 {
- req.CollaborateType = 1
- }
- // 报告布局,1:常规布局,2:智能布局。默认:1
- if req.ReportLayout == 0 {
- req.ReportLayout = 1
- }
- // 是否公开发布,1:是,2:否
- if req.IsPublicPublish == 0 {
- req.IsPublicPublish = 1
- }
- classifyItemList, err := models.GetClassifyListByIdList([]int{req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird})
- classifyMap := make(map[int]string)
- for _, v := range classifyItemList {
- classifyMap[v.Id] = v.ClassifyName
- }
- item := new(models.Report)
- item.AddType = req.AddType
- item.ReportVersion = 2
- item.ClassifyIdFirst = req.ClassifyIdFirst
- item.ClassifyNameFirst = classifyMap[req.ClassifyIdFirst]
- item.ClassifyIdSecond = req.ClassifyIdSecond
- item.ClassifyNameSecond = classifyMap[req.ClassifyIdSecond]
- 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
- item.ClassifyIdThird = req.ClassifyIdThird
- item.ClassifyNameThird = classifyMap[req.ClassifyIdThird]
- // 产品要求,如果是多人协作,那么就是章节类型的报告
- if req.CollaborateType == 2 {
- item.HasChapter = 1
- item.ChapterType = ""
- }
- item.LastModifyAdminId = sysUser.AdminId
- item.LastModifyAdminName = sysUser.RealName
- item.ContentModifyTime = time.Now()
- item.NeedSplice = 1
- item.ContentStruct = html.EscapeString(req.ContentStruct)
- item.HeadImg = req.HeadImg
- item.EndImg = req.EndImg
- item.CanvasColor = req.CanvasColor
- item.HeadResourceId = req.HeadResourceId
- item.EndResourceId = req.EndResourceId
- item.CollaborateType = req.CollaborateType
- item.ReportLayout = req.ReportLayout
- item.IsPublicPublish = req.IsPublicPublish
- item.ReportCreateTime = time.Now()
- err, errMsg := services.AddReportAndChapter(item, req.InheritReportId, req.GrantAdminIdList)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- recordItem := &models.ReportStateRecord{
- ReportId: item.Id,
- 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 = int64(item.Id)
- resp.ReportCode = item.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
- //}
- //更新标记key
- markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
- return
- }
- reportInfo, e := models.GetReportByReportId(int(req.ReportId))
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 编辑报告信息
- err, errMsg := services.EditReport(reportInfo, req, sysUser)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- 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 {
- // 获取章节内容
- tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
- return
- }
- if len(tmpChapterList) > 0 {
- // 章节类型的字段赋值
- for _, item := range tmpChapterList {
- 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)
- item.ContentStruct = html.UnescapeString(item.ContentStruct)
- if item.HeadResourceId > 0 {
- headResource, err := smart_report.GetResourceItemById(item.HeadResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- item.HeadImg = headResource.ImgUrl
- item.HeadStyle = headResource.Style
- }
- if item.EndResourceId > 0 {
- endResource, err := smart_report.GetResourceItemById(item.EndResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- item.EndImg = endResource.ImgUrl
- item.EndStyle = endResource.Style
- }
- resp := &models.ReportDetailView{
- ReportDetail: item,
- ChapterList: chapterList,
- }
- 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
- if reportId <= 0 {
- resp := new(models.SaveReportContentResp)
- resp.ReportId = reportId
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- return
- }
- // 获取报告详情
- reportInfo, _ := models.GetReportByReportId(req.ReportId)
- if reportInfo != nil && reportInfo.State == 2 {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 标记更新中
- {
- markStatus, err := services.UpdateReportEditMark(req.ReportId, 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- }
- // 内容有过修改的话,那么逻辑处理
- if noChangeFlag != 1 {
- content := req.Content
- if content == "" {
- content = this.GetString("Content")
- }
- if content != "" {
- e := utils.ContentXssCheck(req.Content)
- if e != nil {
- br.Msg = "存在非法标签"
- br.ErrMsg = "存在非法标签, Err: " + e.Error()
- return
- }
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- 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)
- }
- reportInfo.Content = html.EscapeString(content)
- reportInfo.ContentSub = html.EscapeString(contentSub)
- reportInfo.ContentStruct = html.EscapeString(req.ContentStruct)
- reportInfo.HeadImg = req.HeadImg
- reportInfo.EndImg = req.EndImg
- reportInfo.CanvasColor = req.CanvasColor
- reportInfo.HeadResourceId = req.HeadResourceId
- reportInfo.EndResourceId = req.EndResourceId
- reportInfo.ModifyTime = time.Now()
- reportInfo.ContentModifyTime = time.Now()
- updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
- err = reportInfo.UpdateReport(updateCols)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- go models.AddReportSaveLog(reportId, this.SysUser.AdminId, reportInfo.Content, reportInfo.ContentSub, reportInfo.ContentStruct, reportInfo.CanvasColor, this.SysUser.AdminName, reportInfo.HeadResourceId, reportInfo.EndResourceId)
- }
- }
- resp := new(models.SaveReportContentResp)
- resp.ReportId = reportId
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // AuthorizedListReport
- // @Title 获取有权限的报告列表接口
- // @Description 获取有权限的报告列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "搜索关键词"
- // @Param ClassifyIdFirst query int true "一级分类id"
- // @Param ClassifyIdSecond query int true "二级分类id"
- // @Param ClassifyIdThird query int true "三级分类id"
- // @Success 200 {object} models.ReportListResp
- // @router /list/authorized [get]
- func (this *ReportController) AuthorizedListReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyword := this.GetString("Keyword")
- classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
- classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
- classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var list []*models.ReportList
- // 没有输入信息,那就不展示
- if keyword == `` && classifyIdFirst <= 0 {
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(models.ReportListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // 当前用户有权限的报告id列表
- grantReportIdList := make([]int, 0)
- {
- obj := report.ReportGrant{}
- grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
- return
- }
- for _, v := range grantList {
- grantReportIdList = append(grantReportIdList, v.ReportId)
- }
- }
- var condition string
- var pars []interface{}
- if classifyIdFirst > 0 {
- condition += ` AND a.classify_id_first = ? `
- pars = append(pars, classifyIdFirst)
- }
- if classifyIdSecond > 0 {
- condition += ` AND a.classify_id_second = ? `
- pars = append(pars, classifyIdSecond)
- }
- if classifyIdThird > 0 {
- condition += ` AND a.classify_id_third = ? `
- pars = append(pars, classifyIdThird)
- }
- if keyword != `` {
- condition += ` AND a.title LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyword, 1)
- }
- var err error
- var total int
- orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
- pars = append(pars, 1, this.SysUser.AdminId)
- // 当前用户有权限的报告id列表
- num := len(grantReportIdList)
- if num > 0 {
- orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
- pars = append(pars, grantReportIdList)
- }
- orCondition += ` ) `
- condition += orCondition
- total, err = models.GetReportListCountByAuthorized(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //for _, item := range list {
- // if item.HasChapter == 1 {
- // item.CanEdit = true
- // } else {
- // markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
- // 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
- }
- // BaseDetail
- // @Title 获取报告基础信息详情接口
- // @Description 获取报告基础信息详情接口
- // @Param request body models.ReportDetailReq true "type json string"
- // @Success 200 {object} models.Report
- // @router /detail/base [get]
- func (this *ReportController) BaseDetail() {
- 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
- }
- reportInfo, 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)
- reportInfo.Content = html.UnescapeString(reportInfo.Content)
- reportInfo.ContentSub = html.UnescapeString(reportInfo.ContentSub)
- grandAdminList := make([]models.ReportDetailViewAdmin, 0)
- permissionList := make([]models.ReportDetailViewPermission, 0)
- // 处理报告授权用户列表
- {
- obj := report.ReportGrant{}
- grantList, tmpErr := obj.GetGrantListById(reportId)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- if len(grantList) > 0 {
- grandAdminIdList := make([]int, 0)
- for _, v := range grantList {
- grandAdminIdList = append(grandAdminIdList, v.AdminId)
- }
- adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range adminList {
- grandAdminList = append(grandAdminList, models.ReportDetailViewAdmin{
- AdminId: v.AdminId,
- AdminName: v.RealName,
- })
- }
- }
- }
- // 处理章节id关联品种id列表
- {
- minClassifyId := reportInfo.ClassifyIdThird
- if minClassifyId <= 0 {
- minClassifyId = reportInfo.ClassifyIdSecond
- }
- if minClassifyId <= 0 {
- minClassifyId = reportInfo.ClassifyIdFirst
- }
- if minClassifyId <= 0 {
- br.Msg = "分类异常"
- br.ErrMsg = "分类异常"
- return
- }
- // 获取分类关联的品种id
- classifyPermissionList, tmpErr := models.GetPermission(minClassifyId)
- if tmpErr != nil {
- br.Msg = "获取分类信息失败"
- br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
- return
- }
- if len(classifyPermissionList) > 0 {
- permissionIdList := make([]int, 0)
- for _, v := range classifyPermissionList {
- permissionIdList = append(permissionIdList, v.ChartPermissionId)
- }
- adminList, tmpErr := models.GetChartPermissionByIdList(permissionIdList)
- if tmpErr != nil {
- br.Msg = "获取章节id授权用户列表失败"
- br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
- return
- }
- for _, v := range adminList {
- permissionList = append(permissionList, models.ReportDetailViewPermission{
- PermissionId: v.ChartPermissionId,
- PermissionName: v.PermissionName,
- })
- }
- }
- }
- resp := &models.ReportDetailView{
- ReportDetail: reportInfo,
- ChapterList: chapterList,
- GrandAdminList: grandAdminList,
- PermissionList: permissionList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EditLayoutImg
- // @Title 版图设置接口
- // @Description 版图设置接口
- // @Param request body models.EditLayoutImgReq true "type json string"
- // @Success 200 {object} models.EditResp
- // @router /layout_img/edit [post]
- func (this *ReportController) EditLayoutImg() {
- 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.EditLayoutImgReq
- 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
- //}
- //更新标记key
- markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
- return
- }
- reportInfo, e := models.GetReportByReportId(int(req.ReportId))
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- br.IsSendEmail = false
- return
- }
- // 编辑报告信息
- err, errMsg := services.EditReportLayoutImg(reportInfo, req, sysUser)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != "" {
- br.Msg = errMsg
- }
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- 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
- }
- // 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
- }
- // 报告的图表刷新状态校验
- refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
- if !refreshResult {
- br.Msg = "图表刷新未完成,请稍后操作"
- br.ErrMsg = "图表刷新未完成,请稍后操作"
- br.IsSendEmail = false
- return
- }
- // 报告发布
- tmpTips, err, errMsg := services.PublishReport(vint, req.ReportUrl, this.SysUser)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = "报告发布失败,Err:" + err.Error()
- return
- }
- tips = tmpTips
- }
- // 发布晨周报部分章节未发布的提示
- if tips != "" {
- br.Data = tips
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- }
- // PublishCancelReport
- // @Title 取消发布报告接口
- // @Description 取消发布报告
- // @Param request body models.PublishCancelReq true "type json string"
- // @Success 200 Ret=200 取消发布成功
- // @router /publish/cancle [post]
- func (this *ReportController) PublishCancelReport() {
- 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, reportInfo.ClassifyIdThird, models.ReportOperateCancelPublish)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag, this.SysUser.AdminId, this.SysUser.RealName)
- 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)
- // 重置小程序详情页海报
- _ = services.ResetMiniProgramReportDetailCover(reportInfo.Id)
- }()
- br.Ret = 200
- br.Success = true
- }
- // 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
- }
- reportDetail, err := models.GetReportById(reportId)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if reportDetail == nil {
- br.Msg = "报告不存在"
- return
- }
- // 如果是章节类型的报告,那么需要确认所有章节已发布
- if reportDetail.HasChapter == 1 {
- chapterList, err := models.GetChapterListByReportId(reportId)
- if err != nil {
- return
- }
- for _, chapter := range chapterList {
- if chapter.PublishState == 1 {
- br.Msg = "还存在未发布的章节"
- br.ErrMsg = "还存在未发布的章节"
- return
- }
- }
- } else {
- if reportDetail.Content == "" {
- br.Msg = "报告内容为空,不可设置定时发布"
- br.ErrMsg = "报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportDetail.Id)
- return
- }
- }
- if reportDetail.State == 2 {
- br.Msg = "报告已发布,不可设置定时发布"
- return
- }
- // 校验是否开启了审批流
- opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, reportDetail.ClassifyIdFirst, reportDetail.ClassifyIdSecond, reportDetail.ClassifyIdThird)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- if opening {
- br.Msg = "报告已开启审批流, 不可设置定时发布"
- return
- }
- var tmpErr error
- if tmpErr = models.SetPrePublishReportById(reportDetail.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
- br.Msg = "设置定时发布失败"
- br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportDetail.Id)
- return
- }
- // 生成报告pdf和长图
- {
- reportPdfUrl := services.GetGeneralPdfUrl(reportDetail.ReportCode, reportDetail.ClassifyNameFirst, reportDetail.ReportLayout)
- go services.Report2pdfAndJpeg(reportPdfUrl, reportDetail.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
- }
- // 如果是章节类型的报告,那么需要确认所有章节已发布
- if reportItem.HasChapter == 1 {
- chapterList, err := models.GetChapterListByReportId(reportId)
- if err != nil {
- return
- }
- for _, chapter := range chapterList {
- if chapter.PublishState == 1 {
- br.Msg = "还存在未发布的章节"
- br.ErrMsg = "还存在未发布的章节"
- return
- }
- }
- } else {
- if reportItem.Content == "" {
- br.Msg = "报告内容为空,不可提交"
- br.ErrMsg = "报告内容为空,不可提交,report_id:" + strconv.Itoa(reportItem.Id)
- return
- }
- }
- // 校验当前审批配置, 返回下一个状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, 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, reportItem.ClassifyIdThird, 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
- }
- // 报告权限处理
- {
- go services.HandleReportPermission(reportItem)
- }
- 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, reportItem.ClassifyIdThird, 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
- //}
- // 重置小程序详情页海报
- go func() {
- _ = services.ResetMiniProgramReportDetailCover(reportItem.Id)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // init
- // @Description: 修复历史报告数据
- // @author: Roc
- // @datetime 2024-06-21 09:19:05
- func init() {
- //fixApproveRecord()
- //fixChapterPermission()
- //fixReportEs()
- //fixSmartReport()
- }
- // 修复研报审批数据
- func fixApproveRecord() {
- recordOb := new(report_approve.ReportApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ? AND %s in (?,?)`, report_approve.ReportApproveRecordCols.NodeType, report_approve.ReportApproveRecordCols.State)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, 0, report_approve.ReportApproveStatePass, report_approve.ReportApproveStateRefuse)
- list, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, "")
- if e != nil {
- fmt.Println("查找审批记录失败,Err:", e.Error())
- return
- }
- for _, recordItem := range list {
- //fmt.Println(recordItem)
- recordItem.NodeState = recordItem.State
- recordItem.NodeApproveUserId = recordItem.ApproveUserId
- recordItem.NodeApproveUserName = recordItem.ApproveUserName
- recordItem.NodeApproveTime = recordItem.ApproveTime
- // 如果不是或签,那么只需要修复自己就好了
- if recordItem.ApproveType != report_approve.NodeApproveTypeAny {
- recordCols := []string{"State", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
- if e = recordItem.Update(recordCols); e != nil {
- fmt.Println("更新审批记录状态失败,Err:", e.Error())
- }
- continue
- }
- // 或签
- // 需要将该审批的同一个节点的记录标记为已审批
- if e := recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); e != nil {
- fmt.Println("更新同一节点的其他审批记录状态失败,Err:", e.Error())
- }
- }
- fmt.Println("审批数据修复完成")
- }
- // fixChapterPermission
- // @Description: 修复章节关联的品种权限
- // @author: Roc
- // @datetime 2024-06-20 18:08:34
- func fixChapterPermission() {
- allChapterTypePermissionList, err := models.GetAllChapterTypePermission()
- if err != nil {
- fmt.Println("获取所有章节类型ID获取章节类型权限列表失败,Err:", err.Error())
- return
- }
- currChapterTypePermissionIdListMap := make(map[int][]int)
- hasPermissionMap := make(map[string]bool)
- for _, v := range allChapterTypePermissionList {
- tmpChapterTypePermissionList, ok := currChapterTypePermissionIdListMap[v.ReportChapterTypeId]
- if !ok {
- tmpChapterTypePermissionList = make([]int, 0)
- }
- key := fmt.Sprint(v.ReportChapterTypeId, "-", v.ChartPermissionId)
- if _, has := hasPermissionMap[key]; !has {
- hasPermissionMap[key] = true
- currChapterTypePermissionIdListMap[v.ReportChapterTypeId] = append(tmpChapterTypePermissionList, v.ChartPermissionId)
- }
- }
- //notIdList := []int{9675, 9675, 9740, 9749, 9768, 9773, 9791, 9792, 9793, 9850, 9851, 9852, 9852, 9852, 9853, 9854, 9856, 9857, 9857, 9858, 9859, 9860, 9861, 9862, 9862, 9863, 9866}
- notIdList := []int{}
- allReportChapterList, err := models.GetAllReportChapter()
- if err != nil {
- fmt.Println("获取所有章节失败,Err:", err.Error())
- return
- }
- addList := make([]*report.ReportChapterPermissionMapping, 0)
- for _, v := range allReportChapterList {
- // 如果是上面的章节id,那么就过滤掉,因为已经入库了
- if utils.InArrayByInt(notIdList, v.ReportChapterId) {
- continue
- }
- permissionIdList, ok := currChapterTypePermissionIdListMap[v.TypeId]
- if !ok {
- continue
- }
- for _, permissionId := range permissionIdList {
- addList = append(addList, &report.ReportChapterPermissionMapping{
- ReportChapterPermissionMappingId: 0,
- ReportChapterId: v.ReportChapterId,
- ChartPermissionId: permissionId,
- CreateTime: v.ModifyTime,
- })
- }
- }
- obj := report.ReportChapterPermissionMapping{}
- err = obj.MultiAdd(addList)
- if err != nil {
- fmt.Println("批量添加报章节的品种权限失败,Err:", err.Error())
- }
- return
- }
- // fixReportEs
- // @Description: 修复报告es数据
- // @author: Roc
- // @datetime 2024-06-20 18:08:34
- func fixReportEs() {
- //reportInfo, err := models.GetReportByReportId(3941)
- //if err != nil {
- // fmt.Println("查询信息失败,", err)
- // return
- //}
- //content := utils.TrimHtml(html.UnescapeString(reportInfo.Content))
- //fmt.Println(content)
- //
- //fmt.Println("=========================")
- //
- //chapterInfo, err := models.GetReportChapterInfoById(9637)
- //if err != nil {
- // fmt.Println("查询信息失败2,", err)
- // return
- //}
- //
- //content = utils.TrimHtml(html.UnescapeString(chapterInfo.Content))
- //fmt.Println(content)
- //
- //services.UpdateReportChapterEs(9637)
- //return
- var condition string
- var pars []interface{}
- condition += " AND state in (2,6) "
- list, err := models.GetReportListV1(condition, pars, 0, 100000)
- if err != nil {
- fmt.Println("查询信息失败,", err)
- return
- }
- num := len(list)
- fmt.Println(num, "条待修复报告es数据")
- for k, v := range list {
- fmt.Println("剩余", num-k, "条")
- services.UpdateReportEs(v.Id, 2)
- }
- fmt.Println("报告ES数据修复完成")
- return
- }
- // fixSmartReport
- // @Description: 修复智能研报的数据
- // @author: Roc
- // @datetime 2024-06-27 16:54:41
- func fixSmartReport() {
- fmt.Println("修复智能研报开始")
- // 先判断是否已经修复过数据,如果修复过,那么就不用修复了
- {
- condition := ` AND report_layout=2 and old_report_id>0 `
- list, err := models.GetReportByCondition(condition, []interface{}{}, []string{}, " order by id asc ", false, 0, 0)
- if err != nil {
- fmt.Println("获取已修复的报告列表失败, Err:" + err.Error())
- return
- }
- if len(list) > 0 {
- fmt.Println("智能研报已经修复过数据,不需要再次修复")
- return
- }
- }
- var condition string
- var pars []interface{}
- reportOB := new(smart_report.SmartReport)
- list, e := reportOB.GetItemsByCondition(condition, pars, []string{}, " smart_report_id asc ")
- if e != nil {
- fmt.Println("获取智能报告列表失败, Err:" + e.Error())
- return
- }
- addList := make([]*models.Report, 0)
- for _, v := range list {
- fmt.Println(v)
- addList = append(addList, &models.Report{
- //Id: 0,
- AddType: 1,
- ClassifyIdFirst: v.ClassifyIdFirst,
- ClassifyNameFirst: v.ClassifyNameFirst,
- ClassifyIdSecond: v.ClassifyIdSecond,
- ClassifyNameSecond: v.ClassifyNameSecond,
- Title: v.Title,
- Abstract: v.Abstract,
- Author: v.Author,
- Frequency: v.Frequency,
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- ModifyTime: v.ModifyTime,
- State: v.State,
- PublishTime: v.PublishTime,
- Stage: v.Stage,
- MsgIsSend: v.MsgIsSend,
- //ThsMsgIsSend: v.Tha,
- Content: v.Content,
- VideoUrl: v.VideoUrl,
- VideoName: v.VideoName,
- VideoPlaySeconds: fmt.Sprint(v.VideoPlaySeconds),
- VideoSize: v.VideoSize,
- ContentSub: v.ContentSub,
- ReportCode: fmt.Sprint(v.SmartReportId),
- ReportVersion: 1,
- HasChapter: 0,
- ChapterType: "",
- OldReportId: v.SmartReportId,
- MsgSendTime: v.MsgSendTime,
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- ApproveTime: v.ApproveTime,
- ApproveId: v.ApproveId,
- DetailImgUrl: v.DetailImgUrl,
- DetailPdfUrl: v.DetailPdfUrl,
- ContentStruct: v.ContentStruct,
- LastModifyAdminId: v.LastModifyAdminId,
- LastModifyAdminName: v.LastModifyAdminName,
- ContentModifyTime: v.ContentModifyTime,
- Pv: v.Pv,
- Uv: v.Uv,
- HeadImg: v.HeadImg,
- EndImg: v.EndImg,
- CanvasColor: v.CanvasColor,
- NeedSplice: v.NeedSplice,
- HeadResourceId: v.HeadResourceId,
- EndResourceId: v.EndResourceId,
- ClassifyIdThird: 0,
- ClassifyNameThird: "",
- CollaborateType: 1,
- ReportLayout: 2,
- IsPublicPublish: 1,
- ReportCreateTime: v.CreateTime,
- InheritReportId: 0,
- })
- }
- if len(addList) > 0 {
- err := models.InsertMultiReport(addList)
- if err != nil {
- fmt.Println("新增智能研报失败")
- return
- }
- reportMap := make(map[int]*models.Report)
- // 找出已经修复过的新的研报
- {
- reportList, tmpErr := models.GetReportByCondition(` AND report_layout=2 and old_report_id>0 `, []interface{}{}, []string{}, " order by id asc ", false, 0, 0)
- if tmpErr != nil {
- fmt.Println("获取已修复的报告列表失败, Err:" + tmpErr.Error())
- return
- }
- for _, v := range reportList {
- v.ReportCode = utils.MD5(strconv.Itoa(v.Id))
- v.Update([]string{"ReportCode"})
- reportMap[v.OldReportId] = v
- }
- }
- // 找出智能研报的审批单并处理
- {
- // 智能研报走审批单的
- reportApproveObj := new(report_approve.ReportApprove)
- approveList, tmpErr := reportApproveObj.GetItemsByCondition(` AND report_type=3 `, []interface{}{}, []string{}, " report_approve_id asc ")
- if tmpErr != nil {
- fmt.Println("获取已修复的报告列表失败, Err:" + tmpErr.Error())
- return
- }
- for _, v := range approveList {
- reportInfo, ok := reportMap[v.ReportId]
- if ok {
- v.ReportId = reportInfo.Id
- v.ReportType = 1
- err = v.Update([]string{"ReportType", "ReportId"})
- if err != nil {
- fmt.Println(v.ReportApproveId, "数据修复失败,其对应的报告ID是:", v.ReportId, ";新的报告ID是:", reportInfo.Id)
- }
- } else {
- fmt.Println(v.ReportApproveId, "找不到对应的报告,其对应的报告ID是:", v.ReportId)
- }
- }
- }
- }
- fmt.Println("修复智能研报完成")
- }
- func initPdf() {
- inFile := "anNNgk3Bbi4LRULwcJgNOPrREYh5.pdf"
- f2, err := services.GeneralWaterMarkPdf(inFile, "颜鹏 - 18170239278")
- //f2, err := services.GeneralWaterMarkPdf(inFile, "上周美国馏分油库存累库95万桶,馏分油表需环比下降(-25.6万桶/日)。本期馏分油产量继续抬升,在供增需减的环比变动下库存持续累库。馏分油供应的增加我们认为可能和进口的油种有关,今年以来美国进口的中重质原油占比不断走高,尤其是5")
- if err != nil {
- fmt.Println("生成失败,ERR:", err)
- return
- }
- // 创建一个新的文件
- newPdf, err := os.Create("new0555.pdf")
- if err != nil {
- fmt.Println("创建临时文件失败,Err:", err)
- return
- }
- defer func() {
- _ = newPdf.Close()
- }()
- _, _ = io.Copy(newPdf, f2)
- }
|