Commit a53ef61d by TongZuu

add script

parent 95977bb3
-- Ѻ getField Data ҡ ScreenValue Worlflow_Data
CREATE FUNCTION [dbo].[ParseString]
(@INSCREENDATA text, @INPATTEXT01 varchar(200), @INPATTEXT02 varchar(200), @INPATTEXT03 varchar(10))
RETURNS varchar(1000)
WITH EXEC AS CALLER
AS
BEGIN
DECLARE @OUTVCHAR VARCHAR(1000);
IF (PATINDEX(@INPATTEXT01,@INSCREENDATA) = 0) OR (PATINDEX(@INPATTEXT01,@INSCREENDATA) IS NULL)
BEGIN
SET @OUTVCHAR = NULL
END
ELSE
BEGIN
SET @OUTVCHAR = SUBSTRING(@INSCREENDATA,PATINDEX(@INPATTEXT01,@INSCREENDATA)+len(@INPATTEXT02)
,(CHARINDEX(@INPATTEXT03,@INSCREENDATA, PATINDEX(@INPATTEXT01,@INSCREENDATA)+len(@INPATTEXT02))
-(PATINDEX(@INPATTEXT01,@INSCREENDATA)+len(@INPATTEXT02))))
END
/*
SET @OUTVCHAR = SUBSTRING(@INSCREENDATA,PATINDEX(@INPATTEXT01,@INSCREENDATA)+len(@INPATTEXT02)
,(CHARINDEX(@INPATTEXT03,@INSCREENDATA, PATINDEX(@INPATTEXT01,@INSCREENDATA)+len(@INPATTEXT02))
-(PATINDEX(@INPATTEXT01,@INSCREENDATA)+len(@INPATTEXT02)))) */
RETURN(@OUTVCHAR);
END
-- ¹ wf_id & category_id ͧ
with tmp as (
select '8001' as wf_id,'8' as CATEGORY_ID
) , cfig as (
select '0' as groupindex,'1' as line_no,'DELETE CATEGORY WHERE CATEGORY_ID = '+CATEGORY_ID+'; ' as script
from tmp
) , cfig2 as (
select '0' as groupindex,'2' as line_no,'DELETE STEP_DEFINITION WHERE WF_ID = '+wf_id+' AND WF_VER = 1; ' as script
from tmp
) , cfig3 as (
select '0' as groupindex,'3' as line_no,'DELETE STEP_TOOL WHERE WF_ID = '+wf_id+' AND WF_VER = 1; ' as script
from tmp
) , cfig4 as (
select '0' as groupindex,'4' as line_no,'DELETE STEP_TOOL_IMPL WHERE WF_ID = '+wf_id+' AND WF_VER = 1; ' as script
from tmp
) , cfig5 as (
select '0' as groupindex,'5' as line_no,'DELETE TRANSITION WHERE WF_ID = '+wf_id+' AND WF_VER = 1; ' as script
from tmp
) , cfig6 as (
select '0' as groupindex,'6' as line_no,'DELETE WFVAR_DEFINITION WHERE WF_ID = '+wf_id+' AND WF_VER = 1; ' as script
from tmp
) , cfig7 as (
select '0' as groupindex,'7' as line_no,'DELETE WORKFLOW_DEFINITION WHERE WF_ID = '+wf_id+' AND WF_VER = 1; ' as script
from tmp
) , cat as (
select '1' as groupindex,'1' as line_no,
'INSERT INTO CATEGORY (COMPANYID,CATEGORY_ID,TNAME,ENAME,TDESC,EDESC,ACTIVE,DEL) VALUES ('''
+COMPANYID+''','''+CATEGORY_ID+''','''+TNAME+''','''+ENAME+''','''
+TDESC+''','''+EDESC+''','''+cast(ACTIVE as varchar(1))+''','''+cast(DEL as varchar(1))
+'''); ' as script
from CATEGORY c2
where exists (select * from tmp t where t.CATEGORY_ID=c2.CATEGORY_ID )
) , sdef as(
select '2' as groupindex,STEP_ID as line_no,
'INSERT INTO STEP_DEFINITION (COMPANYID,WF_ID ,WF_VER,STEP_ID,TNAME,ENAME,TDESC,EDESC,STEP_TYPE,'
+'RECIPIENT_DEF,TASK_RATE,WEB_PAGE,AUTO_APPROVE,ATTACHED_STATUS,COMPLETION_DURATION,EXTENSION_DURATION,'
+'DELAY_DURATION,TAKEOVER_RIGHT,AUTOASSIGNABLE,PASSED_NORECP) VALUES ('''
+COMPANYID+''','''+cast(WF_ID as varchar(4))+''','''+cast(WF_VER as varchar(1))+''','''+cast(STEP_ID as varchar(2))+''','''
+TNAME+''','''+ENAME+''','''+TDESC+''','''+EDESC+''','''+cast(STEP_TYPE as varchar(1))+''','''
+RECIPIENT_DEF+''','''+cast(TASK_RATE as varchar(1))+''','''+WEB_PAGE+''','''+cast(AUTO_APPROVE as varchar(1))+''','''
+cast(ATTACHED_STATUS as varchar(1))+''',''259200000'',''259200000'',''259200000'',''0'',''1'',''0'');' as script
from STEP_DEFINITION sd
where exists(select * from tmp t where sd.WF_ID=t.wf_id)
) , sttoo_tmp as(
select ROW_NUMBER() OVER(partition by wf_id order by step_id,step_tool_id) as idx,
'3' as groupindex,cast(STEP_ID as varchar(2))+cast(STEP_TOOL_ID as varchar(2)) as line_no,
'INSERT INTO STEP_TOOL (COMPANYID,WF_ID,WF_VER,STEP_TOOL_ID,STEP_ID,APP_ID,TOOL_TYPE,IMPL_TYPE,TDESC,EDESC,REF_IMPL) VALUES ('''
+COMPANYID+''','''+cast(WF_ID as varchar(4))+''','''+cast(WF_VER as varchar(1))+''','''
+cast(STEP_TOOL_ID as varchar(2))+''','''+cast(STEP_ID as varchar(2))+''','''+cast(APP_ID as varchar(2))+''','''
+cast(TOOL_TYPE as varchar(2))+''','''+cast(IMPL_TYPE as varchar(2))+''','''
+TDESC+''','''+EDESC+''','''+REF_IMPL+''');' as script,st.step_id as stepid
from STEP_TOOL st
where exists(select * from tmp t where st.wf_id=t.wf_id)
) , sttoo_tmp1 as(
select ISNULL(t2.stepid-t1.stepid , 0) as diff,t1.* from sttoo_tmp t1
left outer join sttoo_tmp t2 on t1.idx = t2.idx-1
) , sttoo as(
select groupindex,line_no,script from sttoo_tmp1 t
union
select groupindex,line_no+diff,'' from sttoo_tmp1 t4 where t4.diff = 1
), stimp_tmp as(
select ROW_NUMBER() OVER(partition by wf_id order by step_id,cast(STEP_ID as varchar(2))+cast(case when IMPL_TYPE > 10 then IMPL_TYPE else '11' end as varchar(10))+cast(STEP_TOOL_IMPL_ID as varchar(2))) as idx,
'4' as groupindex,cast(STEP_ID as varchar(2))+cast(case when IMPL_TYPE > 10 then IMPL_TYPE else '11' end as varchar(10))+cast(STEP_TOOL_IMPL_ID as varchar(2)) as line_no,
'INSERT INTO STEP_TOOL_IMPL(COMPANYID,WF_ID,WF_VER,STEP_TOOL_IMPL_ID,STEP_ID,APP_ID,TOOL_TYPE,IMPL_TYPE,PARAM_NAME,PARAM_VALUE) VALUES('''
+COMPANYID+''','''+cast(WF_ID as varchar(4))+''','''+cast(WF_VER as varchar(1))+''','''
+cast(STEP_TOOL_IMPL_ID as varchar(2))+''','''+cast(STEP_ID as varchar(2))+''','''+cast(APP_ID as varchar(2))+''','''
+cast(TOOL_TYPE as varchar(2))+''','''+cast(IMPL_TYPE as varchar(2))+''','''
+PARAM_NAME+''','''+PARAM_VALUE+''');' as script,stml.STEP_ID as stepid
from STEP_TOOL_IMPL stml
where exists(select * from tmp t where stml.wf_id=t.wf_id)
) , stimp_tmp1 as(
select ISNULL(t2.stepid-t1.stepid , 0) as diff,t1.* from stimp_tmp t1
left outer join stimp_tmp t2 on t1.idx = t2.idx-1
) , stimp as(
select groupindex,line_no,script from stimp_tmp1 t
union
select groupindex,line_no+diff,'' from stimp_tmp1 t4 where t4.diff = 1
), trns as(
select '5' as groupindex,cast(STEP_ID as varchar(2))+cast(TRANSITION_ID as varchar(2)) as line_no,
'INSERT INTO TRANSITION (COMPANYID,WF_ID,WF_VER,TRANSITION_ID,STEP_ID,NEXT_STEP_ID,CONDITION,TDESC,EDESC,TRAN_TYPE) VALUES('''
+COMPANYID+''','''+cast(WF_ID as varchar(4))+''','''+cast(WF_VER as varchar(1))+''','''
+cast(TRANSITION_ID as varchar(2))+''','''+cast(STEP_ID as varchar(2))+''','''+cast(NEXT_STEP_ID as varchar(2))+''','''
+CONDITION+''','''+TDESC+''','''+EDESC+''','''+cast(TRAN_TYPE as varchar(1))+''');' as script
from TRANSITION tr
where exists(select * from tmp t where tr.wf_id=t.wf_id)
), wfvd as(
select '6' as groupindex,VAR_ID as line_no,
'INSERT INTO WFVAR_DEFINITION (COMPANYID,WF_ID,WF_VER,VAR_ID,VAR_NAME,VAR_TYPE,TDESC,EDESC,HINT,INIT_VALUE,VALIDATE_CLASS,NULLABLE,ENCRYPT,PROTABLE_XML) VALUES('''
+COMPANYID+''','''+cast(WF_ID as varchar(4))+''','''+cast(WF_VER as varchar(1))+''','''
+cast(VAR_ID as varchar(1))+''','''+VAR_NAME+''','''+cast(VAR_TYPE as varchar(1))+''','''
+TDESC+''','''+EDESC+''','''+HINT+''','''+INIT_VALUE+''','''+VALIDATE_CLASS+''','''
+cast(NULLABLE as varchar(1))+''','''+cast(ENCRYPT as varchar(1))+''','''+PROTABLE_XML+''');' as script
from WFVAR_DEFINITION wvd
where exists(select * from tmp t where wvd.wf_id=t.wf_id)
), wdef as(
select '7' as groupindex,'1' as line_no,
'INSERT INTO WORKFLOW_DEFINITION(COMPANYID,WF_ID ,WF_VER,CATEGORY_ID,TNAME,ENAME,TDESC,EDESC,LAST_SEQ,INITIATOR_DEF,COMPLETION_DURATION,EXTENSION_DURATION,TRANSFER_FILE,ACTIVE,DEL) VALUES('''
+COMPANYID+''','''+cast(WF_ID as varchar(4))+''','''+cast(WF_VER as varchar(1))+''','''
+cast(CATEGORY_ID as varchar(1))+''','''+TNAME+''','''+ENAME+''','''+TDESC+''','''+EDESC+''',''0'','''
+INITIATOR_DEF+''',''259200000'',''259200000'','''+TRANSFER_FILE+''',''1'',''0'');' as script
from WORKFLOW_DEFINITION wd
where exists(select * from tmp t where wd.wf_id=t.wf_id)
), sc_all as(
select '0' as groupindex,'0' as line_no,'/*** DELETE CONFIG ***/' as script
union
select * from cfig
union
select * from cfig2
union
select * from cfig3
union
select * from cfig4
union
select * from cfig5
union
select * from cfig6
union
select * from cfig7
union
select '0' as groupindex,'99999' as line_no,'' as script
union
select '1' as groupindex,'0' as line_no,'/*** CATEGORY ***/' as script
union
select * from cat
union
select '1' as groupindex,'99999' as line_no,'' as script
union
select '2' as groupindex,'0' as line_no,'/*** STEP_DEFINITION ***/' as script
union
select * From sdef
union
select '2' as groupindex,'99999' as line_no,'' as script
union
select '3' as groupindex,'0' as line_no,'/*** STEP_TOOL ***/' as script
union
select * From sttoo
union
select '3' as groupindex,'99999' as line_no,'' as script
union
select '4' as groupindex,'0' as line_no,'/*** STEP_TOOL_IMPL ***/' as script
union
select * From stimp
union
select '4' as groupindex,'99999' as line_no,'' as script
union
select '5' as groupindex,'0' as line_no,'/*** TRANSITION ***/' as script
union
select * From trns
union
select '5' as groupindex,'99999' as line_no,'' as script
union
select '6' as groupindex,'0' as line_no,'/*** WFVAR_DEFINITION ***/' as script
union
select * From wfvd
union
select '6' as groupindex,'99999' as line_no,'' as script
union
select '7' as groupindex,'0' as line_no,'/*** WORKFLOW_DEFINITION ***/' as script
union
select * From wdef
)
select * from sc_all
order by groupindex , line_no
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment