| 1234567891011121314151617181920212223 |
- // Trace a lesson by either the admin CommonModel ID or the mobile GeneralID.
- async function lessonFeedbackDetail(context,input) {
- requireRole(context,['ops-manager','ops-staff','ops-auditor']);
- const companyId=companyIdOf(context,input),target=text(input.targetId||input.appointmentId||input.lessonId);
- if(!companyId||!target)fail(400,'缺少帐套或预约编号');
- const appointment=await Psql.oneOrNone('SELECT a.*,c."objectId" AS "commonId",c."generalId",c.title,c.subtitle,c.status AS "commonStatus" FROM "CommonModel" c JOIN "CourseAppointment" a ON a.company=c.company AND a.id=c."itemId" WHERE c.company=$1 AND c."modelId"=54 AND (c."objectId"=$2 OR c."generalId"::text=$2 OR a."objectId"=$2) LIMIT 1',[companyId,target]);
- if(!appointment)fail(404,'预约不存在');
- const gid=String(appointment.generalId);
- const [report,lessons,reservations,review,issue]=await Promise.all([
- Psql.oneOrNone('SELECT * FROM "LessonCompletionReport" WHERE company=$1 AND "appointmentGeneralId"::text=$2 ORDER BY "submittedAt" DESC LIMIT 1',[companyId,gid]),
- Psql.query('SELECT "objectId",pf,pjnr,pldp FROM "LessonRecord" WHERE company=$1 AND yyds::text=$2',[companyId,gid]),
- Psql.query('SELECT state,"creditCosts","consumedAt" FROM "CourseCreditReservation" WHERE company=$1 AND "appointmentId"=$2',[companyId,appointment.commonId]),
- Psql.oneOrNone('SELECT score,comment,"submittedAt" FROM "LessonReview" WHERE company=$1 AND "appointmentGeneralId"=$2',[companyId,gid]),
- Psql.oneOrNone('SELECT message FROM "LessonWorkflowIssue" WHERE company=$1 AND "appointmentGeneralId"=$2',[companyId,gid]),
- ]);
- const costs=report?.creditCosts||appointment.creditCostsSnapshot||[];
- return {...(report?safe(report):{}),appointmentGeneralId:gid,hasReport:Boolean(report),status:number(appointment.dszt),plannedAt:appointment.yysj,actualStartAt:report?.actualStartAt||appointment.kssj,actualEndAt:report?.actualEndAt||appointment.jssj,studentName:appointment.title,courseName:appointment.subtitle,courseCategoryName:appointment.courseCategoryName,durationMinutes:appointment.durationMinutes,deliveryLabel:deliveryLabel(appointment.deliveryMode),creditCosts:costs.map(cost=>({...cost,label:TEACHING_CREDIT_LABELS[cost.account]||cost.account})),creditState:reservations.map(r=>r.state).join('、')||'缺少凭据',lessonCount:lessons.length,studentReview:review||(number(lessons[0]?.pf)>0?{score:number(lessons[0].pf),comment:lessons[0].pjnr}:null),issue:issue?.message||(lessons.length>1?'重复上课记录,需核对':'')};
- }
- async function lessonWorkflowSchedule(context,input,data) {
- const issues=await Psql.query('SELECT i."appointmentGeneralId",i.message,i."updatedAt",c."objectId" AS "targetId" FROM "LessonWorkflowIssue" i LEFT JOIN "CommonModel" c ON c.company=i.company AND c."modelId"=54 AND c."generalId"::text=i."appointmentGeneralId" WHERE i.company=$1 ORDER BY i."updatedAt" DESC LIMIT 200',[companyIdOf(context,input)]);
- return {...data,workflowIssues:issues};
- }
|