package com.sysu.admin.site;

import com.alibaba.fastjson.JSON;
import com.sysu.admin.support.system.config.SConfig;
import com.sysu.admin.support.system.config.SConfigService;
import com.xiesx.fastboot.base.result.BaseResult;
import com.xiesx.fastboot.base.result.R;
import com.xiesx.fastboot.core.token.annotation.GoToken;
import com.xiesx.fastboot.core.token.handle.CurrentToken;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/site/cfg")
@RestController
public class SiteCfgController {

    @Autowired
    SConfigService mSConfigService;

    @RequestMapping(value = "/get")
    @ResponseBody
    public BaseResult get(@RequestBody SConfig config,
                          @GoToken() CurrentToken currentToken){
        if(StringUtils.equals(SConfig.ResultType.json.name(), config.getResultType())){
            String value = mSConfigService.getV(config.getK());
            return R.succ("success", JSON.parseObject(value));
        }
        String value = mSConfigService.getV(config.getK());
        return R.succ("success", value);
    }

    @RequestMapping(value = "/sign")
    @ResponseBody
    public BaseResult sign(@RequestBody SConfig config,@GoToken() CurrentToken currentToken){
        String sldXmlJson =  mSConfigService.getV(config.getK());
        System.out.println(sldXmlJson);
        return R.succ("",sldXmlJson);
    }

}
