package org.nl.acs.task.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.acs.task.service.TaskFeedbackService;
import org.nl.acs.task.service.dto.TaskFeedbackDto;
import org.nl.acs.task.service.dto.TaskFeedbackQueryParam;
import org.nl.common.logging.annotation.Log;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

/**
* @author jiaolm
* @date 2023-05-09
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "任务反馈管理")
@RequestMapping("/api/taskFeedback")
public class TaskFeedbackController {

    private final TaskFeedbackService taskFeedbackService;

    @GetMapping
    @Log("查询任务反馈")
    @ApiOperation("查询任务反馈")
    //@PreAuthorize("@el.check('taskFeedback:list')")
    public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
        return new ResponseEntity<>(taskFeedbackService.queryAll(whereJson, page), HttpStatus.OK);
    }

    @Log("导出任务反馈")
    @ApiOperation("导出任务反馈")
    @GetMapping(value = "/download")
    //@PreAuthorize("@el.check('taskFeedback:list')")
    public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException {
        taskFeedbackService.download(taskFeedbackService.queryAll(whereJson), response);
    }

    @Log("重置任务反馈")
    @ApiOperation("重置任务反馈")
    @PostMapping(value = "/retry/{id}")
    public ResponseEntity<Object> retry(@RequestBody String id) {
        taskFeedbackService.retry(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log("作废任务反馈")
    @ApiOperation("作废任务反馈")
    @PostMapping(value = "/invalid/{id}")
    public ResponseEntity<Object> invalid(@RequestBody String id) {
        taskFeedbackService.invalid(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
