123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package flow
- import (
- "encoding/json"
- "errors"
- "hongze/hongze_mobile_admin/models/tables/admin"
- "hongze/hongze_mobile_admin/models/tables/approval_flow"
- "hongze/hongze_mobile_admin/models/tables/approval_flow_node"
- "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
- "strings"
- )
- //获取审批工作流(基础)
- func GetApprovalFlow(flowId int) (approvalFlow *approval_flow.ApprovalFlowItem, err error) {
- approvalFlow, err = approval_flow.GetByFlowItemId(flowId)
- if err != nil {
- err = errors.New("查询审批流程失败:Err:" + err.Error())
- return
- }
- flowNodeList := make([]*approval_flow_node.ApprovalFlowNodeList, 0)
- approvalFlowNodeList, err := approval_flow_node.GetListByFlowId(approvalFlow.FlowId, approvalFlow.CurrVersion)
- if err != nil {
- err = errors.New("查询审批节点失败:Err:" + err.Error())
- return
- }
- for _, approvalFlowNode := range approvalFlowNodeList {
- userList, tmpErr := getAdminListByUser(approvalFlowNode.User, approvalFlow.ProductId)
- if tmpErr != nil {
- err = errors.New("获取审批人失败:Err:" + tmpErr.Error())
- return
- }
- for _, user := range userList {
- userInfo := approval_flow_node.User{
- AdminId: user.AdminId,
- Name: user.RealName,
- RoleTypeCode: user.RoleTypeCode,
- Mobile: user.Mobile,
- }
- approvalFlowNode.UserList = append(approvalFlowNode.UserList, userInfo)
- }
- if len(approvalFlowNode.UserList) > 0 {
- flowNodeList = append(flowNodeList, approvalFlowNode)
- }
- }
- approvalFlow.NodeList = flowNodeList
- return
- }
- //格式化数据返回
- func FormatApprovalFlow(approvalFlow *approval_flow.ApprovalFlowItem) (list [][]contract_approval_record.ContractApprovalRecord, err error) {
- for _, node := range approvalFlow.NodeList {
- approvalRecordList := make([]contract_approval_record.ContractApprovalRecord, 0)
- for _, user := range node.UserList {
- approvalRecord := contract_approval_record.ContractApprovalRecord{
- Status: "待审批",
- ApproveRoleTypeCode: user.RoleTypeCode,
- ApproveUserId: user.AdminId,
- ApproveUserName: user.Name,
- NodeId: node.NodeId,
- NodeType: node.NodeType,
- PrevNodeId: node.PrevNodeId,
- NextNodeId: node.NextNodeId,
- AuditType: node.AuditType,
- CreateTime: node.CreateTime,
- }
- approvalRecordList = append(approvalRecordList, approvalRecord)
- }
- list = append(list, approvalRecordList)
- }
- return
- }
- type NodeUser struct {
- UserType string `json:"user_type" description:"用户类型,枚举值,user:指定人,manager:主管,role:角色"`
- User string `json:"user" description:"所属用户,多个用英文,隔开;用户类型为user代表指定人id,manager代表几级主管,role代表角色类型"`
- }
- //获取审批人信息
- func getAdminListByUser(userStrList string, productId int) (adminList []*admin.Admin, err error) {
- nodeUserList := make([]NodeUser, 0)
- err = json.Unmarshal([]byte(userStrList), &nodeUserList)
- if err != nil {
- return
- }
- firstAdminList := make([]*admin.Admin, 0)
- for _, userInfo := range nodeUserList {
- userType := userInfo.UserType
- user := userInfo.User
- tmpAdminList := make([]*admin.Admin, 0)
- switch userType {
- case "user":
- tmpAdminList, err = admin.GetAdminListByIds(user)
- case "manager":
- roleTypeCode := ``
- if productId == 1 {
- roleTypeCode = `ficc_admin`
- } else if productId == 1 {
- roleTypeCode = `rai_admin`
- }
- if roleTypeCode == `` {
- err = errors.New("找不到对应的主管")
- return
- }
- tmpAdminList, err = admin.GetAdminListByRoleCode(roleTypeCode)
- case "role": //角色类型
- roleSlice := strings.Split(user, ",")
- for _, roleId := range roleSlice {
- list, tmpErr := admin.GetAdminListByRoleId(roleId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- tmpAdminList = append(tmpAdminList, list...)
- }
- }
- firstAdminList = append(firstAdminList, tmpAdminList...)
- }
- userMap := make(map[int]*admin.Admin)
- for _, adminInfo := range firstAdminList {
- //如果不在,那么就插入用户列表,避免同一个节点重复添加用户
- if _, ok := userMap[adminInfo.AdminId]; !ok {
- adminList = append(adminList, adminInfo)
- userMap[adminInfo.AdminId] = adminInfo
- }
- }
- return
- }
- //获取审批单的审批流程
- func GetNewApprovalFlow(contractApprovalId int) (flowNodeListResp [][]*contract_approval_record.ContractApprovalRecord, err error) {
- list, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalId(contractApprovalId)
- nodeMap := make(map[int][]*contract_approval_record.ContractApprovalRecord)
- nodeIdList := make([]int, 0)
- for _, contractApprovalRecord := range list {
- if _, ok := nodeMap[contractApprovalRecord.NodeId]; ok {
- nodeMap[contractApprovalRecord.NodeId] = append(nodeMap[contractApprovalRecord.NodeId], contractApprovalRecord)
- } else {
- tmp := make([]*contract_approval_record.ContractApprovalRecord, 0)
- tmp = append(tmp, contractApprovalRecord)
- nodeMap[contractApprovalRecord.NodeId] = tmp
- nodeIdList = append(nodeIdList, contractApprovalRecord.NodeId)
- }
- }
- for _, nodeId := range nodeIdList {
- flowNodeListResp = append(flowNodeListResp, nodeMap[nodeId])
- }
- return
- }
|