package org.nl.acs.produceshiftorderdetail.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.produceshiftorderdetail.domain.Produceshiftorderdetail;
import org.nl.acs.produceshiftorderdetail.service.ProduceshiftorderdetailService;
import org.nl.acs.produceshiftorderdetail.service.dto.ProduceshiftorderdetailDto;
import org.nl.acs.produceshiftorderdetail.service.dto.ProduceshiftorderdetailQueryParam;
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/produceshiftorderdetail")
public class ProduceshiftorderdetailController {

    private final ProduceshiftorderdetailService produceshiftorderdetailService;

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

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

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

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

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

}
