📄 menubean.java
字号:
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from wap_menu where MENU_ID="+menuId);
if (rs.next()) {
model=new MenuModel();
model.setImgId(rs.getInt("IMG_ID"));
model.setMenuParent(rs.getInt("MENU_PARENT"));
model.setMenuChannel(rs.getInt("MENU_CHANNEL"));
model.setMenuName(rs.getString("MENU_NAME"));
//model.set(rs.getDate("UPDATE_TIME"));
}
rs.close();
stmt.close();
//pool.freeConnection( conn ,0 );
}catch(Exception se) {
//pool.freeConnection( conn ,1 );
return null;
}finally {
closeConn(conn);
}
return model;
}
public static void closeConn(Connection conn) {
try {
conn.close();
}
catch (Exception e) {}
}
public static Connection getConn() throws SysException {
try {
return Database.getConnection();
}
catch(Exception e){
throw new SysException("Exception while execute getConn mothod : \n" + e);
}
}
public static void main(String[] main) {
try {
Collection coll = getTree();
Iterator it = coll.iterator();
while (it.hasNext()) {
TreeModel treeModel = (TreeModel)it.next();
System.out.println("level: " + treeModel.getLevel());
System.out.println("name: " + treeModel.getName());
}
} catch (Exception e) {
}
}
public static void insert(MenuModel menuModel, ChannelModel channelModel, Collection coll) throws SysException {
Connection conn = null;
try {
conn = Database.getConnection();
conn.setAutoCommit(false);
MenuBean.insert(menuModel, conn);
ChannelBean.insert(channelModel, conn);
Iterator it = coll.iterator();
while (it.hasNext()) {
ChannelFeeModel channelFeeModel = (ChannelFeeModel)it.next();
ChannelFeeBean.insert(channelFeeModel, conn);
}
conn.commit();
} catch (Exception e) {
e.printStackTrace();
try {conn.rollback();} catch (Exception ex) {}
throw new SysException("Exception while execute insert");
} finally {
try {conn.setAutoCommit(false);} catch (Exception ex) {}
try {conn.close();} catch (Exception ex) {}
}
}
public static void update(MenuModel menuModel, ChannelModel channelModel, Collection coll) throws SysException {
Connection conn = null;
try {
conn = Database.getConnection();
conn.setAutoCommit(false);
MenuBean.update(menuModel, conn);
ChannelBean.update(channelModel, conn);
ChannelFeeBean.updateBySql("DELETE WAP_CHANNEL_FEE WHERE CHANNEL_ID = " + channelModel.getId(), conn);
Iterator it = coll.iterator();
while (it.hasNext()) {
ChannelFeeModel channelFeeModel = (ChannelFeeModel)it.next();
ChannelFeeBean.insert(channelFeeModel, conn);
}
conn.commit();
} catch (Exception e) {
e.printStackTrace();
try {conn.rollback();} catch (Exception ex) {}
throw new SysException("Exception while execute update");
} finally {
try {conn.setAutoCommit(false);} catch (Exception ex) {}
try {conn.close();} catch (Exception ex) {}
}
}
public static void delete(int menuId, int channelId) throws SysException {
Connection conn = null;
try {
conn = Database.getConnection();
conn.setAutoCommit(false);
MenuBean.delete(menuId, conn);
ChannelBean.updateBySql("UPDATE WAP_CHANNEL SET CHANNEL_STATUS = 9 WHERE ID = " + channelId);
//ChannelBean.delete(channelId, conn);
//ChannelFeeBean.updateBySql("DELETE WAP_CHANNEL_FEE WHERE CHANNEL_ID = " + channelId, conn);
conn.commit();
} catch (Exception e) {
e.printStackTrace();
try {conn.rollback();} catch (Exception ex) {}
throw new SysException("Exception while execute delete");
} finally {
try {conn.setAutoCommit(false);} catch (Exception ex) {}
try {conn.close();} catch (Exception ex) {}
}
}
public static boolean hasSubMenu(int menuId) throws SysException {
String sql = "SELECT COUNT(*) FROM WAP_MENU WHERE MENU_PARENT = " + menuId;
return getRowCountBySql(sql) != 0;
}
//取得所有菜单,频道除外(新加)
public static Collection getAllSysMenu()throws SysException{
int arrayId=0;
java.util.Collection subColl=new java.util.ArrayList();
Hashtable sh=new Hashtable();
Connection conn=getConn();
try {
Statement stmt=conn.createStatement();
String sql="select level,MENU_ID,MENU_PARENT,MENU_NAME from wap_menu "+
"where MENU_CHANNEL='0'"+"start with MENU_PARENT='0' "+
"connect by MENU_PARENT=Prior MENU_ID";
System.out.println(sql);
ResultSet rs=stmt.executeQuery(sql);
NodeModel model=null;
while (rs.next()) {
int level=rs.getInt("level");
if (model!=null) {
if (model.getLevel()<level) {
model.setHasLeaf("1");
}
subColl.add(model);
}
model=new NodeModel();
model.setIndex(arrayId++);
model.setLevel(level);
model.setId(rs.getInt("MENU_ID"));
model.setPid(rs.getInt("MENU_PARENT"));
model.setName(rs.getString("MENU_NAME"));
model.setIsopen("1");
}
if (model!=null) {
subColl.add(model);
}
rs.close();
stmt.close();
}catch(Exception se) {
se.printStackTrace();
return null;//如果没有数据,返回空
}finally {
closeConn(conn);
}
return subColl.size()==0?null:subColl;//返回结果集
}
public static Collection getByMenuChannel(int menuChannel) throws SysException
{
String sql = "SELECT MENU_ID,MENU_PARENT FROM WAP_MENU WHERE MENU_CHANNEL =" + menuChannel;
return MenuDao.queryBySql(sql);
}
public static Collection getChannel(Collection coll,String userMdn) throws SysException{
if (coll.size() != 0) {
Iterator it = coll.iterator();
boolean flag = false;
Object o1 = "";
while (it.hasNext()) {
Object o = it.next();
if(flag){
coll.remove(o1);
}
Hashtable element = (Hashtable) o;
MenuModel menuModel = MenuBean.toModel(element);
int menuChannel = menuModel.getMenuChannel();
if (menuChannel != 0) {
String sql = "SELECT * FROM WAP_USER U,WAP_GROUP_CHANNEL GC WHERE U.USER_GROUP = GC.GROUP_ID AND GC.CHANNEL_ID = " +
menuChannel + " AND U.USER_MDN = '" + userMdn + "'";
String sql1 =
"SELECT * FROM WAP_GROUP_CHANNEL GC WHERE GC.CHANNEL_ID =" +
menuChannel;
System.out.println("------"+sql);
System.out.println("********"+sql1);
if (queryBySql(sql).size() == 0 && queryBySql(sql1).size() != 0) {
flag = true;
o1 = o;
}
System.out.println(coll.size());
System.out.println("%%%%%%%%yes");
}
}
}
return coll;
}
public static Collection getData(int parentMenuId, String userMdn) throws SysException {
String sql = "SELECT M.MENU_ID, M.MENU_NAME, C.ID CHANNEL_ID, C.CHANNEL_NAME, I.IMG_URL FROM " +
" WAP_MENU M, WAP_MENU_IMG I, " +
" (SELECT * FROM WAP_CHANNEL WHERE CHANNEL_TRADE = 0 AND CHANNEL_TEST = 0 AND CHANNEL_STATUS = 1) C " +
" WHERE M.MENU_CHANNEL = C.ID (+) " +
" AND M.IMG_ID = I.ID " +
" AND MENU_PARENT = " + parentMenuId +
" AND NOT (M.MENU_CHANNEL<>0 AND C.ID=0)";
System.out.println(sql);
return queryBySql(sql);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -