package com.dcsoft.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.domain.SysBackGroup;
import com.dcsoft.system.service.ISysBackGroupService;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 背景配置Controller
 *
 * @author dcsoft
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/backGroup")
public class SysBackGroupController extends BaseController
{
    @Autowired
    private ISysBackGroupService sysBackGroupService;

    /**
     * 查询背景配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysBackGroup sysBackGroup)
    {
        startPage();
        List<SysBackGroup> list = sysBackGroupService.selectSysBackGroupList(sysBackGroup);
        return getDataTable(list);
    }

    /**
     * 导出背景配置列表
     */
    @Log(title = "背景配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBackGroup sysBackGroup)
    {
        List<SysBackGroup> list = sysBackGroupService.selectSysBackGroupList(sysBackGroup);
        ExcelUtil<SysBackGroup> util = new ExcelUtil<SysBackGroup>(SysBackGroup.class);
        util.exportExcel(response, list, "背景配置数据");
    }

    /**
     * 获取背景配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysBackGroupService.selectSysBackGroupById(id));
    }

    /**
     * 新增背景配置
     */
    @Log(title = "背景配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBackGroup sysBackGroup)
    {
        sysBackGroupService.deleteSysBackGroup();
        return toAjax(sysBackGroupService.insertSysBackGroup(sysBackGroup));
    }

    /**
     * 修改背景配置
     */
    @Log(title = "背景配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBackGroup sysBackGroup)
    {
        return toAjax(sysBackGroupService.updateSysBackGroup(sysBackGroup));
    }

    /**
     * 删除背景配置
     */
    @Log(title = "背景配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysBackGroupService.deleteSysBackGroupByIds(ids));
    }
}
