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

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.trade.dal.dataobject.order.TradeOrderTotalDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 订单汇总 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface TradeOrderTotalMapper extends BaseMapperX<TradeOrderTotalDO> {

    default List<TradeOrderTotalDO> selectListByOrderIds(List<Long> orderIds) {
        return selectList(new LambdaQueryWrapperX<TradeOrderTotalDO>()
                .inIfPresent(TradeOrderTotalDO::getOldOrderId, orderIds));
    }

    default List<TradeOrderTotalDO> selectListByOldOrderIds(List<Long> orderIds) {
        return selectList(new LambdaQueryWrapperX<TradeOrderTotalDO>()
                .inIfPresent(TradeOrderTotalDO::getOldOrderId, orderIds));
    }

    @Update("UPDATE trade_order_total SET deleted = #{deleted},update_time = now(), sync_status = '0' WHERE old_order_id = #{orderId}")
    @TenantIgnore
    void updateDeleted(@Param("orderId") Long orderId, @Param("deleted")  int deleted);

    @Select("select * from trade_order_total where old_order_id = #{orderId} limit 1")
    @TenantIgnore
    TradeOrderTotalDO selectByOrderId(@Param("orderId") Long orderId);
}