package com.fizz.business.controller;

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

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

/**
 * 光整机弯辊力Controller
 * 
 * @author Joshi
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/business/bendforce")
public class SetupTmBendforceController extends BaseController
{
    @Autowired
    private ISetupTmBendforceService setupTmBendforceService;

    /**
     * 查询光整机弯辊力列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SetupTmBendforce setupTmBendforce)
    {
        startPage();
        List<SetupTmBendforce> list = setupTmBendforceService.selectSetupTmBendforceList(setupTmBendforce);
        return getDataTable(list);
    }

    /**
     * 导出光整机弯辊力列表
     */
    @Log(title = "光整机弯辊力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetupTmBendforce setupTmBendforce)
    {
        List<SetupTmBendforce> list = setupTmBendforceService.selectSetupTmBendforceList(setupTmBendforce);
        ExcelUtil<SetupTmBendforce> util = new ExcelUtil<SetupTmBendforce>(SetupTmBendforce.class);
        util.exportExcel(response, list, "光整机弯辊力数据");
    }

    /**
     * 获取光整机弯辊力详细信息
     */
    @GetMapping()
    public AjaxResult getInfo(@RequestParam Long width,
                              @RequestParam Long rollForce)
    {
        return success(setupTmBendforceService.selectSetupTmBendforceByWidth(width,rollForce));
    }

    /**
     * 新增光整机弯辊力
     */
    @Log(title = "光整机弯辊力", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetupTmBendforce setupTmBendforce)
    {
        return toAjax(setupTmBendforceService.insertSetupTmBendforce(setupTmBendforce));
    }

    /**
     * 修改光整机弯辊力
     */
    @Log(title = "光整机弯辊力", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetupTmBendforce setupTmBendforce)
    {
        return toAjax(setupTmBendforceService.updateSetupTmBendforce(setupTmBendforce));
    }

    /**
     * 删除光整机弯辊力
     */
    @Log(title = "光整机弯辊力", businessType = BusinessType.DELETE)
    @DeleteMapping("/tm/bendforce")
    public AjaxResult removeTmBendforce(@RequestBody TmBendforceDeleteForm form) {
        return toAjax(setupTmBendforceService.deleteSetupTmBendforceByWidths(
                form.getWidths(),
                form.getRollForces()
        ));
    }
}
