diff --git a/services/standard-object-database/main/default/server/object_fields.object.js b/services/standard-object-database/main/default/server/object_fields.object.js index 8db73d5df1..0a5a901fb1 100644 --- a/services/standard-object-database/main/default/server/object_fields.object.js +++ b/services/standard-object-database/main/default/server/object_fields.object.js @@ -5,7 +5,7 @@ var objectCore = require('./objects.core.js'); const objectFieldsFind = function (filter) { return objectql.wrapAsync(async function () { - return await objectql.getObject('object_fields').find(this.filter); + return await objectql.getObject('object_fields').directFind(this.filter); }, { filter: filter }) } diff --git a/services/standard-object-database/main/default/server/objects.object.js b/services/standard-object-database/main/default/server/objects.object.js index 43b6be9875..92a6088bd6 100644 --- a/services/standard-object-database/main/default/server/objects.object.js +++ b/services/standard-object-database/main/default/server/objects.object.js @@ -318,6 +318,59 @@ let objectTriggers = { filterable: true, sort_no: 10 }); + Creator.getCollection("object_fields").insert({ + object: doc.name, + owner: userId, + _name: "created", + label: "创建时间", + space: doc.space, + type: "datetime", + group: '', + sort_no: 9999, + readonly: true, + disabled: true, + sortable: true + }); + Creator.getCollection("object_fields").insert({ + object: doc.name, + owner: userId, + _name: "created_by", + label: "创建人", + space: doc.space, + type: "lookup", + reference_to: 'users', + group: '', + sort_no: 9999, + readonly: true, + disabled: true, + }); + Creator.getCollection("object_fields").insert({ + object: doc.name, + owner: userId, + _name: "modified", + label: "修改时间", + space: doc.space, + type: "datetime", + group: '', + sort_no: 9999, + readonly: true, + disabled: true, + sortable: true + }); + Creator.getCollection("object_fields").insert({ + object: doc.name, + owner: userId, + _name: "modified_by", + label: "修改人", + space: doc.space, + space: doc.space, + type: "lookup", + reference_to: 'users', + group: '', + sort_no: 9999, + readonly: true, + disabled: true, + }); // Creator.getCollection("object_fields").insert({ // object: doc.name, // owner: userId, diff --git a/services/standard-object-database/main/default/services/object_fields.service.js b/services/standard-object-database/main/default/services/object_fields.service.js index cfd3c3d309..025e4292f2 100644 --- a/services/standard-object-database/main/default/services/object_fields.service.js +++ b/services/standard-object-database/main/default/services/object_fields.service.js @@ -7,7 +7,30 @@ const steedosI18n = require("@steedos/i18n"); const _ = require("lodash"); const clone = require("clone"); const serviceObjectMixin = require('@steedos/service-object-mixin'); +const objectql = require('@steedos/objectql'); // 默认值字段代码:services/standard-object-database/main/default/services/object_fields.service.js + +const initSummaryDoc = async (doc) => { + if (!doc.summary_object) { + throw new Error("object_fields_error_summary_object_required"); + } + let summaryObject = register.getObjectConfig(doc.summary_object); + let summaryConfig = { + summary_object: doc.summary_object, + summary_type: doc.summary_type, + summary_field: doc.summary_field, + field_name: doc.name, + object_name: doc.object + }; + const dataType = await objectql.getSummaryDataType(summaryConfig, summaryObject); + if (!dataType) { + throw new Error("object_fields_error_summary_data_type_not_found"); + } + doc.data_type = dataType; + // objectql.validateFilters(doc.summary_filters, summaryObject.fields); +} + + module.exports = { name: "object_fields", mixins: [serviceObjectMixin], @@ -291,7 +314,7 @@ module.exports = { _.map(objectFields, (objectField)=>{ if(!objectField.group){ - objectField.group = '基本信息' + objectField.group = '通用' } }) @@ -404,7 +427,7 @@ module.exports = { const newId = await object_fields._makeNewID(); const now = new Date(); const field = _.find(fields, { name: fieldName }); - await object_fields.directInsert(Object.assign({}, field, { + const doc = Object.assign({}, field, { _id: newId, owner: userSession.userId, space: userSession.spaceId, @@ -415,7 +438,11 @@ module.exports = { modified_by: userSession.userId, company_id: userSession.company_id, company_ids: userSession.company_ids - })); + }); + if(doc.type === "summary"){ + await initSummaryDoc(doc); + } + await object_fields.directInsert(doc); log.insert.success.push(fieldName); } catch (e) { log.insert.error.push(fieldName); @@ -430,6 +457,10 @@ module.exports = { const field = _.find(fields, { name: fieldName }); const id = _.find(dbFields, { name: fieldName })._id; const submitField = _.omit(field, ['name', '_name']); + + if(submitField.type === "summary"){ + await initSummaryDoc(submitField); + } await object_fields.directUpdate(id, Object.assign({}, submitField, { modified: now, modified_by: userSession.userId