package com.yiqi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.system.domain.SysMessageConfig;
import com.yiqi.system.service.ISysMessageConfigService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 消息配置Controller
 *
 * @author douya
 * @date 2024-11-22
 */
@Api(tags = "管理后台 - 消息配置")
@RestController
@RequestMapping(UrlConstants.managerApi + "/system/messageConfig")
public class SysMessageConfigController extends BaseController {
    @Autowired
    private ISysMessageConfigService sysMessageConfigService;


    //<editor-folder desc="基础函数">
/**
 * 查询消息配置列表
 */
@PreAuthorize("@ss.hasPermi('system:messageConfig:list')")
@GetMapping("/list")
    @ApiOperation(value = "查询消息配置列表")
    public TableDataInfo list(SysMessageConfig sysMessageConfig) {
        startPage();
        List<SysMessageConfig> list = sysMessageConfigService.selectSysMessageConfigList(sysMessageConfig);
        return getDataTable(list);
    }

    /**
     * 导出消息配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:messageConfig:export')")
    @Log(title = "消息配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出消息配置列表")
    public void export(HttpServletResponse response, SysMessageConfig sysMessageConfig) {
        List<SysMessageConfig> list = sysMessageConfigService.selectSysMessageConfigList(sysMessageConfig);
        ExcelUtil<SysMessageConfig> util = new ExcelUtil<SysMessageConfig>(SysMessageConfig. class);
        util.exportExcel(response, list, "消息配置数据");
    }

    /**
     * 获取消息配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:messageConfig:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取消息配置详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysMessageConfigService.selectSysMessageConfigById(id));
    }

    /**
     * 新增消息配置
     */
    @PreAuthorize("@ss.hasPermi('system:messageConfig:add')")
    @Log(title = "消息配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增消息配置")
    public AjaxResult add(@RequestBody SysMessageConfig sysMessageConfig) {
        sysMessageConfig.setCreateById(getUserId());
        sysMessageConfig.setCreateBy(getUsername());
        return toAjax(sysMessageConfigService.insertSysMessageConfig(sysMessageConfig));
    }

    /**
     * 修改消息配置
     */
    @PreAuthorize("@ss.hasPermi('system:messageConfig:edit')")
    @Log(title = "消息配置", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改消息配置")
    public AjaxResult edit(@RequestBody SysMessageConfig sysMessageConfig) {
        sysMessageConfig.setUpdateById(getUserId());
        sysMessageConfig.setUpdateBy(getUsername());
        return toAjax(sysMessageConfigService.updateSysMessageConfig(sysMessageConfig));
    }

    /**
     * 删除消息配置
     */
    @PreAuthorize("@ss.hasPermi('system:messageConfig:remove')")
    @Log(title = "消息配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除消息配置")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysMessageConfigService.deleteSysMessageConfigByIds(ids));
    }

            /**
             * 修改消息配置状态
             */
            @PreAuthorize("@ss.hasPermi('system:messageConfig:edit')")
            @Log(title = "消息配置", businessType = BusinessType.UPDATE)
            @PostMapping(value = "updateStatus")
            @ApiOperation(value = "修改消息配置状态")
            public AjaxResult updateSysMessageConfigStatus(@RequestBody SysMessageConfig sysMessageConfig) {
                return toAjax(sysMessageConfigService.updateSysMessageConfigStatus(sysMessageConfig));
            }

    //</editor-folder>
}
