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

📄 deptproxy.java

📁 实现统一的人员日志管理系统管理后台
💻 JAVA
字号:
package com.tb.log.model.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tb.log.factory.OracleDAOFactory;
import com.tb.log.model.bo.vo.dept.AddDeptVo;
import com.tb.log.model.bo.vo.dept.DeptVo;
import com.tb.log.model.bo.vo.dept.ShowDeptVo;
import com.tb.log.model.dao.DAOFactory;
import com.tb.log.model.dao.idao.IDeptDAO;
import com.tb.log.model.dao.idao.IRoleDAO;
import com.tb.log.model.dao.idao.IUserDAO;
import com.tb.log.model.po.Dept;
import com.tb.log.system.SystemException;
import com.tb.log.util.pages.PageBean;

public class DeptProxy extends Proxy {

	@Override
	public boolean add(Object obj) throws SystemException{
		boolean b = false;
		AddDeptVo addDeptVo = (AddDeptVo) obj;
		DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.ORACLE);
		IDeptDAO iDeptDAO = daoFactory.getDeptDAO();
		int dept_code = 1;
		Connection conn = OracleDAOFactory.getConnection();
		try {
			try {
				conn.setAutoCommit(false);
				dept_code = ((Dept) iDeptDAO.findById(addDeptVo.getSupper_id()))
						.getDept_grade();

				int dept_grade = dept_code + 1;
				Dept dept = new Dept(0, dept_code, addDeptVo.getDept_name(),
						addDeptVo.getSupper_id(), dept_grade, addDeptVo
								.getCreat_date(), addDeptVo.getDept_state(),
						addDeptVo.getDept_desc());

				iDeptDAO.save(dept);
				conn.commit();
				conn.setAutoCommit(true);
				b = true;
			} catch (SQLException e) {
				try {
					conn.rollback();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				e.printStackTrace();
			}

		} catch (SystemException e) {

			e.printStackTrace();
		}
		return b;
	}

	@Override
	public Object get(int id) throws SystemException{
		IDeptDAO dept = DAOFactory.getDAOFactory(DAOFactory.ORACLE).getDeptDAO();
		DeptVo deptVo = null;
		
		try {
			Dept dp = (Dept)dept.findById(Integer.toString(id));
			deptVo = new DeptVo(dp.getDept_id(),dp.getDept_code(),dp.getDept_name(),dp.getSupper_id(),
			dp.getDept_grade(),dp.getCreat_date() ,dp.getDept_state(),dp.getDept_desc());
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return deptVo;
	}

	@Override
	public Object load(int id) throws SystemException{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean modify(Object obj) throws SystemException{
		boolean b = false;
		DeptVo deptVo = (DeptVo) obj;
		DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.ORACLE);
		IDeptDAO iDeptDAO = daoFactory.getDeptDAO();
		int dept_code = 1;
		Connection conn = OracleDAOFactory.getConnection();
		try {
			try {
				conn.setAutoCommit(false);
				dept_code = ((Dept) iDeptDAO.findById(deptVo.getSupper_id()))
						.getDept_grade();

				int dept_grade = dept_code + 1;
				Dept dept = new Dept(deptVo.getDept_id(), dept_code, deptVo.getDept_name(),
						deptVo.getSupper_id(), dept_grade, deptVo
								.getCreat_date(), deptVo.getDept_state(),
								deptVo.getDept_desc());

				iDeptDAO.update(dept);
				conn.commit();
				conn.setAutoCommit(true);
				b = true;
			} catch (SQLException e) {
				try {
					conn.rollback();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				e.printStackTrace();
			}

		} catch (SystemException e) {

			e.printStackTrace();
		}
		return b;

	}

	@Override
	public boolean remove(Object obj) throws SystemException{
		DeptVo deptVo = (DeptVo )obj;
		boolean b = false;
		IDeptDAO iDept = DAOFactory.getDAOFactory(DAOFactory.ORACLE).getDeptDAO();
		Connection conn = OracleDAOFactory.getConnection();
		Dept dept = new Dept();
		dept.setDept_id(deptVo.getDept_id());
		try {
			try {
				conn.setAutoCommit(false);
				System.out.println("deptPorxy--remove--------");
				iDept.remove(dept);
				conn.commit();
				conn.setAutoCommit(true);
				b = true;
			} catch (SQLException e) {
				try {
					conn.rollback();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				e.printStackTrace();
			}
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("deptPorxy--remove");
		return b;
	}
	
	public Map findAllPages(ShowDeptVo showVo)throws SystemException{
	     Map map = new HashMap();
		String sql1 = "select * from (select row_.*, rownum rownum_ from (" +
				"select * from t_department where dept_grade like '%"+showVo.getDept_grade()+"%' and dept_state like '%"+showVo.getDept_state()+"%' and supper_id like '%"+showVo.getSupper_id()+"%' and dept_name like '%"+showVo.getDept_name()+"%' ) row_ where rownum <=?) where rownum_ >?";
		String sql2 = "select count(*) from (select * from t_department where dept_grade like '%"+showVo.getDept_grade()+"%' and dept_state like '%"+showVo.getDept_state()+"%' and supper_id like '%"+showVo.getSupper_id()+"%' and dept_name like '%"+showVo.getDept_name()+"%' ) ";
		System.out.println("sql2:"+sql2);
		IDeptDAO idept = DAOFactory.getDAOFactory(DAOFactory.ORACLE).getDeptDAO();
		try {
			List deptList = idept.findByCondition(sql1, showVo.getCurrentPage());
			PageBean pages = idept.getTotalResultsByCondition(sql2);
			map.put(1, deptList);
			map.put(2, pages);
		} catch (SystemException e) {
			e.printStackTrace();
		}
		System.out.println("OK");
		return map;
	}

	public List getAll() throws SystemException{
		DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.ORACLE);
		IDeptDAO iDeptDAO = daoFactory.getDeptDAO();
		List deptList = null;
		try {
			deptList = iDeptDAO.findAll();
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return deptList;
	}

}

⌨️ 快捷键说明

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