package com.ruoyi.logistics.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.logistics.domain.SysDeptRate;
import com.ruoyi.logistics.service.ISysDeptRateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * PC-供应商费率配置
 * 
 * @author RuiJing
 * @date 2026-03-17
 */
@RestController
@RequestMapping("/rate")
public class SysDeptRateController extends BaseController
{
    @Autowired
    private ISysDeptRateService sysDeptRateService;

    /**
     * 查询供应商费率配置列表
     */
    @RequiresPermissions("logistics:rate:list")
    @GetMapping("/list")
    public TableDataInfo list(SysDeptRate sysDeptRate)
    {
//        startPage();
        List<SysDeptRate> list = sysDeptRateService.selectSysDeptRateList(sysDeptRate);
        return getDataTable(list);
    }

    /**
     * 导出供应商费率配置列表
     */
    @RequiresPermissions("logistics:rate:export")
    @Log(title = "供应商费率配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDeptRate sysDeptRate)
    {
        List<SysDeptRate> list = sysDeptRateService.selectSysDeptRateList(sysDeptRate);
        ExcelUtil<SysDeptRate> util = new ExcelUtil<SysDeptRate>(SysDeptRate.class);
        util.exportExcel(response, list, "供应商费率配置数据");
    }

    /**
     * 获取供应商费率配置详细信息
     */
    @RequiresPermissions("logistics:rate:query")
    @GetMapping(value = "/{rateId}")
    public AjaxResult getInfo(@PathVariable("rateId") Long rateId)
    {
        return success(sysDeptRateService.selectSysDeptRateByRateId(rateId));
    }

    /**
     * 新增供应商费率配置
     */
    @RequiresPermissions("logistics:rate:add")
    @Log(title = "供应商费率配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<SysDeptRate> sysDeptRates, @RequestParam("deptId") Long deptId)
    {
        return toAjax(sysDeptRateService.insertSysDeptRate(sysDeptRates, deptId));
    }

    /**
     * 修改供应商费率配置
     */
    @RequiresPermissions("logistics:rate:edit")
    @Log(title = "供应商费率配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDeptRate sysDeptRate)
    {
        return toAjax(sysDeptRateService.updateSysDeptRate(sysDeptRate));
    }

    /**
     * 删除供应商费率配置
     */
    @RequiresPermissions("logistics:rate:remove")
    @Log(title = "供应商费率配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rateIds}")
    public AjaxResult remove(@PathVariable Long[] rateIds)
    {
        return toAjax(sysDeptRateService.deleteSysDeptRateByRateIds(rateIds));
    }
}
