package com.jiayue.ipp.idp.controller.an;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.an.ParsingCdqInfo;
import com.jiayue.ipp.idp.service.an.ParsingCdqInfoService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@RequestMapping("/parsingCdqController")
public class ParsingCdqController {
    @Autowired
    ParsingCdqInfoService parsingCdqInfoService;

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

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

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

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