You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
3.1 KiB
Java

package com.sztzjy.linkCommerce.training.knowledge;
import com.sztzjy.linkCommerce.entity.TrainingTask;
import com.sztzjy.linkCommerce.entity.TrainingTaskClassConfig;
import org.apache.commons.lang3.StringUtils;
/** Effective task data for a student: enabled teacher configuration overrides the admin default field by field. */
public class EffectiveTrainingTaskContent {
private final String scope;
private final String effectiveConfigId;
private final String knowledge;
private final String background;
private final String objectives;
private final String requirements;
private final String steps;
private final String materialName;
private final String materialUrl;
private EffectiveTrainingTaskContent(String scope, String effectiveConfigId, String knowledge, String background,
String objectives, String requirements, String steps, String materialName,
String materialUrl) {
this.scope = scope;
this.effectiveConfigId = effectiveConfigId;
this.knowledge = knowledge;
this.background = background;
this.objectives = objectives;
this.requirements = requirements;
this.steps = steps;
this.materialName = materialName;
this.materialUrl = materialUrl;
}
public static EffectiveTrainingTaskContent resolve(TrainingTask task, TrainingTaskClassConfig classConfig) {
boolean useTeacher = classConfig != null && Boolean.TRUE.equals(classConfig.getEnabled())
&& StringUtils.isNotBlank(classConfig.getId());
return new EffectiveTrainingTaskContent(
useTeacher ? "TEACHER" : "ADMIN",
useTeacher ? classConfig.getId() : task.getId(),
value(useTeacher ? classConfig.getKnowledge() : null, task.getKnowledge()),
value(useTeacher ? classConfig.getBackground() : null, task.getBackground()),
value(useTeacher ? classConfig.getObjectives() : null, task.getObjectives()),
value(useTeacher ? classConfig.getRequirements() : null, task.getRequirements()),
value(useTeacher ? classConfig.getSteps() : null, task.getSteps()),
value(useTeacher ? classConfig.getMaterialName() : null, task.getMaterialName()),
value(useTeacher ? classConfig.getMaterialUrl() : null, task.getMaterialUrl()));
}
private static String value(String preferred, String fallback) {
return StringUtils.isNotBlank(preferred) ? preferred : fallback;
}
public String getScope() { return scope; }
public String getEffectiveConfigId() { return effectiveConfigId; }
public String getKnowledge() { return knowledge; }
public String getBackground() { return background; }
public String getObjectives() { return objectives; }
public String getRequirements() { return requirements; }
public String getSteps() { return steps; }
public String getMaterialName() { return materialName; }
public String getMaterialUrl() { return materialUrl; }
}