java 考勤机数据_zkteco iface702 中控考勤机java开发步骤二---获取考勤机 的考勤数据...

该博客详细介绍了如何使用Java通过ZkemSDKUtils类连接Zkteco IFace702考勤机,获取并处理考勤记录数据。主要涉及的方法包括连接考勤机、读取考勤记录、解析考勤数据等。
摘要由CSDN通过智能技术生成

package com.XXX.gasstation.commons.utils;

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

import com.jacob.com.Variant;

import com.XXX.gasstation.commons.utils.lang.DateUtils;

import net.sf.json.JSONObject;

import java.util.*;

/**

* @ClassName:${type_name}

* @Description:${todo}(连接、获取考勤机数据)

* @author: ZHOUPAN

* @date ${date} ${time}

* @Copyright: 2018 www.zsplat.com Inc. All rights reserved.

* ${tags}

*/

public class ZkemSDKUtils {

//zkemkeeper.ZKEM.1 为zkemkeeper.dll 注册成功后 在注册表可以查看:HKEY_CLASSES_ROOT最下面

private static ActiveXComponent zkem = new ActiveXComponent("zkemkeeper.ZKEM.1");

/**

* 连接考勤机

*

* @param address 考勤机地址

* @param port 端口号

* @return

*/

public static boolean connect(String address, int port) {

boolean result = zkem.invoke("Connect_NET", address, port).getBoolean();

return result;

}

/**

* 读取考勤记录到pc缓存。配合getGeneralLogData使用

*

* @return

*/

public static boolean readGeneralLogData() {

boolean result = zkem.invoke("ReadGeneralLogData", 1).getBoolean();

return result;

}

/**

* 读取该时间之后的最新考勤数据。 配合getGeneralLogData使用。//网上说有这个方法,但是我用的开发文档没有这个方法,也调用不到,我在controller中处理获取当天数据

*

* @param lastest

* @return

*/

public static boolean readLastestLogData(Date lastest) {

boolean result = zkem.invoke("ReadLastestLogData", 2018 - 07 - 24).getBoolean();

return result;

}

/**

* 获取缓存中的考勤数据。配合readGeneralLogData / readLastestLogData使用。

*

* @return 返回的map中,包含以下键值:

* "EnrollNumber" 人员编号

* "Time" 考勤时间串,格式: yyyy-MM-dd HH:mm:ss

* "VerifyMode"

* "InOutMode"

* "Year" 考勤时间:年

* "Month" 考勤时间:月

* "Day" 考勤时间:日

* "Hour" 考勤时间:时

* "Minute" 考勤时间:分

* "Second" 考勤时间:秒

*/

public static List> getGeneralLogData() {

Variant dwMachineNumber = new Variant(1, true);//机器号

Variant dwEnrollNumber = new Variant("", true);

Variant dwVerifyMode = new Variant(0, true);

Variant dwInOutMode = new Variant(0, true);

Variant dwYear = new Variant(0, true);

Variant dwMonth = new Variant(0, true);

Variant dwDay = new Variant(0, true);

Variant dwHour = new Variant(0, true);

Variant dwMinute = new Variant(0, true);

Variant dwSecond = new Variant(0, true);

Variant dwWorkCode = new Variant(0, true);

List> strList = new ArrayList>();

boolean newresult = false;

do {

Variant vResult = Dispatch.call(zkem, "SSR_GetGeneralLogData", dwMachineNumber, dwEnrollNumber, dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkCode);

newresult = vResult.getBoolean();

if (newresult) {

String enrollNumber = dwEnrollNumber.getStringRef();

//如果没有编号,则跳过。

if (enrollNumber == null || enrollNumber.trim().length() == 0)

continue;

String month = dwMonth.getIntRef() + "";

String day = dwDay.getIntRef() + "";

if (dwMonth.getIntRef()<10) {

month= "0"+ dwMonth.getIntRef();

}

if (dwDay.getIntRef() < 10) {

day= "0"+ dwDay.getIntRef();

}

String validDate= dwYear.getIntRef()+ "-" + month + "-" + day;

String currentDate= DateUtils.getCurrentTime("yyyy-MM-dd");if (currentDate.equals(validDate)) {

Map m = new HashMap();

//Mapuser = getUserInfoByNumber(enrollNumber);

m.put("EnrollNumber", enrollNumber);

m.put("Time", dwYear.getIntRef() + "-" + dwMonth.getIntRef() + "-" + dwDay.getIntRef() + " " + dwHour.getIntRef() + ":" + dwMinute.getIntRef() + ":" + dwSecond.getIntRef());

m.put("VerifyMode", dwVerifyMode.getIntRef());

m.put("InOutMode", dwInOutMode.getIntRef());

m.put("Year", dwYear.getIntRef());

m.put("Month", dwMonth.getIntRef());

m.put("Day", dwDay.getIntRef());

m.put("Hour", dwHour.getIntRef());

m.put("Minute", dwMinute.getIntRef());

m.put("Second", dwSecond.getIntRef());

strList.add(m);

}

}

} while (newresult == true);

return strList;

}

/**

* 获取用户信息

*

* @return 返回的Map中,包含以下键值:

* "EnrollNumber" 人员编号

* "Name" 人员姓名

* "Password" 人员密码

* "Privilege"

* "Enabled" 是否启用

*/

public static List> getUserInfo() {

List> resultList = new ArrayList>();

//将用户数据读入缓存中。

boolean result = zkem.invoke("ReadAllUserID", 1).getBoolean();

Variant v0 = new Variant(1);

Variant sdwEnrollNumber = new Variant("", true);

Variant sName = new Variant("", true);

Variant sPassword = new Variant("", true);

Variant iPrivilege = new Variant(0, true);

Variant bEnabled = new Variant(false, true);

while (result) {

//从缓存中读取一条条的用户数据

result = zkem.invoke("SSR_GetAllUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();

//如果没有编号,跳过。

String enrollNumber = sdwEnrollNumber.getStringRef();

if (enrollNumber == null || enrollNumber.trim().length() == 0)

continue;

//由于名字后面会产生乱码,所以这里采用了截取字符串的办法把后面的乱码去掉了,以后有待考察更好的办法。

//只支持2位、3位、4位长度的中文名字。

String name = sName.getStringRef();

if (sName.getStringRef().length() > 4) {

name = sName.getStringRef().substring(0, 4);

}

//如果没有名字,跳过。

if (name.trim().length() == 0)

continue;

Map m = new HashMap();

m.put("EnrollNumber", enrollNumber);

m.put("Name", name);

m.put("Password", sPassword.getStringRef());

m.put("Privilege", iPrivilege.getIntRef());

m.put("Enabled", bEnabled.getBooleanRef());

resultList.add(m);

}

return resultList;

}

/**

* 设置用户信息

*

* @param number

* @param name

* @param password

* @param isPrivilege

* @param enabled

* @return

*/

public static boolean setUserInfo(String number, String name, String password, int isPrivilege, boolean enabled) {

Variant v0 = new Variant(1);

Variant sdwEnrollNumber = new Variant(number, true);

Variant sName = new Variant(name, true);

Variant sPassword = new Variant(password, true);

Variant iPrivilege = new Variant(isPrivilege, true);

Variant bEnabled = new Variant(enabled, true);

boolean result = zkem.invoke("SSR_SetUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();

return result;

}

/**

* 获取用户信息

*

* @param number 考勤号码

* @return

*/

public static MapgetUserInfoByNumber(String number) {

Variant v0 = new Variant(1);

Variant sdwEnrollNumber = new Variant(number, true);

Variant sName = new Variant("", true);

Variant sPassword = new Variant("", true);

Variant iPrivilege = new Variant(0, true);

Variant bEnabled = new Variant(false, true);

boolean result = zkem.invoke("SSR_GetUserInfo", v0, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled).getBoolean();

if (result) {

Map m = new HashMap();

m.put("EnrollNumber", number);

m.put("Name", sName.getStringRef());

m.put("Password", sPassword.getStringRef());

m.put("Privilege", iPrivilege.getIntRef());

m.put("Enabled", bEnabled.getBooleanRef());

return m;

}

return null;

}

public static void main(String[] args) {

ZkemSDKUtils sdk = new ZkemSDKUtils();

Map map = new HashMap();

boolean connFlag = sdk.connect("192.168.1.201", 4370);

if (connFlag) {

boolean flag = sdk.readGeneralLogData();

List> strList = sdk.getGeneralLogData();

map.put("strList", strList);

System.out.println("flag" + flag);

System.out.println(JSONObject.fromObject(map).toString());

}

}

}

2. Controller层

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值