package com.cxyxiaomo.epp.access.service;

import com.cxyxiaomo.epp.access.dao.AccessLogDao;
import com.cxyxiaomo.epp.common.pojo.AccessLog;
import com.cxyxiaomo.epp.common.query.AccessLogQuery;
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class AccessLogService {

    @Resource
    AccessLogDao accessLogDao;

    public List<AccessLog> getAccessLogList(AccessLogQuery accessLogQuery) {
        if (Objects.nonNull(accessLogQuery.getType()) && "".equals(accessLogQuery.getType())) {
            accessLogQuery.setType(null);
        }
        return accessLogDao.getAccessLogList(accessLogQuery);
    }

    public boolean addAccessLog(AccessLog accessLog) throws Exception {
        // 创建日志编号
        SnowflakeManager snowflakeManager = new SnowflakeManager(1L, 1L);
        long orderId = snowflakeManager.nextValue();
        accessLog.setId(orderId);
        return accessLogDao.addAccessLog(accessLog);
    }

    public boolean updateAccessLog(AccessLog accessLog) {
        return accessLogDao.updateAccessLog(accessLog);
    }

    public boolean deleteAccessLog(Long accessLogId) {
        return accessLogDao.deleteAccessLogById(accessLogId);
    }
}
