package com.skr.mdm.api.system.controller;

import com.skr.mdm.api.system.service.SystemParamService;
import com.skr.mdm.bean.qo.system.SystemParamQO;
import com.skr.mdm.bean.vo.system.SystemParamVO;
import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.result.ResponseResult;
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.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author nfq
 * @date 2023-03-13 14:14
 */
@RequestMapping("system/param")
@RestController
@Api(tags = "系统参数配置")
@Validated
public class SystemParamController {

    @Autowired
    private SystemParamService systemParamService;

    @ApiOperation(value = "系统参数获取", response = SystemParamVO.class)
    @PostMapping("get")
    public ResponseResult getSystemParam(@ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return systemParamService.getSystemParam(loginAdminDTO);
    }

    @ApiOperation("系统参数配置")
    @PostMapping("config")
    @PreAuthorize("hasAnyAuthority('sys:config:param')")
    public ResponseResult updateParam(@RequestBody SystemParamQO systemParamQO, @ApiIgnore Authentication authentication) {
        LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
        return systemParamService.updateParam(systemParamQO, loginAdminDTO);
    }
}
