mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
fix(plugin-workflow): fix column name caused error when underscored (#5364)
This commit is contained in:
parent
0183ef0561
commit
75efed6a19
@ -12,7 +12,7 @@ import parser from 'cron-parser';
|
|||||||
import type Plugin from '../../Plugin';
|
import type Plugin from '../../Plugin';
|
||||||
import type { WorkflowModel } from '../../types';
|
import type { WorkflowModel } from '../../types';
|
||||||
import { parseDateWithoutMs, SCHEDULE_MODE } from './utils';
|
import { parseDateWithoutMs, SCHEDULE_MODE } from './utils';
|
||||||
import { parseCollectionName } from '@nocobase/data-source-manager';
|
import { parseCollectionName, SequelizeCollectionManager } from '@nocobase/data-source-manager';
|
||||||
|
|
||||||
export type ScheduleOnField = {
|
export type ScheduleOnField = {
|
||||||
field: string;
|
field: string;
|
||||||
@ -68,10 +68,10 @@ function getDataOptionTime(record, on, dir = 1) {
|
|||||||
|
|
||||||
const DialectTimestampFnMap: { [key: string]: (col: string) => string } = {
|
const DialectTimestampFnMap: { [key: string]: (col: string) => string } = {
|
||||||
postgres(col) {
|
postgres(col) {
|
||||||
return `CAST(FLOOR(extract(epoch from "${col}")) AS INTEGER)`;
|
return `CAST(FLOOR(extract(epoch from ${col})) AS INTEGER)`;
|
||||||
},
|
},
|
||||||
mysql(col) {
|
mysql(col) {
|
||||||
return `CAST(FLOOR(UNIX_TIMESTAMP(\`${col}\`)) AS SIGNED INTEGER)`;
|
return `CAST(FLOOR(UNIX_TIMESTAMP(${col})) AS SIGNED INTEGER)`;
|
||||||
},
|
},
|
||||||
sqlite(col) {
|
sqlite(col) {
|
||||||
return `CAST(FLOOR(unixepoch(${col})) AS INTEGER)`;
|
return `CAST(FLOOR(unixepoch(${col})) AS INTEGER)`;
|
||||||
@ -160,7 +160,7 @@ export default class ScheduleTrigger {
|
|||||||
{ config: { collection, limit, startsOn, repeat, endsOn }, allExecuted }: WorkflowModel,
|
{ config: { collection, limit, startsOn, repeat, endsOn }, allExecuted }: WorkflowModel,
|
||||||
currentDate: Date,
|
currentDate: Date,
|
||||||
) {
|
) {
|
||||||
const { db } = this.workflow.app;
|
const { dataSourceManager } = this.workflow.app;
|
||||||
if (limit && allExecuted >= limit) {
|
if (limit && allExecuted >= limit) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -174,6 +174,14 @@ export default class ScheduleTrigger {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [dataSourceName, collectionName] = parseCollectionName(collection);
|
||||||
|
const { collectionManager } = dataSourceManager.get(dataSourceName);
|
||||||
|
if (!(collectionManager instanceof SequelizeCollectionManager)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const { db } = collectionManager;
|
||||||
|
const { model } = collectionManager.getCollection(collectionName);
|
||||||
|
|
||||||
const range = this.cacheCycle * 2;
|
const range = this.cacheCycle * 2;
|
||||||
|
|
||||||
const conditions: any[] = [
|
const conditions: any[] = [
|
||||||
@ -191,9 +199,12 @@ export default class ScheduleTrigger {
|
|||||||
if (typeof repeat === 'number') {
|
if (typeof repeat === 'number') {
|
||||||
const tsFn = DialectTimestampFnMap[db.options.dialect];
|
const tsFn = DialectTimestampFnMap[db.options.dialect];
|
||||||
if (repeat > range && tsFn) {
|
if (repeat > range && tsFn) {
|
||||||
|
const { field } = model.getAttributes()[startsOn.field];
|
||||||
const modExp = fn(
|
const modExp = fn(
|
||||||
'MOD',
|
'MOD',
|
||||||
literal(`${Math.round(timestamp / 1000)} - ${tsFn(startsOn.field)}`),
|
literal(
|
||||||
|
`${Math.round(timestamp / 1000)} - ${db.sequelize.getQueryInterface().quoteIdentifiers(tsFn(field))}`,
|
||||||
|
),
|
||||||
Math.round(repeat / 1000),
|
Math.round(repeat / 1000),
|
||||||
);
|
);
|
||||||
conditions.push(where(modExp, { [Op.lt]: Math.round(range / 1000) }));
|
conditions.push(where(modExp, { [Op.lt]: Math.round(range / 1000) }));
|
||||||
@ -230,7 +241,6 @@ export default class ScheduleTrigger {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { model } = db.getCollection(collection);
|
|
||||||
return model.findAll({
|
return model.findAll({
|
||||||
where: {
|
where: {
|
||||||
[Op.and]: conditions,
|
[Op.and]: conditions,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user