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.ParsingCdq;
import com.cpp.web.service.datafactory.ParsingCdqService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@RequestMapping("/parsingCdq")
public class ParsingCdqController {
    private final ParsingCdqService parsingCdqService;

    @ApiOperation(value = "添加超短期配置", notes = "添加超短期配置")
    @PostMapping()
    public R add(@RequestBody ParsingCdq parsingCdq) {
        if (parsingCdqService.save(parsingCdq)) {
            return R.ok("添加成功！");
        } else {
            return R.fail("添加失败！");
        }
    }

    @ApiOperation(value = "修改超短期配置", notes = "修改超短期配置")
    @PutMapping()
    public R update(@RequestBody ParsingCdq parsingCdq) {
        if (parsingCdqService.updateById(parsingCdq)) {
            return R.ok("修改成功！");
        } else {
            return R.fail("修改失败！");
        }
    }

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

    @ApiOperation(value = "分页查询超短期配置", notes = "分页查询超短期配置")
    @GetMapping("/page")
    public R page(Long currentPage,Long pageSize) {
        Page page = new Page(currentPage, pageSize);
        page.setMaxLimit((long) -1);
        return R.ok(parsingCdqService.page(page));
    }
}
