📄 signmanager.java
字号:
package com.gforce.gfoa;
import com.gforce.currency.database.*;
import com.gforce.currency.*;
import java.util.*;
import java.text.*;
/**
* <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 SignManager
extends RecordManager
{
public SignManager()
{
}
protected final static String TableName = "SignInfo"; //定义声明本类操作表名称
protected final static String IDFieldName = "ID"; //定义声明主键或者可以确定唯一记录的字段名称为“ID”,必须为自增整型
protected final static String[] NumericFieldsName =
{
"UserID", "SignTypeID", "IsNormal", "EditUserID"}; //声明数值型字段名称
protected final static String[] StringFieldsName =
{
"SignIP", "Remark", "EditIP"}; //声明字符型字段名称
protected final static String[] DatetimeFieldsName =
{
"SignTime"}; //声明日期时间型字段名称
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;
}
/**
* 获取用户是否已经签到
* @param iUserID 用户ID
* @param iSignTypeID 签到类型ID
* @return 用户已经正确签到返回1,用户已经不正确签到返回2,用户没有签到返回3
*/
public static int getIsUserSign(int iUserID, int iSignTypeID)
{
String strDate = StringNew.GetDateString(new Date(), "yyyy-MM-dd");
Vector vt = SQLManager.GetResultSet("Select * from SignInfo where UserID=" + iUserID + " and SignTypeID="
+ iSignTypeID + " and (SignTime Between '" + strDate + " 00:00' and '"
+ strDate + " 23:59') order by IsNormal");
if (vt.size() > 0)
{
if ( ( (Vector) vt.get(0)).get(5).toString().equalsIgnoreCase("true"))
{
return 1;
}
else
{
return 2;
}
}
else
{
return 3;
}
}
/**
* 插入签到记录
* @param iUserID 签到用户
* @param iTypeID 签到类型
* @param strIP 签到用户的IP地址
* @return 是否插入成功等于-6表示此类型已经签到,大于0表示插入成功,等于-1表示记录重复。
*/
public static String InsertRecord(int iUserID, int iTypeID, String strIP)
{
Date dateNow = new Date();
String strNow = StringNew.GetDateString(dateNow, "yyyy-MM-dd HH:mm:ss");
String strDate = StringNew.GetDateString(dateNow, "yyyy-MM-dd");
int iIsUserSigned = getIsUserSign(iUserID, iTypeID);
int IsNormal = 0;
String strMsg = "";
String strTime = StringNew.GetDateString(dateNow, "HH:mm");
String strSQL = "SELECT * FROM SignTypeInfo WHERE ID=" + iTypeID + "";
Vector vt = SQLManager.GetResultSet(strSQL);
if (vt.size() > 0)
{
String strTypeName = ( (Vector) vt.get(0)).get(1).toString();
if (iIsUserSigned == 1)
{
return "“" + strTypeName + "”您已经成功签到了,不能多次签到!";
}
else if(iIsUserSigned == 2)
{
if ( (strTime.compareToIgnoreCase( ( (Vector) vt.get(0)).get(2).toString())) < 0)
{
IsNormal = 0;
strMsg = ( (Vector) vt.get(0)).get(4).toString();
return "在正常签到时间段之前您已经签到了,请在正常签到时间段内签到!\\n" + strMsg;
}
else if ( (strTime.compareToIgnoreCase( ( (Vector) vt.get(0)).get(3).toString())) > 0)
{
IsNormal = 0;
strMsg = ( (Vector) vt.get(0)).get(5).toString();
return "在正常签到时间段之后您已经签到了,希望以后在正常签到时间段内签到!\\n" + strMsg;
}
else
{
IsNormal = 1;
strMsg = "";
SQLManager.ExcuteSQL("Delete from SignInfo where UserID=" + iUserID + " and SignTypeID=" + iTypeID
+ " and (SignTime Between '" + strDate + " 00:00' and '" + strDate + " 23:59')");
SQLManager.ExcuteSQL("Insert " + TableName
+ " (UserID,SignTypeID,SignTime,SignIP,IsNormal,Remark,EditUserID,EditIP) Values ("
+ iUserID + "," + iTypeID + ",'" + strNow + "','" + strIP + "'," + IsNormal + ",'"
+ strMsg + "',0,'')");
return "“" + strTypeName + "”签到成功!";
}
}
else
{
String strReturnValue="“" + strTypeName + "”签到成功!";
if ( (strTime.compareToIgnoreCase( ( (Vector) vt.get(0)).get(2).toString())) < 0)
{
IsNormal = 0;
strMsg = ( (Vector) vt.get(0)).get(4).toString();
strReturnValue=strMsg + "\\n" + strReturnValue;
}
else if ( (strTime.compareToIgnoreCase( ( (Vector) vt.get(0)).get(3).toString())) > 0)
{
IsNormal = 0;
strMsg = ( (Vector) vt.get(0)).get(5).toString();
strReturnValue=strMsg + "\\n" + strReturnValue;
}
else
{
IsNormal = 1;
strMsg = "";
}
SQLManager.ExcuteSQL("Insert " + TableName
+ " (UserID,SignTypeID,SignTime,SignIP,IsNormal,Remark,EditUserID,EditIP) Values ("
+ iUserID + "," + iTypeID + ",'" + strNow + "','" + strIP + "'," + IsNormal + ",'"
+ strMsg + "',0,'')");
return strReturnValue;
}
}
else
{
return "指定的签到不存在,签到失败!请与管理员联系!";
}
}
/**
* 获取指定用户时间段内的签到记录
* @param iUserID 指定用户ID
* @param strStartDate 开始日期
* @param strEndDate 结束日期
* @return 指定用户时间段内的签到记录数据集
*/
public static Vector getUserSign(int iUserID, String strStartDate ,String strEndDate)
{
Vector vt = SQLManager.GetResultSet("SELECT * FROM " + TableName + " where UserID = " + iUserID + " and ('"+ strStartDate +" 00:00:00' < SignTime) and ("+ strEndDate +" 23:59:59 > SignTime) Order By SignTime");
return vt;
}
/**
* 获取指定记录的数据集
* @param SignID 指定记录的ID
* @return 指定记录的数据集
*/
public static Vector getSignByID(int SignID)
{
Vector vt = SQLManager.GetResultSet("SELECT * FROM " + TableName + " where ID = " + SignID );
return vt;
}
/**
* 获取指定用户、指定考勤类型、指定时间段内的签到统计信息
* @param iUserID 指定的用户ID
* @param iTypeID 类型ID
* @param strStartDate 开始时间
* @param strEndDate 结束时间
* @return 指定的记录集
*/
public static String getSignSUM(int iUserID, int iTypeID, String strStartDate, String strEndDate)
{
String strSUM = " ";
try
{
//*************正常签到的数目
Vector vt = SQLManager.GetResultSet("SELECT Count(*) FROM " + TableName + " where (UserID = " + iUserID
+ ")and (SignTypeID = " + iTypeID + ") and ('" + strStartDate
+ "' < SignTime) and ('" + strEndDate
+ " 23:59:59' > SignTime) and (IsNormal = 1)");
int iNormalCount = Integer.parseInt( ( (Vector) vt.get(0)).get(0).toString(), 10);
//*************不正常签到的数目
vt = SQLManager.GetResultSet("SELECT Count(*) FROM " + TableName + " where (UserID = " + iUserID
+ ")and (SignTypeID = " + iTypeID + ") and ('" + strStartDate
+ "' < SignTime) and ('" + strEndDate + " 23:59:59' > SignTime) and (IsNormal = 0)");
int iAbnormalCount = Integer.parseInt( ( (Vector) vt.get(0)).get(0).toString(), 10);
//*************漏签到的数目
vt = SignTypeManager.getRecordByID(iTypeID);
if (vt.size() > 0)
{
if ( ("," + ( (Vector) vt.get(0)).get(8).toString() + ",").indexOf("," + iUserID + ",") < 0)
{
SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date dateStartDate = sdfDateFormat.parse(strStartDate);
Date dateEndDate = sdfDateFormat.parse(strEndDate);
String strActiveWeekday = "," + ((Vector)vt.get(0)).get(7).toString() + ",";
int[] iWeekDays = {0,0,0,0,0,0,0};
int iSignCount = 0;
for(long i=dateStartDate.getTime();i<=dateEndDate.getTime();i+=(3600000 * 24))
{
String strWeek = StringNew.GetDateString((new Date(i)),"E");
strWeek = strWeek.replaceAll("星期日", "0");
strWeek = strWeek.replaceAll("星期一", "1");
strWeek = strWeek.replaceAll("星期二", "2");
strWeek = strWeek.replaceAll("星期三", "3");
strWeek = strWeek.replaceAll("星期四", "4");
strWeek = strWeek.replaceAll("星期五", "5");
strWeek = strWeek.replaceAll("星期六", "6");
if(strActiveWeekday.indexOf("," + strWeek + ",")>=0)
{
iSignCount ++;
}
}
if(iAbnormalCount>0||(iSignCount - iNormalCount - iAbnormalCount)>0)
{
strSUM = "<font color='red'><b>正常" + iNormalCount +"/异常" + iAbnormalCount + "/漏签" + (iSignCount - iNormalCount - iAbnormalCount) + "</b></font>";
}
else
{
strSUM = "正常" + iNormalCount + "/0/0";
}
}
else
{
strSUM = "免签到";
}
}
else
{
strSUM = "<font color='red'>该考勤类型不存在</font>";
}
}
catch(Exception err)
{
strSUM = "<font color='red'><b>未知错误</b></font>";
}
return strSUM;
}
/**
* 获取指定用户指定时段的签到记录
* @param iUserID 指定用户
* @param strStartDate 指定开始时间
* @param strEndDate 指定结束时间
* @return 指定用户指定时段的签到记录集
*/
public static Vector getSignByUserIDDate(int iUserID, String strStartDate, String strEndDate)
{
Vector vt = SQLManager.GetResultSet("SELECT * FROM " + TableName + " where (UserID = "+ iUserID +")and ('"+ strStartDate +" 00:00:00' < SignTime) and ('"+ strEndDate + " 23:59:59' > SignTime)");
return vt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -