package com.example.controller;

import com.example.common.Result;
import com.example.entity.SaleStatement;
import com.example.service.SaleStatementService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 销量表前端操作接口
 **/
@RestController
@RequestMapping("/saleStatement")
public class SaleStatementController {

    @Resource
    private SaleStatementService saleStatementService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody SaleStatement saleStatement) {
        saleStatementService.add(saleStatement);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        saleStatementService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        saleStatementService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody SaleStatement saleStatement) {
        saleStatementService.updateById(saleStatement);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        SaleStatement saleStatement = saleStatementService.selectById(id);
        return Result.success(saleStatement);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(SaleStatement saleStatement) {
        List<SaleStatement> list = saleStatementService.selectAll(saleStatement);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(SaleStatement saleStatement,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<SaleStatement> page = saleStatementService.selectPage(saleStatement, pageNum, pageSize);
        return Result.success(page);
    }

}