现在的公司基本有打卡机,企业办公系统获取考勤机的记录也是很基本的功能。方便员工或者领导查看出勤记录。其实最简单的方法是利用考勤机的软件,导出数据到数据库,直接利用数据库。通过唯一码工号获取我们想要数据就行。我玩过两种类型的考勤机。
1.中控考勤机主要数据表如下
SELECT TOP 10 * FROM Att2008.dbo.USERINFO --考勤机员工信息表
关键有用字段BADGENUMBER,USERID 分别为工号和用户标识ID。
SELECT TOP 10 * FROM Att2008.dbo.CHECKINOUT --考勤记录明细表
2.汉王考勤机主要数据表如下
SELECT *,EmployeeCode FROM HWATT.dbo.KQZ_Employee --员工信息表及工号字段
SELECT * FROM HWATT.dbo.kqz_Card --考勤明细表
3.根据考勤机先后循序,可以把后面生成考勤记录集成到前面的数据库,减少开发工作量。
SELECT kc.CardTime,ke.EmployeeCode
FROM HWATT.dbo.KQZ_Card kc LEFT JOIN HWATT.dbo.KQZ_Employee ke ON kc.EmployeeID=ke.EmployeeID WHERE YEAR(kc.CardTime)=2018 AND ke.EmployeeCode=2717
-- 汉王考勤明细信息
SELECT c.CHECKTIME,u.BADGENUMBER,c.USERID
FROM Att2008.dbo.CHECKINOUT c LEFT JOIN Att2008.dbo.USERINFO u ON c.USERID=u.USERID WHERE YEAR(c.CHECKTIME)=2018 AND month(c.CHECKTIME)=5 AND u.BADGENUMBER=2717
--中控考勤明细信息
4.编写存储过程,定时执行,获取数据
create PROC FaceAttToFinger
AS
IF EXISTS(SELECT 1 FROM HWATT.dbo.KQZ_Employee e LEFT JOIN Att2008.dbo.USERINFO u ON e.EmployeeCode=u.BADGENUMBER WHERE u.USERID IS null)
BEGIN
INSERT INTO Att2008.dbo.USERINFO(BADGENUMBER,[NAME],[STATE])
SELECT e.EmployeeCode,e.EmployeeName,1
FROM HWATT.dbo.KQZ_Employee e LEFT JOIN Att2008.dbo.USERINFO u ON e.EmployeeCode=u.BADGENUMBER WHERE u.USERID IS null
END
INSERT INTO Att2008.dbo.CHECKINOUT
(
USERID,
CHECKTIME,
CHECKTYPE,
VERIFYCODE,
SENSORID,
WorkCode
)
SELECT t3.USERID,t1.CardTime,1,1,1,1 FROM (SELECT kc.CardTime,ke.EmployeeCode
FROM HWATT.dbo.KQZ_Card kc LEFT JOIN HWATT.dbo.KQZ_Employee ke ON kc.EmployeeID=ke.EmployeeID WHERE YEAR(kc.CardTime)=2018) t1 LEFT JOIN (SELECT c.CHECKTIME,u.BADGENUMBER
FROM Att2008.dbo.CHECKINOUT c LEFT JOIN Att2008.dbo.USERINFO u ON c.USERID=u.USERID WHERE YEAR(c.CHECKTIME)=2018) t2 ON t1.EmployeeCode=t2.BADGENUMBER AND t1.CardTime=t2.CHECKTIME LEFT JOIN Att2008.dbo.USERINFO t3 ON t1.EmployeeCode=t3.BADGENUMBER WHERE t2.CHECKTIME IS NULL
go