package com.fs.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TemplateListener  implements SmartApplicationListener {
    @Autowired
    private WeixinTemplateService weixinTemplateService;

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
        return aClass == TemplateEvent.class;
    }

    @Async
    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        //转换事件类型
        TemplateEvent templateEvent = (TemplateEvent) applicationEvent;
        //获取注册用户对象信息
        TemplateBean templateBean = templateEvent.getTemplateBean();
        log.info("模板事件类型：{}", templateBean.getTemplateType());
        switch (TemplateListenEnum.toType(templateBean.getTemplateType())) {
            case TYPE_1:
                weixinTemplateService.cancelOrderNotice(templateBean.getOrderId()
                        , templateBean.getTitle(),templateBean.getRemark(), templateBean.getUid());
                break;
            case TYPE_2:
                weixinTemplateService.receiveOrderNotice(templateBean.getOrderId()
                        , templateBean.getTitle(),templateBean.getRemark(), templateBean.getUid());
                break;
            case TYPE_3:
                weixinTemplateService.unPayPackageOrderNotice(templateBean.getOrderId(),templateBean.getTime()
                        , templateBean.getOrderSn(),templateBean.getRemark(), templateBean.getUid());
                break;
            case TYPE_4:

                weixinTemplateService.followCreateNotice(templateBean.getFollowId(),templateBean.getTitle(),templateBean.getRemark(), templateBean.getUid());
                break;
            case TYPE_5:
                weixinTemplateService.doctorReplyNotice(templateBean.getTitle(),templateBean.getRemark(), templateBean.getUid());
                break;



        }


    }
}
