|
@@ -9,11 +9,13 @@ import (
|
|
|
"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"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -1122,6 +1124,477 @@ func (this *ReportController) EditLayoutImg() {
|
|
|
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.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 = "发布成功"
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (this *ReportController) PublishCancleReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ var req models.PublishCancelReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ReportIds <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ publishTimeNullFlag := true
|
|
|
+ reportInfo, err := models.GetReportById(req.ReportIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告信息失败"
|
|
|
+ br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportInfo.MsgIsSend == 1 {
|
|
|
+ publishTimeNullFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, models.ReportOperateCancelPublish)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "取消发布失败"
|
|
|
+ br.ErrMsg = "取消发布失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if req.ReportUrl != "" {
|
|
|
+ go services.Report2pdfAndJpeg(req.ReportUrl, 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 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
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 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
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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 = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|