六个人上班,早晚班各2人,中班上班学期工作计划1人,月休4天怎样排班

后使用快捷导航没有帐号?
扫一扫,访问微社区
查看: 4184|回复: 12
中级服务员, 积分 55, 距离下一级还需 145 积分
签到天数: 2 天连续签到: 1 天[LV.1]初来乍到
3倍积分手机党
共98间客房,12个服务员,分早中晚三班,其中中班2人,夜班1人,大家帮忙看下怎么排班,每月4天休假
中级服务员, 积分 55, 距离下一级还需 145 积分
签到天数: 2 天连续签到: 1 天[LV.1]初来乍到
3倍积分手机党
高级领班, 积分 1210, 距离下一级还需 390 积分
签到天数: 17 天连续签到: 1 天[LV.4]偶尔看看III
夜班安排两个人。。上12休36两班倒。。还剩下10个人。。98间房。。不要考虑早中班。。周休一天。。很好分吧。。
小费+0前提是早中晚三班倒,且中班2人,夜班1人。这个是前提~
中级服务员, 积分 55, 距离下一级还需 145 积分
签到天数: 2 天连续签到: 1 天[LV.1]初来乍到
wesley_yy 发表于
夜班安排两个人。。上12休36两班倒。。还剩下10个人。。98间房。。不要考虑早中班。。周休一天。。很好分吧 ...
前提是早中晚三班倒,且中班2人,夜班1人。这个是前提~
小费+0干嘛那么死板。。灵活安排一点。。这么多人 98间房 足够了
你意思是三班倒 都是8小时工作制?
你就做个表,夜班一星期一调换,这周夜班上六天,然后休一天,同时白班某个休完回来的补上一周夜班
中班两人一样,中班
中级服务员, 积分 55, 距离下一级还需 145 积分
签到天数: 2 天连续签到: 1 天[LV.1]初来乍到
大婶指点啊
部门经理[初], 积分 5428, 距离下一级还需 72 积分
签到天数: 725 天连续签到: 7 天[LV.9]以坛为家II
排班大致一樣的,另外要根據酒店本身開房情況來排的
部门主管[中], 积分 2398, 距离下一级还需 502 积分
签到天数: 82 天连续签到: 1 天[LV.6]常住居民II
按75%的平均入住率,每个人打扫15间房计算,你白班需要5个人,中班1个既可,夜班如果前台给力交接给行李生,如果不行,夜班就增加1个人吧。那么每日早5个,中1个,夜1个,轮休1个。8人既可。
提拔一个领班上来,减轻自己工作量,把剩下3个服务员的工作量申请拿出部分来给其他员工做加班费。。。
部门主管[中], 积分 2398, 距离下一级还需 502 积分
签到天数: 82 天连续签到: 1 天[LV.6]常住居民II
我之前管理过一间72间客房的酒店,中班夜班都交接给前台加借物品,晚上6点以后不提供打扫房间服务。就这么简单,刚开始肯定会有点难,我很奇怪的是,你们得有多少服务量?中班需要2个人?
部门主管[中], 积分 2344, 距离下一级还需 556 积分
签到天数: 155 天连续签到: 6 天[LV.7]常住居民III
早中夜班人员是固定的 还是轮流上的?
高级领班, 积分 1210, 距离下一级还需 390 积分
签到天数: 17 天连续签到: 1 天[LV.4]偶尔看看III
zhangbin4732 发表于
前提是早中晚三班倒,且中班2人,夜班1人。这个是前提~
干嘛那么死板。。灵活安排一点。。这么多人 98间房 足够了
你意思是三班倒 都是8小时工作制?
你就做个表,夜班一星期一调换,这周夜班上六天,然后休一天,同时白班某个休完回来的补上一周夜班
中班两人一样,中班和早班一样需要打扫房间,把房间均了,或者你看情况安排其他工作藤本植物导航
&>&&>&&>&正文
关于排班。。。我们总共有五个人上班,分三班倒,早班一人,中班晚班各...统一最后一个夜班休息,那是大歇班,上中班中班下午四点到凌晨12点~
大神帮忙排个三班倒排班方式,分早、中、夜三个班,总共48个人,早班和中班必须16个人,夜班4人,剩
klab.cdef.k.i.a.jklabcd组为白,efgh为中.i:ghij.klab.hij③第三天:cdef.ghij,每人需要抽取自己所在小组(abc)和天组(①②③)在公示的时候.efgh.i.jkl综上,6天为一个轮回。6天中每人可以休息2天。所以.def⑤第五天.c.jkl②第二天,i为晚.fgh④第四天.g.e.lab第七天:abcd,排班前需要做的,jkl为休①第一天.bcd⑥第六天,48人分为abcdefghijkl 12组4个人为一组:ijkl.abcd。例如 第一天abcd.efgh:efgh.ijkl:abcd.efgh,只需要标明几月几日是①还是②。例如五月一日~五月六日,排班①~⑥;五月七日~十二日大神帮忙排个三班倒排班方式,分早、中、夜三个班,总共48个人,早班和中班必须16个人,夜班4人,剩4个人为一组,48人分为abcdefghijkl 12组。例如 第一天abcd.efgh.i.jklabcd组为白,efgh为中,i为晚,jkl为休①第
夜班4人,剩下的可以休息,希望来个逻辑思维大神帮忙排一下,感激不尽大神帮忙排个三班倒排班方式,分早、中,早班和中班必须16个人、夜三个班,总共48个人
关于排班。。。我们总共有五个人上班,分三班倒,早班一人,中班晚班各...统一最后一个夜班休息,那是大歇班,上中班中班下午四点到凌晨12点~共5个人,早班2个,中班1个,夜班1个,还有1个休息。上夜班的第二天要休...因为只有5个人,而且工作日与双休日岗位不同,所以需要分两种班制来运行。工作日按工作班次运行,遇双休日时按双休日班次组合轮班,只要达到下夜班者第二天休息就行,则每个双休都从休一或休三开始组合,如休一+休二,休三+休四,休一+休四,休...实行早班8:00-16:00,中班16:00-24:00,晚班:00:00-8:00最好从早班或者中班找替补。如这个月: A早班,B/C中班(B/C隔天休息),DE晚班 下个月 B早班,C/E中班(C/E隔天休息),AD晚班 以此类推,如果晚班有意见者就把周期改为一个星期,反正对大家都公平。每天8人在班,2人休息。 早班3人,中班3人,夜班2人。上夜班的2个人第二...6天一个循环,上5休1,具体如下: 人员第1天第2天第3天第4天第5天第6天 A早中中夜夜休 B休早中中夜夜 C夜休早中中夜 D夜夜休早中中 E中夜夜休早中 F中中夜夜休早我们的工作比较特殊,需要24小时都有人在岗,但只有三个人上班,如果每...u早班AB中班C晚班D----早AD中B晚C------CD/A/B-----BC/D/A-----AB/C/D七天,半个月倒一次。你们自己决定。甲 乙 丙 八小时班次(三班倒转班,也叫硬转班,无休息,只有早班转夜班可以休息一下) 早班7:00-15:00 中班15:00-23:00 夜班23:00-7:00 甲 早 早 夜 夜 中 中 早 早 乙 中 中 早 早 夜 夜 中 中 丙 夜 夜 中 中 早 早 夜 夜 你也可以一个星期...假设三个人分别为A、B、C,早班(8:00-20:00),晚班(20:00-次日8:00),那么这三个人的班表如下: A:早班 晚班 休息 早班 晚班 休息 …… B:晚班 休息 早班 晚班 休息 早班 …… C:休息 早班 晚班 休息 早班 晚班 …… 能保证当天每时每刻都有人...第一个人第二个人第三个人倒班。 第四个人不倒班,从周一到周5都是白天上班,周6周日休息。 周一 第四个人,早晨上班,工作8小时,下午5点下班。 第一个人,下午5点上班,次日周二早晨下班。 周二 第四个人早晨上班,下午5点下班。 第二个人下午............
种植经验最新
种植经验推荐
& 6种植网 版权所有
渝ICP备号-23免费发布咨询,坐等律师在线服务
需求发布后
10分钟内收到律师在线回复
平均有多个律师参与回复
得到了圆满解决
您的位置: & &
6人三班倒,必须保证早班2人,中班一人,夜班也一人,请问怎么排?
6人三班倒,必须保证早班2人,中班一人,夜班也一人,请问怎么排?
精选优质答案
地区:重庆-长寿区
咨询电话:1307230****
帮助网友:288 次
点赞人数:0 人
将6人分别从1到6编号,排班如下:第一天:早班1和2,中班3,夜班4,5和6休息;第二天:早班5和6,中班1,夜班2,3和4休息;第三天:早班3和4,中班5,夜班6,1和2休息;第四天:早班1和2,中班4,夜班3,5和6休息,第五天:早班5和6,中班2,夜班1,3和4休息,第六天:早班3和4,中班6,夜班5,1和2休息。第七天:与第一天同,轮流即可。
相似优质问题答案
我在一家分店工作了有十三天,说好是两个班制,早班和夜班
地区:重庆-渝北区
咨询电话:
帮助网友:1462 次
点赞人数:2 人
用人单位明显违法,可以去当地劳动部门投诉,要求单位返还13天工资还有经济补偿金
你好,一个企业规定上四班三倒,也就是上两个早班在上
地区:重庆-渝北区
咨询电话:1582380****
帮助网友:511 次
点赞人数:2 人
你好,去劳动监察大队投诉或者申请劳动仲裁。
相关优质咨询
热门法律咨询
最新法律咨询电影剧情导航
&>&&>&&>&正文
早班2人,晚班3人。但是其中有一个员工是周一到周五A班,周六周日休息。...1、特殊人员:上周1-5早班,周6-7休息 2、其他5人: (1)先排出7天的,其中周1-5每人1个早班(休息者次日早班)3个晚班休息1天,周6-7以周5早班和休息者早班,晚班者继续晚班 (2)次周周1上周5-7早班者继续1个早班后转晚班,上周6-7早班者休息......
工作排班表 6个人上班,分早晚2个班次。存在特殊情况。这班怎么排?
工作排班表 6个人上班,分早晚2个班次。存在特殊情况。这班怎么排?1、特殊人员:上周1-5早班,周6-7休息2、其他5人:(1)先排出7天的,其中周1-5每人1个早班(休息者次日早班)3个晚班休息1天,周6-7以周5早班和休
早班2人,晚班3人。但是其中有一个员工是周一到周五A班,周六周日休息。。。
早班2人,晚班3人。但是其中有一个员工是周一到周五A班,周六周日休息。...1、特殊人员:上周1-5早班,周6-7休息 2、其他5人: (1)先排出7天的,其中周1-5每人1个早班(休息者次日早班)3个晚班休息1天,周6-7以周5早班和休息者早班,晚班者继续晚班 (2)次周周1上周5-7早班者继续1个早班后转晚班,上周6-7早班者休息...总共6个人,就做A,B,C,D,E,F,好了。(一个星期7天轮流休息)。每...6人3班倒有两种排法: 其一:每人工作5天,休息1天;每组依次排一个连续的白班,然后连续前班、连续后班,倒两次班。一个工作周期是30天,工作单位总计150个。 其二:每人工作6天,休息1天;每人依次排一个连续的白班,然后连续前班、连续后班,...如何在排班表中快速查找是否有晚班连早班的情况就是早中晚三个班 但不能...不知道你的排班表是长啥样子的,你要说清楚啊,数据是怎么排列的6人排班表 早晚班早班8点到20点晚班12点到0点 一个月休息4天,两人特殊...早班AB中班C晚班D----早AD中B晚C------CD/A/B-----BC/D/A-----AB/C/D七天,半个月倒一次。你们自己决定。目前上班时间是早班九点到晚上六点半,晚班时间是中午12点到晚上九点如果一个班排一个人可以用下图排班: 每个人都是早、晚、休的方式去上班,3天一循环,也就是上2休1,这样也无所谓周六日轮休了,基本公平; 如果还有其他条件请具体说明; 6个人 3个班组 每个班组2个人 3班倒 8-16 16-12 12-08 每个月有4天休息 ...4个人上班要有休息必须要有一个人上4天插班,才可以转的起来,插班人员坚固早班和晚班最忙的时候,这样才会有休息 ,怎加一个就没问题了,加的那个顶休息的人就可以了。有4个客服,每人每周休息1天,时间分别是周五到周一。班次是早班和晚班。这可以用运筹学的知识解决的。 有两种合理方式可供选择。 其一:每人工作5天,休息1天;每组依次排一个连续的白班,然后连续前班、连续后班,倒两次班。一个工作周期是30天,工作单位总计150个。 其二:每人工作6天,休息1天;每人依次排一个连...6人3班倒有两种排法: 其一:每人工作5天,休息1天;每组依次排一个连续的白班,然后连续前班、连续后班,倒两次班。一个工作周期是30天,工作单位总计150个。 其二:每人工作6天,休息1天;每人依次排一个连续的白班,然后连续前班、连续后班,...a.b.c.d我代号 如a。b上早班 c.d上晚班 每周换班的话 周6a.c休息 b上早班 d 上晚班 周日b.d休息 d上白班 a上晚班 换班时间自己可以排12个保安,可以设置队长1人,负责全面保安工作,副队人1人,配合队长工作,白天4人,夜班4人。2个机动,负责顶班,有队员休假,机动就顶上,每天可以休息两2人。队长和副队可以一个负责白天,一个负责晚上带班,也可以轮换,这样单位的安全万无...
台词网 版权所有
渝ICP备号-23由于系统系统调取排班信息,所以安排系统进行排班处理00网排班需求1.共三个个班次,正常班,中班、中长班,中班随机穿插在正常班中,中长班随机穿插在中
班中。2.CD两个分组,每个大组分四个小组,如C1,C2,C3,C4,D1,D2,D3,D4。每日需3个中班,C组2
个中班时,D组1个中班;中班人数分配一周轮换一次。中长班班所需人数共2人,从CD组各
安排一个。3.一个月总休息天数和当月周末数相同,当周周末有上班,只能安排在相邻的两个周休息。
同一人周末两天不可连续上班。每人连续上班天数不得超过5天。4.中长班次日必须为休息或中班。仅在附表一中人员中安排中长班(尽量均等),附表二中人
员不可安排中长班。5.CD组同一天休息总人数不可大于3人,周末除外。6.周末值班人数正常班4人、中班4人、中长班2人。7.遇节假日3天休息,值班3天班次不受周六日影响,3天所上班次相同。
主站排班表需求如果A1、A2组今天是呼入,那A3、A4组就是呼出,呼入呼出是每天轮流的,红人只会出现在呼出组 ,每天3人,一个月大家红人天数均等早班班次安排1个晚班,0个长班。中班班次安排2个晚班,3个长班。晚班及长班包括主站客
服及旺旺客服总和。1.共四个班次,早班,中班,长中班,晚班,早中班按周轮,周日到下周六为一轮,晚班随
机穿插在早中班。2.AB两个分组,每个大组分四个小组,如A1,A2,A3,A4,B1,B2,B3,B4。A组上早班时,B组上中
班,晚班所需人数共N人(N可自行设定),从AB组各安排一半,非双数时中班安排多一个。3.一个月总休息天数和当月周末数相同,当周周末有上班,只能安排在相邻的两个周休息。
同一人周末两天不可连续上班。4.晚班次日必须为休息,长晚班次日必须为晚班或休息。仅在附表一中人员中安排长晚班(
尽量均等),附表二中人员不可安排长晚班,非附表一中其他人员晚班数要求尽量均等。5.1,2小组同一天休息人数不可大于大组人数的1/4,周末除外。3,4小组同样要求。6.周末值班人数可自行设定。7.遇节假日3天休息,A组3天班次不受周六日影响,3天所上班次相同。a.根据周进行AB组早中班交替,之前有排班记录的,要接上之前最后周的来交替b.计算每个人早中晚班上班数量,红人等属性(属性可以后续加)
declare @yearmonth int set @yearmonth=11delete tbCustomerScheduled where yearmonth=@yearmonth
declare @maxleave int set @maxleave=4--设置每天最大休息人数为总人数的 1/@maxleavedeclare
@from datedeclare
@end datedeclare @date datedeclare
@i intdeclare
@count intdeclare @worktype intdelete from tbCustomerScheduledTempset @from=(select fromdate from tbCustomerScheduledRecord where id=@yearmonth)set @end=(select enddate from tbCustomerScheduledRecord where id=@yearmonth)
--begin 顺序排早中班开始,默认AB组循环上早中班,手动排班不变set @from=(select fromdate from tbCustomerScheduledRecord where id=@yearmonth)set @end=(select enddate from tbCustomerScheduledRecord where id=@yearmonth)
--插入手工排班班表begininsert into tbCustomerScheduled(customer,worktype,workday,memo,yearmonth,adddate,handinsert)select customer,worktype,workday,memo,yearmonth,adddate,1 from tbCustomerScheduledHand sdhwhere yearmonth=@yearmonth and not exists(select top 1 1 from tbCustomerScheduled sd1 where sdh.customer=sd1.customer and sd1.workday=sdh.workday and sd1.yearmonth=sdh.yearmonth)
declare @morning varchardeclare @noon varcharset @morning=(select ISNULL((select 'A' from tbCustomerScheduledRecord where id=@yearmonth and ismorning=0),'B'))set @noon = (select case when @morning='A' then 'B' else 'A' end)--;//B组分中班
declare @datetemp date
set @datetemp = @
while (@datetemp &= @end)
if (select
case when datename(weekday,@datetemp)='星期日' then 0
when datename(weekday,@datetemp)='星期一' then 1
when datename(weekday,@datetemp)='星期二' then 2
when datename(weekday,@datetemp)='星期三' then 3
when datename(weekday,@datetemp)='星期四' then 4
when datename(weekday,@datetemp)='星期五' then 5
when datename(weekday,@datetemp)='星期六' then 6
else 0 end)
case when datename(weekday,dateadd(d,-1,@datetemp))='星期日' then 0
when datename(weekday,dateadd(d,-1,@datetemp))='星期一' then 1
when datename(weekday,dateadd(d,-1,@datetemp))='星期二' then 2
when datename(weekday,dateadd(d,-1,@datetemp))='星期三' then 3
when datename(weekday,dateadd(d,-1,@datetemp))='星期四' then 4
when datename(weekday,dateadd(d,-1,@datetemp))='星期五' then 5
when datename(weekday,dateadd(d,-1,@datetemp))='星期六' then 6
else 0 end)
set @morning = @
if @morning='A'
set @noon='B'
set @noon='A'
select @morning
insert into tbCustomerScheduled(customer,worktype,workday,yearmonth)
select wd.customer,(select case when p.CustomerGroupBig=@morning then 1 when p.CustomerGroupBig=@noon then 2 else 1 end ),@datetemp,@yearmonth
from P_User p inner join tbCustomerScheduledWorkDay wd on p.userName=wd.customer
where wd.yearmonth=@yearmonth
and not exists(select top 1 1 from tbCustomerScheduled sd1
where wd.customer=sd1.customer and sd1.workday=@datetemp and sd1.yearmonth=@yearmonth)
set @datetemp = dateadd(d,1,@datetemp)
endend--end 顺序排早中班结束
--排班中班早班旺旺和中民客服分开,分两步排班set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)--begin 排中班开始set @worktype=2
--主站客服 begin--算出主站客服还剩多少天中班未上set @count=(select nooncount-(select COUNT(1) from tbCustomerScheduled d where d.worktype=@worktype and d.yearmonth=@yearmonth and d.workday=tbCustomerScheduledDutyDay.workdate and handinsert=1 and yearmonth=@yearmonth) from tbCustomerScheduledDutyDay where workdate=@date and yearmonth=@yearmonth)delete tbCustomerScheduledTempif @count&0begin --查询出适合上中班的主站客服,且是主站客服 --中班的情况一般是周末,周末不让连着上班 --当天前一天跟当天上班类型一样或者前一天是休息才排班 --前6天不是一直上班的才排班 --前后9天没手动排过早中班的才排班(最大化防止周末连着上班) --假期之前安排过最多的排序上班,防止假期不够排 insert into tbCustomerScheduledTemp(customer) select top (@count) customer
from tbCustomerScheduled sd where sd.worktype=@worktype and handinsert=0 and @date=sd.workday
and sd.yearmonth=@yearmonth and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth
and sd1.workday=dateadd(d,-1,sd.workday) and (sd1.worktype=@worktype or sd1.worktype=0)) and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=sd.customer) and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd.yearmonth=@yearmonth and sd1.workday between dateadd(d,-6,@date) and @date and sd1.worktype&&0)&=6 and not exists(select top 1 1 from tbCustomerScheduled sd2
where handinsert=1 and sd2.yearmonth=@yearmonth and sd.customer=sd2.customer and sd2.worktype in(1,2) and sd2.workday between dateadd(d,-9,@date) and dateadd(d,9,@date)) order by (select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and sd.customer=sd1.customer) desc,NEWID() set @count = @count-@@rowcount
--如果上面条件没找到客服或者客服不够上中班 --排查9天上班限制(周末连着上班) if @count&0 begin
insert into tbCustomerScheduledTemp(customer)
select top (@count) customer
from tbCustomerScheduled sd
where sd.worktype=@worktype and handinsert=0
and @date=sd.workday
and sd.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth
and sd1.workday=dateadd(d,-1,sd.workday) and (sd1.worktype=@worktype or sd1.worktype=0))
and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=sd.customer)
and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth and sd1.workday between dateadd(d,-6,@date) and @date and sd1.worktype&&0)&=6
--and not exists(select top 1 1 from tbCustomerScheduled sd2
--where handinsert=1 and sd.customer=sd2.customer and sd2.worktype in(1,2)
--and sd2.workday between dateadd(d,-9,@date) and dateadd(d,9,@date))
and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=sd.customer)
order by (select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and sd.customer=sd1.customer) desc,NEWID() end
update tbCustomerScheduled set worktype=@worktype,handinsert=1
where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduled set worktype=0
where workday=@date and handinsert=0 and worktype=@worktype and yearmonth=@yearmonth and customer not in(select customer from tbCustomerScheduledTemp)end--主站客服 end
--end 排中班结束
--begin 排早班开始set @worktype=1--主站客服beginset @count=(select morningcount-(select COUNT(1) from tbCustomerScheduled d where d.worktype=@worktype and d.workday=dd.workdate and handinsert=1 and yearmonth=@yearmonth) from tbCustomerScheduledDutyDay dd where workdate=@date and yearmonth=@yearmonth)delete tbCustomerScheduledTempif @count&0begin --跟中班规则一样 insert into tbCustomerScheduledTemp(customer) select top (@count) customer
from tbCustomerScheduled sd where sd.worktype=@worktype and handinsert=0 and @date=sd.workday
and sd.yearmonth=@yearmonth and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer
and sd1.yearmonth=@yearmonth and sd1.workday=dateadd(d,-1,sd.workday) and (sd1.worktype=@worktype or sd1.worktype=0)) and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=sd.customer) and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth and sd1.workday between dateadd(d,-6,@date) and @date and sd1.worktype&&0)&=6 and not exists(select top 1 1 from tbCustomerScheduled sd2
where handinsert=1 and sd2.yearmonth=@yearmonth and sd.customer=sd2.customer and sd2.worktype in(1,2,3) and sd2.workday between dateadd(d,-9,@date) and dateadd(d,9,@date)) order by (select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and sd1.yearmonth=@yearmonth and sd.customer=sd1.customer) desc,NEWID() set @count = @count-@@rowcount
--跟中班规则一样 if @count&0 begin
insert into tbCustomerScheduledTemp(customer)
select top (@count) customer
from tbCustomerScheduled sd
where sd.worktype=@worktype and handinsert=0
and @date=sd.workday
and sd.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer
and sd1.yearmonth=@yearmonth
and sd1.workday=dateadd(d,-1,sd.workday) and (sd1.worktype=@worktype or sd1.worktype=0))
and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=sd.customer)
and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth and sd1.workday between dateadd(d,-6,@date) and @date and sd1.worktype&&0)&=6
--and not exists(select top 1 1 from tbCustomerScheduled sd2
--where handinsert=1 and sd.customer=sd2.customer and sd2.worktype in(1,2,3)
--and sd2.workday between dateadd(d,-9,@date) and dateadd(d,9,@date))
and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=sd.customer)
order by (select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and sd.customer=sd1.customer) desc,NEWID() end
update tbCustomerScheduled set worktype=@worktype,handinsert=1
where workday=@date and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduled set worktype=0 where workday=@date and handinsert=0 and worktype=@worktype and yearmonth=@yearmonth and customer not in(select customer from tbCustomerScheduledTemp)
end --主站客服 end
--早班结束
set @i=@i+1end
--设置每个客服该上晚班的天数update tbCustomerScheduledWorkDay set nightdaytemp=nightday-(select COUNT(1) from tbCustomerScheduled d where d.worktype=3 and d.yearmonth=@yearmonth and d.customer=tbCustomerScheduledWorkDay.customer and yearmonth=@yearmonth) where yearmonth=@yearmonth
--begin 排晚班开始set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)set @worktype=3set @count=(select nightcount-(select COUNT(1) from tbCustomerScheduled d where d.worktype=@worktype and d.yearmonth=@yearmonth and d.workday=tbCustomerScheduledDutyDay.workdate and yearmonth=@yearmonth) from tbCustomerScheduledDutyDay where workdate=@date and yearmonth=@yearmonth)delete tbCustomerScheduledTempif @count&0begin --晚班优先排在6天班之内,且6天班前后不排晚班(最大的减少6天班的存在) --在非手工排班内,安排系统排班的早中班选择晚班 --晚班后一天且不为手工排班 --9天内上过晚班的不排晚班 --晚班还剩最多的排序,假期最少的排序 insert into tbCustomerScheduledTemp(customer) select top (@count) customer
from tbCustomerScheduledWorkDay wk where
wk.nightdaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2)
and handinsert=0 and sd.customer=wk.customer and
@date=sd.workday and sd.yearmonth=@yearmonth and not exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth
and sd1.workday=dateadd(d,1,sd.workday) and sd1.handinsert=1)) and (((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,1,@date) and sd1.worktype&&0)=2 and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer
and sd1.yearmonth=@yearmonth and sd1.workday between dateadd(d,-4,@date) and @date and sd1.worktype&&0)=5) or ((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,2,@date) and sd1.worktype&&0)=3 and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer
and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-3,@date) and @date and sd1.worktype&&0)=4) or ((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer
and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,3,@date) and sd1.worktype&&0)=4 and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer
and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-2,@date) and @date and sd1.worktype&&0)=3) or ((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer
and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,4,@date) and sd1.worktype&&0)=5 and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer
and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-1,@date) and @date and sd1.worktype&&0)=2)
and not exists(select top 1 1 from tbCustomerScheduled sd2 where sd2.customer=wk.customer and sd2.yearmonth=@yearmonth
and sd2.worktype=3 and sd2.workday between dateadd(d,-9,@date) and dateadd(d,9,@date)) and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=wk.customer) order by nightdaytemp desc,(select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and wk.customer=sd1.customer) asc,NEWID()
set @count = @count-@@rowcount
--如果当天的还没有安排完,则往下走 --在非手工排班内,安排系统排班的早中班选择晚班 --晚班后一天且不为手工排班 -- if @count&0 begin
insert into tbCustomerScheduledTemp(customer)
select top (@count) customer
from tbCustomerScheduledWorkDay wk where wk.nightdaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and handinsert=0 and sd.customer=wk.customer and
@date=sd.workday and sd.yearmonth=@yearmonth
and not exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer
and sd1.yearmonth=@yearmonth
and sd.workday=dateadd(d,-1,sd1.workday) and sd1.handinsert=1))
and not exists(select top 1 1 from tbCustomerScheduled sd2 where sd2.customer=wk.customer
and sd2.yearmonth=@yearmonth
and sd2.worktype=3 and sd2.workday between dateadd(d,-9,@date) and dateadd(d,9,@date))
and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=wk.customer)
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.workday=DATEADD(d,1,@date) and sd1.yearmonth=@yearmonth
and sd1.worktype=0 and sd1.handinsert&&1)
--and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.workday=dateadd(d,-5,@date) and sd1.worktype=0)
--and (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.workday between dateadd(d,-4,@date) and @date and sd1.worktype&&0)=5
order by nightdaytemp desc,(select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and wk.customer=sd1.customer) asc,NEWID()
set @count = @count-@@rowcount
if @count&0--如果当天的还没有安排完,则随机安排还剩夜班最多的客服
insert into tbCustomerScheduledTemp(customer)
select top (@count) customer
from tbCustomerScheduledWorkDay wk
where wk.nightdaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd
where sd.worktype in (0,1,2) and handinsert=0
and sd.yearmonth=@yearmonth
and sd.customer=wk.customer and
@date=sd.workday
and not exists(select top 1 1 from tbCustomerScheduled sd1
where sd1.customer=sd.customer
and sd1.yearmonth=@yearmonth
and sd.workday=dateadd(d,-1,sd1.workday) and sd1.handinsert=1 and sd1.worktype not in(0,3)))
and not exists(select top 1 1 from tbCustomerScheduled sd2
where sd2.customer=wk.customer
and sd2.yearmonth=@yearmonth
and sd2.worktype=3 and sd2.workday
between dateadd(d,-9,@date) and dateadd(d,9,@date))
and not exists(select top 1 1 from tbCustomerScheduledTemp tp1 where tp1.customer=wk.customer)
order by (select COUNT(1) from tbCustomerScheduled sd1 where sd1.worktype=0 and sd1.yearmonth=@yearmonth and wk.customer=sd1.customer) asc,nightdaytemp desc,NEWID()
update tbCustomerScheduled set worktype=@worktype,handinsert=1
where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set nightdaytemp=nightdaytemp-1 where customer in(select customer from tbCustomerScheduledTemp)
and yearmonth=@yearmonthend set @i=@i+1end--end 排晚班结束
--begin 晚班之后接着休息日update sd set worktype=0 from (select customer,dateadd(d,1,workday) workday from tbCustomerScheduled sd where worktype=3 and yearmonth=@yearmonth and dateadd(d,1,workday) between (select fromdate from tbCustomerScheduledRecord where id=@yearmonth) and (select enddate from tbCustomerScheduledRecord where id=@yearmonth))sd1 inner join tbCustomerScheduled sd on sd1.customer=sd.customer and sd1.workday=sd.workday and sd.yearmonth=@yearmonth and sd.handinsert=0 --然后计算客服还剩多少假日update tbCustomerScheduledWorkDay set leavedaytemp=leaveday-(select COUNT(1) from tbCustomerScheduled d where d.worktype=0 and d.yearmonth=@yearmonth
and d.customer=tbCustomerScheduledWorkDay.customer and d.yearmonth=@yearmonth) where yearmonth=@yearmonth
--这里处理旺旺客服的休息天数declare @leavecustomer int declare @sexworkcount int--循环查找上班6天的客服,3次应该够了,如果有6天班的情况这里就要多循环几次--或者去安排6天班的第二天休息,这里只安排第三、第四天休息set @sexworkcount=3while @sexworkcount&0 and exists(select top 1 1 from tbCustomerScheduled sdwhere (select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-5,sd.workday) and sd.workday and sd1.worktype&&0)&5 and sd.yearmonth=@yearmonth)begin--排假日日期全部没安排休假的客服全部安排休假set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)set @worktype=0--主站客服 begindelete tbCustomerScheduledTemp--1,2小组同一天休息人数不可大于大组人数的1/@maxleave,周末除外。3,4小组同样要求。--查询出今天能安排的休息人数,对于周末已经安排了--主站客服休息人数set @leavecustomer=(select COUNT(1) from tbCustomerScheduled sd where worktype=0 and sd.workday=@date and sd.yearmonth=@yearmonth )--休息人数
--主站客服,最大可休息人数set @count=(select COUNT(1) from tbCustomerScheduledWorkDay where yearmonth=@yearmonth)/@maxleave-@leavecustomer--有没排班主站客服的且最大休息人数大于0就去寻找最优休息客服if @count&0 and (select COUNT(1) from tbCustomerScheduled sd where handinsert=0 and sd.yearmonth=@yearmonth )&0begin --前后有连续上班6天的,如果当天不是手动排班,设置休息日。如果客服有休息日的时候
insert into tbCustomerScheduledTemp(customer) select * from (select top (cast((round(@count/2.0,0)) as int)) customer
from tbCustomerScheduledWorkDay wk where leavedaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and sd.yearmonth=@yearmonth
and handinsert=0 and wk.customer=sd.customer and sd.workday=@date)
and(((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-2,@date) and @date and sd1.worktype&&0)=3 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,3,@date) and sd1.worktype&&0)=4) or((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-3,@date) and @date and sd1.worktype&&0)=4 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,2,@date) and sd1.worktype&&0)=3) or((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-1,@date) and @date and sd1.worktype&&0)=2 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,4,@date) and sd1.worktype&&0)=5) or((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-4,@date) and @date and sd1.worktype&&0)=5 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,1,@date) and sd1.worktype&&0)=2) ) and exists(select top 1 1 from P_User u1 where u1.userName=wk.customer and u1.CustomerGroupBig='A') union select top (cast((round(@count/2.0,0)) as int)) customer
from tbCustomerScheduledWorkDay wk where leavedaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and sd.yearmonth=@yearmonth
and handinsert=0 and wk.customer=sd.customer and sd.workday=@date) and(((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-2,@date) and @date and sd1.worktype&&0)=3 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,3,@date) and sd1.worktype&&0)=4) or((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-3,@date) and @date and sd1.worktype&&0)=4 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,2,@date) and sd1.worktype&&0)=3) or((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-1,@date) and @date and sd1.worktype&&0)=2 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,4,@date) and sd1.worktype&&0)=5) or((select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between dateadd(d,-4,@date) and @date and sd1.worktype&&0)=5 and(select COUNT(1) from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and sd1.workday between @date and dateadd(d,1,@date) and sd1.worktype&&0)=2) ) and exists(select top 1 1 from P_User u1 where u1.userName=wk.customer and u1.CustomerGroupBig='B'))a order by NEWID()
delete tbCustomerScheduledTemp where
customer not in(select top (@count) customer from tbCustomerScheduledTemp order by NEWID())
update tbCustomerScheduled set worktype=@worktype
where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set leavedaytemp=leavedaytemp-1 where customer in(select customer from tbCustomerScheduledTemp) and yearmonth=@yearmonthend --主站客服end
set @i=@i+1end
set @sexworkcount=@sexworkcount-1end--end 排假日结束
--排假日日期全部没安排休假的客服全部安排休假set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)set @worktype=0--主站客服 begindelete tbCustomerScheduledTemp--1,2小组同一天休息人数不可大于大组人数的1/@maxleave,周末除外。3,4小组同样要求。--查询出今天能安排的休息人数,对于周末已经安排了--declare @workcustomer int set @leavecustomer=(select COUNT(1) from tbCustomerScheduled sd where worktype=0 and sd.workday=@date and sd.yearmonth=@yearmonth )--休息人数
--最大可休息人数set @count=(select COUNT(1) from tbCustomerScheduledWorkDay where yearmonth=@yearmonth )/@maxleave-@leavecustomer--有没排班的且最大休息人数大于0就去寻找最优休息客服if @count&0 and (select COUNT(1) from tbCustomerScheduled where handinsert=0
and yearmonth=@yearmonth )&0begin --这里优先安排休息日之后再休息 insert into tbCustomerScheduledTemp(customer) select * from (select top (cast((round(@count/2.0,0)) as int)) customer
from tbCustomerScheduledWorkDay wk where leavedaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and sd.yearmonth=@yearmonth
and handinsert=0 and wk.customer=sd.customer and sd.workday=@date)
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and (sd1.workday =DATEADD(d,-1, @date) or sd1.workday =DATEADD(d,1, @date)) and sd1.worktype=0) and exists(select top 1 1 from P_User u1 where u1.userName=wk.customer and u1.CustomerGroupBig='A') union
select top (cast((round(@count/2.0,0)) as int)) customer
from tbCustomerScheduledWorkDay wk where leavedaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and sd.yearmonth=@yearmonth
and handinsert=0 and wk.customer=sd.customer and sd.workday=@date)
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and (sd1.workday =DATEADD(d,-1, @date) or sd1.workday =DATEADD(d,1, @date)) and sd1.worktype=0) and exists(select top 1 1 from P_User u1 where u1.userName=wk.customer and u1.CustomerGroupBig='B'))a order by NEWID()
delete tbCustomerScheduledTemp where
customer not in(select top (@count) customer from tbCustomerScheduledTemp order by NEWID())
update tbCustomerScheduled set worktype=@worktype
where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set leavedaytemp=leavedaytemp-1 where customer in(select customer from tbCustomerScheduledTemp) and yearmonth=@yearmonthend --主站客服 end
set @i=@i+1end--end 排假日结束
--排假日日期全部没安排休假的客服全部安排休假--防止还有人没安排休假的情况,随机安排set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)set @worktype=0--主站客服 begindelete tbCustomerScheduledTemp--1,2小组同一天休息人数不可大于大组人数的1/@maxleave,周末除外。3,4小组同样要求。--查询出今天能安排的休息人数,对于周末已经安排了--declare @workcustomer int set @leavecustomer=(select COUNT(1) from tbCustomerScheduled sd where worktype=0 and sd.workday=@date and sd.yearmonth=@yearmonth )--休息人数
--最大可休息人数set @count=(select COUNT(1) from tbCustomerScheduledWorkDay where yearmonth=@yearmonth )/@maxleave-@leavecustomer--有没排班的且最大休息人数大于0就去寻找最优休息客服if @count&0 and (select COUNT(1) from tbCustomerScheduled where handinsert=0
and yearmonth=@yearmonth )&0begin --这里优先安排休息日之后再休息 insert into tbCustomerScheduledTemp(customer) select * from (select top (cast((round(@count/2.0,0)) as int)) customer
from tbCustomerScheduledWorkDay wk where leavedaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and sd.yearmonth=@yearmonth
and handinsert=0 and wk.customer=sd.customer and sd.workday=@date)
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=wk.customer and sd1.yearmonth=@yearmonth
and (sd1.workday =DATEADD(d,-1, @date) or sd1.workday =DATEADD(d,1, @date)) and sd1.worktype=0) and exists(select top 1 1 from P_User u1 where u1.userName=wk.customer and u1.CustomerGroupBig='A') union
select top (cast((round(@count/2.0,0)) as int)) customer
from tbCustomerScheduledWorkDay wk where leavedaytemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype in (1,2) and sd.yearmonth=@yearmonth
and handinsert=0 and wk.customer=sd.customer and sd.workday=@date)
--and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=wk.customer and (sd1.workday =DATEADD(d,-1, @date) or sd1.workday =DATEADD(d,1, @date)) and sd1.worktype=0) and exists(select top 1 1 from P_User u1 where u1.userName=wk.customer and u1.CustomerGroupBig='B'))a order by NEWID()
delete tbCustomerScheduledTemp where
customer not in(select top (@count) customer from tbCustomerScheduledTemp order by NEWID())
update tbCustomerScheduled set worktype=@worktype
where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set leavedaytemp=leavedaytemp-1 where customer in(select customer from tbCustomerScheduledTemp) and yearmonth=@yearmonthend --主站客服 end
set @i=@i+1end--end 排假日结束 --中长班 begin--设置每个客服该上中长班的天数,使用longnoontemp做临时变量使用update tbCustomerScheduledWorkDay set longnoontemp=longnoon-(select COUNT(1) from tbCustomerScheduled d where d.longnoon&&0 and d.customer=tbCustomerScheduledWorkDay.customer and yearmonth=@yearmonth) where yearmonth=@yearmonth
set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)set @count=(select longnooncount-(select COUNT(1) from tbCustomerScheduled d where d.longnoon&&0 and d.workday=tbCustomerScheduledDutyDay.workdate and yearmonth=@yearmonth) from tbCustomerScheduledDutyDay where workdate=@date and yearmonth=@yearmonth)delete tbCustomerScheduledTempif @count&0begin --选择当天是中班的客服 --优先排班后一天是休息的客服 --中长班还剩最多的排序 insert into tbCustomerScheduledTemp(customer) select top (@count) customer
from tbCustomerScheduledWorkDay wk where
wk.longnoontemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype=2 and sd.customer=wk.customer and
@date=sd.workday and sd.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd1 where sd1.customer=sd.customer and sd1.yearmonth=@yearmonth
and sd1.workday=dateadd(d,1,sd.workday) and sd1.worktype in(0,3)))
order by longnoontemp desc,NEWID()
set @count = @count-@@rowcount
--如果当天的还没有安排完,则往下走 --在非手工排班内选择当天是中班的客服 --次之,排班,后一天是中中班的客服 --中长班还剩最多的排序 if @count&0 begin
insert into tbCustomerScheduledTemp(customer)
select top (@count) customer
from tbCustomerScheduledWorkDay wk where
wk.longnoontemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype=2
and sd.customer=wk.customer and
@date=sd.workday and sd.yearmonth=@yearmonth
and not exists(select top 1 1 from tbCustomerScheduled sd1
where sd1.customer=sd.customer
and sd1.yearmonth=@yearmonth
and sd1.workday=dateadd(d,1,sd.workday) and sd1.worktype in(0,1,3)))
order by longnoontemp desc,NEWID() end
update tbCustomerScheduled set longnoon=1 where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set longnoontemp=longnoontemp-1 where customer in(select customer from tbCustomerScheduledTemp)
and yearmonth=@yearmonthend set @i=@i+1end
end--中长班
/*--红人 早班红人,中班红人 begin--设置每个客服该上红人的天数,使用isredtemp做临时变量使用update tbCustomerScheduledWorkDay set isredtemp=isred-(select COUNT(1) from tbCustomerScheduled d where d.isred&&0 and d.customer=tbCustomerScheduledWorkDay.customer
and yearmonth=@yearmonth) where yearmonth=@yearmonth
set @i=0while @i&=DATEDIFF(d,@from,@end)beginset @date=DATEADD(d,@i,@from)
--早班红人开始beginset @count=(select isredcount-(select COUNT(1) from tbCustomerScheduled d where d.isred&&0 and d.workday=tbCustomerScheduledDutyDay.workdate and d.worktype=1 and yearmonth=@yearmonth) from tbCustomerScheduledDutyDay where workdate=@date and yearmonth=@yearmonth)delete tbCustomerScheduledTempif @count&0begin --选择当天是早班的客服 --红人还剩最多的排序 insert into tbCustomerScheduledTemp(customer) select top (@count) customer
from tbCustomerScheduledWorkDay wk where
wk.isredtemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype=1
and sd.customer=wk.customer and
@date=sd.workday)
order by isredtemp desc,NEWID()
update tbCustomerScheduled set isred=1 where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set isredtemp=isredtemp-1 where customer in(select customer from tbCustomerScheduledTemp)
and yearmonth=@yearmonthend end --早班结束
--中班红人开始beginset @count=(select isrednooncount-(select COUNT(1) from tbCustomerScheduled d where d.isred&&0 and d.workday=tbCustomerScheduledDutyDay.workdate and d.worktype=2 and yearmonth=@yearmonth) from tbCustomerScheduledDutyDay where workdate=@date and yearmonth=@yearmonth)delete tbCustomerScheduledTempif @count&0begin --选择当天是中班的客服 --红人还剩最多的排序 insert into tbCustomerScheduledTemp(customer) select top (@count) customer
from tbCustomerScheduledWorkDay wk where
wk.isredtemp&0 and wk.yearmonth=@yearmonth
and exists(select top 1 1 from tbCustomerScheduled sd where sd.worktype=2 and sd.customer=wk.customer and
@date=sd.workday)
order by isredtemp desc,NEWID()
update tbCustomerScheduled set isred=1
where workday=@date
and yearmonth=@yearmonth and customer in(select customer from tbCustomerScheduledTemp)
update tbCustomerScheduledWorkDay set isredtemp=isredtemp-1 where customer in(select customer from tbCustomerScheduledTemp)
and yearmonth=@yearmonthend end --中班红人结束
set @i=@i+1end
end--红人 */
支持原创:如有问题或者不同见解请联系
阅读(...) 评论()

我要回帖

更多关于 中班区域活动观察记录 的文章

 

随机推荐