package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipp.common.data.entity.SysParameter;
import com.jiayue.ipp.idp.service.SysParameterService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * idp_sys_parameter
 *
 * @author whc
 * @date 2022-03-18 15:49:37
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysparameter")
@Api(value = "sysparameter", tags = "idp_sys_parameter管理")
public class SysParameterController {

    private final SysParameterService sysParameterService;

    /**
     * 分页查询
     *
     * @param page         分页对象
     * @param sysParameter idp_sys_parameter
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_sysparameter_get')")
    public R getSysParameterPage(Page page, SysParameter sysParameter) {
        return R.ok(sysParameterService.page(page, Wrappers.query(sysParameter)));
    }

    /**
     * 通过id查询idp_sys_parameter
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_sysparameter_get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(sysParameterService.getById(id));
    }

    /**
     * 新增idp_sys_parameter
     *
     * @param sysParameter idp_sys_parameter
     * @return R
     */
    @ApiOperation(value = "新增idp_sys_parameter", notes = "新增idp_sys_parameter")
    //    @SysLog("新增idp_sys_parameter")
    @PostMapping
    //@PreAuthorize("@pms.hasPermission('idp_sysparameter_add')")
    public R save(@RequestBody SysParameter sysParameter) {
        return R.ok(sysParameterService.save(sysParameter));
    }

    /**
     * 修改idp_sys_parameter
     *
     * @param sysParameter idp_sys_parameter
     * @return R
     */
    @ApiOperation(value = "修改idp_sys_parameter", notes = "修改idp_sys_parameter")
    //    @SysLog("修改idp_sys_parameter")
    @PutMapping
    //@PreAuthorize("@pms.hasPermission('idp_sysparameter_edit')")
    public R updateById(@RequestBody SysParameter sysParameter) {
        return R.ok(sysParameterService.updateById(sysParameter));
    }

    /**
     * 通过id删除idp_sys_parameter
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除idp_sys_parameter", notes = "通过id删除idp_sys_parameter")
    //    @SysLog("通过id删除idp_sys_parameter")
    @DeleteMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_sysparameter_del')")
    public R removeById(@PathVariable String id) {
        return R.ok(sysParameterService.removeById(id));
    }
    /**
     * 根据参数标识获取系统参数
     *
     * @param sysKey
     * @return 执行结果
     */

    @GetMapping(value = "/getParameterBySysKey")
    public R getParameterBySysKey(String sysKey) {
        return R.ok(sysParameterService.getParameterBySysKey(sysKey));
    }
}
