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

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.crmrecord.vo.CrmRecordPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.crmrecord.vo.RecordStatisticsRespVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.crmrecord.CrmRecordDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 跟进记录 Mapper
 *
 * @author yshop
 */
@Mapper
public interface CrmRecordMapper extends BaseMapperX<CrmRecordDO> {

    default PageResult<CrmRecordDO> selectPage(CrmRecordPageReqVO reqVO, List<Long> ids) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CrmRecordDO>()
                .eqIfPresent(CrmRecordDO::getTypes, reqVO.getTypes())
                .eqIfPresent(CrmRecordDO::getTypesId, reqVO.getTypesId())
                .eqIfPresent(CrmRecordDO::getContent, reqVO.getContent())
                .eqIfPresent(CrmRecordDO::getRecordType, reqVO.getRecordType())
                .betweenIfPresent(CrmRecordDO::getNextTime, reqVO.getNextTime())
                .inIfPresent(CrmRecordDO::getCreator,ids)
                .orderByDesc(CrmRecordDO::getId));
    }



    List<RecordStatisticsRespVO> selectStatistics(@Param("userIds") List<Long> userIds, @Param("createTime") LocalDateTime[] createTime);

}
