修复登录报错提示内容错误,增加节假日同步功能

This commit is contained in:
qwq
2026-06-04 15:53:23 +08:00
parent 4a8f530921
commit cd63391f89
84 changed files with 874 additions and 31 deletions
+43 -2
View File
@@ -147,10 +147,26 @@ router.delete('/clients/:id', (req, res) => {
// Workday Settings
// ========================
router.get('/workdays', (req, res) => {
router.get('/workdays', async (req, res) => {
const db = getDB(req);
const year = parseInt(req.query.year) || new Date().getFullYear();
const workdays = db.all('SELECT * FROM workdays WHERE year = ? ORDER BY month', [year]);
let workdays = db.all('SELECT * FROM workdays WHERE year = ? ORDER BY month', [year]);
// Auto-calculate and seed if database is empty for this year
if (workdays.length === 0) {
try {
const { getHolidays, calculateMonthlyWorkdays } = require('../utils/holiday');
const holidayMap = await getHolidays(db, year);
const computed = calculateMonthlyWorkdays(year, holidayMap);
for (const item of computed) {
db.run('INSERT OR IGNORE INTO workdays (year, month, days) VALUES (?, ?, ?)', [year, item.month, item.days]);
}
workdays = db.all('SELECT * FROM workdays WHERE year = ? ORDER BY month', [year]);
} catch (e) {
console.error('[Admin] Error auto-seeding workdays:', e.message);
}
}
res.json({ code: 200, data: workdays });
});
@@ -169,6 +185,31 @@ router.post('/workdays', (req, res) => {
res.json({ code: 200, message: '设置成功' });
});
// POST /api/admin/workdays/sync — manually trigger network sync
router.post('/workdays/sync', async (req, res) => {
const db = getDB(req);
const { year } = req.body;
if (!year) return res.status(400).json({ code: 400, message: '请指定要同步的年份' });
try {
const { syncYearWorkdays } = require('../utils/holiday');
const workdaysList = await syncYearWorkdays(db, parseInt(year));
res.json({ code: 200, message: '自动同步成功', data: workdaysList });
} catch (e) {
console.error('[Admin] Sync error:', e.message);
res.status(500).json({ code: 500, message: e.message });
}
});
// GET /api/admin/holidays — retrieve holiday data for a specific year
router.get('/holidays', async (req, res) => {
const db = getDB(req);
const year = parseInt(req.query.year) || new Date().getFullYear();
const { getHolidays } = require('../utils/holiday');
const holidayMap = await getHolidays(db, year);
res.json({ code: 200, data: holidayMap || {} });
});
// ========================
// Global Stats
// ========================
+9
View File
@@ -20,6 +20,15 @@ router.get('/project-types', (req, res) => {
res.json({ code: 200, data: db.all('SELECT id, name FROM project_types ORDER BY id') });
});
// GET /api/rd/holidays — retrieve holiday data for a specific year
router.get('/holidays', async (req, res) => {
const db = getDB(req);
const year = parseInt(req.query.year) || new Date().getFullYear();
const { getHolidays } = require('../utils/holiday');
const holidayMap = await getHolidays(db, year);
res.json({ code: 200, data: holidayMap || {} });
});
// GET /api/rd/timesheets?date=YYYY-MM-DD or ?month=YYYY-MM
router.get('/timesheets', (req, res) => {
const db = getDB(req);