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.RecStores;
import com.ruoyi.framework.recovery.service.IRecStoresService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回收发售门店Controller
 *
 * @author jin
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/recovery/stores")
public class RecStoresController extends BaseController
{
    @Autowired
    private IRecStoresService recStoresService;

    /**
     * 查询回收发售门店列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:stores:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecStores recStores)
    {
        startPage();
        List<RecStores> list = recStoresService.selectRecStoresList(recStores);
        return getDataTable(list);
    }

    /**
     * 导出回收发售门店列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:stores:export')")
    @Log(title = "导出回收发售门店列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecStores recStores)
    {
        List<RecStores> list = recStoresService.selectRecStoresList(recStores);
        ExcelUtil<RecStores> util = new ExcelUtil<RecStores>(RecStores.class);
        util.exportExcel(response, list, "回收发售门店数据");
    }

    /**
     * 获取回收发售门店详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:stores:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recStoresService.selectRecStoresById(id));
    }

    /**
     * 新增回收发售门店
     */
    @PreAuthorize("@ss.hasPermi('recovery:stores:add')")
    @Log(title = "新增回收发售门店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecStores recStores)
    {
        return toAjax(recStoresService.insertRecStores(recStores));
    }

    /**
     * 修改回收发售门店
     */
    @PreAuthorize("@ss.hasPermi('recovery:stores:edit')")
    @Log(title = "修改回收发售门店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecStores recStores)
    {
        return toAjax(recStoresService.updateRecStores(recStores));
    }

    /**
     * 删除回收发售门店
     */
    @PreAuthorize("@ss.hasPermi('recovery:stores:remove')")
    @Log(title = "删除回收发售门店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recStoresService.deleteRecStoresByIds(ids));
    }
}
