package com.ruoyi.system.controller;

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

import com.ruoyi.system.domain.ServiceCate;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IntegralCate;
import com.ruoyi.system.service.IIntegralCateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分商品分类Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/IntegralCate")
public class IntegralCateController extends BaseController
{
    @Autowired
    private IIntegralCateService integralCateService;

    /**
     * 查询积分商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntegralCate integralCate)
    {
        startPage();
        List<IntegralCate> list = integralCateService.selectIntegralCateList(integralCate);
        return getDataTable(list);
    }

    /**
     * 导出积分商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:export')")
    @Log(title = "积分商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegralCate integralCate)
    {
        List<IntegralCate> list = integralCateService.selectIntegralCateList(integralCate);
        ExcelUtil<IntegralCate> util = new ExcelUtil<IntegralCate>(IntegralCate.class);
        util.exportExcel(response, list, "积分商品分类数据");
    }

    /**
     * 获取积分商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(integralCateService.selectIntegralCateById(id));
    }

    /**
     * 新增积分商品分类
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:add')")
    @Log(title = "积分商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralCate integralCate)
    {
        return toAjax(integralCateService.insertIntegralCate(integralCate));
    }

    /**
     * 修改积分商品分类
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:edit')")
    @Log(title = "积分商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralCate integralCate)
    {
        return toAjax(integralCateService.updateIntegralCate(integralCate));
    }
    /**
     * 定时任务状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:changeStatus')")
    @Log(title = "修改状态", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody IntegralCate integralCate)
    {
        IntegralCate newIntegralCate = integralCateService.selectIntegralCateById(integralCate.getId());
        newIntegralCate.setStatus(integralCate.getStatus());
        return toAjax(integralCateService.updateIntegralCate(newIntegralCate));
    }
    /**
     * 删除积分商品分类
     */
    @PreAuthorize("@ss.hasPermi('system:IntegralCate:remove')")
    @Log(title = "积分商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralCateService.deleteIntegralCateByIds(ids));
    }
}
