package com.sundot.airport.ledger.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sundot.airport.common.utils.DateUtils;
import com.sundot.airport.ledger.domain.OperationLanePeakThroughput;
import com.sundot.airport.ledger.domain.vo.LaneThroughputReqVO;
import com.sundot.airport.ledger.domain.vo.LaneThroughputResVO;
import com.sundot.airport.ledger.mapper.OperationLanePeakThroughputMapper;
import com.sundot.airport.ledger.service.IOperationLanePeakThroughputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 通道日别高峰时段过检Service业务层处理
 */
@Service
public class OperationLanePeakThroughputServiceImpl extends ServiceImpl<OperationLanePeakThroughputMapper, OperationLanePeakThroughput>
        implements IOperationLanePeakThroughputService {

    @Autowired
    private OperationLanePeakThroughputMapper operationLanePeakThroughputMapper;

    /**
     * 查询通道日别高峰时段过检列表
     *
     * @param operationLanePeakThroughput 通道日别高峰时段过检
     * @return 通道日别高峰时段过检
     */
    @Override
    public List<OperationLanePeakThroughput> selectOperationLanePeakThroughputList(OperationLanePeakThroughput operationLanePeakThroughput) {
        return operationLanePeakThroughputMapper.selectOperationLanePeakThroughputList(operationLanePeakThroughput);
    }

    /**
     * 新增通道日别高峰时段过检
     *
     * @param operationLanePeakThroughput 通道日别高峰时段过检
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertOperationLanePeakThroughput(OperationLanePeakThroughput operationLanePeakThroughput) {
        operationLanePeakThroughput.setCreateTime(DateUtils.getNowDate());
        return operationLanePeakThroughputMapper.insert(operationLanePeakThroughput);
    }

    /**
     * 修改通道日别高峰时段过检
     *
     * @param operationLanePeakThroughput 通道日别高峰时段过检
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateOperationLanePeakThroughput(OperationLanePeakThroughput operationLanePeakThroughput) {
        operationLanePeakThroughput.setUpdateTime(DateUtils.getNowDate());
        return operationLanePeakThroughputMapper.updateById(operationLanePeakThroughput);
    }

    /**
     * 批量删除通道日别高峰时段过检
     *
     * @param ids 需要删除的通道日别高峰时段过检主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteOperationLanePeakThroughputByIds(Long[] ids) {
        return operationLanePeakThroughputMapper.deleteBatchIds(java.util.Arrays.asList(ids));
    }

    /**
     * 删除通道日别高峰时段过检信息
     *
     * @param id 通道日别高峰时段过检主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteOperationLanePeakThroughputById(Long id) {
        return operationLanePeakThroughputMapper.deleteById(id);
    }

    /**
     * 功能描述：统计通道日级别高峰时段过检率
     *
     * @param laneThroughputQuery 筛选条件
     * @return List<LaneThroughputStatsVO>
     * @method countLanePeakThroughput
     * @author PanHu Sun
     * @date 2026/5/19 15:29
     */
    @Override
    public List<LaneThroughputResVO> countLanePeakThroughput(LaneThroughputReqVO laneThroughputQuery) {
        // 核心逻辑：未选择任何筛选条件，返回空数组
        if (Objects.isNull(laneThroughputQuery.getDeptId()) && Objects.isNull(laneThroughputQuery.getTeamId()) && Objects.isNull(laneThroughputQuery.getGroupId())) {
            return Collections.emptyList();
        }
        List<LaneThroughputResVO> laneThroughputResList = this.baseMapper.countLanePeakThroughput(laneThroughputQuery);
        return CollUtil.emptyIfNull(laneThroughputResList);
    }
}
