package com.fizz.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fizz.business.form.TlDeleteForm;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.fizz.business.domain.SetupTl;
import com.fizz.business.service.ISetupTlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拉矫机参数Controller
 * 
 * @author ruoyi
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/business/tl")
public class SetupTlController extends BaseController
{
    @Autowired
    private ISetupTlService setupTlService;

    /**
     * 查询拉矫机参数列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SetupTl setupTl)
    {
        startPage();
        List<SetupTl> list = setupTlService.selectSetupTlList(setupTl);
        return getDataTable(list);
    }

    /**
     * 导出拉矫机参数列表
     */
    @Log(title = "拉矫机参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetupTl setupTl)
    {
        List<SetupTl> list = setupTlService.selectSetupTlList(setupTl);
        ExcelUtil<SetupTl> util = new ExcelUtil<SetupTl>(SetupTl.class);
        util.exportExcel(response, list, "拉矫机参数数据");
    }

    /**
     * 获取拉矫机参数详细信息
     */
    @GetMapping()
    public AjaxResult getInfo(@RequestParam String steelGrade,
                              @RequestParam Long yieldStren,
                              @RequestParam Long thick)
    {
        return success(setupTlService.selectSetupTlBySteelGrade(steelGrade, yieldStren, thick));
    }

    /**
     * 新增拉矫机参数
     */
    @Log(title = "拉矫机参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetupTl setupTl)
    {
        return toAjax(setupTlService.insertSetupTl(setupTl));
    }

    /**
     * 修改拉矫机参数
     */
    @Log(title = "拉矫机参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetupTl setupTl)
    {
        return toAjax(setupTlService.updateSetupTl(setupTl));
    }

    //  拉矫机参数删除接口
    @Log(title = "拉矫机参数", businessType = BusinessType.DELETE)
    @DeleteMapping("/tl")  // 不同路径区分
    public AjaxResult removeTl(@RequestBody TlDeleteForm form) {
        return toAjax(setupTlService.deleteSetupTlBySteelGrades(
                form.getSteelGrades(),
                form.getYieldStrens(),
                form.getThicks()
        ));
    }
}
