1
This commit is contained in:
@@ -223,7 +223,7 @@ module.exports = {
|
||||
* /admin_api/device/update-config:
|
||||
* post:
|
||||
* summary: 更新设备配置
|
||||
* description: 更新指定设备的配置信息
|
||||
* description: 更新指定设备的配置信息,保存到 pla_account 表的 deliver_config 字段
|
||||
* tags: [后台-设备管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -233,41 +233,46 @@ module.exports = {
|
||||
* type: object
|
||||
* required:
|
||||
* - sn_code
|
||||
* - config
|
||||
* - deliver_config
|
||||
* properties:
|
||||
* sn_code:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* config:
|
||||
* deliver_config:
|
||||
* type: object
|
||||
* description: 配置数据
|
||||
* description: 投递配置数据
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
*/
|
||||
'POST /device/update-config': async (ctx) => {
|
||||
const models = Framework.getModels();
|
||||
const { account_config } = models;
|
||||
const body = ctx.getBody();
|
||||
const { sn_code, config } = body;
|
||||
const { sn_code, deliver_config } = body;
|
||||
|
||||
if (!sn_code || !config) {
|
||||
return ctx.fail('设备SN码和配置数据不能为空');
|
||||
if (!sn_code) {
|
||||
return ctx.fail('设备SN码不能为空');
|
||||
}
|
||||
|
||||
// 从 pla_account 获取账号ID
|
||||
if (!deliver_config) {
|
||||
return ctx.fail('配置数据不能为空');
|
||||
}
|
||||
|
||||
// 从 pla_account 获取账号
|
||||
const { pla_account } = models;
|
||||
const account = await pla_account.findOne({ where: { sn_code } });
|
||||
if (!account) {
|
||||
return ctx.fail('设备不存在');
|
||||
}
|
||||
|
||||
// 更新 account_config 表的配置
|
||||
await account_config.upsert({
|
||||
account_id: account.id,
|
||||
platform_type: account.platform_type,
|
||||
platform_config: config
|
||||
});
|
||||
// 更新 pla_account 表的 deliver_config 字段
|
||||
await pla_account.update(
|
||||
{
|
||||
deliver_config: deliver_config,
|
||||
auto_deliver: deliver_config.auto_delivery ? 1 : 0
|
||||
},
|
||||
{ where: { id: account.id } }
|
||||
);
|
||||
|
||||
return ctx.success({ message: '设备配置更新成功' });
|
||||
},
|
||||
|
||||
@@ -170,7 +170,7 @@ module.exports = {
|
||||
* /api/user/delivery-config/get:
|
||||
* post:
|
||||
* summary: 获取投递配置
|
||||
* description: 根据设备SN码获取用户的投递配置,返回 account_config 表中的 auto_deliver_config 对象
|
||||
* description: 根据设备SN码获取用户的投递配置,返回 pla_account 表中的 deliver_config 对象
|
||||
* tags: [前端-用户管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -201,7 +201,7 @@ module.exports = {
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* auto_deliver_config:
|
||||
* deliver_config:
|
||||
* type: object
|
||||
* description: 自动投递配置对象,如果不存在则返回 null
|
||||
* nullable: true
|
||||
@@ -217,7 +217,7 @@ module.exports = {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
const { pla_account, account_config } = await Framework.getModels();
|
||||
const { pla_account } = await Framework.getModels();
|
||||
|
||||
// 根据 sn_code 查找账号
|
||||
const user = await pla_account.findOne({
|
||||
@@ -228,15 +228,10 @@ module.exports = {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 从 account_config 表获取配置
|
||||
const accountConfig = await account_config.findOne({
|
||||
where: { account_id: user.id }
|
||||
});
|
||||
// 从 pla_account 表的 deliver_config 字段获取配置
|
||||
const deliver_config = user.deliver_config || null;
|
||||
|
||||
// 直接返回 auto_deliver_config 对象
|
||||
const auto_deliver_config = accountConfig?.auto_deliver_config || null;
|
||||
|
||||
return ctx.success({ auto_deliver_config });
|
||||
return ctx.success({ deliver_config });
|
||||
} catch (error) {
|
||||
console.error('获取投递配置失败:', error);
|
||||
return ctx.fail('获取投递配置失败: ' + error.message);
|
||||
@@ -248,7 +243,7 @@ module.exports = {
|
||||
* /api/user/delivery-config/save:
|
||||
* post:
|
||||
* summary: 保存投递配置
|
||||
* description: 根据设备SN码保存用户的投递配置到 account_config 表的 auto_deliver_config 字段
|
||||
* description: 根据设备SN码保存用户的投递配置到 pla_account 表的 deliver_config 字段
|
||||
* tags: [前端-用户管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -258,12 +253,12 @@ module.exports = {
|
||||
* type: object
|
||||
* required:
|
||||
* - sn_code
|
||||
* - auto_deliver_config
|
||||
* - deliver_config
|
||||
* properties:
|
||||
* sn_code:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* auto_deliver_config:
|
||||
* deliver_config:
|
||||
* type: object
|
||||
* description: 自动投递配置对象
|
||||
* properties:
|
||||
@@ -308,18 +303,18 @@ module.exports = {
|
||||
try {
|
||||
console.log('[User Controller] 收到保存投递配置请求');
|
||||
const body = ctx.getBody();
|
||||
const { sn_code, auto_deliver_config } = body;
|
||||
console.log('[User Controller] sn_code:', sn_code, 'auto_deliver_config:', JSON.stringify(auto_deliver_config));
|
||||
const { sn_code, deliver_config } = body;
|
||||
console.log('[User Controller] sn_code:', sn_code, 'deliver_config:', JSON.stringify(deliver_config));
|
||||
|
||||
if (!sn_code) {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
if (!auto_deliver_config) {
|
||||
return ctx.fail('请提供 auto_deliver_config 配置对象');
|
||||
if (!deliver_config) {
|
||||
return ctx.fail('请提供 deliver_config 配置对象');
|
||||
}
|
||||
|
||||
const { pla_account, account_config } = await Framework.getModels();
|
||||
const { pla_account } = await Framework.getModels();
|
||||
|
||||
// 根据 sn_code 查找账号
|
||||
const user = await pla_account.findOne({
|
||||
@@ -330,34 +325,15 @@ module.exports = {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 查找或创建 account_config 记录
|
||||
const accountConfig = await account_config.findOne({
|
||||
where: { account_id: user.id }
|
||||
});
|
||||
|
||||
if (accountConfig) {
|
||||
// 更新现有配置
|
||||
await account_config.update(
|
||||
{ auto_deliver_config: auto_deliver_config },
|
||||
{ where: { account_id: user.id } }
|
||||
);
|
||||
} else {
|
||||
// 创建新配置
|
||||
await account_config.create({
|
||||
account_id: user.id,
|
||||
platform_type: user.platform_type || 'boss',
|
||||
auto_deliver_config: auto_deliver_config
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 更新 pla_account 表的 auto_deliver 字段
|
||||
// 更新 pla_account 表的 deliver_config 和 auto_deliver 字段
|
||||
await pla_account.update(
|
||||
{ auto_deliver: auto_deliver_config.autoDelivery ? 1 : 0 },
|
||||
{
|
||||
deliver_config: deliver_config,
|
||||
auto_deliver: deliver_config.auto_delivery ? 1 : 0
|
||||
},
|
||||
{ where: { id: user.id } }
|
||||
);
|
||||
|
||||
|
||||
return ctx.success({ message: '配置保存成功' });
|
||||
} catch (error) {
|
||||
console.error('保存投递配置失败:', error);
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
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']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// account_config.sync({ alter: true });
|
||||
|
||||
return account_config;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user