1
This commit is contained in:
@@ -167,73 +167,10 @@ module.exports = {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/user/delivery-config:
|
||||
* get:
|
||||
* summary: 获取投递配置
|
||||
* description: 根据设备SN码获取用户的投递配置
|
||||
* tags: [前端-用户管理]
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: sn_code
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
*/
|
||||
'GET /user/delivery-config': async (ctx) => {
|
||||
try {
|
||||
console.log('[User Controller] 收到获取投递配置请求');
|
||||
const { sn_code } = ctx.query;
|
||||
console.log('[User Controller] sn_code:', sn_code);
|
||||
|
||||
if (!sn_code) {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
const { pla_account } = await Framework.getModels();
|
||||
const user = await pla_account.findOne({
|
||||
where: { sn_code }
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 从数据库获取配置
|
||||
const autoDelivery = user.auto_deliver === 1;
|
||||
const deliverConfig = user.deliver_config || {};
|
||||
|
||||
// 转换配置格式为前端需要的格式
|
||||
const config = {
|
||||
autoDelivery: autoDelivery,
|
||||
interval: deliverConfig.deliver_interval || 30,
|
||||
minSalary: deliverConfig.min_salary || 0,
|
||||
maxSalary: deliverConfig.max_salary || 0,
|
||||
scrollPages: deliverConfig.page_count || 3,
|
||||
maxPerBatch: deliverConfig.max_deliver || 10,
|
||||
filterKeywords: deliverConfig.filter_keywords || [],
|
||||
excludeKeywords: deliverConfig.exclude_keywords || [],
|
||||
startTime: deliverConfig.time_range?.start_time || '09:00',
|
||||
endTime: deliverConfig.time_range?.end_time || '18:00',
|
||||
workdaysOnly: deliverConfig.time_range?.workdays_only === 1 || deliverConfig.time_range?.workdays_only === true
|
||||
};
|
||||
|
||||
return ctx.success(config);
|
||||
} catch (error) {
|
||||
console.error('获取投递配置失败:', error);
|
||||
return ctx.fail('获取投递配置失败: ' + error.message);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/user/delivery-config:
|
||||
* /api/user/delivery-config/get:
|
||||
* post:
|
||||
* summary: 保存投递配置
|
||||
* description: 根据设备SN码保存用户的投递配置
|
||||
* summary: 获取投递配置
|
||||
* description: 根据设备SN码获取用户的投递配置,返回 account_config 表中的 auto_deliver_config 对象
|
||||
* tags: [前端-用户管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -247,29 +184,42 @@ module.exports = {
|
||||
* sn_code:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* config:
|
||||
* type: object
|
||||
* description: 投递配置
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 保存成功
|
||||
* description: 获取成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* code:
|
||||
* type: integer
|
||||
* example: 0
|
||||
* message:
|
||||
* type: string
|
||||
* example: 'success'
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* auto_deliver_config:
|
||||
* type: object
|
||||
* description: 自动投递配置对象,如果不存在则返回 null
|
||||
* nullable: true
|
||||
*/
|
||||
'POST /user/delivery-config': async (ctx) => {
|
||||
'POST /user/delivery-config/get': async (ctx) => {
|
||||
try {
|
||||
console.log('[User Controller] 收到保存投递配置请求');
|
||||
console.log('[User Controller] 收到获取投递配置请求');
|
||||
const body = ctx.getBody();
|
||||
const { sn_code, config } = body;
|
||||
console.log('[User Controller] sn_code:', sn_code, 'config:', JSON.stringify(config));
|
||||
const { sn_code } = body;
|
||||
console.log('[User Controller] sn_code:', sn_code);
|
||||
|
||||
if (!sn_code) {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
return ctx.fail('请提供配置信息');
|
||||
}
|
||||
const { pla_account, account_config } = await Framework.getModels();
|
||||
|
||||
const { pla_account } = await Framework.getModels();
|
||||
// 根据 sn_code 查找账号
|
||||
const user = await pla_account.findOne({
|
||||
where: { sn_code }
|
||||
});
|
||||
@@ -278,30 +228,135 @@ module.exports = {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 转换前端配置格式为数据库格式
|
||||
const deliverConfig = {
|
||||
deliver_interval: config.interval || 30,
|
||||
min_salary: config.minSalary || 0,
|
||||
max_salary: config.maxSalary || 0,
|
||||
page_count: config.scrollPages || 3,
|
||||
max_deliver: config.maxPerBatch || 10,
|
||||
filter_keywords: config.filterKeywords || [],
|
||||
exclude_keywords: config.excludeKeywords || [],
|
||||
time_range: {
|
||||
start_time: config.startTime || '09:00',
|
||||
end_time: config.endTime || '18:00',
|
||||
workdays_only: config.workdaysOnly ? 1 : 0
|
||||
}
|
||||
};
|
||||
// 从 account_config 表获取配置
|
||||
const accountConfig = await account_config.findOne({
|
||||
where: { account_id: user.id }
|
||||
});
|
||||
|
||||
// 更新数据库
|
||||
await pla_account.update(
|
||||
{
|
||||
auto_deliver: config.autoDelivery ? 1 : 0,
|
||||
deliver_config: deliverConfig
|
||||
// 直接返回 auto_deliver_config 对象
|
||||
const auto_deliver_config = accountConfig?.auto_deliver_config || null;
|
||||
|
||||
return ctx.success({ auto_deliver_config });
|
||||
} catch (error) {
|
||||
console.error('获取投递配置失败:', error);
|
||||
return ctx.fail('获取投递配置失败: ' + error.message);
|
||||
}
|
||||
},
|
||||
{ where: { sn_code } }
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/user/delivery-config/save:
|
||||
* post:
|
||||
* summary: 保存投递配置
|
||||
* description: 根据设备SN码保存用户的投递配置到 account_config 表的 auto_deliver_config 字段
|
||||
* tags: [前端-用户管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - sn_code
|
||||
* - auto_deliver_config
|
||||
* properties:
|
||||
* sn_code:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* auto_deliver_config:
|
||||
* type: object
|
||||
* description: 自动投递配置对象
|
||||
* properties:
|
||||
* auto_delivery:
|
||||
* type: boolean
|
||||
* description: 是否启用自动投递
|
||||
* interval:
|
||||
* type: integer
|
||||
* description: 投递间隔(分钟)
|
||||
* min_salary:
|
||||
* type: integer
|
||||
* description: 最低薪资
|
||||
* max_salary:
|
||||
* type: integer
|
||||
* description: 最高薪资
|
||||
* scroll_pages:
|
||||
* type: integer
|
||||
* description: 滚动页数
|
||||
* max_per_batch:
|
||||
* type: integer
|
||||
* description: 每批最多投递数
|
||||
* filter_keywords:
|
||||
* type: string
|
||||
* description: 过滤关键词
|
||||
* exclude_keywords:
|
||||
* type: string
|
||||
* description: 排除关键词
|
||||
* start_time:
|
||||
* type: string
|
||||
* description: 开始时间(格式:HH:mm)
|
||||
* end_time:
|
||||
* type: string
|
||||
* description: 结束时间(格式:HH:mm)
|
||||
* workdays_only:
|
||||
* type: boolean
|
||||
* description: 仅工作日
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 保存成功
|
||||
*/
|
||||
'POST /user/delivery-config/save': async (ctx) => {
|
||||
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));
|
||||
|
||||
if (!sn_code) {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
if (!auto_deliver_config) {
|
||||
return ctx.fail('请提供 auto_deliver_config 配置对象');
|
||||
}
|
||||
|
||||
const { pla_account, account_config } = await Framework.getModels();
|
||||
|
||||
// 根据 sn_code 查找账号
|
||||
const user = await pla_account.findOne({
|
||||
where: { sn_code }
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
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 字段
|
||||
await pla_account.update(
|
||||
{ auto_deliver: auto_deliver_config.autoDelivery ? 1 : 0 },
|
||||
{ where: { id: user.id } }
|
||||
);
|
||||
|
||||
|
||||
return ctx.success({ message: '配置保存成功' });
|
||||
} catch (error) {
|
||||
|
||||
@@ -153,6 +153,8 @@ module.exports = (db) => {
|
||||
]
|
||||
});
|
||||
|
||||
// account_config.sync({ alter: true });
|
||||
|
||||
return account_config;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user