package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.ViewConsSuppFlow;
import cn.ysk.cashier.cons.service.ViewConsSuppFlowService;
import cn.ysk.cashier.cons.service.dto.ViewConsSuppFlowQueryCriteria;
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-03
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "出入库记录管理")
@RequestMapping("/api/viewConsSuppFlow")
public class ViewConsSuppFlowController {

    private final ViewConsSuppFlowService viewConsSuppFlowService;

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

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

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

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

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