1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171 |
- package knowledge_approve
- import (
- "encoding/json"
- "eta_gn/eta_api/models/knowledge"
- "eta_gn/eta_api/models/knowledge_approve"
- "eta_gn/eta_api/models/knowledge_approve/response"
- knowledgeSrv "eta_gn/eta_api/services/knowledge"
- "eta_gn/eta_api/utils"
- "fmt"
- "sort"
- "strings"
- "time"
- )
- var (
- timeField = map[int]string{1: fmt.Sprintf("a.%s", knowledge_approve.KnowledgeResourceApproveRecordCols.CreateTime), 2: fmt.Sprintf("a.%s", knowledge_approve.KnowledgeResourceApproveRecordCols.NodeApproveTime), 3: fmt.Sprintf("b.%s", knowledge_approve.KnowledgeResourceApproveCols.ApproveTime)}
- myTimeField = map[int]string{1: knowledge_approve.KnowledgeResourceApproveCols.CreateTime, 3: knowledge_approve.KnowledgeResourceApproveCols.ApproveTime}
- orderRules = map[int]string{1: "ASC", 2: "DESC"}
- )
- func GetPulicKnowledgeClassifyList(resourceType int) (res []*knowledge.KnowledgeClassifyItem, msg string, err error) {
- obj := new(knowledge.KnowledgeClassify)
- classifyList, err := obj.GetAllClassify(resourceType)
- if err != nil {
- msg = "获取公共分类列表失败"
- return
- }
- res = toClassifyTree(classifyList, 0)
- return
- }
- func PassKnowledgeResourceApprove(approveId int, adminId int) (msg string, err error) {
- approveItem, e := knowledge_approve.GetKnowledgeResourceApproveById(approveId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "审批不存在, 请刷新页面"
- err = e
- return
- }
- msg = "操作失败"
- return
- }
- if approveItem.State != KnowledgeResourceApproveStateApproving {
- msg = "审批状态有误, 请刷新页面"
- err = fmt.Errorf("审批状态有误, State: %d", approveItem.State)
- return
- }
- var ApprovePars []interface{}
- Approveconds := ` AND knowledge_resource_approve_id =? AND approve_user_id =? AND state =? `
- ApprovePars = append(ApprovePars, approveId, adminId, KnowledgeResourceApproveStateApproving)
- recordItem, er := knowledge_approve.GetKnowledgeResourceApproveRecordByCondition(Approveconds, ApprovePars)
- if er != nil {
- if utils.IsErrNoRow(er) {
- msg = "无权审批"
- err = er
- return
- }
- msg = "操作失败"
- return
- }
- // 查询审批流和审批流节点
- flowItem, e := knowledge_approve.GetKnowledgeResourceApproveFlowById(approveItem.FlowId)
- if e != nil {
- err = fmt.Errorf("获取审批流失败, Err: %s", e.Error())
- return
- }
- nodePars := make([]interface{}, 0)
- nodeCond := ` AND knowledge_resource_approve_flow_id =? AND curr_version =? `
- nodePars = append(nodePars, flowItem.KnowledgeResourceApproveFlowId, flowItem.CurrVersion)
- nodeItems, e := knowledge_approve.GetKnowledgeResourceApproveNodeByCondition(nodeCond, nodePars)
- 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]*knowledge_approve.KnowledgeResourceApproveNode)
- for _, v := range nodeItems {
- nodeMap[v.KnowledgeResourceApproveNodeId] = v
- }
- // 取出审批记录的节点
- currNodeItem := nodeMap[recordItem.NodeId]
- if currNodeItem == nil {
- err = fmt.Errorf("当前节点信息有误")
- return
- }
- currNode, e := FormatKnowledgeResourceApproveNode2Item(currNodeItem)
- if e != nil {
- err = fmt.Errorf("当前节点信息有误, Err: %s", e.Error())
- return
- }
- now := time.Now().Local()
- recordItem.State = KnowledgeResourceApproveStatePass
- recordItem.ApproveTime = now
- recordItem.ModifyTime = now
- recordItem.NodeState = KnowledgeResourceApproveStatePass
- 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 == 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(response.KnowledgeResourceApproveNodeUser) // 下一个审批人, 为nil则表示当前审批人即为最后
- for k, v := range currNode.Users {
- // 当前审批人
- if v.UserId == adminId && recordItem.ApproveUserSort == v.Sort {
- if (k + 1) < userLen {
- nextUser = currNode.Users[k+1]
- }
- }
- }
- // 当前节点下一个审批人, 生成下一个审批记录且return
- if nextUser.UserId > 0 {
- newRecord := new(knowledge_approve.KnowledgeResourceApproveRecord)
- newRecord.KnowledgeResourceApproveId = recordItem.KnowledgeResourceApproveId
- newRecord.State = KnowledgeResourceApproveStateApproving
- newRecord.NodeId = currNode.KnowledgeResourceApproveNodeId
- 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 = KnowledgeResourceApproveStateApproving
- if e = newRecord.Create(); e != nil {
- err = fmt.Errorf("生成审批记录失败, Err: %s", e.Error())
- return
- }
- // 推送审批消息
- go func() {
- messageItem := new(knowledge_approve.KnowledgeResourceApproveMessage)
- messageItem.SendUserId = approveItem.ApplyUserId
- messageItem.ReceiveUserId = nextUser.UserId
- messageItem.Content = "您有新的待办任务"
- messageItem.Remark = fmt.Sprintf("%s提交的【%s】需要您审批,请及时处理", approveItem.ApplyUserName, approveItem.KnowledgeResourceTitle)
- messageItem.KnowledgeResourceApproveId = approveItem.KnowledgeResourceApproveId
- messageItem.ApproveState = KnowledgeResourceApproveStateApproving
- messageItem.CreateTime = now
- messageItem.ModifyTime = now
- if e = messageItem.Create(); e != nil {
- utils.FileLog.Info(fmt.Sprintf("PassKnowledgeResourceApprove 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.KnowledgeResourceApproveId, approveItem.ApplyUserId, approveItem.ApplyUserName, approveItem.KnowledgeResourceTitle)
- return
- } else {
- // 最后一个节点
- lastApprove = true
- }
- }
- // 会签
- if currNode.ApproveType == NodeApproveTypeAll {
- // 查询其他审批人是否已审批
- otherCond := ` AND knowledge_resource_approve_id =? AND node_id =? AND approve_user_id <> ? `
- otherPars := make([]interface{}, 0)
- otherPars = append(otherPars, approveItem.KnowledgeResourceApproveId, recordItem.NodeId, adminId)
- otherRecords, e := knowledge_approve.GetKnowledgeResourceApproveRecordItemsByCondition(otherCond, otherPars)
- if e != nil {
- err = fmt.Errorf("获取节点审批记录失败, Err: %s", e.Error())
- return
- }
- otherPass := true
- for _, v := range otherRecords {
- if v.State != KnowledgeResourceApproveStatePass {
- 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.KnowledgeResourceApproveId, approveItem.ApplyUserId, approveItem.ApplyUserName, approveItem.KnowledgeResourceTitle)
- return
- }
- }
- // 或签
- if currNode.ApproveType == NodeApproveTypeAny {
- // 需检查一下审批的当前节点和记录的节点是否匹配, 不匹配可能是因为另外的审批人已通过, 所以此处应给提示
- // 前端也有做相应的判断,但是两个人同时进入审批详情页时就可能出现这种情况
- if approveItem.CurrNodeId != recordItem.NodeId {
- msg = "该节点已完成审批, 请刷新页面"
- return
- }
- if e = recordItem.Update(recordCols); e != nil {
- err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
- return
- }
- // 将该审批的同一个节点的记录标记为已审批
- if e = recordItem.UpdateNodeState(recordItem.KnowledgeResourceApproveId, 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.KnowledgeResourceApproveId, approveItem.ApplyUserId, approveItem.ApplyUserName, approveItem.KnowledgeResourceTitle)
- return
- }
- }
- // 最后一个审批, 更新审批记录、审批、报告状态、推送消息给申请人
- if lastApprove {
- if e = recordItem.Update(recordCols); e != nil {
- err = fmt.Errorf("更新审批记录状态失败, Err: %s", e.Error())
- return
- }
- approveItem.State = KnowledgeResourceApproveStatePass
- 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 = updateKnowledgeResourceApproveState(approveItem.KnowledgeResourceId, KnowledgeStatePass); e != nil {
- err = fmt.Errorf("更新报告审批状态失败, Err: %s", e.Error())
- return
- }
- go func() {
- obj := new(knowledge.KnowledgeResource)
- KnowledgeItem, e := obj.GetById(approveItem.KnowledgeResourceId)
- if e != nil && !utils.IsErrNoRow(e) {
- utils.FileLog.Info(fmt.Sprintf("PassKnowledgeResourceApprove update knowledge resource state err: %s", e.Error()))
- return
- }
- e = knowledgeSrv.EsAddOrEditKnowledgeResource(KnowledgeItem)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("PassKnowledgeResourceApprove update es err: %s", e.Error()))
- return
- }
- }()
- go func() {
- messageItem := new(knowledge_approve.KnowledgeResourceApproveMessage)
- messageItem.SendUserId = adminId
- messageItem.ReceiveUserId = approveItem.ApplyUserId
- messageItem.Content = "您提交的审批已通过"
- messageItem.Remark = fmt.Sprintf("您提交的【%s】已通过", approveItem.KnowledgeResourceTitle)
- messageItem.KnowledgeResourceApproveId = approveItem.KnowledgeResourceApproveId
- messageItem.ApproveState = KnowledgeResourceApproveStatePass
- messageItem.CreateTime = now
- messageItem.ModifyTime = now
- if e = messageItem.Create(); e != nil {
- utils.FileLog.Info(fmt.Sprintf("PassKnowledgeResourceApprove message err: %s", e.Error()))
- return
- }
- }()
- }
- return
- }
- func toClassifyTree(src []*knowledge.KnowledgeClassify, parentId int) (dst []*knowledge.KnowledgeClassifyItem) {
- for _, item := range src {
- if item.ParentId == parentId {
- tmp := new(knowledge.KnowledgeClassifyItem)
- tmp.KnowledgeClassify = *item
- tmp.Child = toClassifyTree(src, item.ClassifyId)
- dst = append(dst, tmp)
- }
- }
- return
- }
- // BuildNextNodeRecordAndMsg 生成下一个节点的审批记录并推送消息
- func BuildNextNodeRecordAndMsg(approveNodeItem *knowledge_approve.KnowledgeResourceApproveNode, approveId, sysAdminId int, sysAdminName, knowledgeTitle string) (err error) {
- if approveNodeItem == nil {
- err = fmt.Errorf("approve node nil")
- return
- }
- // 根据节点审批方式生成审批记录
- now := time.Now().Local()
- approveNode, e := FormatKnowledgeResourceApproveNode2Item(approveNodeItem)
- if e != nil {
- err = fmt.Errorf("FormatKnowledgeResourceApproveNode2Item err: %s", e.Error())
- return
- }
- if len(approveNode.Users) == 0 {
- err = fmt.Errorf("审批节点用户有误")
- return
- }
- newRecords := make([]*knowledge_approve.KnowledgeResourceApproveRecord, 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(knowledge_approve.KnowledgeResourceApproveRecord)
- r.KnowledgeResourceApproveId = approveId
- r.State = KnowledgeResourceApproveStateApproving
- r.NodeId = approveNode.KnowledgeResourceApproveNodeId
- 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 = KnowledgeResourceApproveStateApproving // 当前节点审批状态
- newRecords = append(newRecords, r)
- // 依次审批仅生成一条记录
- if approveNode.ApproveType == NodeApproveTypeRoll {
- break
- }
- }
- recordOb := new(knowledge_approve.KnowledgeResourceApproveRecord)
- if e = recordOb.CreateMulti(newRecords); e != nil {
- err = fmt.Errorf("生成节点审批记录失败, Err: %s", e.Error())
- return
- }
- // 推送审批消息
- go func() {
- messageOb := new(knowledge_approve.KnowledgeResourceApproveMessage)
- messages := make([]*knowledge_approve.KnowledgeResourceApproveMessage, 0)
- for _, v := range newRecords {
- m := new(knowledge_approve.KnowledgeResourceApproveMessage)
- m.SendUserId = sysAdminId
- m.ReceiveUserId = v.ApproveUserId
- m.Content = "您有新的待办任务"
- m.Remark = fmt.Sprintf("%s提交的【%s】需要您审批,请及时处理", sysAdminName, knowledgeTitle)
- m.KnowledgeResourceApproveId = approveId
- m.ApproveState = KnowledgeResourceApproveStateApproving
- 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
- }
- // updateKnowledgeResourceApproveState 更新知识资源审批状态
- func updateKnowledgeResourceApproveState(KnowledgeResourceId, state int) (err error) {
- // updateCols := []string{"ApproveId", "State", "ModifyTime"}
- updateCols := []string{"State", "ModifyTime"}
- obj := new(knowledge.KnowledgeResource)
- KnowledgeItem, e := obj.GetById(KnowledgeResourceId)
- if e != nil && !utils.IsErrNoRow(e) {
- err = fmt.Errorf("获取知识资源失败, Err: %s", e.Error())
- return
- }
- if KnowledgeItem != nil && KnowledgeItem.KnowledgeResourceId > 0 {
- KnowledgeItem.State = state
- KnowledgeItem.ModifyTime = time.Now().Local()
- if e = KnowledgeItem.Update(updateCols); e != nil {
- err = fmt.Errorf("更新知识资源审批状态失败, Err: %s", e.Error())
- return
- }
- }
- return
- }
- func ProcessingKnowledgeResourceApprove(adminId, classifyId, timeType, sortField, sortRule, startSize, pageSize int, adminName, startTime, endTime, keyword string) (respList []*response.KnowledgeResourceApproveItemOrmResp, respTotal int, msg string, err error) {
- cond := fmt.Sprintf(` AND a.%s = ? AND b.%s = ? AND a.%s = ?`, knowledge_approve.KnowledgeResourceApproveRecordCols.State, knowledge_approve.KnowledgeResourceApproveCols.State, knowledge_approve.KnowledgeResourceApproveRecordCols.ApproveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, KnowledgeResourceApproveStateApproving, KnowledgeResourceApproveStateApproving, adminId)
- order := ""
- // 筛选条件
- if classifyId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, knowledge_approve.KnowledgeResourceApproveCols.ClassifyId)
- pars = append(pars, classifyId)
- }
- if timeType <= 0 {
- timeType = 1
- }
- if timeType == 1 && startTime != "" && endTime != "" {
- _, e := time.Parse(utils.FormatDate, startTime)
- if e != nil {
- msg = "开始时间格式有误"
- err = e
- return
- }
- tmpEndTime, e := time.Parse(utils.FormatDate, endTime)
- if e != nil {
- msg = "结束时间格式有误"
- err = e
- return
- }
- tmpEndTime = tmpEndTime.AddDate(0, 0, 1)
- cond += fmt.Sprintf(` AND (b.%s BETWEEN ? AND ?)`, knowledge_approve.KnowledgeResourceApproveCols.CreateTime)
- pars = append(pars, startTime, tmpEndTime)
- }
- keyword = strings.TrimSpace(keyword)
- if keyword != "" {
- kw := fmt.Sprint("%", keyword, "%")
- cond += fmt.Sprintf(` AND b.%s LIKE ?`, knowledge_approve.KnowledgeResourceApproveCols.KnowledgeResourceTitle)
- pars = append(pars, kw)
- }
- if sortField > 0 && sortRule > 0 {
- orderField := timeField[sortField]
- if orderField == "" {
- msg = "时间排序字段有误"
- return
- }
- orderRule := orderRules[sortRule]
- if orderRule == "" {
- msg = "时间排序方式有误"
- return
- }
- order = fmt.Sprintf("%s %s", orderField, orderRule)
- }
- total, e := knowledge_approve.GetApprovingKnowledgeResourceApproveCount(cond, pars)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetApprovingKnowledgeResourceApproveCount err: %s", e.Error())
- return
- }
- list, e := knowledge_approve.GetApprovingKnowledgeResourceApprovePageList(cond, pars, order, startSize, pageSize)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetApprovingKnowledgeResourceApprovePageList err: %s", e.Error())
- return
- }
- respList = toKnowledgeResourceApproveItemOrmResp(list)
- respTotal = total
- return
- }
- // SolvedKnowledgeResourceApprove 已处理的审批
- func SolvedKnowledgeResourceApprove(adminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize int, adminName, startTime, endTime, keyword string) (respList []*response.KnowledgeResourceApproveItemOrmResp, respTotal int, msg string, err error) {
- cond := fmt.Sprintf(` AND a.%s = ? AND a.%s IN (?)`, knowledge_approve.KnowledgeResourceApproveRecordCols.ApproveUserId, knowledge_approve.KnowledgeResourceApproveRecordCols.NodeState)
- pars := make([]interface{}, 0)
- pars = append(pars, adminId, []int{KnowledgeResourceApproveStatePass, KnowledgeResourceApproveStateRefuse})
- order := ""
- // 筛选条件
- if classifyId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, knowledge_approve.KnowledgeResourceApproveCols.ClassifyId)
- pars = append(pars, classifyId)
- }
- if timeType > 0 && startTime != "" && endTime != "" {
- _, e := time.Parse(utils.FormatDate, startTime)
- if e != nil {
- msg = "开始时间格式有误"
- err = e
- return
- }
- tmpEndTime, e := time.Parse(utils.FormatDate, endTime)
- if e != nil {
- msg = "结束时间格式有误"
- err = e
- return
- }
- tmpEndTime = tmpEndTime.AddDate(0, 0, 1)
- cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, timeField[timeType])
- pars = append(pars, startTime, tmpEndTime)
- }
- keyword = strings.TrimSpace(keyword)
- if keyword != "" {
- kw := fmt.Sprint("%", keyword, "%")
- cond += fmt.Sprintf(` AND b.%s LIKE ?`, knowledge_approve.KnowledgeResourceApproveCols.KnowledgeResourceTitle)
- pars = append(pars, kw)
- }
- if sortField > 0 && sortRule > 0 {
- orderField := timeField[sortField]
- if orderField == "" {
- msg = "时间排序字段有误"
- return
- }
- orderRule := orderRules[sortRule]
- if orderRule == "" {
- msg = "时间排序方式有误"
- return
- }
- order = fmt.Sprintf("%s %s", orderField, orderRule)
- }
- if approveState > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, knowledge_approve.KnowledgeResourceApproveRecordCols.NodeState)
- pars = append(pars, approveState)
- }
- total, e := knowledge_approve.GetApprovedKnowledgeResourceApproveCount(cond, pars)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetApprovedKnowledgeResourceApproveCount err: %s", e.Error())
- return
- }
- list, e := knowledge_approve.GetApprovedKnowledgeResourceApprovePageList(cond, pars, order, startSize, pageSize)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetApprovedKnowledgeResourceApprovePageList err: %s", e.Error())
- return
- }
- for _, v := range list {
- // 这个时候的状态,用审批状态
- v.RecordState = v.NodeState
- v.ApproveTime = v.NodeApproveTime
- }
- respList = toKnowledgeResourceApproveItemOrmResp(list)
- respTotal = total
- return
- }
- func MyApplyKnowledgeResourceApproves(adminId, classifyId, timeType, sortField, sortRule, approveState, startSize, pageSize int, adminName, startTime, endTime, keyword string) (respList []*response.KnowledgeResourceApproveItemOrmResp, respTotal int, msg string, err error) {
- cond := fmt.Sprintf(` AND a.%s = ?`, knowledge_approve.KnowledgeResourceApproveCols.ApplyUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, adminId)
- order := ""
- // 筛选条件
- if classifyId > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, knowledge_approve.KnowledgeResourceApproveCols.ClassifyId)
- pars = append(pars, classifyId)
- }
- if timeType > 0 && startTime != "" && endTime != "" {
- _, e := time.Parse(utils.FormatDate, startTime)
- if e != nil {
- msg = "开始时间格式有误"
- err = e
- return
- }
- tmpEndTime, e := time.Parse(utils.FormatDate, endTime)
- if e != nil {
- msg = "结束时间格式有误"
- err = e
- return
- }
- tmpEndTimeStr := tmpEndTime.AddDate(0, 0, 1).Format(utils.FormatDate)
- cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, myTimeField[timeType])
- pars = append(pars, startTime, tmpEndTimeStr)
- }
- keyword = strings.TrimSpace(keyword)
- if keyword != "" {
- kw := fmt.Sprint("%", keyword, "%")
- cond += fmt.Sprintf(` AND a.%s LIKE ?`, knowledge_approve.KnowledgeResourceApproveCols.KnowledgeResourceTitle)
- pars = append(pars, kw)
- }
- if sortField > 0 && sortRule > 0 {
- orderField := myTimeField[sortField]
- if orderField == "" {
- msg = "时间排序字段有误"
- return
- }
- orderRule := orderRules[sortRule]
- if orderRule == "" {
- msg = "时间排序方式有误"
- return
- }
- order = fmt.Sprintf("%s %s", orderField, orderRule)
- }
- if approveState > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, knowledge_approve.KnowledgeResourceApproveRecordCols.State)
- pars = append(pars, approveState)
- }
- total, e := knowledge_approve.GetApplyKnowledgeResourceApproveCount(cond, pars)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetApplyKnowledgeResourceApproveCount err: %s", e.Error())
- return
- }
- respTotal = total
- list, e := knowledge_approve.GetApplyKnowledgeResourceApprovePageList(cond, pars, order, startSize, pageSize)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetApplyKnowledgeResourceApprovePageList err: %s", e.Error())
- return
- }
- respList = toKnowledgeResourceApproveItemOrmResp(list)
- return
- }
- func GetApproveDetail(approveId int) (resp *response.KnowledgeResourceApproveDetail, msg string, err error) {
- approveItem, e := knowledge_approve.GetKnowledgeResourceApproveById(approveId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "审批已被删除, 请刷新页面"
- err = e
- return
- }
- msg = "获取失败"
- err = fmt.Errorf("GetItemById err: %s", e.Error())
- return
- }
- // 审批信息
- detail := new(response.KnowledgeResourceApproveDetail)
- detail.Approve = new(response.KnowledgeResourceApproveDetailItem)
- detail.Approve.KnowledgeResourceApproveId = approveItem.KnowledgeResourceApproveId
- detail.Approve.State = approveItem.State
- detail.Approve.FlowId = approveItem.FlowId
- detail.Approve.FlowVersion = approveItem.FlowVersion
- detail.Approve.StartNodeId = approveItem.StartNodeId
- detail.Approve.CurrNodeId = approveItem.CurrNodeId
- detail.Approve.ApplyUserId = approveItem.ApplyUserId
- detail.Approve.ApplyUserName = approveItem.ApplyUserName
- detail.Approve.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.ApproveTime)
- detail.Approve.CreateTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.CreateTime)
- detail.Approve.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.ModifyTime)
- // 审批节点
- nodeOb := new(knowledge_approve.KnowledgeResourceApproveNode)
- nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, knowledge_approve.KnowledgeResourceApproveNodeCols.KnowledgeResourceApproveFlowId, knowledge_approve.KnowledgeResourceApproveNodeCols.CurrVersion)
- nodePars := make([]interface{}, 0)
- nodePars = append(nodePars, approveItem.FlowId, approveItem.FlowVersion)
- nodeItems, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetItemsByCondition err: %s", e.Error())
- return
- }
- // 审批记录
- recordOb := new(knowledge_approve.KnowledgeResourceApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ?`, knowledge_approve.KnowledgeResourceApproveRecordCols.KnowledgeResourceApproveId)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, approveItem.KnowledgeResourceApproveId)
- recordItems, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, fmt.Sprintf("%s DESC", knowledge_approve.KnowledgeResourceApproveRecordCols.ApproveTime))
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetItemsByCondition err: %s", e.Error())
- return
- }
- recordMap := make(map[string]*knowledge_approve.KnowledgeResourceApproveRecord)
- for _, v := range recordItems {
- k := fmt.Sprintf("%d-%d", v.NodeId, v.ApproveUserId)
- recordMap[k] = v
- }
- // 审批流节点详情
- detail.ApproveFlowNodes = make([]*response.KnowledgeResourceApproveDetailNodes, 0)
- for _, v := range nodeItems {
- t := new(response.KnowledgeResourceApproveDetailNodes)
- t.KnowledgeResourceApproveNodeId = v.KnowledgeResourceApproveNodeId
- t.KnowledgeResourceApproveFlowId = v.KnowledgeResourceApproveFlowId
- t.PrevNodeId = v.PrevNodeId
- t.NextNodeId = v.NextNodeId
- t.NodeType = v.NodeType
- t.ApproveType = v.ApproveType
- t.Users = make([]*response.KnowledgeResourceApproveDetailNodeUser, 0)
- us := make([]*response.KnowledgeResourceApproveNodeUserReq, 0)
- if v.Users != "" {
- e = json.Unmarshal([]byte(v.Users), &us)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("json.Unmarshal err: %s", e.Error())
- return
- }
- }
- for _, vu := range us {
- u := new(response.KnowledgeResourceApproveDetailNodeUser)
- u.UserType = vu.UserType
- u.UserId = vu.UserId
- u.UserName = vu.UserName
- u.Sort = vu.Sort
- // 审批记录
- k := fmt.Sprintf("%d-%d", v.KnowledgeResourceApproveNodeId, vu.UserId)
- r := recordMap[k]
- if r != nil {
- u.ApproveRecord = new(response.KnowledgeResourceApproveDetailNodeUserRecord)
- u.ApproveRecord.KnowledgeResourceApproveRecordId = r.KnowledgeResourceApproveRecordId
- u.ApproveRecord.State = r.State
- u.ApproveRecord.ApproveUserId = r.ApproveUserId
- u.ApproveRecord.ApproveUserName = r.ApproveUserName
- u.ApproveRecord.ApproveRemark = r.ApproveRemark
- u.ApproveRecord.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, r.ApproveTime)
- }
- 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 := make(map[int]string)
- obj := new(knowledge.KnowledgeClassify)
- cnClassify, e := obj.GetAllClassify(knowledge.KnowledgeResourceTypeOpinion)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetKnowledgeDashboardClassifyAllList err: %s", e.Error())
- return
- }
- for _, v := range cnClassify {
- cnClassifyIdName[v.ClassifyId] = v.ClassifyName
- }
- detail.Knowledge = new(response.KnowledgeResourceApproveDetailKnowledge)
- detail.Knowledge.KnowledgeResourceId = approveItem.KnowledgeResourceId
- detail.Knowledge.KnowledgeResourceTitle = approveItem.KnowledgeResourceTitle
- detail.Knowledge.KnowledgeClassify = cnClassifyIdName[approveItem.ClassifyId]
- resp = detail
- return
- }
- func KnowledgeResourceApproveRefuse(KnowledgeResourceApproveId, adminId int, approveRemark string) (msg string, err error) {
- approveItem, e := knowledge_approve.GetKnowledgeResourceApproveById(KnowledgeResourceApproveId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "审批不存在, 请刷新页面"
- err = e
- return
- }
- msg = "操作失败"
- err = fmt.Errorf("GetKnowledgeResourceApproveById err: %s", e.Error())
- return
- }
- if approveItem.State != KnowledgeResourceApproveStateApproving {
- msg = "审批状态有误, 请刷新页面"
- err = fmt.Errorf("审批状态有误, State: %d", approveItem.State)
- return
- }
- // 校验审批记录和审批
- recordOb := new(knowledge_approve.KnowledgeResourceApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ?`, knowledge_approve.KnowledgeResourceApproveRecordCols.KnowledgeResourceApproveId, knowledge_approve.KnowledgeResourceApproveRecordCols.ApproveUserId, knowledge_approve.KnowledgeResourceApproveRecordCols.State)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, approveItem.KnowledgeResourceApproveId, adminId, KnowledgeResourceApproveStateApproving)
- recordItem, e := recordOb.GetItemByCondition(recordCond, recordPars, "")
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "无权审批"
- err = e
- return
- }
- msg = "操作失败"
- err = fmt.Errorf("GetItemByCondition err: %s", e.Error())
- return
- }
- // 驳回审批
- if e = refuseKnowledgeResourceApprove(approveItem, recordItem, approveRemark, adminId); e != nil {
- msg = "操作失败"
- err = fmt.Errorf("RefuseKnowledgeResourceApprove err: %s", e.Error())
- return
- }
- return
- }
- // refuseKnowledgeResourceApprove 驳回审批
- func refuseKnowledgeResourceApprove(approveItem *knowledge_approve.KnowledgeResourceApprove, recordItem *knowledge_approve.KnowledgeResourceApproveRecord, 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 = KnowledgeResourceApproveStateRefuse
- recordItem.ApproveRemark = approveRemark
- recordItem.ApproveTime = now
- recordItem.ModifyTime = now
- recordItem.NodeState = KnowledgeResourceApproveStateRefuse
- 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.KnowledgeResourceApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); e != nil {
- err = fmt.Errorf("更新同一节点的其他审批记录状态失败, Err: %s", e.Error())
- return
- }
- // 驳回-更新审批, 报告状态, 推送消息
- approveItem.State = KnowledgeResourceApproveStateRefuse
- 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 := updateKnowledgeResourceApproveState(approveItem.KnowledgeResourceId, KnowledgeStateRefused); e != nil {
- err = fmt.Errorf("更新报告状态失败, Err: %s", e.Error())
- return
- }
- // 推送驳回消息给申请人
- go func() {
- messageItem := new(knowledge_approve.KnowledgeResourceApproveMessage)
- messageItem.SendUserId = sysAdminId
- messageItem.ReceiveUserId = approveItem.ApplyUserId
- messageItem.Content = "您提交的审批被驳回"
- messageItem.Remark = fmt.Sprintf("您提交的【%s】已被驳回", approveItem.KnowledgeResourceTitle)
- messageItem.KnowledgeResourceApproveId = approveItem.KnowledgeResourceApproveId
- messageItem.ApproveState = KnowledgeResourceApproveStateRefuse
- messageItem.CreateTime = now
- messageItem.ModifyTime = now
- if e := messageItem.Create(); e != nil {
- utils.FileLog.Info(fmt.Sprintf("ApproveKnowledge message err: %s", e.Error()))
- return
- }
- }()
- return
- }
- func KnowledgeResourceApproveCancel(KnowledgeResourceApproveId, adminId int, adminName string) (msg string, err error) {
- approveItem, e := knowledge_approve.GetKnowledgeResourceApproveById(KnowledgeResourceApproveId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "审批已被删除, 请刷新页面"
- err = e
- return
- }
- msg = "操作失败"
- err = fmt.Errorf("GetKnowledgeResourceApproveById err: %s", e.Error())
- return
- }
- if approveItem.ApplyUserId != adminId {
- msg = "非申请人不可撤销"
- err = fmt.Errorf("非申请人不可撤销")
- return
- }
- // 撤销审批
- e = cancelKnowledgeResourceApprove(approveItem.KnowledgeResourceId, approveItem.KnowledgeResourceApproveId, adminId, adminName)
- if e != nil {
- msg = "操作失败"
- err = fmt.Errorf("cancelKnowledgeResourceApprove err: %s", e.Error())
- return
- }
- return
- }
- // cancelKnowledgeResourceApprove 撤回审批
- func cancelKnowledgeResourceApprove(knowledgeId, approveId, sysAdminId int, sysAdminName string) (err error) {
- // 默认内部审批, 如果是走的第三方审批, 那么仅修改状态
- // confMap, e := models.GetBusinessConf()
- // if e != nil {
- // err = fmt.Errorf("GetBusinessConf err: %s", e.Error())
- // return
- // }
- // openApprove := t
- // if !openApprove {
- // //err = fmt.Errorf("未开启审批")
- // return
- // }
- // 修改审批信息状态
- approveItem, e := knowledge_approve.GetKnowledgeResourceApproveById(approveId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- err = e
- return
- }
- err = fmt.Errorf("approve GetItemById err: %s", e.Error())
- return
- }
- if approveItem.State == KnowledgeResourceApproveStateCancel {
- return
- }
- approveItem.State = KnowledgeResourceApproveStateCancel
- approveItem.ModifyTime = time.Now()
- cols := []string{"State", "ModifyTime"}
- if e = approveItem.Update(cols); e != nil {
- err = fmt.Errorf("approve Update err: %s", e.Error())
- return
- }
- // 修改报告状态
- e = updateKnowledgeResourceApproveState(knowledgeId, KnowledgeStateUnpublished)
- if e != nil {
- err = fmt.Errorf("更新报告审批撤回失败, Err: %s", e.Error())
- return
- }
- // 推送到Es
- go func() {
- obj := new(knowledge.KnowledgeResource)
- KnowledgeItem, e := obj.GetById(approveItem.KnowledgeResourceId)
- if e != nil && !utils.IsErrNoRow(e) {
- utils.FileLog.Info(fmt.Sprintf("PassKnowledgeResourceApprove update knowledge resource state err: %s", e.Error()))
- return
- }
- e = knowledgeSrv.EsAddOrEditKnowledgeResource(KnowledgeItem)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("PassKnowledgeResourceApprove update es err: %s", e.Error()))
- return
- }
- }()
- // 推送撤回消息
- go func() {
- recordOb := new(knowledge_approve.KnowledgeResourceApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ?`, knowledge_approve.KnowledgeResourceApproveRecordCols.KnowledgeResourceApproveId)
- 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(knowledge_approve.KnowledgeResourceApproveMessage)
- messages := make([]*knowledge_approve.KnowledgeResourceApproveMessage, 0)
- for _, v := range recordItems {
- m := new(knowledge_approve.KnowledgeResourceApproveMessage)
- m.SendUserId = sysAdminId
- m.ReceiveUserId = v.ApproveUserId
- m.Content = fmt.Sprintf("%s提交的【%s】已撤回", sysAdminName, approveItem.KnowledgeResourceTitle)
- m.KnowledgeResourceApproveId = approveId
- m.ApproveState = KnowledgeResourceApproveStateCancel
- 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("CancelKnowledgeResourceApprove messages err: %s", e.Error()))
- return
- }
- }()
- return
- }
- // CheckKnowledgeOpenApprove 校验报告是否开启了审批流
- func CheckKnowledgeOpenApprove(classifyId 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.BusinessConfIsBIApprove]]
- // 查询对应分类是否有审批流
- flowOb := new(knowledge_approve.KnowledgeResourceApproveFlow)
- flowCond := fmt.Sprintf(` AND %s = ?`, knowledge_approve.KnowledgeResourceApproveFlowCols.ClassifyId)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, classifyId)
- flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
- if e != nil {
- if utils.IsErrNoRow(e) {
- opening = false
- return
- }
- err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
- return
- }
- // 开启审批/有审批流
- if flowItem != nil {
- opening = true
- return
- }
- return
- }
- // SubmitKnowledgeResourceApprove 提交审批
- func SubmitKnowledgeResourceApprove(KnowledgeResourceId int, KnowledgeResourceTitle string, classifyId int, sysAdminId int, sysAdminName string) (approveId int, msg 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.BusinessConfIsBIApprove]]
- // if !openApprove {
- // err = fmt.Errorf("未开启审批")
- // return
- // }
- // 查询审批流
- flowOb := new(knowledge_approve.KnowledgeResourceApproveFlow)
- flowCond := fmt.Sprintf(` AND %s = ?`, knowledge_approve.KnowledgeResourceApproveFlowCols.ClassifyId)
- flowPars := make([]interface{}, 0)
- flowPars = append(flowPars, classifyId)
- flowItem, e := flowOb.GetItemByCondition(flowCond, flowPars, "")
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "该分类未设置审批流"
- return
- }
- err = fmt.Errorf("ApproveFlow GetItemByCondition err: %s", e.Error())
- return
- }
- // 查询审批节点
- nodeOb := new(knowledge_approve.KnowledgeResourceApproveNode)
- nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, knowledge_approve.KnowledgeResourceApproveNodeCols.KnowledgeResourceApproveFlowId, knowledge_approve.KnowledgeResourceApproveNodeCols.CurrVersion)
- nodePars := make([]interface{}, 0)
- nodePars = append(nodePars, flowItem.KnowledgeResourceApproveFlowId, 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 {
- msg = "无审批节点"
- err = fmt.Errorf("无审批节点")
- return
- }
- // 取出首个节点
- firstNodeItem := new(knowledge_approve.KnowledgeResourceApproveNode)
- for _, v := range nodeItems {
- if v.PrevNodeId == 0 {
- firstNodeItem = v
- continue
- }
- }
- if firstNodeItem == nil {
- err = fmt.Errorf("首个审批节点有误")
- return
- }
- // 审批信息
- now := time.Now().Local()
- newApprove := new(knowledge_approve.KnowledgeResourceApprove)
- newApprove.KnowledgeResourceId = KnowledgeResourceId
- newApprove.KnowledgeResourceTitle = KnowledgeResourceTitle
- newApprove.ClassifyId = classifyId
- newApprove.State = KnowledgeResourceApproveStateApproving
- newApprove.FlowId = flowItem.KnowledgeResourceApproveFlowId
- newApprove.FlowVersion = flowItem.CurrVersion
- newApprove.StartNodeId = firstNodeItem.KnowledgeResourceApproveNodeId
- newApprove.CurrNodeId = firstNodeItem.KnowledgeResourceApproveNodeId
- 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.KnowledgeResourceApproveId
- // 生成节点审批记录
- err = BuildNextNodeRecordAndMsg(firstNodeItem, newApprove.KnowledgeResourceApproveId, sysAdminId, sysAdminName, newApprove.KnowledgeResourceTitle)
- return
- }
- func toKnowledgeResourceApproveItemOrmResp(src []*knowledge_approve.KnowledgeResourceApproveItemOrm) (res []*response.KnowledgeResourceApproveItemOrmResp) {
- res = make([]*response.KnowledgeResourceApproveItemOrmResp, 0)
- for _, v := range src {
- r := new(response.KnowledgeResourceApproveItemOrmResp)
- r.KnowledgeResourceApproveId = v.KnowledgeResourceApproveId
- r.KnowledgeResourceApproveRecordId = v.KnowledgeResourceApproveRecordId
- r.KnowledgeResourceId = v.KnowledgeResourceId
- r.KnowledgeResourceTitle = v.KnowledgeResourceTitle
- r.ClassifyId = v.ClassifyId
- r.State = v.State
- r.RecordState = v.RecordState
- r.FlowId = v.FlowId
- r.FlowVersion = v.FlowVersion
- r.StartNodeId = v.StartNodeId
- r.CurrNodeId = v.CurrNodeId
- r.ApplyUserId = v.ApplyUserId
- r.ApplyUserName = v.ApplyUserName
- r.ApproveRemark = v.ApproveRemark
- r.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, v.ApproveTime)
- r.HandleTime = utils.TimeTransferString(utils.FormatDateTime, v.HandleTime)
- r.CreateTime = utils.TimeTransferString(utils.FormatDateTime, v.CreateTime)
- r.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, v.ModifyTime)
- r.NodeState = v.NodeState
- res = append(res, r)
- }
- return
- }
- func GetKnowledgeClassifyAll() (list []*knowledge.KnowledgeClassify, msg string, err error) {
- obj := new(knowledge.KnowledgeClassify)
- ClassifyList, e := obj.GetAllClassify(knowledge.KnowledgeResourceTypeOpinion)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("GetKnowledgeDashboardClassifyAllList err: %s", e.Error())
- return
- }
- list = ClassifyList
- return
- }
- func CheckHasApprovingKnowledge() (ok bool, err error) {
- count, err := knowledge_approve.GetKnowledgeResourceApproveCountByState(KnowledgeResourceApproveStateApproving)
- if err != nil {
- return
- }
- if count > 0 {
- ok = true
- }
- return
- }
- func GetKnowledgeApproveIdByKnowledgeResourceId(knowledgeResourceId int) (approveId int, err error) {
- approveItem, err := knowledge_approve.GetKnowledgeApproveByKnowledgeId(knowledgeResourceId)
- if err != nil {
- return
- }
- approveId = approveItem.KnowledgeResourceApproveId
- return
- }
|