package org.springblade.manager.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.manager.entity.Formula;
import org.springblade.manager.service.impl.FormulaService;
import org.springframework.web.bind.annotation.*;

/**
 * @author yangyj
 * @Date 2022/6/9 14:27
 * @description TODO
 */
@RestController
@AllArgsConstructor
@RequestMapping("/formula")
@Api(value = "公式脚本", tags = "公式脚本")
public class FormulaController {
    private final FormulaService service;
    /**
     * 新增或修改
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增或修改", notes = "传入")
    public R save(Formula f) {
        return R.status(service.save(f));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入脚本")
    public R update( Formula f) {
        return R.status(service.updateById(f));
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除", notes = "传入id集合")
    public R remove(@RequestParam String ids) {
        return R.status(this.service.deleteLogic(Func.toLongList(ids)));
    }
    /**
     * 查询单条
     */
    @ApiOperationSupport(order =7)
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/detail")
    public R<Formula> detail(Formula f) {
        Formula detail = service.getOne(Condition.getQueryWrapper(f));
        return R.data(detail);
    }


}
