/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.dm.printingApproval.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.dm.printingApproval.domain.DmPrintingApproval;
import me.zhengjie.modules.dm.printingApproval.service.DmPrintingApprovalService;
import me.zhengjie.modules.dm.printingApproval.service.dto.DmPrintingApprovalQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
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;

/**
* @website https://el-admin.vip
* @author xwx
* @date 2021-03-17
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "dmPrintingApproval管理")
@RequestMapping("/api/dmPrintingApproval")
public class DmPrintingApprovalController {

    private final DmPrintingApprovalService dmPrintingApprovalService;



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

    @GetMapping
    @Log("查询dmPrintingApproval")
    @ApiOperation("查询dmPrintingApproval")
    @PreAuthorize("@el.check('dmPrintingApproval:list')")
    public ResponseEntity<Object> query(DmPrintingApprovalQueryCriteria criteria, Pageable pageable){

        return new ResponseEntity<>(dmPrintingApprovalService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增dmPrintingApproval")
    @ApiOperation("新增dmPrintingApproval")
    @PreAuthorize("@el.check('dmPrintingApproval:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody DmPrintingApproval resources){
        return new ResponseEntity<>(dmPrintingApprovalService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改dmPrintingApproval")
    @ApiOperation("修改dmPrintingApproval")
    @PreAuthorize("@el.check('dmPrintingApproval:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody DmPrintingApproval resources){
        dmPrintingApprovalService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除dmPrintingApproval")
    @ApiOperation("删除dmPrintingApproval")
    @PreAuthorize("@el.check('dmPrintingApproval:del')")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
        dmPrintingApprovalService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping(value = "/approval")
    @Log("审批文印申请")
    @ApiOperation("审批文印申请")
    public ResponseEntity<Object> Approval(@RequestBody DmPrintingApproval resources){
        dmPrintingApprovalService.approval(resources);
        return new ResponseEntity<>("审批完成",HttpStatus.OK);


    }
}