package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.PointsConfig;
import com.ruoyi.abuwx.service.IPointsConfigService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 积分配置Controller
 * 
 * @author lujie
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/points/config")
public class PointsConfigController extends BaseController
{
    @Autowired
    private IPointsConfigService pointsConfigService;

    /**
     * 查询积分配置列表
     */
    @PreAuthorize("@ss.hasPermi('points:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsConfig pointsConfig)
    {
        startPage();
        List<PointsConfig> list = pointsConfigService.selectPointsConfigList(pointsConfig);
        return getDataTable(list);
    }

    /**
     * 导出积分配置列表
     */
    @PreAuthorize("@ss.hasPermi('points:config:export')")
    @Log(title = "积分配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsConfig pointsConfig)
    {
        List<PointsConfig> list = pointsConfigService.selectPointsConfigList(pointsConfig);
        ExcelUtil<PointsConfig> util = new ExcelUtil<PointsConfig>(PointsConfig.class);
        util.exportExcel(response, list, "积分配置数据");
    }

    /**
     * 获取积分配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('points:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pointsConfigService.selectPointsConfigById(id));
    }

    /**
     * 新增积分配置
     */
    @PreAuthorize("@ss.hasPermi('points:config:add')")
    @Log(title = "积分配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsConfig pointsConfig)
    {
        return toAjax(pointsConfigService.insertPointsConfig(pointsConfig));
    }

    /**
     * 修改积分配置
     */
    @PreAuthorize("@ss.hasPermi('points:config:edit')")
    @Log(title = "积分配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsConfig pointsConfig)
    {
        return toAjax(pointsConfigService.updatePointsConfig(pointsConfig));
    }

    /**
     * 删除积分配置
     */
    @PreAuthorize("@ss.hasPermi('points:config:remove')")
    @Log(title = "积分配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsConfigService.deletePointsConfigByIds(ids));
    }
}
