package cn.iocoder.yudao.module.crm.dal.mysql.crmachievement;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.crmachievement.vo.DeptAchieveSaveVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.crmachievement.CrmAchievementDO;
import cn.iocoder.yudao.module.crm.controller.admin.crmachievement.vo.CrmAchievementPageReqVO;
import cn.iocoder.yudao.module.hrm.enums.FlowStepEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 业绩目标 Mapper
 *
 * @author yshop
 */
@Mapper
public interface CrmAchievementMapper extends BaseMapperX<CrmAchievementDO> {

    default PageResult<CrmAchievementDO> selectPage(CrmAchievementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CrmAchievementDO>()
                .likeIfPresent(CrmAchievementDO::getName, reqVO.getName())
                .eqIfPresent(CrmAchievementDO::getConfig, reqVO.getConfig())
                .eqIfPresent(CrmAchievementDO::getType, reqVO.getType())
                .eqIfPresent(CrmAchievementDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(CrmAchievementDO::getYear, reqVO.getYear())
                .eqIfPresent(CrmAchievementDO::getJanuary, reqVO.getJanuary())
                .eqIfPresent(CrmAchievementDO::getFebruary, reqVO.getFebruary())
                .eqIfPresent(CrmAchievementDO::getMarch, reqVO.getMarch())
                .eqIfPresent(CrmAchievementDO::getApril, reqVO.getApril())
                .eqIfPresent(CrmAchievementDO::getMay, reqVO.getMay())
                .eqIfPresent(CrmAchievementDO::getJune, reqVO.getJune())
                .eqIfPresent(CrmAchievementDO::getJuly, reqVO.getJuly())
                .eqIfPresent(CrmAchievementDO::getAugust, reqVO.getAugust())
                .eqIfPresent(CrmAchievementDO::getSeptember, reqVO.getSeptember())
                .eqIfPresent(CrmAchievementDO::getOctober, reqVO.getOctober())
                .eqIfPresent(CrmAchievementDO::getNovember, reqVO.getNovember())
                .eqIfPresent(CrmAchievementDO::getDecember, reqVO.getDecember())
                .eqIfPresent(CrmAchievementDO::getYeartarget, reqVO.getYeartarget())
                .betweenIfPresent(CrmAchievementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CrmAchievementDO::getId));
    }

    default List<CrmAchievementDO> selectAchievementList(Integer type, Integer year, List<Long> typeIds) {

        return selectList(new LambdaQueryWrapper<CrmAchievementDO>()
                .eq(CrmAchievementDO::getType, FlowStepEnum.TYPE_3.getValue())
                .eq(CrmAchievementDO::getConfig, type)
                .in(CrmAchievementDO::getTypeId, typeIds)
                .eq(CrmAchievementDO::getYear, year));
    }

    default List<CrmAchievementDO> selectAchievementList(DeptAchieveSaveVO createReqVO, List<Long> typeIds) {

        return selectList(new LambdaQueryWrapperX<CrmAchievementDO>()
                .eq(CrmAchievementDO::getType, createReqVO.getAchievementRespVO().getType())
                .eq(CrmAchievementDO::getConfig, createReqVO.getAchievementRespVO().getConfig())
                .eq(CrmAchievementDO::getYear, createReqVO.getAchievementRespVO().getYear())
                .inIfPresent(CrmAchievementDO::getTypeId, typeIds));
    }
}
