package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.mapper.MailLogMapper;
import cn.com.ctop.common.module.service.ISendMessageService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.CorpWexinUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SendMessageServiceImpl implements ISendMessageService {
    @Autowired
    private MailLogMapper mailLogMapper;
    @Autowired
    private CorpWexinUtils corpWexinUtils;

    @Override
    public void sendMessage(String userId, String text) {
        JSONObject weChatId = mailLogMapper.getWChatIdByUserId(userId);
        if (!Check.isNull(weChatId)) {
            corpWexinUtils.sendMessageByWeChatId(weChatId, text);
            log.info("消息发送成功，userId:{}", userId);
        }
    }
}
