package com.sundot.airport.web.controller.blocked;

import java.util.List;
import javax.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.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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.blocked.domain.BlockedRate;
import com.sundot.airport.blocked.service.IBlockedRateService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 速率Controller
 *
 * @author ruoyi
 * @date 2026-04-13
 */
@RestController
@RequestMapping("/blocked/rate")
public class BlockedRateController extends BaseController {
    @Autowired
    private IBlockedRateService blockedRateService;

    /**
     * 查询速率列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlockedRate itemSeizureRate) {
        startPage();
        List<BlockedRate> list = blockedRateService.selectBlockedRateList(itemSeizureRate);
        return getDataTable(list);
    }

    /**
     * 导出速率列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:export')")
    @Log(title = "速率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlockedRate itemSeizureRate) {
        List<BlockedRate> list = blockedRateService.selectBlockedRateList(itemSeizureRate);
        ExcelUtil<BlockedRate> util = new ExcelUtil<>(BlockedRate.class);
        util.exportExcel(response, list, "速率数据");
    }

    /**
     * 导入速率列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:import')")
    @Log(title = "导入速率列表", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<BlockedRate> util = new ExcelUtil<>(BlockedRate.class);
        List<BlockedRate> list = util.importExcel(file.getInputStream());
        String message = blockedRateService.importData(list, updateSupport);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BlockedRate> util = new ExcelUtil<>(BlockedRate.class);
        util.importTemplateExcel(response, "速率数据导入模板");
    }

    /**
     * 获取速率详细信息
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(blockedRateService.selectBlockedRateById(id));
    }

    /**
     * 新增速率
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:add')")
    @Log(title = "速率", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BlockedRate itemSeizureRate) {
        itemSeizureRate.setCreateBy(getUsername());
        return toAjax(blockedRateService.insertBlockedRate(itemSeizureRate));
    }

    /**
     * 修改速率
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:edit')")
    @Log(title = "速率", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BlockedRate itemSeizureRate) {
        itemSeizureRate.setUpdateBy(getUsername());
        return toAjax(blockedRateService.updateBlockedRate(itemSeizureRate));
    }

    /**
     * 删除速率
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:remove')")
    @Log(title = "速率", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blockedRateService.deleteBlockedRateByIds(ids));
    }
}
