package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.ViewHandover;
import cn.ysk.cashier.cons.service.ViewHandoverService;
import cn.ysk.cashier.cons.service.dto.ViewHandoverQueryCriteria;
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-08-05
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "交班查询管理")
@RequestMapping("/api/tbHandover")
public class ViewHandoverController {

    private final ViewHandoverService viewHandoverService;

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

    @GetMapping
    @ApiOperation("查询交班查询")
    public ResponseEntity<Object> queryViewHandover(ViewHandoverQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(viewHandoverService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增交班查询")
    @ApiOperation("新增交班查询")
    public ResponseEntity<Object> createViewHandover(@Validated @RequestBody ViewHandover resources){
        return new ResponseEntity<>(viewHandoverService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改交班查询")
    @ApiOperation("修改交班查询")
    public ResponseEntity<Object> updateViewHandover(@Validated @RequestBody ViewHandover resources){
        viewHandoverService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除交班查询")
    @ApiOperation("删除交班查询")
    public ResponseEntity<Object> deleteViewHandover(@RequestBody Integer[] ids) {
        viewHandoverService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}