package com.ruoyi.project.business.controller;

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

import com.ruoyi.framework.annotation.DataUpdateCheck;
import com.ruoyi.project.business.domain.TpParaLibrary;
import com.ruoyi.project.business.domain.vo.parabar.*;
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.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.TpParabar;
import com.ruoyi.project.business.service.ITpParabarService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 参数包Controller
 * 
 * @author ruoyi
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/business/parabar")
public class TpParabarController extends BaseController
{
    @Resource
    private ITpParabarService tpParabarService;

    /**
     * 查询参数包列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TpParabar tpParabar)
    {
        startPage();
        List<TpParabar> list = tpParabarService.selectTpParabarList(tpParabar);
        return getDataTable(list);
    }


    @GetMapping("/parabarDetailList")
    public List<ParabarDetailVO> selectParabarDetail(ParabarVO parabarVO)
    {
        List<ParabarDetailVO> list = tpParabarService.selectParabarDetail(parabarVO);
        return list;
    }

    /**
     *  获取关联梯型
     */
    @GetMapping("/relatedModelList")
    public List<RelatedModelVO> getRelatedModelList(TpParabar tpParabar)
    {
        List<RelatedModelVO> list = tpParabarService.getRelatedModelList(tpParabar);
        return list;
    }

    /**
     *  获取关联梯形的共同参数
     */
    @GetMapping("/commonParaList")
    public List<CommonPara> getCommonParaList(ParaForGetCommonPara para)
    {
        List<CommonPara> list = tpParabarService.getCommonParaList(para);
        return list;
    }

    /**
     *  获取关联梯形的共同参数以及共同选项
     */
    @GetMapping("/commonParaAndItemList")
    public List<CommonPara> getCommonParaAndItemList(ParaForGetCommonPara para)
    {
        List<CommonPara> list = tpParabarService.getCommonParaAndItemList(para);
        return list;
    }


    /**
     * 导出参数包列表
     */
    @Log(title = "参数包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TpParabar tpParabar)
    {
        List<TpParabar> list = tpParabarService.selectTpParabarList(tpParabar);
        ExcelUtil<TpParabar> util = new ExcelUtil<TpParabar>(TpParabar.class);
        util.exportExcel(response, list, "参数包数据");
    }

    /**
     * 获取参数包详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tpParabarService.selectTpParabarById(id));
    }

    /**
     * 新增参数包
     */
    @Log(title = "参数包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParabarVO parabarVO)
    {
        return toAjax(tpParabarService.insertTpParabar(parabarVO));
    }

    /**
     * 修改参数包
     */
    @Log(title = "参数包", businessType = BusinessType.UPDATE)
    @PutMapping
    @DataUpdateCheck(key = "id", tableName = "tp_parabar")
    public AjaxResult edit(@RequestBody ParabarVO parabarVO)
    {
        return toAjax(tpParabarService.updateTpParabar(parabarVO));
    }

    /**
     * 删除参数包
     */
    @Log(title = "参数包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tpParabarService.deleteTpParabarByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "参数", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TpParabar tpParabar) {
        return toAjax(tpParabarService.updateParaStatus(tpParabar));
    }
}
