package com.zt.plat.module.base.dal.mysql.base;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.api.dto.AccountDTO;
import com.zt.plat.module.base.controller.admin.base.vo.AccountPageReqVO;
import com.zt.plat.module.base.dal.dataobject.base.AccountDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 账户条款 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface AccountMapper extends BaseMapperX<AccountDO> {

    default PageResult<AccountDO> selectPage(AccountPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AccountDO>()
                .eqIfPresent(AccountDO::getType, reqVO.getType())
                .likeIfPresent(AccountDO::getAccountName, reqVO.getAccountName())
                .likeIfPresent(AccountDO::getAddress, reqVO.getAddress())
                .likeIfPresent(AccountDO::getPhone, reqVO.getPhone())
                .eqIfPresent(AccountDO::getBankAccount, reqVO.getBankAccount())
                .likeIfPresent(AccountDO::getCustomerName, reqVO.getCustomerName())
                .likeIfPresent(AccountDO::getCustomerNumber, reqVO.getCustomerNumber())
                .eqIfPresent(AccountDO::getIsEnable, reqVO.getIsEnable())
                .likeIfPresent(AccountDO::getAccountNumber, reqVO.getAccountNumber())
                .likeIfPresent(AccountDO::getTaxNumber, reqVO.getTaxNumber())
                .betweenIfPresent(AccountDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AccountDO::getId));
    }

    default List<AccountDO> selectNoPage(AccountDTO dto){
        return selectList(new LambdaQueryWrapperX<AccountDO>()
                .eqIfPresent(AccountDO::getType, dto.getType())
                .likeIfPresent(AccountDO::getAccountName, dto.getAccountName())
                .likeIfPresent(AccountDO::getAddress, dto.getAddress())
                .likeIfPresent(AccountDO::getPhone, dto.getPhone())
                .eqIfPresent(AccountDO::getBankAccount, dto.getBankAccount())
                .likeIfPresent(AccountDO::getCustomerName, dto.getCustomerName())
                .likeIfPresent(AccountDO::getCustomerNumber, dto.getCustomerNumber())
                .eqIfPresent(AccountDO::getIsEnable, dto.getIsEnable())
                .likeIfPresent(AccountDO::getAccountNumber, dto.getAccountNumber())
                .likeIfPresent(AccountDO::getTaxNumber, dto.getTaxNumber())
                .orderByDesc(AccountDO::getId));
    }
}