flow.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package flow
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "hongze/hongze_mobile_admin/models/tables/admin"
  6. "hongze/hongze_mobile_admin/models/tables/approval_flow"
  7. "hongze/hongze_mobile_admin/models/tables/approval_flow_node"
  8. "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
  9. "strings"
  10. )
  11. //获取审批工作流(基础)
  12. func GetApprovalFlow(flowId int) (approvalFlow *approval_flow.ApprovalFlowItem, err error) {
  13. approvalFlow, err = approval_flow.GetByFlowItemId(flowId)
  14. if err != nil {
  15. err = errors.New("查询审批流程失败:Err:" + err.Error())
  16. return
  17. }
  18. flowNodeList := make([]*approval_flow_node.ApprovalFlowNodeList, 0)
  19. approvalFlowNodeList, err := approval_flow_node.GetListByFlowId(approvalFlow.FlowId, approvalFlow.CurrVersion)
  20. if err != nil {
  21. err = errors.New("查询审批节点失败:Err:" + err.Error())
  22. return
  23. }
  24. for _, approvalFlowNode := range approvalFlowNodeList {
  25. userList, tmpErr := getAdminListByUser(approvalFlowNode.User, approvalFlow.ProductId)
  26. if tmpErr != nil {
  27. err = errors.New("获取审批人失败:Err:" + tmpErr.Error())
  28. return
  29. }
  30. for _, user := range userList {
  31. userInfo := approval_flow_node.User{
  32. AdminId: user.AdminId,
  33. Name: user.RealName,
  34. RoleTypeCode: user.RoleTypeCode,
  35. Mobile: user.Mobile,
  36. }
  37. approvalFlowNode.UserList = append(approvalFlowNode.UserList, userInfo)
  38. }
  39. if len(approvalFlowNode.UserList) > 0 {
  40. flowNodeList = append(flowNodeList, approvalFlowNode)
  41. }
  42. }
  43. approvalFlow.NodeList = flowNodeList
  44. return
  45. }
  46. //格式化数据返回
  47. func FormatApprovalFlow(approvalFlow *approval_flow.ApprovalFlowItem) (list [][]contract_approval_record.ContractApprovalRecord, err error) {
  48. for _, node := range approvalFlow.NodeList {
  49. approvalRecordList := make([]contract_approval_record.ContractApprovalRecord, 0)
  50. for _, user := range node.UserList {
  51. approvalRecord := contract_approval_record.ContractApprovalRecord{
  52. Status: "待审批",
  53. ApproveRoleTypeCode: user.RoleTypeCode,
  54. ApproveUserId: user.AdminId,
  55. ApproveUserName: user.Name,
  56. NodeId: node.NodeId,
  57. NodeType: node.NodeType,
  58. PrevNodeId: node.PrevNodeId,
  59. NextNodeId: node.NextNodeId,
  60. AuditType: node.AuditType,
  61. CreateTime: node.CreateTime,
  62. }
  63. approvalRecordList = append(approvalRecordList, approvalRecord)
  64. }
  65. list = append(list, approvalRecordList)
  66. }
  67. return
  68. }
  69. type NodeUser struct {
  70. UserType string `json:"user_type" description:"用户类型,枚举值,user:指定人,manager:主管,role:角色"`
  71. User string `json:"user" description:"所属用户,多个用英文,隔开;用户类型为user代表指定人id,manager代表几级主管,role代表角色类型"`
  72. }
  73. //获取审批人信息
  74. func getAdminListByUser(userStrList string, productId int) (adminList []*admin.Admin, err error) {
  75. nodeUserList := make([]NodeUser, 0)
  76. err = json.Unmarshal([]byte(userStrList), &nodeUserList)
  77. if err != nil {
  78. return
  79. }
  80. firstAdminList := make([]*admin.Admin, 0)
  81. for _, userInfo := range nodeUserList {
  82. userType := userInfo.UserType
  83. user := userInfo.User
  84. tmpAdminList := make([]*admin.Admin, 0)
  85. switch userType {
  86. case "user":
  87. tmpAdminList, err = admin.GetAdminListByIds(user)
  88. case "manager":
  89. roleTypeCode := ``
  90. if productId == 1 {
  91. roleTypeCode = `ficc_admin`
  92. } else if productId == 1 {
  93. roleTypeCode = `rai_admin`
  94. }
  95. if roleTypeCode == `` {
  96. err = errors.New("找不到对应的主管")
  97. return
  98. }
  99. tmpAdminList, err = admin.GetAdminListByRoleCode(roleTypeCode)
  100. case "role": //角色类型
  101. roleSlice := strings.Split(user, ",")
  102. for _, roleId := range roleSlice {
  103. list, tmpErr := admin.GetAdminListByRoleId(roleId)
  104. if tmpErr != nil {
  105. err = tmpErr
  106. return
  107. }
  108. tmpAdminList = append(tmpAdminList, list...)
  109. }
  110. }
  111. firstAdminList = append(firstAdminList, tmpAdminList...)
  112. }
  113. userMap := make(map[int]*admin.Admin)
  114. for _, adminInfo := range firstAdminList {
  115. //如果不在,那么就插入用户列表,避免同一个节点重复添加用户
  116. if _, ok := userMap[adminInfo.AdminId]; !ok {
  117. adminList = append(adminList, adminInfo)
  118. userMap[adminInfo.AdminId] = adminInfo
  119. }
  120. }
  121. return
  122. }
  123. //获取审批单的审批流程
  124. func GetNewApprovalFlow(contractApprovalId int) (flowNodeListResp [][]*contract_approval_record.ContractApprovalRecord, err error) {
  125. list, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalId(contractApprovalId)
  126. nodeMap := make(map[int][]*contract_approval_record.ContractApprovalRecord)
  127. nodeIdList := make([]int, 0)
  128. for _, contractApprovalRecord := range list {
  129. if _, ok := nodeMap[contractApprovalRecord.NodeId]; ok {
  130. nodeMap[contractApprovalRecord.NodeId] = append(nodeMap[contractApprovalRecord.NodeId], contractApprovalRecord)
  131. } else {
  132. tmp := make([]*contract_approval_record.ContractApprovalRecord, 0)
  133. tmp = append(tmp, contractApprovalRecord)
  134. nodeMap[contractApprovalRecord.NodeId] = tmp
  135. nodeIdList = append(nodeIdList, contractApprovalRecord.NodeId)
  136. }
  137. }
  138. for _, nodeId := range nodeIdList {
  139. flowNodeListResp = append(flowNodeListResp, nodeMap[nodeId])
  140. }
  141. return
  142. }