|
@@ -114,19 +114,9 @@ func CheckReportCurrState(reportType, firstId, secondId, operate int) (state int
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
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
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
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)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
-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 {
|
|
|
+
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func ApproveReport() (err error) {
|
|
|
+
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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)
|
|
|
+
|
|
|
+ nextUser := new(report_approve.ReportApproveNodeUserReq)
|
|
|
+ for k, v := range currNode.Users {
|
|
|
+
|
|
|
+ if v.UserId == sysAdminId && recordItem.ApproveUserSort == v.Sort {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (k + 1) <= userLen {
|
|
|
+ nextUser = currNode.Users[k+1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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
|
|
|
}
|