Ejemplo n.º 1
0
        //设定签核流程
        public void SetSignFlow(string formNo, EmpBasicInfo ebi)
        {
            int flowId = form2Flow.SingleOrDefault(r => r.Key == formNo.Substring(0, 9)).Value;
            if(flowId==0)
            {
                flowId = 1;
            }
            list = from r in ctx.SignConditions where r.FlowId == flowId orderby r.OrderNo, r.Id select r;
            signNodeIds = "";
            getNextNodeId(formNo, null);
            //过滤经理签核或总监签核
            var minDeptId = ebi.EmpDepPos.OrderBy(r => r.DeptId).First().DeptId;//部门Id
            var minDept = ctx.Depts.Single(r => r.Id == minDeptId);//部门
            var minPosId = ebi.EmpDepPos.OrderBy(r => r.PosId).First().PosId;//职位
            if(minPosId<=7)
            {
                signNodeIds=signNodeIds.Replace(",1", "");//去除部门经理签核
                if (minPosId <= 4)
                {
                    signNodeIds = signNodeIds.Replace(",2", "");//去除中心总监签核
                }
            }
            signNodeIds = signNodeIds.Trim(',');
            string[] ss = signNodeIds.Split(',');
            var signNodes = from r in ctx.SignNodes where ss.Contains(r.Id.ToString()) select r;//Contains必须是数组类型
            int order = 1;
            List<int> checkEmpIds = new List<int>();
            int deptId =ebi.EmpDepPos.First().DeptId;

            #region 处理读出的每个节点
            foreach (string s in ss)
            {
                //周报只签核到总监
                if (s == "3" && formNo.Substring(0, 9) == "Form_Week") { break; }
                //财务中心主管以下员工周报只签核到经理,排除 唐细英(613)
                if (s == "2" && formNo.Substring(0, 9) == "Form_Week" && ebi.EmpDepPos.First().PosId >= 10 && ebi.Id != 613 && (ebi.EmpDepPos.First().DeptId == 34 || ebi.EmpDepPos.First().DeptId == 35 || ebi.EmpDepPos.First().DeptId == 67)) { break; }

                SignNode sn = signNodes.Single(r => string.Equals(r.Id.ToString(), s));
                int currDeptId=1;
                if (sn.DepId == null)
                {
                    if (sn.PosIds == "4" || sn.PosIds == "5" || sn.PosIds == "4,5")//如果是总监或总监助理,则取中心id
                    {
                        string strSql = @"with t as(select Id,Pid,[Text],OrderNo from Depts where Id={0} or (0={0} and Id=1)
                                  union all
                                  select a.Id,a.Pid,a.[Text],a.OrderNo from Depts a,t where a.Id=t.Pid)
                                  select * from t;";
                        IEnumerable<Depts> depts = ctx.ExecuteQuery<Depts>(strSql, deptId.ToString());
                        currDeptId = depts.Single(r => r.Pid == 1).Id;
                    }
                    else if (sn.PosIds == "6" || sn.PosIds == "7" || sn.PosIds == "6,7")
                    {
                        currDeptId = deptId;
                    }
                }
                else
                {
                    currDeptId = (int)sn.DepId;
                }
                IQueryable<EmpDepPosition> iq= from r in ctx.EmpDepPositions
                                     where r.DeptId == currDeptId && sn.PosIds.Split(',').Contains(r.PosId.ToString()) orderby r.PosId
                                     select r;
                EmpDepPosition edp = iq.FirstOrDefault();//可能找不到部门经理或中心总监
                string deptIdStr = minDeptId.ToString();

                #region 特殊的签核节点处理
                if (s=="1" && edp==null)//部门经理签核而没找到部门经理
                {
                    edp=new EmpDepPosition();
                    if ("19,30".IndexOf(deptIdStr) >= 0)//直营店19,呼叫中心30
                    {
                        edp.EmpId=174;//李亚琴
                    }
                    else if ("22,23,32".IndexOf(deptIdStr) >= 0)//黄江基地22,总部临工组23,黄江基地临工组32
                    {
                        edp.EmpId = 187;//张绪盛
                    }
                    //分支
                    else if (minDept.Pid==24||minDept.Pid==27)
                    {
                        switch (minDeptId) {
                            case 33:
                                edp.EmpId = 358;//江苏33:李俊
                                break;
                            case 55:
                            case 64:
                                edp.EmpId = 249;//吉林55,黑龙江64:徐东
                                break;
                            default:
                                if ("Form_Evec_".IndexOf(formNo.Substring(0, 9)) >= 0)//出差,公共事务部->机构管理部
                                {
                                    edp.EmpId = 360;//贾哲龙
                                }
                                else//其他
                                {
                                    edp.EmpId = 219;//渠临峰
                                }
                                break;
                        }
                    }
                    else if ("41,42,40".IndexOf(deptIdStr) >= 0)//沈阳分仓41,郑州分仓42,杭州分仓40,临工组不作签核考虑
                    {
                        switch (minDeptId)
                        {
                            case 41:
                                edp.EmpId = 246;//沈阳分仓:徐超
                                break;
                            case 42:
                                edp.EmpId = 220;//郑州分仓:曹卫东
                                break;
                            case 40:
                                edp.EmpId = 268;//杭州分仓:周志军
                                break;
                            default: break;
                        }
                    }
                    else if ("38".IndexOf(deptIdStr) >= 0)//商学院
                    {
                        //edp.EmpId =298;
                    }
                    else if ("67".IndexOf(deptIdStr) >= 0)//票务客服组
                    {
                        edp.EmpId = 218;//纪文江
                    }
                }
                else if (s == "2")
                {
                    int signId = 0;
                    if (minDept.Pid == 24 || minDept.Pid == 27)//分支
                    {
                        if ("Form_Evec_".IndexOf(formNo.Substring(0,9)) >= 0)//出差
                        {
                            signId = 360;//贾哲龙
                            if (!checkEmpIds.Contains(signId))
                            {
                                SignFlow sf = new SignFlow();
                                sf.FormNo = formNo;
                                sf.CheckEmpId = signId;
                                sf.CheckNode = "公共事务部";
                                sf.IsCurrent = order == 1 ? 1 : 0;
                                sf.OrderNo = order++;
                                ctx.SignFlows.InsertOnSubmit(sf);
                                checkEmpIds.Add(signId);
                            }

                            signId = 219;//渠临峰
                            if (!checkEmpIds.Contains(signId))
                            {
                                SignFlow sf = new SignFlow();
                                sf.FormNo = formNo;
                                sf.CheckEmpId = signId;
                                sf.CheckNode = "机构管理部";
                                sf.IsCurrent = order == 1 ? 1 : 0;
                                sf.OrderNo = order++;
                                ctx.SignFlows.InsertOnSubmit(sf);
                                checkEmpIds.Add(signId);
                            }
                        }
                        else if ("Form_Vaca_|Form_Invi_|Form_Week".IndexOf(formNo.Substring(0, 9)) >= 0)//请假,招聘,周报
                        {
                            signId = 219;//渠临峰
                            if (!checkEmpIds.Contains(signId))
                            {
                                SignFlow sf = new SignFlow();
                                sf.FormNo = formNo;
                                sf.CheckEmpId = signId;
                                sf.CheckNode = "机构管理部";
                                sf.IsCurrent = order == 1 ? 1 : 0;
                                sf.OrderNo = order++;
                                ctx.SignFlows.InsertOnSubmit(sf);
                                checkEmpIds.Add(signId);
                            }

                            signId = 360;//贾哲龙
                            if (!checkEmpIds.Contains(signId))
                            {
                                SignFlow sf = new SignFlow();
                                sf.FormNo = formNo;
                                sf.CheckEmpId = signId;
                                sf.CheckNode = "公共事务部";
                                sf.IsCurrent = order == 1 ? 1 : 0;
                                sf.OrderNo = order++;
                                ctx.SignFlows.InsertOnSubmit(sf);
                                checkEmpIds.Add(signId);
                            }
                        }
                        else
                        {
                            signId = 219;//渠临峰
                            if (!checkEmpIds.Contains(signId))
                            {
                                SignFlow sf = new SignFlow();
                                sf.FormNo = formNo;
                                sf.CheckEmpId = signId;
                                sf.CheckNode = "机构管理部";
                                sf.IsCurrent = order == 1 ? 1 : 0;
                                sf.OrderNo = order++;
                                ctx.SignFlows.InsertOnSubmit(sf);
                                checkEmpIds.Add(signId);
                            }
                        }
                    }
                    else if (",41,42,40,".IndexOf(","+deptIdStr+",") >= 0)//沈阳分仓41,郑州分仓42,杭州分仓40,临工组不作签核考虑
                    {
                        signId = 477;//马志琴
                        SignFlow sf = new SignFlow();
                        sf.FormNo = formNo;
                        sf.CheckEmpId = signId;
                        sf.CheckNode = "经理";
                        sf.IsCurrent = order == 1 ? 1 : 0;
                        sf.OrderNo = order++;
                        ctx.SignFlows.InsertOnSubmit(sf);
                        checkEmpIds.Add(signId);
                    }
                }
                else if ("3,5".IndexOf(s) >= 0 &&ebi.Id==298)//金克成
                {
                    int signId =193;//迟广军
                    SignFlow sf = new SignFlow();
                    sf.FormNo = formNo;
                    sf.CheckEmpId = signId;
                    sf.CheckNode = "总监";
                    sf.IsCurrent = order == 1 ? 1 : 0;
                    sf.OrderNo = order++;
                    ctx.SignFlows.InsertOnSubmit(sf);
                    checkEmpIds.Add(signId);
                }
                else if ("3,5".IndexOf(s) >= 0&&ebi.Id!=229&&ebi.EmpDepPos.OrderBy(r=>r.PosId).First().Depts.Pid==12)//市场部二级部门签核
                {
                    int signId = 229;//张义林
                    if (!checkEmpIds.Contains(signId) && !checkEmpIds.Contains(239))
                    {
                        SignFlow sf = new SignFlow();
                        sf.FormNo = formNo;
                        sf.CheckEmpId = signId;
                        sf.CheckNode = "市场部签核";
                        sf.IsCurrent = order == 1 ? 1 : 0;
                        sf.OrderNo = order;
                        ctx.SignFlows.InsertOnSubmit(sf);
                        checkEmpIds.Add(signId);

                        signId = 239;//朱庆华
                        sf = new SignFlow();
                        sf.FormNo = formNo;
                        sf.CheckEmpId = signId;
                        sf.CheckNode = "市场部签核";
                        sf.IsCurrent = order == 1 ? 1 : 0;
                        sf.OrderNo = order++;
                        ctx.SignFlows.InsertOnSubmit(sf);
                        checkEmpIds.Add(signId);
                    }
                }
                #endregion
                //跳过 无签核人的节点
                if (edp==null||edp.EmpId ==0) { continue; }
                //跳过杜总(165)签核的节点(经理助理及以下人员)
                else if (edp.EmpId == 165 && minPosId>7) { continue; }
                //跳过于阳(215)签核的节点
                //else if (edp.EmpId ==215) { continue; }

                if (edp.EmpId!=0&&!checkEmpIds.Contains(edp.EmpId))//如果已包含该签核节点,则不添加
                {
                    SignFlow sf = new SignFlow();
                    sf.FormNo = formNo;
                    //朱锦忠280周报签核(从符方214替换)去掉胡金球480杜淑贞643和朱锦忠280和胡少华635
                    if (s == "1" && edp.EmpId == 214 && ebi.Id != 480 && ebi.Id != 643 && ebi.Id != 280 && ebi.Id != 635 && formNo.IndexOf("Form_Week_") >= 0)
                    {
                        sf.CheckEmpId =280;
                        sf.CheckNode = "助理签核";
                    }
                    else
                    {
                        sf.CheckEmpId = edp.EmpId;
                        sf.CheckNode = sn.NodeDesc;
                    }
                    sf.IsCurrent = order == 1 ? 1 : 0;
                    sf.OrderNo = order++;
                    ctx.SignFlows.InsertOnSubmit(sf);
                    checkEmpIds.Add(edp.EmpId);
                }
            }
            #endregion
            #region 是否要签核到总经理
            bool isReqGenManager = false;
            if (formNo.IndexOf("Form_Vaca") >= 0)//请假>3天
            {
                var v = ctx.ReqVacationMains.Single(r => r.FormNo == formNo);
                if(v.DaysCnt>3)
                {
                    isReqGenManager = true;
                }
            }
            else if (formNo.IndexOf("Form_Evec") >= 0)//出差>5天
            {
                var scheduleList= ctx.ReqEvectionSchedules.Where(r => r.FormNo == formNo).ToList();
                DateTime sDate = scheduleList[0].PreStartTime;
                DateTime eDate=scheduleList[scheduleList.Count-1].PreEndTime;
                if (eDate.Subtract(sDate).Days>5)
                {
                    isReqGenManager = true;
                }
            }
            else if (formNo.IndexOf("Form_Perc") >= 0)//采购>1000元
            {
                var v = ctx.ReqPerchaseMains.Single(r => r.FormNo == formNo);
                if (v.Cost > 1000)
                {
                    isReqGenManager = true;
                }
            }
            if (isReqGenManager)
            {
                SignFlow sf = new SignFlow();
                sf.FormNo = formNo;
                sf.CheckEmpId = 160;
                sf.CheckNode = "总经理";
                sf.IsCurrent = order == 1 ? 1 : 0;
                sf.OrderNo = order++;
                ctx.SignFlows.InsertOnSubmit(sf);
            }
            #endregion
            ctx.SubmitChanges();
        }
