package com.palmnest.service.ws;

import com.dh.buildlock.pub.DHDataProcessPub;
import com.palmnest.application.Constants;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
public class VistorCodeClient {


	public static String           generateVisitCodeWithIds;
	public static DHDataProcessPub lockInit;

	/**
	 * @param deviceId      设备id
	 * @param devicePwd     设备密码
	 * @param vilidDate     访问日期
	 * @param communityCode 小区编号
	 * @param buildingCode  楼栋编号
	 * @param visitIndex    访客索引
	 * @param pswType       密码有效期 1当天有效，0使用1次后失效
	 */
	public static String generateVisitCodeWithIds(String deviceId, String devicePwd, Date vilidDate,
												  int communityCode, int buildingCode, int visitIndex, int pswType) {
		lockInit = DHDataProcessPub.lockInit();
		generateVisitCodeWithIds = lockInit.generateVisitCodeWithIds(deviceId, devicePwd, vilidDate, communityCode,
				buildingCode, visitIndex, pswType);
		return generateVisitCodeWithIds;
	}

	public static String getPassword(Date startTime, Integer count, Integer companyId) {
		String password = "";
		try {
			// 生成密码
			password = VistorCodeClient.generateVisitCodeWithIds("ABABABAB",
					"12345678", startTime, companyId,
					Constants.DOOR_ID, count, 0);
		} catch (Exception e) {
			log.error("【生成大豪密码异常 信息如下:】" + e.getMessage());
			return "";
		}
		return password;
	}
}
