/// <summary>
        /// 当前登录人是否有权限审核并获取下一次审核权限实体
        /// </summary>
        /// <param name="currUser">当前登录人</param>
        /// <param name="state">是否有权限审核 1:能审核 0 :不能审核</param>
        /// <param name="moduleName">模块名称</param>
        /// <param name="createdeptid">创建人部门ID</param>
        /// <returns>null-当前为最后一次审核,ManyPowerCheckEntity:下一次审核权限实体</returns>
        public ManyPowerCheckEntity CheckAuditPower(Operator currUser, out string state, string moduleName, string createdeptid, out string curFlowId)
        {
            ManyPowerCheckEntity   nextCheck  = null;//下一步审核
            IManyPowerCheckService powerCheck = new ManyPowerCheckService();
            //获取流程节点配置
            List <ManyPowerCheckEntity> powerList = powerCheck.GetListBySerialNum(currUser.OrganizeCode, moduleName);

            if (powerList.Count > 0)
            {
                DepartmentEntity department = new DepartmentService().GetEntity(createdeptid);
                foreach (var item in powerList)
                {
                    if (item.CHECKDEPTCODE == "-3" || item.CHECKDEPTID == "-3")
                    {
                        string executedept = department.DepartmentId;
                        //powerList[i].CHECKDEPTCODE = new DepartmentService().GetEntity(ourEngineer.FindEntity(outengineerid).ENGINEERLETDEPTID).EnCode;
                        //powerList[i].CHECKDEPTID = new DepartmentService().GetEntity(ourEngineer.FindEntity(outengineerid).ENGINEERLETDEPTID).DepartmentId;
                        switch (item.ChooseDeptRange) //判断部门范围
                        {
                        case "0":
                            item.CHECKDEPTID   = executedept;
                            item.CHECKDEPTNAME = department.FullName;
                            break;

                        case "1":
                            var dept = deptservice.GetEntity(executedept);
                            while (dept.Nature != "部门" && dept.Nature != "厂级")
                            {
                                dept = deptservice.GetEntity(dept.ParentId);
                            }
                            item.CHECKDEPTID   = dept.DepartmentId;
                            item.CHECKDEPTNAME = dept.FullName;
                            break;

                        case "2":
                            var dept1 = deptservice.GetEntity(executedept);
                            while (dept1.Nature != "部门" && dept1.Nature != "厂级")
                            {
                                dept1 = deptservice.GetEntity(dept1.ParentId);
                            }
                            item.CHECKDEPTID   = (dept1.DepartmentId + "," + executedept).Trim(',');
                            item.CHECKDEPTNAME = (dept1.FullName + "," + department.FullName).Trim();
                            break;

                        default:
                            item.CHECKDEPTID   = executedept;
                            item.CHECKDEPTNAME = department.FullName;
                            break;
                        }

                        ////查询 执行部门
                        //item.CHECKDEPTCODE = new DepartmentService().GetEntity(createdeptid).EnCode;
                        //item.CHECKDEPTID = new DepartmentService().GetEntity(createdeptid).DepartmentId;
                    }
                }

                List <ManyPowerCheckEntity> checkPower = new List <ManyPowerCheckEntity>();

                //登录人是否有审核权限--有审核权限直接审核通过
                for (int i = 0; i < powerList.Count; i++)
                {
                    if (powerList[i].CHECKDEPTID == currUser.DeptId)
                    {
                        var rolelist = currUser.RoleName.Split(',');
                        for (int j = 0; j < rolelist.Length; j++)
                        {
                            if (powerList[i].CHECKROLENAME.Contains(rolelist[j]))
                            {
                                checkPower.Add(powerList[i]);
                                break;
                            }
                        }
                    }
                }

                powerList.GroupBy(t => t.SERIALNUM).ToList().Count();
                if (checkPower.Count > 0)
                {
                    state = "1";
                    ManyPowerCheckEntity check = checkPower.Last();//当前
                    curFlowId = check.ID;
                    for (int i = 0; i < powerList.Count; i++)
                    {
                        if (check.ID == powerList[i].ID)
                        {
                            if ((i + 1) >= powerList.Count)
                            {
                                nextCheck = null;
                            }
                            else
                            {
                                nextCheck = powerList[i + 1];
                            }
                        }
                    }
                }
                else
                {
                    state     = "0";
                    curFlowId = "";
                    nextCheck = powerList.First();
                }

                if (nextCheck != null)
                {
                    //当前审核序号下的对应集合
                    var serialList = powerList.Where(p => p.SERIALNUM == nextCheck.SERIALNUM);
                    //集合记录大于1,则表示存在并行审核(审查)的情况
                    if (serialList.Count() > 1)
                    {
                        ManyPowerCheckEntity slastEntity = new ManyPowerCheckEntity();
                        slastEntity = serialList.LastOrDefault();
                        nextCheck   = slastEntity;
                    }
                }

                return(nextCheck);
            }
            else
            {
                state     = "0";
                curFlowId = "";
                return(nextCheck);
            }
        }
        /// <summary>
        /// 当前登录人是否有权限审核并获取下一次审核权限实体
        /// </summary>
        /// <param name="currUser">当前登录人</param>
        /// <param name="state">是否有权限审核 1:能审核 0 :不能审核</param>
        /// <param name="moduleName">模块名称</param>
        /// <param name="createdeptid">创建人部门ID</param>
        /// <returns>null-当前为最后一次审核,ManyPowerCheckEntity:下一次审核权限实体</returns>
        public ManyPowerCheckEntity CheckAuditPower(Operator currUser, out string state, string moduleName, string createdeptid, string applyId = "")
        {
            ManyPowerCheckEntity        nextCheck  = null;//下一步审核
            IManyPowerCheckService      powerCheck = new ManyPowerCheckService();
            List <ManyPowerCheckEntity> powerList  = powerCheck.GetListBySerialNum(currUser.OrganizeCode, moduleName);
            bool   hasRight = false;
            string deptId   = "-1";
            ThreePeopleCheckEntity entity = new ThreePeopleCheckEntity();

            if (!string.IsNullOrEmpty(applyId))
            {
                deptId = createdeptid;
                entity = BaseRepository().FindEntity(applyId);
                if (entity != null)
                {
                    if (!string.IsNullOrEmpty(entity.NodeId))
                    {
                        ManyPowerCheckEntity mp = powerCheck.GetEntity(entity.NodeId);
                        if (mp != null)
                        {
                            if (mp.CHECKDEPTID == "-1")
                            {
                                if (entity.ApplyType == "内部")
                                {
                                    deptId = mp.CHECKDEPTID = entity.BelongDeptId;
                                }
                                else
                                {
                                    string    sql = string.Format("select ENGINEERLETDEPTID from EPG_OUTSOURINGENGINEER t where id='{0}'", entity.ProjectId);
                                    DataTable dt  = BaseRepository().FindTable(sql);
                                    if (dt.Rows.Count > 0)
                                    {
                                        deptId = mp.CHECKDEPTID = dt.Rows[0][0].ToString();
                                    }
                                }
                                if (mp.CHECKDEPTID == currUser.DeptId)
                                {
                                    var rolelist = currUser.RoleName.Split(',');
                                    for (int j = 0; j < rolelist.Length; j++)
                                    {
                                        if (mp.CHECKROLENAME.Contains(rolelist[j]))
                                        {
                                            hasRight = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            else if (mp.CHECKDEPTID == "-3")
                            {
                                deptId = entity.CreateUserDeptId;
                                if (entity.CreateUserDeptId == currUser.DeptId)
                                {
                                    var rolelist = currUser.RoleName.Split(',');
                                    for (int j = 0; j < rolelist.Length; j++)
                                    {
                                        if (mp.CHECKROLENAME.Contains(rolelist[j]))
                                        {
                                            hasRight = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                deptId = mp.CHECKDEPTID;
                                if (mp.CHECKDEPTID == currUser.DeptId)
                                {
                                    var rolelist = currUser.RoleName.Split(',');
                                    for (int j = 0; j < rolelist.Length; j++)
                                    {
                                        if (mp.CHECKROLENAME.Contains(rolelist[j]))
                                        {
                                            hasRight = true;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    hasRight = false;
                                }
                            }
                        }
                    }
                }
            }
            if (powerList.Count > 0)
            {
                var dept = new DepartmentService().GetEntity(deptId);
                if (dept != null)
                {
                    foreach (var item in powerList)
                    {
                        if (item.CHECKDEPTID == "-3" || item.CHECKDEPTID == "-1")
                        {
                            item.CHECKDEPTID   = deptId;
                            item.CHECKDEPTCODE = dept.DeptCode;
                            item.CHECKDEPTNAME = dept.FullName;
                        }
                    }
                    List <ManyPowerCheckEntity> checkPower = new List <ManyPowerCheckEntity>();

                    //登录人是否有审核权限--有审核权限直接审核通过
                    for (int i = 0; i < powerList.Count; i++)
                    {
                        if (powerList[i].CHECKDEPTID == currUser.DeptId)
                        {
                            var rolelist = currUser.RoleName.Split(',');
                            for (int j = 0; j < rolelist.Length; j++)
                            {
                                if (powerList[i].CHECKROLENAME.Contains(rolelist[j]))
                                {
                                    checkPower.Add(powerList[i]);
                                    break;
                                }
                            }
                        }
                    }
                    powerList.GroupBy(t => t.SERIALNUM).ToList().Count();
                    if (checkPower.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(applyId))
                        {
                            if (hasRight)
                            {
                                state = "1";
                            }
                            else
                            {
                                state = "0";
                            }
                        }
                        else
                        {
                            state = "1";
                        }

                        ManyPowerCheckEntity check = checkPower.Last();//当前

                        for (int i = 0; i < powerList.Count; i++)
                        {
                            if (check.ID == powerList[i].ID)
                            {
                                if ((i + 1) >= powerList.Count)
                                {
                                    nextCheck = null;
                                }
                                else
                                {
                                    nextCheck = powerList[i + 1];
                                }
                            }
                        }
                    }
                    else
                    {
                        state     = "0";
                        nextCheck = powerList.First();
                    }

                    if (null != nextCheck)
                    {
                        //当前审核序号下的对应集合
                        var serialList = powerList.Where(p => p.SERIALNUM == nextCheck.SERIALNUM);
                        //集合记录大于1,则表示存在并行审核(审查)的情况
                        if (serialList.Count() > 1)
                        {
                            string flowdept     = string.Empty; // 存取值形式 a1,a2
                            string flowdeptname = string.Empty; // 存取值形式 b1,b2
                            string flowrole     = string.Empty; // 存取值形式 c1|c2|  (c1数据构成: cc1,cc2,cc3)
                            string flowrolename = string.Empty; // 存取值形式 d1|d2| (d1数据构成: dd1,dd2,dd3)

                            ManyPowerCheckEntity slastEntity = new ManyPowerCheckEntity();
                            slastEntity = serialList.LastOrDefault();
                            foreach (ManyPowerCheckEntity model in serialList)
                            {
                                flowdept     += model.CHECKDEPTID + ",";
                                flowdeptname += model.CHECKDEPTNAME + ",";
                                flowrole     += model.CHECKROLEID + "|";
                                flowrolename += model.CHECKROLENAME + "|";
                            }
                            if (!flowdept.IsEmpty())
                            {
                                slastEntity.CHECKDEPTID = flowdept.Substring(0, flowdept.Length - 1);
                            }
                            if (!flowdeptname.IsEmpty())
                            {
                                slastEntity.CHECKDEPTNAME = flowdeptname.Substring(0, flowdeptname.Length - 1);
                            }
                            if (!flowdept.IsEmpty())
                            {
                                slastEntity.CHECKROLEID = flowrole.Substring(0, flowrole.Length - 1);
                            }
                            if (!flowdept.IsEmpty())
                            {
                                slastEntity.CHECKROLENAME = flowrolename.Substring(0, flowrolename.Length - 1);
                            }
                            nextCheck = slastEntity;
                        }
                    }
                    return(nextCheck);
                }
                else
                {
                    state = "0";
                    return(nextCheck);
                }
            }
            else
            {
                state = "0";
                return(nextCheck);
            }
        }
Example #3
0
        /// <summary>
        /// 获取流程图
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="modulename"></param>
        /// <returns></returns>
        public Flow GetFlow(string modulename, string keyValue, string adjustId)
        {
            List <nodes> nlist = new List <nodes>();
            List <lines> llist = new List <lines>();
            Operator     user  = ERCHTMS.Code.OperatorProvider.Provider.Current();
            //得到流程节点
            SafeAdjustmentEntity adjustmentEntity = adjustmentService.GetEntity(keyValue);

            if (string.IsNullOrEmpty(adjustId))
            {
                //取最新一条
                adjustmentEntity = adjustmentService.GetEntity(keyValue);
                adjustId         = adjustmentEntity.ID;
            }
            DataTable         nodeDt = service.GetCheckInfo(modulename, keyValue, adjustId);
            SafeMeasureEntity entity = service.GetEntity(keyValue);
            Flow flow = new Flow();

            flow.title    = "";
            flow.initNum  = 22;
            flow.activeID = entity.FlowId;

            if (nodeDt != null && nodeDt.Rows.Count > 0)
            {
                #region [创建node对象]
                for (int i = 0; i < nodeDt.Rows.Count; i++)
                {
                    DataRow dr    = nodeDt.Rows[i];
                    nodes   nodes = new nodes();
                    nodes.alt     = true;
                    nodes.isclick = false;
                    nodes.css     = "";
                    nodes.id      = dr["id"].ToString(); //主键
                    nodes.img     = "";
                    nodes.name    = dr["flowname"].ToString();
                    nodes.type    = "stepnode";
                    nodes.width   = 150;
                    nodes.height  = 60;
                    //位置
                    int m = i % 4;
                    int n = i / 4;
                    if (m == 0)
                    {
                        nodes.left = 120;
                    }
                    else
                    {
                        nodes.left = 120 + ((150 + 60) * m);
                    }
                    if (n == 0)
                    {
                        nodes.top = 54;
                    }
                    else
                    {
                        nodes.top = (n * 100) + 54;
                    }


                    setInfo sinfo = new setInfo();
                    sinfo.NodeName = nodes.name;
                    if (dr["AUDITDEPT"] != null && !string.IsNullOrEmpty(dr["AUDITDEPT"].ToString()))
                    {
                        sinfo.Taged = 1;
                        List <NodeDesignateData> nodelist          = new List <NodeDesignateData>();
                        NodeDesignateData        nodedesignatedata = new NodeDesignateData();
                        DateTime auditdate;
                        DateTime.TryParse(dr["AUDITTIME"].ToString(), out auditdate);
                        nodedesignatedata.createdate = auditdate.ToString("yyyy-MM-dd HH:mm");
                        nodedesignatedata.creatdept  = dr["AUDITDEPT"].ToString();
                        nodedesignatedata.createuser = dr["AUDITPEOPLE"].ToString();
                        nodedesignatedata.status     = dr["AUDITRESULT"].ToString() == "0" ? "同意" : "不同意";
                        if (dr["AUDITRESULT"].ToString() == "1")
                        {
                            flow.activeID = "";
                        }
                        if (i == 0)
                        {
                            nodedesignatedata.prevnode = "无";
                        }
                        else
                        {
                            nodedesignatedata.prevnode = nodeDt.Rows[i - 1]["flowname"].ToString();
                        }
                        nodelist.Add(nodedesignatedata);
                        sinfo.NodeDesignateData = nodelist;
                        nodes.setInfo           = sinfo;
                    }
                    else
                    {
                        List <NodeDesignateData> nodelist          = new List <NodeDesignateData>();
                        NodeDesignateData        nodedesignatedata = new NodeDesignateData();
                        nodedesignatedata.createdate = "无";
                        //获取执行部门
                        string executeDeptId = string.Empty;
                        if (dr["checkdeptid"].ToString() == "-3")
                        {
                            executeDeptId = service.GetExecuteDept(entity.Id);
                        }
                        else
                        {
                            executeDeptId = dr["checkdeptid"].ToString();
                        }
                        //获取执行人
                        IManyPowerCheckService powerCheck = new ManyPowerCheckService();
                        //获取流程节点配置
                        List <ManyPowerCheckEntity> powerList = powerCheck.GetListBySerialNum(user.OrganizeCode, "安措计划调整审批");
                        if (powerList.Count > 0)
                        {
                            var item = powerList.Where(t => t.FLOWNAME == dr["FLOWNAME"].ToString()).FirstOrDefault();
                            if (item.CHECKDEPTCODE == "-3" || item.CHECKDEPTID == "-3")
                            {
                                string executedept = new DepartmentService().GetEntity(executeDeptId).DepartmentId;
                                switch (item.ChooseDeptRange) //判断部门范围
                                {
                                case "0":
                                    item.CHECKDEPTID = executedept;
                                    break;

                                case "1":
                                    var dept = deptservice.GetEntity(executedept);
                                    while (dept.Nature != "部门" && dept.Nature != "厂级")
                                    {
                                        dept = deptservice.GetEntity(dept.ParentId);
                                    }
                                    item.CHECKDEPTID = dept.DepartmentId;
                                    break;

                                case "2":
                                    var dept1 = deptservice.GetEntity(executedept);
                                    while (dept1.Nature != "部门" && dept1.Nature != "厂级")
                                    {
                                        dept1 = deptservice.GetEntity(dept1.ParentId);
                                    }
                                    item.CHECKDEPTID = (dept1.DepartmentId + "," + executedept).Trim(',');
                                    break;

                                default:
                                    item.CHECKDEPTID = executedept;
                                    break;
                                }
                                executeDeptId = item.CHECKDEPTID;
                            }
                        }
                        string    userNames = "";
                        string    execusers = GetNextStepUser(dr["checkrolename"].ToString(), executeDeptId, out userNames);
                        DataTable dtuser    = userservice.GetUserTable(execusers.Split(','));
                        string[]  usernames = dtuser.AsEnumerable().Select(d => d.Field <string>("realname")).ToArray();
                        string[]  deptnames = dtuser.AsEnumerable().Select(d => d.Field <string>("deptname")).ToArray().GroupBy(t => t).Select(p => p.Key).ToArray();
                        nodedesignatedata.createuser = usernames.Length > 0 ? string.Join(",", usernames) : "无";
                        nodedesignatedata.creatdept  = deptnames.Length > 0 ? string.Join(",", deptnames) : "无";
                        //nodedesignatedata.createuser = "******";
                        //nodedesignatedata.creatdept = "无";
                        nodedesignatedata.status = "无";
                        if (i == 0)
                        {
                            nodedesignatedata.prevnode = "无";
                        }
                        else
                        {
                            nodedesignatedata.prevnode = nodeDt.Rows[i - 1]["flowname"].ToString();
                        }
                        nodelist.Add(nodedesignatedata);
                        sinfo.NodeDesignateData = nodelist;
                        nodes.setInfo           = sinfo;
                    }

                    nlist.Add(nodes);
                }
                //流程结束节点
                nodes nodes_end = new nodes();
                nodes_end.alt     = true;
                nodes_end.isclick = false;
                nodes_end.css     = "";
                nodes_end.id      = Guid.NewGuid().ToString();
                nodes_end.img     = "";
                nodes_end.name    = "流程结束";
                nodes_end.type    = "endround";
                nodes_end.width   = 150;
                nodes_end.height  = 60;
                //取最后一流程的位置,相对排位
                nodes_end.left = nlist[nlist.Count - 1].left;
                nodes_end.top  = nlist[nlist.Count - 1].top + 100;
                nlist.Add(nodes_end);

                //如果状态为审核通过或不通过,流程结束进行标识
                if (entity.Stauts == "审批不通过" || (entity.IsOver == 1 && entity.Stauts == "审批通过"))
                {
                    setInfo sinfo = new setInfo();
                    sinfo.NodeName = nodes_end.name;
                    sinfo.Taged    = 1;
                    List <NodeDesignateData> nodelist          = new List <NodeDesignateData>();
                    NodeDesignateData        nodedesignatedata = new NodeDesignateData();

                    //取流程结束时的节点信息
                    DataRow[] end_rows = nodeDt.Select("AUDITPEOPLE is not null").OrderBy(t => t.Field <DateTime>("AUDITTIME")).ToArray();
                    DataRow   end_row  = end_rows[end_rows.Count() - 1];
                    DateTime  auditdate;
                    DateTime.TryParse(end_row["AUDITTIME"].ToString(), out auditdate);
                    nodedesignatedata.createdate = auditdate.ToString("yyyy-MM-dd HH:mm");
                    nodedesignatedata.creatdept  = end_row["AUDITDEPT"].ToString();
                    nodedesignatedata.createuser = end_row["AUDITPEOPLE"].ToString();
                    nodedesignatedata.status     = end_row["AUDITRESULT"].ToString() == "0" ? "同意" : "不同意";
                    nodedesignatedata.prevnode   = end_row["flowname"].ToString();

                    nodelist.Add(nodedesignatedata);
                    sinfo.NodeDesignateData = nodelist;
                    nodes_end.setInfo       = sinfo;
                }

                #region 创建line对象

                for (int i = 0; i < nodeDt.Rows.Count; i++)
                {
                    lines lines = new lines();
                    lines.alt  = true;
                    lines.id   = Guid.NewGuid().ToString();
                    lines.from = nodeDt.Rows[i]["id"].ToString();
                    if (i < nodeDt.Rows.Count - 1)
                    {
                        lines.to = nodeDt.Rows[i + 1]["id"].ToString();
                    }
                    lines.name = "";
                    lines.type = "sl";
                    llist.Add(lines);
                }

                lines lines_end = new lines();
                lines_end.alt  = true;
                lines_end.id   = Guid.NewGuid().ToString();
                lines_end.from = nodeDt.Rows[nodeDt.Rows.Count - 1]["id"].ToString();
                lines_end.to   = nodes_end.id;
                llist.Add(lines_end);
                #endregion

                flow.nodes = nlist;
                flow.lines = llist;
                #endregion
            }
            return(flow);
        }