package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysUnitConvert;
import com.ruoyi.system.service.ISysUnitConvertService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单位换算Controller
 * 
 * @author ruoyi
 * @date 2025-10-08
 */
@RestController
@RequestMapping("/system/convert")
@Tag(name = "【单位换算】管理")
public class SysUnitConvertController extends BaseController
{
    @Autowired
    private ISysUnitConvertService sysUnitConvertService;

    /**
     * 查询单位换算列表
     */
    @Operation(summary = "查询单位换算列表")
    @GetMapping("/list")
    public TableDataInfo list(SysUnitConvert sysUnitConvert)
    {
        startPage();
        List<SysUnitConvert> list = sysUnitConvertService.selectSysUnitConvertList(sysUnitConvert);
        return getDataTable(list);
    }

    /**
     * 导出单位换算列表
     */
    @Operation(summary = "导出单位换算列表")
    @PreAuthorize("@ss.hasPermi('system:convert:export')")
    @Log(title = "单位换算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUnitConvert sysUnitConvert)
    {
        List<SysUnitConvert> list = sysUnitConvertService.selectSysUnitConvertList(sysUnitConvert);
        ExcelUtil<SysUnitConvert> util = new ExcelUtil<SysUnitConvert>(SysUnitConvert.class);
        util.exportExcel(response, list, "单位换算数据");
    }

    /**
     * 获取单位换算详细信息
     */
    @Operation(summary = "获取单位换算详细信息")
    @PreAuthorize("@ss.hasPermi('system:convert:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysUnitConvertService.selectSysUnitConvertById(id));
    }

    /**
     * 新增单位换算
     */
    @Operation(summary = "新增单位换算")
    @PreAuthorize("@ss.hasPermi('system:convert:add')")
    @Log(title = "单位换算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUnitConvert sysUnitConvert)
    {
        return toAjax(sysUnitConvertService.insertSysUnitConvert(sysUnitConvert));
    }

    /**
     * 修改单位换算
     */
    @Operation(summary = "修改单位换算")
    @PreAuthorize("@ss.hasPermi('system:convert:edit')")
    @Log(title = "单位换算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUnitConvert sysUnitConvert)
    {
        return toAjax(sysUnitConvertService.updateSysUnitConvert(sysUnitConvert));
    }

    /**
     * 删除单位换算
     */
    @Operation(summary = "删除单位换算")
    @PreAuthorize("@ss.hasPermi('system:convert:remove')")
    @Log(title = "单位换算", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(sysUnitConvertService.deleteSysUnitConvertByIds(ids));
    }
}
