package com.its.op.global;

import com.its.op.entity.its.unit.TbUnitSyst;
import com.its.op.dao.repository.its.unit.TbUnitSystRepository;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@RequiredArgsConstructor
@Getter
@Component
public class UnitSystManager {

    private final TbUnitSystRepository repo;

    private static final ConcurrentHashMap<String, TbUnitSyst> objMap = new ConcurrentHashMap<>();

    @PostConstruct
    void init() {
        load();
    }

    public void load() {

        List<TbUnitSyst> objList = repo.findAllUnitSystList();
        objList.forEach(obj -> {
            objMap.put(obj.getSystId(), obj);
        });
        //log.info("=== {}", objMap);
    }

    public static TbUnitSyst get(String id) {
        if (id == null) {
            return null;
        }
        return objMap.get(id);
    }
}
