/*************************************************** * Copyright 2014-7-23, -sinosoft.com.cn All rights reserved. *【创建日期】 : 2014-7-23 *【创建人】 : 徐杨 *【类名】:SysCustomMenuDaoImpl.java *【功能】:本类是菜单角色自定义数据层实现类 *【修改日志】 * -------------------------------------------------- * VERSION DATE 修改人 修改内容 * -------------------------------------------------- * 1.0 2014-7-23 * -------------------------------------------------- **************************************************/ package com.sinosoft.lz.system.menu.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import com.formaction.Utils; import com.persistence.DbConnection; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.assitant.generator.IdentityGenerator; import com.persistence.service.exception.PersistenceException; import com.sinosoft.lz.system.menu.vo.IndexMenu; import com.sinosoft.lz.system.menu.vo.SysMenu; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; public class SysCustomMenuDaoImpl implements ISysCustomMenuDao{ private static SysModel sysmodel = ModelFactory.getSysmodel(); private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); private final static Logger log = Logger.getLogger(SysCustomMenuDaoImpl.class); /** * 功能: 查询源菜单数据 * * @return List */ @SuppressWarnings("rawtypes") @Override public List loadMenuInfo() { /* String sql = "select code id, parentcode pid, RightName name, " + " sort sort, Handler handler, RightType type,img img,functionlink functionlink " + " from Sys_Menu where RightType='1' and is_del='0' order by sort asc ";*/ String sql = "select m.menu_id id, m.parent_menu_id pid, m.menu_name name, " + " m.sortno sort, m.menu_statu type,m.menu_img img,m.menu_url functionlink " + " from Sys_Menu m where m.is_del='0' order by m.menu_id asc "; log.info(sql); return this.loadInfo(sql); } /** * 功能: 根据角色查询源菜单数据 * * @param roleid * 角色编号 * @return List */ @SuppressWarnings("rawtypes") @Override public List loadMenuInfoByRoleId(String roleid) { /* String sql = " select code id, parentcode pid, RightName name, t1.sort sort, " + " t1.Handler handler, t1.RightType type, roleid, menuid " + " from Sys_Menu t1 left join " + " (select * from SYS_CUSTOM_MENU where roleid='" + roleid + "' )t2 " + " on t1.code = t2.menuid where t1.RightType='1' and t1.is_del='0' order by t1.sort asc ";*/ String roleids = ""; if(roleid != null && !"".equals(roleid)){ String[] ids = roleid.split(","); for(int i=0;i getIndexMenu(String menuId,String roleIds){ String[] rids = roleIds.split(","); String ins = ""; for(int i=0;i3 "); // sql.append(" START WITH m.MENU_ID= ? "); // sql.append(" CONNECT BY PRIOR m.menu_ID=m.PARENT_MENU_ID "); // sql.append(" order by m.menu_id "); sql.append(" select distinct m.fd_objectid,m.menu_id,m.menu_name,m.menu_url,m.parent_menu_id,m.menu_info,m.sortno,m.menu_statu,m.is_leaf,m.in_control,m.is_del,m.mod_date,m.menu_img "); sql.append(" from sys_menu m "); sql.append(" inner join sys_role_right_rel r on m.menu_id = r.menu_id and r.role_id in ( "+ins+")"); sql.append(" where CHAR_LENGTH(m.menu_id)>3 "); sql.append(" and left(m.menu_id,1)= ? "); sql.append(" and m.IS_DEL = '0' "); sql.append(" order by m.menu_id "); log.info(sql.toString()); DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; List menuList = new ArrayList(); try{ conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql.toString()); for(int i=0;i queryIndexMenu(String menuName,String roleIds){ String[] rids = roleIds.split(","); String ins = ""; for(int i=0;i menuList = new ArrayList(); try{ conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql.toString()); for(int i=0;i queryIndexSubMenu(String menuName,String roleIds){ String[] rids = roleIds.split(","); String ins = ""; for(int i=0;i menuList = new ArrayList(); try{ conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql.toString()); for(int i=0;i queryIndexMenu(String user_id){ StringBuffer sql = new StringBuffer(); //sql.append(" select FD_OBJECTID,IMAGE_URL,TITLE_NAME,BUSINESS_URL,IS_DEL,USER_ID,SORT,STATE,UPDATEDATE,MENU_ID from SYS_INDEX_MENU where IS_DEL = '0' and STATE = '0' "); sql.append(" select SIM.FD_OBJECTID,SM.MENU_URL,SM.MENU_ID,SM.MENU_NAME,SM.MENU_IMG from SYS_MENU SM LEFT JOIN SYS_INDEX_MENU SIM ON SM.MENU_ID = SIM.MENU_ID where SM.IS_DEL = '0' AND SIM.STATE = '0' "); sql.append(" and SIM.user_id = "); sql.append("'"+user_id+"'"); sql.append(" ORDER BY SIM.CLICK_NUM DESC "); log.info(sql); DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; ResultSet rs = null; List menuList = new ArrayList(); try{ conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql.toString()); rs = pstm.executeQuery(); while(rs.next()){ IndexMenu menu = new IndexMenu(); menu.setFD_OBJECTID(rs.getString("FD_OBJECTID")); menu.setBUSINESS_URL(rs.getString("MENU_URL")); menu.setMENU_ID(rs.getString("MENU_ID")); menu.setTITLE_NAME(rs.getString("MENU_NAME")); menu.setIMAGE_URL(rs.getString("MENU_IMG")); menuList.add(menu); } }catch(Exception e){ log.error("查询菜单错误"+e.getMessage()); }finally{ try { rs.close(); pstm.close(); conn.close(); } catch (SQLException e) { log.error("关闭数据库连接错误:"+e.getMessage()); } } return menuList; } public String setUserClickNum(String menu_id, String user_id) { String result = "error"; String sql = "update SYS_INDEX_MENU set CLICK_NUM=CLICK_NUM+1 where MENU_ID=? AND USER_ID=?"; DbConnection dbConn = new DbConnection(); Connection conn = null; PreparedStatement pstm = null; try { conn = dbConn.getConnection(); pstm = conn.prepareStatement(sql); //设置参数值 pstm.setString(1, menu_id); pstm.setString(2, user_id); int i = pstm.executeUpdate(); if(i==1){ result = "success"; } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { pstm.close(); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block log.error("关闭数据库连接错误:"+e.getMessage()); } } return result; } }