UserManager.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:17k
源码类别:
OA系统
开发平台:
Java
- package com.gforce.gfoa;
- import com.gforce.currency.database.*;
- import com.gforce.currency.*;
- import java.util.*;
- /**
- * <p>Title: 吉力科技办公自动化系统</p>
- * <p>Description: 吉力科技办公自动化系统</p>
- * <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司 Copyright (c) 2003 GForce Sceince & Technology</p>
- * <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
- * @author 马登军
- * @version 1.0
- */
- public class UserManager
- extends RecordManager
- {
- public UserManager()
- {
- }
- protected final static String TableName = "UserInfo"; //定义声明本类操作表名称为“UserInfo”
- protected final static String IDFieldName = "ID"; //定义声明主键或者可以确定唯一记录的字段名称为“ID”,必须为自增整型
- protected final static String[] NumericFieldsName =
- {
- "PersonnelID", "RoleID"}; //声明数值型字段名称
- protected final static String[] StringFieldsName =
- {
- "UserName", "Password"}; //声明字符型字段名称
- protected final static String[] DatetimeFieldsName =
- {}; //声明日期时间型字段名称
- protected final static String[] TextFieldsName =
- {}; //声明大字符串型字段名称
- /**
- * 根据字段名称获取插入数据时表单元素名称
- * @param strFieldName 字段名称
- * @return 表单素名称
- */
- protected String InsertParament(String strFieldName)
- {
- return "" + strFieldName + ""; //可以根据需要加前缀、后缀
- }
- /**
- * 根据字段名称获取修改数据时表单元素名称
- * @param strFieldName 字段名称
- * @return 表单素名称
- */
- protected String UpdateParament(String strFieldName)
- {
- return "" + strFieldName + ""; //可以根据需要加前缀、后缀
- }
- /**
- * 获取本类操作表名称
- * @return 表名称
- */
- public String getTableName()
- { //获取本类操作表名称
- return TableName;
- }
- protected String getIDFieldName()
- { //获取主键或者可以确定唯一记录的字段名称
- return IDFieldName;
- }
- protected String[] getNumericFieldsName()
- { //获取数值型字段名称
- return NumericFieldsName;
- }
- protected String[] getStringFieldsName()
- { //获取字符型字段名称
- return StringFieldsName;
- }
- protected String[] getDatetimeFieldsName()
- { //获取日期时间型字段名称
- return DatetimeFieldsName;
- }
- protected String[] getTextFieldsName()
- { //获取大字符串型字段名称
- return TextFieldsName;
- }
- /**
- *检查用户登录是否正确,并返回用户ID
- * @param strUserName 用户名
- * @param strPassword 用户密码
- * @return 用户ID
- */
- public static int CheckLogin(String strUserName, String strPassword)
- {
- int intReturn = 0;
- Vector vt = SQLManager.GetResultSet(
- "Select ID from UserInfo where UserName = '" + strUserName.toLowerCase() +
- "' and Password = '" + StringNew.getEncodePassword(strPassword) + "'");
- if (vt.size() > 0)
- {
- intReturn = Integer.parseInt( ( (Vector) vt.get(0)).get(0).toString());
- }
- return intReturn;
- }
- /**
- * 通过用户ID获取用户角色ID
- * @param intUserID 用户ID
- * @return 角色ID
- */
- public static int GetUserRoleID(int intUserID)
- {
- int intReturn = 0;
- try
- {
- Vector vt = SQLManager.GetResultSet("Select RoleID from UserInfo where ID=" + intUserID + "");
- if (vt.size() > 0)
- {
- intReturn = Integer.parseInt( ( (Vector) vt.get(0)).get(0).toString());
- }
- }
- catch (Exception err)
- {
- }
- return intReturn;
- }
- /**
- * 获取所有记录向量集
- * @return 所有记录向量集
- */
- public static Vector getAllRecord()
- {
- Vector vt = SQLManager.GetResultSet("SELECT a.*,b.Number,b.Name FROM " + TableName +
- " as a left outer join PersonnelInfo as b on (a.PersonnelID = b.ID) ORDER BY b.Number,b.ID,a.ID");
- return vt;
- }
- /**
- * 获取属于指定ID部门的所有用户向量集和员工信息
- * @param iDepartmentID 指定部门ID
- * @return 属于指定部门的用户向量集
- */
- public static Vector getRecordAndPersonnelInfoByDepartmentID(int iDepartmentID)
- {
- String strSQL = "SELECT a.*,b.Number,b.Name FROM " + TableName
- + " as a left outer join PersonnelInfo as b on (a.PersonnelID = b.ID) where not b.ID is null ORDER BY b.Number,b.ID,a.ID";
- if (iDepartmentID == 0)
- {
- strSQL = "SELECT a.*,b.Number,b.Name FROM " + TableName
- + " as a left outer join PersonnelInfo as b on (a.PersonnelID = b.ID) where not b.ID is null ORDER BY b.Number,b.ID,a.ID";
- }
- else
- {
- strSQL = "SELECT a.*,b.Number,b.Name FROM " + TableName + " as a left outer join PersonnelInfo as b on (a.PersonnelID = b.ID) Where b.DepartmentID in (select ID from DepartmentInfo where Station like ((select Station from DepartmentInfo where ID="
- + iDepartmentID + ")+'" + iDepartmentID + "_%')) or b.DepartmentID=" +
- iDepartmentID + " ORDER BY b.Number,b.ID,a.ID";
- }
- Vector vt = SQLManager.GetResultSet(strSQL);
- return vt;
- }
- /**
- * 获取属于指定ID部门的所有用户向量集
- * @param iDepartmentID 指定部门ID
- * @return 属于指定部门的用户向量集
- */
- public static Vector getRecordByDepartmentID(int iDepartmentID)
- {
- Vector vt = SQLManager.GetResultSet("SELECT a.ID,a.UserName,a.Password,a.PersonnelID,a.RoleID,c.RoleName FROM "
- + TableName + " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) left outer join RoleInfo as c on (a.RoleID=c.ID) where b.DepartmentID=" +
- iDepartmentID +
- " ORDER BY a.ID");
- return vt;
- }
- /**
- * 获取属于指定IDs部门的所有用户向量集
- * @param iDepartmentID 指定部门ID
- * @return 属于指定部门的用户向量集
- */
- public static Vector getRecordByDepartmentIDs(String strDepartmentIDs)
- {
- Vector vt = SQLManager.GetResultSet("SELECT a.ID,a.UserName,a.Password,a.PersonnelID,a.RoleID,c.RoleName FROM "
- + TableName + " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) left outer join RoleInfo as c on (a.RoleID=c.ID) where b.DepartmentID in (" +
- strDepartmentIDs +
- ") ORDER BY a.ID");
- return vt;
- }
- /**
- * 获取指定用户ID的用户信息,包括部门ID
- * @param iUserID 用户ID
- * @return 指定用户ID的用户信息,包括部门ID
- */
- public static Vector getUserInfoByID(int iUserID)
- {
- Vector vt = SQLManager.GetResultSet("SELECT a.ID,a.UserName,a.Password,a.PersonnelID,a.RoleID,b.DepartmentID FROM "
- + TableName +
- " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) where a.ID="
- + iUserID + " ORDER BY a.ID");
- return vt;
- }
- /**
- * 通过用户ID获取员工姓名
- * @param iUserID 用户ID
- * @return 员工姓名
- */
- public static String getPersonnelNameByUserID(int iUserID)
- {
- String strReturnValue = "姓名未知";
- Vector vt = SQLManager.GetResultSet("SELECT b.Name FROM " + TableName +
- " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) where a.ID="
- + iUserID + " ORDER BY a.ID");
- if (vt.size() > 0)
- {
- strReturnValue = ( (Vector) vt.get(0)).get(0).toString();
- }
- return strReturnValue;
- }
- /**
- * 通过用户IDs字符串获取员工姓名
- * @param strUserIDs 用户IDs字符串
- * @return 员工姓名
- */
- public static String getPersonnelNamesByUserIDs(String strUserIDs)
- {
- String strReturnValue = "";
- if(strUserIDs.length()>0)
- {
- Vector vt = SQLManager.GetResultSet("SELECT b.Name FROM " + TableName +
- " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) where a.ID in ("
- + strUserIDs + ") ORDER BY b.Number");
- for(int i=0;i<vt.size();i++)
- {
- strReturnValue += "," + ((Vector) vt.get(i)).get(0).toString();
- }
- }
- if(strReturnValue.length()>0)
- {
- return strReturnValue.substring(1);
- }
- else
- {
- return "";
- }
- }
- /**
- * 通过用户ID获取员工编号
- * @param iUserID 用户ID
- * @return 员工编号
- */
- public static String getPersonnelNumberByUserID(int iUserID)
- {
- String strReturnValue = "";
- Vector vt = SQLManager.GetResultSet("SELECT b.Number FROM " + TableName +
- " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) where a.ID="
- + iUserID + " ORDER BY a.ID");
- if (vt.size() > 0)
- {
- strReturnValue = ( (Vector) vt.get(0)).get(0).toString();
- }
- return strReturnValue;
- }
- /**
- * 通过用户ID获取员工职务
- * @param iUserID 用户ID
- * @return 员工职务
- */
- public static String getPlaceNameByUserID(int iUserID)
- {
- String strReturnValue = "职务未知";
- Vector vt = SQLManager.GetResultSet("SELECT c.PlaceName FROM " + TableName + " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) left outer join PlaceInfo as c on (b.PlaceID=c.ID) where a.ID=" +
- iUserID + " ORDER BY a.ID");
- if (vt.size() > 0)
- {
- strReturnValue = ( (Vector) vt.get(0)).get(0).toString();
- }
- return strReturnValue;
- }
- /**
- * 通过用户ID获取部门名称
- * @param iUserID 用户ID
- * @return 员工所属部门名称
- */
- public static String getDepartmentNameByUserID(int iUserID)
- {
- String strReturnValue = SystemParament.GetSystemName();
- Vector vt = SQLManager.GetResultSet("SELECT c.Name FROM " + TableName + " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) left outer join DepartmentInfo as c on (b.DepartmentID=c.ID) where a.ID=" +
- iUserID + " ORDER BY a.ID");
- if (vt.size() > 0)
- {
- strReturnValue = ( (Vector) vt.get(0)).get(0).toString();
- }
- return strReturnValue;
- }
- /**
- * 通过用户ID获取部门ID
- * @param iUserID 用户ID
- * @return 员工所属部门ID
- */
- public static String getDepartmentIDByUserID(int iUserID)
- {
- String strReturnValue = SystemParament.GetSystemName();
- Vector vt = SQLManager.GetResultSet("SELECT c.ID FROM " + TableName + " as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) left outer join DepartmentInfo as c on (b.DepartmentID=c.ID) where a.ID=" +
- iUserID + " ORDER BY a.ID");
- if (vt.size() > 0)
- {
- strReturnValue = ( (Vector) vt.get(0)).get(0).toString();
- }
- return strReturnValue;
- }
- /**
- * 通过用户ID获取用户角色名称
- * @param iUserID 用户ID
- * @return 用户角色名称
- */
- public static String getRoleNameByUserID(int iUserID)
- {
- String strReturnValue = "未知角色";
- Vector vt = SQLManager.GetResultSet("SELECT b.RoleName FROM " + TableName +
- " as a left outer join RoleInfo as b on (a.RoleID=b.ID) where a.ID=" +
- iUserID + " ORDER BY a.ID");
- if (vt.size() > 0)
- {
- strReturnValue = ( (Vector) vt.get(0)).get(0).toString();
- }
- return strReturnValue;
- }
- /**
- * 修改用户密码
- * @param strUserName 用户名
- * @param strOldPassword 旧密码
- * @param strNewPassword 新密码
- * @return 错误代码
- */
- public static int changeUserPassword(String strUserName, String strOldPassword, String strNewPassword)
- {
- strNewPassword = StringNew.getEncodePassword(strNewPassword);
- int iReturnValue = CheckLogin(strUserName, strOldPassword);
- if (iReturnValue < 1)
- {
- return -4;
- }
- return SQLManager.ExcuteSQL("Update " + TableName + " set Password='" + strNewPassword + "' where ID="
- + iReturnValue);
- }
- /**
- * 获取用户列表数据向量集
- * @return 用户列表数据向量集
- */
- public static Vector getUserTreeData()
- {
- Vector vc = new Vector();
- vc = SQLManager.GetResultSet("select a.ID,b.Name,b.DepartmentID,b.Number,c.Station from UserInfo as a left outer join PersonnelInfo as b on (a.PersonnelID=b.ID) left outer join DepartmentInfo as c on(c.ID=b.DepartmentID) where b.Name<>'' and (not b.Number like '%离职%') order by b.Number,b.ID,a.ID");
- return vc;
- }
- /**
- * 获取所有用户FTP用户名、密码数据
- * @return 所有用户FTP用户名、密码数据
- */
- public static Vector getAllUserFTPData()
- {
- return SQLManager.GetResultSet("Select a.ID,b.Name,b.Number,a.FTPUserName,a.FTPPassword from " + TableName
- + " as a left outer join PersonnelInfo as b on (a.PersonnelID = b.ID) order by b.Number,b.ID,a.ID");
- }
- /**
- * 获取指定用户的FTP用户名、密码
- * @param iUserID 用户ID
- * @return 指定用户的FTP用户名、密码
- */
- public static Vector getUserFTPData(int iUserID)
- {
- return SQLManager.GetResultSet("Select FTPUserName,FTPPassword from " + TableName + " where ID=" + iUserID);
- }
- /**
- * 设置指定用户的FTP用户名、密码
- * @param iUserID 用户ID
- * @param strFTPUserName FTP用户名
- * @param strFTPPassword FTP密码
- * @return 错误代码
- */
- public static int updateUserFTPData(int iUserID, String strFTPUserName, String strFTPPassword)
- {
- Vector vt = SQLManager.GetResultSet("Select * from " + TableName + " where ID=" + iUserID);
- if (vt.size() > 0)
- {
- strFTPUserName = strFTPUserName.replaceAll("'", "''");
- strFTPPassword = strFTPPassword.replaceAll("'", "''");
- return SQLManager.ExcuteSQL("Update " + TableName + " set FTPUserName='" + strFTPUserName + "',FTPPassword='"
- + strFTPPassword + "' where ID=" + iUserID);
- }
- else
- {
- /**
- * 该用户不存在
- */
- return -1;
- }
- }
- /**
- * 获取指定用户的风格ID
- * @param iUserID 用户ID
- * @return 指定用户的风格ID
- */
- public static int getUserStyleID(int iUserID)
- {
- try
- {
- Vector vt = SQLManager.GetResultSet("Select StyleID from " + TableName + " where ID=" + iUserID);
- if (vt.size() > 0)
- {
- String strStyle = ( (Vector) vt.get(0)).get(0).toString();
- if (strStyle.length() > 0)
- {
- return Integer.parseInt(strStyle);
- }
- else
- {
- return 0;
- }
- }
- else
- {
- return 0;
- }
- }
- catch (Exception err)
- {
- return 0;
- }
- }
- /**
- * 设置指定用户风格ID
- * @param iUserID 用户ID
- * @param iStyleID 风格ID
- * @return 错误代码
- */
- public static int setUserStyle(int iUserID, int iStyleID)
- {
- Vector vt = SQLManager.GetResultSet("Select * from " + TableName + " where ID=" + iUserID);
- if (vt.size() > 0)
- {
- vt = SQLManager.GetResultSet("Select * from StyleInfo where ID=" + iStyleID);
- if (vt.size() > 0)
- {
- return SQLManager.ExcuteSQL("Update " + TableName + " set StyleID='" + iStyleID + "' where ID=" + iUserID);
- }
- else
- {
- /**
- * 该系统风格不存在
- */
- return -8;
- }
- }
- else
- {
- /**
- * 该用户不存在
- */
- return -1;
- }
- }
- /**
- * 重构插入记录的方法,将用户名自动转换为小写,解决用户名区分大小写的问题
- * @param m_request 包含记录内容的Request请求
- * @return 新用户ID或者错误代码(小于1)
- */
- public int InsertRecord(Request m_request)
- {
- int iReturnValue = 0;
- iReturnValue = super.InsertRecord(m_request);
- SQLManager.ExcuteSQL("Update " + TableName + " set UserName='" + m_request.GetString(InsertParament("UserName")).toLowerCase() + "',Password='" + StringNew.getEncodePassword(m_request.GetString(InsertParament("Password"))) + "' where ID=" + iReturnValue);
- return iReturnValue;
- }
- /**
- * 重构修改记录的方法,将用户名自动转换为小写,解决用户名区分大小写的问题
- * @param m_request 包含记录内容的Request请求
- * @return 错误代码(小于1)
- */
- public int UpdateRecord(Request m_request)
- {
- int iReturnValue = super.UpdateRecord(m_request);
- SQLManager.ExcuteSQL("update " + TableName + " set UserName='" + m_request.GetString(UpdateParament("UserName")).toLowerCase() + "',Password='" + StringNew.getEncodePassword(m_request.GetString(UpdateParament("Password"))) + "' where " + IDFieldName + "=" + m_request.GetInt(UpdateParament(IDFieldName)) + "");
- return iReturnValue;
- }
- /**
- * 获取属于指定ID部门的所有用户向量集
- * @param iDepartmentID 指定部门ID
- * @return 属于指定部门的用户向量集
- */
- public static Vector getRecordByIDs(String strIDs)
- {
- Vector vt = SQLManager.GetResultSet("select * from " + TableName + " where ID IN (" + strIDs + ")");
- return vt;
- }
- }