Files
autoAiWorkSys/api/model/account_config.js
张成 4443d43ec1 1
2025-12-15 22:03:01 +08:00

159 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const Sequelize = require('sequelize');
/**
* 账号配置表模型
* 配置不同平台的账号设置
*/
module.exports = (db) => {
const account_config = db.define("account_config", {
account_id: {
comment: '账号ID关联 pla_account.id',
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true
},
platform_type: {
comment: '平台类型boss- Boss直聘, liepin- 猎聘)',
type: Sequelize.STRING(50),
allowNull: false,
defaultValue: 'boss'
},
// 平台相关配置JSON格式
platform_config: {
comment: '平台相关配置JSON对象',
type: Sequelize.JSON(),
allowNull: true,
get: function () {
const value = this.getDataValue('platform_config');
if (!value) return null;
if (typeof value === 'string') {
try {
return JSON.parse(value);
} catch (e) {
return null;
}
}
return value;
},
set: function (value) {
if (value === null || value === undefined) {
this.setDataValue('platform_config', null);
} else if (typeof value === 'string') {
this.setDataValue('platform_config', value);
} else {
this.setDataValue('platform_config', JSON.stringify(value));
}
},
defaultValue: null
},
// 自动投递配置
auto_deliver_config: {
comment: '自动投递配置JSON对象',
type: Sequelize.JSON(),
allowNull: true,
get: function () {
const value = this.getDataValue('auto_deliver_config');
if (!value) return null;
if (typeof value === 'string') {
try {
return JSON.parse(value);
} catch (e) {
return null;
}
}
return value;
},
set: function (value) {
if (value === null || value === undefined) {
this.setDataValue('auto_deliver_config', null);
} else if (typeof value === 'string') {
this.setDataValue('auto_deliver_config', value);
} else {
this.setDataValue('auto_deliver_config', JSON.stringify(value));
}
},
defaultValue: null
},
// 自动沟通配置
auto_chat_config: {
comment: '自动沟通配置JSON对象',
type: Sequelize.JSON(),
allowNull: true,
get: function () {
const value = this.getDataValue('auto_chat_config');
if (!value) return null;
if (typeof value === 'string') {
try {
return JSON.parse(value);
} catch (e) {
return null;
}
}
return value;
},
set: function (value) {
if (value === null || value === undefined) {
this.setDataValue('auto_chat_config', null);
} else if (typeof value === 'string') {
this.setDataValue('auto_chat_config', value);
} else {
this.setDataValue('auto_chat_config', JSON.stringify(value));
}
},
defaultValue: null
},
// 自动活跃配置
auto_active_config: {
comment: '自动活跃配置JSON对象',
type: Sequelize.JSON(),
allowNull: true,
get: function () {
const value = this.getDataValue('auto_active_config');
if (!value) return null;
if (typeof value === 'string') {
try {
return JSON.parse(value);
} catch (e) {
return null;
}
}
return value;
},
set: function (value) {
if (value === null || value === undefined) {
this.setDataValue('auto_active_config', null);
} else if (typeof value === 'string') {
this.setDataValue('auto_active_config', value);
} else {
this.setDataValue('auto_active_config', JSON.stringify(value));
}
},
defaultValue: null
},
// 备注
notes: {
comment: '备注',
type: Sequelize.TEXT,
allowNull: true,
defaultValue: ''
}
}, {
timestamps: true,
createdAt: 'created_time',
updatedAt: 'last_update_time',
indexes: [
{
unique: false,
fields: ['account_id']
},
{
unique: false,
fields: ['platform_type']
}
]
});
return account_config;
};