package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.TbConsInfoFlow;
import cn.ysk.cashier.cons.service.TbConsInfoFlowService;
import cn.ysk.cashier.cons.service.dto.TbConsInfoFlowQueryCriteria;
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-06-22
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "耗材流水管理")
@RequestMapping("/api/tbConsInfoFlow")
public class TbConsInfoFlowController {

    private final TbConsInfoFlowService tbConsInfoFlowService;

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

    @GetMapping
    @ApiOperation("查询耗材流水")
    public ResponseEntity<Object> queryTbConsInfoFlow(TbConsInfoFlowQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(tbConsInfoFlowService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增耗材流水")
    @ApiOperation("新增耗材流水")
    public ResponseEntity<Object> createTbConsInfoFlow(@Validated @RequestBody TbConsInfoFlow resources){
        return new ResponseEntity<>(tbConsInfoFlowService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改耗材流水")
    @ApiOperation("修改耗材流水")
    public ResponseEntity<Object> updateTbConsInfoFlow(@Validated @RequestBody TbConsInfoFlow resources){
        tbConsInfoFlowService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除耗材流水")
    @ApiOperation("删除耗材流水")
    public ResponseEntity<Object> deleteTbConsInfoFlow(@RequestBody Integer[] ids) {
        tbConsInfoFlowService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}