package com.ruoyi.project.business.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.domain.TpParaLibrary;
import com.ruoyi.project.business.domain.vo.parabar.ParabarVO;
import com.ruoyi.project.business.service.ITpParaLibraryService;
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 2024-04-23
 */
@RestController
@RequestMapping("/business/library")
public class TpParaLibraryController extends BaseController {
    @Autowired
    private ITpParaLibraryService tpParaLibraryService;

    /**
     * 查询参数列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TpParaLibrary tpParaLibrary) {
        startPage();
        List<TpParaLibrary> list = tpParaLibraryService.selectTpParaLibraryList(tpParaLibrary);
        return getDataTable(list);
    }

    /**
     * 查询参数列表
     */
    @GetMapping("/listForParabar")
    public List<TpParaLibrary> listForParabar(ParabarVO parabarVO) {
        List<TpParaLibrary> list = tpParaLibraryService.selectTpParaLibraryByParabarId(parabarVO.getParabarId());
        return list;
    }

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

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

    /**
     * 新增参数
     */
    @Log(title = "参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TpParaLibrary tpParaLibrary) {
        return toAjax(tpParaLibraryService.insertTpParaLibrary(tpParaLibrary));
    }

    /**
     * 修改参数
     */
    @Log(title = "参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TpParaLibrary tpParaLibrary) {
        return toAjax(tpParaLibraryService.updateTpParaLibrary(tpParaLibrary));
    }

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

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


    /**
     * description: listForConfig  服务于公式配置页面的查询，无需分页
     *
     * @param tpParaLibrary:
     * @return com.ruoyi.framework.web.domain.AjaxResult
     * @author jubs 😀
     * @date 2024/4/28 14:05
     */
    @GetMapping("/listForConfig")
    public AjaxResult listForConfig(TpParaLibrary tpParaLibrary) {
        List<TpParaLibrary> list = tpParaLibraryService.selectTpParaLibraryList(tpParaLibrary);
        return AjaxResult.success(list);
    }
}
