package org.dromara.system.controller;

import org.dromara.system.config.AjaxResult;
import org.dromara.system.domain.SysConfig;
import org.dromara.system.domain.vo.SysConfigVo;
import org.dromara.system.service.ISysConfigService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/config")
public class ConfigController extends BaseController {

    @Autowired
    private ISysConfigService configService;

    @GetMapping(value = "/configKey2/{configKey}")
    public AjaxResult getConfigKey2(@PathVariable String configKey) {
        return AjaxResult.success(configService.selectConfigByKey2(configKey));
    }

    @PostMapping("/addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody SysConfigVo content) {
        SysConfig config = new SysConfig();
        BeanUtils.copyProperties(content,config);
        if (config.getConfigId() == null) {
            config.setCreateBy(getUserId());
            return toAjax(configService.insertConfig1(config));
        }
        config.setUpdateBy(getUserId());
        return toAjax(configService.updateConfig1(config));
    }
}
