package com.fizz.business.controller;

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

import com.fizz.business.form.TmRollforceDeleteForm;
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.SetupTmRollforce;
import com.fizz.business.service.ISetupTmRollforceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 光整机轧制力Controller
 * 
 * @author Joshi
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/business/rollforce")
public class SetupTmRollforceController extends BaseController
{
    @Autowired
    private ISetupTmRollforceService setupTmRollforceService;

    /**
     * 查询光整机轧制力列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SetupTmRollforce setupTmRollforce)
    {
        startPage();
        List<SetupTmRollforce> list = setupTmRollforceService.selectSetupTmRollforceList(setupTmRollforce);
        return getDataTable(list);
    }

    /**
     * 导出光整机轧制力列表
     */
    @Log(title = "光整机轧制力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetupTmRollforce setupTmRollforce)
    {
        List<SetupTmRollforce> list = setupTmRollforceService.selectSetupTmRollforceList(setupTmRollforce);
        ExcelUtil<SetupTmRollforce> util = new ExcelUtil<SetupTmRollforce>(SetupTmRollforce.class);
        util.exportExcel(response, list, "光整机轧制力数据");
    }

    /**
     * 获取光整机轧制力详细信息
     */
    @GetMapping()
    public AjaxResult getInfo(@RequestParam String steelGrade,
                              @RequestParam Long yieldStren,
                              @RequestParam Long thick,
                              @RequestParam Long elong)
    {
        return success(setupTmRollforceService.selectSetupTmRollforceBySteelGrade(steelGrade, yieldStren, thick, elong));
    }

    /**
     * 新增光整机轧制力
     */
    @Log(title = "光整机轧制力", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetupTmRollforce setupTmRollforce)
    {
        return toAjax(setupTmRollforceService.insertSetupTmRollforce(setupTmRollforce));
    }

    /**
     * 修改光整机轧制力
     */
    @Log(title = "光整机轧制力", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetupTmRollforce setupTmRollforce)
    {
        return toAjax(setupTmRollforceService.updateSetupTmRollforce(setupTmRollforce));
    }

    /**
     * 删除光整机轧制力
     */
    @Log(title = "光整机轧制力", businessType = BusinessType.DELETE)
    @DeleteMapping("/tm/rollforce")
    public AjaxResult removeTmRollforce(@RequestBody TmRollforceDeleteForm form) {
        return toAjax(setupTmRollforceService.deleteSetupTmRollforceBySteelGrades(
                form.getSteelGrades(),
                form.getThicks(),
                form.getYieldStrens(),
                form.getElongs()
        ));
    }
}
