package com.yc.ship.module.trade.dal.mysql.tradeOrderaudit;

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.trade.controller.admin.tradeOrderaudit.vo.TradeOrderAuditPageReqVO;
import com.yc.ship.module.trade.dal.dataobject.tradeOrderaudit.TradeOrderAuditDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 订单审核记录 Mapper
 *
 * @author qsl
 */
@Mapper
public interface TradeOrderAuditMapper extends BaseMapperX<TradeOrderAuditDO> {

    default PageResult<TradeOrderAuditDO> selectPage(TradeOrderAuditPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TradeOrderAuditDO>()
                .eqIfPresent(TradeOrderAuditDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(TradeOrderAuditDO::getType, reqVO.getType())
                .eqIfPresent(TradeOrderAuditDO::getAuditUser, reqVO.getAuditUser())
                .betweenIfPresent(TradeOrderAuditDO::getAuditTime, reqVO.getAuditTime())
                .eqIfPresent(TradeOrderAuditDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(TradeOrderAuditDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(TradeOrderAuditDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TradeOrderAuditDO::getId));
    }

    default TradeOrderAuditDO selectNewAuditorByOrderNo(String orderNo) {
        return selectOne(new LambdaQueryWrapperX<TradeOrderAuditDO>()
                .eq(TradeOrderAuditDO::getOrderNo, orderNo)
                .eq(TradeOrderAuditDO::getAuditStatus, 1)
                .orderByDesc(TradeOrderAuditDO::getCreateTime)
                .last("LIMIT 1"));
    }

    default List<TradeOrderAuditDO> selectNewAuditorByOrderId(Long orderId, Integer auditType) {
        return selectList(new LambdaQueryWrapperX<TradeOrderAuditDO>()
                .eq(TradeOrderAuditDO::getOrderId, orderId)
                .eq(TradeOrderAuditDO::getAuditType, auditType)
                .orderByDesc(TradeOrderAuditDO::getCreateTime));
    }
}