/**
* Represents a class for preparing fields for saving records.
*/
export class PrepareField {
/**
* Constructs a new PrepareField instance.
* @param {string} field - The field name.
* @param {*} data - The data associated with the field.
* @throws {Error} If field name is missing.
*/
constructor(field, data) {
if (field) {
this.field = field;
this.data = data;
this.sid = 1;
this.entryCount = 1;
this.groupId = 'PARENT';
this.groupEntry = 1;
} else {
throw new Error(`Field name is missing. Please provide a valid field name.`);
}
}
/**
* Sets the message ID.
* @param {string} messageId - The message ID to set.
* @returns {PrepareField} The current instance for chaining.
*/
setMessageId(messageId) {
this.messageId = messageId;
return this;
}
/**
* Sets the SID (System Identifier).
* @param {string} sid - The SID to set.
* @returns {PrepareField} The current instance for chaining.
*/
setSID(sid) {
this.sid = sid;
return this;
}
/**
* Sets the group ID.
* @param {number} groupId - The group ID to set.
* @returns {PrepareField} The current instance for chaining.
*/
setGroupId(groupId) {
this.groupId = groupId;
return this;
}
/**
* Set the groupEntry.
* @param {string} groupEntry - The group groupEntry to set.
*/
setGroupEntry(groupEntry) {
this.groupEntry = groupEntry;
return this;
}
/**
* Sets the entry count in the group.
* @param {number} entryCount - The entry count to set.
* @returns {PrepareField} The current instance for chaining.
*/
setEntryCount(entryCount) {
this.entryCount = entryCount;
return this;
}
/**
* Sets the segment.
* @param {string} segment - The segment to set.
* @returns {PrepareField} The current instance for chaining.
*/
setSegment(segment) {
this.segment = segment;
return this;
}
/**
* Prepares the field with the provided data.
* @param {Object} data - The data to include in the prepared field.
* @returns {Object} The prepared field object.
*/
prepareField(data) {
return {
msg_id: this.messageId,
msg_segment: this.segment,
msg_sid: this.sid,
msg_group_id: this.groupId,
msg_group_entry: this.groupEntry,
msg_field_entry: this.entryCount,
msg_field_type: this.field,
...data
};
}
prepareEntityIdentifier(entInt) {
try {
return entInt?.EntityIdentifier?.toString() || null;
} catch (e) {
console.error('Error preparing entity identifier:', e);
return null;
}
}
/**
* Prepares the field for saving records.
* @throws {Error} If message ID or segment data is missing.
*/
prepare() {
if (!this.messageId) {
throw new Error(`Message ID is required for saving the record. Please set the message ID before preparing.`);
}
if (!this.segment) {
throw new Error(`Segment data is missing. Please set the segment data before preparing.`);
}
}
}

普通网友
- 粉丝: 3496
最新资源
- 第十四章分布存储系统并行编程培训课件.ppt
- Javascript获取CSS伪元素属性的实现代码.doc
- 软件测试报告(2).doc
- 软件工程笔记(完整版).doc
- cad线稿导入ps教程.ppt
- 基于51单片机交通信号灯课程设计.doc
- 电子商务公司规章制度(1)(2).doc
- 互联网+背景下中职学校招生模式探究.docx
- 中等职业学校英语教学中信息化技术的应用(1).docx
- Ctrlbo Project项目管理软件使用心得.doc
- 基于虚拟机技术的操作系统虚拟实验室系统的设计与实现的开题报告.docx
- 大型国际货运代理企业信息化系统的研究与实现的开题报告.docx
- Sqlserver技术知识点之二十(1).doc
- 画图软件课件 PPT.ppt
- WCDMA网络规划和优化软件技术-职业学院毕业论文文章教学教材.doc
- 一种辅助性的制图工具+交互图+一种软件工程设计人员必学习的内容研究报告.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


