1
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
-- Active: 1763990602551@@192.144.167.231@3306@autoaiworksys
|
|
||||||
-- ============================================
|
|
||||||
-- 检查 account_config 表的状态
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 1. 检查表是否存在
|
|
||||||
SELECT
|
|
||||||
TABLE_NAME,
|
|
||||||
TABLE_COMMENT,
|
|
||||||
ENGINE,
|
|
||||||
TABLE_ROWS,
|
|
||||||
CREATE_TIME,
|
|
||||||
UPDATE_TIME
|
|
||||||
FROM INFORMATION_SCHEMA.TABLES
|
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
|
||||||
AND TABLE_NAME = 'account_config';
|
|
||||||
|
|
||||||
-- 2. 查看表结构
|
|
||||||
DESCRIBE account_config;
|
|
||||||
|
|
||||||
-- 或者使用:
|
|
||||||
-- SHOW CREATE TABLE account_config;
|
|
||||||
|
|
||||||
-- 3. 查看表中的数据(应该是空的,因为这是配置表,需要手动创建记录)
|
|
||||||
SELECT * FROM account_config;
|
|
||||||
|
|
||||||
-- 4. 查看 pla_account 表中的账号,看看有哪些账号可以创建配置
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
sn_code,
|
|
||||||
name,
|
|
||||||
platform_type,
|
|
||||||
login_name,
|
|
||||||
is_enabled
|
|
||||||
FROM pla_account
|
|
||||||
WHERE is_delete = 0
|
|
||||||
ORDER BY id;
|
|
||||||
|
|
||||||
-- 5. 如果需要为所有账号创建默认配置,可以执行以下 SQL:
|
|
||||||
-- INSERT INTO account_config (account_id, platform_type, notes)
|
|
||||||
-- SELECT
|
|
||||||
-- id AS account_id,
|
|
||||||
-- platform_type,
|
|
||||||
-- '默认配置' AS notes
|
|
||||||
-- FROM pla_account
|
|
||||||
-- WHERE is_delete = 0
|
|
||||||
-- AND id NOT IN (SELECT account_id FROM account_config);
|
|
||||||
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
-- Active: 1763990602551@@192.144.167.231@3306@autoaiworksys
|
|
||||||
-- ============================================
|
|
||||||
-- 为 pla_account 表中的所有账号创建默认的 account_config 配置
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 为所有启用的账号创建默认配置(如果配置不存在)
|
|
||||||
INSERT INTO account_config (account_id, platform_type, notes, created_time, last_update_time)
|
|
||||||
SELECT
|
|
||||||
id AS account_id,
|
|
||||||
platform_type,
|
|
||||||
'默认配置' AS notes,
|
|
||||||
NOW() AS created_time,
|
|
||||||
NOW() AS last_update_time
|
|
||||||
FROM pla_account
|
|
||||||
WHERE is_delete = 0
|
|
||||||
AND id NOT IN (SELECT account_id FROM account_config)
|
|
||||||
ON DUPLICATE KEY UPDATE
|
|
||||||
last_update_time = NOW();
|
|
||||||
|
|
||||||
-- 查看创建的结果
|
|
||||||
SELECT
|
|
||||||
ac.account_id,
|
|
||||||
pa.name AS account_name,
|
|
||||||
pa.sn_code,
|
|
||||||
ac.platform_type,
|
|
||||||
ac.platform_config,
|
|
||||||
ac.auto_deliver_config,
|
|
||||||
ac.auto_chat_config,
|
|
||||||
ac.auto_active_config,
|
|
||||||
ac.notes,
|
|
||||||
ac.created_time,
|
|
||||||
ac.last_update_time
|
|
||||||
FROM account_config ac
|
|
||||||
INNER JOIN pla_account pa ON ac.account_id = pa.id
|
|
||||||
ORDER BY ac.account_id;
|
|
||||||
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
-- ============================================
|
|
||||||
-- 数据库迁移脚本:移除 device_status,迁移到 pla_account
|
|
||||||
-- 执行时间:2025-01-XX
|
|
||||||
-- 说明:
|
|
||||||
-- 1. 为 pla_account 表添加 device_id 字段
|
|
||||||
-- 2. 删除 device_status 表(如果存在)
|
|
||||||
-- 3. 创建 account_config 表(账号配置表)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 1. 为 pla_account 表添加 device_id 字段
|
|
||||||
-- ============================================
|
|
||||||
SET @exist_device_id = (
|
|
||||||
SELECT COUNT(*)
|
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
|
||||||
AND TABLE_NAME = 'pla_account'
|
|
||||||
AND COLUMN_NAME = 'device_id'
|
|
||||||
);
|
|
||||||
|
|
||||||
SET @sql_device_id = IF(@exist_device_id = 0,
|
|
||||||
'ALTER TABLE `pla_account`
|
|
||||||
ADD COLUMN `device_id` VARCHAR(200) NULL DEFAULT '''' COMMENT ''设备ID''
|
|
||||||
AFTER `sn_code`',
|
|
||||||
'SELECT ''字段 device_id 已存在,跳过添加'' AS message'
|
|
||||||
);
|
|
||||||
|
|
||||||
PREPARE stmt FROM @sql_device_id;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 2. 创建 account_config 表(如果不存在)
|
|
||||||
-- ============================================
|
|
||||||
CREATE TABLE IF NOT EXISTS `account_config` (
|
|
||||||
`account_id` INT NOT NULL COMMENT '账号ID(关联 pla_account.id)',
|
|
||||||
`platform_type` VARCHAR(50) NOT NULL DEFAULT 'boss' COMMENT '平台类型(boss- Boss直聘, liepin- 猎聘)',
|
|
||||||
`platform_config` JSON NULL COMMENT '平台相关配置(JSON对象)',
|
|
||||||
`auto_deliver_config` JSON NULL COMMENT '自动投递配置(JSON对象)',
|
|
||||||
`auto_chat_config` JSON NULL COMMENT '自动沟通配置(JSON对象)',
|
|
||||||
`auto_active_config` JSON NULL COMMENT '自动活跃配置(JSON对象)',
|
|
||||||
`notes` TEXT NULL DEFAULT '' COMMENT '备注',
|
|
||||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
PRIMARY KEY (`account_id`),
|
|
||||||
INDEX `idx_platform_type` (`platform_type`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账号配置表';
|
|
||||||
|
|
||||||
-- 如果 MySQL 版本低于 5.7,不支持 JSON 类型,可以使用以下 SQL(将 JSON 改为 TEXT):
|
|
||||||
/*
|
|
||||||
CREATE TABLE IF NOT EXISTS `account_config` (
|
|
||||||
`account_id` INT NOT NULL COMMENT '账号ID(关联 pla_account.id)',
|
|
||||||
`platform_type` VARCHAR(50) NOT NULL DEFAULT 'boss' COMMENT '平台类型(boss- Boss直聘, liepin- 猎聘)',
|
|
||||||
`platform_config` TEXT NULL COMMENT '平台相关配置(JSON对象)',
|
|
||||||
`auto_deliver_config` TEXT NULL COMMENT '自动投递配置(JSON对象)',
|
|
||||||
`auto_chat_config` TEXT NULL COMMENT '自动沟通配置(JSON对象)',
|
|
||||||
`auto_active_config` TEXT NULL COMMENT '自动活跃配置(JSON对象)',
|
|
||||||
`notes` TEXT NULL DEFAULT '' COMMENT '备注',
|
|
||||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
PRIMARY KEY (`account_id`),
|
|
||||||
INDEX `idx_platform_type` (`platform_type`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账号配置表';
|
|
||||||
*/
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 3. 可选:迁移 device_status 中的 device_id 到 pla_account
|
|
||||||
-- ============================================
|
|
||||||
-- 注意:此步骤只在 device_status 表存在且有数据时执行
|
|
||||||
-- 如果 device_status 表已不存在,可以跳过此步骤
|
|
||||||
|
|
||||||
-- 检查 device_status 表是否存在
|
|
||||||
SET @table_exists = (
|
|
||||||
SELECT COUNT(*)
|
|
||||||
FROM INFORMATION_SCHEMA.TABLES
|
|
||||||
WHERE TABLE_SCHEMA = DATABASE()
|
|
||||||
AND TABLE_NAME = 'device_status'
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 如果 device_status 表存在,尝试迁移 device_id 数据
|
|
||||||
-- 注意:此迁移假设 device_status 使用 sn_code 作为主键,pla_account 也有 sn_code 字段
|
|
||||||
-- 如果结构不同,请手动调整迁移 SQL
|
|
||||||
/*
|
|
||||||
SET @sql_migrate_device_id = IF(@table_exists > 0,
|
|
||||||
'UPDATE `pla_account` pa
|
|
||||||
INNER JOIN `device_status` ds ON pa.sn_code = ds.sn_code
|
|
||||||
SET pa.device_id = ds.device_id
|
|
||||||
WHERE pa.device_id IS NULL OR pa.device_id = ''''
|
|
||||||
AND ds.device_id IS NOT NULL AND ds.device_id != ''''',
|
|
||||||
'SELECT ''device_status 表不存在,跳过数据迁移'' AS message'
|
|
||||||
);
|
|
||||||
|
|
||||||
PREPARE stmt FROM @sql_migrate_device_id;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
*/
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 4. 删除 device_status 表(谨慎操作!)
|
|
||||||
-- ============================================
|
|
||||||
-- ⚠️ 警告:删除表会丢失所有数据,请确保已经备份或迁移了需要的数据
|
|
||||||
-- 如果确定要删除 device_status 表,请取消下面 SQL 的注释
|
|
||||||
|
|
||||||
-- DROP TABLE IF EXISTS `device_status`;
|
|
||||||
|
|
||||||
-- 如果不想直接删除,可以重命名表作为备份:
|
|
||||||
-- RENAME TABLE `device_status` TO `device_status_backup_202501XX`;
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 注意事项
|
|
||||||
-- ============================================
|
|
||||||
-- 1. 执行前请先备份数据库
|
|
||||||
-- 2. device_id 字段允许为 NULL,旧数据可能没有 device_id
|
|
||||||
-- 3. account_config 表使用 account_id 作为主键,关联 pla_account.id
|
|
||||||
-- 4. 如果 MySQL 版本低于 5.7,请使用 TEXT 类型替代 JSON 类型
|
|
||||||
-- 5. device_status 表的删除操作是可选的,建议先重命名备份
|
|
||||||
-- 6. 如果 device_status 表不存在,相关的 SQL 会自动跳过
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 验证执行结果
|
|
||||||
-- ============================================
|
|
||||||
-- 执行以下 SQL 验证迁移结果:
|
|
||||||
|
|
||||||
-- 1. 检查 pla_account 表的 device_id 字段
|
|
||||||
-- DESCRIBE pla_account;
|
|
||||||
|
|
||||||
-- 2. 检查 account_config 表是否创建成功
|
|
||||||
-- DESCRIBE account_config;
|
|
||||||
|
|
||||||
-- 3. 检查 device_status 表是否还存在(如果已删除,此查询会报错)
|
|
||||||
-- SELECT COUNT(*) FROM device_status;
|
|
||||||
|
|
||||||
-- 4. 查看已迁移 device_id 的账号数量
|
|
||||||
-- SELECT COUNT(*) FROM pla_account WHERE device_id IS NOT NULL AND device_id != '';
|
|
||||||
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
-- Active: 1763990602551@@192.144.167.231@3306@autoaiworksys
|
|
||||||
-- ============================================
|
|
||||||
-- 数据库迁移脚本(简化版):移除 device_status,迁移到 pla_account
|
|
||||||
-- 执行时间:2025-01-XX
|
|
||||||
-- 说明:简化版 SQL,直接执行 ALTER 和 CREATE 语句
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 1. 为 pla_account 表添加 device_id 字段
|
|
||||||
-- 注意:如果字段已存在会报错,请先检查字段是否存在
|
|
||||||
-- 检查方法:DESCRIBE pla_account; 或 SHOW COLUMNS FROM pla_account LIKE 'device_id';
|
|
||||||
ALTER TABLE `pla_account`
|
|
||||||
ADD COLUMN `device_id` VARCHAR(200) NULL DEFAULT '' COMMENT '设备ID'
|
|
||||||
AFTER `sn_code`;
|
|
||||||
|
|
||||||
-- 2. 创建 account_config 表
|
|
||||||
CREATE TABLE IF NOT EXISTS `account_config` (
|
|
||||||
`account_id` INT NOT NULL COMMENT '账号ID(关联 pla_account.id)',
|
|
||||||
`platform_type` VARCHAR(50) NOT NULL DEFAULT 'boss' COMMENT '平台类型(boss- Boss直聘, liepin- 猎聘)',
|
|
||||||
`platform_config` JSON NULL COMMENT '平台相关配置(JSON对象)',
|
|
||||||
`auto_deliver_config` JSON NULL COMMENT '自动投递配置(JSON对象)',
|
|
||||||
`auto_chat_config` JSON NULL COMMENT '自动沟通配置(JSON对象)',
|
|
||||||
`auto_active_config` JSON NULL COMMENT '自动活跃配置(JSON对象)',
|
|
||||||
`notes` TEXT NULL COMMENT '备注',
|
|
||||||
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`last_update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
PRIMARY KEY (`account_id`),
|
|
||||||
INDEX `idx_platform_type` (`platform_type`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账号配置表';
|
|
||||||
|
|
||||||
-- 如果 MySQL 版本低于 5.7,不支持 JSON 类型,请使用以下 SQL(将 JSON 改为 TEXT):
|
|
||||||
/*
|
|
||||||
CREATE TABLE IF NOT EXISTS `account_config` (
|
|
||||||
`account_id` INT NOT NULL COMMENT '账号ID(关联 pla_account.id)',
|
|
||||||
`platform_type` VARCHAR(50) NOT NULL DEFAULT 'boss' COMMENT '平台类型(boss- Boss直聘, liepin- 猎聘)',
|
|
||||||
`platform_config` TEXT NULL COMMENT '平台相关配置(JSON对象)',
|
|
||||||
`auto_deliver_config` TEXT NULL COMMENT '自动投递配置(JSON对象)',
|
|
||||||
`auto_chat_config` TEXT NULL COMMENT '自动沟通配置(JSON对象)',
|
|
||||||
`auto_active_config` TEXT NULL COMMENT '自动活跃配置(JSON对象)',
|
|
||||||
`notes` TEXT NULL DEFAULT '' COMMENT '备注',
|
|
||||||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
||||||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
||||||
PRIMARY KEY (`account_id`),
|
|
||||||
INDEX `idx_platform_type` (`platform_type`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='账号配置表';
|
|
||||||
*/
|
|
||||||
|
|
||||||
-- 3. 可选:删除 device_status 表(谨慎操作!)
|
|
||||||
-- ⚠️ 警告:删除表会丢失所有数据,请确保已经备份或迁移了需要的数据
|
|
||||||
-- DROP TABLE IF EXISTS `device_status`;
|
|
||||||
|
|
||||||
-- 或者重命名表作为备份:
|
|
||||||
-- RENAME TABLE `device_status` TO `device_status_backup_202501XX`;
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 注意事项
|
|
||||||
-- ============================================
|
|
||||||
-- 1. 执行前请先备份数据库
|
|
||||||
-- 2. 如果字段已存在,使用 IF NOT EXISTS 可以避免报错(MySQL 8.0.19+)
|
|
||||||
-- 3. 如果 MySQL 版本较低,请手动检查字段是否存在再执行
|
|
||||||
-- 4. device_status 表的删除操作是可选的,建议先重命名备份
|
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ module.exports = {
|
|||||||
* /admin_api/device/update-config:
|
* /admin_api/device/update-config:
|
||||||
* post:
|
* post:
|
||||||
* summary: 更新设备配置
|
* summary: 更新设备配置
|
||||||
* description: 更新指定设备的配置信息
|
* description: 更新指定设备的配置信息,保存到 pla_account 表的 deliver_config 字段
|
||||||
* tags: [后台-设备管理]
|
* tags: [后台-设备管理]
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
@@ -233,41 +233,46 @@ module.exports = {
|
|||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
* - sn_code
|
* - sn_code
|
||||||
* - config
|
* - deliver_config
|
||||||
* properties:
|
* properties:
|
||||||
* sn_code:
|
* sn_code:
|
||||||
* type: string
|
* type: string
|
||||||
* description: 设备SN码
|
* description: 设备SN码
|
||||||
* config:
|
* deliver_config:
|
||||||
* type: object
|
* type: object
|
||||||
* description: 配置数据
|
* description: 投递配置数据
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: 更新成功
|
* description: 更新成功
|
||||||
*/
|
*/
|
||||||
'POST /device/update-config': async (ctx) => {
|
'POST /device/update-config': async (ctx) => {
|
||||||
const models = Framework.getModels();
|
const models = Framework.getModels();
|
||||||
const { account_config } = models;
|
|
||||||
const body = ctx.getBody();
|
const body = ctx.getBody();
|
||||||
const { sn_code, config } = body;
|
const { sn_code, deliver_config } = body;
|
||||||
|
|
||||||
if (!sn_code || !config) {
|
if (!sn_code) {
|
||||||
return ctx.fail('设备SN码和配置数据不能为空');
|
return ctx.fail('设备SN码不能为空');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 pla_account 获取账号ID
|
if (!deliver_config) {
|
||||||
|
return ctx.fail('配置数据不能为空');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从 pla_account 获取账号
|
||||||
const { pla_account } = models;
|
const { pla_account } = models;
|
||||||
const account = await pla_account.findOne({ where: { sn_code } });
|
const account = await pla_account.findOne({ where: { sn_code } });
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return ctx.fail('设备不存在');
|
return ctx.fail('设备不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新 account_config 表的配置
|
// 更新 pla_account 表的 deliver_config 字段
|
||||||
await account_config.upsert({
|
await pla_account.update(
|
||||||
account_id: account.id,
|
{
|
||||||
platform_type: account.platform_type,
|
deliver_config: deliver_config,
|
||||||
platform_config: config
|
auto_deliver: deliver_config.auto_delivery ? 1 : 0
|
||||||
});
|
},
|
||||||
|
{ where: { id: account.id } }
|
||||||
|
);
|
||||||
|
|
||||||
return ctx.success({ message: '设备配置更新成功' });
|
return ctx.success({ message: '设备配置更新成功' });
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ module.exports = {
|
|||||||
* /api/user/delivery-config/get:
|
* /api/user/delivery-config/get:
|
||||||
* post:
|
* post:
|
||||||
* summary: 获取投递配置
|
* summary: 获取投递配置
|
||||||
* description: 根据设备SN码获取用户的投递配置,返回 account_config 表中的 auto_deliver_config 对象
|
* description: 根据设备SN码获取用户的投递配置,返回 pla_account 表中的 deliver_config 对象
|
||||||
* tags: [前端-用户管理]
|
* tags: [前端-用户管理]
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
@@ -201,7 +201,7 @@ module.exports = {
|
|||||||
* data:
|
* data:
|
||||||
* type: object
|
* type: object
|
||||||
* properties:
|
* properties:
|
||||||
* auto_deliver_config:
|
* deliver_config:
|
||||||
* type: object
|
* type: object
|
||||||
* description: 自动投递配置对象,如果不存在则返回 null
|
* description: 自动投递配置对象,如果不存在则返回 null
|
||||||
* nullable: true
|
* nullable: true
|
||||||
@@ -217,7 +217,7 @@ module.exports = {
|
|||||||
return ctx.fail('请提供设备SN码');
|
return ctx.fail('请提供设备SN码');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { pla_account, account_config } = await Framework.getModels();
|
const { pla_account } = await Framework.getModels();
|
||||||
|
|
||||||
// 根据 sn_code 查找账号
|
// 根据 sn_code 查找账号
|
||||||
const user = await pla_account.findOne({
|
const user = await pla_account.findOne({
|
||||||
@@ -228,15 +228,10 @@ module.exports = {
|
|||||||
return ctx.fail('用户不存在');
|
return ctx.fail('用户不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 account_config 表获取配置
|
// 从 pla_account 表的 deliver_config 字段获取配置
|
||||||
const accountConfig = await account_config.findOne({
|
const deliver_config = user.deliver_config || null;
|
||||||
where: { account_id: user.id }
|
|
||||||
});
|
|
||||||
|
|
||||||
// 直接返回 auto_deliver_config 对象
|
return ctx.success({ deliver_config });
|
||||||
const auto_deliver_config = accountConfig?.auto_deliver_config || null;
|
|
||||||
|
|
||||||
return ctx.success({ auto_deliver_config });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取投递配置失败:', error);
|
console.error('获取投递配置失败:', error);
|
||||||
return ctx.fail('获取投递配置失败: ' + error.message);
|
return ctx.fail('获取投递配置失败: ' + error.message);
|
||||||
@@ -248,7 +243,7 @@ module.exports = {
|
|||||||
* /api/user/delivery-config/save:
|
* /api/user/delivery-config/save:
|
||||||
* post:
|
* post:
|
||||||
* summary: 保存投递配置
|
* summary: 保存投递配置
|
||||||
* description: 根据设备SN码保存用户的投递配置到 account_config 表的 auto_deliver_config 字段
|
* description: 根据设备SN码保存用户的投递配置到 pla_account 表的 deliver_config 字段
|
||||||
* tags: [前端-用户管理]
|
* tags: [前端-用户管理]
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
@@ -258,12 +253,12 @@ module.exports = {
|
|||||||
* type: object
|
* type: object
|
||||||
* required:
|
* required:
|
||||||
* - sn_code
|
* - sn_code
|
||||||
* - auto_deliver_config
|
* - deliver_config
|
||||||
* properties:
|
* properties:
|
||||||
* sn_code:
|
* sn_code:
|
||||||
* type: string
|
* type: string
|
||||||
* description: 设备SN码
|
* description: 设备SN码
|
||||||
* auto_deliver_config:
|
* deliver_config:
|
||||||
* type: object
|
* type: object
|
||||||
* description: 自动投递配置对象
|
* description: 自动投递配置对象
|
||||||
* properties:
|
* properties:
|
||||||
@@ -308,18 +303,18 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
console.log('[User Controller] 收到保存投递配置请求');
|
console.log('[User Controller] 收到保存投递配置请求');
|
||||||
const body = ctx.getBody();
|
const body = ctx.getBody();
|
||||||
const { sn_code, auto_deliver_config } = body;
|
const { sn_code, deliver_config } = body;
|
||||||
console.log('[User Controller] sn_code:', sn_code, 'auto_deliver_config:', JSON.stringify(auto_deliver_config));
|
console.log('[User Controller] sn_code:', sn_code, 'deliver_config:', JSON.stringify(deliver_config));
|
||||||
|
|
||||||
if (!sn_code) {
|
if (!sn_code) {
|
||||||
return ctx.fail('请提供设备SN码');
|
return ctx.fail('请提供设备SN码');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!auto_deliver_config) {
|
if (!deliver_config) {
|
||||||
return ctx.fail('请提供 auto_deliver_config 配置对象');
|
return ctx.fail('请提供 deliver_config 配置对象');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { pla_account, account_config } = await Framework.getModels();
|
const { pla_account } = await Framework.getModels();
|
||||||
|
|
||||||
// 根据 sn_code 查找账号
|
// 根据 sn_code 查找账号
|
||||||
const user = await pla_account.findOne({
|
const user = await pla_account.findOne({
|
||||||
@@ -330,34 +325,15 @@ module.exports = {
|
|||||||
return ctx.fail('用户不存在');
|
return ctx.fail('用户不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找或创建 account_config 记录
|
// 更新 pla_account 表的 deliver_config 和 auto_deliver 字段
|
||||||
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 字段
|
|
||||||
await pla_account.update(
|
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 } }
|
{ where: { id: user.id } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
return ctx.success({ message: '配置保存成功' });
|
return ctx.success({ message: '配置保存成功' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('保存投递配置失败:', 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