package com.cpp.web.controller.configManager;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpp.common.core.domain.R;
import com.cpp.web.domain.datafactory.ParsingCft;
import com.cpp.web.service.datafactory.ParsingCftService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@RequestMapping("/parsingCft")
public class ParsingCftController {
    private final ParsingCftService parsingCftService;

    @ApiOperation(value = "添加Cft配置", notes = "添加Cft配置")
    @PostMapping()
    public R add(@RequestBody ParsingCft parsingCft) {
        if (parsingCftService.save(parsingCft)) {
            return R.ok("添加成功！");
        } else {
            return R.fail("添加失败！");
        }
    }

    @ApiOperation(value = "修改Cft配置", notes = "修改Cft配置")
    @PutMapping()
    public R update(@RequestBody ParsingCft parsingCft) {
        if (parsingCftService.updateById(parsingCft)) {
            return R.ok("修改成功！");
        } else {
            return R.fail("修改失败！");
        }
    }

    @ApiOperation(value = "根据id删除Cft配置", notes = "根据id删除Cft配置")
    @DeleteMapping("/{id}")
    public R delete(@PathVariable String id) {
        if (parsingCftService.removeById(id)) {
            return R.ok("删除成功！");
        } else {
            return R.fail("删除失败！");
        }
    }

    @ApiOperation(value = "分页查询Cft配置", notes = "分页查询Cft配置")
    @GetMapping("/page")
    public R page(ParsingCft parsingCft, Page page) {
        return R.ok(parsingCftService.page(page, Wrappers.query(parsingCft)));
    }
}
