package foundation.dao;
|
|
import java.util.Set;
|
|
import foundation.dao.version.ApplyRelation;
|
import foundation.dao.version.VersionCompareType;
|
import foundation.dao.version.VersionRequest;
|
import foundation.data.entity.Entity;
|
import foundation.data.meta.property.MetaType;
|
import foundation.route.Operation;
|
import foundation.util.Util;
|
|
public class Domain {
|
|
private DataReader dataReader;
|
private Operation operation;
|
private String token;
|
private String dataName;
|
private String partialName;
|
private String parentId;
|
private String id;
|
private String hostId;
|
private Set<String> hostItems;
|
private String operator;
|
private OperatorCode operatorCode;
|
private MetaType metaType;
|
private String scene;
|
private DataPackage dataPackage;
|
private VersionRequest versionRequest;
|
private boolean empty;
|
|
|
public Domain(DataReader dataReader, Operation operation) throws Exception {
|
this.dataReader = dataReader;
|
this.operation = operation;
|
this.versionRequest = new VersionRequest();
|
}
|
|
public synchronized DataPackage getDataPackage() throws Exception {
|
if (dataPackage == null) {
|
synchronized (this) {
|
if (dataPackage == null) {
|
createDataPackage();
|
}
|
}
|
}
|
|
if (dataPackage == null) {
|
return null;
|
}
|
|
//1. 加载数据/单据本身
|
dataPackage.loadDataFromRequest();
|
dataPackage.loadMasterFromDB();
|
|
//2. 加载Host
|
DataPackage host = dataPackage.getHost();
|
if (host == null) {
|
return dataPackage;
|
}
|
|
//1.3 如果有宿主,加载 host limit,重新构建items
|
// Set<String> itemLimits = loadItemLimits();
|
// host.execItemLimits(itemLimits);
|
|
Entity entity = dataPackage.getMasterEntity(DataSource.DB);
|
|
if (entity == null) {
|
return dataPackage;
|
}
|
|
String hostId = entity.getString("host_id");
|
if (Util.isEmpty(hostId)) {
|
return dataPackage;
|
}
|
|
host.setMasterId(hostId);
|
|
//2.
|
String applyName = dataPackage.getName();
|
String applyTypeCode = entity.getString("type_code");
|
ApplyRelation relation = ApplyRelation.getInstance(applyName, applyTypeCode);
|
|
if (relation == null) {
|
return dataPackage;
|
}
|
|
//2.1 如果申请/原单据启用了多版本管理,根据多版本管理设定获取原单据
|
if (relation.isVersionActive()) {
|
host.loadOneDataFromFile();
|
host.setResultData(DataSource.File);
|
}
|
//2.2 如果申请/原单据没有启用多版本管理,从数据库获取原单据
|
else {
|
host.loadOneDataFromDB();
|
host.setResultData(DataSource.DB);
|
}
|
|
//3. 如果需要对比宿主,需要获取数据库数据并对比
|
// Domain domain = dataReader.getDomain();
|
// VersionCompareType compareType = domain.getVersionCompareType();
|
|
// if (VersionCompareType.DoNothing != compareType) {
|
// host.loadOneDataFromDB();
|
// host.compare(DataSource.DB, DataSource.File);
|
// }
|
|
return dataPackage;
|
}
|
|
private DataPackage createDataPackage() throws Exception {
|
//1. create data package
|
dataPackage = DataPackage.getInstance(getDataName(), getPartialName());
|
|
if (dataPackage == null) {
|
return null;
|
}
|
|
dataPackage.setDataReader(dataReader);
|
dataPackage.setMasterId(getId());
|
|
//2. create host
|
String hostName = dataPackage.getHostName();
|
|
if (!Util.isEmpty(hostName)) {
|
DataPackage host = DataPackage.getInstance(hostName);
|
|
String hostId = getHostId();
|
host.setMasterId(hostId);
|
|
dataPackage.setHost(host);
|
}
|
|
//3.
|
dataPackage.loadMasterFromDB();
|
return dataPackage;
|
}
|
|
public Operation getOperation() {
|
return operation;
|
}
|
|
public String getToken() {
|
return token;
|
}
|
|
public String getDataName() {
|
return dataName;
|
}
|
|
public String getPartialName() {
|
return partialName;
|
}
|
|
public String getParentId() {
|
return parentId;
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public String getHostId() {
|
return hostId;
|
}
|
|
public Set<String> getHostItems() {
|
return hostItems;
|
}
|
|
public boolean isEmpty() {
|
return empty;
|
}
|
|
public void setEmpty(boolean empty) {
|
this.empty = empty;
|
}
|
|
public void setToken(String token) {
|
this.token = token;
|
}
|
|
public void setDataName(String dataName) {
|
this.dataName = dataName;
|
}
|
|
public void setPartialName(String partialName) {
|
this.partialName = partialName;
|
}
|
|
public boolean isPartial() {
|
return !Util.isEmpty(partialName);
|
}
|
|
public void setParentId(String parentId) {
|
this.parentId = parentId;
|
}
|
|
public void setId(String id) {
|
this.id = id;
|
}
|
|
public boolean isEmptyId() {
|
return Util.isEmpty(id);
|
}
|
|
public void setHostId(String hostId) {
|
this.hostId = hostId;
|
}
|
|
public void setHostItems(Set<String> hostItems) {
|
this.hostItems = hostItems;
|
}
|
|
public void setOperator(String operator) {
|
this.operator = operator;
|
}
|
|
public String getOperator() {
|
return operator;
|
}
|
|
public MetaType getMetaType() {
|
return metaType;
|
}
|
|
public void setMetaType(MetaType metaType) {
|
this.metaType = metaType;
|
}
|
|
public String getScene() {
|
return scene;
|
}
|
|
public void setScene(String scene) {
|
this.scene = scene;
|
}
|
|
public OperatorCode getOperatorCode() {
|
return operatorCode;
|
}
|
|
public void setOperatorCode(OperatorCode operatorCode) {
|
this.operatorCode = operatorCode;
|
}
|
|
public VersionRequest getVersionRequest() {
|
return versionRequest;
|
}
|
|
public void setVersionRequest(VersionRequest versionRequest) {
|
this.versionRequest = versionRequest;
|
}
|
|
public VersionCompareType getVersionCompareType() {
|
if (versionRequest == null) {
|
return VersionCompareType.DoNothing;
|
}
|
|
return versionRequest.getCompareType();
|
}
|
}
|