package com.ruoyi.ucp.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ucp.entity.Formula;
import com.ruoyi.ucp.service.IFormulaService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gfhd
 * @since 2024-03-05
 */
@RestController
@RequestMapping("/formula")
public class FormulaController extends BaseController {
    @Resource
    private IFormulaService formulaService;

    /**
     * 查询方法列表
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('monitor:job:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<Formula> list = formulaService.list();
        return getDataTable(list);
    }

    /**
     * 获取方法详细信息
     */
    @PreAuthorize("@ss.hasPermi('monitor:job:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId) {
        return success(formulaService.getById(jobId));
    }

    /**
     * 新增方法
     */
    @PreAuthorize("@ss.hasPermi('monitor:job:add')")
    @Log(title = "方法", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Formula job) {
        return toAjax(formulaService.saveOrUpdate(job));
    }

    /**
     * 删除方法
     */
    @PreAuthorize("@ss.hasPermi('monitor:job:remove')")
    @Log(title = "方法", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable List<Long> jobIds) {
        return toAjax(formulaService.removeByIds(jobIds));
    }
}
