|
|
@@ -2559,9 +2559,30 @@ async function orderDetailRow(inputId, current, authorize = true) {
|
|
|
let source = rows[0]; if (!source && /^[A-Za-z0-9_-]{10,40}$/.test(id)) { const direct = await Psql.query('SELECT a.*, n."nodeName" AS "__courseTitle" FROM "CourseAppointment" a LEFT JOIN "Node" n ON n."company" = $1 AND CAST(n."nodeId" AS text) = CAST(a."kcid" AS text) WHERE a."company" = $1 AND a."objectId" = $2 LIMIT 1', [DEFAULT_COMPANY_ID, id]); if (direct[0]) source = { ...direct[0], generalId: id, GeneralID: id, title: direct[0].title || '课程预约' }; }
|
|
|
if (!source) return null; const addon = source.__addon || {}; const courseTitle = source.__courseTitle || source.subtitle || ''; delete source.__addon; delete source.__courseTitle; const row = legacyAliases({ ...source, ...addon }, 'CommonModel'); row.cancelled=number(source.status)===-2; row.kcmc = row.kcmc || courseTitle; row.yykcmc = row.yykcmc || courseTitle; row.HoneyName = row.HoneyName || String(row.Title || '').split('(')[0]; if (authorize) await authorizeBusinessRow(current, row, ['szyh'], ['pl']); return row;
|
|
|
}
|
|
|
+async function legacyStudyRecordWords(id, ownerId) {
|
|
|
+ try {
|
|
|
+ const config = await appLegacyConfig();
|
|
|
+ if (!config.url || !config.apiId || !config.apiKey) return [];
|
|
|
+ const params = new URLSearchParams({ action:'content_get', id:String(id), apiId:config.apiId, apiKey:config.apiKey });
|
|
|
+ const url = config.url + (config.url.includes('?') ? '&' : '?') + params.toString();
|
|
|
+ const response = await fetch(url, { headers:{ accept:'application/json' }, signal:typeof AbortSignal !== 'undefined' && AbortSignal.timeout ? AbortSignal.timeout(8000) : undefined });
|
|
|
+ if (!response.ok) return [];
|
|
|
+ const payload = await response.json();
|
|
|
+ let result = payload && payload.result;
|
|
|
+ if (typeof result === 'string') result = JSON.parse(result);
|
|
|
+ const record = Array.isArray(result) ? result[0] : Array.isArray(result && result.items) ? result.items[0] : result;
|
|
|
+ if (!record || number(firstValue(record.UserID,record.userId)) !== number(ownerId)) return [];
|
|
|
+ return parseArray(record.xxqs).filter((item) => item && typeof item === 'object');
|
|
|
+ } catch (_) { return []; }
|
|
|
+}
|
|
|
async function recordDetailData(input, current) {
|
|
|
const id = String(input.id || input.gid || ''); if (!id) fail(400, '缺少学习记录 ID'); const rows = await Psql.query('SELECT c.*, row_to_json(d) AS "__addon" FROM "CommonModel" c JOIN "DailyStudyRecord" d ON d."company" = $1 AND CAST(d."id" AS text) = CAST(c."itemId" AS text) WHERE c."company" = $1 AND CAST(c."modelId" AS text) = \'56\' AND CAST(c."generalId" AS text) = $2 LIMIT 1', [DEFAULT_COMPANY_ID, id]);
|
|
|
- if (!rows.length) return null; const source = rows[0]; const recordAddon = source.__addon || {}; delete source.__addon; const record = legacyAliases({ ...source, ...recordAddon }, 'CommonModel'); await authorizeLearningRecordAccess(current, record); const storedWords = parseArray(recordAddon.xxqs); const ids = [...new Set(storedWords.map((item) => String(item && (item.GeneralID ?? item.generalId ?? item.id) || '')).filter(Boolean))]; let wordRows = [];
|
|
|
+ if (!rows.length) {
|
|
|
+ const targetId = await appLearningTarget(current,input.studentId);
|
|
|
+ const words = await legacyStudyRecordWords(id,targetId);
|
|
|
+ return words.length ? { words:words.map((item) => ({ ...item, Title:item.Title || item.title || item.word || '' })), addon:[] } : null;
|
|
|
+ }
|
|
|
+ const source = rows[0]; const recordAddon = source.__addon || {}; delete source.__addon; const record = legacyAliases({ ...source, ...recordAddon }, 'CommonModel'); await authorizeLearningRecordAccess(current, record); let storedWords = parseArray(recordAddon.xxqs); if (!storedWords.length) storedWords = await legacyStudyRecordWords(id,number(record.userId ?? record.UserID)); const ids = [...new Set(storedWords.map((item) => String(item && (item.GeneralID ?? item.generalId ?? item.id) || '')).filter(Boolean))]; let wordRows = [];
|
|
|
if (ids.length) wordRows = await Psql.query('SELECT c.*, row_to_json(v) AS "__addon" FROM "CommonModel" c LEFT JOIN "VocabularyWord" v ON v."company" = $1 AND CAST(v."id" AS text) = CAST(c."itemId" AS text) WHERE c."company" = $1 AND CAST(c."modelId" AS text) = \'52\' AND CAST(c."generalId" AS text) = ANY($2::text[])', [DEFAULT_COMPANY_ID, ids]);
|
|
|
const details = new Map(wordRows.map((row) => { const normalized = normalizeWordRow(row); return [String(normalized.GeneralID || normalized.generalId), normalized]; })); const words = storedWords.map((item) => { const raw = item && typeof item === 'object' ? safe(item) : {}; const wordId = String(raw.GeneralID ?? raw.generalId ?? raw.id ?? ''); const detail = details.get(wordId) || legacyAliases({ generalId: wordId, title: raw.Title || raw.title || '' }, 'CommonModel'); return { ...detail, ...raw, GeneralID: number(wordId, wordId), Title: raw.Title || raw.title || detail.Title || detail.title || '', detail: [detail] }; });
|
|
|
const order = recordAddon.dsid ? await orderDetailRow(recordAddon.dsid, current, false) : null; return { words, addon: order ? [order] : [], record };
|