package com.yc.ship.module.trade.controller.admin.report;

import com.yc.ship.framework.apilog.core.annotation.ApiAccessLog;
import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.module.trade.controller.admin.report.vo.*;
import com.yc.ship.module.trade.service.report.VoyageStockBoardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static com.yc.ship.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.yc.ship.framework.common.pojo.CommonResult.success;

/**
 * 航次库存看板 Controller
 */
@Tag(name = "管理后台 - 航次库存看板")
@RestController
@RequestMapping("/report/kanbanBoard")
@Validated
@Slf4j
public class KanbanBoardController {

    @Resource
    private VoyageStockBoardService voyageStockBoardService;

    /**
     * 查询航次库存看板分页
     *
     * @param pageReqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/voyageStockBoard/page")
    @Operation(summary = "查询航次库存看板分页")
    public CommonResult<PageResult<VoyageStockBoardRespVO>> getVoyageStockBoardPage(@Valid VoyageStockBoardReqVO pageReqVO) {
        PageResult<VoyageStockBoardRespVO> pageResult = voyageStockBoardService.getVoyageStockBoardPage(pageReqVO);
        return success(pageResult);
    }

    /**
     * 导出航次库存看板 Excel
     *
     * @param pageReqVO 查询条件
     * @param response  HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/voyageStockBoard/export-excel")
    @Operation(summary = "导出航次库存看板 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportVoyageStockBoardExcel(@Valid VoyageStockBoardReqVO pageReqVO,
                                             HttpServletResponse response) throws IOException {
        voyageStockBoardService.exportVoyageStockBoardExcel(pageReqVO, response);
    }


    /**
     * 查询全航次库存看板表头信息
     *
     * @param reqVO 查询条件
     * @return
     */
    @GetMapping("/allVoyageStockBoard/tableHead")
    @Operation(summary = "查询全航次库存看板表头信息")
    public CommonResult<List<AllVoyageStockBoardTableHeadRespVO>> getAllVoyageStockBoardTableHead(@Valid AllVoyageStockBoardReqVO reqVO) {
        List<AllVoyageStockBoardTableHeadRespVO> list = voyageStockBoardService.getAllVoyageStockBoardTableHead(reqVO);
        return success(list);
    }


    /**
     * 查询全航次库存看板分页信息
     *
     * @param reqVO 分页查询条件
     * @return 分页结果
     */
    @GetMapping("/allVoyageStockBoard/page")
    @Operation(summary = "查询全航次库存看板分页信息")
    public CommonResult<PageResult<AllVoyageStockBoardRespVO>> getAllVoyageStockBoardPage(@Valid AllVoyageStockBoardReqVO reqVO) {
        PageResult<AllVoyageStockBoardRespVO> page = voyageStockBoardService.getAllVoyageStockBoardPage(reqVO);
        return success(page);
    }

    /**
     * 查询客源地分析看板数据
     *
     * @param reqVO 查询条件
     * @return 客源地分析看板数据
     */
    @GetMapping("/visitorSourceDashboard")
    @Operation(summary = "查询客源地分析看板数据")
    public CommonResult<VisitorSourceDashboardRespVO> getVisitorSourceDashboard(@Valid VisitorSourceDashboardReqVO reqVO) {
        VisitorSourceDashboardRespVO respVO = voyageStockBoardService.getVisitorSourceDashboard(reqVO);
        return success(respVO);
    }

    /**
     * 导出客源地分析看板 Excel
     *
     * @param reqVO    查询条件
     * @param response HTTP响应
     * @throws IOException IO异常
     */
    @GetMapping("/visitorSourceDashboard/export-excel")
    @Operation(summary = "导出客源地分析看板 Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportVisitorSourceDashboardExcel(@Valid VisitorSourceDashboardReqVO reqVO,
                                                   HttpServletResponse response) throws IOException {
        voyageStockBoardService.exportVisitorSourceDashboardExcel(reqVO, response);
    }

}
