package org.nl.acs.log.rest;

import org.nl.common.logging.annotation.Log;
import org.nl.acs.log.service.LogService;
import org.nl.acs.log.service.dto.LogDto;
import org.nl.acs.log.service.dto.LogQueryParam;
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 = "acs日志管理")
@RequestMapping("/api/log")
public class LogController {

    private final LogService logService;

    @GetMapping
    @Log("查询acs日志")
    @ApiOperation("查询acs日志")
    //@PreAuthorize("@el.check('log:list')")
    public ResponseEntity query(LogQueryParam query, Pageable pageable){
        return new ResponseEntity<>(logService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增acs日志")
    @ApiOperation("新增acs日志")
    //@PreAuthorize("@el.check('log:add')")
    public ResponseEntity create(@Validated @RequestBody LogDto resources){
        return new ResponseEntity<>(logService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改acs日志")
    @ApiOperation("修改acs日志")
    //@PreAuthorize("@el.check('log:edit')")
    public ResponseEntity update(@Validated @RequestBody LogDto resources){
        logService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除acs日志")
    @ApiOperation("删除acs日志")
    //@PreAuthorize("@el.check('log:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        logService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出acs日志")
    @ApiOperation("导出acs日志")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('log:list')")
    public void download(HttpServletResponse response, LogQueryParam query) throws IOException {
        logService.download(logService.queryAll(query), response);
    }*/

}
