All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.soento.core.lang.BaseEntity Maven / Gradle / Ivy

package com.soento.core.lang;

import com.soento.core.consts.Constants;
import com.soento.core.enums.DeleteFlag;
import com.soento.core.util.StringUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * @author yantao.zeng
 */
@Getter
@Setter
public abstract class BaseEntity extends BaseObject {
    private String id;
    private String createBy;
    private Date createDate;
    private String modifyBy;
    private Date modifyDate;
    private Integer deleteFlag;

    public void init(String userId) {
        this.createBy = userId;
        this.modifyBy = userId;
        this.createDate = new Date();
        this.modifyDate = new Date();
        this.deleteFlag = DeleteFlag.NOT_DELETED.getValue();
    }

    public void init() {
        this.init(Constants.SYSTEM);
    }

    public void init(UserInfo user) {
        if (user != null && StringUtil.isNotBlank(user.getId())) {
            init(user.getId());
        } else {
            init();
        }
    }

    public void update(String userId) {
        this.modifyBy = userId;
        this.modifyDate = new Date();
    }

    public void update() {
        this.update(Constants.SYSTEM);
    }

    public void update(UserInfo user) {
        if (user != null && StringUtil.isNotBlank(user.getId())) {
            update(user.getId());
        } else {
            update();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy