package com.yc.ship.module.ota.dal.mysql.distributoraudit;

import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.ota.controller.admin.distributoraudit.vo.DistributorAuditPageReqVO;
import com.yc.ship.module.ota.dal.dataobject.distributoraudit.DistributorAuditDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

/**
 * 分销商授信提额/授信充值/余额充值 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface DistributorAuditMapper extends BaseMapperX<DistributorAuditDO> {

    default PageResult<DistributorAuditDO> selectPage(DistributorAuditPageReqVO reqVO) {
        String menuType = reqVO.getType();
        String type = "";
        if (StringUtils.isNotBlank(menuType)) {
            String[] menuTypes = menuType.split("-");
            reqVO.setOperateType(Integer.valueOf(menuTypes[0]));
            type = menuTypes[1];
        }
        LambdaQueryWrapperX<DistributorAuditDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eqIfPresent(DistributorAuditDO::getDistributorId, reqVO.getDistributorId());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getOperateType, reqVO.getOperateType());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getOperateMode, reqVO.getOperateMode());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getAmount, reqVO.getAmount());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getApplyUser, reqVO.getApplyUser());
        queryWrapperX.likeIfPresent(DistributorAuditDO::getApplyUserName, reqVO.getApplyUserName());
        queryWrapperX.betweenIfPresent(DistributorAuditDO::getApplyTime, reqVO.getApplyTime());
        if (StringUtils.equals("1", type)) {
            queryWrapperX.eqIfPresent(DistributorAuditDO::getStatus, 0);
        }
        if (StringUtils.equals("2", type)) {
            queryWrapperX.inIfPresent(DistributorAuditDO::getStatus, 1, 2);
        }
        queryWrapperX.eqIfPresent(DistributorAuditDO::getAuditUser, reqVO.getAuditUser());
        queryWrapperX.likeIfPresent(DistributorAuditDO::getAuditUserName, reqVO.getAuditUserName());
        queryWrapperX.betweenIfPresent(DistributorAuditDO::getAuditTime, reqVO.getAuditTime());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getApplyRemark, reqVO.getApplyRemark());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getAuditRemark, reqVO.getAuditRemark());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getSerialNum, reqVO.getSerialNum());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getRechargeLogId, reqVO.getRechargeLogId());
        queryWrapperX.eqIfPresent(DistributorAuditDO::getFileUrl, reqVO.getFileUrl());
        queryWrapperX.betweenIfPresent(DistributorAuditDO::getCreateTime, reqVO.getCreateTime());
        queryWrapperX.orderByDesc(DistributorAuditDO::getId);
        return selectPage(reqVO, queryWrapperX);
    }

}
