package com.ltgk.port.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ltgk.common.core.controller.BaseController;
import com.ltgk.common.core.domain.AjaxResult;
import com.ltgk.common.core.page.TableDataInfo;
import com.ltgk.port.domain.dto.GetInPortListReq;
import com.ltgk.port.domain.dto.GetOutEnterPortListReq;
import com.ltgk.port.domain.dto.GetOutEnterPortSortReq;
import com.ltgk.port.domain.dto.GetOutPortListReq;
import com.ltgk.port.domain.vo.BoatEnterOutVo;
import com.ltgk.port.domain.vo.BoatNavigateStatusVo;
import com.ltgk.port.domain.vo.EnterOutVo;
import com.ltgk.port.domain.vo.PortStatisticsVo;
import com.ltgk.port.service.PortStatisticsService;
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.validation.annotation.Validated;
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.validation.Valid;
import java.util.List;

/**
 * @Author: wan kun
 * @Description: 大屏一张图  渔港统计
 * @Date: 2025/1/16 15:07
 * @Version: 1.0
 */
@Api(value = "大屏一张图  渔港统计")
@RestController
@Validated
@RequestMapping("/portStatistics")
@Slf4j
public class PortStatisticsController extends BaseController {
    @Autowired
    private PortStatisticsService portStatisticsService;

    /**
     * 渔港统计
     *
     * @return {@link PortStatisticsVo}
     */
    @PostMapping("/getPortStatistics")
    @ApiOperation(value = "渔港统计")
    public AjaxResult getPortStatistics() {
        return portStatisticsService.getPortStatistics();
    }

    /**
     * 各渔港渔船进出港排名
     *
     * @param getOutEnterPortSortReq
     * @return {@link List<EnterOutVo>}
     */
    @PostMapping("/getOutEnterPortSort")
    @ApiOperation(value = "各渔港渔船进出港排名")
    public AjaxResult getOutEnterPortSort(@RequestBody @Valid GetOutEnterPortSortReq getOutEnterPortSortReq) {
        return AjaxResult.success(portStatisticsService.getOutEnterPortSort(getOutEnterPortSortReq));
    }

    /**
     * 24小时进出港列表
     *
     * @param getOutEnterPortListReq
     * @return {@link List<BoatEnterOutVo>}
     */
    @PostMapping("/getOutEnterPortList")
    @ApiOperation(value = "24小时进出港列表")
    public TableDataInfo getOutEnterPortList(@RequestBody @Valid GetOutEnterPortListReq getOutEnterPortListReq) {
        return getDataTable(portStatisticsService.getOutEnterPortList(getOutEnterPortListReq));
    }

    /**
     * 获取在港渔船列表
     *
     * @param getInPortListReq
     * @return {@link List<BoatNavigateStatusVo>}
     */
    @PostMapping("/getInPortList")
    @ApiOperation(value = "获取在港渔船列表")
    public TableDataInfo getInPortList(@RequestBody @Valid GetInPortListReq getInPortListReq) {
        List<BoatNavigateStatusVo> inPortList = portStatisticsService.getInPortList(getInPortListReq);
        if (CollectionUtils.isEmpty(inPortList)) {
            return getDataTable(inPortList);
        } else {
            TableDataInfo dataTable = getDataTable(inPortList);
            int size = 0;
            if (dataTable.getData().size() > getInPortListReq.getPageSize() + ((getInPortListReq.getPageNum() - 1) * getInPortListReq.getPageSize())) {
                size = getInPortListReq.getPageSize() + ((getInPortListReq.getPageNum() - 1) * getInPortListReq.getPageSize());
            } else {
                size = dataTable.getData().size();
            }
            dataTable.setRows(dataTable.getData().subList(
                    ((getInPortListReq.getPageNum() - 1) * getInPortListReq.getPageSize()), size)
            );
            return dataTable;
        }

    }

    /**
     * 获取外出作业船只
     *
     * @param getOutPortListReq
     * @return {@link List<BoatNavigateStatusVo>}
     */
    @PostMapping("/getOutPortList")
    @ApiOperation(value = "获取外出作业船只")
    public TableDataInfo getOutPortList(@RequestBody @Valid GetOutPortListReq getOutPortListReq) {
        List<BoatNavigateStatusVo> outPortList = portStatisticsService.getOutPortList(getOutPortListReq);
        if (CollectionUtils.isEmpty(outPortList)) {
            return getDataTable(outPortList);
        } else {
            TableDataInfo dataTable = getDataTable(outPortList);
            int size = 0;
            if (dataTable.getData().size() > getOutPortListReq.getPageSize() + ((getOutPortListReq.getPageNum() - 1) * getOutPortListReq.getPageSize())) {
                size = getOutPortListReq.getPageSize() + ((getOutPortListReq.getPageNum() - 1) * getOutPortListReq.getPageSize());
            } else {
                size = dataTable.getData().size();
            }
            dataTable.setRows(dataTable.getData().subList(
                    ((getOutPortListReq.getPageNum() - 1) * getOutPortListReq.getPageSize()), size)
            );
            return dataTable;
        }

    }
}
