//如果是手工排班需要不需要检查里面有无排班,如果有排班的数据,那么就不重新全部删除,而是保留一部分原来的排班的数据 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); }
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 :;//操作下一个店铺 } }
//检查某个模板是否可用,同时更新模板的可用状态。 //(1)过期的无所谓了(2)店铺是否都包含在了模板的班组里面(3)班组里面是否设置了客服。 public string checkShopTempletValid(int shopTempletID) { //历史的模板就不更新了 //检查模板里面的班组,全部班组加起来是否满足了模板当地的店铺的需求。 ShopGroupRepository shopGroupRepo = new ShopGroupRepository(); ShopGroupDetailRepository shopGroupDetailsRepo = new ShopGroupDetailRepository(); ShopRepository shopRepo = new ShopRepository(); ShopTemplet shopTemplet = this.GetByDatabaseID(shopTempletID); //如果是历史的模板,就不检查了。 if (shopTemplet.isExpire == isExpire.过期) { return("过期的模板不需要检查"); } //该模板有哪些班组 ShopTempletDetailsRepository shopTempletDetailsRepo = new ShopTempletDetailsRepository(); List <ShopTempletDetails> listShopTempletDetails = shopTempletDetailsRepo.GetAll() .Where(it => it._ShopTemplet == shopTemplet) .ToList(); //排进去的班组 List <ShopGroups> listShopGroups = new List <ShopGroups>(); foreach (var shopTempletDetail in listShopTempletDetails) { listShopGroups.Add(shopTempletDetail._ShopGroup); } List <ShopGroupDetails> listShopGroupDetails = shopGroupDetailsRepo.GetAll().ToList(); List <ShopGroupDetails> listLocalShopGroupDetails = new List <ShopGroupDetails>(); foreach (var shopGroup in listShopGroups) { List <ShopGroupDetails> listLocalSmallShopGroupDetails = listShopGroupDetails.Where(it => it._ShopGroup == shopGroup).ToList(); foreach (var shopGroupDetail in listLocalSmallShopGroupDetails) { listLocalShopGroupDetails.Add(shopGroupDetail); } } //实际的店铺 List <Shop> listExistShop = shopRepo.GetAll() .Where(it => it.ShopStateID == ShopStates.正常服务) .Where(it => it._Kf_DepartMent == shopTemplet._Kf_DepartMent) .ToList(); string strResult = ""; //(1)首先检查所有的店铺是否在班组中,如果有不在的,那么就退出,提示哪个店铺没有在班组中。 foreach (var shop in listExistShop) { List <ShopGroupDetails> localShopGroupDetails = listLocalShopGroupDetails.Where(it => it._Shop == shop).ToList(); //有这些店铺的班组列表,检查这些列表,看里面的东西。 List <ShopGroups> localShopGroupList = localShopGroupDetails.Select(it => it._ShopGroup).ToList(); if (localShopGroupDetails.Count() == 0) { strResult = "店铺" + shop.Name + "没有分配班组,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } //这个店铺分配了几个班组,如果班组数量小于店铺中设置的组数数量,那么是不对的,退出,白班晚班要分开统计. if (localShopGroupDetails.Count < shop.GroupCount) { strResult = "店铺" + shop.Name + "的组数为" + shop.GroupCount.ToString().Trim() + ",班组数量为" + localShopGroupDetails.Count.ToString().Trim() + ",班组数量少于店铺要求的组数,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } // switch (shop.ZhiBanTypeID) { case ZhiBanType.全托: //如果是全托,那么要么分配全天,要么一个白班一个晚班。 //检查是否有白班和夜班的班组,如果有一个没有的,那么就退出 if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.全天).Count() == 0 && (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).Count() == 0 && localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.晚班).Count() == 0)) { strResult = "店铺" + shop.Name + "是全托,但是没有分配白晚班班组,也没有分配全天班组。请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } break; case ZhiBanType.仅白班: if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).Count() == 0) { strResult = "店铺" + shop.Name + "是仅白班,但是白班没有分配班组,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.晚班).Count() != 0) { strResult = "店铺" + shop.Name + "是仅白班,但是晚班分配了班组" + localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.晚班).FirstOrDefault().ToString() + ",请检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } break; case ZhiBanType.仅夜班: if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).Count() != 0) { strResult = "店铺" + shop.Name + "是仅夜班,但是分配了班组" + localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).FirstOrDefault().ToString() + ",请检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.晚班).Count() == 0) { strResult = "店铺" + shop.Name + "是仅夜班,但是晚班没有分配班组,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } break; case ZhiBanType.周末: if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).Count() == 0) { strResult = "店铺" + shop.Name + "是周末,但是白班没有分配班组,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.晚班).Count() == 0) { strResult = "店铺" + shop.Name + "是周末,但是晚班没有分配班组,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } break; case ZhiBanType.夜班加周末: if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).Count() != 0) { strResult = "店铺" + shop.Name + "是仅夜班加周末,但是分配了班组" + localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.白班).FirstOrDefault().ToString() + ",请检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } if (localShopGroupList.Where(it => it.WorkDayOrNight == DayOrNight.晚班).Count() == 0) { strResult = "店铺" + shop.Name + "是仅夜班加周末,但是晚班没有分配班组,请分配后再检查"; shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } break; default: break; } } //再(判断模板中的班组中的客服是否齐全,如果客服设置不全,那么也进行提示。 //用于检查班组是否安排客服了 //List<ShopGroups> listShopGroups = new List<ShopGroups>(); PersonShopGroupRepository personShopGroupRepo = new PersonShopGroupRepository(); foreach (var shopGroup in listShopGroups) { strResult = personShopGroupRepo.checkPersonShopGroupValid(shopGroup); if (strResult.Trim() != "班组客服有效") { shopTemplet.isValid = isValid.无效; this.Update(shopTemplet); return(strResult); } } strResult = "模板有效"; shopTemplet.isValid = isValid.效; this.Update(shopTemplet); return(strResult); }