package cn.iocoder.yudao.module.visit.dal.mysql.info;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.visit.dal.dataobject.info.InfoDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.visit.controller.admin.info.vo.*;

/**
 * 客户拜访记录 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface InfoMapper extends BaseMapperX<InfoDO> {

    default PageResult<InfoDO> selectPage(InfoPageReqVO reqVO) {
        Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
        return selectPage(reqVO, new LambdaQueryWrapperX<InfoDO>()
                .likeIfPresent(InfoDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(InfoDO::getContact, reqVO.getContact())
                .likeIfPresent(InfoDO::getCompanyName, reqVO.getCompanyName())
                .betweenIfPresent(InfoDO::getVisitDate, reqVO.getVisitDate())
                .eqIfPresent(InfoDO::getCustomerStatus, reqVO.getCustomerStatus())
                .eqIfPresent(InfoDO::getVisitProductIds, reqVO.getVisitProductIds())
                .eqIfPresent(InfoDO::getVisitMethod, reqVO.getVisitMethod())
                .eqIfPresent(InfoDO::getVisitType, reqVO.getVisitType())
                .eqIfPresent(InfoDO::getCompanyId,companyId)
                .betweenIfPresent(InfoDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(InfoDO::getCreator,reqVO.getCreator())
                .orderByDesc(InfoDO::getVisitDate));
    }
    default PageResult<InfoDO> selectHomePage(InfoPageReqVO reqVO) {
        Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
        return selectPage(reqVO, new LambdaQueryWrapperX<InfoDO>()
                .eqIfPresent(InfoDO::getCustomerName, reqVO.getCustomerName())
                .eqIfPresent(InfoDO::getContact, reqVO.getContact())
                .eqIfPresent(InfoDO::getCompanyName, reqVO.getCompanyName())
                .betweenIfPresent(InfoDO::getVisitDate, reqVO.getVisitDate())
                .eqIfPresent(InfoDO::getCustomerStatus, reqVO.getCustomerStatus())
                .eqIfPresent(InfoDO::getVisitProductIds, reqVO.getVisitProductIds())
                .eqIfPresent(InfoDO::getVisitMethod, reqVO.getVisitMethod())
                .eqIfPresent(InfoDO::getVisitType, reqVO.getVisitType())
                .eqIfPresent(InfoDO::getCompanyId,companyId)
                .betweenIfPresent(InfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InfoDO::getId));
    }

    default List<InfoDO> selectByCompanyName(String companyName) {
        Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
        return selectList(new LambdaQueryWrapperX<InfoDO>()
                .eqIfPresent(InfoDO::getCompanyId,companyId)
                .eq(InfoDO::getCompanyName, companyName));
    }
}