package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.TbConsSuppFlow;
import cn.ysk.cashier.cons.service.TbConsSuppFlowService;
import cn.ysk.cashier.cons.service.dto.TbConsSuppFlowQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author admin
* @date 2024-07-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "入库记录管理")
@RequestMapping("/api/tbConsSuppFlow")
public class TbConsSuppFlowController {

    private final TbConsSuppFlowService tbConsSuppFlowService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void exportTbConsSuppFlow(HttpServletResponse response, TbConsSuppFlowQueryCriteria criteria) throws IOException {
        tbConsSuppFlowService.download(tbConsSuppFlowService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询入库记录")
    public ResponseEntity<Object> queryTbConsSuppFlow(TbConsSuppFlowQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(tbConsSuppFlowService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增入库记录")
    @ApiOperation("新增入库记录")
    public ResponseEntity<Object> createTbConsSuppFlow(@Validated @RequestBody TbConsSuppFlow resources){
        return new ResponseEntity<>(tbConsSuppFlowService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改入库记录")
    @ApiOperation("修改入库记录")
    public ResponseEntity<Object> updateTbConsSuppFlow(@Validated @RequestBody TbConsSuppFlow resources){
        tbConsSuppFlowService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除入库记录")
    @ApiOperation("删除入库记录")
    public ResponseEntity<Object> deleteTbConsSuppFlow(@RequestBody Integer[] ids) {
        tbConsSuppFlowService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}