package com.ktg.iscs.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.iscs.domain.IsMailNotifyConfig;
import com.ktg.iscs.mapper.IsMailNotifyConfigMapper;
import com.ktg.iscs.service.IIsMailNotifyConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 系统邮件提醒周期配置Service业务层处理
 *
 * @author cgj
 * @date 2025-01-15
 */
@Service
public class IsMailNotifyConfigServiceImpl extends ServiceImpl<IsMailNotifyConfigMapper, IsMailNotifyConfig> implements IIsMailNotifyConfigService {

    @Autowired
    private IsMailNotifyConfigMapper isMailNotifyConfigMapper;

    @Override
    public Page<IsMailNotifyConfig> getIsMailNotifyConfigPage(Page<IsMailNotifyConfig> page, IsMailNotifyConfig isMailNotifyConfig) {
        return isMailNotifyConfigMapper.getIsMailNotifyConfigPage(page, isMailNotifyConfig);
    }

    @Override
    public Boolean updateAutomaticConfig(IsMailNotifyConfig isMailNotifyConfig) {
        Assert.notBlank(isMailNotifyConfig.getTemplateCode(), "模板code不能为空！");
        update(Wrappers.<IsMailNotifyConfig>lambdaUpdate()
                .eq(IsMailNotifyConfig::getTemplateCode, isMailNotifyConfig.getTemplateCode())
                .set(IsMailNotifyConfig::getPlanFrequency, isMailNotifyConfig.getPlanFrequency())
                .set(IsMailNotifyConfig::getPlanDate, isMailNotifyConfig.getPlanDate())
                .set(IsMailNotifyConfig::getStartStatus, isMailNotifyConfig.getStartStatus())
                .set(IsMailNotifyConfig::getCheckUserId, isMailNotifyConfig.getCheckUserId()));
        return true;
    }

}
