package com.xiang.xservice.application.script.domain.service;

import com.xiang.xmc.service.message.dingTalk.service.DingTalkService;
import com.xiang.xservice.config.DingTalkRobotScriptConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: xiang
 * @Date: 2025-08-07 10:30
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DingTalkScriptDomainService {

    private final DingTalkService dingTalkService;
    private final DingTalkRobotScriptConfig dingTalkRobotScriptConfig;

    /**
     * 发送脚本消息
     * @param msg   消息
     */
    public void sendScriptMsg(String msg) {
        try {
            dingTalkService.sendRobotMessage(dingTalkRobotScriptConfig.getSecret(), dingTalkRobotScriptConfig.getToken(),
                    dingTalkRobotScriptConfig.getUsers(), msg);
        } catch (Exception e) {
            log.error("信息发送异常, 信息：{}", msg, e);
        }
    }
}
