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.ParsingRpInfo;
import com.jiayue.ipp.idp.service.an.ParsingRpInfoService;
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("/parsingRpController")
public class ParsingRpController {
    @Autowired
    ParsingRpInfoService parsingRpInfoService;

    @ApiOperation(value = "添加实际功率配置", notes = "添加实际功率配置")
    @PostMapping()
    public R add(@RequestBody ParsingRpInfo parsingRpInfo) {
        if (parsingRpInfoService.save(parsingRpInfo)) {
            return R.ok("添加成功！");
        } else {
            return R.failed("添加失败！");
        }
    }

    @ApiOperation(value = "修改实际功率配置", notes = "修改实际功率配置")
    @PutMapping()
    public R update(@RequestBody ParsingRpInfo parsingRpInfo) {
        if (parsingRpInfoService.updateById(parsingRpInfo)) {
            return R.ok("修改成功！");
        } else {
            return R.failed("修改失败！");
        }
    }

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

    @ApiOperation(value = "分页查询实际功率配置", notes = "分页查询实际功率配置")
    @GetMapping("/page")
    public R page(ParsingRpInfo parsingRpInfo, Page page) {
        return R.ok(parsingRpInfoService.page(page, Wrappers.query(parsingRpInfo)));
    }
}
