package com.yunfeiyun.agmp.common.core.controller;

import com.google.gson.Gson;
import com.yunfeiyun.agmp.common.constant.ErrorCode;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.core.domain.model.IBaseTheme;
import com.yunfeiyun.agmp.common.core.domain.model.PortalTheme;
import com.yunfeiyun.agmp.common.exception.BizException;
import com.yunfeiyun.agmp.common.web.system.domain.SysConfig;
import com.yunfeiyun.agmp.common.web.system.service.ISysConfigService;
import com.yunfeiyun.agmp.common.utils.ConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 主题获取的统一接口
 *
 * @author 杨晓辉
 */
@RestController
@RequestMapping("/theme/cfg")
public class ThemeController {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ISysConfigService configService;

    /**
     * 得到门户的主题配信息
     */
    @GetMapping("/portal")
    public AjaxResult portalCfg()
    {
        SysConfig sysConfig = configService.selectConfigByKey(ConfigUtils.ConfigKeyEnum.PORTAL_THEME.getKey(),1);
        if(null != sysConfig && null != sysConfig.getConfigValue() && !"".equalsIgnoreCase(sysConfig.getConfigValue())) {
            IBaseTheme portalTheme = new Gson().fromJson(sysConfig.getConfigValue(), PortalTheme.class);
            return AjaxResult.success(portalTheme);
        }
        throw new BizException(ErrorCode.FAILURE.getCode(),ErrorCode.FAILURE.getMessage());
    }

    /**
     * 得到子系统的主题配信息
     */
    @GetMapping("/sys")
    public AjaxResult sysCfg()
    {
        return null;
    }

}
