package com.ruoyi.framework.recovery.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
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.framework.recovery.domain.RecCommodity;
import com.ruoyi.framework.recovery.service.IRecCommodityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回收品牌Controller
 * 
 * @author jin
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/recovery/commodity")
public class RecCommodityController extends BaseController
{
    @Autowired
    private IRecCommodityService recCommodityService;

    /**
     * 查询回收品牌列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:commodity:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecCommodity recCommodity)
    {
        startPage();
        List<RecCommodity> list = recCommodityService.selectRecCommodityList(recCommodity);
        return getDataTable(list);
    }

    /**
     * 导出回收品牌列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:commodity:export')")
    @Log(title = "回收品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecCommodity recCommodity)
    {
        List<RecCommodity> list = recCommodityService.selectRecCommodityList(recCommodity);
        ExcelUtil<RecCommodity> util = new ExcelUtil<RecCommodity>(RecCommodity.class);
        util.exportExcel(response, list, "回收品牌数据");
    }

    /**
     * 获取回收品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:commodity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recCommodityService.selectRecCommodityById(id));
    }

    /**
     * 新增回收品牌
     */
    @PreAuthorize("@ss.hasPermi('recovery:commodity:add')")
    @Log(title = "回收品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecCommodity recCommodity)
    {
        return toAjax(recCommodityService.insertRecCommodity(recCommodity));
    }

    /**
     * 修改回收品牌
     */
    @PreAuthorize("@ss.hasPermi('recovery:commodity:edit')")
    @Log(title = "回收品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecCommodity recCommodity)
    {
        return toAjax(recCommodityService.updateRecCommodity(recCommodity));
    }

    /**
     * 删除回收品牌
     */
    @PreAuthorize("@ss.hasPermi('recovery:commodity:remove')")
    @Log(title = "回收品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recCommodityService.deleteRecCommodityByIds(ids));
    }
}
