package io.renren.service;

import org.springframework.stereotype.Component;

@Component
public class HikIn {

   /* private static Logger logger = LoggerFactory.getLogger(HikVisionService.class);
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    static String m_sUsername;//设备用户名    可能不一样 自己问问现场
    static String m_sPassword;//设备密码
    static String m_sDeviceIP;//设备密码
    static short m_sPort;//端口号，这是默认的

    @Autowired
    private CarService carService;

    @Value("${Hik.in_sUsername}")
    public  void setM_sUsername(String m_sUsername) {
        HikIn.m_sUsername = m_sUsername;
    }
    @Value("${Hik.in_sPassword}")
    public  void setM_sPassword(String m_sPassword) {
        HikIn.m_sPassword = m_sPassword;
    }
    @Value("${Hik.in_sDeviceIP}")
    public  void setM_sDeviceIP(String m_sDeviceIP) {
        HikIn.m_sDeviceIP = m_sDeviceIP;
    }
    @Value("${Hik.in_sPort}")
    public  void setM_sPort(short m_sPort) {
        HikIn.m_sPort = m_sPort;
    }

    public NativeLong lUserID;//用户句柄
    public NativeLong lAlarmHandle;//报警布防句柄
    public int lListenHandle;//报警监听句柄
    public NativeLong RemoteConfig;
    public static int code = 5;

    static DevInfoCallBack fVehicleCrtlCB = null;
    public void init(List<String> carList){
        // 初始化
        Boolean flag = hCNetSDK.NET_DVR_Init();
        if (flag){
            System.out.println("初始化成功");
        }else{
            System.out.println("初始化失败");
        }
        //设置连接时间与重连时间
        hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
        hCNetSDK.NET_DVR_SetReconnect(100000, true);
        //设备信息, 输出参数
        HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
        HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();
        // 注册设备-登录参数，包括设备地址、登录用户、密码等
        m_strLoginInfo.sDeviceAddress = new byte[hCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
        System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
        m_strLoginInfo.sUserName = new byte[hCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
        System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
        m_strLoginInfo.sPassword = new byte[hCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
        System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
        m_strLoginInfo.wPort = m_sPort;
        m_strLoginInfo.bUseAsynLogin = false; //是否异步登录：0- 否，1- 是
        m_strLoginInfo.write();

        //设备信息, 输出参数
        int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo,m_strDeviceInfo);
        if(lUserID==-1){
            System.out.println("ip==="+m_sDeviceIP+"登陆失败");
            hCNetSDK.NET_DVR_Cleanup();
            return;
        }
        fVehicleCrtlCB = new DevInfoCallBack();
        int lhand = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID,hCNetSDK.NET_DVR_VEHICLELIST_CTRL_START,null,0,fVehicleCrtlCB, Pointer.NULL);
        for(String carNo :carList){
            HCNetSDK.NET_DVR_VEHICLE_CONTROL_LIST_INFO info  =new  HCNetSDK.NET_DVR_VEHICLE_CONTROL_LIST_INFO();
            info.read();
            info.dwSize = info.size();
            info.dwChannel = 1; //通道号，出入口设备默认1
            String sLicense = carNo;
            try {
                info.sLicense = sLicense.getBytes("GBK"); //车牌号码
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            info.byListType = 0; //名单属性（黑白名单）：0- 白名单，1- 黑名单
            info.byPlateType = 4; //STANDARD92_BACK_PLATE 民用车双行尾牌 8- 新能源车牌 0- 标准民用车与军车车牌
            info.byPlateColor = 0; //VCA_YELLOW_PLATE 黄色车牌 0- 蓝色车牌 1- 黄色车牌 2- 白色车牌 4- 绿色车牌
            String cardNo = "1";   //卡号
            info.sCardNo = cardNo.getBytes();
            //有效开始时间
            info.struStartTime.wYear = (short) 2022;
            info.struStartTime.byMonth = (byte) 12;
            info.struStartTime.byDay = (byte) 01;
            info.struStartTime.byHour = (byte) 01;
            info.struStartTime.byMinute = (byte) 02;
            info.struStartTime.bySecond = (byte) 01;
            //有效结束时间
            info.struStopTime.wYear = (short) 2023;
            info.struStopTime.byMonth = (byte) 12;
            info.struStopTime.byDay = (byte) 31;
            info.struStopTime.byHour = (byte) 23;
            info.struStopTime.byMinute = (byte) 59;
            info.struStopTime.bySecond = (byte) 59;
            info.write();
            hCNetSDK.NET_DVR_SendRemoteConfig(lhand,hCNetSDK.ENUM_SENDDATA,info.getPointer(),info.size());
            System.out.println("ip==="+m_sDeviceIP+"\t车牌\t"+carNo+"\t添加白名单成功");
        }
        hCNetSDK.NET_DVR_Cleanup();
    }


    public void initCarList(List<CarEntity> carList){
        // 初始化
        Boolean flag = hCNetSDK.NET_DVR_Init();
        if (flag){
            System.out.println("初始化成功");
        }else{
            System.out.println("初始化失败");
        }
        //设置连接时间与重连时间
        hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
        hCNetSDK.NET_DVR_SetReconnect(100000, true);
        //设备信息, 输出参数
        HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
        HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();
        // 注册设备-登录参数，包括设备地址、登录用户、密码等
        m_strLoginInfo.sDeviceAddress = new byte[hCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
        System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
        m_strLoginInfo.sUserName = new byte[hCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
        System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
        m_strLoginInfo.sPassword = new byte[hCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
        System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
        m_strLoginInfo.wPort = m_sPort;
        m_strLoginInfo.bUseAsynLogin = false; //是否异步登录：0- 否，1- 是
        m_strLoginInfo.write();

        //设备信息, 输出参数
        int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo,m_strDeviceInfo);
        if(lUserID==-1){
            System.out.println("ip==="+m_sDeviceIP+"登陆失败");
            hCNetSDK.NET_DVR_Cleanup();
            return;
        }
        fVehicleCrtlCB = new DevInfoCallBack();
        int lhand = hCNetSDK.NET_DVR_StartRemoteConfig(lUserID,hCNetSDK.NET_DVR_VEHICLELIST_CTRL_START,null,0,fVehicleCrtlCB, Pointer.NULL);
        for(CarEntity car :carList){
            HCNetSDK.NET_DVR_VEHICLE_CONTROL_LIST_INFO info  =new  HCNetSDK.NET_DVR_VEHICLE_CONTROL_LIST_INFO();
            info.read();
            info.dwSize = info.size();
            info.dwChannel = 1; //通道号，出入口设备默认1
            String sLicense = car.getCarNo();
            try {
                info.sLicense = sLicense.getBytes("GBK"); //车牌号码
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if("1".equals(car.getIsDel())){//删除车辆不进行授权
                info.byListType = 1; //名单属性（黑白名单）：0- 白名单，1- 黑名单
            }else{
                info.byListType = 0; //名单属性（黑白名单）：0- 白名单，1- 黑名单
            }
            info.byPlateType = Byte.parseByte(car.getPlateType()); //STANDARD92_BACK_PLATE 民用车双行尾牌 8- 新能源车牌 0- 标准民用车与军车车牌
            info.byPlateColor = Byte.parseByte(car.getPlateColor());; //VCA_YELLOW_PLATE 黄色车牌 0- 蓝色车牌 1- 黄色车牌 2- 白色车牌 4- 绿色车牌
            String cardNo = car.getCardNo();   //卡号
            info.sCardNo = cardNo.getBytes();
            //有效开始时间
            if(car.getStruStartTime()!=null){
                Calendar ca = Calendar.getInstance();
                ca.setTime(car.getStruStartTime());
                int year = ca.get(Calendar.YEAR);
                int month = ca.get(Calendar.MONTH) + 1;
                int day = ca.get(Calendar.DAY_OF_MONTH);
                info.struStartTime.wYear = (short) year;
                info.struStartTime.byMonth = (byte) month;
                info.struStartTime.byDay = (byte) day;
                info.struStartTime.byHour = (byte) 00;
                info.struStartTime.byMinute = (byte) 00;
                info.struStartTime.bySecond = (byte) 01;
            }else{
                info.struStartTime.wYear = (short) 2023;
                info.struStartTime.byMonth = (byte) 01;
                info.struStartTime.byDay = (byte) 01;
                info.struStartTime.byHour = (byte) 00;
                info.struStartTime.byMinute = (byte) 00;
                info.struStartTime.bySecond = (byte) 01;
            }
            //有效结束时间
            if(car.getStruStopTime()!=null) {
                Calendar ca = Calendar.getInstance();
                ca.setTime(car.getStruStopTime());
                int year = ca.get(Calendar.YEAR);
                int month = ca.get(Calendar.MONTH) + 1;
                int day = ca.get(Calendar.DAY_OF_MONTH);
                info.struStopTime.wYear = (short) year;
                info.struStopTime.byMonth = (byte) month;
                info.struStopTime.byDay = (byte) day;
                info.struStopTime.byHour = (byte) 23;
                info.struStopTime.byMinute = (byte) 59;
                info.struStopTime.bySecond = (byte) 59;
            }else{
                info.struStopTime.wYear = (short) 2023;
                info.struStopTime.byMonth = (byte) 12;
                info.struStopTime.byDay = (byte) 31;
                info.struStopTime.byHour = (byte) 23;
                info.struStopTime.byMinute = (byte) 59;
                info.struStopTime.bySecond = (byte) 59;
            }
            info.write();
            hCNetSDK.NET_DVR_SendRemoteConfig(lhand,hCNetSDK.ENUM_SENDDATA,info.getPointer(),info.size());
            System.out.println("ip==="+m_sDeviceIP+"\t车牌\t"+car.getCarNo()+"\t添加白名单成功");
            car.setSync("1");
            carService.updateCar(car);
        }
        hCNetSDK.NET_DVR_Cleanup();
    }*/

}
