package com.seer.teach.mp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.seer.teach.mp.entity.MpTemplateMessageConfigEntity;
import com.seer.teach.mp.mapper.MpTemplateMessageConfigMapper;
import com.seer.teach.mp.service.IMpTemplateMessageConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 模板消息自动发送配置表 服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-08-12 09:21:28
 */
@Service
public class MpTemplateMessageConfigServiceImpl extends ServiceImpl<MpTemplateMessageConfigMapper, MpTemplateMessageConfigEntity> implements IMpTemplateMessageConfigService {

    @Override
    public IPage<MpTemplateMessageConfigEntity> pageList(IPage<MpTemplateMessageConfigEntity> pageParm, MpTemplateMessageConfigEntity queryParam) {
        return super.page(pageParm, new LambdaQueryWrapper<>(MpTemplateMessageConfigEntity.class).eq(StringUtils.hasText(queryParam.getBusinessSceneCode()),MpTemplateMessageConfigEntity::getBusinessSceneCode, queryParam.getBusinessSceneCode()));
    }

    @Override
    public MpTemplateMessageConfigEntity getGroupIdsByBusinessSceneCode(String businessSceneCode) {
        return super.getOne(new LambdaQueryWrapper<>(MpTemplateMessageConfigEntity.class).eq(MpTemplateMessageConfigEntity::getBusinessSceneCode, businessSceneCode));
    }

    @Override
    public long getTemplateIdByBusinessSceneCodeAndTemplateId(String businessSceneCode, String templateId) {
        return super.count(new LambdaQueryWrapper<>(MpTemplateMessageConfigEntity.class).eq(MpTemplateMessageConfigEntity::getBusinessSceneCode, businessSceneCode).eq(MpTemplateMessageConfigEntity::getTemplateId, templateId));
    }
}