package com.ruoyi.oa.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.oa.domain.SysOaWarehouse;
import com.ruoyi.oa.domain.dto.SummaryFilterDTO;
import com.ruoyi.oa.domain.vo.SysOaWarehouseVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 仓库管理Mapper接口
 *
 * @author liuzongkun999
 * @date 2024-11-02
 */
public interface SysOaWarehouseMapper extends BaseMapperPlus<SysOaWarehouseMapper, SysOaWarehouse, SysOaWarehouseVo> {

    /**
     *
     * 查询已经被逻辑删除的数据
     * @param warehouseId
     * @return
     */
    SysOaWarehouseVo selectVoByIdAndXml(Long warehouseId);

    Page<SysOaWarehouseVo> selectVoPageThreshold(@Param("page")Page<SysOaWarehouseVo> build,@Param(Constants.WRAPPER) LambdaQueryWrapper<SysOaWarehouse> lqw);

    Page<SysOaWarehouseVo> selectListVoPage(@Param("page")Page<SysOaWarehouseVo> build,@Param(Constants.WRAPPER) QueryWrapper<SysOaWarehouse> lqw);

    /**
     * 数据报表使用接口
     */
    // 快照时点的库存总量
    Long selectInventoryAt(@Param("f") SummaryFilterDTO filter);

    // 区间内的在途物料
    Long selectInTransitBetween(@Param("f") SummaryFilterDTO filter);

    // 某日的入库量
    Long selectInboundOn(@Param("f") SummaryFilterDTO filter);

    // 某日的出库量
    Long selectOutboundOn(@Param("f") SummaryFilterDTO filter);

    // 某日的预警信息
    Integer selectWarningOn(@Param("f") SummaryFilterDTO filter);


    /** 年度入库量按月分组 */
    List<Map<String,Object>> selectInboundByMonth(@Param("year") int year);

    /** 年度出库量按月分组 */
    List<Map<String,Object>> selectOutboundByMonth(@Param("year") int year);

    /** 任意日期的库存快照 */
    Long selectInventorySnapshot(@Param("date") LocalDate date);

}
