package org.nl.acs.produceshiftorder.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.produceshiftorder.domain.Produceshiftorder;
import org.nl.acs.produceshiftorder.service.ProduceshiftorderService;
import org.nl.acs.produceshiftorder.service.dto.ProduceshiftorderDto;
import org.nl.acs.produceshiftorder.service.dto.ProduceshiftorderQueryParam;
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.util.Set;

/**
* @author jiaolm
* @date 2023-05-09
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工单管理")
@RequestMapping("/api/produceshiftorder")
public class ProduceshiftorderController {

    private final ProduceshiftorderService produceshiftorderService;

    @GetMapping
    @Log("查询工单")
    @ApiOperation("查询工单")
    //@PreAuthorize("@el.check('produceshiftorder:list')")
    public ResponseEntity query(ProduceshiftorderQueryParam query, Pageable pageable){
        return new ResponseEntity<>(produceshiftorderService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工单")
    @ApiOperation("新增工单")
    //@PreAuthorize("@el.check('produceshiftorder:add')")
    public ResponseEntity create(@Validated @RequestBody ProduceshiftorderDto resources){
        return new ResponseEntity<>(produceshiftorderService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工单")
    @ApiOperation("修改工单")
    //@PreAuthorize("@el.check('produceshiftorder:edit')")
    public ResponseEntity update(@Validated @RequestBody ProduceshiftorderDto resources){
        produceshiftorderService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工单")
    @ApiOperation("删除工单")
    //@PreAuthorize("@el.check('produceshiftorder:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        produceshiftorderService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出工单")
    @ApiOperation("导出工单")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('produceshiftorder:list')")
    public void download(HttpServletResponse response, ProduceshiftorderQueryParam query) throws IOException {
        produceshiftorderService.download(produceshiftorderService.queryAll(query), response);
    }*/

}
