package cn.axzo.msg.center.dal;


import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.msg.center.dal.mapper.MessageRouterMapper;
import cn.axzo.msg.center.domain.dto.SyncRouterDataDTO;
import cn.axzo.msg.center.domain.entity.MessageRouter;
import cn.axzo.msg.center.domain.enums.MsgRouteTypeEnum;
import cn.axzo.msg.center.domain.persistence.BaseEntity;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Set;

/**
 * 消息路由配置信息(MessageRouter)表数据库访问层
 *
 * @author zhangran
 * @since 2022-03-28 14:59:16
 */
@Service
@Slf4j
public class MessageRouterDao extends
    ServiceImpl<MessageRouterMapper, MessageRouter> {

  /**
   * 通过relationId获取router
   *
   * @param relationId
   * @return
   */
  public List<MessageRouter> getByRelationId(Long relationId, List<MsgRouteTypeEnum> routeTypeEnumList) {
    return lambdaQuery().eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
        .in(MessageRouter::getRouterType, routeTypeEnumList)
        .eq(MessageRouter::getRelationId, relationId).list();
  }

  public List<MessageRouter> listRoutersByRelationIds(Set<Long> relationIds) {
    return this.lambdaQuery().in(MessageRouter::getRelationId,relationIds).eq(BaseEntity::getIsDelete, 0)
        .list();
  }

  public void insertBatchSql(List<SyncRouterDataDTO> adds) {
    if(CollectionUtils.isEmpty(adds)){
      return;
    }
    this.baseMapper.navtiveBatchSql(adds);
  }
}

