package foundation.io.define;
|
|
import foundation.dao.Filter;
|
import foundation.dao.bizlogic.ICodeProvider;
|
import foundation.data.entity.Entity;
|
import foundation.data.entity.EntitySet;
|
import foundation.data.object.DataObject;
|
import foundation.io.IOLoader;
|
import foundation.io.engine.LineValueTrigger;
|
import foundation.io.mapping.MappingDirection;
|
import foundation.io.mapping.MappingsRuntime;
|
import foundation.server.config.ServerStatus;
|
import foundation.util.MapList;
|
import foundation.util.Util;
|
|
public class DataIO {
|
|
private String id;
|
private String taskName;
|
private String fromName;
|
private String toName;
|
private String toTempName;
|
private String templateName;
|
private String fileName;
|
private boolean writeTitle;
|
private IODirection direction;
|
private String mappingId;
|
private boolean distinctSelect;
|
private boolean standardMove;
|
private String[] filterFieldValues;
|
private String[] keyFieldPairs;
|
private String[] checkDocField;
|
private String additionalFields;
|
private AppendMode appendMode;
|
private DeleteMode deleteMode;
|
private int fromTitleRowNo;
|
private int fromDataRowNo;
|
private int toTitleRowNo;
|
private int toDataRowNo;
|
private String action;
|
private String actionMethod;
|
private boolean active;
|
private IOSource source;
|
private MapList<String, LineValueTrigger> valueTriggers;
|
|
private DataObject fromDataObject;
|
private DataObject toDataObject;
|
private DataObject toTempDataObject;
|
private MappingDirection mappingDirection;
|
private IOSQLContext context;
|
private IOWorkflow wrokflow;
|
|
|
public DataIO() {
|
distinctSelect = false;
|
standardMove = true;
|
|
fromTitleRowNo = 0;
|
fromDataRowNo = 1;
|
toTitleRowNo = 0;
|
toDataRowNo = 1;
|
|
mappingDirection = MappingDirection.Normal;
|
appendMode = AppendMode.Append;
|
deleteMode = DeleteMode.HardDelete;
|
|
additionalFields = null;
|
keyFieldPairs = null;
|
filterFieldValues = null;
|
|
active = true;
|
context = new IOSQLContext(this);
|
}
|
|
public void load(Entity entity) throws Exception {
|
id = entity.getString("id");
|
taskName = entity.getString("task_name");
|
|
fromName = entity.getString("from_name");
|
toName = entity.getString("to_name");
|
toTempName = entity.getString("to_temp_name");
|
fileName = templateName = entity.getString("template_name");
|
writeTitle = entity.getBoolean("is_write_title", true);
|
direction = IODirection.parse(entity.getString("direction_code"));
|
|
mappingId = entity.getString("mapping_id");
|
mappingDirection = MappingDirection.parse((entity.getString("mapping_direction")));
|
|
distinctSelect = entity.getBoolean("is_distinct_select", false);
|
standardMove = entity.getBoolean("is_standard_move", true);
|
|
fromTitleRowNo = entity.getInteger("from_title_rowno", 0);
|
fromDataRowNo = entity.getInteger("from_data_rowno", 1);
|
toTitleRowNo = entity.getInteger("to_title_rowno", 0);
|
toDataRowNo = entity.getInteger("to_data_rowno", 1);
|
|
action = entity.getString("action_name");
|
actionMethod = entity.getString("method_name");
|
|
appendMode = AppendMode.parse(entity.getString("append_mode"), AppendMode.ClearAndAppend);
|
deleteMode = DeleteMode.parse(entity.getString("delete_mode"), DeleteMode.HardDelete);
|
|
additionalFields = entity.getString("additional_field");
|
|
String keyField = entity.getString("key_field_pairs");
|
if (!Util.isEmpty(keyField)) {
|
keyFieldPairs = keyField.split(";");
|
}
|
|
String filterField = entity.getString("filter_field_values");
|
if (!Util.isEmpty(filterField)) {
|
filterFieldValues = filterField.split(";");
|
}
|
|
String docFilterFieldStr = entity.getString("check_doc_field");
|
if (!Util.isEmpty(docFilterFieldStr)) {
|
checkDocField = docFilterFieldStr.split(";");
|
}
|
|
|
active = entity.getBoolean("is_active", true);
|
source = IOSource.ConfigDefine;
|
|
valueTriggers = new MapList<String, LineValueTrigger>();
|
loadValueTriggers(entity);
|
}
|
|
private void loadValueTriggers(Entity entity) throws Exception{
|
DataObject dataObject = DataObject.getInstance("sys_io_trigger");
|
Filter filter = new Filter("parent_id", id).add("is_active", "T");
|
EntitySet dataIOTriggerSet = dataObject.getTableEntitySet(filter);
|
|
for (Entity oneTrigger: dataIOTriggerSet) {
|
LineValueTrigger trigger = new LineValueTrigger();
|
trigger.load(oneTrigger);
|
valueTriggers.add(trigger.getTriggerName(), trigger);
|
}
|
|
}
|
|
public static String extractSheetName(String value) {
|
if (Util.isEmpty(value)) {
|
return "Sheet1";
|
}
|
|
int begin = value.indexOf("[");
|
|
if (begin < 0) {
|
return "Sheet1";
|
}
|
|
int end = value.indexOf("]", begin);
|
|
if (end < 0) {
|
return "Sheet1";
|
}
|
|
return value.substring(begin + 1, end - begin - 1);
|
}
|
|
public static String extractFileName(String value) {
|
if (Util.isEmpty(value)) {
|
return null;
|
}
|
|
int end = value.indexOf("[");
|
|
if (end < 0) {
|
return value;
|
}
|
|
return value.substring(0, end - 1);
|
}
|
|
public boolean existsFilterFieldValues() {
|
if (filterFieldValues == null) {
|
return false;
|
}
|
|
return filterFieldValues.length > 0;
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public void setId(String id) {
|
this.id = id;
|
}
|
|
public String getTaskName() {
|
return taskName;
|
}
|
|
public void setTaskName(String taskName) {
|
this.taskName = taskName;
|
}
|
|
public String getFromName() {
|
return fromName;
|
}
|
|
public void setFromName(String fromName) {
|
this.fromName = fromName;
|
}
|
|
public String getToName() {
|
return toName;
|
}
|
|
public boolean existsToName() {
|
return !Util.isEmpty(toName);
|
}
|
|
public void setToName(String toName) {
|
this.toName = toName;
|
}
|
|
public String getToTempName() {
|
return toTempName;
|
}
|
|
public void setToTempName(String toTempName) {
|
this.toTempName = toTempName;
|
}
|
|
public MapList<String, LineValueTrigger> getValueTriggers() {
|
return valueTriggers;
|
}
|
|
public IODirection getDirection() {
|
return direction;
|
}
|
|
public void setDirection(IODirection direction) {
|
this.direction = direction;
|
}
|
|
public boolean isWriteTitle() {
|
return writeTitle;
|
}
|
|
public void setWriteTitle(boolean value) {
|
writeTitle = value;
|
}
|
|
public String getTemplateName() {
|
return templateName;
|
}
|
|
public void setTemplateName(String value) {
|
templateName = value;
|
}
|
|
public String getFileName() {
|
if (!Util.isEmpty(fileName)) {
|
return fileName;
|
}
|
|
if (IODirection.TableToSheet == direction) {
|
fileName = getFromDataObject().getTitle();
|
fileName = fileName + ".xlsx";
|
}
|
|
return fileName;
|
}
|
|
public void setFileName(String fileName) {
|
this.fileName = fileName;
|
}
|
|
public String getMappingId() {
|
return mappingId;
|
}
|
|
public boolean isDistinctSelect() {
|
return distinctSelect;
|
}
|
|
public boolean isStandardMove() {
|
return standardMove;
|
}
|
|
public String[] getFilterFieldValues() {
|
return filterFieldValues;
|
}
|
|
public String[] getKeyFieldPairs() {
|
return keyFieldPairs;
|
}
|
|
public String[] getCheckDocField() {
|
return checkDocField;
|
}
|
|
public AppendMode getAppendMode() {
|
return appendMode;
|
}
|
|
public void setAppendMode(AppendMode appendMode) {
|
this.appendMode = appendMode;
|
}
|
|
public DeleteMode getDeleteMode() {
|
return deleteMode;
|
}
|
|
public MappingDirection getMappingDirection() {
|
return mappingDirection;
|
}
|
|
public int getFromTitleRowNo() {
|
return fromTitleRowNo;
|
}
|
|
public int getFromDataRowNo() {
|
return fromDataRowNo;
|
}
|
|
public int getToTitleRowNo() {
|
return toTitleRowNo;
|
}
|
|
public int getToDataRowNo() {
|
return toDataRowNo;
|
}
|
|
public String getAdditionalFields() {
|
return additionalFields;
|
}
|
|
public boolean isActive() {
|
return active;
|
}
|
|
public IOSQLContext getContext() {
|
return context;
|
}
|
|
public DataObject getToDataObject() {
|
if (toDataObject == null) {
|
toDataObject = DataObject.getInstance(toName);
|
}
|
|
return toDataObject;
|
}
|
|
public DataObject getToTempDataObject() {
|
if (toTempDataObject == null) {
|
toTempDataObject = DataObject.getInstance(toTempName);
|
}
|
|
return toTempDataObject;
|
}
|
|
public DataObject getFromDataObject() {
|
if (fromDataObject == null) {
|
fromDataObject = DataObject.getInstance(fromName);
|
}
|
|
return fromDataObject;
|
}
|
|
public IOWorkflow getWorkflows() throws Exception {
|
if (wrokflow != null && !ServerStatus.isCheckMetaUpdateOnTime()) {
|
return wrokflow;
|
}
|
|
synchronized (this) {
|
if (wrokflow != null && !ServerStatus.isCheckMetaUpdateOnTime()) {
|
return wrokflow;
|
}
|
|
wrokflow = IOLoader.loadIOActions(this, wrokflow);
|
}
|
|
return wrokflow;
|
}
|
|
public IOSource getSource() {
|
return source;
|
}
|
|
public void setSource(IOSource source) {
|
this.source = source;
|
}
|
|
public String getAction() {
|
return action;
|
}
|
|
public void setMappingId(String mappingId) {
|
this.mappingId = mappingId;
|
}
|
|
public String getActionMethod() {
|
return actionMethod;
|
}
|
|
public void setAction(String action) {
|
this.action = action;
|
}
|
|
public void setActionMethod(String actionMethod) {
|
this.actionMethod = actionMethod;
|
}
|
|
public ICodeProvider getCodeRule(MappingsRuntime mappingsRuntime) throws Exception {
|
//1. 如果不是导入操作,不需要自动编码
|
if (IODirection.SheetToTable != direction) {
|
return null;
|
}
|
|
//2. 遍历 mapping,获取第一个编码规则(目前只支持一个编码)
|
DataObject toObject = getToDataObject();
|
|
if (toObject == null) {
|
return null;
|
}
|
|
ICodeProvider codeProvider = toObject.getCodeProvider();
|
|
if (codeProvider == null) {
|
return null;
|
}
|
|
return codeProvider;
|
}
|
|
@Override
|
public String toString() {
|
StringBuilder result = new StringBuilder();
|
|
if (IODirection.SheetToTable == direction) {
|
String sheetName = Util.isEmpty(fromName) ? "Sheet1" : fromName;
|
|
result.append("Sheet[").append(sheetName).append("]");
|
result.append("-->");
|
result.append("表[").append(toTempName).append("]");
|
}
|
else if (IODirection.TableToSheet == direction) {
|
String sheetName = Util.isEmpty(toName) ? "Sheet1" : toName;
|
|
result.append("表[").append(fromName).append("]");
|
result.append("-->");
|
result.append("Sheet[").append(sheetName).append("]");
|
}
|
else if (IODirection.TableToTable == direction) {
|
result.append("表[").append(fromName).append("]");
|
result.append("-->");
|
result.append("表[").append(toName).append("]");
|
}
|
|
result.append(" 规则:").append(source.toChinese());
|
|
return result.toString();
|
}
|
|
}
|