/* 单据类型布局方案升级  单据类型没有唯一索引这里取相同flocaleid的fpkid最大值*/
insert into T_CTS_LAYOUTSCHEME_L(fpkid, fid, flocaleid, fname) 
select A.fpkid, A.fid, A.flocaleid, CONCAT(A.fname, '_BT_S1') from t_bas_billtype_l A 
where not exists (select fpkid from T_CTS_LAYOUTSCHEME_L where fid = A.fid and flocaleid = A.flocaleid)
and A.fpkid in (select max(fpkid) from t_bas_billtype_l group by fid, flocaleid);

insert into t_cts_layoutfieldctl (fid, fentryid, fseq, fparententryid, fdefaultvalue, fmustinput, fenabled, feditenabled, fsubmitenabled, fauditenabled, fvinit, fvnew, fvedit, fvview, fvsubmit, fvaudit, ffieldkey,  FDEFAULTFUNCPARAM)
select fid, fentryid, fseq, 0, fdefaultvalue, fmustinput, fenabled, feditenabled, fsubmitenabled, fauditenabled, fvinit, fvnew, fvedit, fvview, fvsubmit, fvaudit, ffieldkey, fdefaultfuncparam 
from T_BAS_BILLTYPEFLDCTL where fid not in (select fid from t_cts_layoutfieldctl);
