package com.hotent.portal.service.impl;

import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.StringUtil;
import com.hotent.portal.service.SysPropertiesService;
import com.hotent.sys.persistence.manager.SysPropertiesManager;
import com.hotent.sys.persistence.model.SysProperties;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysPropertiesServiceImpl implements SysPropertiesService {
    @Resource
    SysPropertiesManager sysPropertiesManager;

    @Override
    public SysProperties getJson(String id) throws Exception{
        SysProperties sysProperties =new SysProperties();
        List<String> groups= sysPropertiesManager.getGroups();
        if(StringUtil.isEmpty(id)){
            sysProperties.setCategorys(groups);
            return sysProperties;
        }
        sysProperties=sysPropertiesManager.get(id);
        if (BeanUtils.isEmpty(sysProperties)) {
            sysProperties =sysPropertiesManager.getByAliasFromDb(id);
        }
        if (BeanUtils.isNotEmpty(sysProperties)) {
            String val=sysProperties.getRealVal();
            sysProperties.setValue(val);
            sysProperties.setCategorys(groups);
        }
        return sysProperties;
    }
}
