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

📄 treeviewmgr.java

📁 基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰富
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.yuanchung.organize.treeview;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.yuanchung.sales.dao.user.UserDAO;
import com.yuanchung.sales.exception.SystemException;
import com.yuanchung.sales.model.Position;
import com.yuanchung.sales.model.Treeview;
import com.yuanchung.sales.model.admin.position.UserPosition;
import com.yuanchung.sales.model.user.User;

public class TreeViewMgr {
	static Logger logger = Logger.getLogger(TreeViewMgr.class);
	private static TreeviewDAO treeviewDao;
	private UserDAO userDao;

	/**
	 * @return the userDao
	 */
	public UserDAO getUserDao() {
		return userDao;
	}

	/**
	 * @param userDao
	 *            the userDao to set
	 */
	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}

	public void setTreeviewDao(TreeviewDAO treeviewDao) {
		System.out.println("����" + treeviewDao);
		this.treeviewDao = treeviewDao;
	}

	public TreeviewDAO getTreeviewDao() {
		return this.treeviewDao;
	}

	/**
	 * 通过ParentId查找对象
	 * @param parentId   主键
	 * @return
	 * @throws SystemException
	 */
	public static Treeview findByParentId(int parentID) throws SystemException {
		Treeview treeview = null;
		try {
			treeview = treeviewDao.findByParentId(parentID);
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw new SystemException("根据parentId查找对象出现异常!");
		}
		return treeview;
	}

	// ��ݸ����ȡ����
	public List<Treeview> getAllTreeByParentId(int parentId)
			throws SystemException {
		try {
			List<Treeview> tvList = treeviewDao.getAllTreeByParentId(parentId);
			return tvList;
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	/**
	 * 根据父部门节点ID查找所有子部门节点
	 * 
	 * @param parentId
	 * @return
	 * @throws SystemException
	 */
	public List<Treeview> getSubDeptByParentId(int parentId)
			throws SystemException {
		try {
			List<Treeview> tvList = treeviewDao.getSubDeptByParentId(parentId);
			return tvList;
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw new SystemException("系统出错!");
		}
	}

	// ��������ҽ��
	public Treeview treeviewDao(int nodeId) throws SystemException {
		try {
			return treeviewDao.findById(nodeId);
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// ��ݸ�λ����������Ա��
	public List<TreeviewVo> TransformTreeviewToVo(List<Treeview> treeviews,
			String deptName) throws SystemException {
		TreeviewVo treeviewVo = null;
		// ��ݽ��ID�����û�
		User user = null;
		List<TreeviewVo> TreeviewVoList = new ArrayList<TreeviewVo>();
		try {
			for (Object o : treeviews) {
				Treeview treeviewTmp = (Treeview) o;

				List userList = treeviewDao.getUserByTreeview(treeviewTmp);// ��ݽ������û�

				// ����û����Ҹ�λ
				// UserPosition position =
				// treeviewDao.getUserPositionByUser(user);
				for (Object O : userList) {
					user = (User) O;
					// ת����VO
					treeviewVo = new TreeviewVo(user.getId(), user
							.getUserName(), user.getPassword(), user
							.getFamilyName(), user.getPosition(), user
							.getEmail(), user.getPhone(), user.getType(),
							treeviewTmp.getId(), user.getIsDeptLead(), deptName);
					TreeviewVoList.add(treeviewVo);
				}
			}
			return TreeviewVoList;
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// ��ʼ����λPO
	public Position initPosition(Treeview treeview, String positionName)
			throws SystemException {
		return new Position(treeview, positionName);
	}

	// ��Ӹ�λ
	public boolean addPosition(Position position) throws SystemException {
		try {
			treeviewDao.addPosition(position);
		} catch (RuntimeException re) {
			re.printStackTrace();
			throw new SystemException("��ݿ�����쳣!");
		}
		return true;
	}

	// ��ݸ�λ�Ͳ��Ų������е��û�
	public List<TreeviewVo> getTreeviewByPositionLike(int deptName,
			String positionName, String familyName) throws SystemException {
		// ��ݲ��ź͸�λ��Ʋ���
		List positions = treeviewDao.findPositionLike(deptName, positionName);
		Treeview treeview = treeviewDao.findById(deptName);
		Position position = null;
		List<TreeviewVo> treeviews = new ArrayList<TreeviewVo>();
		for (Object o : positions) {
			position = (Position) o;

			// ��ݸ�λ�����û�
			User user = treeviewDao.getUserByPosition(position);

			treeviews.add(new TreeviewVo(user.getId(), user.getUserName(), user
					.getPassword(), user.getFamilyName(), user.getPosition(),
					user.getEmail(), user.getPhone(), user.getType(), user
							.getTreeview().getId(), user.getIsDeptLead(),
					treeview.getName()));
		}
		System.out.println("�ҵ�" + treeviews + "��");
		return treeviews;
	}

	// ��ݲ��������根据部门ID查找岗位
	public List<PositionVo> getPositionByDeptId(int deptId)
			throws SystemException {
		logger.debug("-------------------------------------------------------:"
				+ deptId);

		try {
			List<PositionVo> positions = new ArrayList<PositionVo>();
			List positionList = treeviewDao.getPositionByDeptId(deptId,
					Constants.DEPARTMENT);

			for (Object o : positionList) {
				Treeview temp = (Treeview) o;
				positions.add(new PositionVo(temp.getId(), temp.getName()));
			}
			return positions;
		} catch (Exception e) {
			throw new SystemException("��ݿ�����");
		}
	}

	// ��ݸ�λID���Ҹ�λ
	public Position getPositionById(int positionId) throws SystemException {
		try {
			return treeviewDao.getPositionById(positionId);
		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	public void updateUserPosition(UserPosition userPosition)
			throws SystemException {
		try {
			treeviewDao.updateUserPosition(userPosition);
		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// ����û��͸�λ�����û�---��λ
	public UserPosition getUserPositionByUserAndPosition(User user,
			Position position) throws SystemException {
		try {
			UserPosition userPosition = treeviewDao
					.getUserPositionByUserAndPosition(user);
			// userPosition.setPosition(position);
			return userPosition;
		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// ���ID�����û�
	public User getUserById(int userId) throws SystemException {
		try {
			return treeviewDao.getUserById(userId);
		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// �����û�
	public boolean updateUser(User user) throws SystemException {
		try {
			treeviewDao.updateUser(user);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	// ���½ڵ�
	public boolean updateNode(String nodeName, Treeview treeview)
			throws SystemException {
		try {
			treeviewDao.updateTreeview(treeview);

			if (treeview.getIsLeader().equals(2)) {// ���Ǹ�λ�ڵ�
				Position position = treeviewDao.findPositionByNameAndDeptId(
						nodeName, treeview.getParentId());
				position.setPositionName(treeview.getName());
				treeviewDao.updatePosition(position);
			}
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	// ������֯
	public boolean addOrganize(Treeview treeview) throws SystemException {
		try {
			treeviewDao.saveTreeview(treeview);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	public Treeview initTreeview(int parentId, String nodeName, int isLeader,
			String positionLevel, int activeFlag, int isChauffeur) {
		return new Treeview(parentId, nodeName, isLeader, positionLevel,
				activeFlag, isChauffeur);
	}

	// �����������û�
	public List getUserByTreeview(Treeview treeview) throws SystemException {
		try {
			return treeviewDao.getUserByTreeview(treeview);
		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// �ж��Ƿ��ɾ��
	public boolean isDeleteNode(int nodeId) throws SystemException {
		try {

			// �������е��ӽڵ�
			List childNodes = treeviewDao.getAllTreeByParentId(nodeId);
			System.out.println("����1" + childNodes);
			// �������еĸ�λ
			List Positions = treeviewDao.getPositionByDeptId(nodeId,
					Constants.DEPARTMENT);
			System.out.println("����2" + Positions);
			// �������е��û�
			List users = treeviewDao.getUserByTreeview(treeviewDao
					.findById(nodeId));
			System.out.println("����3" + Positions);
			if ((childNodes != null && childNodes.size() > 0)
					|| (Positions != null && Positions.size() > 0)
					|| (users != null && users.size() > 0)) {
				// ��ýڵ㻹���Ӳ��š���λ��Ա��������ɾ��
				return false;
			} else {// ����ɾ��
				return true;
			}

		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}


	/**
	 * 根据主键获取对象
	 * @param nodeId   主键id
	 * @return  对象Treeview
	 * @throws SystemException
	 */
	public Treeview getTreeviewById(int nodeId) throws SystemException {
		try {
			return treeviewDao.findById(nodeId);
		} catch (Exception e) {
			throw new SystemException("��ݿ�����쳣!");
		}
	}

	// 删除节点
	public void deleteNode(String treeviewId) throws SystemException {
		try {
			Treeview treeview = treeviewDao.findById(Integer
					.parseInt(treeviewId));
			System.out.println("节点为空吗。。。:" + treeview);
			treeviewDao.deleteTreeview(treeview);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(Constants.DELETENODEFAILTRUE);
			throw new SystemException(Constants.DELETENODEFAILTRUE);
		}
	}

	public List<Treeview> getAllDept() throws SystemException {
		try {
			return treeviewDao.getTreeViewToDept();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

⌨️ 快捷键说明

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