package cn.iocoder.yudao.module.order.dal.mysql.orderMutual;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.module.order.dal.dataobject.orderMutual.OrderMutualDO;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.order.vo.orderMutual.*;
import org.apache.ibatis.annotations.Select;

/**
 * 订单互斥 Mapper
 * @author 系统管理员
 */
@Mapper
public interface OrderMutualMapper extends AbstractMapper<OrderMutualDO> {
    @Override
    default PageResult<OrderMutualDO> selectPage(PageVO page, Object object) {
        if (object instanceof OrderMutualQueryVO) {
            OrderMutualQueryVO vo = (OrderMutualQueryVO)object;
            return selectPage(page, new LambdaQuery<OrderMutualDO>()
                .betweenIfPresent(OrderMutualDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                .eqIfPresent(OrderMutualDO::getOrderId, vo.getOrderId())
                .eqIfPresent(OrderMutualDO::getMutualOrderId, vo.getMutualOrderId())
                .betweenIfPresent(OrderMutualDO::getAddTime, vo.getBeginAddTime(), vo.getEndAddTime())
                    .orderByDesc(OrderMutualDO::getId));
        }

        return null;
    }

    @Override
    default List<OrderMutualDO> selectList(Object object) {
        if (object instanceof OrderMutualQueryVO) {
            OrderMutualQueryVO vo = (OrderMutualQueryVO)object;
            return selectList(new LambdaQuery<OrderMutualDO>()
                .betweenIfPresent(OrderMutualDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                .eqIfPresent(OrderMutualDO::getOrderId, vo.getOrderId())
                .eqIfPresent(OrderMutualDO::getMutualOrderId, vo.getMutualOrderId())
                .betweenIfPresent(OrderMutualDO::getAddTime, vo.getBeginAddTime(), vo.getEndAddTime())
                    .orderByDesc(OrderMutualDO::getId));
        }

        return null;
    }

    @Select("update ecw_order_mutual set deleted=0 where creator=#{query.creator} and create_time=#{query.createTime} " +
            "and updater=#{query.updater} and update_time=#{query.updateTime} and mutual_order_id=#{query.mutualOrderId}")
    void updateMutualBackByRelatId(OrderMutualDO item);

    @Select("update ecw_order_mutual set deleted=0 where creator=#{query.creator} and create_time=#{query.createTime} " +
            "and updater=#{query.updater} and update_time=#{query.updateTime} and order_id=#{query.orderId}")
    void updateMutualBackByOrderId(OrderMutualDO item);
}