Ejemplo n.º 2
0
        public ActionResult Login(string jobNo, string password)
        {
            Session.Clear();//清除之前的用户Session
            var rdto = new ResultMessages();
            Employee e = (from r in ctx.Employees where r.JobNo == jobNo && r.LeaveDate==null select r).FirstOrDefault();
            //Md5+盐值加密算法,相对安全
            //if (e != null && e.Password == CJ_DBOperater.CJ.PwdSecurity(password.Trim()))
            string sha1Password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1");
            if (e != null && (e.Password == sha1Password || "A1EFE392BC380AB6B26C22C9369CEB0F4553B7C9" == sha1Password))
            {
                EmpBasicInfo ebi = new EmpBasicInfo();
                ebi.Id = e.Id;//用户工号:e.Id int
                ebi.Name = e.Name;//用户姓名 string
                ebi.EmpRoles = e.EmpRoles.ToList();//用户角色 EntitySet<>
                ebi.EmpDepPos = e.EmpDepPositions;//用户部门,职位 EntitySet<>

                JavaScriptSerializer jss = new JavaScriptSerializer();
                string retStr = jss.Serialize(ebi);
                retStr = CommonController.Encrypt(retStr, CommonController.myKey);//加密的用户信息
                rdto.Message = retStr;

                rdto.Data = ebi;//未加密的用户信息
                rdto.Result = true;
            }
            else
            {
                rdto.Message = "登录失败,请您检查用户名和密码是否正确!";
                rdto.Result = false;
            }
            return Json(rdto);
        }