package com.fizz.business.controller;

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

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

/**
 * 全线张力Controller
 * 
 * @author ruoyi
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/business/tension")
public class SetupTensionController extends BaseController
{
    @Autowired
    private ISetupTensionService setupTensionService;

    /**
     * 查询全线张力列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SetupTension setupTension)
    {
        startPage();
        List<SetupTension> list = setupTensionService.selectSetupTensionList(setupTension);
        return getDataTable(list);
    }

    /**
     * 导出全线张力列表
     */
    @Log(title = "全线张力", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetupTension setupTension)
    {
        List<SetupTension> list = setupTensionService.selectSetupTensionList(setupTension);
        ExcelUtil<SetupTension> util = new ExcelUtil<SetupTension>(SetupTension.class);
        util.exportExcel(response, list, "全线张力数据");
    }

    /**
     * 获取全线张力详细信息
     */
    @GetMapping()
    public AjaxResult getInfo(@RequestParam(required = false) Long thick ,@RequestParam(required = false) Long yieldStren)
    {
        return success(setupTensionService.selectSetupTensionByThick(thick, yieldStren));
    }

    /**
     * 新增全线张力
     */
    @Log(title = "全线张力", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetupTension setupTension)
    {
        return toAjax(setupTensionService.insertSetupTension(setupTension));
    }

    /**
     * 修改全线张力
     */
    @Log(title = "全线张力", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetupTension setupTension)
    {
        return toAjax(setupTensionService.updateSetupTension(setupTension));
    }

    /**
     * 删除全线张力
     */
    @Log(title = "全线张力", businessType = BusinessType.DELETE)
    @DeleteMapping("/tension")  // 建议添加路径区分不同删除接口
    public AjaxResult removeTension(@RequestBody TensionDeleteForm form) {
        return toAjax(setupTensionService.deleteSetupTensionByThicks(
                form.getThicks(),
                form.getYieldStrens()
        ));
    }
}
