package com.fizz.business.controller;

import com.fizz.business.domain.CrmPdoExcoil;
import com.fizz.business.form.CrmPdoExcoilForm;
import com.fizz.business.service.CrmPdoExcoilService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/pdo")
@Tag(name ="实绩管理")
@Anonymous
public class CrmPdoExcoilController extends BaseController {

    @Resource
    private CrmPdoExcoilService crmPdoExcoilService;

    @GetMapping("/get/{excoilid}")
    @Operation(summary ="查询实绩")
    public R<CrmPdoExcoil> getByExcoilId(@PathVariable String excoilid) {
        return R.ok(crmPdoExcoilService.getByExcoilId(excoilid));
    }

    @PostMapping("/add")
    @Operation(summary ="新增实绩")
    public R<Boolean> add(@RequestBody CrmPdoExcoil crmPdoExcoil) {
        return R.ok(crmPdoExcoilService.addCrmPdoExcoil(crmPdoExcoil));
    }

    @PutMapping("/update")
    @Operation(summary ="修改")
    public R<Boolean> update(@RequestBody CrmPdoExcoil crmPdoExcoil) {
        return R.ok(crmPdoExcoilService.updateCrmPdoExcoil(crmPdoExcoil));
    }

    @DeleteMapping("/delete/{excoilid}/{planId}")
    @Operation(summary ="删除实绩")

    public R<Boolean> delete(@PathVariable String excoilid, @PathVariable String planId) {
        return R.ok(crmPdoExcoilService.deleteCrmPdoExcoil(excoilid, planId));
    }

    @PostMapping("/list")
    @Operation(summary ="查询实绩列表")
    public TableDataInfo list(@RequestBody CrmPdoExcoilForm form) {
        // 设置分页参数，默认每页20条
        if (form.getPageNum() == null || form.getPageNum() < 1) {
            form.setPageNum(1);
        }
        if (form.getPageSize() == null || form.getPageSize() < 1) {
            form.setPageSize(20);
        }
        com.github.pagehelper.PageHelper.startPage(form.getPageNum(), form.getPageSize());
        List<CrmPdoExcoil> list = crmPdoExcoilService.listAll(form);
        return getDataTable(list);
    }
}
