package com.ho.flow.config;

import cn.hutool.core.lang.Snowflake;
import com.ho.common.tools.entity.SimpleUser;
import com.ho.common.tools.entity.UserDetailRespVO;
import com.ho.flow.feignclient.UserFeignClient;
import com.ho.user.api.entity.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author fancl
 * @desc:
 * @date 2022/10/20
 */
@Component
@Slf4j
public class SaveLogComponent {

    @Autowired
    Snowflake snowflake;

    @Autowired
    UserFeignClient userFeignClient;

    //保存日志
    @Async
    public void saveSysLog(SysLog sysLog, UserDetailRespVO user, SimpleUser simpleUser, long time) {
        sysLog.setId(snowflake.nextId());
        sysLog.setGroupId(simpleUser.getGroupId());
        sysLog.setDeptId(simpleUser.getDeptId());
        sysLog.setUsername(user.getUsername());
        sysLog.setUserId(user.getUserId());
        sysLog.setTime((int) time);
        //调用User-center的服务记录日志
        userFeignClient.insertLog(sysLog);
    }
}
