package com.wms.system_service.serviceImplents;

import com.wms.WmsApplication;
import com.wms.entity.table.Config;
import com.wms.service.ConfigService;
import com.wms.system_service.ISystemService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.wms.config.InitLocalConfig.configMap;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SystemServiceImplements implements ISystemService {
    private final ConfigService configService;
    @Override
    public boolean restartSystem() {
        try {
            WmsApplication.restart();
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public boolean reloadConfig() {
        try {
            List<Config> configs = configService.selectConfigs("");
            if (configs.size() > 0) {
                for (Config config : configs) {
                    configMap.put(config.getConfigKey(), config.getConfigValue());
                }
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
