⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodedaoimpl.java

📁 该系统可以实现邮件的收发
💻 JAVA
字号:
package com.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.dao.NodeDao;
import com.domain.Node;
import com.domain.Position;
import com.util.JdbcUtil;

public class NodeDaoImpl implements NodeDao {

	private String SELECT_INFO_FROM_POSITION = "select * from position";
	
	//查找职位表中信息返回
	public List searchNode(){
		
		Connection conn = JdbcUtil.getConnection();
		Position position = null;
		List<Position> list = new ArrayList<Position>();
		try {
			PreparedStatement ps = conn.prepareStatement(SELECT_INFO_FROM_POSITION);
			ResultSet rs = ps.executeQuery();
					
			while(rs.next()){
				position = new Position();
				position.setPositionId(rs.getInt("positionId"));
				position.setParentID(rs.getInt("parentId"));
				position.setPositionName(rs.getString("positionName"));
				list.add(position);
			}
			rs.close();
			ps.close();			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	public String createJsArray(List list, String dtree) {

		if(list == null || list.size()== 0 ){
			return "";
		}

		StringBuffer contents = new StringBuffer(100);

		for (int i = 0; i < list.size(); i++) { 

			contents.append("\n");

			contents.append(dtree+".add('");

			contents.append(((Position)list.get(i)).getPositionId());

			contents.append("','");

			contents.append(((Position)list.get(i)).getParentID());

			contents.append("','");

			contents.append(((Position)list.get(i)).getPositionName());

			contents.append("','");

			contents.append("Position.do?name="+
					((Position)list.get(i)).getPositionId()+"&onwork=1"
					);

			contents.append("','','");
			
			contents.append("right");
			
			contents.append("');");
		}

		return contents.toString();
	}
	
	/*
	  查出NODENAME NODEID PARENTID = 1 根据NODEID 查询 privilege 
	   中的 privilegename priid 根据priid 去positionprivilege查positionid
       根据positionid 去staffposition中去查staffid 去staff 中去查name password判断密码
	 */
	public List searchNodeNameByStaffName(String name) {
		
		Connection conn = JdbcUtil.getConnection();
		String info = "select nodeid,nodename,parentId,forwardpath,picpath from node where nodeid in (" +
				"select nodeid from privilege where privilegename in(" +
				"select privilegename from privilege where priid in(" +
				"select priid from positionprivilege where positionid in(" +
				"select positionid from staffposition where staffid in(" +
				"select staffId from staff where loginid = '"+name+"' )))))";
		
		List<Node> list = new ArrayList<Node>();
		try {
			PreparedStatement ps = conn.prepareStatement(info);
			ResultSet rs = ps.executeQuery();
					
			while(rs.next()){
				Node node = new Node();
				node.setNodeName(rs.getString("nodeName"));
				node.setParentId(rs.getInt("nodeId"));
				node.setForwardPath(rs.getString("forwardpath"));			
				node.setPicPath(rs.getString("picpath"));
				
				list.add(node);
			}
			rs.close();
			ps.close();			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
	//创建功能菜单树
	public String createTree(List list, String dtree) {

		if(list == null || list.size()== 0 ){

			return "";
		}

		StringBuffer contents = new StringBuffer(100);
		
		for (int i = 0; i < list.size(); i++) { 

			contents.append("\n");

			contents.append(dtree+".add('");

			contents.append(((Node)list.get(i)).getParentId());

			contents.append("','");

			contents.append(((Node)list.get(i)).getNodeId());

			contents.append("','");

			contents.append(((Node)list.get(i)).getNodeName());
			
			contents.append("','");
			
			contents.append(((Node)list.get(i)).getForwardPath());
			
			contents.append("','','");
			
			if((((Node)list.get(i)).getNodeName()).equals("我的邮件")){
				contents.append("right'");
			}else{			
				contents.append("left'");
			}
			
			contents.append(",'','");
			
			contents.append(((Node)list.get(i)).getPicPath());
			
			contents.append("','");
			
			contents.append("true");
			
			contents.append("');");
		}

		return contents.toString();
	}
	
	//获得职位ID方法
	public String getPositionId(String name){
		Connection conn = JdbcUtil.getConnection();
		String info = "select positionid from staffposition where staffid in(" +
		"select staffId from staff where loginid = '"+name+"' )";
		String positionId = "";
		try {
			PreparedStatement ps = conn.prepareStatement(info);
			ResultSet rs = ps.executeQuery();
					
			if(rs.next()){
				positionId = rs.getString("positionId");
			}
			rs.close();
			ps.close();			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return positionId;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -