package me.zhengjie.modules.dm.printingCount.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.dm.printingCount.service.DmPrintingCountService;
import me.zhengjie.modules.dm.printingCount.service.dto.DmPrintingCountQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequiredArgsConstructor
@Api(tags = "dmPrintingCount管理")
@RequestMapping("/api/dmPrintingCount")
public class DmPrintingCountController {
    @Resource
    private final DmPrintingCountService dmPrintingCountService;

    @GetMapping(value = "/selectList")
    @Log("查询选择列表")
    @ApiOperation("查询选择列表")
    public ResponseEntity<Object> selectList(DmPrintingCountQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(dmPrintingCountService.selectList(criteria,pageable), HttpStatus.OK);
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('dmPrintingCount:list')")
    public void download(HttpServletResponse response, DmPrintingCountQueryCriteria criteria) throws IOException {
        dmPrintingCountService.download(dmPrintingCountService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询dmDevice")
    @ApiOperation("查询dmPrintingCount")
    @PreAuthorize("@el.check('dmPrintingCount:list')")
    public ResponseEntity<Object> query(DmPrintingCountQueryCriteria criteria, Pageable pageable){
        //return new ResponseEntity<>(dmPrintingCountService.selectList(criteria,pageable), HttpStatus.OK);
        return new ResponseEntity<>(dmPrintingCountService.queryAll(criteria,pageable),HttpStatus.OK);
    }


//    @PostMapping
//    @Log("新增dmPrintingCount")
//    @ApiOperation("新增dmPrintingCount")
//    @PreAuthorize("@el.check('dmPrintingCount:add')")
//    public ResponseEntity<Object> create(@Validated @RequestBody DmPrintingCount resources){
//        return new ResponseEntity<>(dmPrintingCountService.create(resources),HttpStatus.CREATED);
//    }
//
//    @PutMapping
//    @Log("修改dmPrintingCount")
//    @ApiOperation("修改dmPrintingCount")
//    @PreAuthorize("@el.check('dmPrintingCount:edit')")
//    public ResponseEntity<Object> update(@Validated @RequestBody DmPrintingCount resources){
//        dmPrintingCountService.update(resources);
//        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
//    }
//
//    @Log("删除dmPrintingCount")
//    @ApiOperation("删除dmPrintingCount")
//    @PreAuthorize("@el.check('dmPrintingCount:del')")
//    @DeleteMapping
//    public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
//        dmPrintingCountService.deleteAll(ids);
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
}
