关于值班打点的存储进程
发布时间:2018-08-20 16:26:59 所属栏目:电商 来源:站长网
导读:一个bt主任的要求 值班打点 要求如下 1 一组行列 n 小我私人, 有4种脚色,率领,夫君,大妈,司机。n小我私纪獯照本身脚色按次序排好队 2 值班要求:周一到周日 1个率领值班1个司机值班;周一到周日 每晚1个夫君 值班;周六 周日 上午下战书2个大妈值班;假期天天1
一个bt主任的要求 值班打点 要求如下 1 一组行列 n 小我私人, 有4种脚色,率领,夫君,大妈,司机。n小我私纪獯照本身脚色按次序排好队 2 值班要求:周一到周日 1个率领值班1个司机值班;周一到周日 每晚1个夫君 值班;周六 周日 上午下战书2个大妈值班;假期天天1个率领1个司机1个夫君上午下战书2个大妈 3 要求行列可增删查该 ,职员次序可以调解,行列产生变革时,值班表自动更新 4 要求行列职员随时可以抽调对列中的职员不介入本轮排序(出差或告假)下轮继承按行列次序排序,职员抽调后 ,行列自动向前顶替 5 调班等... 建2个表 1 watching [datetime] 日期 [weekday]礼拜 [leaderid]率领id [maleid]夫君id [female1]大妈1id [female2]大妈2id [driverid] 司机id [mark]备注 2 watching_person [ordercode]职员编号 [personid] 职员id [part]职员脚色 [leave]是否分开 [mark]备注 part 为职员脚色 1率领2夫君3大妈4司机 当新的行列发生时必要更细从来日诰日往后的值班布置表(此处为30天),然后将 按脚色列队好的 起始位置传给存储进程 (即 领到从第几位开始排 司机从第几位开始排 夫君 大妈...) create proc Proc_WatchingSetup --参数为四种脚色的起始位置 @leader int, @Male int, @Female int, @Driver intas declare @i int --计数器declare @j intdeclare @PersonID intdeclare @weekday intdeclare @InsertPoint datetimedeclare @msg char(20) set @i=1set @j=1 -- 事宜开始Begin tran ReChange--删除来日诰日往后的记录(行列已改变删除早年的)delete from Watching where [Datetime]>GetDate() if (@@error <>0) Begin rollback tran set @msg='error1' return end --从头插入后30天的日期和礼拜while @i<=30 begin insert Watching (Datetime,WeekDay) values (dateadd(day,@i,{fn curdate()}),datepart(weekday,dateadd(day,@i,{fn curdate()}))) set @i=@i+1 end if (@@error !=0) Begin rollback tran set @msg='error2' return end --开始行使游标 set @j=1 --////起首按列队次序读出率领的行列 declare cur_watchingPerson scroll cursor For select Personid from watching_person where part=1 order by orderCode asc open cur_watchingPerson --移动到开始位置fetch absolute @leader from cur_watchingPerson into @PersonIDif @@fetch_status=-1 fetch first from cur_watchingperson into @PersonID set @i=1 while @i<=30 begin while @j<=7 --最长也许是1人插入7天 begin update watching set LeaderId=@PersonID where [datetime]=(dateadd(day,@i,{fn curdate()})) if (@@error !=0) Begin rollback tran set @msg='error3' return end --假如不敷7天就到周末 退出轮回 换人 select @weekday=datepart(weekday,dateadd(day,@i,{fn curdate()})) set @i=@i+1 if (@weekday=1) break end set @j=1 fetch next from cur_watchingperson into @PersonID -- 假如超出界线 转头行列第一位 if @@fetch_status=-1 fetch first from cur_watchingperson into @PersonID end Close cur_watchingPersondeallocate cur_watchingPerson --////////////司机很率领完全一样declare cur_watchingPerson4 scroll cursor For select Personid from watching_person where part=4 order by orderCode asc open cur_watchingPerson4 --移动到开始位置fetch absolute @driver from cur_watchingPerson4 into @PersonIDif @@fetch_status=-1 fetch first from cur_watchingperson4 into @PersonID set @i=1 while @i<=30 begin while @j<=7 --最长也许是1人插入7天 begin update watching set driverId=@PersonID where [datetime]=(dateadd(day,@i,{fn curdate()})) if (@@error !=0) Begin --rollback tran set @msg='error3' return end select @weekday=datepart(weekday,dateadd(day,@i,{fn curdate()})) set @i=@i+1 if (@weekday=1) break end set @j=1 fetch next from cur_watchingperson4 into @PersonID -- 假如超出界线 转头行列第一位 if @@fetch_status=-1 fetch first from cur_watchingperson4 into @PersonID end Close cur_watchingPerson4deallocate cur_watchingPerson4 --/////////// --夫君天天1人值夜班 相对轻易declare cur_watchingPerson2 scroll cursor For select Personid from watching_person where part=2 order by orderCode asc open cur_watchingPerson2 --移动到开始位置fetch absolute @male from cur_watchingPerson2 into @PersonIDif @@fetch_status=-1 fetch first from cur_watchingperson2 into @PersonID set @i=1 while @i<=30 begin update watching set MaleId=@PersonID where [datetime]=(dateadd(day,@i,{fn curdate()})) if (@@error !=0) Begin rollback tran set @msg='error3' return end set @i=@i+1 fetch next from cur_watchingperson2 into @PersonID -- 假如超出界线 转头行列第一位 if @@fetch_status=-1 fetch first from cur_watchingperson2 into @PersonID end Close cur_watchingPerson2deallocate cur_watchingPerson2 --大妈每周六周日2人值白班declare cur_watchingPerson3 scroll cursor For select Personid from watching_person where part=3 order by orderCode asc open cur_watchingPerson3 fetch absolute @female from cur_watchingPerson3 into @PersonIDif @@fetch_status=-1 fetch first from cur_watchingperson3 into @PersonID set @i=1 while @i<=30 begin select @weekday=[weekday] from watching where [datetime]=(dateadd(day,@i,{fn curdate()})) --判定 只有周末的半天才值班 布置2人 if @weekday=7 or @weekday=1 begin --插入第一位 update watching set Female1=@PersonID where [datetime]=(dateadd(day,@i,{fn curdate()})) if (@@error !=0) Begin rollback tran set @msg='error3' return end fetch next from cur_watchingperson3 into @PersonID -- 假如超出界线 转头行列第一位 if @@fetch_status=-1 fetch first from cur_watchingperson3 into @PersonID --插入第二位 update watching set Female2=@PersonID where [datetime]=(dateadd(day,@i,{fn curdate()})) if (@@error !=0) Begin --rollback tran set @msg='error3' return end end set @i=@i+1 fetch next from cur_watchingperson3 into @PersonID -- 假如超出界线 转头行列第一位 if @@fetch_status=-1 fetch first from cur_watchingperson3 into @PersonID end Close cur_watchingPerson3deallocate cur_watchingPerson3 commit tran 以上为行列改变时天生新值班布置的存储进程 其他 诸如 划定假期 调解职员 大同小异 接待品评指正 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |