Beispiel #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();
        }
        //按登录人员获取 待其签核的所有表单
        public ActionResult GetSigningNodes()
        {
            EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
            int empId = ebi.Id;
            //最近45天申请的所有表单
            var v = (from r in ctx.Weeklies where r.CreatDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "周  报", r.EmpId, ReqDate=r.CreatDate })
                    .Concat(from r in ctx.ReqVehicleMains where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "用车申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqEvectionMains where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "出差申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqOvertimes where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "加班申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqVacationMains where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "请假申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqMeetingRooms where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "会议室申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqPerchaseMains where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "采购申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqReceptions where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "商务接待申请", r.EmpId, r.ReqDate })
                    .Concat(from r in ctx.ReqInvites where r.ReqDate >= DateTime.Today.AddDays(-45) select new { r.FormNo, ReqTypeName = "招聘申请", r.EmpId, r.ReqDate });
            //等待签核的表单
            var v2 = from r in v
                     where
                         (from r2 in ctx.SignFlows
                          where r2.IsCurrent == 1 && r2.CheckEmpId == empId
                          select r2.FormNo).Contains(r.FormNo) select r;
            var list = (from r in v2 join r2 in ctx.Employees on r.EmpId equals r2.Id orderby r.ReqDate descending select new ReqSignDTO { FormNo = r.FormNo, ReqTypeName = r.ReqTypeName, EmpId = r.EmpId, Name = r2.Name, ReqDate=r.ReqDate }).ToList();
            #region 打卡签核 start
            if (DateTime.Today.Day<7)
            {
                string ym = DateTime.Today.AddDays(-9).ToString("yyMM");
                if (ebi.Id == 360)//贾泽龙360
                {
                    int[] deptIds = { 29, 33, 48 };//安徽29,江苏33,四川48
                    var vt = from r in ctx.Employees
                             join r2 in ctx.EmpDepPositions on r.Id equals r2.EmpId
                             where r2.PosId > 7 && deptIds.Contains(r2.DeptId) && !(from r3 in ctx.SignFlows where r3.FormNo.Contains("Form_Card_") && r3.IsCurrent==0 select r3.FormNo.Substring(10,3)).Contains(r.Id.ToString())
                             select new ReqSignDTO { FormNo = "Form_Card_" + r.Id + ym, ReqTypeName = "打卡签核", EmpId = r.Id, Name = r.Name, ReqDate = DateTime.Today };
                    IEnumerable<ReqSignDTO> reqSignDtos = vt.ToList();
                    foreach(ReqSignDTO n in reqSignDtos)
                    {
                        SignFlow sf = ctx.SignFlows.SingleOrDefault(r => r.FormNo == n.FormNo);
                        if(sf==null)
                        {
                            sf = new SignFlow();
                            sf.FormNo =n.FormNo;
                            sf.CheckEmpId =ebi.Id;
                            sf.CheckNode = "经理";
                            sf.IsCurrent =1;
                            sf.OrderNo =1;
                            ctx.SignFlows.InsertOnSubmit(sf);
                        }
                    }
                    ctx.SubmitChanges();
                    list.AddRange(reqSignDtos);
                }
                else if (ebi.Id == 311)//徐擎311
                {
                    int[] deptIds = {26};//浙江26
                    var vt = from r in ctx.Employees
                             join r2 in ctx.EmpDepPositions on r.Id equals r2.EmpId
                             where r2.PosId > 7 && deptIds.Contains(r2.DeptId) && !(from r3 in ctx.SignFlows where r3.FormNo.Contains("Form_Card_" + ym) && r3.IsCurrent == 0 select r3.FormNo.Substring(10, 3)).Contains(r.Id.ToString())
                             select new ReqSignDTO { FormNo = "Form_Card_" + r.Id + ym, ReqTypeName = "打卡签核", EmpId = r.Id, Name = r.Name, ReqDate = DateTime.Today };
                    IEnumerable<ReqSignDTO> reqSignDtos = vt.ToList();
                    foreach (ReqSignDTO n in reqSignDtos)
                    {
                        SignFlow sf = ctx.SignFlows.SingleOrDefault(r => r.FormNo == n.FormNo);
                        if (sf == null)
                        {
                            sf = new SignFlow();
                            sf.FormNo = n.FormNo;
                            sf.CheckEmpId = ebi.Id;
                            sf.CheckNode = "经理";
                            sf.IsCurrent = 1;
                            sf.OrderNo = 1;
                            ctx.SignFlows.InsertOnSubmit(sf);
                        }
                    }
                    ctx.SubmitChanges();
                    list.AddRange(reqSignDtos);
                }
                else if (ebi.Id == 249)//徐东249
                {
                    int[] deptIds = {27};//辽宁27
                    var vt = from r in ctx.Employees
                             join r2 in ctx.EmpDepPositions on r.Id equals r2.EmpId
                             where r2.PosId > 7 && deptIds.Contains(r2.DeptId) && !(from r3 in ctx.SignFlows where r3.FormNo.Contains("Form_Card_" + ym) && r3.IsCurrent == 0 select r3.FormNo.Substring(10, 3)).Contains(r.Id.ToString())
                             select new ReqSignDTO { FormNo = "Form_Card_" + r.Id + ym, ReqTypeName = "打卡签核", EmpId = r.Id, Name = r.Name, ReqDate = DateTime.Today };
                    IEnumerable<ReqSignDTO> reqSignDtos = vt.ToList();
                    foreach (ReqSignDTO n in reqSignDtos)
                    {
                        SignFlow sf = ctx.SignFlows.SingleOrDefault(r => r.FormNo == n.FormNo);
                        if (sf == null)
                        {
                            sf = new SignFlow();
                            sf.FormNo = n.FormNo;
                            sf.CheckEmpId = ebi.Id;
                            sf.CheckNode = "经理";
                            sf.IsCurrent = 1;
                            sf.OrderNo = 1;
                            ctx.SignFlows.InsertOnSubmit(sf);
                        }
                    }
                    ctx.SubmitChanges();
                    list.AddRange(reqSignDtos);
                }
                else if (ebi.Id == 251)//程海涛251
                {
                    int[] deptIds = {28};//山东28
                    var vt = from r in ctx.Employees
                             join r2 in ctx.EmpDepPositions on r.Id equals r2.EmpId
                             where r2.PosId > 7 && deptIds.Contains(r2.DeptId) && !(from r3 in ctx.SignFlows where r3.FormNo.Contains("Form_Card_" + ym) && r3.IsCurrent == 0 select r3.FormNo.Substring(10, 3)).Contains(r.Id.ToString())
                             select new ReqSignDTO { FormNo = "Form_Card_" + r.Id + ym, ReqTypeName = "打卡签核", EmpId = r.Id, Name = r.Name, ReqDate = DateTime.Today };
                    IEnumerable<ReqSignDTO> reqSignDtos = vt.ToList();
                    foreach (ReqSignDTO n in reqSignDtos)
                    {
                        SignFlow sf = ctx.SignFlows.SingleOrDefault(r => r.FormNo == n.FormNo);
                        if (sf == null)
                        {
                            sf = new SignFlow();
                            sf.FormNo = n.FormNo;
                            sf.CheckEmpId = ebi.Id;
                            sf.CheckNode = "经理";
                            sf.IsCurrent = 1;
                            sf.OrderNo = 1;
                            ctx.SignFlows.InsertOnSubmit(sf);
                        }
                    }
                    ctx.SubmitChanges();
                    list.AddRange(reqSignDtos);
                }
            }
            #endregion

            IEnumerable<ReqSignDTO> examTypes = ctx.ExecuteQuery<ReqSignDTO>(string.Format(@"select 'Form_Exam_'+cast(Id as nvarchar(10)) as FormNo,'考试/调查' ReqTypeName,0 EmpId,'' Name,StartTime ReqDate
            from ExamType a where ','+Testers+',' like '%,{0},%' and dateadd(mi,{1},StartTime)<=GETDATE() and EndTime>=GETDATE()
            and exists(select 0 from ExamQuestions where TypeId=a.Id and Id not in(select QuestionId from ExamAnswers where EmpId={0}));", ebi.Id, -5));
            list.AddRange(examTypes);
            return Json(list);
        }
 partial void UpdateSignFlow(SignFlow instance);
 partial void DeleteSignFlow(SignFlow instance);
 partial void InsertSignFlow(SignFlow instance);