package com.mortals.xhx.base.framework.aspect;

import com.mortals.framework.model.OperateLogPdu;
import com.mortals.framework.service.ILogService;
import com.mortals.framework.service.impl.FileLogServiceImpl;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.base.system.oper.service.OperLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.Date;

/**
 * 操作日志记录
 *
 * @author: zxfei
 * @date: 2021/11/5 13:28
 */
@Component
@Slf4j
public class OperlogAspect extends FileLogServiceImpl implements ILogService {

    @Autowired
    private OperLogService operLogService;
    @Autowired
    private MessageProducer messageProducer;

    @Override
    public void doHandlerLog(String platformMark, Long userId, String userName, String loginName, String requestUrl,
                             String content, String ip, Date logDate) {
        super.doHandlerLog(platformMark, userId, userName, loginName, requestUrl, content, ip, logDate);
        if(ObjectUtils.isEmpty(userId)) return;
        operLogService.insertOperLog(ip, requestUrl, userId, userName, loginName, content);
        OperateLogPdu operateLogPdu = new OperateLogPdu();
        operateLogPdu.initAttrValue();
        operateLogPdu.setIp(ip);
        operateLogPdu.setRequestUrl(requestUrl);
        operateLogPdu.setUserId(userId);
        operateLogPdu.setUserName(userName);
        operateLogPdu.setLoginName(loginName);
        operateLogPdu.setPlatformMark(platformMark);
        operateLogPdu.setLogDate(logDate);
        operateLogPdu.setContent(content);
        operateLogPdu.setOperType(1);
        messageProducer.syncOperSend(operateLogPdu);
    }

    @Override
    public void doHandlerLog(String platformMark, String loginName, String requestUrl, String content, String ip) {
        this.doHandlerLog(platformMark, null, "", loginName, requestUrl, content, ip, new Date());


    }
}
