package com.neusoft.smart.pos.gateway.service;

import com.neusoft.smart.pos.gateway.service.feignService.RemoteDeviceService;
import com.neusoft.smart.pos.gateway.service.feignService.RemoteOTAService;
import com.neusoft.smart.pos.gateway.service.feignService.RemoteOrgService;
import com.neusoft.smart.pos.gateway.service.feignService.RemoteUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class RedisService {

    @Autowired
    RemoteUserService remoteUserService;
    @Autowired
    RemoteOrgService remoteOrgService;
    @Autowired
    private RemoteDeviceService deviceService;
    @Autowired
    private RemoteOTAService otaService;

    public void load2Redis() throws InterruptedException {
        if (deviceService.load2Redis().equals("ok")) {
            Thread.sleep(2000);
            otaService.load2Redis();
        }
    }


    public void loadUserData2Redis() {
        remoteUserService.loadUserData2Redis();
        log.info("load user data in method");
    }

    public void loadUserData2Redis(Integer shopId, Integer orgId) {
        if (orgId != null) {
            remoteUserService.loadUserData2RedisByOrg(orgId);
        }
        if (shopId != null) {
            remoteUserService.loadUserData2RedisByShop(shopId);
        }
        log.info("load user data in method");
    }
}
