package org.agt.module.license.dal.mysql.license;

import org.agt.framework.common.pojo.PageResult;
import org.agt.framework.mybatis.core.mapper.BaseMapperX;
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.agt.module.license.controller.admin.license.vo.LicensePageReqVO;
import org.agt.module.license.dal.dataobject.license.LicenseDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * License Mapper
 *
 * @author 管理员
 */
@Mapper
public interface LicenseMapper extends BaseMapperX<LicenseDO> {

    default PageResult<LicenseDO> selectPage(LicensePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LicenseDO>()
                .eqIfPresent(LicenseDO::getCustomerId, reqVO.getCustomerId())
                .eqIfPresent(LicenseDO::getProjectId, reqVO.getProjectId())
                .likeIfPresent(LicenseDO::getSerialNo, reqVO.getSerialNo())
                .betweenIfPresent(LicenseDO::getExpiryDate, reqVO.getExpiryDate())
                .eqIfPresent(LicenseDO::getUserNumber, reqVO.getUserNumber())
                .eqIfPresent(LicenseDO::getRanNumber, reqVO.getRanNumber())
                .eqIfPresent(LicenseDO::getApplicant, reqVO.getApplicant())
                .eqIfPresent(LicenseDO::getApprover, reqVO.getApprover())
                .eqIfPresent(LicenseDO::getStatus, reqVO.getStatus())
                .eqIfPresent(LicenseDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(LicenseDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LicenseDO::getId));
    }

    default LicenseDO selectBySn(String sn) {
        return selectOne(LicenseDO::getSerialNo, sn);
    }
}