package com.ruoyi.framework.recovery.controller;

import java.util.List;

import com.ruoyi.framework.recovery.domain.vo.RecStallGoodsVo;
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.RecStall;
import com.ruoyi.framework.recovery.service.IRecStallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回收档口Controller
 * 
 * @author jin
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/recovery/stall")
public class RecStallController extends BaseController
{
    @Autowired
    private IRecStallService recStallService;

    /**
     * 查询回收档口列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecStall recStall)
    {
        startPage();
        List<RecStall> list = recStallService.selectRecStallList(recStall);
        return getDataTable(list);
    }

    /**
     * 导出回收档口列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:export')")
    @Log(title = "回收档口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecStall recStall)
    {
        List<RecStall> list = recStallService.selectRecStallList(recStall);
        ExcelUtil<RecStall> util = new ExcelUtil<RecStall>(RecStall.class);
        util.exportExcel(response, list, "回收档口数据");
    }

    /**
     * 获取回收档口详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recStallService.selectRecStallById(id));
    }

    /**
     * 新增回收档口
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:add')")
    @Log(title = "回收档口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecStall recStall)
    {
        return toAjax(recStallService.insertRecStall(recStall));
    }

    /**
     * 修改回收档口
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:edit')")
    @Log(title = "回收档口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecStall recStall)
    {
        return toAjax(recStallService.updateRecStall(recStall));
    }

    /**
     * 删除回收档口
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:remove')")
    @Log(title = "回收档口", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recStallService.deleteRecStallByIds(ids));
    }

    /**
     * 查询所有商品内容
     */
    @PreAuthorize("@ss.hasPermi('recovery:stall:list')")
    @GetMapping("/goods/list")
    public AjaxResult getGoods()
    {
        List<RecStallGoodsVo> list = recStallService.selectGoodsList();
        return AjaxResult.success(list);
    }
}
