package com.vci.server.portal.service;
|
|
import java.sql.Connection;
|
import java.sql.SQLException;
|
import java.sql.Statement;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import org.hibernate.HibernateException;
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
|
public class UIDeleteService {
|
public static final int DELETE_CONTEXT = 1;
|
public static final int DELETE_TAB = 2;
|
public static final int DELETE_COMPONENT = 3;
|
public static final int DELETE_BUTTON = 4;
|
public boolean deleteUIByOidsForCascade(String[] oids, int deleteType) throws Throwable {
|
try{
|
List<String> sqls = new ArrayList<String>();
|
for(String oid : oids){
|
if(deleteType == DELETE_CONTEXT){
|
//--删除UI组件里的按钮的参数
|
sqls.add("delete plcommandparameter cp where cp.plcommandoid in(select tb.ploid from pltabbutton tb where tb.pltableoid in(select pd.ploid from plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "'))))");
|
//-- 删除UI组件里的按钮
|
sqls.add("delete pltabbutton tb where tb.pltableoid in(select pd.ploid from plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "')))");
|
//-- 删除页签里的UI组件
|
sqls.add("delete plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "'))");
|
//-- 删除页签
|
sqls.add("delete pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "')");
|
//-- 删除上下文的SQL
|
sqls.add("delete pluilayout pld where pld.ploid='" + oid + "'");
|
//-- 删除上下文角色权限
|
sqls.add("delete plroleright rr where rr.plfuncoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "')");
|
//-- 删除上下文页签角色权限
|
sqls.add("delete plroleright rr where rr.plfuncoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "'))");
|
//-- 删除上下文页签里的组件权限
|
sqls.add("delete plroleright rr where rr.plfuncoid in(select pd.ploid from plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "')))");
|
} else if(deleteType == DELETE_TAB){
|
//--删除UI组件里的按钮的参数
|
sqls.add("delete plcommandparameter cp where cp.plcommandoid in(select tb.ploid from pltabbutton tb where tb.pltableoid in(select pd.ploid from plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.ploid='" + oid + "')))");
|
//-- 删除UI组件里的按钮
|
sqls.add("delete pltabbutton tb where tb.pltableoid in(select pd.ploid from plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.ploid='" + oid + "'))");
|
//-- 删除页签里的UI组件
|
sqls.add("delete plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.ploid='" + oid + "')");
|
//-- 删除页签
|
sqls.add("delete pltabpage tp where tp.ploid='" + oid + "'");
|
//-- 删除上下文页签角色权限
|
sqls.add("delete plroleright rr where rr.plfuncoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "'))");
|
//-- 删除上下文页签里的组件权限
|
sqls.add("delete plroleright rr where rr.plfuncoid in(select pd.ploid from plpagedefination pd where pd.plpagecontextoid in(select tp.ploid from pltabpage tp where tp.plpagedefinationoid in(select pld.ploid from pluilayout pld where pld.ploid='" + oid + "')))");
|
} else if(deleteType == DELETE_COMPONENT){
|
//--删除UI组件里的按钮的参数
|
sqls.add("delete plcommandparameter cp where cp.plcommandoid in(select tb.ploid from pltabbutton tb where tb.pltableoid in(select pd.ploid from plpagedefination pd where pd.ploid='" + oid + "'))");
|
//-- 删除UI组件里的按钮
|
sqls.add("delete pltabbutton tb where tb.pltableoid in(select pd.ploid from plpagedefination pd where pd.ploid='" + oid + "')");
|
//-- 删除页签里的UI组件
|
sqls.add("delete plpagedefination pd where pd.ploid='" + oid + "'");
|
//-- 删除上下文页签里的组件权限
|
sqls.add("delete plroleright rr where rr.plfuncoid ='" + oid + "'");
|
} else if(deleteType == DELETE_BUTTON){
|
//--删除UI组件里的按钮的参数
|
sqls.add("delete plcommandparameter cp where cp.plcommandoid in(select tb.ploid from pltabbutton tb where tb.ploid='" + oid + "')");
|
//-- 删除UI组件里的按钮
|
sqls.add("delete pltabbutton tb where tb.ploid='" + oid + "'");
|
}
|
}
|
|
executeUpdateSqls(sqls.toArray(new String[]{}));
|
return true;
|
}catch(Throwable e){
|
throw e;
|
}
|
}
|
|
private boolean executeUpdateSqls(String[] sqls) throws HibernateException, SQLException {
|
boolean rs = false;
|
Connection conn = HibernateSessionFactory.getSessionConnection();
|
Statement st = null;
|
try {
|
st = conn.createStatement();
|
for (int i = 0; i < sqls.length; i++) {
|
st.addBatch(sqls[i]);
|
if ((i + 1) % 200 == 0) {
|
st.executeBatch();
|
}
|
}
|
|
if (sqls.length % 200 != 0) {
|
st.executeBatch();
|
}
|
rs = true;
|
} finally {
|
if (st != null) {
|
st.close();
|
st = null;
|
}
|
}
|
|
return rs;
|
}
|
|
}
|