package com.ruoyi.interfaces.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.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.interfaces.domain.MdApp;
import com.ruoyi.interfaces.service.IMdAppService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型应用Controller
 * 
 * @author 朱得糠
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/md/app")
public class MdAppController extends BaseController
{
    @Autowired
    private IMdAppService mdAppService;

    /**
     * 查询模型应用列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MdApp mdApp)
    {
        startPage();
        List<MdApp> list = mdAppService.selectMdAppList(mdApp);
        return getDataTable(list);
    }

    /**
     * 导出模型应用列表
     */
    @Log(title = "模型应用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdApp mdApp)
    {
        List<MdApp> list = mdAppService.selectMdAppList(mdApp);
        ExcelUtil<MdApp> util = new ExcelUtil<MdApp>(MdApp.class);
        util.exportExcel(response, list, "模型应用数据");
    }

    /**
     * 获取模型应用详细信息
     */
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId)
    {
        return success(mdAppService.selectMdAppByAppId(appId));
    }

    /**
     * 新增模型应用
     */
    @Log(title = "模型应用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdApp mdApp)
    {
        mdApp.setCreateBy(getUsername());
        return toAjax(mdAppService.insertMdApp(mdApp));
    }

    /**
     * 修改模型应用
     */
    @Log(title = "模型应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdApp mdApp)
    {
        mdApp.setUpdateBy(getUsername());
        return toAjax(mdAppService.updateMdApp(mdApp));
    }

    /**
     * 删除模型应用
     */
    @Log(title = "模型应用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds)
    {
        return toAjax(mdAppService.deleteMdAppByAppIds(appIds));
    }
}
