package cn.axzo.msg.center.inside.notices.listener;


import cn.axzo.msg.center.inside.notices.event.PlatUserCreateEvent;
import cn.axzo.msg.center.inside.notices.utils.DingTalkUtilWangli;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @author: wangli
 * @date: 2022/1/25 18:32
 */
@Component
@Slf4j
public class PlatUserCreateListener {

  @Autowired
  private DingTalkUtilWangli util;

  @Value("${spring.profiles.active}")
  private String active;

  @TransactionalEventListener(classes = PlatUserCreateEvent.class)
  public void onEvent(PlatUserCreateEvent event) {
    log.info("监听到平台用户创建的事件: {}", event);
    String mobile = event.getPhone();
    String acme = "";

    switch (active) {
      case "dev":
        acme = "dev-";
        break;
      case "test":
        acme = "test-";
        break;
      case "test1":
        acme = "test1-";
        break;
      case "pre":
        acme = "pre-";
        break;
      default:
        break;
    }
    util.sendMsg(mobile,
        "已为您分配OMS账号\r账号: " + mobile + "\r密码: " + event.getPwd() + "\rOMS地址: " + String.format(
            "https://%soms.axzo.cn/", acme));
  }
}
