1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423 |
- package english_report
- import (
- "encoding/json"
- "eta/eta_mobile/controllers"
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/company"
- "eta/eta_mobile/models/report_approve"
- "eta/eta_mobile/models/system"
- "eta/eta_mobile/services"
- "eta/eta_mobile/services/alarm_msg"
- "eta/eta_mobile/services/data"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "html"
- "strconv"
- "strings"
- "time"
- )
- // EnglishReportController 研报活动模块
- type EnglishReportController struct {
- controllers.BaseAuthController
- }
- // @Title 新增报告接口
- // @Description 新增报告
- // @Param request body models.AddEnglishReportReq true "type json string"
- // @Success 200 {object} models.AddEnglishReportResp
- // @router /add [post]
- func (this *EnglishReportController) 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.AddEnglishReportReq
- 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
- }
- if req.Overview == "" {
- br.Msg = "请输入overview"
- return
- }
- if req.Abstract == "" {
- br.Msg = "请输入摘要"
- return
- }
- var contentSub string
- if req.Content != "" {
- content, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- req.Content = content
- contentSub, err = services.GetReportContentSub(req.Content)
- if err != nil {
- go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- maxStage, err := models.GetEnglishReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
- if err != nil {
- br.Msg = "期数获取失败!"
- br.ErrMsg = "期数获取失败,Err:" + err.Error()
- return
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird, models.ReportOperateAdd)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- item := new(models.EnglishReport)
- item.AddType = req.AddType
- item.ClassifyIdFirst = req.ClassifyIdFirst
- item.ClassifyNameFirst = req.ClassifyNameFirst
- item.ClassifyIdSecond = req.ClassifyIdSecond
- item.ClassifyNameSecond = req.ClassifyNameSecond
- item.Title = req.Title
- item.Abstract = req.Abstract
- item.Author = req.Author
- item.Frequency = req.Frequency
- item.State = state
- item.Content = html.EscapeString(req.Content)
- item.Stage = maxStage + 1
- item.ContentSub = html.EscapeString(contentSub)
- item.CreateTime = req.CreateTime
- item.ModifyTime = time.Now()
- item.Overview = req.Overview
- item.AdminId = sysUser.AdminId
- item.AdminRealName = sysUser.RealName
- newReportId, err := models.AddEnglishReport(item)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
- //修改唯一编码
- {
- go models.ModifyEnglishReportCode(newReportId, reportCode)
- }
- resp := new(models.AddEnglishReportResp)
- resp.ReportId = newReportId
- resp.ReportCode = reportCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // @Title 编辑报告接口
- // @Description 编辑报告
- // @Param request body models.EditEnglishReportReq true "type json string"
- // @Success 200 {object} models.EditEnglishReportResp
- // @router /edit [post]
- func (this *EnglishReportController) 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.EditEnglishReportReq
- 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
- }
- if req.Overview == "" {
- br.Msg = "请输入overview"
- return
- }
- if req.Abstract == "" {
- br.Msg = "请输入摘要"
- return
- }
- markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- var contentSub string
- if req.Content != "" {
- content, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- req.Content = content
- contentSub, err = services.GetReportContentSub(req.Content)
- if err != nil {
- go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }
- var stage int
- report, e := models.GetEnglishReportById(int(req.ReportId))
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- if report.State == models.ReportStatePublished || report.State == models.ReportStatePass {
- br.Msg = "该报告已发布,不允许编辑"
- br.ErrMsg = "该报告已发布,不允许编辑"
- return
- }
- if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
- maxStage, _ := models.GetEnglishReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
- maxStage = maxStage + 1
- stage = maxStage
- } else {
- stage = report.Stage
- }
- item := new(models.EnglishReport)
- item.ClassifyIdFirst = req.ClassifyIdFirst
- item.ClassifyNameFirst = req.ClassifyNameFirst
- item.ClassifyIdSecond = req.ClassifyIdSecond
- item.ClassifyNameSecond = req.ClassifyNameSecond
- item.Title = req.Title
- item.Abstract = req.Abstract
- item.Author = req.Author
- item.Frequency = req.Frequency
- item.State = report.State // 编辑不变更状态
- item.Stage = stage
- item.Content = html.EscapeString(req.Content)
- item.ContentSub = html.EscapeString(contentSub)
- item.CreateTime = req.CreateTime
- item.Overview = req.Overview
- err = models.EditEnglishReport(item, req.ReportId)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
- resp := new(models.EditEnglishReportResp)
- resp.ReportId = req.ReportId
- resp.ReportCode = reportCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // @Title 获取报告详情接口
- // @Description 获取报告详情
- // @Param request body models.ReportDetailReq true "type json string"
- // @Success 200 {object} models.EnglishReportDetailView
- // @router /detail [get]
- func (this *EnglishReportController) 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.GetEnglishReportById(reportId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "报告已被删除"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
- if item.ClassifyIdSecond > 0 {
- nameList, tErr := models.GetEnglishClassifyFullNameByIds([]int{item.ClassifyIdSecond})
- if tErr != nil {
- br.Msg = "获取分类名称失败"
- br.ErrMsg = "获取分类名称失败, ERR:" + tErr.Error()
- return
- }
- for _, v := range nameList {
- classifyNameMap[v.Id] = v
- }
- //处理分类名
- if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
- item.ClassifyNameRoot = n.RootName
- item.ClassifyIdRoot = n.RootId
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // 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 string true "一级分类id"
- // @Param ClassifyIdSecond query string true "二级分类id"
- // @Param State query int true "状态"
- // @Param KeyWord query string true "搜索关键词"
- // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
- // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
- // @Success 200 {object} models.ReportListResp
- // @router /list [get]
- func (this *EnglishReportController) ListReport() {
- 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
- }
- 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")
- classifyIdSecond, _ := this.GetInt("ClassifyIdSecond")
- classifyIdRoot, _ := this.GetInt("ClassifyIdRoot")
- state, _ := this.GetInt("State")
- keyWord := this.GetString("KeyWord")
- companyType := this.GetString("CompanyType")
- // 群发邮件状态筛选
- emailState, _ := this.GetInt("EmailState")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
- }
- if timeType == "" {
- timeType = "publish_time"
- }
- if timeType != "publish_time" && timeType != "modify_time" && timeType != "approve_time" {
- br.Msg = "请选择正确的时间"
- br.ErrMsg = "请选择正确的时间"
- return
- }
- if startDate != "" {
- condition += ` AND ` + timeType + ` >= ? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND ` + timeType + ` <= ? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- if classifyIdFirst != 0 {
- condition += ` AND classify_id_first = ? `
- pars = append(pars, classifyIdFirst)
- }
- if classifyIdSecond != 0 {
- condition += ` AND classify_id_second = ? `
- pars = append(pars, classifyIdSecond)
- }
- if state > 0 {
- condition += ` AND state = ? `
- pars = append(pars, state)
- }
- if classifyIdRoot > 0 && classifyIdFirst == 0 && classifyIdSecond == 0 {
- //查询顶级分类下的所有二级分类ID
- childClassify, err := models.GetEnglishSecondClassifyList([]int{classifyIdRoot})
- if err != nil {
- br.Msg = "查询子分类出错"
- br.ErrMsg = "查询子分类出错, Err:" + err.Error()
- return
- }
- var childClassifyIds []int
- if len(childClassify) > 0 {
- for _, v := range childClassify {
- childClassifyIds = append(childClassifyIds, v.Id)
- }
- condition += ` AND classify_id_first IN (` + utils.GetOrmInReplace(len(childClassifyIds)) + `)`
- pars = append(pars, childClassifyIds)
- } else {
- //一级分类下没有子分类,直接返回空列表
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp := new(models.EnglishReportListResp)
- resp.Paging = page
- resp.List = make([]*models.EnglishReportList, 0)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- }
- // 群发邮件状态筛选
- {
- // 未群发邮件(包含推送邮件失败的)
- if emailState == 1 {
- condition += ` AND (email_state = 0 OR email_has_fail = 1) `
- }
- // 已群发邮件
- if emailState == 2 {
- condition += ` AND email_state = 1 AND email_has_fail = 0 `
- }
- }
- var authOk bool
- adminMap := make(map[int]string, 0) // 编辑中的研究员姓名
- total, e := models.GetEnglishReportListCount(condition, pars, companyType)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取英文研报Count失败, Err: " + e.Error()
- return
- }
- list, e := models.GetEnglishReportList(condition, pars, companyType, startSize, pageSize, []string{})
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取英文研报列表失败, Err: " + e.Error()
- return
- }
- // 获取邮件配置-是否有权限群发
- conf := new(models.EnglishReportEmailConf)
- authKey := "english_report_email_conf"
- confAuth, e := company.GetConfigDetailByCode(authKey)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
- return
- }
- if confAuth.ConfigValue == "" {
- br.Msg = "获取失败"
- br.ErrMsg = "群发邮件配置为空"
- return
- }
- if e = json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "群发邮件配置有误, Err: " + e.Error()
- return
- }
- authArr := strings.Split(conf.SendAuthGroup, ",")
- if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
- authOk = true
- }
- // 获取admin, 用于匹配编辑中的研究员姓名
- admins, e := system.GetSysAdminList("", make([]interface{}, 0), []string{"admin_id", "real_name"}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取系统用户列表失败, Err: " + e.Error()
- return
- }
- for _, a := range admins {
- adminMap[a.AdminId] = a.RealName
- }
- // 查询分类信息
- var classifyIdSecondSlice []int
- for _, item := range list {
- classifyIdSecondSlice = append(classifyIdSecondSlice, item.ClassifyIdSecond)
- }
- classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
- if len(classifyIdSecondSlice) > 0 {
- nameList, err := models.GetEnglishClassifyFullNameByIds(classifyIdSecondSlice)
- if err != nil {
- br.Msg = "获取分类名称失败"
- br.ErrMsg = "获取分类名称失败, ERR:" + err.Error()
- return
- }
- for _, v := range nameList {
- classifyNameMap[v.Id] = v
- }
- }
- respList := make([]*models.EnglishReportList, 0)
- for _, v := range list {
- t := models.FormatEnglishReport2ListItem(v)
- if v.State == 2 {
- t.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + v.ReportCode
- }
- t.EmailAuth = authOk
- // 报告是否正在编辑中
- var opUser models.MarkReportItem
- key := fmt.Sprint(`crm:enReport:edit:`, v.Id)
- opUserId, e := utils.Rc.RedisInt(key)
- if e != nil {
- str, te := utils.Rc.RedisString(key)
- if te == nil {
- te = json.Unmarshal([]byte(str), &opUser)
- if te == nil {
- opUserId = opUser.AdminId
- }
- }
- }
- var ret models.MarkReportResp
- if opUserId > 0 && opUserId != sysUser.AdminId {
- editor := opUser.Editor
- if editor == "" {
- editor = adminMap[opUserId]
- }
- ret.Status = 1
- if this.Lang == utils.EnLangVersion {
- ret.Msg = fmt.Sprintf("%s is currently editing the report", editor)
- } else {
- ret.Msg = fmt.Sprintf("当前%s正在编辑报告", editor)
- }
- ret.Editor = editor
- }
- if ret.Status == 0 {
- t.CanEdit = true
- } else {
- t.Editor = ret.Editor
- }
- //处理分类名
- if n, ok := classifyNameMap[v.ClassifyIdSecond]; ok {
- if n.RootId == 0 {
- t.FullClassifyName = strings.Join([]string{n.ParentName, n.ClassifyName}, "/")
- } else {
- t.FullClassifyName = strings.Join([]string{n.RootName, n.ParentName, n.ClassifyName}, "/")
- }
- t.ClassifyIdRoot = n.RootId
- t.ClassifyNameRoot = n.RootName
- }
- respList = append(respList, t)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.EnglishReportListResp)
- resp.Paging = page
- resp.List = respList
- 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 *EnglishReportController) 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, ",")
- for _, v := range reportArr {
- vint, err := strconv.Atoi(v)
- if err != nil {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,Err:" + err.Error()
- return
- }
- report, err := models.GetEnglishReportById(vint)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- // 图表刷新状态
- refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
- if !refreshResult {
- br.Msg = "图表刷新未完成,请稍后操作"
- br.ErrMsg = "图表刷新未完成,请稍后操作"
- br.IsSendEmail = false
- return
- }
- var tmpErr error
- if report.Content == "" {
- br.Msg = "报告内容为空,不可发布"
- br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
- return
- }
- var publishTime string
- if report.PublishTime != "" {
- // 发布时间固定为首次发布时间
- publishTime = report.PublishTime
- } else {
- publishTime = time.Now().Format(utils.FormatDateTime)
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, report.ClassifyIdFirst, report.ClassifyIdSecond, 0, models.ReportOperatePublish)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- if state == models.ReportStatePublished {
- // 发布报告
- if tmpErr = models.PublishEnglishReportById(report.Id, publishTime); tmpErr != nil {
- br.Msg = "报告发布失败"
- br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
- return
- }
- go func() {
- _ = services.UpdateEnglishReportEs(report.Id, 2)
- }()
- // 生成报告pdf和长图
- if req.ReportUrl != "" {
- go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 2)
- }
- } else {
- // 从无审批切换为有审批, 状态重置
- if e = models.ResetEnglishReportById(report.Id, state); tmpErr != nil {
- br.Msg = "操作失败"
- br.ErrMsg = fmt.Sprintf("重置英文报告状态失败, Err: %s, ReportId: %d", e.Error(), report.Id)
- return
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "发布成功"
- }
- // PrePublishReport
- // @Title 设置定时发布接口
- // @Description 设置定时发布接口
- // @Param request body models.PrePublishReq true "type json string"
- // @Success 200 Ret=200 发布成功
- // @router /pre_publish [post]
- func (this *EnglishReportController) 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
- }
- prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
- if err != nil {
- br.Msg = "发布时间格式错误"
- br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
- return
- }
- if prePublishTime.Before(time.Now()) {
- br.Msg = "发布时间不允许选择过去时间"
- return
- }
- if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
- br.Msg = "发布时间距离当前时间太近了"
- return
- }
- report, err := models.GetEnglishReportById(reportId)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- if report == nil {
- br.Msg = "报告不存在"
- return
- }
- if report.Content == "" {
- br.Msg = "报告内容为空,不可发布"
- br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
- return
- }
- if report.State == 2 {
- br.Msg = "报告已发布,不可设置定时发布"
- return
- }
- // 校验是否开启了审批流
- opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeEnglish, report.ClassifyIdFirst, report.ClassifyIdSecond, 0)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- if opening {
- br.Msg = "报告已开启审批流, 不可设置定时发布"
- return
- }
- var tmpErr error
- if tmpErr = models.SetPrePublishEnglishReportById(report.Id, req.PrePublishTime); tmpErr != nil {
- br.Msg = "设置定时发布失败"
- br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
- return
- }
- // 生成报告pdf和长图
- if req.ReportUrl != "" {
- go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 2)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "定时发布成功"
- }
- // @Title 取消发布报告接口
- // @Description 取消发布报告
- // @Param request body models.PublishCancelReq true "type json string"
- // @Success 200 Ret=200 取消发布成功
- // @router /publish/cancel [post]
- func (this *EnglishReportController) PublishCancleReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.PublishCancelReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportIds <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- reportInfo, err := models.GetEnglishReportById(req.ReportIds)
- if err != nil {
- br.Msg = "获取报告信息失败"
- br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
- return
- }
- // 根据审批开关及审批流判断当前报告状态
- state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, 0, models.ReportOperateCancelPublish)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
- return
- }
- err = models.PublishCancelEnglishReport(req.ReportIds, state)
- if err != nil {
- br.Msg = "取消发布失败"
- br.ErrMsg = "取消发布失败,Err:" + err.Error()
- return
- }
- // 更新es里的报告状态
- go func() {
- _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "取消发布成功"
- }
- // @Title 删除报告接口
- // @Description 删除报告
- // @Param request body models.DeleteReq true "type json string"
- // @Success 200 Ret=200 删除成功
- // @router /delete [post]
- func (this *EnglishReportController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportIds <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,报告id不可为空"
- return
- }
- reportInfo, err := models.GetEnglishReportById(req.ReportIds)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "报告不存在"
- return
- }
- br.Msg = "查询报告信息失败"
- br.ErrMsg = "查询报告信息失败, Err" + err.Error()
- return
- }
- // 更新es里的报告状态
- _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
- if err = models.DeleteEnglishReportAndChapter(reportInfo); err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除报告失败, Err: " + err.Error()
- return
- }
- // 重置PPT关联报告
- go func() {
- _ = services.ResetPPTReport(req.ReportIds, true)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // @Title 保存草稿
- // @Description 保存草稿
- // @Param request body models.SaveReportContent true "type json string"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /saveReportContent [post]
- func (this *EnglishReportController) SaveReportContent() {
- br := new(models.BaseResponse).Init()
- br.IsSendEmail = false
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.SaveReportContent
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- reportId := req.ReportId
- noChangeFlag := req.NoChange
- fmt.Println("reportId:", reportId)
- if reportId <= 0 {
- br.Msg = "请输入报告ID"
- return
- }
- markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- if noChangeFlag != 1 {
- content := req.Content
- if content == "" {
- content = this.GetString("Content")
- }
- if content != "" {
- contentClean, e := services.FilterReportContentBr(req.Content)
- if e != nil {
- br.Msg = "内容去除前后空格失败"
- br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
- return
- }
- content = contentClean
- contentSub, err := services.GetReportContentSub(content)
- if err != nil {
- go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
- //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
- }
- content = html.EscapeString(content)
- contentSub = html.EscapeString(contentSub)
- err = models.EditEnglishReportContent(reportId, content, contentSub)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- go models.AddEnglishReportSaveLog(reportId, this.SysUser.AdminId, content, contentSub, this.SysUser.AdminName)
- }
- }
- resp := new(models.SaveReportContentResp)
- resp.ReportId = reportId
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功成功"
- br.Data = resp
- }
- // @Title 根据分类获取最近一次报告详情接口
- // @Description 根据分类获取最近一次报告详情
- // @Param request body models.ClassifyIdDetailReq true "type json string"
- // @Success 200 {object} models.Report
- // @router /classifyIdDetail [get]
- func (this *EnglishReportController) ClassifyIdDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //classify_id_first=34&classify_id_second=36
- /*var req models.ClassifyIdDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }*/
- classifyIdFirst, _ := this.GetInt("classify_id_first")
- if classifyIdFirst <= 0 {
- classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
- }
- classifyIdSecond, _ := this.GetInt("classify_id_second")
- if classifyIdSecond <= 0 {
- classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
- }
- item, err := models.GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if item != nil {
- item.Content = html.UnescapeString(item.Content)
- item.ContentSub = html.UnescapeString(item.ContentSub)
- classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
- if item.ClassifyIdSecond > 0 {
- nameList, tErr := models.GetEnglishClassifyFullNameByIds([]int{item.ClassifyIdSecond})
- if tErr != nil {
- br.Msg = "获取分类名称失败"
- br.ErrMsg = "获取分类名称失败, ERR:" + tErr.Error()
- return
- }
- for _, v := range nameList {
- classifyNameMap[v.Id] = v
- }
- //处理分类名
- if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
- item.ClassifyNameRoot = n.RootName
- item.ClassifyIdRoot = n.RootId
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // Author
- // @Title 获取报告作者接口
- // @Description 获取报告作者
- // @Param AuthorType query int true "来源类型,1:中文,2:英文"
- // @Param Keyword query string true "搜索关键词"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string true "开始时间"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /author [get]
- func (this *EnglishReportController) Author() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyword := this.GetString("Keyword")
- var condition string
- var pars []interface{}
- condition += ` AND author_type = 2 AND enable = 1`
- if keyword != `` {
- condition += ` AND report_author like ? `
- pars = append(pars, utils.GetLikeKeyword(keyword))
- }
- _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
- if err != nil {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := models.ReportAuthorResp{
- List: items,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MarkEditStatus
- // @Title 标记报告编辑状态
- // @Description 标记报告编辑状态接口
- // @Param request body request.MarkEditEnReport true "type json string"
- // @Success 200 标记成功 ;202 标记成功
- // @router /mark [post]
- func (this *EnglishReportController) MarkEditStatus() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.MarkEditEnReport
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportId <= 0 {
- br.Msg = "缺少报告Id"
- return
- }
- if req.Status <= 0 {
- br.Msg = "标记状态异常"
- return
- }
- //更新标记key
- data, err := services.UpdateEnReportEditMark(req.ReportId, sysUser.AdminId, req.Status, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- msg := "标记成功"
- br.Ret = 200
- br.Success = true
- br.Msg = msg
- br.Data = data
- }
- // @Title 编辑来自策略报告的报告
- // @Description 编辑来自策略报告的报告
- // @Param request body models.EditEnglishReportFromPolicyReq true "type json string"
- // @Success 200 {object} models.EditEnglishReportResp
- // @router /edit_policy [post]
- func (this *EnglishReportController) EditPolicy() {
- 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.EditEnglishReportFromPolicyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ReportId <= 0 {
- br.Msg = "请选择报告ID"
- return
- }
- if req.Title == "" {
- br.Msg = "请输入标题"
- return
- }
- if req.Abstract == "" {
- br.Msg = "请输入摘要"
- return
- }
- if req.Frequency == "" {
- br.Msg = "请输入频度"
- return
- }
- if req.Author == "" {
- br.Msg = "请输入作者"
- return
- }
- if req.CreateTime == "" {
- br.Msg = "请输入创建时间"
- return
- }
- //查询报告是否存在
- reportInfo, err := models.GetEnglishReportItemById(int(req.ReportId))
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "报告不存在"
- return
- }
- br.Msg = "查询报告信息失败"
- br.ErrMsg = "查询报告信息失败, Err" + err.Error()
- return
- }
- if reportInfo.State == 2 {
- br.Msg = "报告已发布不允许编辑"
- return
- }
- markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
- if err != nil {
- br.Msg = err.Error()
- return
- }
- if markStatus.Status == 1 {
- br.Msg = markStatus.Msg
- return
- }
- item := reportInfo
- item.Title = req.Title
- item.Abstract = req.Abstract
- item.Author = req.Author
- item.Frequency = req.Frequency
- item.CreateTime = req.CreateTime
- item.ModifyTime = time.Now()
- err = item.Update([]string{"Title", "Abstract", "Author", "Frequency", "CreateTime", "ModifyTime"})
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- reportCode := reportInfo.ReportCode
- resp := new(models.EditEnglishReportResp)
- resp.ReportId = req.ReportId
- resp.ReportCode = reportCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- }
- // SubmitApprove
- // @Title 提交审批
- // @Description 提交审批接口
- // @Param request body models.ReportSubmitApproveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /approve/submit [post]
- func (this *EnglishReportController) 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.EnglishReport)
- 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.FlowReportTypeEnglish, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, 0, 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.FlowReportTypeEnglish, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, 0, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "提交审批失败, Err: " + e.Error()
- return
- }
- reportItem.ApproveId = approveId
- reportItem.State = models.ReportStateWaitApprove
- reportItem.ModifyTime = time.Now().Local()
- e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // CancelApprove
- // @Title 撤销审批
- // @Description 撤销审批
- // @Param request body models.ReportCancelApproveReq true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /approve/cancel [post]
- func (this *EnglishReportController) 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.EnglishReport)
- 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.FlowReportTypeEnglish, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, 0, 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.FlowReportTypeEnglish, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "撤销审批失败, Err: " + e.Error()
- return
- }
- //reportItem.ApproveId = 0
- //reportItem.State = models.ReportStateWaitSubmit
- //reportItem.ModifyTime = time.Now().Local()
- //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
- //if e != nil {
- // br.Msg = "操作失败"
- // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
- // return
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|