package com.ruoyi.interfaces.controller;

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

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.interfaces.domain.MdModelParams;
import com.ruoyi.interfaces.service.IMdModelParamsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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-07-15
 */
@RestController
@RequestMapping("/model/params")
public class MdModelParamsController extends BaseController
{
    @Autowired
    private IMdModelParamsService mdModelParamsService;

    /**
     * 查询模型参数信息列表
     */
    @ApiOperation("查询模型参数信息列表")
    @GetMapping("/list")
    public TableDataInfo list(MdModelParams mdModelParams)
    {
        startPage();
        List<MdModelParams> list = mdModelParamsService.selectMdModelParamsList(mdModelParams);
        return getDataTable(list);
    }

    /**
     * 查询模型参数信息列表
     */
    @ApiOperation("查询模型参数信息列表")
    @GetMapping("/allList")
    public AjaxResult allList(MdModelParams mdModelParams)
    {
        List<MdModelParams> list = mdModelParamsService.selectMdModelParamsList(mdModelParams);
        return AjaxResult.success(list);
    }


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

    /**
     * 获取模型参数信息详细信息
     */
    @ApiOperation("获取模型参数信息详细信息")
    @GetMapping(value = "/{parId}")
    public AjaxResult getInfo(@PathVariable("parId") String parId)
    {
        return success(mdModelParamsService.selectMdModelParamsByParId(parId));
    }

    /**
     * 新增模型参数信息
     */
    @ApiOperation("新增模型参数信息")
    @Log(title = "模型参数信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdModelParams mdModelParams)
    {
        return toAjax(mdModelParamsService.insertMdModelParams(mdModelParams));
    }

    /**
     * 批量新增模型参数信息
     */
    @ApiOperation("新增模型参数信息")
    @Log(title = "模型参数信息", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<MdModelParams> mdModelParams)
    {
        if (StringUtils.isEmpty(mdModelParams)) return AjaxResult.error("数据为空");
        mdModelParamsService.deleteMdModelParamsByMdid(mdModelParams.get(0).getMdid());
        for (int i = 0; i < mdModelParams.size(); i++) {
            mdModelParams.get(i).setSort(i);
        }
        mdModelParams.forEach(mdModelParamsService::insertMdModelParams);
        return success("插入成功");
    }


    /**
     * 修改模型参数信息
     */
    @ApiOperation("修改模型参数信息")
    @Log(title = "模型参数信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdModelParams mdModelParams)
    {
        return toAjax(mdModelParamsService.updateMdModelParams(mdModelParams));
    }

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