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

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.erp.controller.admin.erp.vo.ErpCustomerPageReqVO;
import com.zt.plat.module.erp.dal.dataobject.erp.ErpCustomerDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * ERP客商主数据 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ErpCustomerMapper extends BaseMapperX<ErpCustomerDO> {

    default PageResult<ErpCustomerDO> selectPage(ErpCustomerPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ErpCustomerDO>()
                .likeIfPresent(ErpCustomerDO::getNumber, reqVO.getNumber())
                .likeIfPresent(ErpCustomerDO::getName, reqVO.getName())
                .eqIfPresent(ErpCustomerDO::getAccountGroup, reqVO.getAccountGroup())
                .likeIfPresent(ErpCustomerDO::getDescription, reqVO.getDescription())
                .eqIfPresent(ErpCustomerDO::getCenterNumber, reqVO.getCenterNumber())
                .betweenIfPresent(ErpCustomerDO::getCreateDate, reqVO.getCreateDate())
                .betweenIfPresent(ErpCustomerDO::getRepairDate, reqVO.getRepairDate())
                .eqIfPresent(ErpCustomerDO::getIsGiveback, reqVO.getIsGiveback())
                .eqIfPresent(ErpCustomerDO::getIsProvisional, reqVO.getIsProvisional())
                .orderByDesc(ErpCustomerDO::getId));
    }

    void updateBatchByNumber(@Param("toUpdate")  List<ErpCustomerDO> toUpdate);
}