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

📄 usersmanager.java

📁 OA典型例子
💻 JAVA
字号:
package com.sure.oa.orgnization;

import com.sure.businessmodel.Page;
import com.sure.businessmodel.UpdateException;
import com.sure.businesslogic.AlreadyExistsException;
import com.sure.businesslogic.NotFoundException;
import com.sure.dataabstraction.DBManager;
import com.sure.dataabstraction.DBPoolException;
import com.sure.util.StringUtils;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.Vector;
/**
 * <p>Title: OA</p>
 * <p>Description: 国办项目</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: sure</p>
 * @author mengzy
 * @version 1.0
 */

public class UsersManager {

  public UsersManager() {
  }

  /**
   * 根据userId获得人员详情
   * @param userId
   */
  public Users getUsers(int userId) throws SQLException,DBPoolException, NotFoundException {
      Connection cn = DBManager.getConnection();
      try {
          String where = "Where userId = " + userId;
          Vector beans = UsersPersistent.load(cn, where);
          Users bean = (Users)beans.firstElement();
          return bean;
      }catch (SQLException sqle) {
          throw new NotFoundException();
      } finally {
          cn.close();
      }
  }

  /**
   * 根据userId获得人员详情
   * @param userId
   */
  public Users getUsers(String userId) throws SQLException,DBPoolException, NotFoundException{
    return getUsers(Integer.parseInt(userId));
  }

  /**
   * 根据userAccount获得人员详情
   * @param userAccount
   * @return
   */
  public Users getUsersByAccount(String userAccount) throws SQLException,DBPoolException, NotFoundException{
      Connection cn = DBManager.getConnection();
      try {
          String where = "Where LOWER(Account) = '" + userAccount + "'";
          Vector beans = UsersPersistent.load(cn, where);
          Users bean = (Users)beans.firstElement();
          return bean;
      }catch (SQLException sqle) {
          throw new NotFoundException();
      } finally {
          cn.close();
      }
  }
  /**
   * 根据一个单位的ID获得其管理员ID
   * @param unitId
   * @return
   * @throws SQLException
   * @throws DBPoolException
   */
  public Users getManagerUserId(int unitId) throws SQLException,DBPoolException {
      Connection cn = DBManager.getConnection();
      try{
          String where = "where status=1 and unitId=" + unitId + "";
          Vector p = UsersPersistent.load(cn,where);
          if(p!=null && p.size()>0){
            return (Users) p.firstElement();
          }else{
            return new Users();
          }
      }finally {
          cn.close();
      }
  }

  /**
  * 获得人员列表(包括查询和排序)
  * status说明:0——普通用户,1——单位管理员
  */
 public Page getUsersList(int start,String userName,String account,String sex,String position,int deptId,String orderBy,int unitId) throws SQLException,DBPoolException {
     Connection cn = DBManager.getConnection();
     try{
         String where = "where status in (0) ";
         if (!userName.equals("")){
           where = where + "and userName like '%" + userName + "%' ";
         }
         if (!account.equals("")){
           where = where + "and LOWER(account) like '%" + account.toLowerCase() + "%' ";
         }
         if (!sex.equals("")){
           where = where + "and sex='" + sex + "' ";
         }
         if (!position.equals("")){
           where = where + "and position like '%" + position + "%' ";
         }
         if (deptId != 0){
           where = where + "and deptId=" + deptId;
         }
         where = where + " and unitId=" + unitId + "  order by " + orderBy;
         Page p = UsersPersistent.load(cn, start, 10, where);
         return p;
     }finally {
         cn.close();
     }
 }

  /**
   * 根据deptId和unitId获得人员
   * @param deptId
   * @param unitId
   * @return
   * @throws SQLException
   * @throws DBPoolException
   */
  public Vector getUsersList(int deptId,int unitId) throws SQLException,DBPoolException {
      Connection cn = DBManager.getConnection();
      try{
          String where = "where status in (0)";
          if (deptId != 0){
            where = where + " and deptId=" + deptId;
          }
          where = where + " and unitId=" + unitId + " order by userName";
          Vector p = UsersPersistent.load(cn, where);
          return p;
      }finally {
          cn.close();
      }
  }

   /**
   * 根据unitId获得人员
   * @param unitId
   * @return
   * @throws SQLException
   * @throws DBPoolException
   */
  public Vector getUsersList(int unitId) throws SQLException,
         DBPoolException {
    return getUsersList(0, unitId);
  }

  /**
   * 保存人员信息
   * @param u
   * @return
   */
  public int saveUsers(Users u) throws SQLException,
            DBPoolException, UpdateException, NotFoundException {
      int retval = 0;
      Connection cn = DBManager.getConnection();
      try{

        String account = StringUtils.getSQLencode(u.getAccount());
        String where = "Where len(account)>0 and status in (0,1) and LOWER(account) = '" + account.toLowerCase() + "' and userId<>"+u.getUserId()+"";
        int intResult = UsersPersistent.getCount(cn, where);
        if (intResult > 0){
          throw new  UpdateException("系统中已经存在" + account + "这个帐号!");
        }
        retval = saveUsers(cn, u);
      }finally {
          cn.close();
      }
    return retval;
  }

  public int saveUsers(Connection cn, Users u) throws SQLException,
      DBPoolException, NotFoundException {
    int retval = 0;
    int userId = u.getUserId().intValue();
    UsersPersistent user = new UsersPersistent(u);
    if (userId == 0){
      u.setPassword(u.getEncodedPassword(u.getPassword()));
    }else{
      if (u.getPsnChanPass() != 1){//如果不修改密码,则将密码赋值为老的密码
        Users oldUser = getUsers(u.getUserId().intValue());
        u.setPassword(oldUser.getPassword());
      }else{
        //将密码加密处理
        u.setPassword(u.getEncodedPassword(u.getPassword()));
      }
      user.setRecordExists(true);
    }
    user.persist(cn);
    retval=user.getBean().getUserId().intValue();
    return retval;
  }

  /**
     * 删除人员
     * @param deptId
     * @throws SQLException
     * @throws DBPoolException
     * @throws NotFoundException
     */
    public void  delUsers(int userId) throws SQLException,
              DBPoolException, NotFoundException {
          Connection cn = DBManager.getConnection();
          try {
              String where = "Where userId = " + userId;
              UsersPersistent.delete(cn, where);
          }catch (SQLException sqle) {
              throw new NotFoundException();
          } finally {
              cn.close();
          }
      }

  public int getUsersCount(int unitId) throws SQLException, DBPoolException{
    Connection cn = DBManager.getConnection();
    try{
      String where = "where status in (0) and unitId = " + unitId + "";
      return UsersPersistent.getCount(cn, where);
    }finally {
      cn.close();
    }
  }
  }

⌨️ 快捷键说明

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