|
@@ -2845,7 +2845,7 @@ function appOverviewToday() {
|
|
|
const parts=new Intl.DateTimeFormat('en-US',{timeZone:'Asia/Shanghai',year:'numeric',month:'2-digit',day:'2-digit'}).formatToParts(new Date()),values={};for(const part of parts)values[part.type]=part.value;return values.year+'-'+values.month+'-'+values.day;
|
|
const parts=new Intl.DateTimeFormat('en-US',{timeZone:'Asia/Shanghai',year:'numeric',month:'2-digit',day:'2-digit'}).formatToParts(new Date()),values={};for(const part of parts)values[part.type]=part.value;return values.year+'-'+values.month+'-'+values.day;
|
|
|
}
|
|
}
|
|
|
function appOverviewScheduleRow(source) {
|
|
function appOverviewScheduleRow(source) {
|
|
|
- return { teacherPay:source.teacherPay,payStatus:source.payStatus,payReason:source.payReason,feedbackStatus:source.feedbackStatus,objectId:String(source.objectId||source.appointmentObjectId||''),GeneralID:number(source.generalId||source.id),ID:number(source.generalId||source.id),Title:String(source.title||source.courseTitle||'课程预约'),Title2:String(source.courseTitle||''),CreateTime:firstValue(source.createTime,source.createdAt),cancelled:number(source.commonStatus)===-2,status:number(source.commonStatus,99),durationMinutes:source.durationMinutes,bindingId:source.bindingId,courseCategoryKey:source.courseCategoryKey,courseCategoryName:source.courseCategoryName,pl:source.pl,bxrq:source.bxrq,dslx:source.dslx,dszt:source.dszt,fxpl:source.fxpl,jffs:source.jffs,jssj:source.jssj,kcid:source.kcid,kssj:source.kssj,plxm:source.plxm,scsj:source.scsj,sdsd:source.sdsd,szmd:source.szmd,szyh:source.szyh,yysj:source.yysj,yykcid:source.yykcid };
|
|
|
|
|
|
|
+ return { legacyLessonId:source.legacyLessonId,teacherPay:source.teacherPay,payStatus:source.payStatus,payReason:source.payReason,feedbackStatus:source.feedbackStatus,objectId:String(source.objectId||source.appointmentObjectId||''),GeneralID:number(source.generalId||source.id),ID:number(source.generalId||source.id),Title:String(source.title||source.courseTitle||'课程预约'),Title2:String(source.courseTitle||''),CreateTime:firstValue(source.createTime,source.createdAt),cancelled:number(source.commonStatus)===-2,status:number(source.commonStatus,99),durationMinutes:source.durationMinutes,bindingId:source.bindingId,courseCategoryKey:source.courseCategoryKey,courseCategoryName:source.courseCategoryName,pl:source.pl,bxrq:source.bxrq,dslx:source.dslx,dszt:source.dszt,fxpl:source.fxpl,jffs:source.jffs,jssj:source.jssj,kcid:source.kcid,kssj:source.kssj,plxm:source.plxm,scsj:source.scsj,sdsd:source.sdsd,szmd:source.szmd,szyh:source.szyh,yysj:source.yysj,yykcid:source.yykcid };
|
|
|
}
|
|
}
|
|
|
function appOverviewCourseRow(source) {
|
|
function appOverviewCourseRow(source) {
|
|
|
return { objectId:String(source.objectId||source.bindingObjectId||''),GeneralID:number(source.generalId||source.id),ID:number(source.generalId||source.id),Title:String(source.title||source.courseTitle||'课程内容'),Title2:String(source.courseTitle||''),CreateTime:firstValue(source.createTime,source.createdAt),bindingId:String(source.bindingObjectId||source.objectId||''),categoryKey:source.categoryKey,categoryName:source.categoryName,id:source.id,yxx:source.yxx,cksl:source.cksl,kcid:source.kcid,syjd:source.syjd,yhid:source.yhid };
|
|
return { objectId:String(source.objectId||source.bindingObjectId||''),GeneralID:number(source.generalId||source.id),ID:number(source.generalId||source.id),Title:String(source.title||source.courseTitle||'课程内容'),Title2:String(source.courseTitle||''),CreateTime:firstValue(source.createTime,source.createdAt),bindingId:String(source.bindingObjectId||source.objectId||''),categoryKey:source.categoryKey,categoryName:source.categoryName,id:source.id,yxx:source.yxx,cksl:source.cksl,kcid:source.kcid,syjd:source.syjd,yhid:source.yhid };
|
|
@@ -3030,22 +3030,27 @@ async function appCompanionOverview(input,current) {
|
|
|
const args=[DEFAULT_COMPANY_ID,String(uid)],clauses=['a."company"=$1','a."'+(coach?'pl':'szyh')+'"=$2'];
|
|
const args=[DEFAULT_COMPANY_ID,String(uid)],clauses=['a."company"=$1','a."'+(coach?'pl':'szyh')+'"=$2'];
|
|
|
const date="to_char(xs_appointment_day(a.\"bxrq\",a.\"yysj\"),'YYYY-MM-DD')";
|
|
const date="to_char(xs_appointment_day(a.\"bxrq\",a.\"yysj\"),'YYYY-MM-DD')";
|
|
|
const add=(sql,value)=>{args.push(value);clauses.push(sql.replace('?', '$'+args.length));};
|
|
const add=(sql,value)=>{args.push(value);clauses.push(sql.replace('?', '$'+args.length));};
|
|
|
- if(history)clauses.push('(a."dszt"::numeric>=30 OR c."status"=-2)');else clauses.push('COALESCE(c."status",99)<>-2');
|
|
|
|
|
|
|
+ const teacherHistory=coach&&history;
|
|
|
|
|
+ const delivered='a."dszt"::numeric>=30 AND COALESCE(c."status",99)<>-2';
|
|
|
|
|
+ const finished=teacherHistory?'(('+delivered+') OR legacy."legacyLessonId" IS NOT NULL)':'('+delivered+')';
|
|
|
|
|
+ const lessonColumn=teacherHistory?',legacy."legacyLessonId"':'';
|
|
|
|
|
+ if(history)clauses.push('('+finished+' OR c."status"=-2)');else clauses.push('COALESCE(c."status",99)<>-2');
|
|
|
if(coach&&number(input.studentId))add('a."szyh"=?',String(input.studentId));
|
|
if(coach&&number(input.studentId))add('a."szyh"=?',String(input.studentId));
|
|
|
if(input.search)add('c."title" ILIKE ?','%'+String(input.search).trim().slice(0,100)+'%');
|
|
if(input.search)add('c."title" ILIKE ?','%'+String(input.search).trim().slice(0,100)+'%');
|
|
|
if(input.month&&/^\d{4}-\d{2}$/.test(input.month))add('LEFT('+date+',7)=?',input.month);
|
|
if(input.month&&/^\d{4}-\d{2}$/.test(input.month))add('LEFT('+date+',7)=?',input.month);
|
|
|
- const join=' FROM "CourseAppointment" a LEFT JOIN "CommonModel" c ON c."company"=a."company" AND c."modelId"=54 AND c."itemId"=a."id"';
|
|
|
|
|
|
|
+ const bookingJoin=' FROM "CourseAppointment" a LEFT JOIN "CommonModel" c ON c."company"=a."company" AND c."modelId"=54 AND c."itemId"=a."id"';
|
|
|
|
|
+ const join=bookingJoin+(teacherHistory?companionLegacyLessonJoin():'');
|
|
|
const summaryWhere=clauses.join(' AND '),summaryArgs=[...args];
|
|
const summaryWhere=clauses.join(' AND '),summaryArgs=[...args];
|
|
|
- const readDates=()=>Psql.query('SELECT '+date+' AS date,COUNT(*) FILTER(WHERE a."dszt"::numeric>=30 AND COALESCE(c."status",99)<>-2)::int finished,COUNT(*) FILTER(WHERE a."dszt"::numeric<30 AND COALESCE(c."status",99)<>-2)::int planned'+join+' WHERE '+summaryWhere+' GROUP BY '+date,summaryArgs);
|
|
|
|
|
- const readStudentOptions=()=>coach?Psql.query('SELECT a."szyh" AS id,MAX('+companionStudentNameSql()+') AS name,COUNT(*)::int count'+join+' LEFT JOIN "_User" u ON u."company"=a."company" AND u."legacyUserId"::text=a."szyh" WHERE a."company"=$1 AND a."pl"=$2 AND COALESCE(c."status",99)<>-2 GROUP BY a."szyh" ORDER BY name',[DEFAULT_COMPANY_ID,String(uid)]):[];
|
|
|
|
|
|
|
+ const readDates=()=>Psql.query('SELECT '+date+' AS date,COUNT(*) FILTER(WHERE '+finished+')::int finished,COUNT(*) FILTER(WHERE NOT '+finished+' AND COALESCE(c."status",99)<>-2)::int planned'+join+' WHERE '+summaryWhere+' GROUP BY '+date,summaryArgs);
|
|
|
|
|
+ const readStudentOptions=()=>coach?Psql.query('SELECT a."szyh" AS id,MAX('+companionStudentNameSql()+') AS name,COUNT(*)::int count'+bookingJoin+' LEFT JOIN "_User" u ON u."company"=a."company" AND u."legacyUserId"::text=a."szyh" WHERE a."company"=$1 AND a."pl"=$2 AND COALESCE(c."status",99)<>-2 GROUP BY a."szyh" ORDER BY name',[DEFAULT_COMPANY_ID,String(uid)]):[];
|
|
|
if(input.dateStart)add(date+'>=?',String(input.dateStart));
|
|
if(input.dateStart)add(date+'>=?',String(input.dateStart));
|
|
|
if(input.dateEnd)add(date+'<=?',String(input.dateEnd));
|
|
if(input.dateEnd)add(date+'<=?',String(input.dateEnd));
|
|
|
- if(input.filter==='finished')clauses.push('a."dszt"::numeric>=30 AND COALESCE(c."status",99)<>-2');
|
|
|
|
|
- if(input.filter==='pending'){clauses.push('a."dszt"::numeric<30 AND COALESCE(c."status",99)<>-2');add(date+'<?',appOverviewToday());}
|
|
|
|
|
|
|
+ if(input.filter==='finished')clauses.push(finished);
|
|
|
|
|
+ if(input.filter==='pending'){clauses.push('NOT '+finished+' AND COALESCE(c."status",99)<>-2');add(date+'<?',appOverviewToday());}
|
|
|
const where=clauses.join(' AND '),readCount=()=>Psql.one('SELECT COUNT(*)::int total'+join+' WHERE '+where,args);
|
|
const where=clauses.join(' AND '),readCount=()=>Psql.one('SELECT COUNT(*)::int total'+join+' WHERE '+where,args);
|
|
|
- const readRows=()=>Psql.query('SELECT c."generalId",c."title",c."createTime",c."status" AS "commonStatus",a.*,n."nodeName" AS "courseTitle"'+join+' LEFT JOIN "Node" n ON n."company"=a."company" AND n."nodeId"::text=a."kcid" WHERE '+where+' ORDER BY a."yysj" '+(history||input.filter==='finished'?'DESC':'ASC')+',a."id" DESC LIMIT $'+(args.length+1)+' OFFSET $'+(args.length+2),[...args,p.size,(p.index-1)*p.size]);
|
|
|
|
|
|
|
+ const readRows=()=>Psql.query('SELECT c."generalId",c."title",c."createTime",c."status" AS "commonStatus",a.*,n."nodeName" AS "courseTitle"'+lessonColumn+join+' LEFT JOIN "Node" n ON n."company"=a."company" AND n."nodeId"::text=a."kcid" WHERE '+where+' ORDER BY a."yysj" '+(history||input.filter==='finished'?'DESC':'ASC')+',a."id" DESC LIMIT $'+(args.length+1)+' OFFSET $'+(args.length+2),[...args,p.size,(p.index-1)*p.size]);
|
|
|
const readCourses=()=>coach?[]:Psql.query('SELECT c."generalId",c."title",b.*,b."objectId" AS "bindingObjectId",n."nodeName" AS "courseTitle" FROM "CourseBinding" b JOIN "CommonModel" c ON c."company"=b."company" AND c."modelId"=58 AND c."itemId"=b."id" LEFT JOIN "Node" n ON n."company"=b."company" AND n."nodeId"::text=b."kcid" WHERE b."company"=$1 AND b."yhid"=$2 AND b."enrollmentStatus"=\'active\' AND c."status"=99 AND COALESCE(n."zstatus",99)=99 ORDER BY b."id" DESC',[DEFAULT_COMPANY_ID,String(uid)]);
|
|
const readCourses=()=>coach?[]:Psql.query('SELECT c."generalId",c."title",b.*,b."objectId" AS "bindingObjectId",n."nodeName" AS "courseTitle" FROM "CourseBinding" b JOIN "CommonModel" c ON c."company"=b."company" AND c."modelId"=58 AND c."itemId"=b."id" LEFT JOIN "Node" n ON n."company"=b."company" AND n."nodeId"::text=b."kcid" WHERE b."company"=$1 AND b."yhid"=$2 AND b."enrollmentStatus"=\'active\' AND c."status"=99 AND COALESCE(n."zstatus",99)=99 ORDER BY b."id" DESC',[DEFAULT_COMPANY_ID,String(uid)]);
|
|
|
- const readAllRows=()=>coach&&history?Psql.query('SELECT c."generalId",c."status" AS "commonStatus",a.dszt'+join+' WHERE '+where,args):[];
|
|
|
|
|
|
|
+ const readAllRows=()=>coach&&history?Psql.query('SELECT c."generalId",c."status" AS "commonStatus",a.dszt'+lessonColumn+join+' WHERE '+where,args):[];
|
|
|
// Each request reads fresh data; only independent reads overlap, with bounded database pressure.
|
|
// Each request reads fresh data; only independent reads overlap, with bounded database pressure.
|
|
|
const reads=[readDates,readStudentOptions,readCount,readRows,readCourses,readAllRows],results=[];
|
|
const reads=[readDates,readStudentOptions,readCount,readRows,readCourses,readAllRows],results=[];
|
|
|
let nextRead=0,readError;
|
|
let nextRead=0,readError;
|
|
@@ -3060,7 +3065,7 @@ async function appCompanionOverview(input,current) {
|
|
|
let earningsSummary, scheduleRows=rows;
|
|
let earningsSummary, scheduleRows=rows;
|
|
|
if(coach&&history){
|
|
if(coach&&history){
|
|
|
const paidRows=await teacherSchedulePay(allRows,uid);
|
|
const paidRows=await teacherSchedulePay(allRows,uid);
|
|
|
- earningsSummary={amount:paidRows.reduce((sum,row)=>sum+(Number(row.commonStatus)!==-2&&row.payStatus==='earned'?Math.round(Number(row.teacherPay)*100):0),0)/100,pendingCount:paidRows.filter(row=>Number(row.commonStatus)!==-2&&row.payStatus!=='earned').length};
|
|
|
|
|
|
|
+ earningsSummary={amount:paidRows.reduce((sum,row)=>sum+((Number(row.commonStatus)!==-2||row.legacyLessonId)&&row.payStatus==='earned'?Math.round(Number(row.teacherPay)*100):0),0)/100,pendingCount:paidRows.filter(row=>(Number(row.commonStatus)!==-2||row.legacyLessonId)&&row.payStatus!=='earned').length};
|
|
|
const payById=new Map(paidRows.map(row=>[String(row.generalId),row]));
|
|
const payById=new Map(paidRows.map(row=>[String(row.generalId),row]));
|
|
|
scheduleRows=rows.map(row=>{
|
|
scheduleRows=rows.map(row=>{
|
|
|
const pay=payById.get(String(row.generalId));
|
|
const pay=payById.get(String(row.generalId));
|