package com.yc.ship.module.otc.dal.mysql.storeaudit;

import com.baomidou.mybatisplus.core.metadata.IPage;
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.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.otc.controller.admin.storeaudit.vo.StoreAuditPageReqVO;
import com.yc.ship.module.otc.controller.admin.storeaudit.vo.StoreAuditRespVO;
import com.yc.ship.module.otc.dal.dataobject.storeaudit.StoreAuditDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 旅行社门店授信提额/授信充值/余额充值 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface StoreAuditMapper extends BaseMapperX<StoreAuditDO> {

    default PageResult<StoreAuditDO> selectPage(StoreAuditPageReqVO reqVO) {
        String menuType = reqVO.getType();
        String type = "";
        if (StringUtils.isNotBlank(menuType)) {
            String[] menuTypes = menuType.split("-");
            try {
                reqVO.setOperateType(Integer.parseInt(menuTypes[0]));
                type = menuTypes[1];
            }catch (Exception ignored){

            }

        }
        LambdaQueryWrapperX<StoreAuditDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eqIfPresent(StoreAuditDO::getStoreId, reqVO.getStoreId());
        queryWrapperX.eqIfPresent(StoreAuditDO::getOperateType, reqVO.getOperateType());
        queryWrapperX.eqIfPresent(StoreAuditDO::getAmount, reqVO.getAmount());
        queryWrapperX.eqIfPresent(StoreAuditDO::getApplyUser, reqVO.getApplyUser());
        queryWrapperX.likeIfPresent(StoreAuditDO::getApplyUserName, reqVO.getApplyUserName());
        queryWrapperX.betweenIfPresent(StoreAuditDO::getApplyTime, reqVO.getApplyTime());
        if (StringUtils.equals("1", type)) {
            queryWrapperX.eqIfPresent(StoreAuditDO::getStatus, 0);
        }
        if (StringUtils.equals("2", type)) {
            queryWrapperX.inIfPresent(StoreAuditDO::getStatus, 1, 2);
        }
        queryWrapperX.eqIfPresent(StoreAuditDO::getStatus, reqVO.getStatus());
        queryWrapperX.eqIfPresent(StoreAuditDO::getAuditUser, reqVO.getAuditUser());
        queryWrapperX.likeIfPresent(StoreAuditDO::getAuditUserName, reqVO.getAuditUserName());
        queryWrapperX.betweenIfPresent(StoreAuditDO::getAuditTime, reqVO.getAuditTime());
        queryWrapperX.eqIfPresent(StoreAuditDO::getApplyRemark, reqVO.getApplyRemark());
        queryWrapperX.eqIfPresent(StoreAuditDO::getAuditRemark, reqVO.getAuditRemark());
        queryWrapperX.eqIfPresent(StoreAuditDO::getRechargeLogId, reqVO.getRechargeLogId());
        queryWrapperX.eqIfPresent(StoreAuditDO::getFileUrl, reqVO.getFileUrl());
        queryWrapperX.betweenIfPresent(StoreAuditDO::getCreateTime, reqVO.getCreateTime());
        queryWrapperX.eqIfPresent(StoreAuditDO::getPlatTenantId, reqVO.getPlatTenantId());
        queryWrapperX.orderByDesc(StoreAuditDO::getId);
        return selectPage(reqVO, queryWrapperX);
    }

    @TenantIgnore
    IPage<StoreAuditRespVO> selectStoreAuditByPage(IPage<StoreAuditRespVO> page, @Param("vo") StoreAuditPageReqVO reqVO);
}
