1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/report"
- "eta_gn/eta_api/models/report_approve"
- "eta_gn/eta_api/models/smart_report"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services"
- "eta_gn/eta_api/services/alarm_msg"
- "eta_gn/eta_api/services/data"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- "strconv"
- "strings"
- "time"
- )
- 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)
- }
-
- 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 {
-
- 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)
- oldAndNewReportIdMap := make(map[int]int)
- 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
- }
-
- 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
- }
- }
-
-
-
- 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
-
-
-
- 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[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 {
-
- 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
- }
- 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)
-
- }
- }
-
- 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
- }
-
- if req.CollaborateType == 0 {
- req.CollaborateType = 1
- }
-
- if req.ReportLayout == 0 {
- req.ReportLayout = 1
- }
-
- req.IsPublicPublish = 2
-
-
-
- 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)
- if req.CreateTime != `` {
- formatDate := utils.FormatDateTime
- if !strings.Contains(req.CreateTime, ":") {
- formatDate = utils.FormatDate
- }
- createTime, tmpErr := time.ParseInLocation(formatDate, req.CreateTime, time.Local)
- if tmpErr != nil {
- br.Msg = "时间解析异常"
- br.ErrMsg = "时间解析异常,Err:" + err.Error()
- return
- }
- item.CreateTime = 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()
- item.ReportSource = utils.ReportSourceLocal
- 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
- }
- 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
- }
-
-
-
-
-
- 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
-
- return
- }
- reportInfo, e := models.GetReportByReportId(int(req.ReportId))
- if e != nil {
- if utils.IsErrNoRow(e) {
- 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
- }
- func (this *ReportController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
-
- 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 utils.IsErrNoRow(err) {
- 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.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
- }
- 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, err := models.GetReportByReportId(req.ReportId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "该报告不存在"
- br.ErrMsg = "该报告不存在, Err: " + err.Error()
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取报告详情失败, Err: " + err.Error()
- return
- }
- if reportInfo.Id > 0 && 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 || req.IsManualSave {
- 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)
-
- }
- 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
- }
-
- if req.IsManualSave {
- reportHistory := new(models.ReportHistory)
- reportHistory.ReportId = req.ReportId
- reportHistory.Title = reportInfo.Title
- reportHistory.Content = reportInfo.Content
- reportHistory.ContentSub = reportInfo.ContentSub
- reportHistory.ContentStruct = reportInfo.ContentStruct
- reportHistory.CanvasColor = reportInfo.CanvasColor
- reportHistory.HeadResourceId = reportInfo.HeadResourceId
- reportHistory.EndResourceId = reportInfo.EndResourceId
- reportHistory.AdminId = sysUser.AdminId
- reportHistory.AdminName = sysUser.AdminName
- reportHistory.CreateTime = time.Now()
- e = reportHistory.Add()
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + e.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
- }
- 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)
- stateStr := this.GetString("State")
- 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
- }
-
- 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)
- }
- if stateStr != `` {
- stateStrList := strings.Split(stateStr, ",")
- condition += ` AND a.state in (` + utils.GetOrmInReplace(len(stateStrList)) + `) `
- pars = append(pars, stateStrList)
- }
- 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)
-
- 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
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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
- }
- func (this *ReportController) BaseDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
-
- 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 utils.IsErrNoRow(err) {
- br.Msg = "报告已被删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- fmt.Println(reportInfo)
-
- 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,
- })
- }
- }
- }
-
- {
- minClassifyId := reportInfo.ClassifyIdThird
- if minClassifyId <= 0 {
- minClassifyId = reportInfo.ClassifyIdSecond
- }
- if minClassifyId <= 0 {
- minClassifyId = reportInfo.ClassifyIdFirst
- }
- if minClassifyId <= 0 {
- br.Msg = "分类异常"
- br.ErrMsg = "分类异常"
- return
- }
-
- 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
- }
- 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
- }
-
-
-
-
-
- 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
-
- return
- }
- reportInfo, e := models.GetReportByReportId(int(req.ReportId))
- if e != nil {
- if utils.IsErrNoRow(e) {
- 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
- }
- 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.PublishReportV2(vint, 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 = "发布成功"
- }
- 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
- }
-
- {
- go services.UpdateReportEs(req.ReportIds, 1)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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
- }
- 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
- }
-
- {
- reportPdfUrl := services.GetGeneralPdfUrl(reportDetail.ReportCode, reportDetail.ClassifyNameFirst, reportDetail.ReportLayout)
- go services.Report2pdfAndJpeg(reportPdfUrl, reportDetail.Id, 1)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "定时发布成功"
- }
- 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 utils.IsErrNoRow(e) {
- 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 = "操作成功"
- }
- 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 utils.IsErrNoRow(e) {
- 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
- }
-
-
-
-
-
-
- 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
- }
-
-
-
-
-
-
-
-
-
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- func (this *ReportController) MessageList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- pageIndex, _ := this.GetInt("CurrentIndex")
-
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if pageIndex <= 0 {
- pageIndex = 1
- }
- startSize = utils.StartIndex(pageIndex, pageSize)
- resp := new(models.ReportMessageListResp)
- resp.List = make([]*models.ReportMessageItem, 0)
- cond := fmt.Sprintf(` AND %s = ?`, models.ReportMessageCols.ReceiveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId)
- order := fmt.Sprintf(`%s ASC, %s DESC`, models.ReportMessageCols.IsRead, models.ReportMessageCols.CreateTime)
- messageOb := new(models.ReportMessage)
- total, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取消息列表总数失败, Err: " + e.Error()
- return
- }
- list, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取消息列表失败, Err: " + e.Error()
- return
- }
- var reportIds, pptIds []int
- for _, v := range list {
- t := models.FormatReportMessage2Item(v)
- if v.ExtraContent != "" {
- am := new(models.ReportMessageApproveItem)
- if e = json.Unmarshal([]byte(v.ExtraContent), &am); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("消息列表审批信息解析失败, %v", e)
- return
- }
- t.ApproveMsg = am
- }
- resp.List = append(resp.List, t)
-
- if v.ReportType == utils.ReportTypeDefault {
- reportIds = append(reportIds, v.ReportId)
- }
- if v.ReportType == utils.ReportTypePPT {
- pptIds = append(pptIds, v.ReportId)
- }
- }
- stateReport := make(map[int]int)
- statePpt := make(map[int]int)
- if len(reportIds) > 0 {
- ob := new(models.Report)
- cond := ` AND id IN (?)`
- pars := make([]interface{}, 0)
- pars = append(pars, reportIds)
- items, e := ob.GetItemsByCondition(cond, pars, []string{"id", "state"}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取报告列表失败, %v", e)
- return
- }
- for _, v := range items {
- stateReport[v.Id] = v.State
- }
- }
- if len(pptIds) > 0 {
- ob := new(models.PptV2)
- cond := ` AND ppt_id IN (?)`
- pars := make([]interface{}, 0)
- pars = append(pars, pptIds)
- items, e := ob.GetItemsByCondition(cond, pars, []string{"ppt_id", "state"}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取PPT列表失败, %v", e)
- return
- }
- for _, v := range items {
- statePpt[v.PptId] = v.State
- }
- }
- for _, v := range resp.List {
- if v.ReportType == utils.ReportTypeDefault {
- v.ReportState = stateReport[v.ReportId]
- }
- if v.ReportType == utils.ReportTypePPT {
- v.ReportState = statePpt[v.ReportId]
- }
- }
-
- cond += fmt.Sprintf(` AND %s = ?`, models.ReportMessageCols.IsRead)
- pars = append(pars, 0)
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取消息列表总数失败, Err: " + e.Error()
- return
- }
- resp.UnreadTotal = unreadTotal
- page := paging.GetPaging(pageIndex, pageSize, total)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- func (this *ReportController) MessageRead() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.ReportMessageReadReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- if req.MessageId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
- return
- }
- messageOb := new(models.ReportMessage)
- messageItem, e := messageOb.GetItemById(req.MessageId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- br.Msg = "消息不存在, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取消息失败, Err: " + e.Error()
- return
- }
- messageItem.IsRead = 1
- messageItem.ModifyTime = time.Now().Local()
- cols := []string{"IsRead", "ModifyTime"}
- if e = messageItem.Update(cols); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新消息已读失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|