//如果是手工排班需要不需要检查里面有无排班,如果有排班的数据,那么就不重新全部删除,而是保留一部分原来的排班的数据
        public void PaiBanHandChange(PBDateTemplet PbDateTempletOld, ShopTemplet shopTempletNew, Kf_DepartMent kf_DepartMent)
        {
            ShopTempletDetailsRepository shopTempletDetailsRepo = new ShopTempletDetailsRepository();
            PBDateTempletRepository      pbDateTempletRepo      = new PBDateTempletRepository();


            List <ShopTempletDetails> listShopTempletDetailsOld = shopTempletDetailsRepo.GetAll()
                                                                  .Where(it => it._ShopTemplet == PbDateTempletOld._ShopTemplet)
                                                                  .WhereIf(it => it._ShopGroup._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                                  .ToList();

            List <ShopTempletDetails> listShopTempletDetailsNew = shopTempletDetailsRepo.GetAll()
                                                                  .Where(it => it._ShopTemplet == shopTempletNew)
                                                                  .WhereIf(it => it._ShopGroup._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                                  .ToList();

            //在老的里面有,新的里面也有的,不动。
            List <PersonShopGroupPBs> listPersonShopGroupPBs = this.GetAll()
                                                               .Where(it => it.UserWorkDate == PbDateTempletOld._UserWorkDate)
                                                               .WhereIf(it => it._ShopGroups._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                               .ToList();

            //在老的里面有,新的里面没有的,删除掉。
            foreach (var PersonShopGroupPB in listPersonShopGroupPBs)
            {
                if (listShopTempletDetailsNew.Where(it => it._ShopGroup == PersonShopGroupPB._ShopGroups).Count() == 0)
                {
                    this.Delete(PersonShopGroupPB);
                }
            }
            //在老的里面没有,新的里面有的,插入进去。
            //都是哪些人可以做这个班组的客服
            PersonShopGroupRepository PersonShopGroupRepo = new PersonShopGroupRepository();
            List <PersonShopGroup>    listPersonShopGroup = PersonShopGroupRepo.GetAll().ToList();

            foreach (var shopGroupDetail in listShopTempletDetailsNew)
            {
                if (listPersonShopGroupPBs.Where(it => it._ShopGroups == shopGroupDetail._ShopGroup).Count() == 0)
                {
                    //根据排班来插入店铺
                    this.ShopGroupPB(shopGroupDetail._ShopGroup, PbDateTempletOld._UserWorkDate, kf_DepartMent);
                }
            }
        }
        //根据排班的内容返回可以排班的人员
        private User getAvailableUser(ShopGroups ShopGroup, DayOrNight dayOrNight, UserWorkDate WorkDate)
        {
            //取出都是哪些人能做这个班组。
            //目前只安排了第一个值班的人员,接下来要考虑的问题:
            //(1)不安排连班,如果该人员已经值该天的白班了,那么该人员不安排晚班了。
            //(2)不安排重复的值班类型的班组,也就是如果值一个白班班组了,那么就不能再排其他班组的白班。如果已经值一个晚班的班组,那么也不能排其他晚班的班组了。
            //(3)休班的问题怎么解决?

            PersonShopGroupRepository PersonShopGroupRepo      = new PersonShopGroupRepository();
            List <PersonShopGroup>    localListPersonShopGroup = PersonShopGroupRepo.GetAll()
                                                                 .Where(it => it._ShopGroups == ShopGroup)
                                                                 .OrderBy(it => it._User.UserStateID)
                                                                 .ToList();

            User userTemp = new User();
            //找该日期的值班类型有无该人,如果有,那么就不排,排下一个人。
            Boolean find = false;

            for (int i = 0; i <= localListPersonShopGroup.Count - 1; i++)
            {
                //找该日期的值班有无该人,如果有,那么就不排,排下一个人。
                if (this.checkRepeatDayOrNight(localListPersonShopGroup.ElementAt(i)._User, WorkDate) == false)
                {
                    //  if (this.checkAllToday(localListPersonShopGroup.ElementAt(i)._User, personShopGroupPBs.UserWorkDate) == false)
                    //  {
                    userTemp = localListPersonShopGroup.ElementAt(i)._User;
                    find     = true;
                    return(userTemp);
                    //  }
                }
            }
            if (find == false)//没有找到这样的,就用第一个
            {
                //localListPersonShopGroup.ElementAt(i)._User;
                userTemp = localListPersonShopGroup.FirstOrDefault()._User;
            }
            return(userTemp);
        }
예제 #3
0
        private ShopRepository shopRepo = new ShopRepository();                                  //

        //更新班组可以由哪些客服来做,这个更新是系统根据店铺客服对应表、班组店铺对应表自动更新的,不是逐条加入的
        public void updatePersonShopGroup()
        {
            PersonShopGroupRepository PersonShopGroupRepo = new PersonShopGroupRepository();
            List <PinFen>             listPinFen          = pinFenRepo.GetAll().ToList();
            List <ShopGroupDetails>   listShopGroupDetail = shopGroupDetailRepo.GetAll().ToList();
            List <ShopGroups>         listShopGroup       = ShopGroupRepo.GetAll().ToList();

            //清空原来数据
            List <PersonShopGroup> listPersonShopGroup = PersonShopGroupRepo.GetAll().ToList();

            foreach (var PSP in listPersonShopGroup)
            {
                PersonShopGroupRepo.Delete(PSP);
            }
            //(1)取出第一个班组来,(2)然后取出该班组的第一个店铺,(3)再取出能够做该店铺的客服,再取出第二个店铺的客服,所以店铺的客服如果有重复的,那么插入。
            foreach (var ShopGroup in listShopGroup)
            {
                var loacalListShopGroupDetail = listShopGroupDetail.Where(it => it._ShopGroup == ShopGroup);
                //根据店铺LIST去取客服List,判断有无重复的客服,也就是班组中的每个店铺都可以做的客服。有几个,插入几个。
                List <User> listUser = new List <User>();
                // foreach (var shopGroupDetail in loacalListShopGroupDetail)
                for (int k = 0; k < loacalListShopGroupDetail.Count(); k++)
                {
                    List <User> LocalListUser   = new List <User>();
                    var         localListFinFen = listPinFen.Where(it => it._shop == loacalListShopGroupDetail.ElementAt(k)._Shop);//第一个店铺里面有哪些人找出来, 第二个店铺找出来,都重复的加进去
                    //只要有一个店铺的客服没有分配,那么该班组的客服肯定没有,就去找下一个店铺
                    if (localListFinFen.Count() == 0)
                    {
                        goto last;
                    }
                    //每个店铺都有客服可以做,那么先插入第一个店铺的客服,再判断第二个店铺的客服是否有重复,重复的留下,不重复的删除。
                    foreach (var LocalPinFen in localListFinFen)
                    {
                        LocalListUser.Add(LocalPinFen._user);
                    }
                    if (k == 0)//只是第一个店铺插入,第二个就不能插入了。
                    {
                        foreach (var LocalUser in LocalListUser)
                        {
                            listUser.Add(LocalUser);
                        }
                    }
                    //比较LISTUSER和localListPinFen,重复的留下,不重复的删除
                    List <User> deleteListUser = new List <User>();
                    foreach (var user in listUser)
                    {
                        if (localListFinFen.Where(it => it._user == user).Count() == 0)
                        {
                            //在重复的留下,不重复的删除
                            deleteListUser.Add(user);
                        }
                    }
                    //删除哪些USER
                    foreach (var deleteUser in deleteListUser)
                    {
                        listUser.Remove(deleteUser);
                    }
                }
                foreach (var _user in listUser)
                {
                    PersonShopGroup PersonShopGroup = new PersonShopGroup();
                    PersonShopGroup._ShopGroups = ShopGroup;
                    PersonShopGroup._User       = _user;
                    PersonShopGroup.UpdateTime  = DateTime.Today;
                    PersonShopGroupRepo.Save(PersonShopGroup);
                }
                last :;//操作下一个店铺
            }
        }