DepartmentManager.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:13k
源码类别:
OA系统
开发平台:
Java
- package com.gforce.gfoa;
- /**
- * <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
- */
- import com.gforce.currency.*;
- import com.gforce.currency.database.*;
- import java.sql.*;
- import java.util.*;
- public class DepartmentManager
- extends RecordManager
- {
- public DepartmentManager()
- {
- }
- protected final static String TableName = "DepartmentInfo"; //定义声明本类操作表名称为
- protected final static String IDFieldName = "ID"; //定义声明主键或者可以确定唯一记录的字段名称为“ID”,必须为自增整型
- protected final static String[] NumericFieldsName =
- {
- "LevelNumber", "ChildrenAcount", "OrderNumber", "IsLink", "IsShow"}; //声明数值型字段名称
- protected final static String[] StringFieldsName =
- {
- "Name", "Station", "OpenedICO", "CloseedICO", "LinkUrl", "Target", "Content"}; //声明字符型字段名称
- 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;
- }
- /**
- * 获取所有记录的向量集
- * @return 所有记录的向量集
- */
- public static Vector getDepartmentData()
- {
- Vector vc = new Vector();
- vc = SQLManager.GetResultSet("select * from " + TableName + " ORDER BY OrderNumber ");
- return vc;
- }
- /**
- * 获取指定ID的数据集
- * @param intID 要检索的ID
- * @return 指定ID的数据集
- */
- public static Vector getRecordByID(int intID)
- {
- Vector vc = new Vector();
- vc = SQLManager.GetResultSet("select * from " + TableName + " WHERE ID = " + intID);
- return vc;
- }
- /**
- * 获取指定ID部门带上级信息全称
- * @param iID 部门ID
- * @return 带上级信息的部门全称
- */
- public static String getDepartFullName(int iID)
- {
- String strDepartName = "";
- Vector vc = getRecordByID(iID);
- if(vc.size()>0)
- {
- strDepartName = ((Vector)vc.get(0)).get(2).toString();
- strDepartName = strDepartName.replaceAll("_0_","").trim();
- if(strDepartName.indexOf("_")>0)
- {
- String[] strDepartID = strDepartName.split("_");
- strDepartName = "";
- for(int i=0;i<strDepartID.length;i++)
- {
- try
- {
- Vector vt = getRecordByID(Integer.parseInt(strDepartID[i], 10));
- if (vt.size() > 0)
- {
- strDepartName += ( (Vector) vt.get(0)).get(1).toString() + "→";
- }
- }
- catch(Exception err)
- {
- }
- }
- }
- else
- {
- strDepartName = "";
- }
- strDepartName += ((Vector)vc.get(0)).get(1).toString();
- }
- return strDepartName;
- }
- /**
- * 根据部门ID字符串获取部门全称
- * @param iIDs 部门ID字符串
- * @return 部门全称
- */
- public static String getDepartNamesByIDs(String iIDs)
- {
- String strDepartNames = "";
- if(iIDs.length()>0)
- {
- String[] strDepartID = iIDs.split(",");
- for(int i=0;i<strDepartID.length;i++)
- {
- try
- {
- strDepartNames += "n" + getDepartFullName(Integer.parseInt(strDepartID[i], 10));
- }
- catch(Exception err){}
- }
- }
- if(strDepartNames.length()>0)
- {
- return strDepartNames.substring(1);
- }
- else
- {
- return "";
- }
- }
- /**
- * 获取指定ID部门下子部门个数
- * @param iDepartmentID 部门ID
- * @return 指定ID部门下子部门个数
- */
- public static int getSubDepartmentCount(int iDepartmentID)
- {
- int iReturnValue = 0;
- String strSQL;
- Vector vc = new Vector();
- if (iDepartmentID == 0)
- {
- strSQL = "select count(*) from " + TableName + " Where Station = '_0_'";
- }
- else
- {
- strSQL = "select Count(*) from " + TableName + " where Station=((select Station from " + TableName +
- " where ID=" + iDepartmentID + ")+'" + iDepartmentID + "_')";
- }
- vc = SQLManager.GetResultSet(strSQL);
- iReturnValue = Integer.parseInt( ( (Vector) vc.get(0)).get(0).toString());
- return iReturnValue;
- }
- /**
- * 更新指定ID部门的子部门个数
- * @param iDepartmentID 部门ID
- */
- public void updateSubDepartmentCount(int iDepartmentID)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set ChildrenAcount=" + getSubDepartmentCount(iDepartmentID) +
- " where ID=" + iDepartmentID);
- }
- public void updateSubDepartmentData(int iDepartmentID, String strNewStation, String strOldStation, int iLevelChange)
- {
- String strUpdateSQL = "Update " + TableName + " set LevelNumber=LevelNumber + " + iLevelChange
- + ",Station = Replace(Station,'" + strOldStation + "','" + strNewStation + "') where Station like '"
- + strOldStation + iDepartmentID + "_" + "%'";
- SQLManager.ExcuteSQL(strUpdateSQL);
- }
- /**
- * 获取指定ID部门下所有员工人数
- * @param iDepartmentID 部门ID
- * @return 指定ID部门下所有员工人数
- */
- public static int getPersonCountOfDepartment(int iDepartmentID)
- {
- int iReturnValue = 0;
- String strSQL;
- Vector vc = new Vector();
- if (iDepartmentID == 0)
- {
- strSQL = "select count(*) from PersonnelInfo";
- }
- else
- {
- strSQL = "select count(*) from PersonnelInfo where DepartmentID in (select ID from " + TableName +
- " where Station like ((select Station from " + TableName +
- " where ID=" + iDepartmentID + ")+'" + iDepartmentID + "_%')) or DepartmentID=" + iDepartmentID;
- }
- vc = SQLManager.GetResultSet(strSQL);
- iReturnValue = Integer.parseInt( ( (Vector) vc.get(0)).get(0).toString());
- return iReturnValue;
- }
- /**
- * 新增部门记录
- * @param m_request 包含新部门记录的Request请求
- * @return 新部门的ID(大于等于1)或者错误代码(小于1)
- */
- public int InsertRecord(Request m_request)
- {
- int iReturnValue = super.InsertRecord(m_request);
- int iDepartmentID = m_request.GetInt("DepartmentID");
- updateSubDepartmentCount(iDepartmentID);
- return iReturnValue;
- }
- /**
- * 修改部门记录
- * @param m_request 包含部门记录的Request请求
- * @return 部门的ID(大于等于1)或者错误代码(小于1)
- */
- public int UpdateRecord(Request m_request)
- {
- int iID = m_request.GetInt("ID");
- int iNewLevelNumber = m_request.GetInt("LevelNumber");
- String strNewStation = m_request.GetString("Station");
- Vector vc = SQLManager.GetResultSet("select Station,LevelNumber from " + TableName + " where ID=" + iID);
- String strOldStation = ( (Vector) vc.get(0)).get(0).toString();
- int iOldLevelNumber = Integer.parseInt(( (Vector) vc.get(0)).get(1).toString());
- String strStation = strOldStation.substring(0, strOldStation.length() - 1);
- int iOldDepartmentID = Integer.parseInt(strStation.substring(strStation.lastIndexOf("_")+1));
- int iNewDepartmentID = m_request.GetInt("DepartmentID");
- int iReturnValue = 0;
- if (iOldDepartmentID != iNewDepartmentID)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where OrderNumber>(select OrderNumber from " + TableName + " where ID=" + iID +") and Station=((select Station from " + TableName + " where ID=" + iID +")+'')");
- iReturnValue = super.UpdateRecord(m_request);
- updateSubDepartmentCount(iNewDepartmentID);
- updateSubDepartmentCount(iOldDepartmentID);
- updateSubDepartmentData(iID,strNewStation,strOldStation,iNewLevelNumber-iOldLevelNumber);
- setDepartmentOrderNumber(iID,10000);
- reOrderDepartment(strOldStation);
- reOrderDepartment(strNewStation);
- }
- else
- {
- iReturnValue = super.UpdateRecord(m_request);
- reOrderDepartment(strNewStation);
- }
- return iReturnValue;
- }
- /**
- * 删除指定ID部门
- * @param iID 部门ID
- * @return 错误代码(小于1)
- */
- public int DeleteByID(int iID)
- {
- SQLManager.ExcuteSQL("Update " + TableName
- + " set OrderNumber=OrderNumber-1 where OrderNumber>(select OrderNumber from " + TableName
- + " where ID=" + iID + ") and Station=((select Station from " + TableName + " where ID="
- + iID + ")+'')");
- int iReturnValue = super.DeleteByID(iID);
- updateSubDepartmentCount(iID);
- return iReturnValue;
- }
- /**
- * 获取部门树形列表数据向量集
- * @return 部门树形列表数据向量集
- */
- public static Vector getDepartmentTreeData()
- {
- Vector vc = new Vector();
- vc = SQLManager.GetResultSet("select * from " + TableName + " where IsShow=1 ORDER BY OrderNumber ");
- return vc;
- }
- /**
- * 按照指定方向移动指定部门
- * @param iDepartmentID int 指定部门的ID
- * @param strDirect String 指定移动方向
- * @return int 错误代码
- */
- public static int moveDepartment(int iDepartmentID,String strDirect)
- {
- int iErrCode=1;
- Vector vt=getRecordByID(iDepartmentID);
- if(vt.size()==1)
- {
- if(strDirect.equalsIgnoreCase("Top"))
- {
- setDepartmentOrderNumber(iDepartmentID,-10000);
- }
- else if(strDirect.equalsIgnoreCase("Bottom"))
- {
- setDepartmentOrderNumber(iDepartmentID,10000);
- }
- else if(strDirect.equalsIgnoreCase("Up"))
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where ID=" + iDepartmentID +"");
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber+1 where ID in (Select ID from " + TableName + " where Station=(Select Station from " + TableName + " where ID=" + iDepartmentID +") and OrderNumber=(Select OrderNumber from " + TableName + " where ID=" + iDepartmentID +") and ID<>" + iDepartmentID + ")");
- }
- else if(strDirect.equalsIgnoreCase("Down"))
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber+1 where ID=" + iDepartmentID +"");
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where ID in (Select ID from " + TableName + " where Station=(Select Station from " + TableName + " where ID=" + iDepartmentID +") and OrderNumber=(Select OrderNumber from " + TableName + " where ID=" + iDepartmentID +") and ID<>" + iDepartmentID + ")");
- }
- reOrderDepartment(( (Vector) vt.get(0)).get(2).toString());
- }
- else
- {
- iErrCode=-3;
- }
- return iErrCode;
- }
- /**
- * 修改指定部门的排序编号
- * @param iDepartmentID int 指定部门ID
- * @param iOrderNumber int 新的排序编号
- */
- private static void setDepartmentOrderNumber(int iDepartmentID,int iOrderNumber)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=" + iOrderNumber + " where ID=" + iDepartmentID + "");
- }
- /**
- * 重新排序指定位置的部门
- * @param strStation String
- */
- private static void reOrderDepartment(String strStation)
- {
- if(strStation==null || strStation.trim().length()==0)
- {
- strStation="_0_";
- }
- Vector vt=SQLManager.GetResultSet("Select * from " + TableName + " where Station='" + strStation + "' order by OrderNumber");
- for(int i=0;i<vt.size();i++)
- {
- try
- {
- int iID = 0;
- iID=Integer.parseInt(( (Vector) vt.get(i)).get(0).toString());
- setDepartmentOrderNumber(iID,i+1);
- }
- catch(Exception err)
- {
- }
- }
- }
- }