package com.cyksj.service.sms.impl;

import cn.hutool.core.util.StrUtil;
import com.cyksj.common.constant.Constant;
import com.cyksj.common.util.SmsUtil;
import com.cyksj.mapper.GroupsRelationMapper;
import com.cyksj.model.entity.PhoneCode;
import com.cyksj.service.sms.SmsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/*
 *项目名: netflix
 *文件名: SmsServiceImpl
 *创建者: JavaZou
 *创建时间:2023/5/9 9:58
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class SmsServiceImpl implements SmsService {
	private final GroupsRelationMapper groupsRelationMapper;

	@Override
	public void sendSmsToRelationUser(Long userId, String template, String... objs) throws Exception {
		PhoneCode areaPhone = groupsRelationMapper.getAreaPhoneByUserId(userId);
		if (areaPhone != null && StrUtil.isNotBlank(areaPhone.getPhone())) {
			String phone = areaPhone.getPhone();
			//国际短信通知
			if (areaPhone.getCid() != null && areaPhone.getCid() != 86) {
				if (StrUtil.equals(template, Constant.CHANGE_GROUPS_TRIPS_ACCOUNT)) {
					log.info("发送手机号:{}国际化短信通知车票账号密码修改", phone);
					SmsUtil.sendAccountInternalSmsMsg(areaPhone.getCid(), phone, objs[0]);
				}
			} else {
				String msg = String.format(template, objs);
				SmsUtil.sendLuoKey2Msg(phone, msg);
			}
		}
	}
}
