package com.dcs.hnyz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.dcs.common.annotation.Log;
import com.dcs.common.core.controller.BaseController;
import com.dcs.common.core.domain.AjaxResult;
import com.dcs.common.enums.BusinessType;
import com.dcs.hnyz.domain.ModelComponent;
import com.dcs.hnyz.service.IModelComponentService;
import com.dcs.common.utils.poi.ExcelUtil;
import com.dcs.common.core.page.TableDataInfo;

/**
 * 模型组件管理Controller
 * 
 * @author hmy
 * @date 2025-07-04
 */
@RestController
@RequestMapping("/hnyz/modelComponent")
public class ModelComponentController extends BaseController
{
    @Autowired
    private IModelComponentService modelComponentService;

    /**
     * 查询模型组件管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:modelComponent:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelComponent modelComponent)
    {
        startPage();
        List<ModelComponent> list = modelComponentService.selectModelComponentList(modelComponent);
        return getDataTable(list);
    }

    /**
     * 导出模型组件管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:modelComponent:export')")
    @Log(title = "模型组件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelComponent modelComponent)
    {
        List<ModelComponent> list = modelComponentService.selectModelComponentList(modelComponent);
        ExcelUtil<ModelComponent> util = new ExcelUtil<ModelComponent>(ModelComponent.class);
        util.exportExcel(response, list, "模型组件管理数据");
    }

    /**
     * 获取模型组件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hnyz:modelComponent:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return success(modelComponentService.selectModelComponentByModelId(modelId));
    }

    /**
     * 新增模型组件管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:modelComponent:add')")
    @Log(title = "模型组件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ModelComponent modelComponent)
    {
        return toAjax(modelComponentService.insertModelComponent(modelComponent));
    }

    /**
     * 修改模型组件管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:modelComponent:edit')")
    @Log(title = "模型组件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModelComponent modelComponent)
    {
        return toAjax(modelComponentService.updateModelComponent(modelComponent));
    }

    /**
     * 删除模型组件管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:modelComponent:remove')")
    @Log(title = "模型组件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(modelComponentService.deleteModelComponentByModelIds(modelIds));
    }

    /**
     * 获取模型select选择列表
     */
    @GetMapping("/getModelSelectList")
    public AjaxResult getSelectList(){
        return success(modelComponentService.getModelComponentSelectList());
    }
}
