package com.fizz.business.controller;

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

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

/**
 * 光整机插入量Controller
 * 
 * @author Joshi
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/business/mesh")
public class SetupTmMeshController extends BaseController
{
    @Autowired
    private ISetupTmMeshService setupTmMeshService;

    /**
     * 查询光整机插入量列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SetupTmMesh setupTmMesh)
    {
        startPage();
        List<SetupTmMesh> list = setupTmMeshService.selectSetupTmMeshList(setupTmMesh);
        return getDataTable(list);
    }

    /**
     * 导出光整机插入量列表
     */
    @Log(title = "光整机插入量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetupTmMesh setupTmMesh)
    {
        List<SetupTmMesh> list = setupTmMeshService.selectSetupTmMeshList(setupTmMesh);
        ExcelUtil<SetupTmMesh> util = new ExcelUtil<SetupTmMesh>(SetupTmMesh.class);
        util.exportExcel(response, list, "光整机插入量数据");
    }

    /**
     * 获取光整机插入量详细信息
     */
    @GetMapping()
    public AjaxResult getInfo(@RequestParam String steelGrade,
                              @RequestParam Long yieldStren,
                              @RequestParam Long thick)
    {
        return success(setupTmMeshService.selectSetupTmMeshBySteelGrade(steelGrade, yieldStren, thick));
    }

    /**
     * 新增光整机插入量
     */
    @Log(title = "光整机插入量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetupTmMesh setupTmMesh)
    {
        return toAjax(setupTmMeshService.insertSetupTmMesh(setupTmMesh));
    }

    /**
     * 修改光整机插入量
     */
    @Log(title = "光整机插入量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetupTmMesh setupTmMesh)
    {
        return toAjax(setupTmMeshService.updateSetupTmMesh(setupTmMesh));
    }

    /**
     * 删除光整机插入量
     */
    @Log(title = "光整机插入量", businessType = BusinessType.DELETE)
    @DeleteMapping("/tm/mesh")
    public AjaxResult removeTmMesh(@RequestBody TmMeshDeleteForm form) {
        return toAjax(setupTmMeshService.deleteSetupTmMeshBySteelGrades(
                form.getSteelGrades(),
                form.getYieldStrens(),
                form.getThicks()
        ));
    }
}
