package com.ruoyi.oa.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
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.SysOaProject;
import com.ruoyi.oa.domain.bo.SysOaProjectBo;
import com.ruoyi.oa.domain.dto.ProjectActivityDTO;
import com.ruoyi.oa.domain.dto.ProjectDataDTO;
import com.ruoyi.oa.domain.vo.*;
import com.ruoyi.common.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 项目管理Mapper接口
 *
 * @author huangxing
 * @date 2024-01-11
 */
public interface SysOaProjectMapper extends BaseMapperPlus<SysOaProjectMapper, SysOaProject, SysOaProjectVo> {

    Page<SysOaOutWarehouseListVo> selectPageOutList(@Param("page") Page<SysOaOutWarehouseListVo> page,@Param(Constants.WRAPPER) Wrapper<SysOaProject> queryWrapper);


    List<SysOaProjectVo> getProjectDataByMonth(@Param("firstDay") Date firstDay, @Param("lastDay") Date lastDay);

    List<SysOaProjectVo> getProjectDataByMonthAndDate(@Param("firstDay") Date firstDay, @Param("lastDay") Date lastDay);



    Page<SysOaCostAllVo> selectListToCost(@Param("page") Page<SysOaProject> page,@Param(Constants.WRAPPER)  QueryWrapper<SysOaProjectBo> queryWrapper);

    Map<String, Object> selectProjectDetails(@Param("projectId") Long projectId);

    Page<SysOaProjectVo> selectVoPlus(@Param("page") Page<SysOaProjectVo> build,@Param(Constants.WRAPPER)  LambdaQueryWrapper<SysOaProject> lqw);

    Page<SysOaProjectVo> selectFileVoList(@Param("page") Page<Object> build, @Param(Constants.WRAPPER)  QueryWrapper<SysOaProject> sysOaProjectQueryWrapper);

    Page<SysOaProjectVo> selectVoAndProgress(@Param("page") Page<Object> build, @Param(Constants.WRAPPER)  LambdaQueryWrapper<SysOaProject> sysOaProjectQueryWrapper);

    /**
     * 外贸进度使用list
     * @param build
     * @param bo
     * @return
     */
    Page<SysOaProjectVo> selectVoListPage(@Param("page") Page<SysOaProjectVo> build,@Param(Constants.WRAPPER) QueryWrapper<SysOaProject> bo);

    Page<SysOaProjectVo> listWareProject(@Param("page") Page<SysOaProjectVo> build,@Param(Constants.WRAPPER) QueryWrapper<SysOaProject> bo);


    SysOaProjectVo selectVoByIdPlus(Long projectId);

    /** 本月合同总额 */
    BigDecimal selectTotalFunds(@Param("start") Date start,
                                @Param("end")   Date end, @Param("tradeType") Long tradeType);

    /** 本月合同数量 */
    Integer selectContractCount(@Param("start") Date start,
                                @Param("end")   Date end, @Param("tradeType") Long tradeType);

    /** 临期项目数量（到期日在 start~end 之间） */
    Integer selectExpiringCount(@Param("start") Date start,
                                @Param("end")   Date end, @Param("tradeType") Long tradeType);

    List<TrendPointVo> selectContractAmountTrend(@Param("start") Date start,
                                                 @Param("end")   Date end, @Param("tradeType") Long tradeType);

    /** 项目状态分布（示例按 finish_time 与 project_status 简单分类） */
    List<StatusCountVo> selectProjectStatusDistribution(@Param("tradeType") Long tradeType);

    /** 月度合同数量对比 */
    List<TrendPointVo> selectMonthlyContractComparison(@Param("start") Date start,
                                                       @Param("end")   Date end, @Param("tradeType") Long tradeType);

    List<SysOaProjectVo> selectExpiringForeignProjects(@Param("now") Date now, @Param("expireDays") Integer expireDays, @Param("tradeType") Long tradeType);

    List<ProjectDataDTO> getProjectData(@Param("month") String month);
    List<ProjectActivityDTO> getProjectActivities();

    BigDecimal selectPrevAvgTotalFunds(@Param("start") Date start, @Param("end") Date end, @Param("tradeType") Long tradeType);

    BigDecimal selectPrevAvgContractCount(@Param("start") Date start, @Param("end") Date end, @Param("tradeType") Long tradeType);

    BigDecimal selectPrevAvgExpiringCount(@Param("start") Date start, @Param("end") Date end, @Param("tradeType") Long tradeType);
}
