1
This commit is contained in:
@@ -471,18 +471,33 @@ module.exports = {
|
||||
const { sn_code } = body;
|
||||
if (!sn_code) return ctx.fail('请提供设备SN码');
|
||||
|
||||
const { pla_account } = await Framework.getModels();
|
||||
const { pla_account, resume_info } = await Framework.getModels();
|
||||
const user = await pla_account.findOne({ where: { sn_code } });
|
||||
if (!user) return ctx.fail('用户不存在');
|
||||
|
||||
const u = user.toJSON ? user.toJSON() : user;
|
||||
return ctx.success({
|
||||
const result = {
|
||||
deliver_config: u.deliver_config || null,
|
||||
chat_strategy: u.chat_strategy || null,
|
||||
active_actions: u.active_actions || null,
|
||||
auto_chat: u.auto_chat != null ? !!u.auto_chat : false,
|
||||
auto_active: u.auto_active != null ? !!u.auto_active : false
|
||||
};
|
||||
|
||||
const platform = u.platform_type || 'boss';
|
||||
const resume = await resume_info.findOne({
|
||||
where: { sn_code, platform, isActive: true },
|
||||
order: [['last_modify_time', 'DESC']]
|
||||
});
|
||||
if (resume) {
|
||||
const r = resume.toJSON ? resume.toJSON() : resume;
|
||||
result.job_listings = Array.isArray(r.job_listings) ? r.job_listings : [];
|
||||
result.deliver_tab_label = r.deliver_tab_label != null ? String(r.deliver_tab_label) : '';
|
||||
} else {
|
||||
result.job_listings = [];
|
||||
result.deliver_tab_label = '';
|
||||
}
|
||||
return ctx.success(result);
|
||||
} catch (error) {
|
||||
console.error('[获取账号配置失败]', error);
|
||||
return ctx.fail('获取账号配置失败');
|
||||
@@ -495,10 +510,10 @@ module.exports = {
|
||||
'POST /user/account-config/save': async (ctx) => {
|
||||
try {
|
||||
const body = ctx.getBody();
|
||||
const { sn_code, deliver_config, chat_strategy, active_actions } = body;
|
||||
const { sn_code, deliver_config, chat_strategy, active_actions, deliver_tab_label, job_listings } = body;
|
||||
if (!sn_code) return ctx.fail('请提供设备SN码');
|
||||
|
||||
const { pla_account } = await Framework.getModels();
|
||||
const { pla_account, resume_info } = await Framework.getModels();
|
||||
const user = await pla_account.findOne({ where: { sn_code } });
|
||||
if (!user) return ctx.fail('用户不存在');
|
||||
|
||||
@@ -529,9 +544,37 @@ module.exports = {
|
||||
updateData.active_actions = active_actions;
|
||||
if (active_actions.auto_active !== undefined) updateData.auto_active = active_actions.auto_active ? 1 : 0;
|
||||
}
|
||||
if (Object.keys(updateData).length === 0) return ctx.success({ message: '无更新' });
|
||||
if (deliver_tab_label !== undefined || job_listings !== undefined) {
|
||||
const platform = user.platform_type || 'boss';
|
||||
const account_id = user.account_id != null ? String(user.account_id) : (user.id != null ? String(user.id) : '');
|
||||
let resume = await resume_info.findOne({
|
||||
where: { sn_code, platform },
|
||||
order: [['last_modify_time', 'DESC']]
|
||||
});
|
||||
const resumePayload = {};
|
||||
if (deliver_tab_label !== undefined) resumePayload.deliver_tab_label = deliver_tab_label;
|
||||
if (job_listings !== undefined) resumePayload.job_listings = Array.isArray(job_listings) ? job_listings : [];
|
||||
if (resume) {
|
||||
await resume_info.update(resumePayload, { where: { id: resume.id } });
|
||||
} else {
|
||||
await resume_info.create({
|
||||
sn_code,
|
||||
account_id: account_id || '',
|
||||
platform,
|
||||
resumeId: '',
|
||||
deliver_tab_label: resumePayload.deliver_tab_label != null ? resumePayload.deliver_tab_label : '',
|
||||
job_listings: resumePayload.job_listings || [],
|
||||
isActive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await pla_account.update(updateData, { where: { id: user.id } });
|
||||
if (Object.keys(updateData).length === 0 && deliver_tab_label === undefined && job_listings === undefined) {
|
||||
return ctx.success({ message: '无更新' });
|
||||
}
|
||||
if (Object.keys(updateData).length > 0) {
|
||||
await pla_account.update(updateData, { where: { id: user.id } });
|
||||
}
|
||||
return ctx.success({ message: '配置保存成功' });
|
||||
} catch (error) {
|
||||
console.error('[保存账号配置失败]', error);
|
||||
|
||||
Reference in New Issue
Block a user