update lect set ,status=#status#,oktime=case when oktime is null and #status# = 4 and status<>4 then now() else oktime end where lectno=#lectno# and status in (3,4,5);
update pay a
inner join lect b on b.lectno=#lectno# and b.payno=a.payno and b.status in (4,5)
set a.pstatus=case when b.status = 4 then 21 else 52 end
where a.pstatus=51;
update payitem a
inner join lect b on b.lectno=#lectno# and b.pino=a.pino and b.status in (4,5)
set a.pstatus=case when b.status=4 then 21 else 52 end
where a.pstatus=51
update lect set
,ischanged=1
where lectno=#lectno#;
insert into lect (cmno,payno,pino,userno,status,iscomplete,orgcmno,attrate,isrebate,ispc,isjoin,fgno,ischanged,)
select #cmno#,payno,pino,userno,status,null,cmno,0,isrebate,ispc,isjoin,fgno,0,
from lect a
where a.lectno=#lectno#
insert into scdlectlog (userno,scdno,dday,dtime,istalk,isemail,isuse,)
select #uno#,scdno,dday,dtime,istalk,isemail,isuse,
from scdlect;
update scdlect a
inner join (
select #Ds[].scdno# scdno,#Ds[].dday# dday,#Ds[].dtime# dtime,#Ds[].istalk# istalk,#Ds[].isemail# isemail,#Ds[].isuse# isuse
) b on b.scdno=a.scdno
set a.dday=b.dday,a.dtime=b.dtime,a.istalk=b.istalk,a.isemail=b.isemail,a.isuse=b.isuse,a.udt=,a.uno=#uno#,a.uip=#uip#;
insert into scdlect (scdno,dday,dtime,istalk,isemail,isuse,)
select a.scdno,a.dday,a.dtime,a.istalk,a.isemail,a.isuse,
from (
select #Ds[].scdno# scdno,#Ds[].dday# dday,#Ds[].dtime# dtime,#Ds[].istalk# istalk,#Ds[].isemail# isemail,#Ds[].isuse# isuse
) a
left outer join scdlect b on b.scdno=a.scdno
where b.scdno is null
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.cmno cmexno,b.cname,null stime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char) email,CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char) mobile
,null place
from scdlect a
inner join cm b on b.ismaster=0 and date_format(b.setime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.cshape in (0,2) and b.isuse=1 and b.isdel=0
inner join lect c on c.cmno=b.cmno and c.attrate < 80 and c.status=1 and c.ischanged=0
inner join users d on d.userno=c.userno and d.status=1
where a.scdno < 3 and a.isuse=1 and a.dtime=#dtime#
union all
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.cmno cmexno,b.cname,null stime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char) email,CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char) mobile
,null place
from scdlect a
inner join cm b on b.ismaster=0 and date_format(b.setime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.cshape in (0,2) and b.isuse=1 and b.isdel=0
inner join lect c on c.cmno=b.cmno and c.status=1 and c.ischanged=0
inner join users d on d.userno=c.userno and d.status=1
inner join cmex e on e.cmno=c.cmno and e.extype=case when a.scdno=3 then 0 else 1 end and e.isdel=0
left outer join lectex f on f.lectno=c.lectno and f.exno=e.exno
where a.scdno > 2 and a.scdno < 5 and a.isuse=1 and a.dtime=#dtime# and f.lectno is null
union all
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.cmno cmexno,b.cname,null stime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char) email,CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char) mobile
,null place
from scdlect a
inner join cm b on b.ismaster=0 and date_format(b.setime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.cshape in (0,2) and b.isuse=1 and b.isdel=0
inner join lect c on c.cmno=b.cmno and c.status=1 and c.ischanged=0
inner join users d on d.userno=c.userno and d.status=1
inner join cmsd e on e.cmno=c.cmno and e.sdtype=0 and e.isdel=0
left outer join lectsd f on f.lectno=c.lectno and f.sdno=e.sdno
where a.scdno=5 and a.isuse=1 and a.dtime=#dtime# and f.lectno is null
union all
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.cmno cmexno,b.cname,null stime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char) email,CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char) mobile
,null place
from scdlect a
inner join cm b on b.ismaster=0 and date_format(b.setime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.cshape in (0,2) and b.isuse=1 and b.isdel=0
inner join lect c on c.cmno=b.cmno and c.status=1 and c.ischanged=0
inner join users d on d.userno=c.userno and d.status=1
inner join cmsd e on e.cmno=c.cmno and e.sdtype=1 and e.isdel=0
left outer join lectsd f on f.lectno=c.lectno and f.sdno=e.sdno
where a.scdno=6 and a.isuse=1 and a.dtime=#dtime# and f.lectno is null
union all
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.cmno cmexno,b.cname,null stime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char) email,CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char) mobile
,null place
from scdlect a
inner join cm b on b.ismaster=0 and date_format(b.setime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.cshape in (0,2) and b.isuse=1 and b.isdel=0
inner join lect c on c.cmno=b.cmno and c.status=1 and c.ischanged=0
inner join users d on d.userno=c.userno and d.status=1
inner join cmrs e on e.cmno=c.cmno and e.rstype=0 and e.isdel=0
left outer join lectrs f on f.lectno=c.lectno and f.rsno=e.rsno
where a.scdno=7 and a.isuse=1 and a.dtime=#dtime# and f.lectno is null
union all
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.cmno cmexno,b.cname,b.sstime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char),CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char)
,bc.cname place
from scdlect a
inner join cm b on b.ismaster=0 and date_format(b.sstime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.cshape =1 and b.isuse=1 and b.isdel=0
left outer join comcode bc on bc.ccode=b.studyplace
inner join lect c on c.cmno=b.cmno and c.status=1 and c.ischanged=0
inner join users d on d.userno=c.userno and d.status=1
where a.scdno=8 and a.isuse=1 and a.dtime=#dtime#
union all
select a.scdno,a.dday,a.istalk,a.isemail
,d.userno,d.username
,b.exno cmexno,b.exname cname,b.estime
,CAST(AES_DECRYPT(UNHEX(d.email), ) AS char),CAST(AES_DECRYPT(UNHEX(d.mobile), ) AS char)
,b.elocation place
from scdlect a
inner join exam b on date_format(b.estime,'%Y%m%d')=date_format(date_add(now(), interval a.dday day), '%Y%m%d') and b.isopen=1
inner join examuser c on c.exno=b.exno and c.status=1 and c.pstatus=1
inner join users d on d.userno=c.userno and d.status=1
where a.scdno=9 and a.isuse=1 and a.dtime=#dtime#
update lectex set estart=null,eend=null,eip=null,tpoint=0,recount=recount+1,entercount=0,cblock=0 where lectno=#lectno# and exno=#exno#;
update lectexq a
inner join cmex b on b.exno=a.exno and b.eqtype=0
set a.atext=null,a.qinos=null,a.cpoint=0,a.iscorrect=null
where a.lectno=#lectno# and a.exno=#exno#;
delete from lectexq where lectno=#lectno# and exno=#exno# and eqno in (
select a.eqno
from (
select b.eqno
from cmex a
inner join lectexq b on b.lectno=#lectno# and b.exno=a.exno
where a.exno=#exno# and a.eqtype=1
) a
);
insert into lectexq (lectno,exno,eqno,cpoint,dpoint,qseq,)
select a.lectno,a.exno,a.eqno,0,a.rpoint,row_number() over(order by case when a.israndq=0 then a.qseq else rand() end),
from (
select a.*
from (
select a.lectno,a.exno,d.eqno,c.israndq,el.qcount,d.rpoint,d.qseq,rank() over(partition by el.qdiff,el.cc1,el.cc2,el.cc3,el.cc4,el.cc5 order by rand()) rank
from (select #lectno# lectno, #exno# exno) a
left outer join lectex b on b.lectno=a.lectno and b.exno=a.exno
inner join cmex c on c.exno=a.exno and c.eqtype=1
inner join cmexlayer el on el.exno=c.exno and el.qcount > 0
inner join cmexq d on d.exno=el.exno
inner join question e on e.qno=d.qno
and e.qdiff=case when el.qdiff=0 then e.qdiff else el.qdiff end
and e.cc1=case when el.cc1=0 then e.cc1 else el.cc1 end
and e.cc2=case when el.cc2=0 then e.cc2 else el.cc2 end
and e.cc3=case when el.cc3=0 then e.cc3 else el.cc3 end
and e.cc4=case when el.cc4=0 then e.cc4 else el.cc4 end
and e.cc5=case when el.cc5=0 then e.cc5 else el.cc5 end
) a
where a.rank <= a.qcount
) a
order by rand();
insert into lectexq (lectno,exno,eqno,cpoint,dpoint,qseq,)
select a.lectno,a.exno,d.eqno,0,d.rpoint,row_number() over(order by case when c.israndq=0 then d.qseq else rand() * d.qseq end),
from (select #lectno# lectno, #exno# exno) a
inner join lect a2 on a2.lectno=a.lectno and a2.userno=#userno#
left outer join lectex b on b.lectno=a.lectno and b.exno=a.exno
inner join cmex c on c.exno=a.exno and c.eqtype=0
inner join cmexq d on d.exno=c.exno
inner join (
select count(b.lectno) exq
from (select 1 col1) a
left outer join lectexq b on b.lectno=#lectno# and b.exno=#exno#
) z on z.exq < 1
where b.lectno is null
order by rand();
insert into lectexq (lectno,exno,eqno,cpoint,dpoint,qseq,)
select a.lectno,a.exno,a.eqno,0,a.rpoint,row_number() over(order by case when a.israndq=0 then a.qseq else rand() end),
from (
select a.lectno,a.exno,d.eqno,d.rpoint,el.qcount,c.israndq,d.qseq,rank() over(partition by el.qdiff, el.cc1, el.cc2, el.cc3, el.cc4, el.cc5 order by rand()) rank
from (select #lectno# lectno, #exno# exno) a
inner join lect a2 on a2.lectno=a.lectno and a2.userno=#userno#
left outer join lectex b on b.lectno=a.lectno and b.exno=a.exno
inner join cmex c on c.exno=a.exno and c.eqtype=1
inner join cmexlayer el on el.exno=c.exno and el.qcount > 0
inner join cmexq d on d.exno=el.exno
inner join question e on e.qno=d.qno
and e.qdiff=case when el.qdiff=0 then e.qdiff else el.qdiff end
and e.cc1=case when el.cc1=0 then e.cc1 else el.cc1 end
and e.cc2=case when el.cc2=0 then e.cc2 else el.cc2 end
and e.cc3=case when el.cc3=0 then e.cc3 else el.cc3 end
and e.cc4=case when el.cc4=0 then e.cc4 else el.cc4 end
and e.cc5=case when el.cc5=0 then e.cc5 else el.cc5 end
where b.lectno is null
) a
inner join (
select count(b.lectno) exq
from (select 1 col1) a
left outer join lectexq b on b.lectno=#lectno# and b.exno=#exno#
) z on z.exq < 1
where a.rank <= a.qcount
order by rand();
insert into lectex (lectno,exno,tpoint,recount,cblock,)
select a.lectno,a.exno,0,0,0,
from (select #lectno# lectno, #exno# exno) a
inner join lect a2 on a2.lectno=a.lectno and a2.userno=#userno#
left outer join lectex b on b.lectno=a.lectno and b.exno=a.exno
where b.lectno is null;
update lectexq set
,rechecktime=
,cpoint=#cpoint#
where lectno=#lectno# and exno=#exno# and eqno=#eqno#;
update lectex a
inner join (
select lectno, sum(cpoint) tpoint
from lectexq where lectno=#lectno# and exno=#exno#
group by lectno
) b on b.lectno=a.lectno
set a.udt=,a.uno=#uno#,a.uip=#uip#
,a.tpoint=b.tpoint
,a.rechecktime=
where a.lectno=#lectno# and a.exno=#exno#
update lectsd set
,iscopy=#iscopy#,cpoint=#cpoint#
,feedb=case when feedb is null then #feedb# else feedb end
,checktime=case when #cpoint# is not null or #feedb# is not null then now() else checktime end
,checkip=case when #cpoint# is not null or #feedb# is not null then #uip# else checkip end
where lectno=#lectno# and sdno=#sdno#;
insert into lectsd (lectno,sdno,atext,fgno,copyrate,iscopy,cpoint,feedb,submittime,submitip,checktime,checkip,)
select #lectno#,#sdno#,null,null,null,#iscopy#,#cpoint#,#feedb#,null,null
,case when #cpoint# is not null or #feedb# is not null then now() else null end
,case when #cpoint# is not null or #feedb# is not null then #uip# else null end
,
from (select 1 col1) a
left outer join lectsd b on b.lectno=#lectno# and b.sdno=#sdno#
where b.lectno is null
update lectsd set
,iscopy=#iscopy#,cpoint=#cpoint#,feedb=case when feedb is null then #feedb# else feedb end
,checktime=case when #cpoint# is not null or #feedb# is not null then now() else checktime end
,checkip=case when #cpoint# is not null or #feedb# is not null then #uip# else checkip end
where lectno in ($lectnos$) and sdno=#sdno#;
insert into lectsd (lectno,sdno,atext,fgno,copyrate,iscopy,cpoint,feedb,submittime,submitip,checktime,checkip,)
select a.lectno,#sdno#,null,null,null,#iscopy#,#cpoint#,#feedb#,null,null
,case when #cpoint# is not null or #feedb# is not null then now() else null end
,case when #cpoint# is not null or #feedb# is not null then #uip# else null end
,
from lect a
left outer join lectsd b on b.lectno=a.lectno and b.sdno=#sdno#
where a.lectno in ($lectnos$) and a.status=1 and a.ischanged=0 and b.lectno is null
update lectsd set
,cpoint=#cpoint#,feedb=#feedb#
,checktime=case when #cpoint# is not null or #feedb# is not null then now() else checktime end
,checkip=case when #cpoint# is not null or #feedb# is not null then #uip# else checkip end
where lectno=#lectno# and sdno=#sdno#;
insert into lectsd (lectno,sdno,atext,fgno,copyrate,iscopy,cpoint,feedb,submittime,submitip,checktime,checkip,)
select #lectno#,#sdno#,null,null,null,0,#cpoint#,#feedb#,null,null
,case when #cpoint# is not null or #feedb# is not null then now() else null end
,case when #cpoint# is not null or #feedb# is not null then #uip# else null end
,
from (select 1 col1) a
left outer join lectsd b on b.lectno=#lectno# and b.sdno=#sdno#
where b.lectno is null
update lectsd set
,cpoint=#cpoint#,feedb=#feedb#
,checktime=case when #cpoint# is not null or #feedb# is not null then now() else checktime end
,checkip=case when #cpoint# is not null or #feedb# is not null then #uip# else checkip end
where lectno in ($lectnos$) and sdno=#sdno#;
insert into lectsd (lectno,sdno,atext,fgno,copyrate,iscopy,cpoint,feedb,submittime,submitip,checktime,checkip,)
select a.lectno,#sdno#,null,null,null,0,#cpoint#,#feedb#,null,null
,case when #cpoint# is not null or #feedb# is not null then checktime else null end
,case when #cpoint# is not null or #feedb# is not null then #uip# else null end
,
from lect a
left outer join lectsd b on b.lectno=a.lectno and b.sdno=#sdno#
where a.lectno in ($lectnos$) and a.status=1 and a.ischanged=0 and b.lectno is null
insert into edub2b (etype,userno,edate,esubject,etarget,ecount,eplace,ecomment,compname,ceoname,brno,addr,btype,bkind,manname,email,telno,fgno,)
values (#etype#,#userno#,#edate#,#esubject#,#etarget#,#ecount#,#eplace#,#ecomment#,#compname#,#ceoname#,#brno#,#addr#,#btype#,#bkind#,#manname#,HEX(AES_ENCRYPT(#email#, )),HEX(AES_ENCRYPT(#telno#, )),#fgno#,)
update alarms set isdel=1 where alno=#alno# and userno=#userno#