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.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.manager.entity.FormulaBase;
import org.springblade.manager.service.impl.FormulaBaseService;
import org.springblade.manager.vo.FormulaBaseVo;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;


/**
 * @author yangyj
 * @Date 2022/6/6 15:31
 * @description TODO
 */
@RestController
@AllArgsConstructor
@RequestMapping("/fb")
@Api(value = "基础公式", tags = "基础公式")
public class FormulaBaseController extends BladeController {

    private final FormulaBaseService service;
    /**
     * 新增或修改
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增或修改", notes = "传入")
    public R save(FormulaBase fb) {
        return R.status(service.save(fb));
    }

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

    /**
     * 删除
     */
    @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<FormulaBase> detail(FormulaBase fb) {
        FormulaBase detail = service.getOne(Condition.getQueryWrapper(fb));
        return R.data(detail);
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "按类型获取基础公式", notes = "传入id")
    @GetMapping("/getTypeMap")
    public R<Map<String, List<FormulaBaseVo>>> getTypeMap() {
        return R.data(this.service.getTypeMap());
    }


}
