package com.dayou.aspect;

import com.dayou.message.MessageTypeEnum;
import com.dayou.message.annotation.SendMessage;
import com.dayou.service.IMessageService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

import static com.dayou.message.MessageTypeEnum.MAJOR_DECLARE_REMIND;

/**
 * 类说明：
 *
 * @author: wucl
 * @since: 2024/5/21
 * created with IntelliJ IDEA.
 */
@Slf4j
@Component
@Aspect
public class SendMessageAOP {

    @Autowired
    private IMessageService messageService;

    @Around("@annotation(sendMessage)")
    public Object sendMessageAround(ProceedingJoinPoint joinPoint, SendMessage sendMessage) throws Throwable {
        Long proceed = (Long) joinPoint.proceed(joinPoint.getArgs());
        MessageTypeEnum messageTypeEnum = sendMessage.messageType();
        if (messageTypeEnum.equals(MAJOR_DECLARE_REMIND)){
            messageService.packagingMajorDeclareRemind(proceed);
        }
        return null;
    }
}
