package com.cpop.oam.business.controller.backstage;

import com.cpop.core.annontation.OperationLog;
import com.cpop.core.base.R;
import com.cpop.core.base.enums.OperationLogEnum;
import com.cpop.oam.business.bo.SysConfigInfoBo;
import com.cpop.oam.business.service.CommonService;
import com.cpop.oam.business.vo.ConfigInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author DB
 * @createTime 2023/09/13 12:00
 * @description
 */
@Api(tags = "系统配置模块")
@RestController
@RequestMapping("/backstage/sysConfig")
public class BackstageSysConfigController {

    @Autowired
    private CommonService commonService;

    /**
     * @Description: 获取系统配置信息
     * @return R<OpenPlatformConfigVo>
     * @author DB
     * @Date: 2023/7/7 0007 16:27
     */
    @PreAuthorize("@aps.hasPermission('system:config:list')")
    @ApiOperation("获取系统配置信息")
    @GetMapping("/getSysConfigInfo")
    public R<ConfigInfoVo> getSysConfigInfo() {
        ConfigInfoVo vo = commonService.getSysConfigInfo();
        return R.ok(vo);
    }

    /**
     * @param bo 请求参数
     * @Description: 设置系统配置信息
     * @return: R<Void>
     * @Author: DB
     * @Date: 2023/5/11 15:48
     **/
    @OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_CONFIG)
    @ApiOperation("设置系统配置信息")
    @PutMapping("/setSysConfigInfo")
    public R<Void> setSysConfigInfo(@RequestBody @Validated SysConfigInfoBo bo) {
        commonService.setSysConfigInfo(bo);
        return R.ok();
    }
}
