|
@@ -2530,6 +2530,7 @@ async function sqlPage(className, input, filters = []) {
|
|
|
async function nodePage(input) {
|
|
async function nodePage(input) {
|
|
|
const paging = pageInput(input); const values = [DEFAULT_COMPANY_ID]; const clauses = ['"company"=$1']; if (input.pid !== undefined && input.pid !== '') { values.push(String(number(input.pid))); clauses.push('CAST("parentId" AS text)=$' + values.length); } const where = clauses.join(' AND '); const countRow = await Psql.one('SELECT COUNT(*)::int AS total FROM "Node" WHERE ' + where,values); const rows = await Psql.query('SELECT * FROM "Node" WHERE ' + where + ' ORDER BY CASE WHEN CAST("orderId" AS text) ~ \'^-?[0-9]+$\' THEN CAST("orderId" AS numeric) ELSE 0 END ASC, CASE WHEN CAST("nodeId" AS text) ~ \'^-?[0-9]+$\' THEN CAST("nodeId" AS numeric) ELSE 0 END ASC LIMIT $' + (values.length + 1) + ' OFFSET $' + (values.length + 2),values.concat([paging.size,(paging.index - 1) * paging.size])); const total = number(countRow.total); return { rows:rows.filter(isVisible).map((row) => legacyAliases(row,'Node')),page:{itemCount:total,pageCount:Math.ceil(total / paging.size),pageIndex:paging.index,pageSize:paging.size} };
|
|
const paging = pageInput(input); const values = [DEFAULT_COMPANY_ID]; const clauses = ['"company"=$1']; if (input.pid !== undefined && input.pid !== '') { values.push(String(number(input.pid))); clauses.push('CAST("parentId" AS text)=$' + values.length); } const where = clauses.join(' AND '); const countRow = await Psql.one('SELECT COUNT(*)::int AS total FROM "Node" WHERE ' + where,values); const rows = await Psql.query('SELECT * FROM "Node" WHERE ' + where + ' ORDER BY CASE WHEN CAST("orderId" AS text) ~ \'^-?[0-9]+$\' THEN CAST("orderId" AS numeric) ELSE 0 END ASC, CASE WHEN CAST("nodeId" AS text) ~ \'^-?[0-9]+$\' THEN CAST("nodeId" AS numeric) ELSE 0 END ASC LIMIT $' + (values.length + 1) + ' OFFSET $' + (values.length + 2),values.concat([paging.size,(paging.index - 1) * paging.size])); const total = number(countRow.total); return { rows:rows.filter(isVisible).map((row) => legacyAliases(row,'Node')),page:{itemCount:total,pageCount:Math.ceil(total / paging.size),pageIndex:paging.index,pageSize:paging.size} };
|
|
|
}
|
|
}
|
|
|
|
|
+// Keep original text equality guards while exposing numeric model/node/word keys to existing indexes.
|
|
|
async function nodeUnitPage(input,current) {
|
|
async function nodeUnitPage(input,current) {
|
|
|
const uid = await authorizeRequestedUser(current,input.userId || input.uid); const paging = pageInput(input); const bindingId = String(input.bindingId || '').trim(); let parentId = number(input.pid); let binding = null;
|
|
const uid = await authorizeRequestedUser(current,input.userId || input.uid); const paging = pageInput(input); const bindingId = String(input.bindingId || '').trim(); let parentId = number(input.pid); let binding = null;
|
|
|
const bindingRows=await Psql.query('SELECT b.* FROM "CourseBinding" b JOIN "CommonModel" c ON c."company"=b."company" AND c."modelId"=58 AND c."itemId"=b."id" WHERE b."company"=$1 AND b."yhid"::text=$2 AND b."enrollmentStatus"=\'active\' AND c."status"=99 AND (($3<>\'\' AND (b."id"::text=$3 OR b."objectId"=$3)) OR ($3=\'\' AND b."kcid"::text=$4))',[DEFAULT_COMPANY_ID,String(uid),bindingId,String(parentId)]);
|
|
const bindingRows=await Psql.query('SELECT b.* FROM "CourseBinding" b JOIN "CommonModel" c ON c."company"=b."company" AND c."modelId"=58 AND c."itemId"=b."id" WHERE b."company"=$1 AND b."yhid"::text=$2 AND b."enrollmentStatus"=\'active\' AND c."status"=99 AND (($3<>\'\' AND (b."id"::text=$3 OR b."objectId"=$3)) OR ($3=\'\' AND b."kcid"::text=$4))',[DEFAULT_COMPANY_ID,String(uid),bindingId,String(parentId)]);
|
|
@@ -2537,10 +2538,10 @@ async function nodeUnitPage(input,current) {
|
|
|
if (!binding) fail(403,'该课程尚未分配给当前学员'); parentId = number(binding.kcid,parentId);
|
|
if (!binding) fail(403,'该课程尚未分配给当前学员'); parentId = number(binding.kcid,parentId);
|
|
|
if (parentId) {
|
|
if (parentId) {
|
|
|
const countRow = await Psql.one('SELECT COUNT(*)::int AS total FROM "Node" WHERE "company"=$1 AND CAST("parentId" AS text)=$2',[DEFAULT_COMPANY_ID,String(parentId)]); const total = number(countRow.total);
|
|
const countRow = await Psql.one('SELECT COUNT(*)::int AS total FROM "Node" WHERE "company"=$1 AND CAST("parentId" AS text)=$2',[DEFAULT_COMPANY_ID,String(parentId)]); const total = number(countRow.total);
|
|
|
- if (total) { const rows = await Psql.query('SELECT n.*,COALESCE(w.total,0)::int AS "total",COALESCE(l.learned,0)::int AS "yx_word" FROM "Node" n LEFT JOIN LATERAL (SELECT COUNT(*)::int AS total FROM "CommonModel" c WHERE c."company"=$1 AND CAST(c."modelId" AS text)=\'52\' AND CAST(c."nodeId" AS text)=CAST(n."nodeId" AS text)) w ON TRUE LEFT JOIN LATERAL (SELECT COUNT(DISTINCT CAST(p."scid" AS text))::int AS learned FROM "PracticeRecord" p JOIN "CommonModel" c ON c."company"=$1 AND CAST(c."modelId" AS text)=\'52\' AND CAST(c."generalId" AS text)=CAST(p."scid" AS text) AND CAST(c."nodeId" AS text)=CAST(n."nodeId" AS text) WHERE p."company"=$1 AND CAST(p."yhid" AS text)=$3 AND CASE WHEN CAST(p."xxcs" AS text) ~ \'^[0-9]+(?:\\.[0-9]+)?$\' THEN CAST(p."xxcs" AS numeric) ELSE 0 END>0) l ON TRUE WHERE n."company"=$1 AND CAST(n."parentId" AS text)=$2 ORDER BY CASE WHEN CAST(n."orderId" AS text) ~ \'^-?[0-9]+$\' THEN CAST(n."orderId" AS numeric) ELSE 0 END ASC,CASE WHEN CAST(n."nodeId" AS text) ~ \'^-?[0-9]+$\' THEN CAST(n."nodeId" AS numeric) ELSE 0 END ASC LIMIT $4 OFFSET $5',[DEFAULT_COMPANY_ID,String(parentId),String(uid),paging.size,(paging.index - 1) * paging.size]); return { rows:rows.map((source) => { const row = legacyAliases(source,'Node'); row.total = number(source.total); row.yx_word = number(source.yx_word); row.process = row.total ? Math.round(row.yx_word / row.total * 100) : 0; return row; }),page:{itemCount:total,pageCount:Math.ceil(total / paging.size),pageIndex:paging.index,pageSize:paging.size} }; }
|
|
|
|
|
|
|
+ if (total) { const rows = await Psql.query('SELECT n.*,COALESCE(w.total,0)::int AS "total",COALESCE(l.learned,0)::int AS "yx_word" FROM "Node" n LEFT JOIN LATERAL (SELECT COUNT(*)::int AS total FROM "CommonModel" c WHERE c."company"=$1 AND c."modelId"=52 AND CAST(c."modelId" AS text)=\'52\' AND c."nodeId"=n."nodeId" AND CAST(c."nodeId" AS text)=CAST(n."nodeId" AS text)) w ON TRUE LEFT JOIN LATERAL (SELECT COUNT(DISTINCT CAST(p."scid" AS text))::int AS learned FROM "PracticeRecord" p JOIN "CommonModel" c ON c."company"=$1 AND c."modelId"=52 AND CAST(c."modelId" AS text)=\'52\' AND c."generalId"=p."scid" AND CAST(c."generalId" AS text)=CAST(p."scid" AS text) AND c."nodeId"=n."nodeId" AND CAST(c."nodeId" AS text)=CAST(n."nodeId" AS text) WHERE p."company"=$1 AND CAST(p."yhid" AS text)=$3 AND CASE WHEN CAST(p."xxcs" AS text) ~ \'^[0-9]+(?:\\.[0-9]+)?$\' THEN CAST(p."xxcs" AS numeric) ELSE 0 END>0) l ON TRUE WHERE n."company"=$1 AND CAST(n."parentId" AS text)=$2 ORDER BY CASE WHEN CAST(n."orderId" AS text) ~ \'^-?[0-9]+$\' THEN CAST(n."orderId" AS numeric) ELSE 0 END ASC,CASE WHEN CAST(n."nodeId" AS text) ~ \'^-?[0-9]+$\' THEN CAST(n."nodeId" AS numeric) ELSE 0 END ASC LIMIT $4 OFFSET $5',[DEFAULT_COMPANY_ID,String(parentId),String(uid),paging.size,(paging.index - 1) * paging.size]); return { rows:rows.map((source) => { const row = legacyAliases(source,'Node'); row.total = number(source.total); row.yx_word = number(source.yx_word); row.process = row.total ? Math.round(row.yx_word / row.total * 100) : 0; return row; }),page:{itemCount:total,pageCount:Math.ceil(total / paging.size),pageIndex:paging.index,pageSize:paging.size} }; }
|
|
|
}
|
|
}
|
|
|
const assigned = courseAssignedUnits(binding.syjd); const total = assigned.length; if (!total) return {rows:[],page:{itemCount:0,pageCount:0,pageIndex:paging.index,pageSize:paging.size}}; const pageUnits = assigned.slice((paging.index - 1) * paging.size,paging.index * paging.size),unitIds=pageUnits.map((unit)=>unit.id);
|
|
const assigned = courseAssignedUnits(binding.syjd); const total = assigned.length; if (!total) return {rows:[],page:{itemCount:0,pageCount:0,pageIndex:paging.index,pageSize:paging.size}}; const pageUnits = assigned.slice((paging.index - 1) * paging.size,paging.index * paging.size),unitIds=pageUnits.map((unit)=>unit.id);
|
|
|
- const wordRows = await Psql.query('SELECT CAST(c."nodeId" AS text) AS id,COUNT(*)::int AS total FROM "CommonModel" c WHERE c."company"=$1 AND CAST(c."modelId" AS text)=\'52\' AND CAST(c."nodeId" AS text)=ANY($2::text[]) GROUP BY CAST(c."nodeId" AS text)',[DEFAULT_COMPANY_ID,unitIds]); const learnedRows = await Psql.query('SELECT CAST(c."nodeId" AS text) AS id,COUNT(DISTINCT CAST(p."scid" AS text))::int AS learned FROM "PracticeRecord" p JOIN "CommonModel" c ON c."company"=$1 AND CAST(c."modelId" AS text)=\'52\' AND CAST(c."generalId" AS text)=CAST(p."scid" AS text) WHERE p."company"=$1 AND CAST(p."yhid" AS text)=$2 AND CAST(c."nodeId" AS text)=ANY($3::text[]) AND CASE WHEN CAST(p."xxcs" AS text) ~ \'^[0-9]+(?:\\.[0-9]+)?$\' THEN CAST(p."xxcs" AS numeric) ELSE 0 END>0 GROUP BY CAST(c."nodeId" AS text)',[DEFAULT_COMPANY_ID,String(uid),unitIds]); const totals=new Map(wordRows.map((row)=>[String(row.id),number(row.total)])),learned=new Map(learnedRows.map((row)=>[String(row.id),number(row.learned)])); const rows=pageUnits.map((unit)=>{const count=totals.get(unit.id)||0,done=learned.get(unit.id)||0;return legacyAliases({nodeId:number(unit.id),nodeName:unit.name,parentId,total:count,yx_word:done,process:count?Math.round(done/count*100):0},'Node');}); return {rows,page:{itemCount:total,pageCount:Math.ceil(total/paging.size),pageIndex:paging.index,pageSize:paging.size}};
|
|
|
|
|
|
|
+ const wordRows = await Psql.query('SELECT CAST(c."nodeId" AS text) AS id,COUNT(*)::int AS total FROM "CommonModel" c WHERE c."company"=$1 AND c."modelId"=52 AND CAST(c."modelId" AS text)=\'52\' AND c."nodeId"=ANY($2::numeric[]) AND CAST(c."nodeId" AS text)=ANY($2::text[]) GROUP BY CAST(c."nodeId" AS text)',[DEFAULT_COMPANY_ID,unitIds]); const learnedRows = await Psql.query('SELECT CAST(c."nodeId" AS text) AS id,COUNT(DISTINCT CAST(p."scid" AS text))::int AS learned FROM "PracticeRecord" p JOIN "CommonModel" c ON c."company"=$1 AND c."modelId"=52 AND CAST(c."modelId" AS text)=\'52\' AND c."generalId"=p."scid" AND CAST(c."generalId" AS text)=CAST(p."scid" AS text) WHERE p."company"=$1 AND CAST(p."yhid" AS text)=$2 AND c."nodeId"=ANY($3::numeric[]) AND CAST(c."nodeId" AS text)=ANY($3::text[]) AND CASE WHEN CAST(p."xxcs" AS text) ~ \'^[0-9]+(?:\\.[0-9]+)?$\' THEN CAST(p."xxcs" AS numeric) ELSE 0 END>0 GROUP BY CAST(c."nodeId" AS text)',[DEFAULT_COMPANY_ID,String(uid),unitIds]); const totals=new Map(wordRows.map((row)=>[String(row.id),number(row.total)])),learned=new Map(learnedRows.map((row)=>[String(row.id),number(row.learned)])); const rows=pageUnits.map((unit)=>{const count=totals.get(unit.id)||0,done=learned.get(unit.id)||0;return legacyAliases({nodeId:number(unit.id),nodeName:unit.name,parentId,total:count,yx_word:done,process:count?Math.round(done/count*100):0},'Node');}); return {rows,page:{itemCount:total,pageCount:Math.ceil(total/paging.size),pageIndex:paging.index,pageSize:paging.size}};
|
|
|
}
|
|
}
|
|
|
function legacyAppRow(source) { if (!source) return null; const row = legacyAliases(source,'App'); row.ver = number(firstValue(row.index,String(row.version || '').replace(/\D/g,''))); row.nver = String(row.version || ''); row.intro = String(firstValue(row.changelog,row.desc,'') || ''); row.path = String(firstValue(row.downUrl,row.apkUrl,'') || ''); row.size = null; row.sizeUnavailable = true; return row; }
|
|
function legacyAppRow(source) { if (!source) return null; const row = legacyAliases(source,'App'); row.ver = number(firstValue(row.index,String(row.version || '').replace(/\D/g,''))); row.nver = String(row.version || ''); row.intro = String(firstValue(row.changelog,row.desc,'') || ''); row.path = String(firstValue(row.downUrl,row.apkUrl,'') || ''); row.size = null; row.sizeUnavailable = true; return row; }
|
|
|
function parseArray(value) { if (Array.isArray(value)) return value; if (typeof value !== 'string' || !value.trim()) return []; try { const parsed = JSON.parse(value); return Array.isArray(parsed) ? parsed : []; } catch (_) { return []; } }
|
|
function parseArray(value) { if (Array.isArray(value)) return value; if (typeof value !== 'string' || !value.trim()) return []; try { const parsed = JSON.parse(value); return Array.isArray(parsed) ? parsed : []; } catch (_) { return []; } }
|
|
@@ -2690,7 +2691,11 @@ async function newWordPage(input, current) {
|
|
|
const countRow = await Psql.one('SELECT COUNT(*) FILTER (WHERE NOT (' + learned + '))::int AS "pendingCount", COUNT(*) FILTER (WHERE ' + learned + ')::int AS "completedCount"' + from + where, values);
|
|
const countRow = await Psql.one('SELECT COUNT(*) FILTER (WHERE NOT (' + learned + '))::int AS "pendingCount", COUNT(*) FILTER (WHERE ' + learned + ')::int AS "completedCount"' + from + where, values);
|
|
|
const filter = status ? ' AND ' + (status === 'completed' ? learned : 'NOT (' + learned + ')') : '';
|
|
const filter = status ? ' AND ' + (status === 'completed' ? learned : 'NOT (' + learned + ')') : '';
|
|
|
const rows = await Psql.query('SELECT p.*, pc."generalId" AS "__practiceGeneralId", c.*, row_to_json(v) AS "__addon"' + from + ' LEFT JOIN "VocabularyWord" v ON v."company" = $1 AND v."id" = c."itemId" AND CAST(v."id" AS text) = CAST(c."itemId" AS text) LEFT JOIN "CommonModel" pc ON pc."company" = $1 AND pc."modelId" = 53 AND pc."itemId" = CAST(CAST(p."id" AS text) AS numeric) AND CAST(pc."modelId" AS text) = \'53\' AND CAST(pc."itemId" AS text) = CAST(p."id" AS text)' + where + filter + ' ORDER BY p."updatedAt" DESC, p."id" DESC LIMIT $3 OFFSET $4', values.concat([paging.size, (paging.index - 1) * paging.size]));
|
|
const rows = await Psql.query('SELECT p.*, pc."generalId" AS "__practiceGeneralId", c.*, row_to_json(v) AS "__addon"' + from + ' LEFT JOIN "VocabularyWord" v ON v."company" = $1 AND v."id" = c."itemId" AND CAST(v."id" AS text) = CAST(c."itemId" AS text) LEFT JOIN "CommonModel" pc ON pc."company" = $1 AND pc."modelId" = 53 AND pc."itemId" = CAST(CAST(p."id" AS text) AS numeric) AND CAST(pc."modelId" AS text) = \'53\' AND CAST(pc."itemId" AS text) = CAST(p."id" AS text)' + where + filter + ' ORDER BY p."updatedAt" DESC, p."id" DESC LIMIT $3 OFFSET $4', values.concat([paging.size, (paging.index - 1) * paging.size]));
|
|
|
- const result = rows.map((source) => { const practice = { id: source.id, kcid: source.kcid, scid: source.scid, xxcs: source.xxcs, yhid: source.yhid, jrscb: source.jrscb }; const detail = normalizeWordRow(source); return { ...practice, GeneralID: number(source.__practiceGeneralId || source.id), Title: detail.Title || detail.title || '', detail: [detail] }; });
|
|
|
|
|
|
|
+ const result = rows.map((source) => { const practice = { id: source.id, kcid: source.kcid, scid: source.scid, xxcs: source.xxcs, yhid: source.yhid, jrscb: source.jrscb }; const word = normalizeWordRow(source);
|
|
|
|
|
+ // Opt-in payload: keep teaching data, omit legacy publishing/admin metadata.
|
|
|
|
|
+ const keys = ['GeneralID','NodeID','Title','Title2','word','Word','sy','jssy','Translate','Meaning','yb','Phonetic','phonetic','yp','dy','lj','nodeId'];
|
|
|
|
|
+ const detail = input.compact === true ? Object.fromEntries(keys.filter(key => word[key] !== undefined).map(key => [key,word[key]])) : word;
|
|
|
|
|
+ return { ...practice, GeneralID: number(source.__practiceGeneralId || source.id), Title: detail.Title || detail.title || '', detail: [detail] }; });
|
|
|
const pendingCount = number(countRow.pendingCount), completedCount = number(countRow.completedCount);
|
|
const pendingCount = number(countRow.pendingCount), completedCount = number(countRow.completedCount);
|
|
|
const total = status === 'pending' ? pendingCount : status === 'completed' ? completedCount : pendingCount + completedCount;
|
|
const total = status === 'pending' ? pendingCount : status === 'completed' ? completedCount : pendingCount + completedCount;
|
|
|
return { rows: result, page: { itemCount: total, pageCount: Math.ceil(total / paging.size), pageIndex: paging.index, pageSize: paging.size, pendingCount, completedCount } };
|
|
return { rows: result, page: { itemCount: total, pageCount: Math.ceil(total / paging.size), pageIndex: paging.index, pageSize: paging.size, pendingCount, completedCount } };
|