feat: workflow trigger support blacklist (#1309)
Reviewed-on: daoyoucloud/tachybase#1309
This commit is contained in:
parent
b8fe6cfa17
commit
80937bd6dd
@ -242,30 +242,6 @@ export class RecordService {
|
||||
if (!values) return;
|
||||
// 触发打印更新次数跳过
|
||||
if (Object.keys(values).length === 1 && values?.print_count) return;
|
||||
if (values?.category === RecordCategory.lease && values.contract) {
|
||||
const dateObject = values.date;
|
||||
// 结束时间添加一天,新系统选择时间都是以当天0点开始,但是导入的数据存在不是以0点开始比如2023-12-21:03.000……,提醒结算单的时间可能为2023-12-21:00.000……
|
||||
const settlement = await this.db.sequelize.query(
|
||||
`SELECT * FROM settlements WHERE contract_id = ${values.contract.id} AND start_date <= '${dateObject}' AND end_date >= (TIMESTAMP '${dateObject}' - INTERVAL '1 day')`,
|
||||
);
|
||||
const settlementData: any = settlement[0];
|
||||
if (settlementData.length) {
|
||||
for (const item of settlementData) {
|
||||
const settlement_id = item.id;
|
||||
await this.db.getModel('settlements').update(
|
||||
{
|
||||
status: settlementStatus.needReCompute,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
id: settlement_id,
|
||||
},
|
||||
transaction,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (values?.category === RecordCategory.purchase) {
|
||||
// 定价
|
||||
const rule = values.price_items;
|
||||
|
@ -50,6 +50,15 @@ export default class extends Trigger {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
target: 'blacklist',
|
||||
effects: ['onFieldValueChange'],
|
||||
fulfill: {
|
||||
state: {
|
||||
value: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
target: 'condition',
|
||||
effects: ['onFieldValueChange'],
|
||||
@ -93,6 +102,34 @@ export default class extends Trigger {
|
||||
},
|
||||
],
|
||||
},
|
||||
blacklist: {
|
||||
type: 'array',
|
||||
title: `{{t("Changed fields - blacklist", { ns: "${NAMESPACE}" })}}`,
|
||||
description: `{{t("Triggered only if none of the selected fields changes. When record is added or deleted, this field has no effect.", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'FieldsSelect',
|
||||
'x-component-props': {
|
||||
mode: 'multiple',
|
||||
placeholder: '{{t("Select field")}}',
|
||||
filter(field) {
|
||||
return (
|
||||
!field.hidden &&
|
||||
(field.uiSchema ? !field.uiSchema['x-read-pretty'] : true) &&
|
||||
!['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(field.type)
|
||||
);
|
||||
},
|
||||
},
|
||||
'x-reactions': [
|
||||
{
|
||||
dependencies: ['collection', 'mode'],
|
||||
fulfill: {
|
||||
state: {
|
||||
visible: `{{!!$deps[0] && ($deps[1] & ${COLLECTION_TRIGGER_MODE.UPDATED})}}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
changed: {
|
||||
type: 'array',
|
||||
title: `{{t("Changed fields", { ns: "${NAMESPACE}" })}}`,
|
||||
|
@ -37,7 +37,7 @@ function getFieldRawName(collection: ICollection, name: string) {
|
||||
|
||||
// async function, should return promise
|
||||
async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: Model, options) {
|
||||
const { condition, changed, mode, appends } = workflow.config;
|
||||
const { condition, changed, mode, appends, blacklist } = workflow.config;
|
||||
const [dataSourceName, collectionName] = parseCollectionName(workflow.config.collection);
|
||||
const collection = this.workflow.app.dataSourceManager?.dataSources
|
||||
.get(dataSourceName)
|
||||
@ -57,6 +57,17 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
blacklist &&
|
||||
blacklist.length &&
|
||||
blacklist
|
||||
.filter(
|
||||
(name) => !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(collection.getField(name).options.type),
|
||||
)
|
||||
.some((name) => data.changedWithAssociations(getFieldRawName(collection, name)))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
// NOTE: if no configured condition match, do not trigger
|
||||
if (condition && condition.$and?.length) {
|
||||
// TODO: change to map filter format to calculation format
|
||||
|
Loading…
Reference in New Issue
Block a user