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


@RestController
@RequiredArgsConstructor
@RequestMapping("/parsingDq")
public class ParsingDqController {
    
    private final ParsingDqService parsingDqService;

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

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

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

    @ApiOperation(value = "分页查询短期配置", notes = "分页查询短期配置")
    @GetMapping("/page")
    public R page(ParsingDq parsingDq, Page page) {
        return R.ok(parsingDqService.page(page, Wrappers.query(parsingDq)));
    }
}
