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; };