package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.ViewConInfoFlow;
import cn.ysk.cashier.cons.service.ViewConInfoFlowService;
import cn.ysk.cashier.cons.service.dto.ViewConInfoFlowQueryCriteria;
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-17
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "获取耗材流水信息管理")
@RequestMapping("/api/viewConInfoFlow")
public class ViewConInfoFlowController {

    private final ViewConInfoFlowService viewConInfoFlowService;

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

    @GetMapping
    @ApiOperation("查询获取耗材流水信息")
    public ResponseEntity<Object> queryViewConInfoFlow(ViewConInfoFlowQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(viewConInfoFlowService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增获取耗材流水信息")
    @ApiOperation("新增获取耗材流水信息")
    public ResponseEntity<Object> createViewConInfoFlow(@Validated @RequestBody ViewConInfoFlow resources){
        return new ResponseEntity<>(viewConInfoFlowService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改获取耗材流水信息")
    @ApiOperation("修改获取耗材流水信息")
    public ResponseEntity<Object> updateViewConInfoFlow(@Validated @RequestBody ViewConInfoFlow resources){
        viewConInfoFlowService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

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