package com.ruoyi.interfaces.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.core.page.TableSupport;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.interfaces.domain.MdModelInfo;
import com.ruoyi.interfaces.service.IMdModelInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 模型信息Controller
 *
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/model/info")
public class MdModelInfoController extends BaseController {
    @Autowired
    private IMdModelInfoService mdModelInfoService;

    /**
     * 查询模型信息列表
     */
    @ApiOperation("查询模型信息列表")
    @GetMapping("/list")
    public TableDataInfo list(MdModelInfo mdModelInfo) {
        startPage();
        List<MdModelInfo> list = mdModelInfoService.selectMdModelInfoList(mdModelInfo);
        return getDataTable(list);
    }

    /**
     * 查询模型信息列表
     */
    @ApiOperation("查询模型信息列表")
    @GetMapping("/list2")
    public AjaxResult list2(MdModelInfo mdModelInfo) {
        return AjaxResult.success(mdModelInfoService.selectMdModelInfoList(mdModelInfo));
    }

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

    /**
     * 获取模型信息详细信息
     */
    @ApiOperation("获取模型信息详细信息")
    @GetMapping(value = "/{mdid}")
    public AjaxResult getInfo(@PathVariable("mdid") String mdid) {
        return success(mdModelInfoService.selectMdModelInfoByMdid(mdid));
    }

    /**
     * 新增模型信息
     */
    @ApiOperation("新增模型信息")
    @Log(title = "模型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdModelInfo mdModelInfo) {
        if (StringUtils.isNull(mdModelInfo.getName()))return error("【模型名称】不可为空");
        if (StringUtils.isNull(mdModelInfo.getEnname()))return error("【模型英文名称】不可为空");
        mdModelInfo.setRegUser(getUsername());
        mdModelInfo.setAudit("0");
        return AjaxResult.success(mdModelInfoService.insertMdModelInfo(mdModelInfo));
    }

    /**
     * 修改模型信息
     */
    @ApiOperation("修改模型信息")
    @Log(title = "模型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdModelInfo mdModelInfo) {
        if (StringUtils.isNull(mdModelInfo.getName()))return error("【模型名称】不可为空");
        if (StringUtils.isNull(mdModelInfo.getEnname()))return error("【模型英文名称】不可为空");
        return toAjax(mdModelInfoService.updateMdModelInfo(mdModelInfo));
    }

    /**
     * 删除模型信息
     */
    @ApiOperation("删除模型信息")
    @Log(title = "模型信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mdids}")
    public AjaxResult remove(@PathVariable String[] mdids) {
        return toAjax(mdModelInfoService.deleteMdModelInfoByMdids(mdids));
    }

    @GetMapping("/audit")
    public AjaxResult audit(String[] mdids,String audit){
        return success(mdModelInfoService.audit(mdids,audit));
    }

}
