package com.huijy.weixin.handler;

import com.huijy.management.service.IEarlyWarningSendLogService;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;
@Component
@AllArgsConstructor
public class TemplateSendHandler extends AbstractHandler {

    private IEarlyWarningSendLogService earlyWarningSendLogService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
        if (wxMessage.getMsgType().equals(WxConsts.XmlMsgType.EVENT) &&
                wxMessage.getEvent().equalsIgnoreCase(WxConsts.EventType.TEMPLATE_SEND_JOB_FINISH)){
            String msgId = wxMessage.getMsgId().toString();
            String status = wxMessage.getStatus();
            earlyWarningSendLogService.updateLogByMsgId(msgId,status);
        }
        return null;
    }
}
