package org.ruoyi.chat.domain; import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; import java.io.Serializable; import java.util.HashMap; import java.util.Map; public class DomainObject implements Serializable { @Getter @Setter @ApiModelProperty("ID") protected String id; @Setter protected Map properties; // 扩展属性,仅支持基本类型 @JsonIgnore private final transient Object lock = new Object(); public void sleep() throws InterruptedException { synchronized (this.lock) { this.lock.wait(); } } public void awake() { synchronized (this.lock) { this.lock.notifyAll(); } } public DomainObject setProperty(String name, Object value) { getProperties().put(name, value); return this; } public DomainObject removeProperty(String name) { getProperties().remove(name); return this; } public Object getProperty(String name) { return getProperties().get(name); } @SuppressWarnings("unchecked") public T getPropertyGeneric(String name) { return (T) getProperty(name); } public T getProperty(String name, Class clz) { return getProperty(name, clz, null); } public T getProperty(String name, Class clz, T defaultValue) { Object value = getProperty(name); return value == null ? defaultValue : clz.cast(value); } public Map getProperties() { if (this.properties == null) { this.properties = new HashMap<>(); } return this.properties; } }