1
This commit is contained in:
@@ -206,6 +206,83 @@ module.exports = {
|
|||||||
console.error('获取投递记录详情失败:', error);
|
console.error('获取投递记录详情失败:', error);
|
||||||
return ctx.fail('获取投递记录详情失败: ' + error.message);
|
return ctx.fail('获取投递记录详情失败: ' + error.message);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/apply/trend:
|
||||||
|
* get:
|
||||||
|
* summary: 获取近7天投递趋势数据
|
||||||
|
* description: 根据设备SN码获取近7天的投递数量趋势
|
||||||
|
* tags: [前端-投递管理]
|
||||||
|
* parameters:
|
||||||
|
* - in: query
|
||||||
|
* name: sn_code
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: string
|
||||||
|
* description: 设备SN码
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 获取成功
|
||||||
|
*/
|
||||||
|
'GET /apply/trend': async (ctx) => {
|
||||||
|
try {
|
||||||
|
const models = Framework.getModels();
|
||||||
|
const { apply_records, op } = models;
|
||||||
|
const { sn_code } = ctx.query;
|
||||||
|
|
||||||
|
if (!sn_code) {
|
||||||
|
return ctx.fail('请提供设备SN码');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算近7天的日期范围
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(23, 59, 59, 999);
|
||||||
|
const sevenDaysAgo = new Date();
|
||||||
|
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 6);
|
||||||
|
sevenDaysAgo.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
// 查询近7天的投递记录
|
||||||
|
const records = await apply_records.findAll({
|
||||||
|
where: {
|
||||||
|
sn_code: sn_code,
|
||||||
|
applyTime: {
|
||||||
|
[op.gte]: sevenDaysAgo,
|
||||||
|
[op.lte]: today
|
||||||
|
}
|
||||||
|
},
|
||||||
|
attributes: ['applyTime'],
|
||||||
|
raw: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// 生成7天的日期数组
|
||||||
|
const trendData = [];
|
||||||
|
for (let i = 6; i >= 0; i--) {
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() - i);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const dateStr = `${date.getMonth() + 1}/${date.getDate()}`;
|
||||||
|
|
||||||
|
// 统计当天的投递数量
|
||||||
|
const count = records.filter(record => {
|
||||||
|
const recordDate = new Date(record.applyTime);
|
||||||
|
recordDate.setHours(0, 0, 0, 0);
|
||||||
|
return recordDate.getTime() === date.getTime();
|
||||||
|
}).length;
|
||||||
|
|
||||||
|
trendData.push({
|
||||||
|
date: dateStr,
|
||||||
|
value: count
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.success(trendData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取投递趋势数据失败:', error);
|
||||||
|
return ctx.fail('获取投递趋势数据失败: ' + error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -163,5 +163,146 @@ module.exports = {
|
|||||||
device_id,
|
device_id,
|
||||||
user: userInfo
|
user: userInfo
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 {
|
||||||
|
const { sn_code } = ctx.query;
|
||||||
|
|
||||||
|
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:
|
||||||
|
* post:
|
||||||
|
* summary: 保存投递配置
|
||||||
|
* description: 根据设备SN码保存用户的投递配置
|
||||||
|
* tags: [前端-用户管理]
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* required:
|
||||||
|
* - sn_code
|
||||||
|
* properties:
|
||||||
|
* sn_code:
|
||||||
|
* type: string
|
||||||
|
* description: 设备SN码
|
||||||
|
* config:
|
||||||
|
* type: object
|
||||||
|
* description: 投递配置
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 保存成功
|
||||||
|
*/
|
||||||
|
'POST /user/delivery-config': async (ctx) => {
|
||||||
|
try {
|
||||||
|
const body = ctx.getBody();
|
||||||
|
const { sn_code, config } = body;
|
||||||
|
|
||||||
|
if (!sn_code) {
|
||||||
|
return ctx.fail('请提供设备SN码');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
|
return ctx.fail('请提供配置信息');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { pla_account } = await Framework.getModels();
|
||||||
|
const user = await pla_account.findOne({
|
||||||
|
where: { sn_code }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 更新数据库
|
||||||
|
await pla_account.update(
|
||||||
|
{
|
||||||
|
auto_deliver: config.autoDelivery ? 1 : 0,
|
||||||
|
deliver_config: deliverConfig
|
||||||
|
},
|
||||||
|
{ where: { sn_code } }
|
||||||
|
);
|
||||||
|
|
||||||
|
return ctx.success({ message: '配置保存成功' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存投递配置失败:', error);
|
||||||
|
return ctx.fail('保存投递配置失败: ' + error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user