|
@@ -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
|
|
|
}
|
|
|
|
|
|
+// PublishReport
|
|
|
+// @Title 发布报告接口
|
|
|
+// @Description 发布报告
|
|
|
+// @Param request body models.PublishReq true "type json string"
|
|
|
+// @Success 200 Ret=200 发布成功
|
|
|
+// @router /publish [post]
|
|
|
+func (this *ReportController) PublishReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ var req models.PublishReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportIds := req.ReportIds
|
|
|
+ if reportIds == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 这里实际上不会批量发布了...
|
|
|
+ reportArr := strings.Split(reportIds, ",")
|
|
|
+ tips := ""
|
|
|
+ for _, v := range reportArr {
|
|
|
+ vint, err := strconv.Atoi(v)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 报告的图表刷新状态校验
|
|
|
+ refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
|
|
|
+ if !refreshResult {
|
|
|
+ br.Msg = "图表刷新未完成,请稍后操作"
|
|
|
+ br.ErrMsg = "图表刷新未完成,请稍后操作"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 报告发布
|
|
|
+ tmpTips, err, errMsg := services.PublishReport(vint, req.ReportUrl, this.SysUser)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = errMsg
|
|
|
+ br.ErrMsg = "报告发布失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tips = tmpTips
|
|
|
+ }
|
|
|
+ // 发布晨周报部分章节未发布的提示
|
|
|
+ if tips != "" {
|
|
|
+ br.Data = tips
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "发布成功"
|
|
|
+}
|
|
|
+
|
|
|
+// PublishCancleReport
|
|
|
+// @Title 取消发布报告接口
|
|
|
+// @Description 取消发布报告
|
|
|
+// @Param request body models.PublishCancelReq true "type json string"
|
|
|
+// @Success 200 Ret=200 取消发布成功
|
|
|
+// @router /publish/cancle [post]
|
|
|
+func (this *ReportController) PublishCancleReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ var req models.PublishCancelReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ReportIds <= 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ publishTimeNullFlag := true
|
|
|
+ reportInfo, err := models.GetReportById(req.ReportIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告信息失败"
|
|
|
+ br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportInfo.MsgIsSend == 1 {
|
|
|
+ publishTimeNullFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据审批开关及审批流判断当前报告状态
|
|
|
+ state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, 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
|
|
|
+ }
|
|
|
+ // 更新ES禁用
|
|
|
+ {
|
|
|
+ go services.UpdateReportEs(req.ReportIds, 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ //// 获取审批流设置
|
|
|
+ //confKey := "approval_flow"
|
|
|
+ //confTmp, e := company.GetConfigDetailByCode(confKey)
|
|
|
+ //if e != nil {
|
|
|
+ // br.Msg = "获取审批流配置失败"
|
|
|
+ // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if confTmp.ConfigValue == "1" || confTmp.ConfigValue == "2" || confTmp.ConfigValue == "3" {
|
|
|
+ // br.Msg = "撤销成功"
|
|
|
+ //} else {
|
|
|
+ // br.Msg = "取消发布成功"
|
|
|
+ //}
|
|
|
+
|
|
|
+ recordItem := &models.ReportStateRecord{
|
|
|
+ ReportId: req.ReportIds,
|
|
|
+ ReportType: 1,
|
|
|
+ State: state,
|
|
|
+ AdminId: this.SysUser.AdminId,
|
|
|
+ AdminName: this.SysUser.AdminName,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ }
|
|
|
+ go func() {
|
|
|
+ _, _ = models.AddReportStateRecord(recordItem)
|
|
|
+ }()
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+}
|
|
|
+
|
|
|
+// PrePublishReport
|
|
|
+// @Title 设置定时发布接口
|
|
|
+// @Description 设置定时发布接口
|
|
|
+// @Param request body models.PrePublishReq true "type json string"
|
|
|
+// @Success 200 Ret=200 发布成功
|
|
|
+// @router /pre_publish [post]
|
|
|
+func (this *ReportController) PrePublishReport() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ var req models.PrePublishReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportId := req.ReportId
|
|
|
+ if reportId == 0 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,报告id不可为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.PrePublishTime == "" {
|
|
|
+ br.Msg = "发布时间不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "是否发送模版消息标识错误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "发布时间格式错误"
|
|
|
+ br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if prePublishTime.Before(time.Now()) {
|
|
|
+ br.Msg = "发布时间不允许选择过去时间"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
|
|
|
+ br.Msg = "发布时间距离当前时间太近了"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ reportDetail, err := models.GetReportById(reportId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取报告信息失败"
|
|
|
+ br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportDetail == nil {
|
|
|
+ br.Msg = "报告不存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是章节类型的报告,那么需要确认所有章节已发布
|
|
|
+ if reportDetail.HasChapter == 1 {
|
|
|
+ chapterList, err := models.GetChapterListByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, chapter := range chapterList {
|
|
|
+ if chapter.PublishState == 1 {
|
|
|
+ br.Msg = "还存在未发布的章节"
|
|
|
+ br.ErrMsg = "还存在未发布的章节"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if reportDetail.Content == "" {
|
|
|
+ br.Msg = "报告内容为空,不可设置定时发布"
|
|
|
+ br.ErrMsg = "报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportDetail.Id)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if reportDetail.State == 2 {
|
|
|
+ br.Msg = "报告已发布,不可设置定时发布"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验是否开启了审批流
|
|
|
+ opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, reportDetail.ClassifyIdFirst, reportDetail.ClassifyIdSecond, reportDetail.ClassifyIdThird)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if opening {
|
|
|
+ br.Msg = "报告已开启审批流, 不可设置定时发布"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var tmpErr error
|
|
|
+ if tmpErr = models.SetPrePublishReportById(reportDetail.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
|
|
|
+ br.Msg = "设置定时发布失败"
|
|
|
+ br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportDetail.Id)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成报告pdf和长图
|
|
|
+ if req.ReportUrl != "" {
|
|
|
+ go services.Report2pdfAndJpeg(req.ReportUrl, reportDetail.Id, 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "定时发布成功"
|
|
|
+}
|
|
|
+
|
|
|
+// SubmitApprove
|
|
|
+// @Title 提交审批
|
|
|
+// @Description 提交审批接口
|
|
|
+// @Param request body models.ReportSubmitApproveReq true "type json string"
|
|
|
+// @Success 200 Ret=200 操作成功
|
|
|
+// @router /approve/submit [post]
|
|
|
+func (this *ReportController) SubmitApprove() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req models.ReportSubmitApproveReq
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportId := req.ReportId
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ reportOb := new(models.Report)
|
|
|
+ reportItem, e := reportOb.GetItemById(reportId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "报告已被删除, 请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取报告失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是章节类型的报告,那么需要确认所有章节已发布
|
|
|
+ if reportItem.HasChapter == 1 {
|
|
|
+ chapterList, err := models.GetChapterListByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, chapter := range chapterList {
|
|
|
+ if chapter.PublishState == 1 {
|
|
|
+ br.Msg = "还存在未发布的章节"
|
|
|
+ br.ErrMsg = "还存在未发布的章节"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if reportItem.Content == "" {
|
|
|
+ br.Msg = "报告内容为空,不可提交"
|
|
|
+ br.ErrMsg = "报告内容为空,不可提交,report_id:" + strconv.Itoa(reportItem.Id)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验当前审批配置, 返回下一个状态
|
|
|
+ state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateSubmitApprove)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下一个状态不为待审批时, 仅更新状态
|
|
|
+ if state != models.ReportStateWaitApprove {
|
|
|
+ reportItem.State = state
|
|
|
+ e = reportItem.UpdateReport([]string{"State"})
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提交审批
|
|
|
+ approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, sysUser.AdminId, sysUser.RealName)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "提交审批失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportItem.ApproveId = approveId
|
|
|
+ reportItem.State = models.ReportStateWaitApprove
|
|
|
+ reportItem.ModifyTime = time.Now().Local()
|
|
|
+ e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
+// CancelApprove
|
|
|
+// @Title 撤销审批
|
|
|
+// @Description 撤销审批
|
|
|
+// @Param request body models.ReportCancelApproveReq true "type json string"
|
|
|
+// @Success 200 Ret=200 操作成功
|
|
|
+// @router /approve/cancel [post]
|
|
|
+func (this *ReportController) CancelApprove() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ if br.ErrMsg == "" {
|
|
|
+ br.IsSendEmail = false
|
|
|
+ }
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req models.ReportCancelApproveReq
|
|
|
+ if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = "参数解析失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ reportId := req.ReportId
|
|
|
+ if reportId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ reportOb := new(models.Report)
|
|
|
+ reportItem, e := reportOb.GetItemById(reportId)
|
|
|
+ if e != nil {
|
|
|
+ if e.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "报告已被删除, 请刷新页面"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取报告失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验当前审批配置, 返回下一个状态
|
|
|
+ state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateCancelApprove)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下一个状态不为待提交时, 仅更新状态
|
|
|
+ if state != models.ReportStateWaitSubmit {
|
|
|
+ reportItem.State = state
|
|
|
+ e = reportItem.UpdateReport([]string{"State"})
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //if reportItem.ApproveId <= 0 {
|
|
|
+ // br.Msg = "报告审批不存在"
|
|
|
+ // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 撤销审批
|
|
|
+ e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "撤销审批失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //reportItem.ApproveId = 0
|
|
|
+ //reportItem.State = models.ReportStateWaitSubmit
|
|
|
+ //reportItem.ModifyTime = time.Now().Local()
|
|
|
+ //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
|
|
|
+ //if e != nil {
|
|
|
+ // br.Msg = "操作失败"
|
|
|
+ // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
// init
|
|
|
// @Description: 修复历史报告数据
|
|
|
// @author: Roc
|