package com.usky.issue.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.usky.issue.domain.IssueCloudConfig;
import com.usky.issue.domain.IssueOperationLog;
import com.usky.issue.mapper.IssueCloudConfigMapper;
import com.usky.issue.mapper.IssueOperationLogMapper;
import com.usky.issue.service.CloudOperationLogService;
import com.usky.issue.service.support.CloudEntitySupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 操作审计日志实现
 *
 * @author fyc
 * @date 2026-05-21
 */
@Service
public class CloudOperationLogServiceImpl implements CloudOperationLogService {

    @Autowired
    private IssueOperationLogMapper operationLogMapper;

    @Autowired
    private IssueCloudConfigMapper configMapper;

    @DS("usky-cloud")
    @Override
    public void log(Long configId, String operationType, String detail, String operator, String requestIp) {
        IssueOperationLog log = new IssueOperationLog();
        log.setConfigId(configId);
        IssueCloudConfig config = configMapper.selectById(configId);
        if (config != null) {
            log.setTenantId(config.getTenantId());
        }
        log.setOperationType(operationType);
        log.setOperationDetail(detail);
        log.setRequestIp(requestIp);
        CloudEntitySupport.fillOnInsert(log);
        log.setCreatedBy(operator);
        operationLogMapper.insert(log);
    }
}
