package com.ruoyi.common.utils;

import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class YPMsgUtils {
    private static final Logger log = LoggerFactory.getLogger(YPMsgUtils.class);

    public static final String apikey = SpringUtils.getRequiredProperty("yp.apikey");

    /**
     * 发送下单短信
     */
    public static void sendPlaceOrderMsg(String orderNo , String sendPhone, String orderPhone) {
        Map<String, String> params = new HashMap<>();
        params.put("apikey", apikey);
        params.put("text", "【小兜出行】您有新的订单已成功下单！订单号为："+orderNo+"，手机号为：["+orderPhone+"]，请及时配送。");
        params.put("mobile", sendPhone);
        String s = HttpUtils.sendPost("https://sms.yunpian.com/v2/sms/single_send.json", params);
        log.info("【下单短信】发送短信结果："+s);
    }

    /**
     * 发送即将到期提醒
     * 是否发送过短信
     */
    public static void expirationReminderMsg(String orderNo , String sendPhone, String time) {
        Map<String, String> params = new HashMap<>();
        params.put("apikey", apikey);
        params.put("text", "您好！您的租赁订单：["+orderNo+"]即将到期，到期时间为：["+time+"]。\n" +
                "如需续单请及时处理，若有其他疑问，请联系我们的客服。感谢您的支持与信任！");
        params.put("mobile", sendPhone);
        String s = HttpUtils.sendPost("https://sms.yunpian.com/v2/sms/single_send.json", params);
        log.info("【到期提醒】发送短信结果："+s);
    }

    /**
     * 发送保洁通知短信
     * 是否发送过短信
     */
    public static void sendClearMsg(String roomName ,String sendPhone) {
        log.info("【保洁通知】发送短信开始,roomName=【{}】，sendPhone=【{}】",roomName,sendPhone);
        Map<String, String> params = new HashMap<>();
        params.put("apikey", apikey);
        params.put("text", "您好！您的包间["+roomName+"]订单已结束，请及时打扫!");
        params.put("mobile", sendPhone);
        String s = HttpUtils.sendPost("https://sms.yunpian.com/v2/sms/single_send.json", params);
        log.info("【保洁通知】发送短信结果：{}", s);
    }

//    public static void main(String[] args) {
//        expirationReminderMsg("123456789","18650502300","2024-11-05");
//    }
}
