package com.flossom.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.flossom.common.core.domain.entity.WxSystemSetting;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
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.flossom.system.service.IWxSystemSettingService;

/**
 * 平台参数设置Controller
 *
 * @author flossom
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/setting")
public class WxSystemSettingController extends BaseController {
    @Autowired
    private IWxSystemSettingService wxSystemSettingService;

    /**
     * 查询平台参数设置列表
     */
    @RequiresPermissions("system:setting:list")
    @GetMapping("/list")
    public TableDataInfo list(WxSystemSetting wxSystemSetting) {
        startPage();
        List<WxSystemSetting> list = wxSystemSettingService.selectWxSystemSettingList(wxSystemSetting);
        return getDataTable(list);
    }

    /**
     * 导出平台参数设置列表
     */
    @RequiresPermissions("system:setting:export")
    @Log(title = "平台参数设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxSystemSetting wxSystemSetting) {
        List<WxSystemSetting> list = wxSystemSettingService.selectWxSystemSettingList(wxSystemSetting);
        ExcelUtil<WxSystemSetting> util = new ExcelUtil<WxSystemSetting>(WxSystemSetting.class);
        util.exportExcel(response, list, "平台参数设置数据");
    }

    /**
     * 获取平台参数设置详细信息
     */
    @RequiresPermissions("system:setting:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wxSystemSettingService.selectWxSystemSettingById(id));
    }

    /**
     * 新增平台参数设置
     */
    @RequiresPermissions("system:setting:add")
    @Log(title = "平台参数设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxSystemSetting wxSystemSetting) {
        return toAjax(wxSystemSettingService.insertWxSystemSetting(wxSystemSetting));
    }

    /**
     * 修改平台参数设置
     */
    @RequiresPermissions("system:setting:edit")
    @Log(title = "平台参数设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxSystemSetting wxSystemSetting) {
        return toAjax(wxSystemSettingService.updateWxSystemSetting(wxSystemSetting));
    }

    /**
     * 删除平台参数设置
     */
    @RequiresPermissions("system:setting:remove")
    @Log(title = "平台参数设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxSystemSettingService.deleteWxSystemSettingByIds(ids));
    }
}
