package com.zcloud.zcGbsServicer.service;

import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.framework.repository.basedo.BaseDO;

import java.time.LocalDateTime;

abstract class FireAlarmServiceSupport {

    protected Long currentTenantId() {
        return AuthContext.getTenantId();
    }

    protected Long currentUserId() {
        return AuthContext.getUserId();
    }

    protected String currentUserName() {
        SSOUser user = AuthContext.getCurrentUser();
        return user == null ? null : user.getName();
    }

    protected void fillCreateAudit(BaseDO dataObject) {
        LocalDateTime now = LocalDateTime.now();
        dataObject.setTenantId(currentTenantId());
        dataObject.setOrgId(currentTenantId());
        dataObject.setDeleteEnum("FALSE");
        dataObject.setVersion(0);
        dataObject.setCreateId(currentUserId());
        dataObject.setCreateName(currentUserName());
        dataObject.setCreateTime(now);
        dataObject.setUpdateId(currentUserId());
        dataObject.setUpdateName(currentUserName());
        dataObject.setUpdateTime(now);
    }

    protected void fillUpdateAudit(BaseDO dataObject) {
        dataObject.setUpdateId(currentUserId());
        dataObject.setUpdateName(currentUserName());
        dataObject.setUpdateTime(LocalDateTime.now());
    }
}
