package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.TbConCheck;
import cn.ysk.cashier.cons.service.TbConCheckService;
import cn.ysk.cashier.cons.service.dto.TbConCheckQueryCriteria;
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-06
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "盘点耗材管理")
@RequestMapping("/api/tbConCheck")
public class TbConCheckController {

    private final TbConCheckService tbConCheckService;

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

    @GetMapping
    @ApiOperation("查询盘点耗材")
    public ResponseEntity<Object> queryTbConCheck(TbConCheckQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(tbConCheckService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增盘点耗材")
    @ApiOperation("新增盘点耗材")
    public ResponseEntity<Object> createTbConCheck(@Validated @RequestBody TbConCheck resources) throws Exception {
        return new ResponseEntity<>(tbConCheckService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改盘点耗材")
    @ApiOperation("修改盘点耗材")
    public ResponseEntity<Object> updateTbConCheck(@Validated @RequestBody TbConCheck resources){
        tbConCheckService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除盘点耗材")
    @ApiOperation("删除盘点耗材")
    public ResponseEntity<Object> deleteTbConCheck(@RequestBody Integer[] ids) {
        tbConCheckService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}