package com.prolog.eis.controller.sys;

import com.prolog.eis.model.sys.SysParam;
import com.prolog.eis.service.sys.SysParamService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.dao.util.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: xiong
 * @description: TODO
 * @date: 2024/8/12 9:35
 * @version: 1.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "系统参数接口服务")
@RequestMapping(value = "api/v1/sys")
public class SystemController {
    private final SysParamService sysParamService;

    @ApiOperation(notes = "查询系统参数列表", value = "查询系统参数列表")
    @PostMapping(value = "/page/list")
    public RestMessage mcsRequest(@RequestBody SystemPageReqDTO pageParam) {
        PageUtils.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        List<SysParam> list = sysParamService.findPageList(pageParam);
        return RestMessage.doSuccess(PageUtils.getPage(list));
    }

    /**
     * 通过ID修改系统参数
     */
    @ApiOperation(notes = "修改系统参数", value = "修改系统参数")
    @PostMapping(value = "/update")
    public RestMessage update(@RequestBody SysParam sysParam) {
        sysParamService.updateSysParamById(sysParam);
        return RestMessage.doSuccess(null);
    }

    @ApiOperation(notes = "新增系统参数", value = "新增系统参数")
    @PostMapping(value = "/add")
    public RestMessage add(@RequestBody SysParam sysParam) {
        sysParamService.add(sysParam);
        return RestMessage.doSuccess(null);
    }

    @ApiOperation(notes = "删除系统参数", value = "删除系统参数")
    @GetMapping(value = "/delete")
    public RestMessage delete(Integer id) {
        sysParamService.delete(id);
        return RestMessage.doSuccess(null);
    }
}
