declare @AssStuId varchar(20) = '51000096',
@ScoreSource varchar(20) = '一体化考核',
@CreateId varchar(20) = '123456789'
declare ExpTempCursor cursor for
select
i.StuID
,cls.BeginDate,cls.EndDate
,isnull(((s.LLScore * 0.3) + (s.SCScore * 0.7)),0) as TotalScore
,pro.Name as ProfessionName
,m.ModuleName
,post.Layer,cls.ItemID,post.ClassRoomTypeID
from PT_ClassStu s inner join PT_StuInfo i on i.StuID=s.StuID
inner join PT_Class as cls on s.ClassID = cls.ClassID
inner join PT_Module as m on cls.ModuleID = m.ModuleID
inner join PT_Post as post on m.PostID = post.PostID
inner join PT_Profession as pro on post.ProfessionID = pro.ProfessionID
where s.StuID = @AssStuId
and isnull(((s.LLScore * 0.3) + (s.SCScore * 0.7)),0) > 60
open ExpTempCursor
declare @StuID varchar(20),@BeginDate date,@EndDate date
declare @TotalScore float,@ProfessionName varchar(50)
declare @ModuleName varchar(100),@Layer int,@ItemId varchar(20)
declare @TranError int = 0,@expCount int,@ExperienceName varchar(200),@ClassRoomId int
fetch next from ExpTempCursor
into @StuID,@BeginDate,@EndDate,@TotalScore,@ProfessionName,@ModuleName,@Layer,@ItemId,@ClassRoomId
while(@@FETCH_STATUS = 0)
begin
set @ExperienceName = @ProfessionName + '(' + @ModuleName + ')'
select @expCount = Count(ExperienceInfoId)
from CER_ExperienceInfo
where StuInfoId = @StuID
and ExperienceName = @ExperienceName
and LevelNo = @Layer + ''
and BeginDate = @BeginDate
and EndDate = @EndDate
if(@expCount = 0)
begin
begin tran Tran_ImportFunc
begin try
--插入实训信息
insert into CER_ExperienceInfo(StuInfoId,ExperienceName,LevelNo,BeginDate,EndDate
,TotalSocre,GradeSource,StateStatistical,CreateDate,CreateId,Remark)
values(@StuID,@ExperienceName,@Layer + '',@BeginDate,@EndDate,@TotalScore,@ScoreSource
,1,CURRENT_TIMESTAMP,@CreateId,'')
declare @expId int
select @expId=SCOPE_IDENTITY()
--插入任务信息
declare taskCursor cursor for
select TaskName,m.ModuleId,tv.SXPeriod
from PT_Module m
left outer join PT_Item i on m.ModuleID=i.ModuleID
left outer join PT_TaskItem ti on i.itemId=ti.ItemId
left outer join PT_Task t on t.TaskID=ti.TaskID
left outer join PT_TaskVersion tv on t.TaskID=tv.TaskID and tv.IsCurrent=1
where i.ItemId = @ItemId
open taskCursor
declare @TaskName varchar(50),@ModuleId varchar(20),@ClassHour float
while(@@FETCH_STATUS = 0)
begin
fetch next from taskCursor into @TaskName,@ModuleId,@ClassHour
insert into CER_Task(ExperienceInfoId,TaskName,ClassHour,ModuleID,Remark)
values(@expId,@TaskName,@ClassHour,@ModuleId,'')
end
close taskCursor
deallocate taskCursor
declare @CerNo varchar(15)
declare @RoomName varchar(400),@RoomCode varchar(2)
select @RoomName = Name from SYS_Column where CId = @ClassRoomId
select @RoomCode = case @RoomName
when '智能楼宇实训中心' then '01'
when '工业自动化控制实训中心' then '02'
when '现代汽车维修实训中心' then '03'
when '现代汽车维修实训中心' then '04'
when '数控加工实训中心' then '05'
when '数字印刷实训中心' then '06'
when '会展技术实训中心' then '07'
else '01' end
declare @LayerCode varchar(1)
select @LayerCode = case @Layer
when 0 then '4'
when 1 then '3'
when 2 then '2'
when 3 then '1'
else '1' end
declare @Counts int,@CerNumber varchar(4) = '0000'
select @Counts = Count(LicenceDate)
from CER_Certificate
where DATEPART(YEAR, LicenceDate) = DATEPART(YEAR, CURRENT_TIMESTAMP)
set @Counts = @Counts + 1
set @CerNumber = case LEN(@Counts)
when 1 then '000'+cast(@Counts as varchar)
when 2 then '00'+cast(@Counts as varchar)
when 3 then '0'+cast(@Counts as varchar)
when 4 then cast(@Counts as varchar)
else '0000' end
set @CerNo = 'GXJY' + cast(DATEPART(YEAR, GETDATE()) as varchar(4)) + @RoomCode + @LayerCode + @CerNumber
--插入证书编号
insert into CER_Certificate(StuId,ExperienceInfoId,LicenceDate,CerCode,CreateId,CreateDate,Remark)
values(@StuID,@expId,CURRENT_TIMESTAMP,@CerNo,@CreateId,CURRENT_TIMESTAMP,'')
end try
BEGIN CATCH
PRINT '出现异常,错误编号:' + convert(varchar,error_number()) + ',错误消息:' + error_message()
SET @TranError = @TranError + 1
END CATCH
IF(@TranError > 0)
BEGIN
--执行出错,回滚事务
ROLLBACK TRAN;
PRINT '导入失败!';
END
ELSE
BEGIN
--没有异常,提交事务
COMMIT TRAN;
PRINT '导入成功!';
END
end
fetch next from ExpTempCursor
into @StuID,@BeginDate,@EndDate,@TotalScore,@ProfessionName,@ModuleName,@Layer,@ItemId,@ClassRoomId
end
close ExpTempCursor
deallocate ExpTempCursor