123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053 |
- package services
- import (
- "eta/eta_api/models"
- "eta/eta_api/models/report_approve"
- "eta/eta_api/models/smart_report"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/utils"
- "fmt"
- "sort"
- "time"
- )
- func GetReportClassifyTreeRecursive(list []*models.Classify, parentId int) []*report_approve.ReportClassifyTreeItem {
- res := make([]*report_approve.ReportClassifyTreeItem, 0)
- for _, v := range list {
- if v.ParentId == parentId {
- t := new(report_approve.ReportClassifyTreeItem)
- t.ClassifyId = v.Id
- t.ClassifyName = v.ClassifyName
- t.ParentId = v.ParentId
- t.Children = GetReportClassifyTreeRecursive(list, v.Id)
- res = append(res, t)
- }
- }
- return res
- }
- func CheckReportApproveFlowChange(reportType, classifyFirstId, classifySecondId, classifyThirdId int) (ok bool, err error) {
- var count int
- cond := ` AND classify_id_first = ? AND classify_id_second = ? AND state = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, classifyFirstId, classifySecondId, models.ReportStateWaitApprove)
- switch reportType {
- case report_approve.FlowReportTypeChinese:
- cond += ` AND classify_id_third = ? `
- pars = append(pars, classifyThirdId)
- ct, e := models.GetReportListCount(cond, pars)
- if e != nil {
- err = fmt.Errorf("GetReportListCount err: %s", e.Error())
- return
- }
- count = ct
- case report_approve.FlowReportTypeEnglish:
- ct, e := models.GetEnglishReportListCount(cond, pars, "")
- if e != nil {
- err = fmt.Errorf("GetEnglishReportListCount err: %s", e.Error())
- return
- }
- count = ct
- case report_approve.FlowReportTypeSmart:
- ob := new(smart_report.SmartReport)
- ct, e := ob.GetCountByCondition(cond, pars)
- if e != nil {
- err = fmt.Errorf("SmartReport GetCountByCondition err: %s", e.Error())
- return
- }
- count = ct
- default:
- err = fmt.Errorf("报告类型有误")
- return
- }
- if count <= 0 {
- ok = true
- }
- return
- }
- func CheckReportOpenApprove(reportType, firstId, secondId, thirdId int) (opening bool, err error) {
-
- confMap, e := models.GetBusinessConf()
- if e != nil {
- err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
- return
- }
- openMap := map[string]bool{"false": false, "true": true}
- openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
-
- flowOb := new(report_approve.ReportApproveFlow)
- flowCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId, report_approve.ReportApproveFlowCols.ClassifyThirdId)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, reportType, firstId, secondId, thirdId)
- flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
- return
- }
-
- if openApprove && (flowItem != nil || confMap[models.BusinessConfReportApproveType] == models.BusinessConfReportApproveTypeOther) {
- opening = true
- return
- }
- return
- }
- func CheckReportCurrState(reportType, firstId, secondId, thirdId, operate int) (state int, err error) {
-
- confMap, e := models.GetBusinessConf()
- if e != nil {
- err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
- return
- }
- openMap := map[string]bool{"false": false, "true": true}
- openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
-
- flowOb := new(report_approve.ReportApproveFlow)
- flowCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId, report_approve.ReportApproveFlowCols.ClassifyThirdId)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, reportType, firstId, secondId, thirdId)
- flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
- return
- }
-
- if openApprove && (flowItem != nil || confMap[models.BusinessConfReportApproveType] == models.BusinessConfReportApproveTypeOther) {
-
- stateMap := map[int]int{
- models.ReportOperateAdd: models.ReportStateWaitSubmit,
- models.ReportOperateEdit: models.ReportStateWaitSubmit,
- models.ReportOperatePublish: models.ReportStateWaitSubmit,
- models.ReportOperateCancelPublish: models.ReportStateWaitSubmit,
- models.ReportOperateSubmitApprove: models.ReportStateWaitApprove,
- models.ReportOperateCancelApprove: models.ReportStateWaitSubmit,
- }
- state = stateMap[operate]
- return
- }
-
-
- stateMap := map[int]int{
- models.ReportOperateAdd: models.ReportStateUnpublished,
- models.ReportOperateEdit: models.ReportStateUnpublished,
- models.ReportOperatePublish: models.ReportStatePublished,
- models.ReportOperateCancelPublish: models.ReportStateUnpublished,
- models.ReportOperateSubmitApprove: models.ReportStateUnpublished,
- models.ReportOperateCancelApprove: models.ReportStateUnpublished,
- }
- state = stateMap[operate]
- return
- }
- func SubmitReportApprove(reportType, reportId int, reportTitle string, firstId, secondId, thirdId int, sysAdminId int, sysAdminName string) (approveId int, err error) {
-
- confMap, e := models.GetBusinessConf()
- if e != nil {
- err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
- return
- }
- openMap := map[string]bool{"false": false, "true": true}
- openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
- if !openApprove {
- err = fmt.Errorf("未开启审批")
- return
- }
- confApproveType := confMap[models.BusinessConfReportApproveType]
- if confApproveType == "" {
- confApproveType = models.BusinessConfReportApproveTypeEta
- }
- if confApproveType == models.BusinessConfReportApproveTypeOther {
- return
- }
-
- flowOb := new(report_approve.ReportApproveFlow)
- flowCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveFlowCols.ReportType, report_approve.ReportApproveFlowCols.ClassifyFirstId, report_approve.ReportApproveFlowCols.ClassifySecondId, report_approve.ReportApproveFlowCols.ClassifyThirdId)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, reportType, firstId, secondId, thirdId)
- flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
- if e != nil {
- err = fmt.Errorf("ApproveFlow GetItemByCondition 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
- }
-
- firstNodeItem := new(report_approve.ReportApproveNode)
- for _, v := range nodeItems {
- if v.PrevNodeId == 0 {
- firstNodeItem = v
- continue
- }
- }
- if firstNodeItem == nil {
- err = fmt.Errorf("首个审批节点有误")
- return
- }
-
- now := time.Now().Local()
- newApprove := new(report_approve.ReportApprove)
- newApprove.ReportType = reportType
- newApprove.ReportId = reportId
- newApprove.ReportTitle = reportTitle
- newApprove.ClassifyFirstId = firstId
- newApprove.ClassifySecondId = secondId
- newApprove.ClassifyThirdId = thirdId
- newApprove.State = report_approve.ReportApproveStateApproving
- newApprove.FlowId = flowItem.ReportApproveFlowId
- newApprove.FlowVersion = flowItem.CurrVersion
- newApprove.StartNodeId = firstNodeItem.ReportApproveNodeId
- newApprove.CurrNodeId = firstNodeItem.ReportApproveNodeId
- newApprove.ApplyUserId = sysAdminId
- newApprove.ApplyUserName = sysAdminName
- newApprove.CreateTime = now
- newApprove.ModifyTime = now
- if e = newApprove.Create(); e != nil {
- err = fmt.Errorf("生成审批信息失败, Err: %s", e.Error())
- return
- }
- approveId = newApprove.ReportApproveId
-
- err = BuildNextNodeRecordAndMsg(firstNodeItem, newApprove.ReportApproveId, sysAdminId, sysAdminName)
- return
- }
- 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())
- return
- }
- openMap := map[string]bool{"false": false, "true": true}
- openApprove := openMap[confMap[models.BusinessConfIsReportApprove]]
- if !openApprove {
-
- return
- }
- confApproveType := confMap[models.BusinessConfReportApproveType]
- if confApproveType == "" {
- confApproveType = models.BusinessConfReportApproveTypeEta
- }
-
- if confApproveType == models.BusinessConfReportApproveTypeOther {
- e = updateReportApproveState(reportType, reportId, 0, models.ReportStateWaitSubmit)
- if e != nil {
- err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
- return
- }
- return
- }
-
- approveOb := new(report_approve.ReportApprove)
- approveItem, e := approveOb.GetItemById(approveId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- return
- }
- err = fmt.Errorf("approve GetItemById err: %s", e.Error())
- return
- }
- if approveItem.State == report_approve.ReportApproveStateCancel {
- return
- }
- approveItem.State = report_approve.ReportApproveStateCancel
- cols := []string{"State", "ModifyTime"}
- if e = approveItem.Update(cols); e != nil {
- err = fmt.Errorf("approve Update err: %s", e.Error())
- 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)
- recordCond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, approveId)
- recordItems, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, "")
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("approve record GetItemsByCondition err: %s", e.Error()))
- return
- }
- messageOb := new(report_approve.ReportApproveMessage)
- messages := make([]*report_approve.ReportApproveMessage, 0)
- for _, v := range recordItems {
- m := new(report_approve.ReportApproveMessage)
- m.SendUserId = sysAdminId
- m.ReceiveUserId = v.ApproveUserId
- m.Content = fmt.Sprintf("%s提交的【研报审批】已撤回", sysAdminName)
- m.ReportApproveId = approveId
- m.ApproveState = report_approve.ReportApproveStateCancel
- m.CreateTime = time.Now().Local()
- m.ModifyTime = time.Now().Local()
- messages = append(messages, m)
- }
- e = messageOb.CreateMulti(messages)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("CancelReportApprove messages err: %s", e.Error()))
- return
- }
- }()
- return
- }
- func updateReportApproveState(reportType, reportId, approveId, state int) (err error) {
- updateCols := []string{"ApproveId", "State", "ModifyTime"}
- 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 state == models.ReportStatePass || state == models.ReportStateRefused {
- updateCols = append(updateCols, "ApproveTime")
- reportItem.ApproveTime = time.Now().Local()
- }
- if state == models.ReportStatePass {
- updateCols = append(updateCols, "PublishTime")
- reportItem.PublishTime = time.Now().Local()
- }
- if e = reportItem.UpdateReport(updateCols); 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 state == models.ReportStatePass || state == models.ReportStateRefused {
- updateCols = append(updateCols, "ApproveTime")
- reportItem.ApproveTime = time.Now().Local()
- }
- if state == models.ReportStatePass {
- updateCols = append(updateCols, "PublishTime")
- reportItem.PublishTime = time.Now().Local()
- }
- if e = reportItem.UpdateReport(updateCols); 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 state == models.ReportStatePass || state == models.ReportStateRefused {
- updateCols = append(updateCols, "ApproveTime")
- reportItem.ApproveTime = time.Now().Local()
- }
- if state == models.ReportStatePass {
- updateCols = append(updateCols, "PublishTime")
- reportItem.PublishTime = time.Now().Local()
- }
- if e = reportItem.Update(updateCols); e != nil {
- err = fmt.Errorf("更新智能研报审批状态失败, Err: %s", e.Error())
- return
- }
- }
- }
- return
- }
- func PassReportApprove(approveItem *report_approve.ReportApprove, recordItem *report_approve.ReportApproveRecord, sysAdminId int, reportUrl string) (tips string, err error) {
- if approveItem == nil {
- err = fmt.Errorf("审批信息有误")
- return
- }
- if recordItem == nil {
- 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
- recordItem.NodeState = report_approve.ReportApproveStatePass
- recordItem.NodeApproveUserId = recordItem.ApproveUserId
- recordItem.NodeApproveUserName = recordItem.ApproveUserName
- recordItem.NodeApproveTime = now
- recordCols := []string{"State", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
- 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.UserId > 0 {
- 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
- newRecord.NodeState = report_approve.ReportApproveStateApproving
- if e = newRecord.Create(); e != nil {
- err = fmt.Errorf("生成审批记录失败, Err: %s", e.Error())
- return
- }
-
- go func() {
- messageItem := new(report_approve.ReportApproveMessage)
- messageItem.SendUserId = approveItem.ApplyUserId
- 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, approveItem.ApplyUserId, approveItem.ApplyUserName)
- return
- } else {
-
- lastApprove = true
- }
- }
-
- if currNode.ApproveType == report_approve.NodeApproveTypeAll {
-
- otherOb := new(report_approve.ReportApproveRecord)
- 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 := otherOb.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, approveItem.ApplyUserId, approveItem.ApplyUserName)
- return
- }
- }
-
- if currNode.ApproveType == report_approve.NodeApproveTypeAny {
-
-
- if approveItem.CurrNodeId != recordItem.NodeId {
- tips = "该节点已完成审批, 请刷新页面"
- return
- }
- if e = recordItem.Update(recordCols); e != nil {
- err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
- return
- }
-
- if e = recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); 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, approveItem.ApplyUserId, approveItem.ApplyUserName)
- 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
- }
- }()
-
- go func() {
- if e = AfterReportApprovePass(approveItem.ReportType, approveItem.ReportId); e != nil {
- utils.FileLog.Info(fmt.Sprintf("AfterReportApprovePass err: %s, ReportType: %d, ReportId: %d", e.Error(), approveItem.ReportType, approveItem.ReportId))
- return
- }
- }()
- }
- return
- }
- func RefuseReportApprove(approveItem *report_approve.ReportApprove, recordItem *report_approve.ReportApproveRecord, approveRemark string, sysAdminId int) (err error) {
- if approveItem == nil {
- err = fmt.Errorf("审批信息有误")
- return
- }
- if recordItem == nil {
- err = fmt.Errorf("审批记录有误")
- return
- }
-
- now := time.Now().Local()
- recordItem.State = report_approve.ReportApproveStateRefuse
- recordItem.ApproveRemark = approveRemark
- recordItem.ApproveTime = now
- recordItem.ModifyTime = now
- recordItem.NodeState = report_approve.ReportApproveStateRefuse
- recordItem.NodeApproveUserId = recordItem.ApproveUserId
- recordItem.NodeApproveUserName = recordItem.ApproveUserName
- recordItem.NodeApproveTime = now
- recordCols := []string{"State", "ApproveRemark", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
- if e := recordItem.Update(recordCols); e != nil {
- err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
- return
- }
-
- if e := recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); 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.ReportApproveId = approveId
- 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
- r.NodeState = report_approve.ReportApproveStateApproving
- 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
- }
- func AfterReportApprovePass(reportType, reportId int) (err error) {
-
- if reportType == report_approve.FlowReportTypeChinese {
- reportInfo, e := models.GetReportByReportId(reportId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- return
- }
- err = fmt.Errorf("获取研报信息失败, Err: %s", e.Error())
- return
- }
-
- go UpdateReportVideo(reportInfo)
-
- {
- reportPdfUrl := GetGeneralPdfUrl(reportInfo.ReportCode, reportInfo.ClassifyNameFirst, reportInfo.ReportLayout)
- go Report2pdfAndJpeg(reportPdfUrl, reportId, 1)
- }
-
- _ = UpdateReportEs(reportInfo.Id, models.ReportStatePublished)
- return
- }
-
- if reportType == report_approve.FlowReportTypeEnglish {
- _ = UpdateEnglishReportEs(reportId, models.ReportStatePublished)
- return
- }
-
- if reportType == report_approve.FlowReportTypeSmart {
- ob := new(smart_report.SmartReport)
- item, e := ob.GetItemById(reportId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- return
- }
- err = fmt.Errorf("获取智能研报信息失败, Err: %s", e.Error())
- return
- }
-
-
-
-
-
-
- if item.VideoUrl == "" {
- SmartReportBuildVideoAndUpdate(item)
- }
-
- _ = SmartReportElasticUpsert(item.SmartReportId, models.ReportStatePublished)
- }
- return
- }
- func CheckCloseReportApproveConf() (yes bool, err error) {
-
- count, e := models.GetReportStateCount(models.ReportStateWaitApprove)
- if e != nil {
- err = fmt.Errorf("查询审批中的报告数量失败, Err: %s", e.Error())
- return
- }
- if count > 0 {
- return
- }
- count, e = models.GetEnglishReportStateCount(models.ReportStateWaitApprove)
- if e != nil {
- err = fmt.Errorf("查询审批中的英文报告数量失败, Err: %s", e.Error())
- return
- }
- if count > 0 {
- return
- }
- smartOb := new(smart_report.SmartReport)
- cond := ` AND state = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, models.ReportStateWaitApprove)
- count, e = smartOb.GetCountByCondition(cond, pars)
- if e != nil {
- err = fmt.Errorf("查询审批中的智能报告数量失败, Err: %s", e.Error())
- return
- }
- if count > 0 {
- return
- }
- yes = true
- return
- }
- func FlowOperateResetReportState(reportType, classifyFirstId, classifySecondId, classifyThirdId, oldState, State int) (err error) {
- defer func() {
- if err != nil {
- tips := fmt.Sprintf("审批流变化-重置报告初始状态失败, ErrMsg: %s", err.Error())
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 2)
- }
- }()
-
- if reportType == report_approve.FlowReportTypeChinese {
- e := models.UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, State)
- if e != nil {
- err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
- }
- return
- }
-
- if reportType == report_approve.FlowReportTypeEnglish {
- e := models.UpdateEnglishReportsStateByCond(classifyFirstId, classifySecondId, oldState, State)
- if e != nil {
- err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
- }
- return
- }
-
- if reportType == report_approve.FlowReportTypeSmart {
- e := smart_report.UpdateSmartReportsStateByCond(classifyFirstId, classifySecondId, oldState, State)
- if e != nil {
- err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
- }
- return
- }
- return
- }
- func ConfigChangeResetReportState(changeType string) (err error) {
- defer func() {
- if err != nil {
- tips := fmt.Sprintf("审批配置变化-重置报告初始状态失败, ErrMsg: %s", err.Error())
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 2)
- }
- }()
-
- if changeType == "" {
- e := models.UpdateReportsStateByCond(0, 0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
- if e != nil {
- err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
- }
- e = models.UpdateEnglishReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
- if e != nil {
- err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
- }
- e = smart_report.UpdateSmartReportsStateByCond(0, 0, models.ReportStateWaitSubmit, models.ReportStateUnpublished)
- if e != nil {
- err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
- }
- return
- }
-
- if changeType == models.BusinessConfReportApproveTypeEta {
- flowOb := new(report_approve.ReportApproveFlow)
- flows, e := flowOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
- if e != nil {
- err = fmt.Errorf("GetApproveFlows err: %s", e.Error())
- return
- }
- reportSecondIds, englishSecondIds, smartSecondIds := make([]int, 0), make([]int, 0), make([]int, 0)
- for _, v := range flows {
- if v.ReportType == report_approve.FlowReportTypeChinese {
- reportSecondIds = append(reportSecondIds, v.ClassifySecondId)
- continue
- }
- if v.ReportType == report_approve.FlowReportTypeEnglish {
- englishSecondIds = append(englishSecondIds, v.ClassifySecondId)
- continue
- }
- if v.ReportType == report_approve.FlowReportTypeSmart {
- smartSecondIds = append(smartSecondIds, v.ClassifySecondId)
- }
- }
- if len(reportSecondIds) > 0 {
- e = models.UpdateReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, reportSecondIds)
- if e != nil {
- err = fmt.Errorf("UpdateReportsStateBySecondIds err: %s", e.Error())
- return
- }
- }
- if len(englishSecondIds) > 0 {
- e = models.UpdateEnglishReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, englishSecondIds)
- if e != nil {
- err = fmt.Errorf("UpdateEnglishReportsStateBySecondIds err: %s", e.Error())
- return
- }
- }
- if len(smartSecondIds) > 0 {
- e = smart_report.UpdateSmartReportsStateBySecondIds(models.ReportStateUnpublished, models.ReportStateWaitSubmit, smartSecondIds)
- if e != nil {
- err = fmt.Errorf("UpdateSmartReportsStateBySecondIds err: %s", e.Error())
- return
- }
- }
- return
- }
-
- if changeType == models.BusinessConfReportApproveTypeOther {
- e := models.UpdateReportsStateByCond(0, 0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
- if e != nil {
- err = fmt.Errorf("UpdateReportsStateByCond err: %s", e.Error())
- }
- e = models.UpdateEnglishReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
- if e != nil {
- err = fmt.Errorf("UpdateEnglishReportsStateByCond err: %s", e.Error())
- }
- e = smart_report.UpdateSmartReportsStateByCond(0, 0, models.ReportStateUnpublished, models.ReportStateWaitSubmit)
- if e != nil {
- err = fmt.Errorf("UpdateSmartReportsStateByCond err: %s", e.Error())
- }
- return
- }
- return
- }
|