package com.ruoyi.interfaces.controller;

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

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.interfaces.domain.TbModels;
import com.ruoyi.interfaces.service.TbModelsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型Controller
 * 
 * @author ruoyi
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/tb/models")
public class TbModelsController extends BaseController
{
    @Autowired
    private TbModelsService tbModelsService;

    /**
     * 查询模型列表
     */
    @ApiOperation("查询模型列表")
    @GetMapping("/list")
    public TableDataInfo list(TbModels tbModels)
    {
        startPage();
        List<TbModels> list = tbModelsService.selectTbModelsList(tbModels);
        return getDataTable(list);
    }

    /**
     * 导出模型列表
     */
    @ApiOperation("导出模型列表")
    @Log(title = "模型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbModels tbModels)
    {
        List<TbModels> list = tbModelsService.selectTbModelsList(tbModels);
        ExcelUtil<TbModels> util = new ExcelUtil<TbModels>(TbModels.class);
        util.exportExcel(response, list, "模型数据");
    }

    /**
     * 获取模型详细信息
     */
    @ApiOperation("获取模型详细信息")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return success(tbModelsService.selectTbModelsByModelId(modelId));
    }

    /**
     * 新增模型
     */
    @ApiOperation("新增模型")
    @Log(title = "模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbModels tbModels)
    {
        tbModels.setCreatedBy(getUsername());
        tbModels.setCreatedTime(DateUtils.getNowDate());
        return toAjax(tbModelsService.insertTbModels(tbModels));
    }

    /**
     * 修改模型
     */
    @ApiOperation("修改模型")
    @Log(title = "模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbModels tbModels)
    {
        tbModels.setUpdatedBy(getUsername());
        tbModels.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(tbModelsService.updateTbModels(tbModels));
    }

    /**
     * 删除模型
     */
    @ApiOperation("删除模型")
    @Log(title = "模型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(tbModelsService.deleteTbModelsByModelIds(modelIds));
    }
}