樹狀圖複製功能 :寫了一個存儲過程
create or replace procedure copy_TemplateDetail(
sourceId number, --源id
u_id number, --更新的id
u_createUser varchar2) is
new_one_id number;
new_two_id number;
one_level number;
sourceDetailId number;
sourceTwoDetailId number;
two_level number;
begin
select count(1) into one_level from 表A where templateId = sourceId and parentId is null;
DBMS_OUTPUT.put_line(one_level);
while one_level>0 loop
SELECT S_ASSESSMENTTEMPLATEDETAILS.Nextval into new_one_id from dual;
insert into 表A (ID,TEMPLATEID,DETAILLEVEL,PARENTID) select new_one_id,u_id,m.DETAILLEVEL, m.PARENTID from (select a.*,rownum rowss from 表A a where a.templateId=sourceId and a.parentId is null ) m where m.rowss=one_level;
select m.id into sourceDetailId from (select a.id ,rownum as rowss from 表A a where a.templateId=sourceId and a.parentId is null order by a.displayseq) m where m.rowss= one_level;
select count(1) into two_level from 表A where parentId = sourceDetailId;
one_level:= one_level - 1;
DBMS_OUTPUT.put_line(sourceDetailId);
while two_level>0 loop
SELECT S_ASSESSMENTTEMPLATEDETAILS.Nextval into new_two_id from dual;
insert into 表A (ID,TEMPLATEID,DETAILLEVEL,PARENTID) select new_two_id,u_id,m.DETAILLEVEL, m.MINSCORE,new_one_id from (select a.*,rownum rowss from 表A a where a.templateId=sourceId and a.parentId =sourceDetailId order by a.displayseq ) m where m.rowss=two_level;
select m.id into sourceTwoDetailId from (select a.id ,rownum as rowss from 表A a where a.templateId=sourceId and a.parentId=sourceDetailId order by a.displayseq) m where m.rowss= two_level;
insert into 表A (ID,TEMPLATEID,DETAILLEVEL,PARENTID) select S_ASSESSMENTTEMPLATEDETAILS.Nextval,u_id,m.DETAILLEVEL,new_two_id from (select a.*,rownum rowss from ASSESSMENTTEMPLATEDETAILS a where a.templateId=sourceId and a.parentId =sourceTwoDetailId order by a.displayseq ) m ;
two_level:=two_level-1;
end LOOP;
end LOOP;
end copy_TemplateDetail;
這是一種思路,還有一種是通過java代碼實現的
大概思路先獲取要複製的所有數據(List),然後在通過獲取一定數量序列值,然後寫一個map緩存一下,map(id+parentId,對應列),for(序列){ for(複製數據list)map(寫入) 刪除複製id 層級判斷 }
目前就想到了這兩種方式(比較噁心),大家有好的方式歡迎留言
表達的永遠不是他所說的內容,而是渴望被理解的心情。
——蘇更生