package com.securitycontrol.common.log.service;

import com.securitycontrol.common.core.constant.SecurityConstants;
import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.system.api.RemoteLogService;
import com.securitycontrol.system.api.RemoteUserService;
import com.securitycontrol.system.api.domain.SysLog;
import com.securitycontrol.system.api.domain.SysOperLog;
import com.securitycontrol.system.api.domain.decision.SysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 异步调用日志服务
 *
 * @author czc
 */
@Service
public class AsyncLogService {
    @Autowired
    private RemoteLogService remoteLogService;

    @Autowired
    private RemoteUserService remoteUserService;

    /**
     * 保存系统日志记录
     */
    @Async
    public void saveSysLog(SysOperLog sysOperLog) {
        remoteLogService.saveLogs(sysOperLog, SecurityConstants.INNER);
    }


    /**
     * 查询用户信息
     */
    public SysUserVo queryUserInfo(String userId) {
        Result<SysUserVo> userEntityR = remoteUserService.getUserById(userId, SecurityConstants.INNER);
        if (Result.SUCCESS == userEntityR.getCode()) {
            return userEntityR.getData();
        }
        return null;

    }

    @Async
    public void addSaveSysLog(SysLog sysLog) {
        remoteLogService.saveSysLog(sysLog, SecurityConstants.INNER);
    }
}
