package cn.axzo.msg.center.dal;

import cn.axzo.msg.center.dal.mapper.PendingMessageRecordMapper;
import cn.axzo.msg.center.domain.entity.PendingMessageRecord;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @description
 * @author cold_blade
 * @date 2023/9/28
 * @version 1.0
 */
@Slf4j
@Component
public class PendingMessageRecordDao extends ServiceImpl<PendingMessageRecordMapper, PendingMessageRecord> {

    /**
     * 通过消息唯一标识查询对应的消息记录
     *
     * @param msgIdentityCode  消息唯一标识
     * @return 消息记录
     */
    public Optional<PendingMessageRecord> queryByIdentityCode(String msgIdentityCode) {
        if (StringUtils.isBlank(msgIdentityCode)) {
            return Optional.empty();
        }
        PendingMessageRecord record = lambdaQuery()
                .eq(PendingMessageRecord::getIdentityCode, msgIdentityCode)
                .eq(PendingMessageRecord::getIsDelete, 0)
                .one();
        return Optional.ofNullable(record);
    }
}
