海康汽车服务

HatcUtil.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.njyunzhi.nanyang.common;
  2. import com.hikvision.ae.hatc.sdk.service.SDKService;
  3. import com.hikvision.ae.hatc.sdk.service.impl.HatcClientFactory;
  4. import com.njyunzhi.nanyang.config.HatcConfig;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. @Component
  8. public class HatcUtil {
  9. SDKService sdkService;
  10. HatcConfig hatcConfig;
  11. @Autowired
  12. public HatcUtil(HatcConfig hatcConfig) {
  13. this.hatcConfig = hatcConfig;
  14. try {
  15. initSDK();
  16. } catch (InterruptedException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. public SDKService getSdkService() {
  21. if (sdkService == null) {
  22. try {
  23. initSDK();
  24. } catch (InterruptedException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. return sdkService;
  29. }
  30. public void initSDK() throws InterruptedException {
  31. Boolean enabled = hatcConfig.getEnable();
  32. if (enabled == null || !enabled) return;
  33. sdkService = HatcClientFactory.getSDKClient(
  34. hatcConfig.getCmsAddress(),
  35. hatcConfig.getCmsPort(),
  36. hatcConfig.getHatcAccount(),
  37. hatcConfig.getHatcSecret()
  38. );
  39. }
  40. }