package com.app.controller.admin;

import com.app.dto.PageResult;
import com.app.dto.Result;
import com.app.dto.order.OpenCourseOrderDto;
import com.app.dto.order.operation.ExportOrderDto;
import com.app.dto.order.search.SearchAdminOpenCourseOrderDto;
import com.app.service.order.OpenCourseOrderExportService;
import com.app.service.order.OpenCourseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Api(description = "订单")
@Slf4j
@RestController("AdminOpenCourseOrderController")
@RequestMapping("/admin/order")
public class OpenCourseOrderController {

    @Autowired
    private OpenCourseOrderService openCourseOrderService;

    @Autowired
    private OpenCourseOrderExportService openCourseOrderExportService;

    /**
     * 功能描述：查询所有[订单]
     *
     * @param params 查询对象
     * @return
     */
    @ApiOperation(value = "查询所有[订单]")
    @PostMapping("/page")
    public ResponseEntity<Result<PageResult<OpenCourseOrderDto>>> page(@Valid @RequestBody SearchAdminOpenCourseOrderDto params) {
        return new ResponseEntity(new Result().ok(openCourseOrderService.page(params)), HttpStatus.OK);
    }

    @ApiOperation(value = "导出[订单]")
    @PostMapping("/export-excel")
    public void exportExcel(@Valid @RequestBody ExportOrderDto params, HttpServletRequest request, HttpServletResponse response) throws Exception {
        openCourseOrderExportService.exportOrderExcel(params, request, response);
    }

}
