浏览代码

Merge branch 'feature/eta_1.3.8' into debug

hsun 1 年之前
父节点
当前提交
f794a232eb

+ 188 - 0
controllers/english_report/report.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
+	"eta/eta_api/models/report_approve"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services"
 	"eta/eta_api/services/alarm_msg"
@@ -1233,3 +1234,190 @@ func (this *EnglishReportController) EditPolicy() {
 	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, 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, 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, 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 = "操作成功"
+}

+ 15 - 10
controllers/report.go

@@ -3545,23 +3545,28 @@ func (this *ReportController) CancelApprove() {
 		br.Msg = "操作成功"
 		return
 	}
+	if reportItem.ApproveId <= 0 {
+		br.Msg = "报告审批不存在"
+		br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
+		return
+	}
 
 	// 撤销审批
-	e = services.CancelReportApprove(reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
+	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
-	}
+	//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

+ 250 - 34
controllers/report_approve/report_approve.go

@@ -6,10 +6,11 @@ import (
 	"eta/eta_api/models"
 	"eta/eta_api/models/report_approve"
 	"eta/eta_api/models/smart_report"
+	"eta/eta_api/services"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
-	"html"
+	"sort"
 	"strings"
 	"time"
 )
@@ -106,14 +107,14 @@ func (this *ReportApproveController) List() {
 
 	// 待处理
 	if params.ListType == 1 {
-		cond := fmt.Sprintf(` AND a.%s = ? AND b.%s = ? AND b.%s = ?`, report_approve.ReportApproveCols.State, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State)
+		cond := fmt.Sprintf(` AND a.%s = ? AND b.%s = ? AND a.%s = ?`, report_approve.ReportApproveRecordCols.State, report_approve.ReportApproveCols.State, report_approve.ReportApproveRecordCols.ApproveUserId)
 		pars := make([]interface{}, 0)
-		pars = append(pars, report_approve.ReportApproveStateApproving, sysUser.AdminId, report_approve.ReportApproveStateApproving)
+		pars = append(pars, report_approve.ReportApproveStateApproving, report_approve.ReportApproveStateApproving, sysUser.AdminId)
 		order := ""
 
 		// 筛选条件
 		if params.ReportType > 0 && params.ClassifySecondId > 0 {
-			cond += fmt.Sprintf(` AND a.%s = ? AND a.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
+			cond += fmt.Sprintf(` AND b.%s = ? AND b.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
 			pars = append(pars, params.ReportType, params.ClassifySecondId)
 		}
 		if params.TimeType <= 0 {
@@ -132,13 +133,13 @@ func (this *ReportApproveController) List() {
 			}
 			st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
 			ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
-			cond += fmt.Sprintf(` AND (a.%s BETWEEN ? AND ?)`, report_approve.ReportApproveCols.CreateTime)
+			cond += fmt.Sprintf(` AND (b.%s BETWEEN ? AND ?)`, report_approve.ReportApproveCols.CreateTime)
 			pars = append(pars, st, ed)
 		}
 		params.Keyword = strings.TrimSpace(params.Keyword)
 		if params.Keyword != "" {
 			kw := fmt.Sprint("%", params.Keyword, "%")
-			cond += fmt.Sprintf(` AND a.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
+			cond += fmt.Sprintf(` AND b.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
 			pars = append(pars, kw)
 		}
 		if params.SortField > 0 && params.SortRule > 0 {
@@ -172,14 +173,14 @@ func (this *ReportApproveController) List() {
 
 	// 已处理
 	if params.ListType == 2 {
-		cond := fmt.Sprintf(` AND b.%s = ? AND b.%s IN (%s)`, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State, utils.GetOrmInReplace(2))
+		cond := fmt.Sprintf(` AND a.%s = ? AND a.%s IN (%s)`, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State, utils.GetOrmInReplace(2))
 		pars := make([]interface{}, 0)
 		pars = append(pars, sysUser.AdminId, []int{report_approve.ReportApproveStatePass, report_approve.ReportApproveStateRefuse})
 		order := ""
 
 		// 筛选条件
 		if params.ReportType > 0 && params.ClassifySecondId > 0 {
-			cond += fmt.Sprintf(` AND a.%s = ? AND a.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
+			cond += fmt.Sprintf(` AND b.%s = ? AND b.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
 			pars = append(pars, params.ReportType, params.ClassifySecondId)
 		}
 		if params.TimeType > 0 && params.StartTime != "" && params.EndTime != "" {
@@ -195,13 +196,13 @@ func (this *ReportApproveController) List() {
 			}
 			st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
 			ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
-			cond += fmt.Sprintf(` AND (a.%s BETWEEN ? AND ?)`, timeField[params.TimeType])
+			cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, timeField[params.TimeType])
 			pars = append(pars, st, ed)
 		}
 		params.Keyword = strings.TrimSpace(params.Keyword)
 		if params.Keyword != "" {
 			kw := fmt.Sprint("%", params.Keyword, "%")
-			cond += fmt.Sprintf(` AND a.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
+			cond += fmt.Sprintf(` AND b.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
 			pars = append(pars, kw)
 		}
 		if params.SortField > 0 && params.SortRule > 0 {
@@ -218,7 +219,7 @@ func (this *ReportApproveController) List() {
 			order = fmt.Sprintf("%s %s", orderField, orderRule)
 		}
 		if params.ApproveState > 0 {
-			cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveRecordCols.State)
+			cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveRecordCols.State)
 			pars = append(pars, params.ApproveState)
 		}
 		total, e := report_approve.GetApprovedReportApproveCount(cond, pars)
@@ -285,7 +286,7 @@ func (this *ReportApproveController) List() {
 			order = fmt.Sprintf("%s %s", orderField, orderRule)
 		}
 		if params.ApproveState > 0 {
-			cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveRecordCols.State)
+			cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveRecordCols.State)
 			pars = append(pars, params.ApproveState)
 		}
 		total, e := report_approve.GetApplyReportApproveCount(cond, pars)
@@ -328,7 +329,7 @@ func (this *ReportApproveController) List() {
 // @Title 审批详情
 // @Description 审批详情
 // @Param   ReportApproveId  query  int  true  "审批ID"
-// @Success 200 {object} report_approve.ReportApproveListResp
+// @Success 200 {object} report_approve.ReportApproveDetail
 // @router /detail [get]
 func (this *ReportApproveController) Detail() {
 	br := new(models.BaseResponse).Init()
@@ -454,6 +455,7 @@ func (this *ReportApproveController) Detail() {
 			r := recordMap[k]
 			if r != nil {
 				u.ApproveRecord = new(report_approve.ReportApproveDetailNodeUserRecord)
+				u.ApproveRecord.ReportApproveRecordId = r.ReportApproveRecordId
 				u.ApproveRecord.State = r.State
 				u.ApproveRecord.ApproveUserId = r.ApproveUserId
 				u.ApproveRecord.ApproveUserName = r.ApproveUserName
@@ -462,10 +464,34 @@ func (this *ReportApproveController) Detail() {
 			}
 			t.Users = append(t.Users, u)
 		}
+		sort.Slice(t.Users, func(k, j int) bool {
+			return t.Users[k].Sort < t.Users[j].Sort
+		})
 		detail.ApproveFlowNodes = append(detail.ApproveFlowNodes, t)
 	}
 
 	// 报告信息
+	cnClassifyIdName, enClassifyIdName := make(map[int]string), make(map[int]string)
+	cnClassify, e := models.GetAllClassify()
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取中文分类失败, Err: " + e.Error()
+		return
+	}
+	for _, v := range cnClassify {
+		cnClassifyIdName[v.Id] = v.ClassifyName
+	}
+	enClassify, e := models.GetAllEnglishClassify()
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取英文分类失败, Err: " + e.Error()
+		return
+	}
+	enRootIdMap := make(map[int]int) // 英文分类的一级分类ID
+	for _, v := range enClassify {
+		enClassifyIdName[v.Id] = v.ClassifyName
+		enRootIdMap[v.Id] = v.RootId
+	}
 	detail.Report = new(report_approve.ReportApproveDetailReport)
 	detail.Report.ReportType = approveItem.ReportType
 	detail.Report.ReportId = approveItem.ReportId
@@ -481,9 +507,7 @@ func (this *ReportApproveController) Detail() {
 			return
 		}
 		detail.Report.ReportTitle = rp.Title
-		detail.Report.ClassifyFirstId = rp.ClassifyIdFirst
-		detail.Report.ClassifySecondId = rp.ClassifyIdSecond
-		detail.Report.Content = html.UnescapeString(rp.Content)
+		detail.Report.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[approveItem.ReportType], cnClassifyIdName[rp.ClassifyIdFirst], cnClassifyIdName[rp.ClassifyIdSecond])
 	}
 	if approveItem.ReportType == report_approve.FlowReportTypeEnglish {
 		rp, e := models.GetEnglishReportById(approveItem.ReportId)
@@ -497,9 +521,7 @@ func (this *ReportApproveController) Detail() {
 			return
 		}
 		detail.Report.ReportTitle = rp.Title
-		detail.Report.ClassifyFirstId = rp.ClassifyIdFirst
-		detail.Report.ClassifySecondId = rp.ClassifyIdSecond
-		detail.Report.Content = html.UnescapeString(rp.Content)
+		detail.Report.ReportClassify = fmt.Sprintf("%s/%s/%s/%s", report_approve.FlowReportTypeMap[approveItem.ReportType], enClassifyIdName[enRootIdMap[rp.ClassifyIdSecond]], enClassifyIdName[rp.ClassifyIdFirst], enClassifyIdName[rp.ClassifyIdSecond])
 	}
 	if approveItem.ReportType == report_approve.FlowReportTypeSmart {
 		smartOb := new(smart_report.SmartReport)
@@ -514,9 +536,7 @@ func (this *ReportApproveController) Detail() {
 			return
 		}
 		detail.Report.ReportTitle = rp.Title
-		detail.Report.ClassifyFirstId = rp.ClassifyIdFirst
-		detail.Report.ClassifySecondId = rp.ClassifyIdSecond
-		detail.Report.Content = html.UnescapeString(rp.Content)
+		detail.Report.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[approveItem.ReportType], cnClassifyIdName[rp.ClassifyIdFirst], cnClassifyIdName[rp.ClassifyIdSecond])
 	}
 
 	br.Data = detail
@@ -528,10 +548,10 @@ func (this *ReportApproveController) Detail() {
 // Approve
 // @Title 通过审批
 // @Description 通过审批
-// @Param	request	body report_approve.ReportApproveFlowAddReq true "type json string"
-// @Success 200 {object} report_approve.ReportApproveDetailItem
+// @Param	request	body report_approve.ReportApprovePassReq true "type json string"
+// @Success 200 string "操作成功"
 // @router /approve [post]
-func (this *ReportApproveFlowController) Approve() {
+func (this *ReportApproveController) Approve() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		if br.ErrMsg == "" {
@@ -547,12 +567,24 @@ func (this *ReportApproveFlowController) Approve() {
 		br.Ret = 408
 		return
 	}
-	var req report_approve.ReportApproveFlowAddReq
+	var req report_approve.ReportApprovePassReq
 	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
 		br.Msg = "参数有误"
 		br.ErrMsg = "参数解析失败, Err: " + e.Error()
 		return
 	}
+	if req.ReportApproveRecordId <= 0 {
+		br.Msg = "参数有误"
+		br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveRecordId: %d", req.ReportApproveRecordId)
+		return
+	}
+
+	// 通过审批
+	if e := services.PassReportApprove(req.ReportApproveRecordId, sysUser.AdminId, sysUser.RealName); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "通过审批失败, Err: " + e.Error()
+		return
+	}
 
 	br.Ret = 200
 	br.Success = true
@@ -562,10 +594,10 @@ func (this *ReportApproveFlowController) Approve() {
 // Refuse
 // @Title 驳回审批
 // @Description 驳回审批
-// @Param	request	body report_approve.ReportApproveFlowAddReq true "type json string"
-// @Success 200 {object} report_approve.ReportApproveDetailItem
+// @Param	request	body report_approve.ReportApproveRefuseReq true "type json string"
+// @Success 200 string "操作成功"
 // @router /refuse [post]
-func (this *ReportApproveFlowController) Refuse() {
+func (this *ReportApproveController) Refuse() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		if br.ErrMsg == "" {
@@ -581,12 +613,24 @@ func (this *ReportApproveFlowController) Refuse() {
 		br.Ret = 408
 		return
 	}
-	var req report_approve.ReportApproveFlowAddReq
+	var req report_approve.ReportApproveRefuseReq
 	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
 		br.Msg = "参数有误"
 		br.ErrMsg = "参数解析失败, Err: " + e.Error()
 		return
 	}
+	if req.ReportApproveRecordId <= 0 {
+		br.Msg = "参数有误"
+		br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveRecordId: %d", req.ReportApproveRecordId)
+		return
+	}
+
+	// 驳回审批
+	if e := services.RefuseReportApprove(req.ReportApproveRecordId, req.ApproveRemark, sysUser.AdminId); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "驳回审批失败, Err: " + e.Error()
+		return
+	}
 
 	br.Ret = 200
 	br.Success = true
@@ -596,10 +640,74 @@ func (this *ReportApproveFlowController) Refuse() {
 // Cancel
 // @Title 撤销审批
 // @Description 撤销审批
-// @Param	request	body report_approve.ReportApproveFlowAddReq true "type json string"
-// @Success 200 {object} report_approve.ReportApproveDetailItem
+// @Param	request	body report_approve.ReportApproveCancelReq true "type json string"
+// @Success 200 string "操作成功"
 // @router /cancel [post]
-func (this *ReportApproveFlowController) Cancel() {
+func (this *ReportApproveController) Cancel() {
+	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 report_approve.ReportApproveCancelReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数有误"
+		br.ErrMsg = "参数解析失败, Err: " + e.Error()
+		return
+	}
+	if req.ReportApproveId <= 0 {
+		br.Msg = "参数有误"
+		br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
+		return
+	}
+
+	approveOb := new(report_approve.ReportApprove)
+	approveItem, e := approveOb.GetItemById(req.ReportApproveId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "审批已被删除, 请刷新页面"
+			return
+		}
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取审批失败, Err: " + e.Error()
+		return
+	}
+	if approveItem.ApplyUserId != sysUser.AdminId {
+		br.Msg = "非申请人不可撤销"
+		return
+	}
+
+	// 撤销审批
+	e = services.CancelReportApprove(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, sysUser.AdminId, sysUser.RealName)
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "撤销审批失败, Err: " + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// MessageList
+// @Title 审批消息列表
+// @Description 审批消息列表
+// @Param   PageSize			query	int		true	"每页数据条数"
+// @Param   CurrentIndex		query	int		true	"当前页页码"
+// @Success 200 {object} report_approve.ReportApproveMessageListResp
+// @router /message/list [get]
+func (this *ReportApproveController) MessageList() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		if br.ErrMsg == "" {
@@ -615,12 +723,120 @@ func (this *ReportApproveFlowController) Cancel() {
 		br.Ret = 408
 		return
 	}
-	var req report_approve.ReportApproveFlowAddReq
+	params := new(report_approve.ReportApproveListReq)
+	if e := this.ParseForm(params); e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "入参解析失败, Err: " + e.Error()
+		return
+	}
+
+	// 分页
+	var startSize int
+	if params.PageSize <= 0 {
+		params.PageSize = utils.PageSize20
+	}
+	if params.CurrentIndex <= 0 {
+		params.CurrentIndex = 1
+	}
+	startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
+
+	resp := new(report_approve.ReportApproveMessageListResp)
+	resp.List = make([]*report_approve.ReportApproveMessageItem, 0)
+	cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
+	pars := make([]interface{}, 0)
+	pars = append(pars, sysUser.AdminId)
+	order := fmt.Sprintf(`%s ASC, %s DESC`, report_approve.ReportApproveMessageCols.IsRead, report_approve.ReportApproveMessageCols.CreateTime)
+
+	messageOb := new(report_approve.ReportApproveMessage)
+	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, params.PageSize)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取审批消息列表失败, Err: " + e.Error()
+		return
+	}
+	for _, v := range list {
+		t := report_approve.FormatReportApproveMessage2Item(v)
+		resp.List = append(resp.List, t)
+	}
+
+	// 未读消息数
+	cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.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(params.CurrentIndex, params.PageSize, total)
+	resp.Paging = page
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
+// MessageRead
+// @Title 消息已读
+// @Description 消息已读
+// @Param	request	body report_approve.ReportApproveMessageReadReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /message/read [post]
+func (this *ReportApproveController) 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 report_approve.ReportApproveMessageReadReq
 	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(report_approve.ReportApproveMessage)
+	messageItem, e := messageOb.GetItemById(req.MessageId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			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

+ 188 - 0
controllers/smart_report/smart_report.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
+	"eta/eta_api/models/report_approve"
 	"eta/eta_api/models/smart_report"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services"
@@ -1258,3 +1259,190 @@ func (this *SmartReportController) VoiceUpload() {
 	br.Data = resp
 	return
 }
+
+// SubmitApprove
+// @Title 提交审批
+// @Description 提交审批接口
+// @Param	request	body models.ReportSubmitApproveReq true "type json string"
+// @Success 200 Ret=200 操作成功
+// @router /approve/submit [post]
+func (this *SmartReportController) 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(smart_report.SmartReport)
+	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.FlowReportTypeSmart, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, models.ReportOperateSubmitApprove)
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
+		return
+	}
+
+	// 下一个状态不为待审批时, 仅更新状态
+	if state != models.ReportStateWaitApprove {
+		reportItem.State = state
+		e = reportItem.Update([]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.FlowReportTypeSmart, reportItem.SmartReportId, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, 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.Update([]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 *SmartReportController) 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(smart_report.SmartReport)
+	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.FlowReportTypeSmart, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, models.ReportOperateCancelApprove)
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
+		return
+	}
+
+	// 下一个状态不为待提交时, 仅更新状态
+	if state != models.ReportStateWaitSubmit {
+		reportItem.State = state
+		e = reportItem.Update([]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.FlowReportTypeSmart, reportItem.SmartReportId, 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 = "操作成功"
+}

+ 11 - 12
controllers/sys_role.go

@@ -3,7 +3,6 @@ package controllers
 import (
 	"encoding/json"
 	"eta/eta_api/models"
-	"eta/eta_api/models/company"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services"
 	"eta/eta_api/utils"
@@ -718,17 +717,17 @@ func (this *SysRoleController) SystemConfig() {
 	list = append(list, osc)
 
 	// 获取审批流设置
-	confKey := "approval_flow"
-	confTmp, e := company.GetConfigDetailByCode(confKey)
-	if e != nil {
-		br.Msg = "获取审批流配置失败"
-		br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
-		return
-	}
-	list = append(list, system.BusinessConf{
-		ConfKey: "ApprovalFlow",
-		ConfVal: confTmp.ConfigValue,
-	})
+	//confKey := "approval_flow"
+	//confTmp, e := company.GetConfigDetailByCode(confKey)
+	//if e != nil {
+	//	br.Msg = "获取审批流配置失败"
+	//	br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
+	//	return
+	//}
+	//list = append(list, system.BusinessConf{
+	//	ConfKey: "ApprovalFlow",
+	//	ConfVal: confTmp.ConfigValue,
+	//})
 
 	br.Data = list
 	br.Ret = 200

+ 8 - 0
models/english_report.go

@@ -43,6 +43,7 @@ type EnglishReport struct {
 	AdminId            int       `description:"创建者账号"`
 	AdminRealName      string    `description:"创建者姓名"`
 	ApproveTime        time.Time `description:"审批时间"`
+	ApproveId          int       `description:"审批ID"`
 }
 
 func GetEnglishReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
@@ -829,3 +830,10 @@ where a.id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
 	_, err = o.Raw(sql, classifyIds).QueryRows(&list)
 	return
 }
+
+func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}

+ 74 - 102
models/report_approve/report_approve.go

@@ -175,25 +175,26 @@ func (m *ReportApprove) GetPageItemsByCondition(condition string, pars []interfa
 
 // ReportApproveItem 报告审批信息
 type ReportApproveItem struct {
-	ReportApproveId  int    `description:"审批ID"`
-	ReportType       int    `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
-	ReportId         int    `description:"报告ID"`
-	ReportTitle      string `description:"报告标题"`
-	ReportClassify   string `description:"报告分类"`
-	ClassifyFirstId  int    `description:"一级分类ID"`
-	ClassifySecondId int    `description:"二级分类ID"`
-	State            int    `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
-	FlowId           int    `description:"审批流ID"`
-	FlowVersion      int    `description:"审批流版本"`
-	StartNodeId      int    `description:"开始节点ID"`
-	CurrNodeId       int    `description:"当前节点ID"`
-	ApplyUserId      int    `description:"申请人ID"`
-	ApplyUserName    string `description:"申请人姓名"`
-	ApproveRemark    string `description:"审批备注"`
-	ApproveTime      string `description:"审批时间"`
-	HandleTime       string `description:"处理时间"`
-	CreateTime       string `description:"创建时间"`
-	ModifyTime       string `description:"修改时间"`
+	ReportApproveId       int    `description:"审批ID"`
+	ReportApproveRecordId int    `description:"审批记录ID"`
+	ReportType            int    `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
+	ReportId              int    `description:"报告ID"`
+	ReportTitle           string `description:"报告标题"`
+	ReportClassify        string `description:"报告分类"`
+	ClassifyFirstId       int    `description:"一级分类ID"`
+	ClassifySecondId      int    `description:"二级分类ID"`
+	State                 int    `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
+	FlowId                int    `description:"审批流ID"`
+	FlowVersion           int    `description:"审批流版本"`
+	StartNodeId           int    `description:"开始节点ID"`
+	CurrNodeId            int    `description:"当前节点ID"`
+	ApplyUserId           int    `description:"申请人ID"`
+	ApplyUserName         string `description:"申请人姓名"`
+	ApproveRemark         string `description:"审批备注"`
+	ApproveTime           string `description:"审批时间"`
+	HandleTime            string `description:"处理时间"`
+	CreateTime            string `description:"创建时间"`
+	ModifyTime            string `description:"修改时间"`
 }
 
 // FormatReportApproveOrm2Item 格式化报告审批
@@ -203,6 +204,7 @@ func FormatReportApproveOrm2Item(origin *ReportApproveItemOrm) (item *ReportAppr
 		return
 	}
 	item.ReportApproveId = origin.ReportApproveId
+	item.ReportApproveRecordId = origin.ReportApproveRecordId
 	item.ReportType = origin.ReportType
 	item.ReportId = origin.ReportId
 	item.ReportTitle = origin.ReportTitle
@@ -247,34 +249,34 @@ type ReportApproveListResp struct {
 }
 
 type ReportApproveItemOrm struct {
-	ReportApproveId  int       `description:"审批ID"`
-	ReportType       int       `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
-	ReportId         int       `description:"报告ID"`
-	ReportTitle      string    `description:"报告标题"`
-	ClassifyFirstId  int       `description:"一级分类ID"`
-	ClassifySecondId int       `description:"二级分类ID"`
-	State            int       `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
-	FlowId           int       `description:"审批流ID"`
-	FlowVersion      int       `description:"审批流版本"`
-	StartNodeId      int       `description:"开始节点ID"`
-	CurrNodeId       int       `description:"当前节点ID"`
-	ApplyUserId      int       `description:"申请人ID"`
-	ApplyUserName    string    `description:"申请人姓名"`
-	ApproveRemark    string    `description:"审批备注"`
-	ApproveTime      time.Time `description:"审批时间"`
-	HandleTime       time.Time `description:"处理时间"`
-	CreateTime       time.Time `description:"创建时间"`
-	ModifyTime       time.Time `description:"修改时间"`
+	ReportApproveId       int       `description:"审批ID"`
+	ReportApproveRecordId int       `description:"审批记录ID"`
+	ReportType            int       `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
+	ReportId              int       `description:"报告ID"`
+	ReportTitle           string    `description:"报告标题"`
+	ClassifyFirstId       int       `description:"一级分类ID"`
+	ClassifySecondId      int       `description:"二级分类ID"`
+	State                 int       `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
+	FlowId                int       `description:"审批流ID"`
+	FlowVersion           int       `description:"审批流版本"`
+	StartNodeId           int       `description:"开始节点ID"`
+	CurrNodeId            int       `description:"当前节点ID"`
+	ApplyUserId           int       `description:"申请人ID"`
+	ApplyUserName         string    `description:"申请人姓名"`
+	ApproveRemark         string    `description:"审批备注"`
+	ApproveTime           time.Time `description:"审批时间"`
+	HandleTime            time.Time `description:"处理时间"`
+	CreateTime            time.Time `description:"创建时间"`
+	ModifyTime            time.Time `description:"修改时间"`
 }
 
 // GetApprovingReportApproveCount 获取待处理的审批分页列表总数
 func GetApprovingReportApproveCount(cond string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	base := fmt.Sprintf(`SELECT a.report_approve_id
-		FROM report_approve AS a
-		JOIN report_approve_record AS b ON a.report_approve_id = b.report_approve_id
-		WHERE 1 = 1 %s
-		GROUP BY a.report_approve_id`, cond)
+	base := fmt.Sprintf(`SELECT a.report_approve_record_id
+		FROM report_approve_record AS a
+		JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
+		WHERE 1 = 1 %s`, cond)
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
 	err = o.Raw(sql, pars).QueryRow(&count)
 	return
@@ -287,14 +289,10 @@ func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRul
 	if orderRule != "" {
 		order = ` ORDER BY ` + orderRule
 	}
-	sql := fmt.Sprintf(`SELECT
-			a.*
-		FROM
-			report_approve AS a
-		JOIN report_approve_record AS b ON a.report_approve_id = b.report_approve_id
-		WHERE
-			1 = 1 %s
-		GROUP BY a.report_approve_id %s
+	sql := fmt.Sprintf(`SELECT a.report_approve_record_id, b.*
+		FROM report_approve_record AS a
+		JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
+		WHERE 1 = 1 %s %s
 		LIMIT ?,?`, cond, order)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
@@ -303,9 +301,9 @@ func GetApprovingReportApprovePageList(cond string, pars []interface{}, orderRul
 // GetApprovedReportApproveCount 获取已处理的审批分页列表总数
 func GetApprovedReportApproveCount(cond string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	base := fmt.Sprintf(`SELECT b.report_approve_record_id
-		FROM report_approve AS a
-		JOIN report_approve_record AS b ON a.report_approve_id = b.report_approve_id
+	base := fmt.Sprintf(`SELECT a.report_approve_record_id
+		FROM report_approve_record AS a
+		JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
 		WHERE 1 = 1 %s`, cond)
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
 	err = o.Raw(sql, pars).QueryRow(&count)
@@ -319,13 +317,10 @@ func GetApprovedReportApprovePageList(cond string, pars []interface{}, orderRule
 	if orderRule != "" {
 		order = ` ORDER BY ` + orderRule
 	}
-	sql := fmt.Sprintf(`SELECT
-			a.*, b.approve_time AS handle_time
-		FROM
-			report_approve AS a
-		JOIN report_approve_record AS b ON a.report_approve_id = b.report_approve_id
-		WHERE
-			1 = 1 %s %s
+	sql := fmt.Sprintf(`SELECT a.report_approve_record_id, b.*
+		FROM report_approve_record AS a
+		JOIN report_approve AS b ON a.report_approve_id = b.report_approve_id
+		WHERE 1 = 1 %s %s
 		LIMIT ?,?`, cond, order)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
@@ -377,12 +372,13 @@ type ReportApproveDetailItem struct {
 
 // ReportApproveDetailReport 审批详情-报告信息
 type ReportApproveDetailReport struct {
-	ReportType       int    `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
-	ReportId         int    `description:"报告ID"`
-	ReportTitle      string `description:"报告标题"`
-	ClassifyFirstId  int    `description:"一级分类ID"`
-	ClassifySecondId int    `description:"二级分类ID"`
-	Content          string `description:"报告内容"`
+	ReportType     int    `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
+	ReportId       int    `description:"报告ID"`
+	ReportTitle    string `description:"报告标题"`
+	ReportClassify string `description:"报告分类"`
+	//ClassifyFirstId  int    `description:"一级分类ID"`
+	//ClassifySecondId int    `description:"二级分类ID"`
+	//Content          string `description:"报告内容"`
 }
 
 // CreateApproveAndRecord 新增审批和记录
@@ -425,42 +421,18 @@ func (m *ReportApprove) CreateApproveAndRecord(approveItem *ReportApprove, recor
 	return
 }
 
-// CancelApproveAndRecord 撤销审批和记录
-func (m *ReportApprove) CancelApproveAndRecord(approveItem *ReportApprove, recordItems []*ReportApproveRecord) (err error) {
-	if approveItem == nil {
-		err = fmt.Errorf("approve is nil")
-		return
-	}
-	o := orm.NewOrmUsingDB("rddp")
-	tx, e := o.Begin()
-	if e != nil {
-		err = fmt.Errorf("orm begin err: %s", e.Error())
-		return
-	}
-	defer func() {
-		if err != nil {
-			_ = tx.Rollback()
-			return
-		}
-		_ = tx.Commit()
-	}()
+// ReportApprovePassReq 审批通过请求体
+type ReportApprovePassReq struct {
+	ReportApproveRecordId int `description:"审批记录ID"`
+}
 
-	lastId, e := tx.Insert(approveItem)
-	if e != nil {
-		err = fmt.Errorf("insert approve err: %s", e.Error())
-		return
-	}
-	approveItem.ReportApproveId = int(lastId)
+// ReportApproveRefuseReq 审批驳回请求体
+type ReportApproveRefuseReq struct {
+	ReportApproveRecordId int    `description:"审批记录ID"`
+	ApproveRemark         string `description:"驳回理由"`
+}
 
-	if len(recordItems) > 0 {
-		for _, v := range recordItems {
-			v.ReportApproveId = approveItem.ReportApproveId
-		}
-		_, e = tx.InsertMulti(len(recordItems), recordItems)
-		if e != nil {
-			err = fmt.Errorf("insert records err: %s", e.Error())
-			return
-		}
-	}
-	return
+// ReportApproveCancelReq 撤销审批请求体
+type ReportApproveCancelReq struct {
+	ReportApproveId int `description:"审批ID"`
 }

+ 19 - 0
models/report_approve/report_approve_message.go

@@ -4,6 +4,7 @@ import (
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"strings"
 	"time"
 )
@@ -183,3 +184,21 @@ func FormatReportApproveMessage2Item(origin *ReportApproveMessage) (item *Report
 	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
 	return
 }
+
+// ReportApproveMessageListReq 审批消息列表请求参数
+type ReportApproveMessageListReq struct {
+	PageSize     int `form:"PageSize"`
+	CurrentIndex int `form:"CurrentIndex"`
+}
+
+// ReportApproveMessageListResp 审批消息列表响应体
+type ReportApproveMessageListResp struct {
+	List        []*ReportApproveMessageItem
+	Paging      *paging.PagingItem `description:"分页数据"`
+	UnreadTotal int                `description:"消息未读数"`
+}
+
+// ReportApproveMessageReadReq 审批消息已读请求体
+type ReportApproveMessageReadReq struct {
+	MessageId int `description:"审批消息ID"`
+}

+ 1 - 0
models/smart_report/smart_report.go

@@ -57,6 +57,7 @@ type SmartReport struct {
 	EndImg              string    `description:"报告尾图地址"`
 	CanvasColor         string    `description:"画布颜色"`
 	ApproveTime         time.Time `description:"审批时间"`
+	ApproveId           int       `description:"审批ID"`
 }
 
 func (m *SmartReport) TableName() string {

+ 69 - 15
routers/commentsRouter.go

@@ -4435,6 +4435,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"],
+        beego.ControllerComments{
+            Method: "CancelApprove",
+            Router: `/approve/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"],
+        beego.ControllerComments{
+            Method: "SubmitApprove",
+            Router: `/approve/submit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"],
         beego.ControllerComments{
             Method: "Author",
@@ -4831,6 +4849,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
+        beego.ControllerComments{
+            Method: "Approve",
+            Router: `/approve`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
+        beego.ControllerComments{
+            Method: "Cancel",
+            Router: `/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
         beego.ControllerComments{
             Method: "Detail",
@@ -4849,19 +4885,28 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"],
+    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
         beego.ControllerComments{
-            Method: "Approve",
-            Router: `/approve`,
+            Method: "MessageList",
+            Router: `/message/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
+        beego.ControllerComments{
+            Method: "MessageRead",
+            Router: `/message/read`,
             AllowHTTPMethods: []string{"post"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"],
+    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveController"],
         beego.ControllerComments{
-            Method: "Cancel",
-            Router: `/cancel`,
+            Method: "Refuse",
+            Router: `/refuse`,
             AllowHTTPMethods: []string{"post"},
             MethodParams: param.Make(),
             Filters: nil,
@@ -4912,15 +4957,6 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"],
-        beego.ControllerComments{
-            Method: "Refuse",
-            Router: `/refuse`,
-            AllowHTTPMethods: []string{"post"},
-            MethodParams: param.Make(),
-            Filters: nil,
-            Params: nil})
-
     beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/report_approve:ReportApproveFlowController"],
         beego.ControllerComments{
             Method: "ReportClassifyTree",
@@ -5380,6 +5416,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportController"],
+        beego.ControllerComments{
+            Method: "CancelApprove",
+            Router: `/approve/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportController"],
+        beego.ControllerComments{
+            Method: "SubmitApprove",
+            Router: `/approve/submit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/smart_report:SmartReportController"],
         beego.ControllerComments{
             Method: "Detail",

+ 568 - 77
services/report_approve.go

@@ -114,19 +114,9 @@ func CheckReportCurrState(reportType, firstId, secondId, operate int) (state int
 	return
 }
 
-//type SubmitReportApprovePars struct {
-//	ReportType   int
-//	ReportId     int
-//	ReportTitle  string
-//	FirstId      int
-//	SecondId     int
-//	SysAdminId   int
-//	SysAdminName string
-//}
-
 // SubmitReportApprove 提交审批
 func SubmitReportApprove(reportType, reportId int, reportTitle string, firstId, secondId int, sysAdminId int, sysAdminName string) (approveId int, err error) {
-	// 如果是走的第三方审批, 那么仅修改状态
+	// 默认内部审批, 如果是走的第三方审批, 那么仅修改状态
 	confMap, e := models.GetBusinessConf()
 	if e != nil {
 		err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
@@ -134,7 +124,15 @@ func SubmitReportApprove(reportType, reportId int, reportTitle string, firstId,
 	}
 	openMap := map[string]bool{"false": false, "true": true}
 	openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
-	if openApprove && confMap[models.BusinessConfReportApproveType] == models.BusinessConfReportApproveTypeOther {
+	if !openApprove {
+		err = fmt.Errorf("未开启审批")
+		return
+	}
+	confApproveType := confMap[models.BusinessConfReportApproveType]
+	if confApproveType == "" {
+		confApproveType = models.BusinessConfReportApproveTypeEta
+	}
+	if confApproveType == models.BusinessConfReportApproveTypeOther {
 		return
 	}
 
@@ -176,15 +174,15 @@ func SubmitReportApprove(reportType, reportId int, reportTitle string, firstId,
 		err = fmt.Errorf("首个审批节点有误")
 		return
 	}
-	firstNode, e := report_approve.FormatReportApproveNode2Item(firstNodeItem)
-	if e != nil {
-		err = fmt.Errorf("首个审批节点信息有误, Err: %s", e.Error())
-		return
-	}
-	if len(firstNode.Users) == 0 {
-		err = fmt.Errorf("首个审批节点审批人信息有误")
-		return
-	}
+	//firstNode, e := report_approve.FormatReportApproveNode2Item(firstNodeItem)
+	//if e != nil {
+	//	err = fmt.Errorf("首个审批节点信息有误, Err: %s", e.Error())
+	//	return
+	//}
+	//if len(firstNode.Users) == 0 {
+	//	err = fmt.Errorf("首个审批节点审批人信息有误")
+	//	return
+	//}
 
 	// 审批信息
 	now := time.Now().Local()
@@ -203,66 +201,75 @@ func SubmitReportApprove(reportType, reportId int, reportTitle string, firstId,
 	newApprove.ApplyUserName = sysAdminName
 	newApprove.CreateTime = now
 	newApprove.ModifyTime = now
-
-	// 根据节点审批方式生成审批记录
-	newRecords := make([]*report_approve.ReportApproveRecord, 0)
-	sort.Slice(firstNode.Users, func(k, j int) bool {
-		return firstNode.Users[k].Sort < firstNode.Users[j].Sort
-	})
-	for _, u := range firstNode.Users {
-		r := new(report_approve.ReportApproveRecord)
-		r.State = report_approve.ReportApproveStateApproving
-		r.NodeId = firstNode.ReportApproveNodeId
-		r.PrevNodeId = firstNode.PrevNodeId
-		r.NextNodeId = firstNode.NextNodeId
-		r.ApproveType = firstNode.ApproveType
-		r.ApproveUserId = u.UserId
-		r.ApproveUserName = u.UserName
-		r.ApproveUserSort = u.Sort
-		r.CreateTime = now
-		r.ModifyTime = now
-		newRecords = append(newRecords, r)
-		// 依次审批仅生成一条记录
-		if firstNode.ApproveType == report_approve.NodeApproveTypeRoll {
-			break
-		}
-	}
-
-	// 新增审批和审批记录
-	if e = newApprove.CreateApproveAndRecord(newApprove, newRecords); e != nil {
-		err = fmt.Errorf("CreateApproveAndRecord err: %s", e.Error())
+	if e = newApprove.Create(); e != nil {
+		err = fmt.Errorf("生成审批信息失败, Err: %s", e.Error())
 		return
 	}
-	approveId = newApprove.ReportApproveId
 
-	// 推送审批消息
-	go func() {
-		messageOb := new(report_approve.ReportApproveMessage)
-		messages := make([]*report_approve.ReportApproveMessage, 0)
-		for _, v := range newRecords {
-			m := new(report_approve.ReportApproveMessage)
-			m.SendUserId = sysAdminId
-			m.ReceiveUserId = v.ApproveUserId
-			m.Content = "您有新的待办任务"
-			m.Remark = fmt.Sprintf("%s提交的【研报审批】需要您审批,请及时处理", sysAdminName)
-			m.ReportApproveId = newApprove.ReportApproveId
-			m.ApproveState = report_approve.ReportApproveStateApproving
-			m.CreateTime = now
-			m.ModifyTime = now
-			messages = append(messages, m)
-		}
-		e = messageOb.CreateMulti(messages)
-		if e != nil {
-			utils.FileLog.Info(fmt.Sprintf("SubmitReportApprove messages err: %s", e.Error()))
-			return
-		}
-	}()
+	// 生成节点审批记录
+	err = BuildNextNodeRecordAndMsg(firstNodeItem, newApprove.ReportApproveId, sysAdminId, sysAdminName)
+	//func BuildNextNodeRecordAndMsg(approveNodeItem *report_approve.ReportApproveNode, approveId, sysAdminId int, sysAdminName string)
+	//BuildNextNodeRecordAndMsg
+
+	// 根据节点审批方式生成审批记录
+	//newRecords := make([]*report_approve.ReportApproveRecord, 0)
+	//sort.Slice(firstNode.Users, func(k, j int) bool {
+	//	return firstNode.Users[k].Sort < firstNode.Users[j].Sort
+	//})
+	//for _, u := range firstNode.Users {
+	//	r := new(report_approve.ReportApproveRecord)
+	//	r.State = report_approve.ReportApproveStateApproving
+	//	r.NodeId = firstNode.ReportApproveNodeId
+	//	r.PrevNodeId = firstNode.PrevNodeId
+	//	r.NextNodeId = firstNode.NextNodeId
+	//	r.ApproveType = firstNode.ApproveType
+	//	r.ApproveUserId = u.UserId
+	//	r.ApproveUserName = u.UserName
+	//	r.ApproveUserSort = u.Sort
+	//	r.CreateTime = now
+	//	r.ModifyTime = now
+	//	newRecords = append(newRecords, r)
+	//	// 依次审批仅生成一条记录
+	//	if firstNode.ApproveType == report_approve.NodeApproveTypeRoll {
+	//		break
+	//	}
+	//}
+	//
+	//// 新增审批和审批记录
+	//if e = newApprove.CreateApproveAndRecord(newApprove, newRecords); e != nil {
+	//	err = fmt.Errorf("CreateApproveAndRecord err: %s", e.Error())
+	//	return
+	//}
+	//approveId = newApprove.ReportApproveId
+	//
+	//// 推送审批消息
+	//go func() {
+	//	messageOb := new(report_approve.ReportApproveMessage)
+	//	messages := make([]*report_approve.ReportApproveMessage, 0)
+	//	for _, v := range newRecords {
+	//		m := new(report_approve.ReportApproveMessage)
+	//		m.SendUserId = sysAdminId
+	//		m.ReceiveUserId = v.ApproveUserId
+	//		m.Content = "您有新的待办任务"
+	//		m.Remark = fmt.Sprintf("%s提交的【研报审批】需要您审批,请及时处理", sysAdminName)
+	//		m.ReportApproveId = newApprove.ReportApproveId
+	//		m.ApproveState = report_approve.ReportApproveStateApproving
+	//		m.CreateTime = now
+	//		m.ModifyTime = now
+	//		messages = append(messages, m)
+	//	}
+	//	e = messageOb.CreateMulti(messages)
+	//	if e != nil {
+	//		utils.FileLog.Info(fmt.Sprintf("SubmitReportApprove messages err: %s", e.Error()))
+	//		return
+	//	}
+	//}()
 	return
 }
 
 // CancelReportApprove 撤回审批
-func CancelReportApprove(approveId, sysAdminId int, sysAdminName string) (err error) {
-	// 如果是走的第三方审批, 那么仅修改状态
+func CancelReportApprove(reportType, reportId, approveId, sysAdminId int, sysAdminName string) (err error) {
+	// 默认内部审批, 如果是走的第三方审批, 那么仅修改状态
 	confMap, e := models.GetBusinessConf()
 	if e != nil {
 		err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
@@ -270,7 +277,23 @@ func CancelReportApprove(approveId, sysAdminId int, sysAdminName string) (err er
 	}
 	openMap := map[string]bool{"false": false, "true": true}
 	openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
-	if openApprove && confMap[models.BusinessConfReportApproveType] == models.BusinessConfReportApproveTypeOther {
+	if !openApprove {
+		//err = fmt.Errorf("未开启审批")
+		return
+	}
+	confApproveType := confMap[models.BusinessConfReportApproveType]
+	if confApproveType == "" {
+		confApproveType = models.BusinessConfReportApproveTypeEta
+	}
+	if confApproveType == models.BusinessConfReportApproveTypeOther {
+		return
+	}
+	if openApprove && confApproveType == models.BusinessConfReportApproveTypeOther {
+		e = updateReportApproveState(reportType, reportId, 0, models.ReportStateWaitSubmit)
+		if e != nil {
+			err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
+			return
+		}
 		return
 	}
 
@@ -294,6 +317,13 @@ func CancelReportApprove(approveId, sysAdminId int, sysAdminName string) (err er
 		return
 	}
 
+	// 修改报告状态
+	e = updateReportApproveState(reportType, reportId, 0, models.ReportStateWaitSubmit)
+	if e != nil {
+		err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
+		return
+	}
+
 	// 推送撤回消息
 	go func() {
 		recordOb := new(report_approve.ReportApproveRecord)
@@ -328,7 +358,468 @@ func CancelReportApprove(approveId, sysAdminId int, sysAdminName string) (err er
 	return
 }
 
-// ApproveReport 报告审批
-func ApproveReport() (err error) {
+// updateReportApproveState 更新报告审批状态
+func updateReportApproveState(reportType, reportId, approveId, state int) (err error) {
+	if reportType == report_approve.FlowReportTypeChinese {
+		reportOb := new(models.Report)
+		reportItem, e := reportOb.GetItemById(reportId)
+		// 报告可能会被删除, 这里查不到就忽略掉
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取中文研报失败, Err: %s", e.Error())
+			return
+		}
+		if reportItem != nil {
+			reportItem.ApproveId = approveId
+			reportItem.State = state
+			reportItem.ModifyTime = time.Now().Local()
+			if e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"}); e != nil {
+				err = fmt.Errorf("更新中文研报审批状态失败, Err: %s", e.Error())
+				return
+			}
+		}
+	}
+	if reportType == report_approve.FlowReportTypeEnglish {
+		reportItem, e := models.GetEnglishReportItemById(reportId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取英文研报失败, Err: %s", e.Error())
+			return
+		}
+		if reportItem != nil {
+			reportItem.ApproveId = approveId
+			reportItem.State = state
+			reportItem.ModifyTime = time.Now().Local()
+			if e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"}); e != nil {
+				err = fmt.Errorf("更新英文研报审批状态失败, Err: %s", e.Error())
+				return
+			}
+		}
+	}
+	if reportType == report_approve.FlowReportTypeSmart {
+		reportOb := new(smart_report.SmartReport)
+		reportItem, e := reportOb.GetItemById(reportId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取智能研报失败, Err: %s", e.Error())
+			return
+		}
+		if reportItem != nil {
+			reportItem.ApproveId = approveId
+			reportItem.State = state
+			reportItem.ModifyTime = time.Now().Local()
+			if e = reportItem.Update([]string{"ApproveId", "State", "ModifyTime"}); e != nil {
+				err = fmt.Errorf("更新智能研报审批状态失败, Err: %s", e.Error())
+				return
+			}
+		}
+	}
+	return
+}
+
+// PassReportApprove 通过审批
+func PassReportApprove(approveRecordId, sysAdminId int, sysAdminName string) (err error) {
+	// 校验审批记录和审批
+	recordOb := new(report_approve.ReportApproveRecord)
+	recordItem, e := recordOb.GetItemById(approveRecordId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			return
+		}
+		err = fmt.Errorf("获取审批记录失败, Err: %s", e.Error())
+		return
+	}
+	if recordItem.State != report_approve.ReportApproveStateApproving {
+		err = fmt.Errorf("审批记录状态有误")
+		return
+	}
+	if recordItem.ApproveUserId != sysAdminId {
+		err = fmt.Errorf("无权审批")
+		return
+	}
+	approveOb := new(report_approve.ReportApprove)
+	approveItem, e := approveOb.GetItemById(recordItem.ReportApproveId)
+	if e != nil {
+		err = fmt.Errorf("获取审批失败, Err: %s", e.Error())
+		return
+	}
+	if approveItem.State != report_approve.ReportApproveStateApproving {
+		err = fmt.Errorf("审批状态有误")
+		return
+	}
+
+	// 查询审批流和审批流节点
+	flowOb := new(report_approve.ReportApproveFlow)
+	flowItem, e := flowOb.GetItemById(approveItem.FlowId)
+	if e != nil {
+		err = fmt.Errorf("获取审批流失败, Err: %s", e.Error())
+		return
+	}
+	nodeOb := new(report_approve.ReportApproveNode)
+	nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveNodeCols.ReportApproveFlowId, report_approve.ReportApproveNodeCols.CurrVersion)
+	nodePars := make([]interface{}, 0)
+	nodePars = append(nodePars, flowItem.ReportApproveFlowId, flowItem.CurrVersion)
+	nodeItems, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
+	if e != nil {
+		err = fmt.Errorf("ApproveNodes GetItemsByCondition err: %s", e.Error())
+		return
+	}
+	if len(nodeItems) == 0 {
+		err = fmt.Errorf("无审批节点")
+		return
+	}
+	nodeMap := make(map[int]*report_approve.ReportApproveNode)
+	for _, v := range nodeItems {
+		nodeMap[v.ReportApproveNodeId] = v
+	}
+
+	// 取出当前节点
+	currNodeItem := nodeMap[recordItem.NodeId]
+	if currNodeItem == nil {
+		err = fmt.Errorf("当前节点信息有误")
+		return
+	}
+	currNode, e := report_approve.FormatReportApproveNode2Item(currNodeItem)
+	if e != nil {
+		err = fmt.Errorf("当前节点信息有误, Err: %s", e.Error())
+		return
+	}
+	now := time.Now().Local()
+	recordItem.State = report_approve.ReportApproveStatePass
+	recordItem.ApproveTime = now
+	recordItem.ModifyTime = now
+	recordCols := []string{"State", "ApproveTime", "ModifyTime"}
+	lastApprove := false
+
+	// 依次审批
+	if currNode.ApproveType == report_approve.NodeApproveTypeRoll {
+		if e = recordItem.Update(recordCols); e != nil {
+			err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
+			return
+		}
+
+		// 检查依次审批情况
+		sort.Slice(currNode.Users, func(k, j int) bool {
+			return currNode.Users[k].Sort < currNode.Users[j].Sort
+		})
+		userLen := len(currNode.Users)
+		//lastRoll := false
+		nextUser := new(report_approve.ReportApproveNodeUserReq) // 下一个审批人, 为nil则表示当前审批人即为最后
+		for k, v := range currNode.Users {
+			// 当前审批人
+			if v.UserId == sysAdminId && recordItem.ApproveUserSort == v.Sort {
+				//if k == (userLen - 1) {
+				//	lastRoll = true
+				//	break
+				//}
+				if (k + 1) <= userLen {
+					nextUser = currNode.Users[k+1]
+				}
+			}
+		}
+		//if lastRoll && currNode.NextNodeId == 0 {
+		//	lastApprove = true
+		//}
+
+		// 当前节点下一个审批人, 生成下一个审批记录且return
+		if nextUser != nil {
+			newRecord := new(report_approve.ReportApproveRecord)
+			newRecord.ReportApproveId = recordItem.ReportApproveId
+			newRecord.State = report_approve.ReportApproveStateApproving
+			newRecord.NodeId = currNode.ReportApproveNodeId
+			newRecord.PrevNodeId = currNode.PrevNodeId
+			newRecord.NextNodeId = currNode.NextNodeId
+			newRecord.ApproveType = currNode.ApproveType
+			newRecord.ApproveUserId = nextUser.UserId
+			newRecord.ApproveUserName = nextUser.UserName
+			newRecord.ApproveUserSort = nextUser.Sort
+			newRecord.CreateTime = now
+			newRecord.ModifyTime = now
+			if e = newRecord.Create(); e != nil {
+				err = fmt.Errorf("生成审批记录失败, Err: %s", e.Error())
+				return
+			}
+
+			// 推送审批消息
+			go func() {
+				messageItem := new(report_approve.ReportApproveMessage)
+				messageItem.SendUserId = sysAdminId
+				messageItem.ReceiveUserId = nextUser.UserId
+				messageItem.Content = "您有新的待办任务"
+				messageItem.Remark = fmt.Sprintf("%s提交的【研报审批】需要您审批,请及时处理", approveItem.ApplyUserName)
+				messageItem.ReportApproveId = approveItem.ReportApproveId
+				messageItem.ApproveState = report_approve.ReportApproveStateApproving
+				messageItem.CreateTime = now
+				messageItem.ModifyTime = now
+				if e = messageItem.Create(); e != nil {
+					utils.FileLog.Info(fmt.Sprintf("PassReportApprove message err: %s", e.Error()))
+					return
+				}
+			}()
+			return
+		}
+
+		// 更新审批当前节点并进入下一个节点
+		if currNode.NextNodeId > 0 {
+			nextNode := nodeMap[currNode.NextNodeId]
+			approveItem.CurrNodeId = currNode.NextNodeId
+			approveItem.ModifyTime = now
+			if e = approveItem.Update([]string{"CurrNodeId", "ModifyTime"}); e != nil {
+				err = fmt.Errorf("更新审批当前节点失败, Err: %s", e.Error())
+				return
+			}
+			err = BuildNextNodeRecordAndMsg(nextNode, approveItem.ReportApproveId, sysAdminId, sysAdminName)
+			return
+		} else {
+			// 最后一个节点
+			lastApprove = true
+		}
+	}
+
+	// 会签
+	if currNode.ApproveType == report_approve.NodeApproveTypeAll {
+		// 查询其他审批人是否已审批
+		otherCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s <> ?`, report_approve.ReportApproveRecordCols.ReportApproveId, report_approve.ReportApproveRecordCols.NodeId, report_approve.ReportApproveRecordCols.ApproveUserId)
+		otherPars := make([]interface{}, 0)
+		otherPars = append(otherPars, approveItem.ReportApproveId, recordItem.NodeId, sysAdminId)
+		otherRecords, e := recordOb.GetItemsByCondition(otherCond, otherPars, []string{}, "")
+		if e != nil {
+			err = fmt.Errorf("获取节点审批记录失败, Err: %s", e.Error())
+			return
+		}
+		otherPass := true
+		for _, v := range otherRecords {
+			if v.State != report_approve.ReportApproveStatePass {
+				otherPass = false
+			}
+		}
+
+		// 其他人未审批, 仅更新当前审批记录
+		if e = recordItem.Update(recordCols); e != nil {
+			err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
+			return
+		}
+
+		// 其他人已审批且为最后节点
+		if otherPass && currNode.NextNodeId == 0 {
+			lastApprove = true
+		}
+
+		// 其他人已审批且不为最后节点, 进入下一节点
+		if otherPass && currNode.NextNodeId > 0 {
+			nextNode := nodeMap[currNode.NextNodeId]
+			approveItem.CurrNodeId = currNode.NextNodeId
+			approveItem.ModifyTime = now
+			if e = approveItem.Update([]string{"CurrNodeId", "ModifyTime"}); e != nil {
+				err = fmt.Errorf("更新审批当前节点失败, Err: %s", e.Error())
+				return
+			}
+			err = BuildNextNodeRecordAndMsg(nextNode, approveItem.ReportApproveId, sysAdminId, sysAdminName)
+			return
+		}
+	}
+
+	// 或签
+	if currNode.ApproveType == report_approve.NodeApproveTypeAny {
+		if e = recordItem.Update(recordCols); e != nil {
+			err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
+			return
+		}
+		if currNode.NextNodeId == 0 {
+			lastApprove = true
+		}
+		if currNode.NextNodeId > 0 {
+			nextNode := nodeMap[currNode.NextNodeId]
+			approveItem.CurrNodeId = currNode.NextNodeId
+			approveItem.ModifyTime = now
+			if e = approveItem.Update([]string{"CurrNodeId", "ModifyTime"}); e != nil {
+				err = fmt.Errorf("更新审批当前节点失败, Err: %s", e.Error())
+				return
+			}
+			err = BuildNextNodeRecordAndMsg(nextNode, approveItem.ReportApproveId, sysAdminId, sysAdminName)
+			return
+		}
+	}
+
+	// 最后一个审批, 更新审批记录、审批、报告状态、推送消息给申请人
+	if lastApprove {
+		if e = recordItem.Update(recordCols); e != nil {
+			err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
+			return
+		}
+		approveItem.State = report_approve.ReportApproveStatePass
+		approveItem.ApproveTime = now
+		approveItem.ModifyTime = now
+		approveCols := []string{"State", "ApproveTime", "ModifyTime"}
+		if e = approveItem.Update(approveCols); e != nil {
+			err = fmt.Errorf("更新审批信息失败, Err: %s", e.Error())
+			return
+		}
+		if e = updateReportApproveState(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, models.ReportStatePass); e != nil {
+			err = fmt.Errorf("更新报告审批状态失败, Err: %s", e.Error())
+			return
+		}
+
+		go func() {
+			messageItem := new(report_approve.ReportApproveMessage)
+			messageItem.SendUserId = sysAdminId
+			messageItem.ReceiveUserId = approveItem.ApplyUserId
+			messageItem.Content = "您提交的审批已通过"
+			messageItem.Remark = "您提交的【研报审批】已通过"
+			messageItem.ReportApproveId = approveItem.ReportApproveId
+			messageItem.ApproveState = report_approve.ReportApproveStatePass
+			messageItem.CreateTime = now
+			messageItem.ModifyTime = now
+			if e = messageItem.Create(); e != nil {
+				utils.FileLog.Info(fmt.Sprintf("PassReportApprove message err: %s", e.Error()))
+				return
+			}
+		}()
+	}
+	return
+}
+
+// RefuseReportApprove 驳回审批
+func RefuseReportApprove(approveRecordId int, approveRemark string, sysAdminId int) (err error) {
+	recordOb := new(report_approve.ReportApproveRecord)
+	recordItem, e := recordOb.GetItemById(approveRecordId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			return
+		}
+		err = fmt.Errorf("获取审批记录失败, Err: %s", e.Error())
+		return
+	}
+	if recordItem.State != report_approve.ReportApproveStateApproving {
+		err = fmt.Errorf("审批记录状态有误")
+		return
+	}
+	if recordItem.ApproveUserId != sysAdminId {
+		err = fmt.Errorf("无权审批")
+		return
+	}
+	approveOb := new(report_approve.ReportApprove)
+	approveItem, e := approveOb.GetItemById(recordItem.ReportApproveId)
+	if e != nil {
+		err = fmt.Errorf("获取审批失败, Err: %s", e.Error())
+		return
+	}
+	if approveItem.State != report_approve.ReportApproveStateApproving {
+		err = fmt.Errorf("审批状态有误")
+		return
+	}
+
+	// 更新审批记录
+	now := time.Now().Local()
+	recordItem.State = report_approve.ReportApproveStateRefuse
+	recordItem.ApproveRemark = approveRemark
+	recordItem.ApproveTime = now
+	recordItem.ModifyTime = now
+	recordCols := []string{"State", "ApproveRemark", "ApproveTime", "ModifyTime"}
+	if e = recordItem.Update(recordCols); e != nil {
+		err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
+		return
+	}
+
+	// 驳回-更新审批, 报告状态, 推送消息
+	approveItem.State = report_approve.ReportApproveStateRefuse
+	approveItem.ApproveRemark = approveRemark
+	approveItem.ApproveTime = now
+	approveItem.ModifyTime = now
+	approveCols := []string{"State", "ApproveRemark", "ApproveTime", "ModifyTime"}
+	if e = approveItem.Update(approveCols); e != nil {
+		err = fmt.Errorf("更新审批状态失败, Err: %s", e.Error())
+		return
+	}
+	if e = updateReportApproveState(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, models.ReportStateRefused); e != nil {
+		err = fmt.Errorf("更新报告状态失败, Err: %s", e.Error())
+		return
+	}
+
+	// 推送驳回消息给申请人
+	go func() {
+		messageItem := new(report_approve.ReportApproveMessage)
+		messageItem.SendUserId = sysAdminId
+		messageItem.ReceiveUserId = approveItem.ApplyUserId
+		messageItem.Content = "您提交的审批被驳回"
+		messageItem.Remark = "您提交的【研报审批】已被驳回"
+		messageItem.ReportApproveId = approveItem.ReportApproveId
+		messageItem.ApproveState = report_approve.ReportApproveStateRefuse
+		messageItem.CreateTime = now
+		messageItem.ModifyTime = now
+		if e = messageItem.Create(); e != nil {
+			utils.FileLog.Info(fmt.Sprintf("ApproveReport message err: %s", e.Error()))
+			return
+		}
+	}()
+	return
+}
+
+// BuildNextNodeRecordAndMsg 生成下一个节点的审批记录并推送消息
+func BuildNextNodeRecordAndMsg(approveNodeItem *report_approve.ReportApproveNode, approveId, sysAdminId int, sysAdminName string) (err error) {
+	if approveNodeItem == nil {
+		err = fmt.Errorf("approve node nil")
+		return
+	}
+
+	// 根据节点审批方式生成审批记录
+	now := time.Now().Local()
+	approveNode, e := report_approve.FormatReportApproveNode2Item(approveNodeItem)
+	if e != nil {
+		err = fmt.Errorf("FormatReportApproveNode2Item err: %s", e.Error())
+		return
+	}
+	if len(approveNode.Users) == 0 {
+		err = fmt.Errorf("审批节点用户有误")
+		return
+	}
+	newRecords := make([]*report_approve.ReportApproveRecord, 0)
+	sort.Slice(approveNode.Users, func(k, j int) bool {
+		return approveNode.Users[k].Sort < approveNode.Users[j].Sort
+	})
+	for _, u := range approveNode.Users {
+		r := new(report_approve.ReportApproveRecord)
+		r.State = report_approve.ReportApproveStateApproving
+		r.NodeId = approveNode.ReportApproveNodeId
+		r.PrevNodeId = approveNode.PrevNodeId
+		r.NextNodeId = approveNode.NextNodeId
+		r.ApproveType = approveNode.ApproveType
+		r.ApproveUserId = u.UserId
+		r.ApproveUserName = u.UserName
+		r.ApproveUserSort = u.Sort
+		r.CreateTime = now
+		r.ModifyTime = now
+		newRecords = append(newRecords, r)
+		// 依次审批仅生成一条记录
+		if approveNode.ApproveType == report_approve.NodeApproveTypeRoll {
+			break
+		}
+	}
+
+	recordOb := new(report_approve.ReportApproveRecord)
+	if e = recordOb.CreateMulti(newRecords); e != nil {
+		err = fmt.Errorf("生成节点审批记录失败, Err: %s", e.Error())
+		return
+	}
+
+	// 推送审批消息
+	go func() {
+		messageOb := new(report_approve.ReportApproveMessage)
+		messages := make([]*report_approve.ReportApproveMessage, 0)
+		for _, v := range newRecords {
+			m := new(report_approve.ReportApproveMessage)
+			m.SendUserId = sysAdminId
+			m.ReceiveUserId = v.ApproveUserId
+			m.Content = "您有新的待办任务"
+			m.Remark = fmt.Sprintf("%s提交的【研报审批】需要您审批,请及时处理", sysAdminName)
+			m.ReportApproveId = approveId
+			m.ApproveState = report_approve.ReportApproveStateApproving
+			m.CreateTime = now
+			m.ModifyTime = now
+			messages = append(messages, m)
+		}
+		e = messageOb.CreateMulti(messages)
+		if e != nil {
+			utils.FileLog.Info(fmt.Sprintf("BuildNextNodeRecordAndMsg messages err: %s", e.Error()))
+			return
+		}
+	}()
 	return
 }